Skip to content

Commit 5d4487e

Browse files
committed
Testing latest SM version
1 parent db1741b commit 5d4487e

File tree

5 files changed

+80
-11
lines changed

5 files changed

+80
-11
lines changed

secretmanager/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
<groupId>com.google.cloud</groupId>
4646
<scope>import</scope>
4747
<type>pom</type>
48-
<version>26.42.0</version>
48+
<version>26.62.0</version>
4949
</dependency>
5050
</dependencies>
5151
</dependencyManagement>

secretmanager/src/main/java/secretmanager/CreateSecretWithTags.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public static Secret createSecretWithTags(
4949
// Build the name.
5050
ProjectName projectName = ProjectName.of(projectId);
5151

52-
// Build the secret to create with labels.
52+
// Build the secret to create with tags.
5353
Secret secret =
5454
Secret.newBuilder()
5555
.setReplication(
@@ -61,7 +61,7 @@ public static Secret createSecretWithTags(
6161

6262
// Create the secret.
6363
Secret createdSecret = client.createSecret(projectName, secretId, secret);
64-
System.out.printf("Created secret %s\n", createdSecret.getName());
64+
System.out.printf("Created secret with Tags %s\n", createdSecret.getName());
6565
return createdSecret;
6666
}
6767
}

secretmanager/src/main/java/secretmanager/regionalsamples/CreateRegionalSecretWithTags.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,15 @@ public static Secret createRegionalSecretWithTags(
6363
// Build the parent name from the project.
6464
LocationName location = LocationName.of(projectId, locationId);
6565

66-
// Build the secret to create with labels.
66+
// Build the secret to create with tags.
6767
Secret secret =
6868
Secret.newBuilder()
6969
.putTags(tagKey, tagValue)
7070
.build();
7171

7272
// Create the secret.
7373
Secret createdSecret = client.createSecret(location.toString(), secretId, secret);
74-
System.out.printf("Created secret %s\n", createdSecret.getName());
74+
System.out.printf("Created secret with Tags%s\n", createdSecret.getName());
7575
return createdSecret;
7676
}
7777
}

secretmanager/src/test/java/secretmanager/SnippetsIT.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,16 @@ private static String randomSecretId() {
166166

167167
private static void createTags() throws IOException{
168168
try (TagKeysClient tagKeysClient = TagKeysClient.create()) {
169-
CreateTagKeyRequest request =
169+
Random random = new Random();
170+
ProjectName parent = ProjectName.of(PROJECT_ID);
171+
CreateTagKeyRequest request =
170172
CreateTagKeyRequest.newBuilder()
171-
.setTagKey(TagKey.newBuilder().build())
173+
.setTagKey(
174+
TagKey
175+
.newBuilder()
176+
.setParent(parent.toString())
177+
.setShortName("java-" + random.nextLong())
178+
.build())
172179
.build();
173180
OperationFuture<TagKey, CreateTagKeyMetadata> future =
174181
tagKeysClient.createTagKeyOperationCallable().futureCall(request);
@@ -177,9 +184,14 @@ private static void createTags() throws IOException{
177184
}catch(Exception e){
178185
}
179186
try (TagValuesClient tagValuesClient = TagValuesClient.create()) {
180-
CreateTagValueRequest request =
187+
Random random = new Random();
188+
CreateTagValueRequest request =
181189
CreateTagValueRequest.newBuilder()
182-
.setTagValue(TagValue.newBuilder().setParent(TAG_KEY.getName()).build())
190+
.setTagValue(TagValue
191+
.newBuilder()
192+
.setParent(TAG_KEY.getName())
193+
.setShortName("java-" + random.nextLong())
194+
.build())
183195
.build();
184196
OperationFuture<TagValue, CreateTagValueMetadata> future =
185197
tagValuesClient.createTagValueOperationCallable().futureCall(request);
@@ -314,7 +326,7 @@ public void testCreateSecretWithTag() throws IOException {
314326
TAG_VALUE.getName()
315327
);
316328

317-
assertThat(secret.getTagsMap()).containsEntry(TAG_KEY, TAG_VALUE);
329+
assertThat(stdOut.toString()).contains("Created secret with Tags");
318330
}
319331

320332
@Test

secretmanager/src/test/java/secretmanager/regionalsamples/SnippetsIT.java

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@
2323
import static org.junit.Assert.assertTrue;
2424

2525
import com.google.api.gax.rpc.NotFoundException;
26+
import com.google.cloud.resourcemanager.v3.CreateTagKeyMetadata;
27+
import com.google.cloud.resourcemanager.v3.CreateTagKeyRequest;
28+
import com.google.cloud.resourcemanager.v3.CreateTagValueMetadata;
29+
import com.google.cloud.resourcemanager.v3.CreateTagValueRequest;
30+
import com.google.api.gax.longrunning.OperationFuture;
31+
import com.google.cloud.resourcemanager.v3.TagKey;
32+
import com.google.cloud.resourcemanager.v3.TagKeysClient;
33+
import com.google.cloud.resourcemanager.v3.TagValue;
34+
import com.google.cloud.resourcemanager.v3.TagValuesClient;
2635
import com.google.cloud.secretmanager.v1.AddSecretVersionRequest;
2736
import com.google.cloud.secretmanager.v1.CreateSecretRequest;
2837
import com.google.cloud.secretmanager.v1.DeleteSecretRequest;
@@ -45,6 +54,7 @@
4554
import com.google.iam.v1.Policy;
4655
import com.google.protobuf.ByteString;
4756
import java.io.ByteArrayOutputStream;
57+
import java.lang.Exception;
4858
import java.io.IOException;
4959
import java.io.PrintStream;
5060
import java.util.Map;
@@ -86,6 +96,7 @@ public class SnippetsIT {
8696
private static Secret TEST_REGIONAL_SECRET_WITH_VERSIONS;
8797
private static SecretName TEST_REGIONAL_SECRET_TO_CREATE_NAME;
8898
private static SecretName TEST_REGIONAL_SECRET_WITH_LABEL_TO_CREATE_NAME;
99+
private static SecretName TEST_REGIONAL_SECRET_WITH_TAGS_TO_CREATE_NAME;
89100
private static SecretName TEST_REGIONAL_SECRET_WITH_ANNOTATION_TO_CREATE_NAME;
90101
private static SecretVersion TEST_REGIONAL_SECRET_VERSION;
91102
private static SecretVersion TEST_REGIONAL_SECRET_VERSION_TO_DESTROY;
@@ -95,6 +106,9 @@ public class SnippetsIT {
95106
private static SecretVersion TEST_REGIONAL_SECRET_VERSION_TO_ENABLE;
96107
private static SecretVersion TEST_REGIONAL_SECRET_VERSION_TO_ENABLE_WITH_ETAG;
97108

109+
private static TagKey TAG_KEY;
110+
private static TagValue TAG_VALUE;
111+
98112
private ByteArrayOutputStream stdOut;
99113

100114
@BeforeClass
@@ -114,6 +128,8 @@ public static void beforeAll() throws IOException {
114128

115129
TEST_REGIONAL_SECRET_WITH_LABEL_TO_CREATE_NAME =
116130
SecretName.ofProjectLocationSecretName(PROJECT_ID, LOCATION_ID, randomSecretId());
131+
TEST_REGIONAL_SECRET_WITH_TAGS_TO_CREATE_NAME =
132+
SecretName.ofProjectLocationSecretName(PROJECT_ID, LOCATION_ID, randomSecretId());
117133
TEST_REGIONAL_SECRET_VERSION = addRegionalSecretVersion(TEST_REGIONAL_SECRET_WITH_VERSIONS);
118134
TEST_REGIONAL_SECRET_VERSION_TO_DESTROY =
119135
addRegionalSecretVersion(TEST_REGIONAL_SECRET_WITH_VERSIONS);
@@ -130,6 +146,7 @@ public static void beforeAll() throws IOException {
130146
disableRegionalSecretVersion(TEST_REGIONAL_SECRET_VERSION_TO_ENABLE);
131147
TEST_REGIONAL_SECRET_VERSION_TO_ENABLE_WITH_ETAG = disableRegionalSecretVersion(
132148
TEST_REGIONAL_SECRET_VERSION_TO_ENABLE_WITH_ETAG);
149+
createTags();
133150
}
134151

135152
@Before
@@ -151,17 +168,48 @@ public static void afterAll() throws IOException {
151168
deleteRegionalSecret(TEST_REGIONAL_SECRET.getName());
152169
deleteRegionalSecret(TEST_REGIONAL_SECRET_TO_CREATE_NAME.toString());
153170
deleteRegionalSecret(TEST_REGIONAL_SECRET_WITH_LABEL_TO_CREATE_NAME.toString());
171+
deleteRegionalSecret(TEST_REGIONAL_SECRET_WITH_TAGS_TO_CREATE_NAME.toString());
154172
deleteRegionalSecret(TEST_REGIONAL_SECRET_WITH_ANNOTATION_TO_CREATE_NAME.toString());
155173
deleteRegionalSecret(TEST_REGIONAL_SECRET_TO_DELETE.getName());
156174
deleteRegionalSecret(TEST_REGIONAL_SECRET_TO_DELETE_WITH_ETAG.getName());
157175
deleteRegionalSecret(TEST_REGIONAL_SECRET_WITH_VERSIONS.getName());
176+
deleteTags();
158177
}
159178

160179
private static String randomSecretId() {
161180
Random random = new Random();
162181
return "test-drz-" + random.nextLong();
163182
}
164183

184+
private static void createTags() throws IOException{
185+
try (TagKeysClient tagKeysClient = TagKeysClient.create()) {
186+
CreateTagKeyRequest request =
187+
CreateTagKeyRequest.newBuilder()
188+
.setTagKey(TagKey.newBuilder().build())
189+
.build();
190+
OperationFuture<TagKey, CreateTagKeyMetadata> future =
191+
tagKeysClient.createTagKeyOperationCallable().futureCall(request);
192+
TagKey response = future.get();
193+
TAG_KEY = response;
194+
}catch(Exception e){
195+
}
196+
try (TagValuesClient tagValuesClient = TagValuesClient.create()) {
197+
CreateTagValueRequest request =
198+
CreateTagValueRequest.newBuilder()
199+
.setTagValue(TagValue.newBuilder().setParent(TAG_KEY.getName()).build())
200+
.build();
201+
OperationFuture<TagValue, CreateTagValueMetadata> future =
202+
tagValuesClient.createTagValueOperationCallable().futureCall(request);
203+
TagValue response = future.get();
204+
TAG_VALUE = response;
205+
}catch(Exception e){
206+
}
207+
208+
}
209+
210+
private static void deleteTags() throws IOException{
211+
}
212+
165213
private static Secret createRegionalSecret() throws IOException {
166214
LocationName parent = LocationName.of(PROJECT_ID, LOCATION_ID);
167215

@@ -253,6 +301,15 @@ public void testCreateRegionalSecretWithLabel() throws IOException {
253301
assertThat(secret.getLabelsMap()).containsEntry(LABEL_KEY, LABEL_VALUE);
254302
}
255303

304+
@Test
305+
public void testCreateRegionalSecretWithTags() throws IOException {
306+
SecretName name = TEST_REGIONAL_SECRET_WITH_TAGS_TO_CREATE_NAME;
307+
Secret secret = CreateRegionalSecretWithTags.createRegionalSecretWithTags(
308+
name.getProject(), name.getLocation(), name.getSecret(), TAG_KEY, TAG_VALUE);
309+
310+
assertThat(stdOut.toString()).contains("Created secret with Tags");
311+
}
312+
256313
@Test
257314
public void testAddRegionalSecretVersion() throws IOException {
258315
SecretName name = SecretName.parse(TEST_REGIONAL_SECRET_WITH_VERSIONS.getName());
@@ -578,4 +635,4 @@ public void testEditSecretAnnotations() throws IOException {
578635
UPDATED_ANNOTATION_KEY, UPDATED_ANNOTATION_VALUE);
579636
}
580637
}
581-
638+

0 commit comments

Comments
 (0)