use of com.google.logging.v2.ProjectName in project java-docs-samples by GoogleCloudPlatform.
the class ListSecretsWithFilter method listSecrets.
// List all secrets for a project
public static void listSecrets(String projectId, String filter) 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.
ProjectName projectName = ProjectName.of(projectId);
// Get filtered secrets.
ListSecretsRequest request = ListSecretsRequest.newBuilder().setParent(projectName.toString()).setFilter(filter).build();
ListSecretsPagedResponse pagedResponse = client.listSecrets(request);
// List all secrets.
pagedResponse.iterateAll().forEach(secret -> {
System.out.printf("Secret %s\n", secret.getName());
});
}
}
use of com.google.logging.v2.ProjectName in project java-docs-samples by GoogleCloudPlatform.
the class SnippetsIT method createSecret.
private static Secret createSecret() throws IOException {
ProjectName parent = ProjectName.of(PROJECT_ID);
CreateSecretRequest request = CreateSecretRequest.newBuilder().setParent(parent.toString()).setSecretId(randomSecretId()).setSecret(Secret.newBuilder().setReplication(Replication.newBuilder().setAutomatic(Replication.Automatic.newBuilder().build()).build()).build()).build();
try (SecretManagerServiceClient client = SecretManagerServiceClient.create()) {
return client.createSecret(request);
}
}
use of com.google.logging.v2.ProjectName 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.google.logging.v2.ProjectName in project java-bigquerydatatransfer by googleapis.
the class RunNotification method runNotification.
public static void runNotification(String projectId, TransferConfig transferConfig) throws IOException {
try (DataTransferServiceClient dataTransferServiceClient = DataTransferServiceClient.create()) {
ProjectName parent = ProjectName.of(projectId);
CreateTransferConfigRequest request = CreateTransferConfigRequest.newBuilder().setParent(parent.toString()).setTransferConfig(transferConfig).build();
TransferConfig config = dataTransferServiceClient.createTransferConfig(request);
System.out.println("\nScheduled query with run notification created successfully :" + config.getName());
} catch (ApiException ex) {
System.out.print("\nScheduled query with run notification was not created." + ex.toString());
}
}
use of com.google.logging.v2.ProjectName in project java-webrisk by googleapis.
the class WebRiskServiceClientTest method createSubmissionExceptionTest.
@Test
public void createSubmissionExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockWebRiskService.addException(exception);
try {
ProjectName parent = ProjectName.of("[PROJECT]");
Submission submission = Submission.newBuilder().build();
client.createSubmission(parent, submission);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception.
}
}
Aggregations