예제 #1
0
        public void ValidateMgmtTelemetry()
        {
            var options = new ArmClientOptions();

            options.Diagnostics.IsTelemetryEnabled = true;
            var client = GetArmClient(options);

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

            options.Diagnostics.IsTelemetryEnabled = false;
            client = GetArmClient(options);
            Assert.IsNull(GetPolicyFromPipeline(GetPipelineFromClient(client), nameof(MgmtTelemetryPolicy)));
            Assert.IsNull(GetPolicyFromPipeline(GetPipelineFromClient(client), "TelemetryPolicy"));
        }
예제 #2
0
        public async Task GetGenericsBadApiVersion()
        {
            var              rgName  = Recording.GenerateAssetName("testrg");
            var              rgOp    = await(await Client.GetDefaultSubscriptionAsync().ConfigureAwait(false)).GetResourceGroups().Construct(AzureLocation.WestUS2).CreateOrUpdateAsync(rgName);
            ResourceGroup    rg      = rgOp.Value;
            ArmClientOptions options = new ArmClientOptions();

            options.SetApiVersion(rg.Id.ResourceType, "1500-10-10");
            var client = GetArmClient(options);
            var genericResourceOperations    = client.GetGenericResource(rg.Id);
            RequestFailedException exception = Assert.ThrowsAsync <RequestFailedException>(async() => await genericResourceOperations.GetAsync());

            Assert.IsTrue(exception.Message.Contains("InvalidApiVersionParameter"));
        }
예제 #3
0
        public async Task VerifyDefaultEnumVersionUsed()
        {
            ResourceGroupVersionTracker tracker = new ResourceGroupVersionTracker();
            ArmClientOptions            options = new ArmClientOptions();

            options.AddPolicy(tracker, HttpPipelinePosition.PerCall);
            var client       = GetArmClient(options);
            var subscription = await client.GetDefaultSubscriptionAsync();

            var rgCollection = subscription.GetResourceGroups();

            _ = await rgCollection.CreateOrUpdateAsync(WaitUntil.Completed, Recording.GenerateAssetName("testRg-"), new ResourceGroupData(AzureLocation.WestUS));

            Assert.AreEqual(GetDefaultResourceGroupVersion(rgCollection), tracker.VersionUsed);
        }
예제 #4
0
        public void VersionNonLoadedChanges()
        {
            var apiVersions          = "2019-10-01";
            var providerName         = "Microsoft.Logic/LogicApps";
            ArmClientOptions options = new ArmClientOptions();

            options.ApiVersions.SetApiVersion(providerName, apiVersions);
            string result = options.ApiVersions.TryGetApiVersion(providerName);

            Assert.True(result.Equals(apiVersions));

            apiVersions = "2021-02-01";
            options.ApiVersions.SetApiVersion(providerName, apiVersions);
            result = options.ApiVersions.TryGetApiVersion(providerName);
            Assert.True(result.Equals(apiVersions));
        }
예제 #5
0
        public void AddPerCallPolicyViaClient()
        {
            var options     = new ArmClientOptions();
            var dummyPolicy = new DummyPolicy();

            options.AddPolicy(dummyPolicy, HttpPipelinePosition.PerCall);
            var client = new ArmClient(Guid.NewGuid().ToString(), new MockCredential(), options);

            var pipelineProperty = client.GetType().GetProperty("Pipeline", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetProperty);
            var pipeline         = pipelineProperty.GetValue(client) as HttpPipeline;

            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)));
        }
예제 #6
0
        public async Task AddPolicy_Percall()
        {
            var options = new ArmClientOptions();
            RequestTimesTracker tracker = new RequestTimesTracker();

            options.AddPolicy(tracker, HttpPipelinePosition.PerCall);
            var client       = GetArmClient(options);
            var subscription = await client.GetDefaultSubscriptionAsync();

            Assert.AreEqual(1, tracker.Times);
            var rgCollection = subscription.GetResourceGroups();

            _ = await rgCollection.GetAsync(_rgName);

            Assert.AreEqual(2, tracker.Times);
        }
        protected ArmClient GetArmClient(ArmClientOptions clientOptions = default, string subscriptionId = default)
        {
            var options = InstrumentClientOptions(clientOptions ?? new ArmClientOptions());

            options.Environment = GetEnvironment(TestEnvironment.ResourceManagerUrl);
            options.AddPolicy(ResourceGroupCleanupPolicy, HttpPipelinePosition.PerCall);
            options.AddPolicy(ManagementGroupCleanupPolicy, HttpPipelinePosition.PerCall);
            if (_apiVersion is not null)
            {
                options.SetApiVersion(_resourceType, _apiVersion);
            }

            return(InstrumentClient(new ArmClient(
                                        TestEnvironment.Credential,
                                        subscriptionId ?? TestEnvironment.SubscriptionId,
                                        options), new IInterceptor[] { new ManagementInterceptor(this) }));
        }
예제 #8
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"));
        }
예제 #9
0
        public void AddPolicy_PerRetry()
        {
            var retryResponse = new MockResponse(408); // Request Timeout
            var mockTransport = new MockTransport(retryResponse, retryResponse, new MockResponse(200));
            var options       = new ArmClientOptions()
            {
                Transport = mockTransport,
            };

            options.Retry.Delay = TimeSpan.FromMilliseconds(100);
            RequestTimesTracker tracker = new RequestTimesTracker();

            options.AddPolicy(tracker, HttpPipelinePosition.PerRetry);
            var client = GetArmClient(options);

            Assert.ThrowsAsync <ArgumentNullException>(async() => _ = await client.GetDefaultSubscriptionAsync());
            Assert.AreEqual(options.Retry.MaxRetries, tracker.Times);
        }
예제 #10
0
        public async Task TestClientContextPolicy()
        {
            ArmClientOptions options1 = new ArmClientOptions();
            var dummyPolicy1          = new dummyPolicy();
            var dummyPolicy2          = new dummyPolicy2();

            options1.AddPolicy(dummyPolicy1, HttpPipelinePosition.PerCall);
            var client1 = GetArmClient(options1);

            Console.WriteLine("-----Client 1-----");
            _ = await(await client1.GetDefaultSubscriptionAsync().ConfigureAwait(false)).GetResourceGroups().Construct(AzureLocation.WestUS2).CreateOrUpdateAsync(Recording.GenerateAssetName("testrg"));
            Assert.AreEqual(2, dummyPolicy1.numMsgGot);

            options1.AddPolicy(dummyPolicy2, HttpPipelinePosition.PerCall);

            _ = await(await client1.GetDefaultSubscriptionAsync().ConfigureAwait(false)).GetResourceGroups().Construct(AzureLocation.WestUS2).CreateOrUpdateAsync(Recording.GenerateAssetName("test2Rg-"));

            Assert.AreEqual(3, dummyPolicy1.numMsgGot);
            Assert.AreEqual(0, dummyPolicy2.numMsgGot);
        }
        public async Task GetUsedResourceApiVersion()
        {
            ProviderCounterPolicy policy  = new ProviderCounterPolicy();
            ArmClientOptions      options = new ArmClientOptions();

            options.AddPolicy(policy, HttpPipelinePosition.PerCall);
            var client       = GetArmClient(options);
            var subscription = await client.GetDefaultSubscriptionAsync();

            var version = await subscription.GetProviders().TryGetApiVersionAsync(new ResourceType("Microsoft.Compute/virtualMachines"));

            Assert.NotNull(version);
            Assert.AreEqual(1, policy.GetCount("Microsoft.Compute"));
            Assert.AreEqual(0, policy.GetCount("Microsoft.Network"));

            version = await subscription.GetProviders().TryGetApiVersionAsync(new ResourceType("Microsoft.Compute/availabilitySets"));

            Assert.NotNull(version);
            Assert.AreEqual(1, policy.GetCount("Microsoft.Compute"));
            Assert.AreEqual(0, policy.GetCount("Microsoft.Network"));
        }
예제 #12
0
 internal StorageAccount(ArmClientOptions clientOptions, TokenCredential credential, Uri uri, HttpPipeline pipeline, ResourceIdentifier id) : base(clientOptions, credential, uri, pipeline, id)
 {
     _clientDiagnostics = new ClientDiagnostics(ClientOptions);
     _restClient        = new StorageAccountsRestOperations(_clientDiagnostics, Pipeline, ClientOptions, Id.SubscriptionId, BaseUri);
     _privateLinkResourcesRestClient = new PrivateLinkResourcesRestOperations(_clientDiagnostics, Pipeline, ClientOptions, Id.SubscriptionId, BaseUri);
 }
예제 #13
0
 internal HostingEnvironmentMultiRolePool(ArmClientOptions clientOptions, TokenCredential credential, Uri uri, HttpPipeline pipeline, ResourceIdentifier id) : base(clientOptions, credential, uri, pipeline, id)
 {
     _clientDiagnostics = new ClientDiagnostics(ClientOptions);
     _appServiceEnvironmentsRestClient = new AppServiceEnvironmentsRestOperations(_clientDiagnostics, Pipeline, ClientOptions, BaseUri);
 }
예제 #14
0
 internal FileService(ArmClientOptions clientOptions, TokenCredential credential, Uri uri, HttpPipeline pipeline, ResourceIdentifier id) : base(clientOptions, credential, uri, pipeline, id)
 {
     _clientDiagnostics      = new ClientDiagnostics(ClientOptions);
     _fileServicesRestClient = new FileServicesRestOperations(_clientDiagnostics, Pipeline, ClientOptions, BaseUri);
 }
예제 #15
0
 public AfdSecretsRestOperations(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, ArmClientOptions options, Uri endpoint = null, string apiVersion = default)
 {
     this.endpoint      = endpoint ?? new Uri("https://management.azure.com");
     this.apiVersion    = apiVersion ?? "2020-09-01";
     _clientDiagnostics = clientDiagnostics;
     _pipeline          = pipeline;
     _userAgent         = HttpMessageUtilities.GetUserAgentName(this, options);
 }
예제 #16
0
 internal EventHubAuthorizationRule(ArmClientOptions clientOptions, TokenCredential credential, Uri uri, HttpPipeline pipeline, ResourceIdentifier id) : base(clientOptions, credential, uri, pipeline, id)
 {
     _clientDiagnostics   = new ClientDiagnostics(ClientOptions);
     _eventHubsRestClient = new EventHubsRestOperations(_clientDiagnostics, Pipeline, ClientOptions, BaseUri);
 }
 internal VpnServerConfiguration(ArmClientOptions clientOptions, TokenCredential credential, Uri uri, HttpPipeline pipeline, ResourceIdentifier id) : base(clientOptions, credential, uri, pipeline, id)
 {
     _clientDiagnostics = new ClientDiagnostics(ClientOptions);
     _vpnServerConfigurationsRestClient = new VpnServerConfigurationsRestOperations(_clientDiagnostics, Pipeline, ClientOptions, BaseUri);
 }
 internal DisasterRecovery(ArmClientOptions clientOptions, TokenCredential credential, Uri uri, HttpPipeline pipeline, ResourceIdentifier id) : base(clientOptions, credential, uri, pipeline, id)
 {
     _clientDiagnostics = new ClientDiagnostics(ClientOptions);
     _disasterRecoveryConfigsRestClient = new DisasterRecoveryConfigsRestOperations(_clientDiagnostics, Pipeline, ClientOptions, BaseUri);
 }
 internal DatabaseAutomaticTuning(ArmClientOptions clientOptions, TokenCredential credential, Uri uri, HttpPipeline pipeline, ResourceIdentifier id) : base(clientOptions, credential, uri, pipeline, id)
 {
     _clientDiagnostics = new ClientDiagnostics(ClientOptions);
     _databaseAutomaticTuningRestClient = new DatabaseAutomaticTuningRestOperations(_clientDiagnostics, Pipeline, ClientOptions, BaseUri);
 }
예제 #20
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SubscriptionOperations"/> class.
 /// </summary>
 /// <param name="options"> The client parameters to use in these operations. </param>
 /// <param name="credential"> A credential used to authenticate to an Azure Service. </param>
 /// <param name="baseUri"> The base URI of the service. </param>
 /// <param name="pipeline"> The HTTP pipeline for sending and receiving REST requests and responses. </param>
 internal TenantOperations(ArmClientOptions options, TokenCredential credential, Uri baseUri, HttpPipeline pipeline)
     : base(new ClientContext(options, credential, baseUri, pipeline), ResourceIdentifier.RootResourceIdentifier)
 {
     _providerRestOperations = new ProviderRestOperations(Diagnostics, Pipeline, Guid.Empty.ToString(), BaseUri);
 }
예제 #21
0
 internal SiteTriggeredWebJobHistory(ArmClientOptions clientOptions, TokenCredential credential, Uri uri, HttpPipeline pipeline, ResourceIdentifier id) : base(clientOptions, credential, uri, pipeline, id)
 {
     _clientDiagnostics = new ClientDiagnostics(ClientOptions);
     _webAppsRestClient = new WebAppsRestOperations(_clientDiagnostics, Pipeline, ClientOptions, BaseUri);
 }
 internal PrivateEndpointConnection(ArmClientOptions clientOptions, TokenCredential credential, Uri uri, HttpPipeline pipeline, ResourceIdentifier id) : base(clientOptions, credential, uri, pipeline, id)
 {
     _clientDiagnostics = new ClientDiagnostics(ClientOptions);
     _privateEndpointConnectionsRestClient = new PrivateEndpointConnectionsRestOperations(_clientDiagnostics, Pipeline, ClientOptions, BaseUri);
 }
 private static LongTermRetentionManagedInstanceBackupsRestOperations GetLongTermRetentionManagedInstanceBackupsRestOperations(ClientDiagnostics clientDiagnostics, TokenCredential credential, ArmClientOptions clientOptions, HttpPipeline pipeline, Uri endpoint = null)
 {
     return(new LongTermRetentionManagedInstanceBackupsRestOperations(clientDiagnostics, pipeline, clientOptions, endpoint));
 }
예제 #24
0
 internal SiteHybridConnectionNamespaceRelay(ArmClientOptions clientOptions, TokenCredential credential, Uri uri, HttpPipeline pipeline, ResourceIdentifier id) : base(clientOptions, credential, uri, pipeline, id)
 {
     _clientDiagnostics = new ClientDiagnostics(ClientOptions);
     _webAppsRestClient = new WebAppsRestOperations(_clientDiagnostics, Pipeline, ClientOptions, BaseUri);
 }
예제 #25
0
 internal ServerSecurityAlertPolicy(ArmClientOptions clientOptions, TokenCredential credential, Uri uri, HttpPipeline pipeline, ResourceIdentifier id) : base(clientOptions, credential, uri, pipeline, id)
 {
     _clientDiagnostics = new ClientDiagnostics(ClientOptions);
     _serverSecurityAlertPoliciesRestClient = new ServerSecurityAlertPoliciesRestOperations(_clientDiagnostics, Pipeline, ClientOptions, BaseUri);
 }
예제 #26
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ContainerBase"/> class.
 /// </summary>
 /// <param name="options"> The options to use. </param>
 /// <param name="credential"> The credential to use. </param>
 /// <param name="baseUri"> The base uri to use. </param>
 /// <param name="pipeline"> The http pipeline policy to use. </param>
 protected ContainerBase(ArmClientOptions options, TokenCredential credential, Uri baseUri, HttpPipeline pipeline)
     : this(new ClientContext(options, credential, baseUri, pipeline))
 {
 }
예제 #27
0
 internal TemplateSpec(ArmClientOptions clientOptions, TokenCredential credential, Uri uri, HttpPipeline pipeline, ResourceIdentifier id) : base(clientOptions, credential, uri, pipeline, id)
 {
     _clientDiagnostics       = new ClientDiagnostics(ClientOptions);
     _templateSpecsRestClient = new TemplateSpecsRestOperations(_clientDiagnostics, Pipeline, ClientOptions, BaseUri);
 }
예제 #28
0
 private static VaultsRestOperations GetVaultsRestOperations(ClientDiagnostics clientDiagnostics, TokenCredential credential, ArmClientOptions clientOptions, HttpPipeline pipeline, string subscriptionId, Uri endpoint = null)
 {
     return(new VaultsRestOperations(clientDiagnostics, pipeline, clientOptions, subscriptionId, endpoint));
 }
예제 #29
0
 internal RouteTable(ArmClientOptions clientOptions, TokenCredential credential, Uri uri, HttpPipeline pipeline, ResourceIdentifier id) : base(clientOptions, credential, uri, pipeline, id)
 {
     _clientDiagnostics = new ClientDiagnostics(ClientOptions);
     _restClient        = new RouteTablesRestOperations(_clientDiagnostics, Pipeline, ClientOptions, Id.SubscriptionId, BaseUri);
 }
 internal SharedPrivateLink(ArmClientOptions clientOptions, TokenCredential credential, Uri uri, HttpPipeline pipeline, ResourceIdentifier id) : base(clientOptions, credential, uri, pipeline, id)
 {
     _clientDiagnostics            = new ClientDiagnostics(ClientOptions);
     _sharedPrivateLinksRestClient = new SharedPrivateLinksRestOperations(_clientDiagnostics, Pipeline, ClientOptions, BaseUri);
 }