Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of <see cref="MetricsQueryClient"/>.
        /// </summary>
        /// <param name="endpoint">The resource manager service endpoint to use. For example <c>https://management.azure.com/</c> for public cloud.</param>
        /// <param name="credential">The <see cref="TokenCredential"/> instance to use for authentication.</param>
        /// <param name="options">The <see cref="MetricsQueryClientOptions"/> instance to as client configuration.</param>
        public MetricsQueryClient(Uri endpoint, TokenCredential credential, MetricsQueryClientOptions options = null)
        {
            Argument.AssertNotNull(credential, nameof(credential));

            options ??= new MetricsQueryClientOptions();

            _clientDiagnostics = new ClientDiagnostics(options);

            var pipeline = HttpPipelineBuilder.Build(options, new BearerTokenAuthenticationPolicy(credential, "https://management.azure.com//.default"));

            _metricDefinitionsClient = new MetricDefinitionsRestClient(_clientDiagnostics, pipeline, endpoint);
            _metricsRestClient       = new MetricsRestClient(_clientDiagnostics, pipeline, endpoint);
            _namespacesRestClient    = new MetricNamespacesRestClient(_clientDiagnostics, pipeline, endpoint);
        }
        /// <summary>
        /// Initializes a new instance of <see cref="MetricsQueryClient"/>.
        /// </summary>
        /// <param name="endpoint">The resource manager service endpoint to use. For example <c>https://management.azure.com/</c> for public cloud.</param>
        /// <param name="credential">The <see cref="TokenCredential"/> instance to use for authentication.</param>
        /// <param name="options">The <see cref="MetricsQueryClientOptions"/> instance to as client configuration.</param>
        public MetricsQueryClient(Uri endpoint, TokenCredential credential, MetricsQueryClientOptions options = null)
        {
            Argument.AssertNotNull(credential, nameof(credential));

            options ??= new MetricsQueryClientOptions();

            _clientDiagnostics = new ClientDiagnostics(options);

            var scope = $"{endpoint.AbsoluteUri}/.default";

            Endpoint = endpoint;

            var pipeline = HttpPipelineBuilder.Build(options,
                                                     new BearerTokenAuthenticationPolicy(credential, scope));

            _metricDefinitionsClient = new MetricDefinitionsRestClient(_clientDiagnostics, pipeline, endpoint);
            _metricsRestClient       = new MetricsRestClient(_clientDiagnostics, pipeline, endpoint);
            _namespacesRestClient    = new MetricNamespacesRestClient(_clientDiagnostics, pipeline, endpoint);
        }
        /// <summary>
        /// Initializes a new instance of <see cref="MetricsQueryClient"/>.
        /// </summary>
        /// <param name="endpoint">The resource manager service endpoint to use. For example <c>https://management.azure.com/</c> for public cloud.</param>
        /// <param name="credential">The <see cref="TokenCredential"/> instance to use for authentication.</param>
        /// <param name="options">The <see cref="MetricsQueryClientOptions"/> instance to as client configuration.</param>
        public MetricsQueryClient(Uri endpoint, TokenCredential credential, MetricsQueryClientOptions options = null)
        {
            Argument.AssertNotNull(credential, nameof(credential));

            options ??= new MetricsQueryClientOptions();

            _clientDiagnostics = new ClientDiagnostics(options);

            Endpoint = endpoint;

            var pipeline = HttpPipelineBuilder.Build(options,
                                                     new BearerTokenAuthenticationPolicy(
                                                         credential,
                                                         $"{options.Audience ?? MetricsQueryClientAudience.AzureResourceManagerPublicCloud}//.default"));

            _metricDefinitionsClient = new MetricDefinitionsRestClient(_clientDiagnostics, pipeline, endpoint);
            _metricsRestClient       = new MetricsRestClient(_clientDiagnostics, pipeline, endpoint);
            _namespacesRestClient    = new MetricNamespacesRestClient(_clientDiagnostics, pipeline, endpoint);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of <see cref="MetricsQueryClient"/>. Uses the default 'https://management.azure.com' endpoint.
 /// </summary>
 /// <param name="credential">The <see cref="TokenCredential"/> instance to use for authentication.</param>
 /// <param name="options">The <see cref="MetricsQueryClientOptions"/> instance to as client configuration.</param>
 public MetricsQueryClient(TokenCredential credential, MetricsQueryClientOptions options) : this(_defaultEndpoint, credential, options)
 {
 }