Search in sources :

Example 31 with SecretName

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

the class UpdateSecretWithEtag method updateSecret.

// Update an existing secret.
public static void updateSecret(String projectId, String secretId, String etag) throws IOException {
    // the "close" method on the client to safely clean up any remaining background resources.
    try (SecretManagerServiceClient client = SecretManagerServiceClient.create()) {
        // Build the name.
        SecretName secretName = SecretName.of(projectId, secretId);
        // Build the updated secret.
        Secret secret = Secret.newBuilder().setName(secretName.toString()).setEtag(etag).putLabels("secretmanager", "rocks").build();
        // Build the field mask.
        FieldMask fieldMask = FieldMaskUtil.fromString("labels");
        // Update the secret.
        Secret updatedSecret = client.updateSecret(secret, fieldMask);
        System.out.printf("Updated secret %s\n", updatedSecret.getName());
    }
}
Also used : SecretName(com.google.cloud.secretmanager.v1.SecretName) Secret(com.google.cloud.secretmanager.v1.Secret) SecretManagerServiceClient(com.google.cloud.secretmanager.v1.SecretManagerServiceClient) FieldMask(com.google.protobuf.FieldMask)

Example 32 with SecretName

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

the class SnippetsIT method testListSecrets.

@Test
public void testListSecrets() throws IOException {
    SecretName name = SecretName.parse(TEST_SECRET.getName());
    ListSecrets.listSecrets(name.getProject());
    assertThat(stdOut.toString()).contains("Secret projects/");
    assertThat(stdOut.toString()).contains(name.getSecret());
}
Also used : SecretName(com.google.cloud.secretmanager.v1.SecretName) Test(org.junit.Test)

Example 33 with SecretName

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

the class SnippetsIT method testListSecretVersionsWithFilter.

@Test
public void testListSecretVersionsWithFilter() throws IOException {
    SecretName name = SecretName.parse(TEST_SECRET_WITH_VERSIONS.getName());
    ListSecretVersionsWithFilter.listSecretVersions(name.getProject(), name.getSecret(), "name:1");
    assertThat(stdOut.toString()).contains("Secret version");
}
Also used : SecretName(com.google.cloud.secretmanager.v1.SecretName) Test(org.junit.Test)

Example 34 with SecretName

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

the class SnippetsIT method testListSecretVersions.

@Test
public void testListSecretVersions() throws IOException {
    SecretName name = SecretName.parse(TEST_SECRET_WITH_VERSIONS.getName());
    ListSecretVersions.listSecretVersions(name.getProject(), name.getSecret());
    assertThat(stdOut.toString()).contains("Secret version");
}
Also used : SecretName(com.google.cloud.secretmanager.v1.SecretName) Test(org.junit.Test)

Example 35 with SecretName

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

the class SnippetsIT method testUpdateSecret.

@Test
public void testUpdateSecret() throws IOException {
    SecretName name = SecretName.parse(TEST_SECRET.getName());
    UpdateSecret.updateSecret(name.getProject(), name.getSecret());
    assertThat(stdOut.toString()).contains("Updated secret");
}
Also used : SecretName(com.google.cloud.secretmanager.v1.SecretName) Test(org.junit.Test)

Aggregations

SecretName (com.google.cloud.secretmanager.v1.SecretName)53 SecretManagerServiceClient (com.google.cloud.secretmanager.v1.SecretManagerServiceClient)23 Test (org.junit.Test)22 DeleteSecretRequest (com.google.cloud.secretmanager.v1.DeleteSecretRequest)8 SecretVersion (com.google.cloud.secretmanager.v1.SecretVersion)6 Secret (com.google.cloud.secretmanager.v1.Secret)5 SecretPayload (com.google.cloud.secretmanager.v1.SecretPayload)5 AddSecretVersionRequest (com.google.cloud.secretmanager.v1.AddSecretVersionRequest)4 ListSecretVersionsPagedResponse (com.google.cloud.secretmanager.v1.SecretManagerServiceClient.ListSecretVersionsPagedResponse)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