Search in sources :

Example 6 with SecretName

use of com.google.cloud.secretmanager.v1.SecretName in project java-docs-samples by GoogleCloudPlatform.

the class ListSecretVersions method listSecretVersions.

// List all secret versions for a secret.
public static void listSecretVersions(String projectId, String secretId) throws IOException {
    // the "close" method on the client to safely clean up any remaining background resources.
    try (SecretManagerServiceClient client = SecretManagerServiceClient.create()) {
        // Build the parent name.
        SecretName secretName = SecretName.of(projectId, secretId);
        // Get all versions.
        ListSecretVersionsPagedResponse pagedResponse = client.listSecretVersions(secretName);
        // List all versions and their state.
        pagedResponse.iterateAll().forEach(version -> {
            System.out.printf("Secret version %s, %s\n", version.getName(), version.getState());
        });
    }
}
Also used : SecretName(com.google.cloud.secretmanager.v1.SecretName) ListSecretVersionsPagedResponse(com.google.cloud.secretmanager.v1.SecretManagerServiceClient.ListSecretVersionsPagedResponse) SecretManagerServiceClient(com.google.cloud.secretmanager.v1.SecretManagerServiceClient)

Example 7 with SecretName

use of com.google.cloud.secretmanager.v1.SecretName in project java-docs-samples by GoogleCloudPlatform.

the class SnippetsIT method testIamGrantAccess.

@Test
public void testIamGrantAccess() throws IOException {
    SecretName name = SecretName.parse(TEST_SECRET.getName());
    IamGrantAccess.iamGrantAccess(name.getProject(), name.getSecret(), IAM_USER);
    assertThat(stdOut.toString()).contains("Updated IAM policy");
}
Also used : SecretName(com.google.cloud.secretmanager.v1.SecretName) Test(org.junit.Test)

Example 8 with SecretName

use of com.google.cloud.secretmanager.v1.SecretName in project java-docs-samples by GoogleCloudPlatform.

the class SnippetsIT method testCreateSecret.

@Test
public void testCreateSecret() throws IOException {
    SecretName name = TEST_SECRET_TO_CREATE_NAME;
    CreateSecret.createSecret(name.getProject(), name.getSecret());
    assertThat(stdOut.toString()).contains("Created secret");
}
Also used : SecretName(com.google.cloud.secretmanager.v1.SecretName) Test(org.junit.Test)

Example 9 with SecretName

use of com.google.cloud.secretmanager.v1.SecretName in project java-docs-samples by GoogleCloudPlatform.

the class SnippetsIT method testDeleteSecretWithEtag.

@Test
public void testDeleteSecretWithEtag() throws IOException {
    SecretName name = SecretName.parse(TEST_SECRET_TO_DELETE_WITH_ETAG.getName());
    String etag = TEST_SECRET_TO_DELETE_WITH_ETAG.getEtag();
    DeleteSecretWithEtag.deleteSecret(name.getProject(), name.getSecret(), etag);
    assertThat(stdOut.toString()).contains("Deleted secret");
}
Also used : SecretName(com.google.cloud.secretmanager.v1.SecretName) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 10 with SecretName

use of com.google.cloud.secretmanager.v1.SecretName in project java-docs-samples by GoogleCloudPlatform.

the class SnippetsIT method testIamRevokeAccess.

@Test
public void testIamRevokeAccess() throws IOException {
    SecretName name = SecretName.parse(TEST_SECRET.getName());
    IamRevokeAccess.iamRevokeAccess(name.getProject(), name.getSecret(), IAM_USER);
    assertThat(stdOut.toString()).contains("Updated IAM policy");
}
Also used : SecretName(com.google.cloud.secretmanager.v1.SecretName) Test(org.junit.Test)

Aggregations

SecretName (com.google.cloud.secretmanager.v1.SecretName)52 SecretManagerServiceClient (com.google.cloud.secretmanager.v1.SecretManagerServiceClient)23 Test (org.junit.Test)22 DeleteSecretRequest (com.google.cloud.secretmanager.v1.DeleteSecretRequest)8 Secret (com.google.cloud.secretmanager.v1.Secret)5 SecretVersion (com.google.cloud.secretmanager.v1.SecretVersion)5 AddSecretVersionRequest (com.google.cloud.secretmanager.v1.AddSecretVersionRequest)4 ListSecretVersionsPagedResponse (com.google.cloud.secretmanager.v1.SecretManagerServiceClient.ListSecretVersionsPagedResponse)4 SecretPayload (com.google.cloud.secretmanager.v1.SecretPayload)4 Binding (com.google.iam.v1.Binding)4 Policy (com.google.iam.v1.Policy)4 FieldMask (com.google.protobuf.FieldMask)3 AfterClass (org.junit.AfterClass)3 ListSecretVersionsRequest (com.google.cloud.secretmanager.v1.ListSecretVersionsRequest)2 AccessSecretVersionResponse (com.google.cloud.secretmanager.v1.AccessSecretVersionResponse)1 SecretVersionName (com.google.cloud.secretmanager.v1.SecretVersionName)1 AbstractMessage (com.google.protobuf.AbstractMessage)1 ByteString (com.google.protobuf.ByteString)1 EventListener (io.micronaut.runtime.event.annotation.EventListener)1 ArrayList (java.util.ArrayList)1