Skip to content

Commit

Permalink
support AAD authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
weidongxu-microsoft committed Mar 14, 2022
1 parent 56a2f1b commit d30773a
Show file tree
Hide file tree
Showing 49 changed files with 263 additions and 49 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.

package com.azure.ai.metricsadvisor;

import com.azure.ai.metricsadvisor.implementation.MetricsAdvisorClientImpl;
Expand All @@ -22,6 +21,7 @@
/** Initializes a new instance of the asynchronous MetricsAdvisorClient type. */
@ServiceClient(builder = MetricsAdvisorClientBuilder.class, isAsync = true)
public final class MetricsAdvisorAsyncClient {

@Generated private final MetricsAdvisorClientImpl serviceClient;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.

package com.azure.ai.metricsadvisor;

import com.azure.core.annotation.Generated;
Expand All @@ -20,6 +19,7 @@
/** Initializes a new instance of the synchronous MetricsAdvisorClient type. */
@ServiceClient(builder = MetricsAdvisorClientBuilder.class)
public final class MetricsAdvisorClient {

@Generated private final MetricsAdvisorAsyncClient asyncClient;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.

package com.azure.ai.metricsadvisor;

import com.azure.ai.metricsadvisor.implementation.MetricsAdvisorClientImpl;
import com.azure.core.annotation.Generated;
import com.azure.core.annotation.ServiceClientBuilder;
import com.azure.core.credential.TokenCredential;
import com.azure.core.http.HttpClient;
import com.azure.core.http.HttpHeaders;
import com.azure.core.http.HttpPipeline;
import com.azure.core.http.HttpPipelineBuilder;
import com.azure.core.http.HttpPipelinePosition;
import com.azure.core.http.policy.AddHeadersPolicy;
import com.azure.core.http.policy.BearerTokenAuthenticationPolicy;
import com.azure.core.http.policy.CookiePolicy;
import com.azure.core.http.policy.HttpLogOptions;
import com.azure.core.http.policy.HttpLoggingPolicy;
Expand All @@ -32,6 +33,7 @@
/** A builder for creating a new instance of the MetricsAdvisorClient type. */
@ServiceClientBuilder(serviceClients = {MetricsAdvisorClient.class, MetricsAdvisorAsyncClient.class})
public final class MetricsAdvisorClientBuilder {

@Generated private static final String SDK_NAME = "name";

@Generated private static final String SDK_VERSION = "version";
Expand Down Expand Up @@ -228,6 +230,9 @@ private HttpPipeline createHttpPipeline() {
HttpPolicyProviders.addBeforeRetryPolicies(policies);
policies.add(retryPolicy == null ? new RetryPolicy() : retryPolicy);
policies.add(new CookiePolicy());
if (tokenCredential != null) {
policies.add(new BearerTokenAuthenticationPolicy(tokenCredential, DEFAULT_SCOPES));
}
policies.addAll(
this.pipelinePolicies.stream()
.filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_RETRY)
Expand Down Expand Up @@ -262,4 +267,24 @@ public MetricsAdvisorAsyncClient buildAsyncClient() {
public MetricsAdvisorClient buildClient() {
return new MetricsAdvisorClient(new MetricsAdvisorAsyncClient(buildInnerClient()));
}

@Generated
private static final String[] DEFAULT_SCOPES = new String[] {"https://cognitiveservices.azure.com/.default"};

/*
* The TokenCredential used for authentication.
*/
@Generated private TokenCredential tokenCredential;

/**
* Sets The TokenCredential used for authentication.
*
* @param tokenCredential the tokenCredential value.
* @return the MetricsAdvisorClientBuilder.
*/
@Generated
public MetricsAdvisorClientBuilder credential(TokenCredential tokenCredential) {
this.tokenCredential = tokenCredential;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@
import com.azure.core.http.rest.RequestOptions;
import com.azure.core.http.rest.Response;
import com.azure.core.util.BinaryData;
import com.azure.identity.DefaultAzureCredentialBuilder;

public class CreateANewDataFeed {
public static void main(String[] args) {
// BEGIN: com.azure.ai.metricsadvisor.generated.createdatafeed.createanewdatafeed
MetricsAdvisorClient metricsAdvisorClient =
new MetricsAdvisorClientBuilder().endpoint("{endpoint}").buildClient();
new MetricsAdvisorClientBuilder()
.credential(new DefaultAzureCredentialBuilder().build())
.endpoint("{endpoint}")
.buildClient();
BinaryData body =
BinaryData.fromString(
"{\"allUpIdentification\":\"__SUM__\",\"authenticationType\":\"Basic\",\"dataFeedDescription\":\"This is a sample data feed.\",\"dataFeedName\":\"Sample - cost/revenue - city/category\",\"dataSourceParameter\":{\"connectionString\":\"Server=PlaceholderSqlServer,1433;Initial Catalog=PlaceholderDatabase;User ID=PlaceholderUserName;Password=PlaceholderPassword;\",\"query\":\"select * from your_table where timestamp = @StartTime\"},\"dataSourceType\":\"SqlServer\",\"dataStartFrom\":\"2020-01-01T00:00:00.000Z\",\"dimension\":[{\"dimensionDisplayName\":\"category\",\"dimensionName\":\"category\"},{\"dimensionDisplayName\":\"city\",\"dimensionName\":\"city\"}],\"fillMissingPointType\":\"SmartFilling\",\"granularityName\":\"Daily\",\"maxConcurrency\":5,\"metrics\":[{\"metricDisplayName\":\"cost\",\"metricName\":\"cost\"},{\"metricDisplayName\":\"revenue\",\"metricName\":\"revenue\"}],\"minRetryIntervalInSeconds\":3600,\"needRollup\":\"NeedRollup\",\"rollUpMethod\":\"Sum\",\"startOffsetInSeconds\":86400,\"stopRetryAfterInSeconds\":604800,\"timestampColumn\":\"timestamp\",\"viewMode\":\"Private\"}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@
import com.azure.core.http.rest.RequestOptions;
import com.azure.core.http.rest.Response;
import com.azure.core.util.BinaryData;
import com.azure.identity.DefaultAzureCredentialBuilder;

public class CreateANewDataSourceCredential {
public static void main(String[] args) {
// BEGIN: com.azure.ai.metricsadvisor.generated.createcredential.createanewdatasourcecredential
MetricsAdvisorClient metricsAdvisorClient =
new MetricsAdvisorClientBuilder().endpoint("{endpoint}").buildClient();
new MetricsAdvisorClientBuilder()
.credential(new DefaultAzureCredentialBuilder().build())
.endpoint("{endpoint}")
.buildClient();
BinaryData body =
BinaryData.fromString(
"{\"dataSourceCredentialDescription\":\"This is a data source credential\",\"dataSourceCredentialName\":\"A data source credential\",\"dataSourceCredentialType\":\"ServicePrincipal\",\"parameters\":{\"clientId\":\"88888888-8888-8888-8888-888888888888\",\"clientSecret\":\"fake-client-secret\",\"tenantId\":\"12345678-1234-1234-1234-123456788888\"}}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@
import com.azure.core.http.rest.RequestOptions;
import com.azure.core.http.rest.Response;
import com.azure.core.util.BinaryData;
import com.azure.identity.DefaultAzureCredentialBuilder;

public class CreateANewHook {
public static void main(String[] args) {
// BEGIN: com.azure.ai.metricsadvisor.generated.createhook.createanewhook
MetricsAdvisorClient metricsAdvisorClient =
new MetricsAdvisorClientBuilder().endpoint("{endpoint}").buildClient();
new MetricsAdvisorClientBuilder()
.credential(new DefaultAzureCredentialBuilder().build())
.endpoint("{endpoint}")
.buildClient();
BinaryData body =
BinaryData.fromString(
"{\"description\":\"This is a webhook.\",\"externalLink\":\"\",\"hookName\":\"A webhook\",\"hookParameter\":{\"endpoint\":\"https://localhost/demo/post\"},\"hookType\":\"Webhook\"}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@
import com.azure.core.http.rest.RequestOptions;
import com.azure.core.http.rest.Response;
import com.azure.core.util.BinaryData;
import com.azure.identity.DefaultAzureCredentialBuilder;

public class CreateANewMetricFeedback {
public static void main(String[] args) {
// BEGIN: com.azure.ai.metricsadvisor.generated.createmetricfeedback.createanewmetricfeedback
MetricsAdvisorClient metricsAdvisorClient =
new MetricsAdvisorClientBuilder().endpoint("{endpoint}").buildClient();
new MetricsAdvisorClientBuilder()
.credential(new DefaultAzureCredentialBuilder().build())
.endpoint("{endpoint}")
.buildClient();
BinaryData body =
BinaryData.fromString(
"{\"anomalyDetectionConfigurationId\":\"33333333-3333-3333-3333-000000000001\",\"dimensionFilter\":{\"dimension\":{\"city\":\"Beijing\"}},\"endTime\":\"2020-01-01T00:00:00.000Z\",\"feedbackType\":\"Anomaly\",\"metricId\":\"22222222-2222-2222-2222-000000000001\",\"startTime\":\"2020-01-01T00:00:00.000Z\",\"value\":{\"anomalyValue\":\"NotAnomaly\"}}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@
import com.azure.core.http.rest.RequestOptions;
import com.azure.core.http.rest.Response;
import com.azure.core.util.BinaryData;
import com.azure.identity.DefaultAzureCredentialBuilder;

public class CreateAnomalyAlertingConfiguration {
public static void main(String[] args) {
// BEGIN:
// com.azure.ai.metricsadvisor.generated.createanomalyalertingconfiguration.createanomalyalertingconfiguration
MetricsAdvisorClient metricsAdvisorClient =
new MetricsAdvisorClientBuilder().endpoint("{endpoint}").buildClient();
new MetricsAdvisorClientBuilder()
.credential(new DefaultAzureCredentialBuilder().build())
.endpoint("{endpoint}")
.buildClient();
BinaryData body =
BinaryData.fromString(
"{\"name\":\"alerting configuration name\",\"crossMetricsOperator\":\"AND\",\"hookIds\":[\"00000000-0000-0000-0000-000000000001\"],\"metricAlertingConfigurations\":[{\"anomalyDetectionConfigurationId\":\"33333333-3333-3333-3333-000000000001\",\"anomalyScopeType\":\"All\",\"negationOperation\":false,\"severityFilter\":{\"maxAlertSeverity\":\"High\",\"minAlertSeverity\":\"Medium\"},\"snoozeFilter\":{\"autoSnooze\":0,\"onlyForSuccessive\":true,\"snoozeScope\":\"Series\"}},{\"anomalyDetectionConfigurationId\":\"33333333-3333-3333-3333-000000000002\",\"anomalyScopeType\":\"Dimension\",\"dimensionAnomalyScope\":{\"dimension\":{\"city\":\"Beijing\"}},\"negationOperation\":false,\"severityFilter\":{\"maxAlertSeverity\":\"High\",\"minAlertSeverity\":\"Low\"},\"snoozeFilter\":{\"autoSnooze\":0,\"onlyForSuccessive\":true,\"snoozeScope\":\"Series\"},\"valueFilter\":{\"type\":\"Value\",\"direction\":\"Both\",\"lower\":0,\"upper\":1000}}]}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@
import com.azure.core.http.rest.RequestOptions;
import com.azure.core.http.rest.Response;
import com.azure.core.util.BinaryData;
import com.azure.identity.DefaultAzureCredentialBuilder;

public class CreateAnomalyDetectionConfiguration {
public static void main(String[] args) {
// BEGIN:
// com.azure.ai.metricsadvisor.generated.createanomalydetectionconfiguration.createanomalydetectionconfiguration
MetricsAdvisorClient metricsAdvisorClient =
new MetricsAdvisorClientBuilder().endpoint("{endpoint}").buildClient();
new MetricsAdvisorClientBuilder()
.credential(new DefaultAzureCredentialBuilder().build())
.endpoint("{endpoint}")
.buildClient();
BinaryData body =
BinaryData.fromString(
"{\"name\":\"Anomaly detection configuration name\",\"description\":\"Anomaly detection configuration description\",\"dimensionGroupOverrideConfigurations\":[{\"changeThresholdCondition\":{\"anomalyDetectorDirection\":\"Both\",\"changePercentage\":5,\"shiftPoint\":1,\"suppressCondition\":{\"minNumber\":1,\"minRatio\":100},\"withinRange\":false},\"conditionOperator\":\"AND\",\"group\":{\"dimension\":{\"city\":\"Beijing\"}},\"hardThresholdCondition\":{\"anomalyDetectorDirection\":\"Both\",\"lowerBound\":1,\"suppressCondition\":{\"minNumber\":1,\"minRatio\":100},\"upperBound\":100},\"smartDetectionCondition\":{\"anomalyDetectorDirection\":\"Both\",\"sensitivity\":91,\"suppressCondition\":{\"minNumber\":1,\"minRatio\":100}}}],\"metricId\":\"22222222-2222-2222-2222-000000000001\",\"seriesOverrideConfigurations\":[{\"changeThresholdCondition\":{\"anomalyDetectorDirection\":\"Both\",\"changePercentage\":5,\"shiftPoint\":1,\"suppressCondition\":{\"minNumber\":1,\"minRatio\":100},\"withinRange\":false},\"conditionOperator\":\"AND\",\"hardThresholdCondition\":{\"anomalyDetectorDirection\":\"Both\",\"lowerBound\":1,\"suppressCondition\":{\"minNumber\":1,\"minRatio\":100},\"upperBound\":100},\"series\":{\"dimension\":{\"category\":\"Jewelry\",\"city\":\"Beijing\"}},\"smartDetectionCondition\":{\"anomalyDetectorDirection\":\"Both\",\"sensitivity\":91,\"suppressCondition\":{\"minNumber\":1,\"minRatio\":100}}}],\"wholeMetricConfiguration\":{\"changeThresholdCondition\":{\"anomalyDetectorDirection\":\"Both\",\"changePercentage\":5,\"shiftPoint\":1,\"suppressCondition\":{\"minNumber\":1,\"minRatio\":100},\"withinRange\":false},\"conditionOperator\":\"AND\",\"hardThresholdCondition\":{\"anomalyDetectorDirection\":\"Both\",\"lowerBound\":1,\"suppressCondition\":{\"minNumber\":1,\"minRatio\":100},\"upperBound\":100},\"smartDetectionCondition\":{\"anomalyDetectorDirection\":\"Both\",\"sensitivity\":91,\"suppressCondition\":{\"minNumber\":1,\"minRatio\":100}}}}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@
import com.azure.ai.metricsadvisor.MetricsAdvisorClientBuilder;
import com.azure.core.http.rest.RequestOptions;
import com.azure.core.http.rest.Response;
import com.azure.identity.DefaultAzureCredentialBuilder;

public class DeleteADataFeed {
public static void main(String[] args) {
// BEGIN: com.azure.ai.metricsadvisor.generated.deletedatafeed.deleteadatafeed
MetricsAdvisorClient metricsAdvisorClient =
new MetricsAdvisorClientBuilder().endpoint("{endpoint}").buildClient();
new MetricsAdvisorClientBuilder()
.credential(new DefaultAzureCredentialBuilder().build())
.endpoint("{endpoint}")
.buildClient();
RequestOptions requestOptions = new RequestOptions();
Response<Void> response =
metricsAdvisorClient.deleteDataFeedWithResponse("01234567-8901-2345-6789-012345678901", requestOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@
import com.azure.ai.metricsadvisor.MetricsAdvisorClientBuilder;
import com.azure.core.http.rest.RequestOptions;
import com.azure.core.http.rest.Response;
import com.azure.identity.DefaultAzureCredentialBuilder;

public class DeleteADataSourceCredential {
public static void main(String[] args) {
// BEGIN: com.azure.ai.metricsadvisor.generated.deletecredential.deleteadatasourcecredential
MetricsAdvisorClient metricsAdvisorClient =
new MetricsAdvisorClientBuilder().endpoint("{endpoint}").buildClient();
new MetricsAdvisorClientBuilder()
.credential(new DefaultAzureCredentialBuilder().build())
.endpoint("{endpoint}")
.buildClient();
RequestOptions requestOptions = new RequestOptions();
Response<Void> response =
metricsAdvisorClient.deleteCredentialWithResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@
import com.azure.ai.metricsadvisor.MetricsAdvisorClientBuilder;
import com.azure.core.http.rest.RequestOptions;
import com.azure.core.http.rest.Response;
import com.azure.identity.DefaultAzureCredentialBuilder;

public class DeleteAHook {
public static void main(String[] args) {
// BEGIN: com.azure.ai.metricsadvisor.generated.deletehook.deleteahook
MetricsAdvisorClient metricsAdvisorClient =
new MetricsAdvisorClientBuilder().endpoint("{endpoint}").buildClient();
new MetricsAdvisorClientBuilder()
.credential(new DefaultAzureCredentialBuilder().build())
.endpoint("{endpoint}")
.buildClient();
RequestOptions requestOptions = new RequestOptions();
Response<Void> response =
metricsAdvisorClient.deleteHookWithResponse("01234567-8901-2345-6789-012345678901", requestOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@
import com.azure.ai.metricsadvisor.MetricsAdvisorClientBuilder;
import com.azure.core.http.rest.RequestOptions;
import com.azure.core.http.rest.Response;
import com.azure.identity.DefaultAzureCredentialBuilder;

public class DeleteAnomalyAlertingConfiguration {
public static void main(String[] args) {
// BEGIN:
// com.azure.ai.metricsadvisor.generated.deleteanomalyalertingconfiguration.deleteanomalyalertingconfiguration
MetricsAdvisorClient metricsAdvisorClient =
new MetricsAdvisorClientBuilder().endpoint("{endpoint}").buildClient();
new MetricsAdvisorClientBuilder()
.credential(new DefaultAzureCredentialBuilder().build())
.endpoint("{endpoint}")
.buildClient();
RequestOptions requestOptions = new RequestOptions();
Response<Void> response =
metricsAdvisorClient.deleteAnomalyAlertingConfigurationWithResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@
import com.azure.ai.metricsadvisor.MetricsAdvisorClientBuilder;
import com.azure.core.http.rest.RequestOptions;
import com.azure.core.http.rest.Response;
import com.azure.identity.DefaultAzureCredentialBuilder;

public class DeleteAnomalyDetectionConfiguration {
public static void main(String[] args) {
// BEGIN:
// com.azure.ai.metricsadvisor.generated.deleteanomalydetectionconfiguration.deleteanomalydetectionconfiguration
MetricsAdvisorClient metricsAdvisorClient =
new MetricsAdvisorClientBuilder().endpoint("{endpoint}").buildClient();
new MetricsAdvisorClientBuilder()
.credential(new DefaultAzureCredentialBuilder().build())
.endpoint("{endpoint}")
.buildClient();
RequestOptions requestOptions = new RequestOptions();
Response<Void> response =
metricsAdvisorClient.deleteAnomalyDetectionConfigurationWithResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@
import com.azure.core.http.rest.RequestOptions;
import com.azure.core.http.rest.Response;
import com.azure.core.util.BinaryData;
import com.azure.identity.DefaultAzureCredentialBuilder;

public class GetADataFeedByItsId {
public static void main(String[] args) {
// BEGIN: com.azure.ai.metricsadvisor.generated.getdatafeedbyid.getadatafeedbyitsid
MetricsAdvisorClient metricsAdvisorClient =
new MetricsAdvisorClientBuilder().endpoint("{endpoint}").buildClient();
new MetricsAdvisorClientBuilder()
.credential(new DefaultAzureCredentialBuilder().build())
.endpoint("{endpoint}")
.buildClient();
RequestOptions requestOptions = new RequestOptions();
Response<BinaryData> response =
metricsAdvisorClient.getDataFeedByIdWithResponse(
Expand Down
Loading

0 comments on commit d30773a

Please sign in to comment.