Search in sources :

Example 1 with Secret

use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Secret in project spring-cloud-gcp by spring-cloud.

the class SecretManagerTemplate method createSecretInternal.

/**
 * Creates a new secret for the GCP Project.
 *
 * <p>
 * Note that the {@link Secret} object does not contain the secret payload. You must
 * create versions of the secret which stores the payload of the secret.
 */
private void createSecretInternal(String secretId, String projectId) {
    ProjectName projectName = ProjectName.of(projectId);
    Secret secret = Secret.newBuilder().setReplication(Replication.newBuilder().setAutomatic(Replication.Automatic.getDefaultInstance())).build();
    CreateSecretRequest request = CreateSecretRequest.newBuilder().setParent(projectName.toString()).setSecretId(secretId).setSecret(secret).build();
    this.secretManagerServiceClient.createSecret(request);
}
Also used : Secret(com.google.cloud.secretmanager.v1.Secret) ProjectName(com.google.cloud.secretmanager.v1.ProjectName) CreateSecretRequest(com.google.cloud.secretmanager.v1.CreateSecretRequest)

Example 2 with Secret

use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Secret in project spring-cloud-config by spring-cloud.

the class GoogleSecretManagerEnvironmentRepositoryTests method testGetSecrets.

@Test
@SuppressWarnings("unchecked")
public void testGetSecrets() throws IOException {
    RestTemplate rest = mock(RestTemplate.class);
    GoogleConfigProvider provider = mock(HttpHeaderGoogleConfigProvider.class);
    when(provider.getValue(HttpHeaderGoogleConfigProvider.PROJECT_ID_HEADER, true)).thenReturn("test-project");
    SecretManagerServiceClient mock = mock(SecretManagerServiceClient.class);
    SecretManagerServiceClient.ListSecretsPagedResponse response = mock(SecretManagerServiceClient.ListSecretsPagedResponse.class);
    Secret secret = Secret.newBuilder().setName("projects/test-project/secrets/test").build();
    List<Secret> secrets = new ArrayList<Secret>();
    secrets.add(secret);
    when(response.iterateAll()).thenReturn(secrets);
    Mockito.doReturn(response).when(mock).listSecrets(any(ListSecretsRequest.class));
    GoogleSecretManagerV1AccessStrategy strategy = new GoogleSecretManagerV1AccessStrategy(rest, provider, mock);
    assertThat(strategy.getSecrets().size()).isEqualTo(1);
}
Also used : Secret(com.google.cloud.secretmanager.v1.Secret) HttpHeaderGoogleConfigProvider(org.springframework.cloud.config.server.environment.secretmanager.HttpHeaderGoogleConfigProvider) GoogleConfigProvider(org.springframework.cloud.config.server.environment.secretmanager.GoogleConfigProvider) ListSecretsRequest(com.google.cloud.secretmanager.v1.ListSecretsRequest) RestTemplate(org.springframework.web.client.RestTemplate) ArrayList(java.util.ArrayList) SecretManagerServiceClient(com.google.cloud.secretmanager.v1.SecretManagerServiceClient) GoogleSecretManagerV1AccessStrategy(org.springframework.cloud.config.server.environment.secretmanager.GoogleSecretManagerV1AccessStrategy) Test(org.junit.Test)

Example 3 with Secret

use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Secret in project spring-cloud-config by spring-cloud.

the class GoogleSecretManagerV1AccessStrategy method getSecrets.

@Override
public List<Secret> getSecrets() {
    // Build the parent name.
    ProjectName project = ProjectName.of(getProjectId());
    // Create the request.
    ListSecretsRequest listSecretRequest = ListSecretsRequest.newBuilder().setParent(project.toString()).build();
    // Get all secrets.
    SecretManagerServiceClient.ListSecretsPagedResponse pagedListSecretResponse = client.listSecrets(listSecretRequest);
    List<Secret> result = new ArrayList<Secret>();
    pagedListSecretResponse.iterateAll().forEach(result::add);
    // List all secrets.
    return result;
}
Also used : Secret(com.google.cloud.secretmanager.v1.Secret) ProjectName(com.google.cloud.secretmanager.v1.ProjectName) ListSecretsRequest(com.google.cloud.secretmanager.v1.ListSecretsRequest) ArrayList(java.util.ArrayList) SecretManagerServiceClient(com.google.cloud.secretmanager.v1.SecretManagerServiceClient)

Example 4 with Secret

use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Secret in project java-docs-samples by GoogleCloudPlatform.

the class Quickstart method quickstart.

public void quickstart(String projectId, String secretId) throws Exception {
    // the "close" method on the client to safely clean up any remaining background resources.
    try (SecretManagerServiceClient client = SecretManagerServiceClient.create()) {
        // Build the parent name from the project.
        ProjectName projectName = ProjectName.of(projectId);
        // Create the parent secret.
        Secret secret = Secret.newBuilder().setReplication(Replication.newBuilder().setAutomatic(Replication.Automatic.newBuilder().build()).build()).build();
        Secret createdSecret = client.createSecret(projectName, secretId, secret);
        // Add a secret version.
        SecretPayload payload = SecretPayload.newBuilder().setData(ByteString.copyFromUtf8("hello world!")).build();
        SecretVersion addedVersion = client.addSecretVersion(createdSecret.getName(), payload);
        // Access the secret version.
        AccessSecretVersionResponse response = client.accessSecretVersion(addedVersion.getName());
        // Print the secret payload.
        // 
        // WARNING: Do not print the secret in a production environment - this
        // snippet is showing how to access the secret material.
        String data = response.getPayload().getData().toStringUtf8();
        System.out.printf("Plaintext: %s\n", data);
    }
}
Also used : Secret(com.google.cloud.secretmanager.v1.Secret) SecretVersion(com.google.cloud.secretmanager.v1.SecretVersion) ProjectName(com.google.cloud.secretmanager.v1.ProjectName) SecretManagerServiceClient(com.google.cloud.secretmanager.v1.SecretManagerServiceClient) ByteString(com.google.protobuf.ByteString) AccessSecretVersionResponse(com.google.cloud.secretmanager.v1.AccessSecretVersionResponse) SecretPayload(com.google.cloud.secretmanager.v1.SecretPayload)

Example 5 with Secret

use of com.marcnuri.yakc.model.io.k8s.api.core.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)

Aggregations

Secret (com.google.cloud.secretmanager.v1.Secret)21 ProjectName (com.google.cloud.secretmanager.v1.ProjectName)11 SecretManagerServiceClient (com.google.cloud.secretmanager.v1.SecretManagerServiceClient)11 SecretName (com.google.cloud.secretmanager.v1.SecretName)5 CreateSecretRequest (com.google.cloud.secretmanager.v1.CreateSecretRequest)4 ByteString (com.google.protobuf.ByteString)4 Secret (com.google.cloud.secretmanager.v1beta1.Secret)3 FieldMask (com.google.protobuf.FieldMask)3 Secret (com.marcnuri.yakc.model.io.k8s.api.core.v1.Secret)3 Test (org.junit.Test)3 Test (org.junit.jupiter.api.Test)3 AccessSecretVersionResponse (com.google.cloud.secretmanager.v1.AccessSecretVersionResponse)2 ListSecretsRequest (com.google.cloud.secretmanager.v1.ListSecretsRequest)2 ListSecretsPagedResponse (com.google.cloud.secretmanager.v1.SecretManagerServiceClient.ListSecretsPagedResponse)2 SecretPayload (com.google.cloud.secretmanager.v1.SecretPayload)2 SecretVersion (com.google.cloud.secretmanager.v1.SecretVersion)2 Configuration (com.marcnuri.yakc.config.Configuration)2 Node (com.marcnuri.yakc.model.io.k8s.api.core.v1.Node)2 ArrayList (java.util.ArrayList)2 AddSecretVersionRequest (com.google.cloud.secretmanager.v1beta1.AddSecretVersionRequest)1