use of com.google.cloud.secretmanager.v1beta1.SecretVersion in project java-secretmanager by googleapis.
the class ITSystemTest method getSecretVersionTest.
@Test
public void getSecretVersionTest() {
GetSecretVersionRequest request = GetSecretVersionRequest.newBuilder().setName(formattedSecretVersion).build();
SecretVersion actualSecretVersion = client.getSecretVersion(request);
assertEquals(secretVersion.getName(), actualSecretVersion.getName());
assertEquals(secretVersion.getCreateTime(), actualSecretVersion.getCreateTime());
assertEquals(SecretVersion.State.ENABLED, actualSecretVersion.getState());
}
use of com.google.cloud.secretmanager.v1beta1.SecretVersion in project java-secretmanager by googleapis.
the class ITSystemTest method setUp.
@BeforeClass
public static void setUp() throws IOException {
/* create secret */
client = SecretManagerServiceClient.create();
Replication createReplication = Replication.newBuilder().setUserManaged(Replication.UserManaged.newBuilder().addReplicas(Replication.UserManaged.Replica.newBuilder().setLocation(LOCATION).build())).build();
Secret createSecret = Secret.newBuilder().setReplication(createReplication).build();
CreateSecretRequest secretRequest = CreateSecretRequest.newBuilder().setParent(PROJECT_NAME).setSecretId(SECRET_ID).setSecret(createSecret).build();
secret = client.createSecret(secretRequest);
secretId = getName(secret.getName());
formattedSecretName = SecretName.of(PROJECT_ID, secretId).toString();
/* create secret version */
AddSecretVersionRequest versionRequest = AddSecretVersionRequest.newBuilder().setParent(formattedSecretName).setPayload(PAYLOAD).build();
secretVersion = client.addSecretVersion(versionRequest);
secretVersionId = getName(secretVersion.getName());
formattedSecretVersion = SecretVersionName.of(PROJECT_ID, secretId, secretVersionId).toString();
}
use of com.google.cloud.secretmanager.v1beta1.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.v1beta1.SecretVersion in project java-secretmanager by googleapis.
the class DisableSecretVersion method disableSecretVersion.
// Disable an existing secret version.
public void disableSecretVersion(String projectId, String secretId, String versionId) throws IOException {
// the "close" method on the client to safely clean up any remaining background resources.
try (SecretManagerServiceClient client = SecretManagerServiceClient.create()) {
// Build the name from the version.
SecretVersionName secretVersionName = SecretVersionName.of(projectId, secretId, versionId);
// Create the secret.
SecretVersion version = client.disableSecretVersion(secretVersionName);
System.out.printf("Disabled secret version %s\n", version.getName());
}
}
Aggregations