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);
}
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);
}
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;
}
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);
}
}
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));
}
Aggregations