use of com.google.storage.v2.ProjectName in project java-docs-samples by GoogleCloudPlatform.
the class Snippets method createMetricDescriptor.
/**
* Creates a metric descriptor.
*
* <p>See:
* https://cloud.google.com/monitoring/api/ref_v3/rest/v3/projects.metricDescriptors/create
*
* @param type The metric type
*/
void createMetricDescriptor(String type) throws IOException {
// [START monitoring_create_metric]
// Your Google Cloud Platform project ID
String projectId = System.getProperty("projectId");
String metricType = CUSTOM_METRIC_DOMAIN + "/" + type;
final MetricServiceClient client = MetricServiceClient.create();
ProjectName name = ProjectName.of(projectId);
MetricDescriptor descriptor = MetricDescriptor.newBuilder().setType(metricType).addLabels(LabelDescriptor.newBuilder().setKey("store_id").setValueType(LabelDescriptor.ValueType.STRING)).setDescription("This is a simple example of a custom metric.").setMetricKind(MetricDescriptor.MetricKind.GAUGE).setValueType(MetricDescriptor.ValueType.DOUBLE).build();
CreateMetricDescriptorRequest request = CreateMetricDescriptorRequest.newBuilder().setName(name.toString()).setMetricDescriptor(descriptor).build();
client.createMetricDescriptor(request);
// [END monitoring_create_metric]
}
use of com.google.storage.v2.ProjectName in project java-docs-samples by GoogleCloudPlatform.
the class Snippets method listTimeSeriesAggregrate.
/**
* Demonstrates listing time series and aggregating them.
*/
void listTimeSeriesAggregrate() throws IOException {
// [START monitoring_read_timeseries_align]
MetricServiceClient metricServiceClient = MetricServiceClient.create();
String projectId = System.getProperty("projectId");
ProjectName name = ProjectName.of(projectId);
// Restrict time to last 20 minutes
long startMillis = System.currentTimeMillis() - ((60 * 20) * 1000);
TimeInterval interval = TimeInterval.newBuilder().setStartTime(Timestamps.fromMillis(startMillis)).setEndTime(Timestamps.fromMillis(System.currentTimeMillis())).build();
Aggregation aggregation = Aggregation.newBuilder().setAlignmentPeriod(Duration.newBuilder().setSeconds(600).build()).setPerSeriesAligner(Aggregation.Aligner.ALIGN_MEAN).build();
ListTimeSeriesRequest.Builder requestBuilder = ListTimeSeriesRequest.newBuilder().setName(name.toString()).setFilter("metric.type=\"compute.googleapis.com/instance/cpu/utilization\"").setInterval(interval).setAggregation(aggregation);
ListTimeSeriesRequest request = requestBuilder.build();
ListTimeSeriesPagedResponse response = metricServiceClient.listTimeSeries(request);
System.out.println("Got timeseries: ");
for (TimeSeries ts : response.iterateAll()) {
System.out.println(ts);
}
// [END monitoring_read_timeseries_align]
}
use of com.google.storage.v2.ProjectName in project java-webrisk by googleapis.
the class WebRiskServiceClientTest method createSubmissionTest.
@Test
public void createSubmissionTest() throws Exception {
Submission expectedResponse = Submission.newBuilder().setUri("uri116076").build();
mockWebRiskService.addResponse(expectedResponse);
ProjectName parent = ProjectName.of("[PROJECT]");
Submission submission = Submission.newBuilder().build();
Submission actualResponse = client.createSubmission(parent, submission);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockWebRiskService.getRequests();
Assert.assertEquals(1, actualRequests.size());
CreateSubmissionRequest actualRequest = ((CreateSubmissionRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertEquals(submission, actualRequest.getSubmission());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.storage.v2.ProjectName in project pomocua-ogloszenia by coi-gov-pl.
the class CaptchaValidator method validate.
public boolean validate(String recaptchaResponse) {
if (!properties.isEnabled()) {
log.debug("Skip captcha validation. To enable change 'app.captcha.enabled' property");
return true;
}
if (!responseSanityCheck(recaptchaResponse)) {
log.warn("Response contains invalid characters");
return false;
}
ProjectName projectName = ProjectName.of(properties.getGoogleCloudProjectId());
Event event = Event.newBuilder().setSiteKey(properties.getSiteKey()).setToken(recaptchaResponse).build();
CreateAssessmentRequest createAssessmentRequest = CreateAssessmentRequest.newBuilder().setParent(projectName.toString()).setAssessment(Assessment.newBuilder().setEvent(event).build()).build();
Assessment response = recaptchaClient.createAssessment(createAssessmentRequest);
if (response == null) {
log.warn("Empty response from reCaptcha");
return false;
}
// Check if the token is valid.
if (!response.getTokenProperties().getValid()) {
String invalidTokenReason = response.getTokenProperties().getInvalidReason().name();
log.debug("The CreateAssessment call failed because the token was: " + invalidTokenReason);
return false;
}
float score = response.getScore();
if (score < properties.getAcceptLevel()) {
List<String> reasons = response.getReasonsList().stream().map(classificationReason -> classificationReason.getDescriptorForType().getFullName()).collect(Collectors.toList());
log.debug("Validation failed. Score: " + score + ". Reasons: " + String.join(", ", reasons));
return false;
}
log.debug("Validation OK - score: " + score);
return true;
}
use of com.google.storage.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;
}
Aggregations