Search in sources :

Example 1 with SecretName

use of com.google.cloud.secretmanager.v1.SecretName in project spring-cloud-gcp by spring-cloud.

the class SecretManagerTemplate method deleteSecret.

@Override
public void deleteSecret(String secretId, String projectId) {
    SecretName name = SecretName.of(projectId, secretId);
    DeleteSecretRequest request = DeleteSecretRequest.newBuilder().setName(name.toString()).build();
    this.secretManagerServiceClient.deleteSecret(request);
}
Also used : SecretName(com.google.cloud.secretmanager.v1.SecretName) DeleteSecretRequest(com.google.cloud.secretmanager.v1.DeleteSecretRequest)

Example 2 with SecretName

use of com.google.cloud.secretmanager.v1.SecretName in project spring-cloud-gcp by spring-cloud.

the class SecretManagerTemplateTests method verifyDeleteSecretRequest.

private void verifyDeleteSecretRequest(String secretId, String projectId) {
    SecretName name = SecretName.of(projectId, secretId);
    DeleteSecretRequest request = DeleteSecretRequest.newBuilder().setName(name.toString()).build();
    verify(this.client).deleteSecret(request);
}
Also used : SecretName(com.google.cloud.secretmanager.v1.SecretName) DeleteSecretRequest(com.google.cloud.secretmanager.v1.DeleteSecretRequest)

Example 3 with SecretName

use of com.google.cloud.secretmanager.v1.SecretName in project spring-cloud-config by spring-cloud.

the class GoogleSecretManagerV1AccessStrategy method getSecretVersions.

private List<SecretVersion> getSecretVersions(Secret secret) {
    SecretName parent = SecretName.parse(secret.getName());
    // Create the request.
    ListSecretVersionsRequest listVersionRequest = ListSecretVersionsRequest.newBuilder().setParent(parent.toString()).build();
    // Get all versions.
    SecretManagerServiceClient.ListSecretVersionsPagedResponse pagedListVersionResponse = client.listSecretVersions(listVersionRequest);
    List<SecretVersion> result = new ArrayList<SecretVersion>();
    pagedListVersionResponse.iterateAll().forEach(result::add);
    return result;
}
Also used : SecretName(com.google.cloud.secretmanager.v1.SecretName) SecretVersion(com.google.cloud.secretmanager.v1.SecretVersion) ArrayList(java.util.ArrayList) SecretManagerServiceClient(com.google.cloud.secretmanager.v1.SecretManagerServiceClient) ListSecretVersionsRequest(com.google.cloud.secretmanager.v1.ListSecretVersionsRequest)

Example 4 with SecretName

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

the class QuickstartIT method afterAll.

@AfterClass
public static void afterAll() throws Exception {
    Assert.assertFalse("missing GOOGLE_CLOUD_PROJECT", Strings.isNullOrEmpty(PROJECT_ID));
    try (SecretManagerServiceClient client = SecretManagerServiceClient.create()) {
        // Delete the secret created by quickstart
        SecretName name = SecretName.of(PROJECT_ID, SECRET_ID);
        DeleteSecretRequest deleteRequest = DeleteSecretRequest.newBuilder().setName(name.toString()).build();
        client.deleteSecret(deleteRequest);
    }
}
Also used : SecretName(com.google.cloud.secretmanager.v1.SecretName) SecretManagerServiceClient(com.google.cloud.secretmanager.v1.SecretManagerServiceClient) DeleteSecretRequest(com.google.cloud.secretmanager.v1.DeleteSecretRequest) AfterClass(org.junit.AfterClass)

Example 5 with SecretName

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

the class AddSecretVersion method addSecretVersion.

// Add a new version to the existing secret.
public static void addSecretVersion(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()) {
        SecretName secretName = SecretName.of(projectId, secretId);
        // Create the secret payload.
        SecretPayload payload = SecretPayload.newBuilder().setData(ByteString.copyFromUtf8("my super secret data")).build();
        // Add the secret version.
        SecretVersion version = client.addSecretVersion(secretName, payload);
        System.out.printf("Added secret version %s\n", version.getName());
    }
}
Also used : SecretName(com.google.cloud.secretmanager.v1.SecretName) SecretVersion(com.google.cloud.secretmanager.v1.SecretVersion) SecretManagerServiceClient(com.google.cloud.secretmanager.v1.SecretManagerServiceClient) SecretPayload(com.google.cloud.secretmanager.v1.SecretPayload)

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