use of com.google.bigtable.admin.v2.ProjectName in project java-logging by googleapis.
the class MetricsClientTest method listLogMetricsTest.
@Test
public void listLogMetricsTest() throws Exception {
LogMetric responsesElement = LogMetric.newBuilder().build();
ListLogMetricsResponse expectedResponse = ListLogMetricsResponse.newBuilder().setNextPageToken("").addAllMetrics(Arrays.asList(responsesElement)).build();
mockMetricsServiceV2.addResponse(expectedResponse);
ProjectName parent = ProjectName.of("[PROJECT]");
ListLogMetricsPagedResponse pagedListResponse = client.listLogMetrics(parent);
List<LogMetric> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getMetricsList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockMetricsServiceV2.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListLogMetricsRequest actualRequest = ((ListLogMetricsRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.bigtable.admin.v2.ProjectName in project java-secretmanager by googleapis.
the class NativeImageSecretManagerSample method createSecret.
static void createSecret(SecretManagerServiceClient client, String projectId, String secretId) {
Secret secret = Secret.newBuilder().setReplication(Replication.newBuilder().setAutomatic(Replication.Automatic.newBuilder().build()).build()).build();
ProjectName projectName = ProjectName.of(projectId);
Secret createdSecret = client.createSecret(projectName, secretId, secret);
System.out.println("Created secret: " + createdSecret.getName());
}
use of com.google.bigtable.admin.v2.ProjectName in project java-secretmanager by googleapis.
the class NativeImageSecretManagerSample 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;
}
use of com.google.bigtable.admin.v2.ProjectName in project java-secretmanager by googleapis.
the class CreateSecret method createSecret.
// Add a new version to the existing secret.
public 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.bigtable.admin.v2.ProjectName in project java-secretmanager by googleapis.
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);
}
}
Aggregations