Search in sources :

Example 36 with SecretName

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

the class SnippetsIT method testListSecretsWithFilter.

@Test
public void testListSecretsWithFilter() throws IOException {
    SecretName name = SecretName.parse(TEST_SECRET.getName());
    ListSecretsWithFilter.listSecrets(name.getProject(), String.format("name:%s", name.getSecret()));
    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 37 with SecretName

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

the class SnippetsIT method testGetSecret.

@Test
public void testGetSecret() throws IOException {
    SecretName name = SecretName.parse(TEST_SECRET.getName());
    GetSecret.getSecret(name.getProject(), name.getSecret());
    assertThat(stdOut.toString()).contains("Secret");
    assertThat(stdOut.toString()).contains("replication AUTOMATIC");
}
Also used : SecretName(com.google.cloud.secretmanager.v1.SecretName) Test(org.junit.Test)

Example 38 with SecretName

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

the class SnippetsIT method addSecretVersion.

private static SecretVersion addSecretVersion(Secret secret) throws IOException {
    SecretName parent = SecretName.parse(secret.getName());
    AddSecretVersionRequest request = AddSecretVersionRequest.newBuilder().setParent(parent.toString()).setPayload(SecretPayload.newBuilder().setData(ByteString.copyFromUtf8("my super secret data")).build()).build();
    try (SecretManagerServiceClient client = SecretManagerServiceClient.create()) {
        return client.addSecretVersion(request);
    }
}
Also used : SecretName(com.google.cloud.secretmanager.v1.SecretName) AddSecretVersionRequest(com.google.cloud.secretmanager.v1.AddSecretVersionRequest) SecretManagerServiceClient(com.google.cloud.secretmanager.v1.SecretManagerServiceClient)

Example 39 with SecretName

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

the class SnippetsIT method testDeleteSecret.

@Test
public void testDeleteSecret() throws IOException {
    SecretName name = SecretName.parse(TEST_SECRET_TO_DELETE.getName());
    DeleteSecret.deleteSecret(name.getProject(), name.getSecret());
    assertThat(stdOut.toString()).contains("Deleted secret");
}
Also used : SecretName(com.google.cloud.secretmanager.v1.SecretName) Test(org.junit.Test)

Example 40 with SecretName

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

the class DeleteSecret method deleteSecret.

// Delete an existing secret with the given name.
public static void deleteSecret(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 secret name.
        SecretName secretName = SecretName.of(projectId, secretId);
        // Delete the secret.
        client.deleteSecret(secretName);
        System.out.printf("Deleted secret %s\n", secretId);
    }
}
Also used : SecretName(com.google.cloud.secretmanager.v1.SecretName) SecretManagerServiceClient(com.google.cloud.secretmanager.v1.SecretManagerServiceClient)

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