use of com.google.cloud.secretmanager.v1.Secret in project java-secretmanager by googleapis.
the class SecretManagerServiceClientTest method listSecretsTest2.
@Test
public void listSecretsTest2() throws Exception {
Secret responsesElement = Secret.newBuilder().build();
ListSecretsResponse expectedResponse = ListSecretsResponse.newBuilder().setNextPageToken("").addAllSecrets(Arrays.asList(responsesElement)).build();
mockSecretManagerService.addResponse(expectedResponse);
String parent = "parent-995424086";
ListSecretsPagedResponse pagedListResponse = client.listSecrets(parent);
List<Secret> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getSecretsList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockSecretManagerService.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListSecretsRequest actualRequest = ((ListSecretsRequest) actualRequests.get(0));
Assert.assertEquals(parent, actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.cloud.secretmanager.v1.Secret in project java-secretmanager by googleapis.
the class SecretManagerServiceClientTest method listSecretsTest.
@Test
public void listSecretsTest() throws Exception {
Secret responsesElement = Secret.newBuilder().build();
ListSecretsResponse expectedResponse = ListSecretsResponse.newBuilder().setNextPageToken("").addAllSecrets(Arrays.asList(responsesElement)).build();
mockSecretManagerService.addResponse(expectedResponse);
ProjectName parent = ProjectName.of("[PROJECT]");
ListSecretsPagedResponse pagedListResponse = client.listSecrets(parent);
List<Secret> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getSecretsList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockSecretManagerService.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListSecretsRequest actualRequest = ((ListSecretsRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.cloud.secretmanager.v1.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.v1.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.v1.Secret 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!)");
}
Aggregations