Skip to content

Commit 0acae16

Browse files
Applied suggestions from code review
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent 36203bb commit 0acae16

File tree

3 files changed

+8
-24
lines changed

3 files changed

+8
-24
lines changed

secretmanager/src/main/java/secretmanager/CreateSecretWithCmek.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package secretmanager;
1818

19-
// [START secretmanager_create_secret_with_annotations]
19+
// [START secretmanager_create_secret_with_cmek]
2020
import com.google.cloud.secretmanager.v1.CustomerManagedEncryption;
2121
import com.google.cloud.secretmanager.v1.ProjectName;
2222
import com.google.cloud.secretmanager.v1.Replication;
@@ -38,7 +38,7 @@ public static void main() throws IOException {
3838
createSecretWithCmek(projectId, secretId, kmsKeyName);
3939
}
4040

41-
// Create a secret with annotations.
41+
// Create a secret with a customer-managed encryption key (CMEK).
4242
public static Secret createSecretWithCmek(String projectId, String secretId, String kmsKeyName)
4343
throws IOException {
4444

@@ -63,7 +63,7 @@ public static Secret createSecretWithCmek(String projectId, String secretId, Str
6363
.build())
6464
.build();
6565

66-
// Build the secret to create with labels.
66+
// Build the secret to create with the replication policy.
6767
Secret secret = Secret.newBuilder().setReplication(secretReplication).build();
6868

6969
// Create the secret.
@@ -73,4 +73,4 @@ public static Secret createSecretWithCmek(String projectId, String secretId, Str
7373
}
7474
}
7575
}
76-
// [END secretmanager_create_secret_with_annotations]
76+
// [END secretmanager_create_secret_with_cmek]

secretmanager/src/main/java/secretmanager/DeleteSecretAnnotations.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,11 @@ public static Secret deleteSecretAnnotations(String projectId, String secretId)
4848
// Build the name of the secret.
4949
SecretName secretName = SecretName.of(projectId, secretId);
5050

51-
// Get the current secret
52-
Secret existingSecret = client.getSecret(secretName);
53-
54-
// Remove all annotations
55-
Map<String, String> existingAnnotationsMap =
56-
new HashMap<String, String>(existingSecret.getAnnotationsMap());
57-
existingAnnotationsMap.clear();
58-
59-
// Build the updated secret.
51+
// Build the updated secret with an empty annotations map.
6052
Secret secret =
6153
Secret.newBuilder()
6254
.setName(secretName.toString())
63-
.putAllAnnotations(existingAnnotationsMap)
55+
.putAllAnnotations(new HashMap<>())
6456
.build();
6557

6658
// Create the field mask for updating only the annotations

secretmanager/src/main/java/secretmanager/regionalsamples/DeleteRegionalSecretAnnotations.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,11 @@ public static Secret deleteRegionalSecretAnnotations(
5959
SecretName secretName =
6060
SecretName.ofProjectLocationSecretName(projectId, locationId, secretId);
6161

62-
// Get the current secret
63-
Secret existingSecret = client.getSecret(secretName);
64-
65-
// Remove all annotations
66-
Map<String, String> existingAnnotationsMap =
67-
new HashMap<String, String>(existingSecret.getAnnotationsMap());
68-
existingAnnotationsMap.clear();
69-
70-
// Build the updated secret.
62+
// Build the updated secret with an empty annotations map.
7163
Secret secret =
7264
Secret.newBuilder()
7365
.setName(secretName.toString())
74-
.putAllAnnotations(existingAnnotationsMap)
66+
.putAllAnnotations(new HashMap<>())
7567
.build();
7668

7769
// Create the field mask for updating only the annotations

0 commit comments

Comments
 (0)