use of com.google.cloud.secretmanager.v1beta1.Secret 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.Secret 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.Secret in project java-secretmanager by googleapis.
the class ITSystemTest method listSecretsTest.
@Test
public void listSecretsTest() {
ListSecretsRequest request = ListSecretsRequest.newBuilder().setParent(PROJECT_NAME).build();
for (Secret actualSecret : client.listSecrets(request).iterateAll()) {
if (secret.getName().equals(actualSecret.getName())) {
assertEquals(secret.getReplication(), actualSecret.getReplication());
assertEquals(secret.getCreateTime(), actualSecret.getCreateTime());
}
}
}
use of com.google.cloud.secretmanager.v1beta1.Secret in project java-secretmanager by googleapis.
the class ITSystemTest method getSecretTest.
@Test
public void getSecretTest() {
GetSecretRequest request = GetSecretRequest.newBuilder().setName(formattedSecretName).build();
Secret actualSecret = client.getSecret(request);
assertEquals(secret.getName(), actualSecret.getName());
assertEquals(secret.getReplication(), actualSecret.getReplication());
assertEquals(secret.getCreateTime(), actualSecret.getCreateTime());
}
use of com.google.cloud.secretmanager.v1beta1.Secret in project java-secretmanager by googleapis.
the class Quickstart method quickstart.
public void quickstart(String projectId, String secretId) throws Exception {
// the "close" method on the client to safely clean up any remaining background resources.
try (SecretManagerServiceClient client = SecretManagerServiceClient.create()) {
// Build the parent name from the project.
ProjectName projectName = ProjectName.of(projectId);
// Create the parent secret.
Secret secret = Secret.newBuilder().setReplication(Replication.newBuilder().setAutomatic(Replication.Automatic.newBuilder().build()).build()).build();
Secret createdSecret = client.createSecret(projectName, secretId, secret);
// Add a secret version.
SecretPayload payload = SecretPayload.newBuilder().setData(ByteString.copyFromUtf8("hello world!")).build();
SecretVersion addedVersion = client.addSecretVersion(createdSecret.getName(), payload);
// Access the secret version.
AccessSecretVersionResponse response = client.accessSecretVersion(addedVersion.getName());
// Print the secret payload.
//
// WARNING: Do not print the secret in a production environment - this
// snippet is showing how to access the secret material.
String data = response.getPayload().getData().toStringUtf8();
System.out.printf("Plaintext: %s\n", data);
}
}
Aggregations