Search in sources :

Example 26 with SecretVersion

use of com.google.cloud.secretmanager.v1.SecretVersion in project nomulus by google.

the class SecretManagerClientImpl method addSecretVersion.

@Override
public String addSecretVersion(String secretId, String data) {
    checkNotNull(secretId, "secretId");
    checkNotNull(data, "data");
    SecretName secretName = SecretName.of(project, secretId);
    SecretPayload secretPayload = SecretPayload.newBuilder().setData(ByteString.copyFromUtf8(data)).build();
    SecretVersion response = callSecretManager(() -> csmClient.addSecretVersion(secretName, secretPayload));
    checkState(SecretVersionName.isParsableFrom(response.getName()));
    SecretVersionName secretVersionName = SecretVersionName.parse(response.getName());
    return secretVersionName.getSecretVersion();
}
Also used : SecretName(com.google.cloud.secretmanager.v1.SecretName) SecretVersion(com.google.cloud.secretmanager.v1.SecretVersion) SecretVersionName(com.google.cloud.secretmanager.v1.SecretVersionName) SecretPayload(com.google.cloud.secretmanager.v1.SecretPayload)

Example 27 with SecretVersion

use of com.google.cloud.secretmanager.v1.SecretVersion in project java-secretmanager by googleapis.

the class ITSystemTest method listSecretVersionsTest.

@Test
public void listSecretVersionsTest() {
    ListSecretVersionsRequest request = ListSecretVersionsRequest.newBuilder().setParent(formattedSecretName).build();
    for (SecretVersion actualSecretVersion : client.listSecretVersions(request).iterateAll()) {
        if (secretVersion.getName().equals(actualSecretVersion.getName())) {
            assertEquals(secretVersion.getCreateTime(), actualSecretVersion.getCreateTime());
            assertEquals(SecretVersion.State.ENABLED, actualSecretVersion.getState());
        }
    }
}
Also used : SecretVersion(com.google.cloud.secretmanager.v1beta1.SecretVersion) ListSecretVersionsRequest(com.google.cloud.secretmanager.v1beta1.ListSecretVersionsRequest) Test(org.junit.Test)

Example 28 with SecretVersion

use of com.google.cloud.secretmanager.v1.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());
}
Also used : GetSecretVersionRequest(com.google.cloud.secretmanager.v1beta1.GetSecretVersionRequest) SecretVersion(com.google.cloud.secretmanager.v1beta1.SecretVersion) Test(org.junit.Test)

Example 29 with SecretVersion

use of com.google.cloud.secretmanager.v1.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()));
}
Also used : ListSecretVersionsPagedResponse(com.google.cloud.secretmanager.v1.SecretManagerServiceClient.ListSecretVersionsPagedResponse) AbstractMessage(com.google.protobuf.AbstractMessage) Test(org.junit.Test)

Example 30 with SecretVersion

use of com.google.cloud.secretmanager.v1.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());
    }
}
Also used : SecretVersionName(com.google.cloud.secretmanager.v1.SecretVersionName) SecretVersion(com.google.cloud.secretmanager.v1.SecretVersion) SecretManagerServiceClient(com.google.cloud.secretmanager.v1.SecretManagerServiceClient)

Aggregations

SecretVersion (com.google.cloud.secretmanager.v1.SecretVersion)22 SecretManagerServiceClient (com.google.cloud.secretmanager.v1.SecretManagerServiceClient)21 SecretVersionName (com.google.cloud.secretmanager.v1.SecretVersionName)13 SecretName (com.google.cloud.secretmanager.v1.SecretName)7 SecretPayload (com.google.cloud.secretmanager.v1.SecretPayload)7 Test (org.junit.Test)7 ByteString (com.google.protobuf.ByteString)6 AccessSecretVersionResponse (com.google.cloud.secretmanager.v1.AccessSecretVersionResponse)5 SecretVersion (com.google.cloud.secretmanager.v1beta1.SecretVersion)4 AccessSecretVersionRequest (com.google.cloud.secretmanager.v1.AccessSecretVersionRequest)2 AddSecretVersionRequest (com.google.cloud.secretmanager.v1.AddSecretVersionRequest)2 ListSecretVersionsRequest (com.google.cloud.secretmanager.v1.ListSecretVersionsRequest)2 ProjectName (com.google.cloud.secretmanager.v1.ProjectName)2 Secret (com.google.cloud.secretmanager.v1.Secret)2 ListSecretVersionsPagedResponse (com.google.cloud.secretmanager.v1.SecretManagerServiceClient.ListSecretVersionsPagedResponse)2 AbstractMessage (com.google.protobuf.AbstractMessage)2 ArrayList (java.util.ArrayList)2 DestroySecretVersionRequest (com.google.cloud.secretmanager.v1.DestroySecretVersionRequest)1 DisableSecretVersionRequest (com.google.cloud.secretmanager.v1.DisableSecretVersionRequest)1 EnableSecretVersionRequest (com.google.cloud.secretmanager.v1.EnableSecretVersionRequest)1