/// <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); }
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; }
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))); }
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; }
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; }
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")); }
/// <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); }