use of com.google.cloud.secretmanager.v1beta1.SecretVersion in project java-secretmanager by googleapis.
the class SecretManagerServiceClientTest method listSecretVersionsTest.
@Test
public void listSecretVersionsTest() throws Exception {
SecretVersion responsesElement = SecretVersion.newBuilder().build();
ListSecretVersionsResponse expectedResponse = ListSecretVersionsResponse.newBuilder().setNextPageToken("").addAllVersions(Arrays.asList(responsesElement)).build();
mockSecretManagerService.addResponse(expectedResponse);
SecretName parent = SecretName.of("[PROJECT]", "[SECRET]");
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.toString(), actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.cloud.secretmanager.v1beta1.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.v1beta1.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.v1beta1.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;
}
use of com.google.cloud.secretmanager.v1beta1.SecretVersion in project java-secretmanager by googleapis.
the class NativeImageSecretManagerSample method main.
/**
* Runs the Secret Manager sample application.
*/
public static void main(String[] args) throws IOException {
String projectId = ServiceOptions.getDefaultProjectId();
try (SecretManagerServiceClient client = SecretManagerServiceClient.create()) {
if (!hasSecret(client, projectId, NATIVE_TEST_SECRET_ID)) {
createSecret(client, projectId, NATIVE_TEST_SECRET_ID);
} else {
System.out.println("Project already has secret: " + NATIVE_TEST_SECRET_ID);
}
SecretVersion version = addSecretVersion(client, projectId, NATIVE_TEST_SECRET_ID);
printSecretVersion(client, version);
}
}
Aggregations