Search in sources :

Example 56 with Secret

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

the class SecretManagerClientImpl method createSecret.

@Override
public void createSecret(String secretId) {
    checkNotNull(secretId, "secretId");
    Secret secretSettings = Secret.newBuilder().setReplication(defaultReplicationPolicy()).build();
    callSecretManager(() -> csmClient.createSecret(ProjectName.of(project), secretId, secretSettings));
}
Also used : Secret(com.google.cloud.secretmanager.v1.Secret)

Example 57 with Secret

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

the class SecretManagerPropertyUtilsTests method testShortProperty_secretId.

@Test
void testShortProperty_secretId() {
    String property = "sm://the-secret";
    SecretVersionName secretIdentifier = SecretManagerPropertyUtils.getSecretVersionName(property, DEFAULT_PROJECT_ID_PROVIDER);
    assertThat(secretIdentifier.getProject()).isEqualTo("defaultProject");
    assertThat(secretIdentifier.getSecret()).isEqualTo("the-secret");
    assertThat(secretIdentifier.getSecretVersion()).isEqualTo("latest");
}
Also used : SecretVersionName(com.google.cloud.secretmanager.v1.SecretVersionName) Test(org.junit.jupiter.api.Test)

Example 58 with Secret

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

the class SecretManagerTemplate method createNewSecretVersion.

/**
 * Create a new version of the secret with the specified payload under a {@link Secret}. Will also
 * create the parent secret if it does not already exist.
 */
private void createNewSecretVersion(String secretId, ByteString payload, String projectId) {
    if (!secretExists(secretId, projectId)) {
        createSecretInternal(secretId, projectId);
    }
    SecretName name = SecretName.of(projectId, secretId);
    AddSecretVersionRequest payloadRequest = AddSecretVersionRequest.newBuilder().setParent(name.toString()).setPayload(SecretPayload.newBuilder().setData(payload)).build();
    secretManagerServiceClient.addSecretVersion(payloadRequest);
}
Also used : SecretName(com.google.cloud.secretmanager.v1.SecretName) AddSecretVersionRequest(com.google.cloud.secretmanager.v1.AddSecretVersionRequest)

Example 59 with Secret

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

the class SecretManagerPropertyUtilsTests method testLongProperty_projectSecretVersion.

@Test
void testLongProperty_projectSecretVersion() {
    String property = "sm://projects/my-project/secrets/the-secret/versions/3";
    SecretVersionName secretIdentifier = SecretManagerPropertyUtils.getSecretVersionName(property, DEFAULT_PROJECT_ID_PROVIDER);
    assertThat(secretIdentifier.getProject()).isEqualTo("my-project");
    assertThat(secretIdentifier.getSecret()).isEqualTo("the-secret");
    assertThat(secretIdentifier.getSecretVersion()).isEqualTo("3");
}
Also used : SecretVersionName(com.google.cloud.secretmanager.v1.SecretVersionName) Test(org.junit.jupiter.api.Test)

Example 60 with Secret

use of com.google.cloud.secretmanager.v1.Secret in project native-image-support-java by GoogleCloudPlatform.

the class SecretManagerSampleApplication method hasSecret.

static boolean hasSecret(SecretManagerServiceClient client, String projectId, String secretId) {
    ProjectName projectName = ProjectName.of(projectId);
    ListSecretsPagedResponse pagedResponse = client.listSecrets(projectName);
    for (Secret secret : pagedResponse.iterateAll()) {
        String otherSecretId = extractSecretId(secret);
        if (secretId.equals(otherSecretId)) {
            return true;
        }
    }
    return false;
}
Also used : Secret(com.google.cloud.secretmanager.v1.Secret) ProjectName(com.google.cloud.secretmanager.v1.ProjectName) ListSecretsPagedResponse(com.google.cloud.secretmanager.v1.SecretManagerServiceClient.ListSecretsPagedResponse) ByteString(com.google.protobuf.ByteString)

Aggregations

SecretManagerServiceClient (com.google.cloud.secretmanager.v1.SecretManagerServiceClient)52 SecretVersionName (com.google.cloud.secretmanager.v1.SecretVersionName)45 SecretName (com.google.cloud.secretmanager.v1.SecretName)44 Test (org.junit.Test)42 SecretVersion (com.google.cloud.secretmanager.v1.SecretVersion)22 Secret (com.google.cloud.secretmanager.v1.Secret)21 ProjectName (com.google.cloud.secretmanager.v1.ProjectName)16 ByteString (com.google.protobuf.ByteString)13 Test (org.junit.jupiter.api.Test)13 AccessSecretVersionResponse (com.google.cloud.secretmanager.v1.AccessSecretVersionResponse)10 ListSecretsPagedResponse (com.google.cloud.secretmanager.v1.SecretManagerServiceClient.ListSecretsPagedResponse)7 CreateSecretRequest (com.google.cloud.secretmanager.v1.CreateSecretRequest)6 SecretPayload (com.google.cloud.secretmanager.v1.SecretPayload)6 AddSecretVersionRequest (com.google.cloud.secretmanager.v1.AddSecretVersionRequest)4 DeleteSecretRequest (com.google.cloud.secretmanager.v1.DeleteSecretRequest)4 ListSecretVersionsPagedResponse (com.google.cloud.secretmanager.v1.SecretManagerServiceClient.ListSecretVersionsPagedResponse)4 Binding (com.google.iam.v1.Binding)4 Policy (com.google.iam.v1.Policy)4 ListSecretsRequest (com.google.cloud.secretmanager.v1.ListSecretsRequest)3 Secret (com.google.cloud.secretmanager.v1beta1.Secret)3