Skip to content
This repository was archived by the owner on Feb 23, 2024. It is now read-only.

Commit 28c8ff5

Browse files
DeagleGrossHardell
andauthored
refactor named-values + logger extractors (#669)
* refactor named-values + logger extractors * Update src/ArmTemplates/Common/Templates/Logger/LoggerTemplateProperties.cs Co-authored-by: Milan Zolota <Hardell@users.noreply.github.com> Co-authored-by: Dmitrii Korolev <dmkorolev@microsoft.com> Co-authored-by: Milan Zolota <Hardell@users.noreply.github.com>
1 parent f447bcb commit 28c8ff5

File tree

55 files changed

+1359
-665
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1359
-665
lines changed

src/ArmTemplates/Commands/Executors/ExtractorExecutor.cs

Lines changed: 118 additions & 92 deletions
Large diffs are not rendered by default.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// --------------------------------------------------------------------------
2+
// <copyright file="ILoggerClient.cs" company="Microsoft">
3+
// Copyright (c) Microsoft Corporation. All rights reserved.
4+
// </copyright>
5+
// --------------------------------------------------------------------------
6+
7+
using System.Collections.Generic;
8+
using System.Threading.Tasks;
9+
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.Logger;
10+
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Extractor.Models;
11+
12+
namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.API.Clients.Abstractions
13+
{
14+
public interface ILoggerClient
15+
{
16+
Task<List<LoggerTemplateResource>> GetAllAsync(ExtractorParameters extractorParameters);
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// --------------------------------------------------------------------------
2+
// <copyright file="INamedValuesClient.cs" company="Microsoft">
3+
// Copyright (c) Microsoft Corporation. All rights reserved.
4+
// </copyright>
5+
// --------------------------------------------------------------------------
6+
7+
using System.Collections.Generic;
8+
using System.Threading.Tasks;
9+
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.NamedValues;
10+
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Extractor.Models;
11+
12+
namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.API.Clients.Abstractions
13+
{
14+
public interface INamedValuesClient
15+
{
16+
Task<List<NamedValueTemplateResource>> GetAllAsync(ExtractorParameters extractorParameters);
17+
}
18+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// --------------------------------------------------------------------------
2+
// <copyright file="LoggerClient.cs" company="Microsoft">
3+
// Copyright (c) Microsoft Corporation. All rights reserved.
4+
// </copyright>
5+
// --------------------------------------------------------------------------
6+
7+
using System.Collections.Generic;
8+
using System.Threading.Tasks;
9+
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.API.Clients.Abstractions;
10+
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.API.Clients.Loggers.Responses;
11+
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Constants;
12+
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.Logger;
13+
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Extractor.Models;
14+
15+
namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.API.Clients.Loggers
16+
{
17+
public class LoggerClient : ApiClientBase, ILoggerClient
18+
{
19+
const string GetAllLoggersRequest = "{0}/subscriptions/{1}/resourceGroups/{2}/providers/Microsoft.ApiManagement/service/{3}/loggers?api-version={4}";
20+
21+
public async Task<List<LoggerTemplateResource>> GetAllAsync(ExtractorParameters extractorParameters)
22+
{
23+
var (azToken, azSubId) = await this.Auth.GetAccessToken();
24+
25+
string requestUrl = string.Format(GetAllLoggersRequest,
26+
this.BaseUrl, azSubId, extractorParameters.ResourceGroup, extractorParameters.SourceApimName, GlobalConstants.ApiVersion);
27+
28+
var response = await this.CallApiManagementAsync<GetLoggersResponse>(azToken, requestUrl);
29+
return response.Loggers;
30+
31+
}
32+
}
33+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// --------------------------------------------------------------------------
2+
// <copyright file="GetLoggersResponse.cs" company="Microsoft">
3+
// Copyright (c) Microsoft Corporation. All rights reserved.
4+
// </copyright>
5+
// --------------------------------------------------------------------------
6+
7+
using System.Collections.Generic;
8+
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.Logger;
9+
using Newtonsoft.Json;
10+
11+
namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.API.Clients.Loggers.Responses
12+
{
13+
public class GetLoggersResponse
14+
{
15+
[JsonProperty("value")]
16+
public List<LoggerTemplateResource> Loggers { get; set; }
17+
18+
public int Count { get; set; }
19+
}
20+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// --------------------------------------------------------------------------
2+
// <copyright file="NamedValuesClient.cs" company="Microsoft">
3+
// Copyright (c) Microsoft Corporation. All rights reserved.
4+
// </copyright>
5+
// --------------------------------------------------------------------------
6+
7+
using System.Collections.Generic;
8+
using System.Threading.Tasks;
9+
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.API.Clients.Abstractions;
10+
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.API.Clients.NamedValues.Responses;
11+
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Constants;
12+
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.NamedValues;
13+
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Extractor.Models;
14+
15+
namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.API.Clients.NamedValues
16+
{
17+
public class NamedValuesClient : ApiClientBase, INamedValuesClient
18+
{
19+
const string GetNamedValuesRequest = "{0}/subscriptions/{1}/resourceGroups/{2}/providers/Microsoft.ApiManagement/service/{3}/namedValues?api-version={4}";
20+
21+
public async Task<List<NamedValueTemplateResource>> GetAllAsync(ExtractorParameters extractorParameters)
22+
{
23+
var (azToken, azSubId) = await this.Auth.GetAccessToken();
24+
25+
var requestUrl = string.Format(GetNamedValuesRequest,
26+
this.BaseUrl, azSubId, extractorParameters.ResourceGroup, extractorParameters.SourceApimName, GlobalConstants.ApiVersion);
27+
28+
var response = await this.CallApiManagementAsync<GetNamedValuesResponse>(azToken, requestUrl);
29+
return response.NamedValues;
30+
}
31+
}
32+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// --------------------------------------------------------------------------
2+
// <copyright file="GetNamedValuesResponse.cs" company="Microsoft">
3+
// Copyright (c) Microsoft Corporation. All rights reserved.
4+
// </copyright>
5+
// --------------------------------------------------------------------------
6+
7+
using System.Collections.Generic;
8+
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.NamedValues;
9+
using Newtonsoft.Json;
10+
11+
namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.API.Clients.NamedValues.Responses
12+
{
13+
class GetNamedValuesResponse
14+
{
15+
[JsonProperty("value")]
16+
public List<NamedValueTemplateResource> NamedValues { get; set; }
17+
18+
public int Count { get; set; }
19+
}
20+
}

src/ArmTemplates/Common/Constants/ResourceTypeConstants.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static class ResourceTypeConstants
2323
public const string Group = "Microsoft.ApiManagement/service/groups";
2424
public const string ProductTag = "Microsoft.ApiManagement/service/products/tags";
2525
public const string ProductPolicy = "Microsoft.ApiManagement/service/products/policies";
26-
public const string Property = "Microsoft.ApiManagement/service/namedValues";
26+
public const string NamedValues = "Microsoft.ApiManagement/service/namedValues";
2727
public const string Subscription = "Microsoft.ApiManagement/service/subscriptions";
2828
public const string Tag = "Microsoft.ApiManagement/service/tags";
2929
public const string Gateway = "Microsoft.ApiManagement/service/gateways";

src/ArmTemplates/Common/FileHandlers/FileNameGenerator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ public static FileNames GenerateFileNames(string baseFileName)
2222
AuthorizationServers = $@"{baseFileName}authorizationServers.template.json",
2323
Backends = $@"\{baseFileName}backends.template.json",
2424
GlobalServicePolicy = $@"{baseFileName}globalServicePolicy.template.json",
25-
Loggers = $@"\{baseFileName}loggers.template.json",
26-
NamedValues = $@"\{baseFileName}namedValues.template.json",
25+
Loggers = $@"{baseFileName}loggers.template.json",
26+
NamedValues = $@"{baseFileName}namedValues.template.json",
2727
Tags = $@"{baseFileName}tags.template.json",
2828
Products = $@"{baseFileName}products.template.json",
2929
ProductAPIs = $@"{baseFileName}productAPIs.template.json",

src/ArmTemplates/Common/TemplateModels/DiagnosticTemplateResource.cs

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,42 +9,38 @@ public class DiagnosticTemplateResource : APITemplateSubResource
99

1010
public class DiagnosticTemplateProperties
1111
{
12-
public string alwaysLog { get; set; }
13-
public string loggerId { get; set; }
14-
public string httpCorrelationProtocol { get; set; }
15-
public string verbosity { get; set; }
16-
public bool? logClientIp { get; set; }
17-
18-
public DiagnosticTemplateSampling sampling { get; set; }
19-
public DiagnosticTemplateFrontendBackend frontend { get; set; }
20-
public DiagnosticTemplateFrontendBackend backend { get; set; }
21-
public bool? enableHttpCorrelationHeaders { get; set; }
12+
public string AlwaysLog { get; set; }
13+
public string LoggerId { get; set; }
14+
public string HttpCorrelationProtocol { get; set; }
15+
public string Verbosity { get; set; }
16+
public bool? LogClientIp { get; set; }
17+
18+
public DiagnosticTemplateSampling Sampling { get; set; }
19+
public DiagnosticTemplateFrontendBackend Frontend { get; set; }
20+
public DiagnosticTemplateFrontendBackend Backend { get; set; }
21+
public bool? EnableHttpCorrelationHeaders { get; set; }
2222
}
2323

2424
public class DiagnosticTemplateSampling
2525
{
26-
public string samplingType { get; set; }
27-
public double percentage { get; set; }
26+
public string SamplingType { get; set; }
27+
public double Percentage { get; set; }
2828
}
2929

3030
public class DiagnosticTemplateFrontendBackend
3131
{
32-
public DiagnosticTemplateRequestResponse request { get; set; }
33-
public DiagnosticTemplateRequestResponse response { get; set; }
32+
public DiagnosticTemplateRequestResponse Request { get; set; }
33+
public DiagnosticTemplateRequestResponse Response { get; set; }
3434
}
3535

3636
public class DiagnosticTemplateRequestResponse
3737
{
38-
public string[] headers { get; set; }
39-
public DiagnosticTemplateRequestResponseBody body { get; set; }
38+
public string[] Headers { get; set; }
39+
public DiagnosticTemplateRequestResponseBody Body { get; set; }
4040
}
4141

4242
public class DiagnosticTemplateRequestResponseBody
4343
{
44-
public int bytes { get; set; }
44+
public int Bytes { get; set; }
4545
}
46-
47-
48-
49-
5046
}

0 commit comments

Comments
 (0)