1 /* 2 * Copyright 2022 Google LLC 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * https://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.google.cloud.kms.inventory.v1; 18 19 import com.google.api.core.BetaApi; 20 import com.google.api.pathtemplate.PathTemplate; 21 import com.google.api.pathtemplate.ValidationException; 22 import com.google.api.resourcenames.ResourceName; 23 import com.google.common.base.Preconditions; 24 import com.google.common.collect.ImmutableMap; 25 import java.util.ArrayList; 26 import java.util.List; 27 import java.util.Map; 28 import java.util.Objects; 29 import javax.annotation.Generated; 30 31 // AUTO-GENERATED DOCUMENTATION AND CLASS. 32 @Generated("by gapic-generator-java") 33 public class ProtectedResourcesSummaryName implements ResourceName { 34 private static final PathTemplate PROJECT_LOCATION_KEY_RING_CRYPTO_KEY = 35 PathTemplate.createWithoutUrlEncoding( 36 "projects/{project}/locations/{location}/keyRings/{key_ring}/cryptoKeys/{crypto_key}/protectedResourcesSummary"); 37 private static final PathTemplate PROJECT_LOCATION_KEY_RING_CRYPTO_KEY_CRYPTO_KEY_VERSION = 38 PathTemplate.createWithoutUrlEncoding( 39 "projects/{project}/locations/{location}/keyRings/{key_ring}/cryptoKeys/{crypto_key}/cryptoKeyVersions/{crypto_key_version}/protectedResourcesSummary"); 40 private volatile Map<String, String> fieldValuesMap; 41 private PathTemplate pathTemplate; 42 private String fixedValue; 43 private final String project; 44 private final String location; 45 private final String keyRing; 46 private final String cryptoKey; 47 private final String cryptoKeyVersion; 48 49 @Deprecated ProtectedResourcesSummaryName()50 protected ProtectedResourcesSummaryName() { 51 project = null; 52 location = null; 53 keyRing = null; 54 cryptoKey = null; 55 cryptoKeyVersion = null; 56 } 57 ProtectedResourcesSummaryName(Builder builder)58 private ProtectedResourcesSummaryName(Builder builder) { 59 project = Preconditions.checkNotNull(builder.getProject()); 60 location = Preconditions.checkNotNull(builder.getLocation()); 61 keyRing = Preconditions.checkNotNull(builder.getKeyRing()); 62 cryptoKey = Preconditions.checkNotNull(builder.getCryptoKey()); 63 cryptoKeyVersion = null; 64 pathTemplate = PROJECT_LOCATION_KEY_RING_CRYPTO_KEY; 65 } 66 ProtectedResourcesSummaryName( ProjectLocationKeyRingCryptoKeyCryptoKeyVersionBuilder builder)67 private ProtectedResourcesSummaryName( 68 ProjectLocationKeyRingCryptoKeyCryptoKeyVersionBuilder builder) { 69 project = Preconditions.checkNotNull(builder.getProject()); 70 location = Preconditions.checkNotNull(builder.getLocation()); 71 keyRing = Preconditions.checkNotNull(builder.getKeyRing()); 72 cryptoKey = Preconditions.checkNotNull(builder.getCryptoKey()); 73 cryptoKeyVersion = Preconditions.checkNotNull(builder.getCryptoKeyVersion()); 74 pathTemplate = PROJECT_LOCATION_KEY_RING_CRYPTO_KEY_CRYPTO_KEY_VERSION; 75 } 76 getProject()77 public String getProject() { 78 return project; 79 } 80 getLocation()81 public String getLocation() { 82 return location; 83 } 84 getKeyRing()85 public String getKeyRing() { 86 return keyRing; 87 } 88 getCryptoKey()89 public String getCryptoKey() { 90 return cryptoKey; 91 } 92 getCryptoKeyVersion()93 public String getCryptoKeyVersion() { 94 return cryptoKeyVersion; 95 } 96 newBuilder()97 public static Builder newBuilder() { 98 return new Builder(); 99 } 100 101 @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.") newProjectLocationKeyRingCryptoKeyBuilder()102 public static Builder newProjectLocationKeyRingCryptoKeyBuilder() { 103 return new Builder(); 104 } 105 106 @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.") 107 public static ProjectLocationKeyRingCryptoKeyCryptoKeyVersionBuilder newProjectLocationKeyRingCryptoKeyCryptoKeyVersionBuilder()108 newProjectLocationKeyRingCryptoKeyCryptoKeyVersionBuilder() { 109 return new ProjectLocationKeyRingCryptoKeyCryptoKeyVersionBuilder(); 110 } 111 toBuilder()112 public Builder toBuilder() { 113 return new Builder(this); 114 } 115 of( String project, String location, String keyRing, String cryptoKey)116 public static ProtectedResourcesSummaryName of( 117 String project, String location, String keyRing, String cryptoKey) { 118 return newBuilder() 119 .setProject(project) 120 .setLocation(location) 121 .setKeyRing(keyRing) 122 .setCryptoKey(cryptoKey) 123 .build(); 124 } 125 126 @BetaApi("The static create methods are not stable yet and may be changed in the future.") ofProjectLocationKeyRingCryptoKeyName( String project, String location, String keyRing, String cryptoKey)127 public static ProtectedResourcesSummaryName ofProjectLocationKeyRingCryptoKeyName( 128 String project, String location, String keyRing, String cryptoKey) { 129 return newBuilder() 130 .setProject(project) 131 .setLocation(location) 132 .setKeyRing(keyRing) 133 .setCryptoKey(cryptoKey) 134 .build(); 135 } 136 137 @BetaApi("The static create methods are not stable yet and may be changed in the future.") ofProjectLocationKeyRingCryptoKeyCryptoKeyVersionName( String project, String location, String keyRing, String cryptoKey, String cryptoKeyVersion)138 public static ProtectedResourcesSummaryName ofProjectLocationKeyRingCryptoKeyCryptoKeyVersionName( 139 String project, String location, String keyRing, String cryptoKey, String cryptoKeyVersion) { 140 return newProjectLocationKeyRingCryptoKeyCryptoKeyVersionBuilder() 141 .setProject(project) 142 .setLocation(location) 143 .setKeyRing(keyRing) 144 .setCryptoKey(cryptoKey) 145 .setCryptoKeyVersion(cryptoKeyVersion) 146 .build(); 147 } 148 format(String project, String location, String keyRing, String cryptoKey)149 public static String format(String project, String location, String keyRing, String cryptoKey) { 150 return newBuilder() 151 .setProject(project) 152 .setLocation(location) 153 .setKeyRing(keyRing) 154 .setCryptoKey(cryptoKey) 155 .build() 156 .toString(); 157 } 158 159 @BetaApi("The static format methods are not stable yet and may be changed in the future.") formatProjectLocationKeyRingCryptoKeyName( String project, String location, String keyRing, String cryptoKey)160 public static String formatProjectLocationKeyRingCryptoKeyName( 161 String project, String location, String keyRing, String cryptoKey) { 162 return newBuilder() 163 .setProject(project) 164 .setLocation(location) 165 .setKeyRing(keyRing) 166 .setCryptoKey(cryptoKey) 167 .build() 168 .toString(); 169 } 170 171 @BetaApi("The static format methods are not stable yet and may be changed in the future.") formatProjectLocationKeyRingCryptoKeyCryptoKeyVersionName( String project, String location, String keyRing, String cryptoKey, String cryptoKeyVersion)172 public static String formatProjectLocationKeyRingCryptoKeyCryptoKeyVersionName( 173 String project, String location, String keyRing, String cryptoKey, String cryptoKeyVersion) { 174 return newProjectLocationKeyRingCryptoKeyCryptoKeyVersionBuilder() 175 .setProject(project) 176 .setLocation(location) 177 .setKeyRing(keyRing) 178 .setCryptoKey(cryptoKey) 179 .setCryptoKeyVersion(cryptoKeyVersion) 180 .build() 181 .toString(); 182 } 183 parse(String formattedString)184 public static ProtectedResourcesSummaryName parse(String formattedString) { 185 if (formattedString.isEmpty()) { 186 return null; 187 } 188 if (PROJECT_LOCATION_KEY_RING_CRYPTO_KEY.matches(formattedString)) { 189 Map<String, String> matchMap = PROJECT_LOCATION_KEY_RING_CRYPTO_KEY.match(formattedString); 190 return ofProjectLocationKeyRingCryptoKeyName( 191 matchMap.get("project"), 192 matchMap.get("location"), 193 matchMap.get("key_ring"), 194 matchMap.get("crypto_key")); 195 } else if (PROJECT_LOCATION_KEY_RING_CRYPTO_KEY_CRYPTO_KEY_VERSION.matches(formattedString)) { 196 Map<String, String> matchMap = 197 PROJECT_LOCATION_KEY_RING_CRYPTO_KEY_CRYPTO_KEY_VERSION.match(formattedString); 198 return ofProjectLocationKeyRingCryptoKeyCryptoKeyVersionName( 199 matchMap.get("project"), 200 matchMap.get("location"), 201 matchMap.get("key_ring"), 202 matchMap.get("crypto_key"), 203 matchMap.get("crypto_key_version")); 204 } 205 throw new ValidationException( 206 "ProtectedResourcesSummaryName.parse: formattedString not in valid format"); 207 } 208 parseList(List<String> formattedStrings)209 public static List<ProtectedResourcesSummaryName> parseList(List<String> formattedStrings) { 210 List<ProtectedResourcesSummaryName> list = new ArrayList<>(formattedStrings.size()); 211 for (String formattedString : formattedStrings) { 212 list.add(parse(formattedString)); 213 } 214 return list; 215 } 216 toStringList(List<ProtectedResourcesSummaryName> values)217 public static List<String> toStringList(List<ProtectedResourcesSummaryName> values) { 218 List<String> list = new ArrayList<>(values.size()); 219 for (ProtectedResourcesSummaryName value : values) { 220 if (value == null) { 221 list.add(""); 222 } else { 223 list.add(value.toString()); 224 } 225 } 226 return list; 227 } 228 isParsableFrom(String formattedString)229 public static boolean isParsableFrom(String formattedString) { 230 return PROJECT_LOCATION_KEY_RING_CRYPTO_KEY.matches(formattedString) 231 || PROJECT_LOCATION_KEY_RING_CRYPTO_KEY_CRYPTO_KEY_VERSION.matches(formattedString); 232 } 233 234 @Override getFieldValuesMap()235 public Map<String, String> getFieldValuesMap() { 236 if (fieldValuesMap == null) { 237 synchronized (this) { 238 if (fieldValuesMap == null) { 239 ImmutableMap.Builder<String, String> fieldMapBuilder = ImmutableMap.builder(); 240 if (project != null) { 241 fieldMapBuilder.put("project", project); 242 } 243 if (location != null) { 244 fieldMapBuilder.put("location", location); 245 } 246 if (keyRing != null) { 247 fieldMapBuilder.put("key_ring", keyRing); 248 } 249 if (cryptoKey != null) { 250 fieldMapBuilder.put("crypto_key", cryptoKey); 251 } 252 if (cryptoKeyVersion != null) { 253 fieldMapBuilder.put("crypto_key_version", cryptoKeyVersion); 254 } 255 fieldValuesMap = fieldMapBuilder.build(); 256 } 257 } 258 } 259 return fieldValuesMap; 260 } 261 getFieldValue(String fieldName)262 public String getFieldValue(String fieldName) { 263 return getFieldValuesMap().get(fieldName); 264 } 265 266 @Override toString()267 public String toString() { 268 return fixedValue != null ? fixedValue : pathTemplate.instantiate(getFieldValuesMap()); 269 } 270 271 @Override equals(Object o)272 public boolean equals(Object o) { 273 if (o == this) { 274 return true; 275 } 276 if (o != null || getClass() == o.getClass()) { 277 ProtectedResourcesSummaryName that = ((ProtectedResourcesSummaryName) o); 278 return Objects.equals(this.project, that.project) 279 && Objects.equals(this.location, that.location) 280 && Objects.equals(this.keyRing, that.keyRing) 281 && Objects.equals(this.cryptoKey, that.cryptoKey) 282 && Objects.equals(this.cryptoKeyVersion, that.cryptoKeyVersion); 283 } 284 return false; 285 } 286 287 @Override hashCode()288 public int hashCode() { 289 int h = 1; 290 h *= 1000003; 291 h ^= Objects.hashCode(fixedValue); 292 h *= 1000003; 293 h ^= Objects.hashCode(project); 294 h *= 1000003; 295 h ^= Objects.hashCode(location); 296 h *= 1000003; 297 h ^= Objects.hashCode(keyRing); 298 h *= 1000003; 299 h ^= Objects.hashCode(cryptoKey); 300 h *= 1000003; 301 h ^= Objects.hashCode(cryptoKeyVersion); 302 return h; 303 } 304 305 /** 306 * Builder for 307 * projects/{project}/locations/{location}/keyRings/{key_ring}/cryptoKeys/{crypto_key}/protectedResourcesSummary. 308 */ 309 public static class Builder { 310 private String project; 311 private String location; 312 private String keyRing; 313 private String cryptoKey; 314 Builder()315 protected Builder() {} 316 getProject()317 public String getProject() { 318 return project; 319 } 320 getLocation()321 public String getLocation() { 322 return location; 323 } 324 getKeyRing()325 public String getKeyRing() { 326 return keyRing; 327 } 328 getCryptoKey()329 public String getCryptoKey() { 330 return cryptoKey; 331 } 332 setProject(String project)333 public Builder setProject(String project) { 334 this.project = project; 335 return this; 336 } 337 setLocation(String location)338 public Builder setLocation(String location) { 339 this.location = location; 340 return this; 341 } 342 setKeyRing(String keyRing)343 public Builder setKeyRing(String keyRing) { 344 this.keyRing = keyRing; 345 return this; 346 } 347 setCryptoKey(String cryptoKey)348 public Builder setCryptoKey(String cryptoKey) { 349 this.cryptoKey = cryptoKey; 350 return this; 351 } 352 Builder(ProtectedResourcesSummaryName protectedResourcesSummaryName)353 private Builder(ProtectedResourcesSummaryName protectedResourcesSummaryName) { 354 Preconditions.checkArgument( 355 Objects.equals( 356 protectedResourcesSummaryName.pathTemplate, PROJECT_LOCATION_KEY_RING_CRYPTO_KEY), 357 "toBuilder is only supported when ProtectedResourcesSummaryName has the pattern of projects/{project}/locations/{location}/keyRings/{key_ring}/cryptoKeys/{crypto_key}/protectedResourcesSummary"); 358 this.project = protectedResourcesSummaryName.project; 359 this.location = protectedResourcesSummaryName.location; 360 this.keyRing = protectedResourcesSummaryName.keyRing; 361 this.cryptoKey = protectedResourcesSummaryName.cryptoKey; 362 } 363 build()364 public ProtectedResourcesSummaryName build() { 365 return new ProtectedResourcesSummaryName(this); 366 } 367 } 368 369 /** 370 * Builder for 371 * projects/{project}/locations/{location}/keyRings/{key_ring}/cryptoKeys/{crypto_key}/cryptoKeyVersions/{crypto_key_version}/protectedResourcesSummary. 372 */ 373 @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.") 374 public static class ProjectLocationKeyRingCryptoKeyCryptoKeyVersionBuilder { 375 private String project; 376 private String location; 377 private String keyRing; 378 private String cryptoKey; 379 private String cryptoKeyVersion; 380 ProjectLocationKeyRingCryptoKeyCryptoKeyVersionBuilder()381 protected ProjectLocationKeyRingCryptoKeyCryptoKeyVersionBuilder() {} 382 getProject()383 public String getProject() { 384 return project; 385 } 386 getLocation()387 public String getLocation() { 388 return location; 389 } 390 getKeyRing()391 public String getKeyRing() { 392 return keyRing; 393 } 394 getCryptoKey()395 public String getCryptoKey() { 396 return cryptoKey; 397 } 398 getCryptoKeyVersion()399 public String getCryptoKeyVersion() { 400 return cryptoKeyVersion; 401 } 402 setProject(String project)403 public ProjectLocationKeyRingCryptoKeyCryptoKeyVersionBuilder setProject(String project) { 404 this.project = project; 405 return this; 406 } 407 setLocation(String location)408 public ProjectLocationKeyRingCryptoKeyCryptoKeyVersionBuilder setLocation(String location) { 409 this.location = location; 410 return this; 411 } 412 setKeyRing(String keyRing)413 public ProjectLocationKeyRingCryptoKeyCryptoKeyVersionBuilder setKeyRing(String keyRing) { 414 this.keyRing = keyRing; 415 return this; 416 } 417 setCryptoKey(String cryptoKey)418 public ProjectLocationKeyRingCryptoKeyCryptoKeyVersionBuilder setCryptoKey(String cryptoKey) { 419 this.cryptoKey = cryptoKey; 420 return this; 421 } 422 setCryptoKeyVersion( String cryptoKeyVersion)423 public ProjectLocationKeyRingCryptoKeyCryptoKeyVersionBuilder setCryptoKeyVersion( 424 String cryptoKeyVersion) { 425 this.cryptoKeyVersion = cryptoKeyVersion; 426 return this; 427 } 428 build()429 public ProtectedResourcesSummaryName build() { 430 return new ProtectedResourcesSummaryName(this); 431 } 432 } 433 } 434