use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Secret in project spring-cloud-gcp by spring-cloud.
the class SecretManagerTemplateTests method verifyCreateSecretRequest.
private void verifyCreateSecretRequest(String secretId, String projectId) {
Secret secretToAdd = Secret.newBuilder().setReplication(Replication.newBuilder().setAutomatic(Replication.Automatic.newBuilder()).build()).build();
CreateSecretRequest createSecretRequest = CreateSecretRequest.newBuilder().setParent("projects/" + projectId).setSecretId(secretId).setSecret(secretToAdd).build();
verify(this.client).createSecret(createSecretRequest);
}
use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Secret in project java-docs-samples by GoogleCloudPlatform.
the class UpdateSecret method updateSecret.
// Update an existing secret.
public static void updateSecret(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 name.
SecretName secretName = SecretName.of(projectId, secretId);
// Build the updated secret.
Secret secret = Secret.newBuilder().setName(secretName.toString()).putLabels("secretmanager", "rocks").build();
// Build the field mask.
FieldMask fieldMask = FieldMaskUtil.fromString("labels");
// Update the secret.
Secret updatedSecret = client.updateSecret(secret, fieldMask);
System.out.printf("Updated secret %s\n", updatedSecret.getName());
}
}
use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Secret in project java-docs-samples by GoogleCloudPlatform.
the class UpdateSecretWithEtag method updateSecret.
// Update an existing secret.
public static void updateSecret(String projectId, String secretId, String etag) throws IOException {
// the "close" method on the client to safely clean up any remaining background resources.
try (SecretManagerServiceClient client = SecretManagerServiceClient.create()) {
// Build the name.
SecretName secretName = SecretName.of(projectId, secretId);
// Build the updated secret.
Secret secret = Secret.newBuilder().setName(secretName.toString()).setEtag(etag).putLabels("secretmanager", "rocks").build();
// Build the field mask.
FieldMask fieldMask = FieldMaskUtil.fromString("labels");
// Update the secret.
Secret updatedSecret = client.updateSecret(secret, fieldMask);
System.out.printf("Updated secret %s\n", updatedSecret.getName());
}
}
use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Secret in project java-docs-samples by GoogleCloudPlatform.
the class CreateSecret method createSecret.
// Add a new version to the existing secret.
public static void createSecret(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 parent name from the project.
ProjectName projectName = ProjectName.of(projectId);
// Build the secret to create.
Secret secret = Secret.newBuilder().setReplication(Replication.newBuilder().setAutomatic(Replication.Automatic.newBuilder().build()).build()).build();
// Create the secret.
Secret createdSecret = client.createSecret(projectName, secretId, secret);
System.out.printf("Created secret %s\n", createdSecret.getName());
}
}
use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Secret in project java-docs-samples by GoogleCloudPlatform.
the class GetSecret method getSecret.
// Get an existing secret.
public static void getSecret(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 name.
SecretName secretName = SecretName.of(projectId, secretId);
// Create the secret.
Secret secret = client.getSecret(secretName);
// Get the replication policy.
String replication = "";
if (secret.getReplication().getAutomatic() != null) {
replication = "AUTOMATIC";
} else if (secret.getReplication().getUserManaged() != null) {
replication = "MANAGED";
} else {
throw new IllegalStateException("Unknown replication type");
}
System.out.printf("Secret %s, replication %s\n", secret.getName(), replication);
}
}
Aggregations