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

Commit 76e7b5e

Browse files
odaibertnzthiago
authored andcommitted
Extractor features (#101)
* add schemas to readme * cleanup readme, include space for extractor * fix table of contents routing * extract diagnostic resource and add to template * update to version 2018-06-01-preview, update creator config values * remove name property from creator diagnostic * extract loggers, enable logger and diagnostic iterative deployment * update creator readme * pull named values and substitute them for previously hidden credentials * add validation on additional creator config properties, write tests * refactor - update file structure, namespaces, remove dup classes, * comment out representations on req/res operation schema until schema templates are extracted * Odaibert/operations policies and products (#100) * Added Products extractor to [APIM-NAME]-products.json file * Finished: - [Extractor] Relationship/Association between APIs and products are not extracted #85 - [Extractor] Allow users to specify if they want to extract all APIs or a single API (using apiId) #78 - [Extractor] Extract policies at the operation level #80 - [Extractor] Split APIs into multiple API templates #77
1 parent 7edbe81 commit 76e7b5e

File tree

81 files changed

+1513
-860
lines changed

Some content is hidden

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

81 files changed

+1513
-860
lines changed

src/APIM_ARMTemplate/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,6 @@ msbuild.wrn
3737

3838
# Visual Studio 2015
3939
.vs/
40+
41+
# Local Testing
42+
*validTesting.yml

src/APIM_ARMTemplate/README.md

Lines changed: 181 additions & 61 deletions
Large diffs are not rendered by default.

src/APIM_ARMTemplate/apimtemplate.test/CmdLine/CreateTests.cs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
using Xunit;
33
using McMaster.Extensions.CommandLineUtils;
44
using System.IO;
5+
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Create;
56

6-
namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates
7+
namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Test
78
{
89
public class CreateTests
910
{
@@ -110,5 +111,41 @@ public void ShouldFailWithInvalidLinking()
110111
var ex = Assert.ThrowsAny<CommandParsingException>(() => createCommand.Execute(args));
111112
Assert.Contains("LinkTemplatesBaseUrl is required for linked templates", ex.Message);
112113
}
114+
115+
[Fact]
116+
public void ShouldFailWithInvalidVersionSetDisplayName()
117+
{
118+
var createCommand = new CreateCommand();
119+
string[] args = new string[] { "--configFile", String.Concat(this.configExamplesFolder, "invalidVersionSetDisplayName.yml") };
120+
var ex = Assert.ThrowsAny<CommandParsingException>(() => createCommand.Execute(args));
121+
Assert.Contains("Display name is required if an API Version Set is provided", ex.Message);
122+
}
123+
124+
[Fact]
125+
public void ShouldFailWithInvalidVersionSetVersioningScheme()
126+
{
127+
var createCommand = new CreateCommand();
128+
string[] args = new string[] { "--configFile", String.Concat(this.configExamplesFolder, "invalidVersionSetVersioningScheme.yml") };
129+
var ex = Assert.ThrowsAny<CommandParsingException>(() => createCommand.Execute(args));
130+
Assert.Contains("Versioning scheme is required if an API Version Set is provided", ex.Message);
131+
}
132+
133+
[Fact]
134+
public void ShouldFailWithInvalidOperationPolicy()
135+
{
136+
var createCommand = new CreateCommand();
137+
string[] args = new string[] { "--configFile", String.Concat(this.configExamplesFolder, "invalidOperationPolicy.yml") };
138+
var ex = Assert.ThrowsAny<CommandParsingException>(() => createCommand.Execute(args));
139+
Assert.Contains("Policy XML is required if an API operation is provided", ex.Message);
140+
}
141+
142+
[Fact]
143+
public void ShouldFailWithInvalidDiagnosticLoggerId()
144+
{
145+
var createCommand = new CreateCommand();
146+
string[] args = new string[] { "--configFile", String.Concat(this.configExamplesFolder, "invalidDiagnosticLoggerId.yml") };
147+
var ex = Assert.ThrowsAny<CommandParsingException>(() => createCommand.Execute(args));
148+
Assert.Contains("LoggerId is required if an API diagnostic is provided", ex.Message);
149+
}
113150
}
114151
}

src/APIM_ARMTemplate/apimtemplate.test/CmdLine/ExtractTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using McMaster.Extensions.CommandLineUtils;
44

55

6-
namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates
6+
namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Test
77
{
88
public class ExtractTests
99
{

src/APIM_ARMTemplate/apimtemplate.test/Creator/FileHandlerTests/FileWriterTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
using Xunit;
33
using Newtonsoft.Json.Linq;
44
using System;
5-
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Create;
5+
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common;
66

7-
namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates
7+
namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Test
88
{
99
public class FileWriterTests
1010
{

src/APIM_ARMTemplate/apimtemplate.test/Creator/FileHandlerTests/OpenAPISpecReaderTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
using Xunit;
2-
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Create;
32
using Microsoft.OpenApi.Models;
3+
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common;
44

5-
namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates
5+
namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Test
66
{
77
public class OpenAPISpecReaderTests
88
{

src/APIM_ARMTemplate/apimtemplate.test/Creator/TemplateCreatorFactories/APITemplateCreatorFactory.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-

2-
namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Create
1+
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common;
2+
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Create;
3+
4+
namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Test
35
{
46
public class APITemplateCreatorFactory
57
{

src/APIM_ARMTemplate/apimtemplate.test/Creator/TemplateCreatorFactories/APIVersionSetTemplateCreatorFactory.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-

2-
namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Create
1+
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Create;
2+
3+
namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Test
34
{
45
public class APIVersionSetTemplateCreatorFactory
56
{

src/APIM_ARMTemplate/apimtemplate.test/Creator/TemplateCreatorFactories/MasterTemplateCreatorFactory.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-

2-
namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Create
1+
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Create;
2+
3+
namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Test
34
{
45
public class MasterTemplateCreatorFactory
56
{

src/APIM_ARMTemplate/apimtemplate.test/Creator/TemplateCreatorFactories/PolicyTemplateCreatorFactory.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-

2-
namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Create
1+
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common;
2+
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Create;
3+
4+
namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Test
35
{
46
public class PolicyTemplateCreatorFactory
57
{

src/APIM_ARMTemplate/apimtemplate.test/Creator/TemplateCreatorTests/APITemplateCreatorTests.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
using Microsoft.OpenApi.Models;
2-
using System;
3-
using System.IO;
42
using Xunit;
3+
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common;
4+
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Create;
55

6-
namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Create
6+
namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Test
77
{
88
public class APITemplateCreatorTests
99
{
@@ -23,6 +23,7 @@ public async void ShouldCreateInitialAPITemplateResourceFromCreatorConfig()
2323
revision = "revision",
2424
revisionDescription = "revisionDescription",
2525
suffix = "suffix",
26+
subscriptionRequired = true,
2627
authenticationSettings = new APITemplateAuthenticationSettings()
2728
{
2829
oAuth2 = new APITemplateOAuth2()
@@ -53,6 +54,7 @@ public async void ShouldCreateInitialAPITemplateResourceFromCreatorConfig()
5354
Assert.Equal(creatorConfig.api.revision, apiTemplateResource.properties.apiRevision);
5455
Assert.Equal(creatorConfig.api.revisionDescription, apiTemplateResource.properties.apiRevisionDescription);
5556
Assert.Equal(creatorConfig.api.suffix, apiTemplateResource.properties.path);
57+
Assert.Equal(creatorConfig.api.subscriptionRequired, apiTemplateResource.properties.subscriptionRequired);
5658
Assert.Equal(creatorConfig.api.authenticationSettings.oAuth2.authorizationServerId, apiTemplateResource.properties.authenticationSettings.oAuth2.authorizationServerId);
5759
Assert.Equal(creatorConfig.api.authenticationSettings.oAuth2.scope, apiTemplateResource.properties.authenticationSettings.oAuth2.scope);
5860
Assert.Equal(creatorConfig.api.authenticationSettings.openid.openidProviderId, apiTemplateResource.properties.authenticationSettings.openid.openidProviderId);

src/APIM_ARMTemplate/apimtemplate.test/Creator/TemplateCreatorTests/APIVersionSetTemplateCreatorTests.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using Xunit;
2+
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common;
3+
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Create;
24

3-
namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Create
5+
namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Test
46
{
57
public class APIVersionSetTemplateCreatorTests
68
{
Lines changed: 56 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using Xunit;
2+
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common;
3+
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Create;
24

3-
namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Create
5+
namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Test
46
{
57
public class DiagnosticTemplateCreatorTests
68
{
@@ -13,56 +15,56 @@ public void ShouldCreateDiagnosticTemplateResourceFromCreatorConfig()
1315
{
1416
api = new APIConfig()
1517
{
16-
name = "name"
17-
},
18-
diagnostic = new DiagnosticTemplateProperties()
19-
{
20-
alwaysLog = "alwaysLog",
21-
loggerId = "loggerId",
22-
sampling = new DiagnosticTemplateSampling()
23-
{
24-
samplingType = "samplingType",
25-
percentage = 100
26-
},
27-
frontend = new DiagnosticTemplateFrontendBackend()
18+
diagnostic = new DiagnosticConfig()
2819
{
29-
request = new DiagnosticTemplateRequestResponse()
20+
name = "applicationinsights",
21+
alwaysLog = "alwaysLog",
22+
loggerId = "loggerId",
23+
sampling = new DiagnosticTemplateSampling()
3024
{
31-
headers = new string[] { "frontendrequestheader" },
32-
body = new DiagnosticTemplateRequestResponseBody()
33-
{
34-
bytes = 512
35-
}
25+
samplingType = "samplingType",
26+
percentage = 100
3627
},
37-
response = new DiagnosticTemplateRequestResponse()
28+
frontend = new DiagnosticTemplateFrontendBackend()
3829
{
39-
headers = new string[] { "frontendresponseheader" },
40-
body = new DiagnosticTemplateRequestResponseBody()
30+
request = new DiagnosticTemplateRequestResponse()
4131
{
42-
bytes = 512
43-
}
44-
}
45-
},
46-
backend = new DiagnosticTemplateFrontendBackend()
47-
{
48-
request = new DiagnosticTemplateRequestResponse()
49-
{
50-
headers = new string[] { "backendrequestheader" },
51-
body = new DiagnosticTemplateRequestResponseBody()
32+
headers = new string[] { "frontendrequestheader" },
33+
body = new DiagnosticTemplateRequestResponseBody()
34+
{
35+
bytes = 512
36+
}
37+
},
38+
response = new DiagnosticTemplateRequestResponse()
5239
{
53-
bytes = 512
40+
headers = new string[] { "frontendresponseheader" },
41+
body = new DiagnosticTemplateRequestResponseBody()
42+
{
43+
bytes = 512
44+
}
5445
}
5546
},
56-
response = new DiagnosticTemplateRequestResponse()
47+
backend = new DiagnosticTemplateFrontendBackend()
5748
{
58-
headers = new string[] { "backendresponseheader" },
59-
body = new DiagnosticTemplateRequestResponseBody()
49+
request = new DiagnosticTemplateRequestResponse()
6050
{
61-
bytes = 512
51+
headers = new string[] { "backendrequestheader" },
52+
body = new DiagnosticTemplateRequestResponseBody()
53+
{
54+
bytes = 512
55+
}
56+
},
57+
response = new DiagnosticTemplateRequestResponse()
58+
{
59+
headers = new string[] { "backendresponseheader" },
60+
body = new DiagnosticTemplateRequestResponseBody()
61+
{
62+
bytes = 512
63+
}
6264
}
63-
}
64-
},
65-
enableHttpCorrelationHeaders = true
65+
},
66+
enableHttpCorrelationHeaders = true
67+
}
6668
}
6769
};
6870

@@ -71,21 +73,21 @@ public void ShouldCreateDiagnosticTemplateResourceFromCreatorConfig()
7173
DiagnosticTemplateResource diagnosticTemplateResource = diagnosticTemplateCreator.CreateAPIDiagnosticTemplateResource(creatorConfig, dependsOn);
7274

7375
// assert
74-
Assert.Equal($"[concat(parameters('ApimServiceName'), '/{creatorConfig.api.name}/diagnostic')]", diagnosticTemplateResource.name);
76+
Assert.Equal($"[concat(parameters('ApimServiceName'), '/{creatorConfig.api.name}/{creatorConfig.api.diagnostic.name}')]", diagnosticTemplateResource.name);
7577
Assert.Equal(dependsOn, diagnosticTemplateResource.dependsOn);
76-
Assert.Equal(creatorConfig.diagnostic.alwaysLog, diagnosticTemplateResource.properties.alwaysLog);
77-
Assert.Equal(creatorConfig.diagnostic.loggerId, diagnosticTemplateResource.properties.loggerId);
78-
Assert.Equal(creatorConfig.diagnostic.enableHttpCorrelationHeaders, diagnosticTemplateResource.properties.enableHttpCorrelationHeaders);
79-
Assert.Equal(creatorConfig.diagnostic.sampling.samplingType, diagnosticTemplateResource.properties.sampling.samplingType);
80-
Assert.Equal(creatorConfig.diagnostic.sampling.percentage, diagnosticTemplateResource.properties.sampling.percentage);
81-
Assert.Equal(creatorConfig.diagnostic.frontend.request.headers, diagnosticTemplateResource.properties.frontend.request.headers);
82-
Assert.Equal(creatorConfig.diagnostic.frontend.request.body.bytes, diagnosticTemplateResource.properties.frontend.request.body.bytes);
83-
Assert.Equal(creatorConfig.diagnostic.frontend.response.headers, diagnosticTemplateResource.properties.frontend.response.headers);
84-
Assert.Equal(creatorConfig.diagnostic.frontend.response.body.bytes, diagnosticTemplateResource.properties.frontend.response.body.bytes);
85-
Assert.Equal(creatorConfig.diagnostic.backend.request.headers, diagnosticTemplateResource.properties.backend.request.headers);
86-
Assert.Equal(creatorConfig.diagnostic.backend.request.body.bytes, diagnosticTemplateResource.properties.backend.request.body.bytes);
87-
Assert.Equal(creatorConfig.diagnostic.backend.response.headers, diagnosticTemplateResource.properties.backend.response.headers);
88-
Assert.Equal(creatorConfig.diagnostic.backend.response.body.bytes, diagnosticTemplateResource.properties.backend.response.body.bytes);
78+
Assert.Equal(creatorConfig.api.diagnostic.alwaysLog, diagnosticTemplateResource.properties.alwaysLog);
79+
Assert.Equal(creatorConfig.api.diagnostic.loggerId, diagnosticTemplateResource.properties.loggerId);
80+
Assert.Equal(creatorConfig.api.diagnostic.enableHttpCorrelationHeaders, diagnosticTemplateResource.properties.enableHttpCorrelationHeaders);
81+
Assert.Equal(creatorConfig.api.diagnostic.sampling.samplingType, diagnosticTemplateResource.properties.sampling.samplingType);
82+
Assert.Equal(creatorConfig.api.diagnostic.sampling.percentage, diagnosticTemplateResource.properties.sampling.percentage);
83+
Assert.Equal(creatorConfig.api.diagnostic.frontend.request.headers, diagnosticTemplateResource.properties.frontend.request.headers);
84+
Assert.Equal(creatorConfig.api.diagnostic.frontend.request.body.bytes, diagnosticTemplateResource.properties.frontend.request.body.bytes);
85+
Assert.Equal(creatorConfig.api.diagnostic.frontend.response.headers, diagnosticTemplateResource.properties.frontend.response.headers);
86+
Assert.Equal(creatorConfig.api.diagnostic.frontend.response.body.bytes, diagnosticTemplateResource.properties.frontend.response.body.bytes);
87+
Assert.Equal(creatorConfig.api.diagnostic.backend.request.headers, diagnosticTemplateResource.properties.backend.request.headers);
88+
Assert.Equal(creatorConfig.api.diagnostic.backend.request.body.bytes, diagnosticTemplateResource.properties.backend.request.body.bytes);
89+
Assert.Equal(creatorConfig.api.diagnostic.backend.response.headers, diagnosticTemplateResource.properties.backend.response.headers);
90+
Assert.Equal(creatorConfig.api.diagnostic.backend.response.body.bytes, diagnosticTemplateResource.properties.backend.response.body.bytes);
8991
}
9092
}
9193
}

src/APIM_ARMTemplate/apimtemplate.test/Creator/TemplateCreatorTests/MasterTemplateCreatorTests.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using System.Collections.Generic;
22
using Xunit;
3+
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common;
4+
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Create;
35

4-
namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Create
6+
namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Test
57
{
68
public class MasterTemplateCreatorTests
79
{

src/APIM_ARMTemplate/apimtemplate.test/Creator/TemplateCreatorTests/PolicyTemplateCreatorTests.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using System.Collections.Generic;
22
using Xunit;
3+
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common;
4+
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Create;
35

4-
namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Create
6+
namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Test
57
{
68
public class PolicyTemplateCreatorTests
79
{

src/APIM_ARMTemplate/apimtemplate.test/Creator/TemplateCreatorTests/ProductAPITemplateCreatorTests.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using System.Collections.Generic;
22
using Xunit;
3+
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common;
4+
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Create;
35

4-
namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Create
6+
namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Test
57
{
68
public class ProductAPITemplateCreatorTests
79
{

0 commit comments

Comments
 (0)