use of com.google.cloud.secretmanager.v1.SecretVersion in project java-secretmanager by googleapis.
the class SecretManagerServiceClientTest method listSecretVersionsTest2.
@Test
public void listSecretVersionsTest2() throws Exception {
SecretVersion responsesElement = SecretVersion.newBuilder().build();
ListSecretVersionsResponse expectedResponse = ListSecretVersionsResponse.newBuilder().setNextPageToken("").addAllVersions(Arrays.asList(responsesElement)).build();
mockSecretManagerService.addResponse(expectedResponse);
String parent = "parent-995424086";
ListSecretVersionsPagedResponse pagedListResponse = client.listSecretVersions(parent);
List<SecretVersion> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getVersionsList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockSecretManagerService.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListSecretVersionsRequest actualRequest = ((ListSecretVersionsRequest) actualRequests.get(0));
Assert.assertEquals(parent, actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.cloud.secretmanager.v1.SecretVersion in project java-secretmanager by googleapis.
the class ITSystemTest method tearDown.
@AfterClass
public static void tearDown() {
/* destroy secret version */
DestroySecretVersionRequest versionRequest = DestroySecretVersionRequest.newBuilder().setName(formattedSecretVersion).build();
SecretVersion actualSecretVersion = client.destroySecretVersion(versionRequest);
assertEquals(secretVersion.getCreateTime(), actualSecretVersion.getCreateTime());
assertEquals(SecretVersion.State.DESTROYED, actualSecretVersion.getState());
/* delete secret */
DeleteSecretRequest secretRequest = DeleteSecretRequest.newBuilder().setName(formattedSecretName).build();
client.deleteSecret(secretRequest);
client.close();
}
use of com.google.cloud.secretmanager.v1.SecretVersion in project java-secretmanager by googleapis.
the class ITSystemTest method disableAndEnableSecretVersionTest.
@Test
public void disableAndEnableSecretVersionTest() {
DisableSecretVersionRequest disableSecretVersionRequest = DisableSecretVersionRequest.newBuilder().setName(formattedSecretVersion).build();
SecretVersion disableSecretVersion = client.disableSecretVersion(disableSecretVersionRequest);
assertEquals(secretVersion.getName(), disableSecretVersion.getName());
assertEquals(secretVersion.getCreateTime(), disableSecretVersion.getCreateTime());
assertEquals(SecretVersion.State.DISABLED, disableSecretVersion.getState());
EnableSecretVersionRequest enableSecretVersionRequest = EnableSecretVersionRequest.newBuilder().setName(formattedSecretVersion).build();
SecretVersion enableSecretVersion = client.enableSecretVersion(enableSecretVersionRequest);
assertEquals(secretVersion.getName(), enableSecretVersion.getName());
assertEquals(secretVersion.getCreateTime(), enableSecretVersion.getCreateTime());
assertEquals(SecretVersion.State.ENABLED, enableSecretVersion.getState());
}
use of com.google.cloud.secretmanager.v1.SecretVersion in project java-secretmanager by googleapis.
the class NativeImageSecretManagerSample method printSecretVersion.
static void printSecretVersion(SecretManagerServiceClient client, SecretVersion version) {
AccessSecretVersionResponse response = client.accessSecretVersion(version.getName());
String payload = response.getPayload().getData().toStringUtf8();
System.out.println("Reading secret value: " + payload);
System.out.println("(Note: Don't print secret values in prod!)");
}
use of com.google.cloud.secretmanager.v1.SecretVersion in project java-secretmanager by googleapis.
the class NativeImageSecretManagerSample method addSecretVersion.
static SecretVersion addSecretVersion(SecretManagerServiceClient client, String projectId, String secretId) {
SecretName secretName = SecretName.of(projectId, secretId);
SecretPayload payload = SecretPayload.newBuilder().setData(ByteString.copyFromUtf8("Hello World")).build();
SecretVersion version = client.addSecretVersion(secretName, payload);
System.out.println("Added Secret Version: " + version.getName());
return version;
}
Aggregations