/// <summary> /// Updates the details of the Diagnostic specified by its identifier. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// The name of the resource group. /// </param> /// <param name='serviceName'> /// The name of the API Management service. /// </param> /// <param name='diagnosticId'> /// Diagnostic identifier. Must be unique in the current API Management service /// instance. /// </param> /// <param name='parameters'> /// Diagnostic Update parameters. /// </param> /// <param name='ifMatch'> /// ETag of the Entity. ETag should match the current entity state from the /// header response of the GET request or it should be * for unconditional /// update. /// </param> public static DiagnosticContract Update(this IDiagnosticOperations operations, string resourceGroupName, string serviceName, string diagnosticId, DiagnosticContract parameters, string ifMatch) { return(operations.UpdateAsync(resourceGroupName, serviceName, diagnosticId, parameters, ifMatch).GetAwaiter().GetResult()); }
/// <summary> /// Updates the details of the Diagnostic specified by its identifier. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// The name of the resource group. /// </param> /// <param name='serviceName'> /// The name of the API Management service. /// </param> /// <param name='diagnosticId'> /// Diagnostic identifier. Must be unique in the current API Management service /// instance. /// </param> /// <param name='parameters'> /// Diagnostic Update parameters. /// </param> /// <param name='ifMatch'> /// ETag of the Entity. ETag should match the current entity state from the /// header response of the GET request or it should be * for unconditional /// update. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <DiagnosticContract> UpdateAsync(this IDiagnosticOperations operations, string resourceGroupName, string serviceName, string diagnosticId, DiagnosticContract parameters, string ifMatch, CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.UpdateWithHttpMessagesAsync(resourceGroupName, serviceName, diagnosticId, parameters, ifMatch, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
/// <summary> /// Creates a new Diagnostic for an API or updates an existing one. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// The name of the resource group. /// </param> /// <param name='serviceName'> /// The name of the API Management service. /// </param> /// <param name='apiId'> /// API identifier. Must be unique in the current API Management service /// instance. /// </param> /// <param name='diagnosticId'> /// Diagnostic identifier. Must be unique in the current API Management service /// instance. /// </param> /// <param name='parameters'> /// Create parameters. /// </param> /// <param name='ifMatch'> /// ETag of the Entity. Not required when creating an entity, but required when /// updating an entity. /// </param> public static DiagnosticContract CreateOrUpdate(this IApiDiagnosticOperations operations, string resourceGroupName, string serviceName, string apiId, string diagnosticId, DiagnosticContract parameters, string ifMatch = default(string)) { return(operations.CreateOrUpdateAsync(resourceGroupName, serviceName, apiId, diagnosticId, parameters, ifMatch).GetAwaiter().GetResult()); }
public async Task CreateListUpdateDelete() { Environment.SetEnvironmentVariable("AZURE_TEST_MODE", "Playback"); using (MockContext context = MockContext.Start(this.GetType())) { var testBase = new ApiManagementTestBase(context); testBase.TryCreateApiManagementService(); // list diagnostics: there should be none var diagnostics = testBase.client.Diagnostic.ListByService( testBase.rgName, testBase.serviceName, null); Assert.NotNull(diagnostics); Assert.Empty(diagnostics); // create new diagnostic, supported Ids are applicationinsights, azuremonitor string diagnosticId = "applicationinsights"; string loggerId = TestUtilities.GenerateName("appInsights"); try { // create a logger Guid applicationInsightsGuid = TestUtilities.GenerateGuid("appInsights"); var credentials = new Dictionary <string, string>(); credentials.Add("instrumentationKey", applicationInsightsGuid.ToString()); var loggerCreateParameters = new LoggerContract(LoggerType.ApplicationInsights, credentials: credentials); var loggerContract = await testBase.client.Logger.CreateOrUpdateAsync( testBase.rgName, testBase.serviceName, loggerId, loggerCreateParameters); Assert.NotNull(loggerContract); Assert.Equal(loggerId, loggerContract.Name); Assert.Equal(LoggerType.ApplicationInsights, loggerContract.LoggerType); Assert.NotNull(loggerContract.Credentials); Assert.Equal(1, loggerContract.Credentials.Keys.Count); // create a diagnostic entity with just loggerId var diagnosticContractParams = new DiagnosticContract() { LoggerId = loggerContract.Id }; var diagnosticContract = await testBase.client.Diagnostic.CreateOrUpdateAsync( testBase.rgName, testBase.serviceName, diagnosticId, diagnosticContractParams); Assert.NotNull(diagnosticContract); Assert.Equal(diagnosticId, diagnosticContract.Name); // check the diagnostic entity etag var diagnosticTag = await testBase.client.Diagnostic.GetEntityTagAsync( testBase.rgName, testBase.serviceName, diagnosticId); Assert.NotNull(diagnosticTag); Assert.NotNull(diagnosticTag.ETag); // now update the sampling and other settings of the diagnostic diagnosticContractParams.AlwaysLog = "allErrors"; diagnosticContractParams.Sampling = new SamplingSettings("fixed", 50); var listOfHeaders = new List <string> { "Content-type" }; var bodyDiagnostic = new BodyDiagnosticSettings(512); diagnosticContractParams.Frontend = new PipelineDiagnosticSettings { Request = new HttpMessageDiagnostic() { Body = bodyDiagnostic, Headers = listOfHeaders }, Response = new HttpMessageDiagnostic() { Body = bodyDiagnostic, Headers = listOfHeaders } }; diagnosticContractParams.Backend = new PipelineDiagnosticSettings { Request = new HttpMessageDiagnostic() { Body = bodyDiagnostic, Headers = listOfHeaders }, Response = new HttpMessageDiagnostic() { Body = bodyDiagnostic, Headers = listOfHeaders } }; var updatedDiagnostic = await testBase.client.Diagnostic.CreateOrUpdateWithHttpMessagesAsync( testBase.rgName, testBase.serviceName, diagnosticId, diagnosticContractParams, diagnosticTag.ETag); Assert.NotNull(updatedDiagnostic); Assert.Equal("allErrors", updatedDiagnostic.Body.AlwaysLog); Assert.NotNull(updatedDiagnostic.Body.Sampling); Assert.NotNull(updatedDiagnostic.Body.Frontend); Assert.NotNull(updatedDiagnostic.Body.Backend); Assert.NotNull(updatedDiagnostic.Body.HttpCorrelationProtocol); Assert.Equal(HttpCorrelationProtocol.Legacy, updatedDiagnostic.Body.HttpCorrelationProtocol); // delete the diagnostic entity await testBase.client.Diagnostic.DeleteAsync( testBase.rgName, testBase.serviceName, diagnosticId, updatedDiagnostic.Headers.ETag); Assert.Throws <ErrorResponseException>(() => testBase.client.Diagnostic.GetEntityTag(testBase.rgName, testBase.serviceName, diagnosticId)); // check the logger entity etag var loggerTag = await testBase.client.Logger.GetEntityTagAsync( testBase.rgName, testBase.serviceName, loggerId); Assert.NotNull(loggerTag); Assert.NotNull(loggerTag.ETag); // delete the logger entity await testBase.client.Logger.DeleteAsync( testBase.rgName, testBase.serviceName, loggerId, loggerTag.ETag); Assert.Throws <ErrorResponseException>(() => testBase.client.Logger.GetEntityTag(testBase.rgName, testBase.serviceName, loggerId)); } finally { testBase.client.Diagnostic.Delete(testBase.rgName, testBase.serviceName, diagnosticId, "*"); testBase.client.Logger.Delete(testBase.rgName, testBase.serviceName, loggerId, "*"); // clean up all properties var listOfProperties = testBase.client.NamedValue.ListByService( testBase.rgName, testBase.serviceName); foreach (var property in listOfProperties) { testBase.client.NamedValue.Delete( testBase.rgName, testBase.serviceName, property.Name, "*"); } } } }
/// <summary> /// Updates the details of the Diagnostic for an API specified by its /// identifier. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// The name of the resource group. /// </param> /// <param name='serviceName'> /// The name of the API Management service. /// </param> /// <param name='apiId'> /// API identifier. Must be unique in the current API Management service /// instance. /// </param> /// <param name='diagnosticId'> /// Diagnostic identifier. Must be unique in the current API Management service /// instance. /// </param> /// <param name='parameters'> /// Diagnostic Update parameters. /// </param> /// <param name='ifMatch'> /// ETag of the Entity. ETag should match the current entity state from the /// header response of the GET request or it should be * for unconditional /// update. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task UpdateAsync(this IApiDiagnosticOperations operations, string resourceGroupName, string serviceName, string apiId, string diagnosticId, DiagnosticContract parameters, string ifMatch, CancellationToken cancellationToken = default(CancellationToken)) { (await operations.UpdateWithHttpMessagesAsync(resourceGroupName, serviceName, apiId, diagnosticId, parameters, ifMatch, null, cancellationToken).ConfigureAwait(false)).Dispose(); }
/// <summary> /// Updates the details of the Diagnostic for an API specified by its /// identifier. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// The name of the resource group. /// </param> /// <param name='serviceName'> /// The name of the API Management service. /// </param> /// <param name='apiId'> /// API identifier. Must be unique in the current API Management service /// instance. /// </param> /// <param name='diagnosticId'> /// Diagnostic identifier. Must be unique in the current API Management service /// instance. /// </param> /// <param name='parameters'> /// Diagnostic Update parameters. /// </param> /// <param name='ifMatch'> /// ETag of the Entity. ETag should match the current entity state from the /// header response of the GET request or it should be * for unconditional /// update. /// </param> public static void Update(this IApiDiagnosticOperations operations, string resourceGroupName, string serviceName, string apiId, string diagnosticId, DiagnosticContract parameters, string ifMatch) { operations.UpdateAsync(resourceGroupName, serviceName, apiId, diagnosticId, parameters, ifMatch).GetAwaiter().GetResult(); }
public async Task CreateListUpdateDelete() { Environment.SetEnvironmentVariable("AZURE_TEST_MODE", "Playback"); using (MockContext context = MockContext.Start(this.GetType().FullName)) { var testBase = new ApiManagementTestBase(context); testBase.TryCreateApiManagementService(); // list diagnostics: there should be none var diagnostics = testBase.client.Diagnostic.ListByService( testBase.rgName, testBase.serviceName, null); Assert.NotNull(diagnostics); Assert.Empty(diagnostics); // create new diagnostic, supported Ids are applicationinsights, azuremonitor string diagnosticId = "applicationinsights"; string loggerId = TestUtilities.GenerateName("appInsights"); try { // create a diagnostic entity var diagnosticContractParams = new DiagnosticContract() { Enabled = true }; var diagnosticContract = await testBase.client.Diagnostic.CreateOrUpdateAsync( testBase.rgName, testBase.serviceName, diagnosticId, diagnosticContractParams); Assert.NotNull(diagnosticContract); Assert.Equal(diagnosticId, diagnosticContract.Name); Assert.Equal(diagnosticContractParams.Enabled, diagnosticContract.Enabled); // create a logger Guid applicationInsightsGuid = TestUtilities.GenerateGuid("appInsights"); var credentials = new Dictionary <string, string>(); credentials.Add("instrumentationKey", applicationInsightsGuid.ToString()); var loggerCreateParameters = new LoggerContract(LoggerType.ApplicationInsights, credentials); var loggerContract = await testBase.client.Logger.CreateOrUpdateAsync( testBase.rgName, testBase.serviceName, loggerId, loggerCreateParameters); Assert.NotNull(loggerContract); Assert.Equal(loggerId, loggerContract.Name); Assert.Equal(LoggerType.ApplicationInsights, loggerContract.LoggerType); Assert.NotNull(loggerContract.Credentials); Assert.Equal(1, loggerContract.Credentials.Keys.Count); // create a diagnostic logger loggerContract = await testBase.client.DiagnosticLogger.CreateOrUpdateAsync( testBase.rgName, testBase.serviceName, diagnosticId, loggerId); Assert.NotNull(loggerContract); Assert.Equal(loggerId, loggerContract.Name); Assert.Equal(LoggerType.ApplicationInsights, loggerContract.LoggerType); //list diagnostic loggers var loggerContractList = await testBase.client.DiagnosticLogger.ListByServiceAsync( testBase.rgName, testBase.serviceName, diagnosticId); Assert.NotNull(loggerContractList); Assert.Single(loggerContractList); Assert.Equal(loggerId, loggerContractList.GetEnumerator().ToIEnumerable().First().Name); Assert.Equal(LoggerType.ApplicationInsights, loggerContractList.GetEnumerator().ToIEnumerable().First().LoggerType); // check the diagnostic entity etag var diagnosticTag = await testBase.client.Diagnostic.GetEntityTagAsync( testBase.rgName, testBase.serviceName, diagnosticId); Assert.NotNull(diagnosticTag); Assert.NotNull(diagnosticTag.ETag); // delete the diagnostic entity await testBase.client.Diagnostic.DeleteAsync( testBase.rgName, testBase.serviceName, diagnosticId, diagnosticTag.ETag); Assert.Throws <ErrorResponseException>(() => testBase.client.Diagnostic.GetEntityTag(testBase.rgName, testBase.serviceName, diagnosticId)); // check the logger entity etag var loggerTag = await testBase.client.Logger.GetEntityTagAsync( testBase.rgName, testBase.serviceName, loggerId); Assert.NotNull(loggerTag); Assert.NotNull(loggerTag.ETag); // delete the logger entity await testBase.client.Logger.DeleteAsync( testBase.rgName, testBase.serviceName, loggerId, loggerTag.ETag); Assert.Throws <ErrorResponseException>(() => testBase.client.Logger.GetEntityTag(testBase.rgName, testBase.serviceName, loggerId)); } finally { testBase.client.Diagnostic.Delete(testBase.rgName, testBase.serviceName, diagnosticId, "*"); testBase.client.Logger.Delete(testBase.rgName, testBase.serviceName, loggerId, "*"); } } }