コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ArmClient"/> class.
        /// </summary>
        /// <param name="defaultSubscriptionId"> The id of the default Azure subscription. </param>
        /// <param name="baseUri"> The base URI of the service. </param>
        /// <param name="credential"> A credential used to authenticate to an Azure Service. </param>
        /// <param name="options"> The client parameters to use in these operations. </param>
        public ArmClient(
            string defaultSubscriptionId,
            Uri baseUri,
            TokenCredential credential,
            ArmClientOptions options = default)
        {
            if (credential is null)
            {
                throw new ArgumentNullException(nameof(credential));
            }

            Credential = credential;
            BaseUri    = baseUri ?? new Uri(DefaultUri);
            options ??= new ArmClientOptions();
            if (options.Diagnostics.IsTelemetryEnabled)
            {
                options.AddPolicy(new MgmtTelemetryPolicy(this, options), HttpPipelinePosition.PerRetry);
            }
            Pipeline = ManagementPipelineBuilder.Build(Credential, options.Scope, options);

            ClientOptions = options.Clone();

            _tenant = new Tenant(ClientOptions, Credential, BaseUri, Pipeline);
            _defaultSubscription = string.IsNullOrWhiteSpace(defaultSubscriptionId) ? null :
                                   new Subscription(new ClientContext(ClientOptions, Credential, BaseUri, Pipeline), ResourceIdentifier.Root.AppendChildResource(Subscription.ResourceType.Type, defaultSubscriptionId));
            ClientOptions.ApiVersions.SetProviderClient(this);
        }
コード例 #2
0
        public MeteringManagementClient(Uri endpoint, TokenCredential tokenCredential, MeteringManagementClientOptions options = null)
        {
            endpoint ??= new Uri("https://marketplaceapi.microsoft.com/api");

            options ??= new MeteringManagementClientOptions();
            _clientDiagnostics = new ClientDiagnostics(options);
            _pipeline          = ManagementPipelineBuilder.Build(tokenCredential, endpoint, options);
            _endpoint          = endpoint;
        }
コード例 #3
0
        public void AddPerCallPolicy()
        {
            var options     = new ArmClientOptions();
            var dummyPolicy = new DummyPolicy();

            options.AddPolicy(dummyPolicy, HttpPipelinePosition.PerCall);
            var pipeline = ManagementPipelineBuilder.Build(new MockCredential(), new Uri("http://foo.com"), options);

            var perCallPolicyField = pipeline.GetType().GetField("_pipeline", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetField);
            var policies           = (ReadOnlyMemory <HttpPipelinePolicy>)perCallPolicyField.GetValue(pipeline);

            Assert.IsNotNull(policies.ToArray().FirstOrDefault(p => p.GetType() == typeof(DummyPolicy)));
        }
コード例 #4
0
        public CosmosDBManagementClient(string subscriptionId, Uri endpoint, TokenCredential tokenCredential, CosmosDBManagementClientOptions options = null)
        {
            if (subscriptionId == null)
            {
                throw new ArgumentNullException(nameof(subscriptionId));
            }
            endpoint ??= new Uri("https://management.azure.com");

            options ??= new CosmosDBManagementClientOptions();
            _clientDiagnostics = new ClientDiagnostics(options);
            _pipeline          = ManagementPipelineBuilder.Build(tokenCredential, endpoint, options);
            _subscriptionId    = subscriptionId;
            _endpoint          = endpoint;
        }
コード例 #5
0
        public RbacManagementClient(string tenantID, Uri endpoint, TokenCredential tokenCredential, RbacManagementClientOptions options = null)
        {
            if (tenantID == null)
            {
                throw new ArgumentNullException(nameof(tenantID));
            }
            endpoint ??= new Uri("https://graph.windows.net");

            options ??= new RbacManagementClientOptions();
            _clientDiagnostics = new ClientDiagnostics(options);
            _pipeline          = ManagementPipelineBuilder.Build(tokenCredential, endpoint, options);
            _tenantID          = tenantID;
            _endpoint          = endpoint;
        }
        public MachineLearningServicesManagementClient(Uri endpoint, string subscriptionId, TokenCredential tokenCredential, MachineLearningServicesManagementClientOptions options = null)
        {
            endpoint ??= new Uri("https://management.azure.com");
            if (subscriptionId == null)
            {
                throw new ArgumentNullException(nameof(subscriptionId));
            }

            options ??= new MachineLearningServicesManagementClientOptions();
            _clientDiagnostics = new ClientDiagnostics(options);
            _pipeline          = ManagementPipelineBuilder.Build(tokenCredential, endpoint, options);
            _endpoint          = endpoint;
            _subscriptionId    = subscriptionId;
        }
コード例 #7
0
        public void ValidateMgmtTelemetry()
        {
            var options  = new ArmClientOptions();
            var pipeline = ManagementPipelineBuilder.Build(new MockCredential(), new Uri("http://foo.com"), options);

            Assert.IsNull(GetPolicyFromPipeline(pipeline, nameof(MgmtTelemetryPolicy)));

            var client = GetArmClient(options);

            Assert.IsNotNull(GetPolicyFromPipeline(GetPipelineFromClient(client), nameof(MgmtTelemetryPolicy)));

            options = new ArmClientOptions();
            options.Diagnostics.IsTelemetryEnabled = false;
            client = GetArmClient(options);
            Assert.IsNull(GetPolicyFromPipeline(GetPipelineFromClient(client), nameof(MgmtTelemetryPolicy)));
            Assert.IsNull(GetPolicyFromPipeline(GetPipelineFromClient(client), "TelemetryPolicy"));
        }
コード例 #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ArmClient"/> class.
        /// </summary>
        /// <param name="defaultSubscriptionId"> The id of the default Azure subscription. </param>
        /// <param name="baseUri"> The base URI of the service. </param>
        /// <param name="credential"> A credential used to authenticate to an Azure Service. </param>
        /// <param name="options"> The client parameters to use in these operations. </param>
        public ArmClient(
            string defaultSubscriptionId,
            Uri baseUri,
            TokenCredential credential,
            ArmClientOptions options = default)
        {
            if (credential is null)
            {
                throw new ArgumentNullException(nameof(credential));
            }

            Credential    = credential;
            BaseUri       = baseUri ?? new Uri(DefaultUri);
            ClientOptions = options?.Clone() ?? new ArmClientOptions();
            Pipeline      = ManagementPipelineBuilder.Build(Credential, options.Scope, options ?? ClientOptions);

            _tenant             = new TenantOperations(ClientOptions, Credential, BaseUri, Pipeline);
            DefaultSubscription = string.IsNullOrWhiteSpace(defaultSubscriptionId)
                ? GetDefaultSubscription()
                : GetSubscriptions().GetIfExists(defaultSubscriptionId);
            ClientOptions.ApiVersions.SetProviderClient(this);
        }