diff --git a/src/ArmTemplates/Commands/Configurations/ExtractorConsoleAppConfiguration.cs b/src/ArmTemplates/Commands/Configurations/ExtractorConsoleAppConfiguration.cs
index 88efe63a..e3b069e7 100644
--- a/src/ArmTemplates/Commands/Configurations/ExtractorConsoleAppConfiguration.cs
+++ b/src/ArmTemplates/Commands/Configurations/ExtractorConsoleAppConfiguration.cs
@@ -3,6 +3,7 @@
// Licensed under the MIT License.
// --------------------------------------------------------------------------
+using System.Collections.Generic;
using CommandLine;
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Constants;
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Extractor.Models;
@@ -60,9 +61,6 @@ public class ExtractorConsoleAppConfiguration
[Option(longName: "baseFileName", HelpText = "Specify base name of the template file")]
public string BaseFileName { get; set; }
- // this is used only from json-file and --extractorConfig option, so no option possibility here
- public ServiceUrlProperty[] ServiceUrlParameters { get; set; }
-
[Option(longName: "paramServiceUrl", HelpText = "Parameterize serviceUrl")]
public string ParamServiceUrl { get; set; }
@@ -98,5 +96,13 @@ public class ExtractorConsoleAppConfiguration
[Option(longName: "overrideProductGuids", HelpText = "Override product GUID identification to system generated")]
public string OverrideProductGuids { get; set; }
+
+ [Option(longName: "paramApiOauth2Scope", HelpText = "Parametrize API OAuth2 scope values")]
+ public string ParamApiOauth2Scope { get; set; }
+
+ ///
+ /// Api parameter properties for overriding Api OAuth2 scope or/and Service urloverride. Available via extractor-config file only.
+ ///
+ public Dictionary ApiParameters { get; set; }
}
}
\ No newline at end of file
diff --git a/src/ArmTemplates/Common/Constants/GlobalConstants.cs b/src/ArmTemplates/Common/Constants/GlobalConstants.cs
index 4a9e51f7..dc44ac83 100644
--- a/src/ArmTemplates/Common/Constants/GlobalConstants.cs
+++ b/src/ArmTemplates/Common/Constants/GlobalConstants.cs
@@ -39,6 +39,7 @@ public static class ParameterNames
public const string LinkedTemplatesBaseUrl = "linkedTemplatesBaseUrl";
public const string NamedValueKeyVaultSecrets = "namedValueKeyVaultSecrets";
public const string BackendSettings = "backendSettings";
+ public const string ApiOauth2ScopeSettings = "apiOauth2ScopeSettings";
}
public static class ParameterPrefix
@@ -48,5 +49,6 @@ public static class ParameterPrefix
public const string Property = "Property";
public const string LogResourceId = "LogResourceId";
public const string Backend = "Backend";
+ public const string ApiOauth2Scope = "ApiOauth2Scope";
}
}
\ No newline at end of file
diff --git a/src/ArmTemplates/Common/Templates/Abstractions/TemplateParameterProperties.cs b/src/ArmTemplates/Common/Templates/Abstractions/TemplateParameterProperties.cs
index ef1a4ec8..e8c03f30 100644
--- a/src/ArmTemplates/Common/Templates/Abstractions/TemplateParameterProperties.cs
+++ b/src/ArmTemplates/Common/Templates/Abstractions/TemplateParameterProperties.cs
@@ -26,6 +26,6 @@ public TemplateParameterProperties(string metadataDescription, string type)
Description = metadataDescription,
};
this.Type = type;
- }
+ }
}
}
diff --git a/src/ArmTemplates/Common/Templates/Builders/TemplateBuilder.cs b/src/ArmTemplates/Common/Templates/Builders/TemplateBuilder.cs
index 4bbbc0d9..892bd5c8 100644
--- a/src/ArmTemplates/Common/Templates/Builders/TemplateBuilder.cs
+++ b/src/ArmTemplates/Common/Templates/Builders/TemplateBuilder.cs
@@ -60,7 +60,8 @@ public TemplateBuilder GenerateTemplateWithPresetProperties(ExtractorParameters
=> this.GenerateTemplateWithApimServiceNameProperty()
.AddPolicyProperties(extractorParameters)
.AddParameterizedServiceUrlProperty(extractorParameters)
- .AddParameterizedApiLoggerIdProperty(extractorParameters);
+ .AddParameterizedApiLoggerIdProperty(extractorParameters)
+ .AddParameterizedApiScopeProperty(extractorParameters);
public TemplateBuilder GenerateEmptyTemplate()
{
@@ -82,7 +83,7 @@ public TemplateBuilder AddPolicyProperties(ExtractorParameters extractorParamete
{
if (extractorParameters.PolicyXMLBaseUrl != null)
{
- TemplateParameterProperties policyTemplateBaseUrlParameterProperties = new TemplateParameterProperties()
+ var policyTemplateBaseUrlParameterProperties = new TemplateParameterProperties()
{
Type = "string"
};
@@ -91,7 +92,7 @@ public TemplateBuilder AddPolicyProperties(ExtractorParameters extractorParamete
if (extractorParameters.PolicyXMLSasToken != null)
{
- TemplateParameterProperties policyTemplateSasTokenParameterProperties = new TemplateParameterProperties()
+ var policyTemplateSasTokenParameterProperties = new TemplateParameterProperties()
{
Type = "string"
};
@@ -104,9 +105,9 @@ public TemplateBuilder AddPolicyProperties(ExtractorParameters extractorParamete
public TemplateBuilder AddParameterizedServiceUrlProperty(ExtractorParameters extractorParameters)
{
- if (extractorParameters.ParameterizeServiceUrl || extractorParameters.ServiceUrlParameters != null && extractorParameters.ServiceUrlParameters.Length > 0)
+ if (extractorParameters.ParameterizeServiceUrl)
{
- TemplateParameterProperties serviceUrlParamProperty = new TemplateParameterProperties()
+ var serviceUrlParamProperty = new TemplateParameterProperties()
{
Type = "object"
};
@@ -116,11 +117,25 @@ public TemplateBuilder AddParameterizedServiceUrlProperty(ExtractorParameters ex
return this;
}
+ public TemplateBuilder AddParameterizedApiScopeProperty(ExtractorParameters extractorParameters)
+ {
+ if (extractorParameters.ParametrizeApiOauth2Scope)
+ {
+ var apiScopeParameterProperty = new TemplateParameterProperties()
+ {
+ Type = "object"
+ };
+ this.template.Parameters.Add(ParameterNames.ApiOauth2ScopeSettings, apiScopeParameterProperty);
+ }
+
+ return this;
+ }
+
public TemplateBuilder AddParameterizedApiLoggerIdProperty(ExtractorParameters extractorParameters)
{
if (extractorParameters.ParameterizeApiLoggerId)
{
- TemplateParameterProperties apiLoggerProperty = new TemplateParameterProperties()
+ var apiLoggerProperty = new TemplateParameterProperties()
{
Type = "object"
};
diff --git a/src/ArmTemplates/Extractor/EntityExtractors/APIExtractor.cs b/src/ArmTemplates/Extractor/EntityExtractors/APIExtractor.cs
index d46ebcdf..05206d20 100644
--- a/src/ArmTemplates/Extractor/EntityExtractors/APIExtractor.cs
+++ b/src/ArmTemplates/Extractor/EntityExtractors/APIExtractor.cs
@@ -145,6 +145,14 @@ void SetArmTemplateValuesToApiTemplateResource(ApiTemplateResource apiResource,
apiResource.Properties.ServiceUrl = $"[parameters('{ParameterNames.ServiceUrl}').{ParameterNamingHelper.GenerateValidParameterName(originalServiceApiName, ParameterPrefix.Api)}]";
}
+ if (extractorParameters.ParametrizeApiOauth2Scope)
+ {
+ if (apiResource.Properties.AuthenticationSettings?.OAuth2?.Scope is not null)
+ {
+ apiResource.Properties.AuthenticationSettings.OAuth2.Scope = $"[parameters('{ParameterNames.ApiOauth2ScopeSettings}').{ParameterNamingHelper.GenerateValidParameterName(originalServiceApiName, ParameterPrefix.ApiOauth2Scope)}]";
+ }
+ }
+
if (apiResource.Properties.ApiVersionSetId != null)
{
apiResource.DependsOn = Array.Empty();
diff --git a/src/ArmTemplates/Extractor/EntityExtractors/BackendExtractor.cs b/src/ArmTemplates/Extractor/EntityExtractors/BackendExtractor.cs
index 1338c45c..a5e3fb77 100644
--- a/src/ArmTemplates/Extractor/EntityExtractors/BackendExtractor.cs
+++ b/src/ArmTemplates/Extractor/EntityExtractors/BackendExtractor.cs
@@ -110,7 +110,7 @@ void SaveBackendApiParametersToCache()
}
var backendApiParameters = new BackendApiParameters();
- var backendValidName = ParameterNamingHelper.GenerateValidParameterName(originalBackendName, ParameterPrefix.Diagnostic).ToLower();
+ var backendValidName = ParameterNamingHelper.GenerateValidParameterName(originalBackendName, ParameterPrefix.Backend).ToLower();
if (!string.IsNullOrEmpty(backendResource.Properties.ResourceId))
{
diff --git a/src/ArmTemplates/Extractor/EntityExtractors/MasterTemplateExtractor.cs b/src/ArmTemplates/Extractor/EntityExtractors/MasterTemplateExtractor.cs
index f1d60bdc..605a5066 100644
--- a/src/ArmTemplates/Extractor/EntityExtractors/MasterTemplateExtractor.cs
+++ b/src/ArmTemplates/Extractor/EntityExtractors/MasterTemplateExtractor.cs
@@ -262,10 +262,17 @@ static MasterTemplateResource CreateLinkedMasterTemplateResourceForApiTemplate(s
{
masterResourceTemplate.Properties.Parameters.Add(ParameterNames.ServiceUrl, new TemplateParameterProperties() { Value = $"[parameters('{ParameterNames.ServiceUrl}')]" });
}
+
if (extractorParameters.ParameterizeApiLoggerId)
{
masterResourceTemplate.Properties.Parameters.Add(ParameterNames.ApiLoggerId, new TemplateParameterProperties() { Value = $"[parameters('{ParameterNames.ApiLoggerId}')]" });
}
+
+ if (extractorParameters.ParametrizeApiOauth2Scope)
+ {
+ masterResourceTemplate.Properties.Parameters.Add(ParameterNames.ApiOauth2ScopeSettings, new TemplateParameterProperties() { Value = $"[parameters('{ParameterNames.ApiOauth2ScopeSettings}')]" });
+ }
+
return masterResourceTemplate;
}
@@ -423,6 +430,13 @@ Dictionary CreateMasterTemplateParameters(E
new TemplateParameterProperties(metadataDescription: "The settings for the Backends", type: "object"));
}
+ if (extractorParameters.ParametrizeApiOauth2Scope)
+ {
+ parameters.Add(
+ ParameterNames.ApiOauth2ScopeSettings,
+ new TemplateParameterProperties(metadataDescription: "The settings for the APIs Oauth2 Scope values", type: "object"));
+ }
+
return parameters;
}
diff --git a/src/ArmTemplates/Extractor/EntityExtractors/ParametersExtractor.cs b/src/ArmTemplates/Extractor/EntityExtractors/ParametersExtractor.cs
index 318ab497..66193c81 100644
--- a/src/ArmTemplates/Extractor/EntityExtractors/ParametersExtractor.cs
+++ b/src/ArmTemplates/Extractor/EntityExtractors/ParametersExtractor.cs
@@ -54,6 +54,7 @@ public async Task CreateMasterTemplateParameterValues(
AddPolicyParameters();
AddNamedValuesParameters();
await AddServiceUrlParameterAsync();
+ await AddApiOauth2ScopeParameterAsync();
void AddLinkedUrlParameters()
{
@@ -102,15 +103,18 @@ async Task AddServiceUrlParameterAsync()
{
var validApiName = ParameterNamingHelper.GenerateValidParameterName(apiName, ParameterPrefix.Api);
- string serviceUrl;
- if (extractorParameters.ServiceUrlParameters is null)
+ string serviceUrl = null;
+ if (extractorParameters.ApiParameters is null)
{
var apiDetails = await this.apisClient.GetSingleAsync(apiName, extractorParameters);
serviceUrl = apiDetails.Properties.ServiceUrl;
}
else
{
- serviceUrl = extractorParameters.ServiceUrlParameters.FirstOrDefault(x => x.ApiName.Equals(apiName))?.ServiceUrl;
+ if (extractorParameters.ApiParameters.ContainsKey(apiName))
+ {
+ serviceUrl = extractorParameters.ApiParameters[apiName].ServiceUrl;
+ }
}
serviceUrls.Add(validApiName, serviceUrl);
@@ -119,6 +123,42 @@ async Task AddServiceUrlParameterAsync()
parameters.Add(ParameterNames.ServiceUrl, new TemplateObjectParameterProperties() { Value = serviceUrls });
}
+ async Task AddApiOauth2ScopeParameterAsync()
+ {
+ if (!extractorParameters.ParametrizeApiOauth2Scope)
+ {
+ return;
+ }
+
+ var apiOauth2Scopes = new Dictionary();
+ foreach (var apiName in apisToExtract)
+ {
+ var apiDetails = await this.apisClient.GetSingleAsync(apiName, extractorParameters);
+
+ if (apiDetails.Properties.AuthenticationSettings?.OAuth2 is not null)
+ {
+ string apiOAuthScope = null;
+ var validApiName = ParameterNamingHelper.GenerateValidParameterName(apiName, ParameterPrefix.Api);
+
+ if (extractorParameters.ApiParameters.IsNullOrEmpty())
+ {
+ apiOAuthScope = apiDetails.Properties.AuthenticationSettings.OAuth2?.Scope;
+ }
+ else
+ {
+ if (extractorParameters.ApiParameters.ContainsKey(apiName))
+ {
+ apiOAuthScope = extractorParameters.ApiParameters[apiName].Oauth2Scope;
+ }
+ }
+
+ apiOauth2Scopes.Add(validApiName, apiOAuthScope);
+ }
+ }
+
+ parameters.Add(ParameterNames.ApiOauth2ScopeSettings, new TemplateObjectParameterProperties() { Value = apiOauth2Scopes });
+ }
+
void AddNamedValuesParameters()
{
if (!extractorParameters.ParameterizeNamedValue &&
diff --git a/src/ArmTemplates/Extractor/Models/ApiParameterProperty.cs b/src/ArmTemplates/Extractor/Models/ApiParameterProperty.cs
new file mode 100644
index 00000000..2ada032a
--- /dev/null
+++ b/src/ArmTemplates/Extractor/Models/ApiParameterProperty.cs
@@ -0,0 +1,20 @@
+// --------------------------------------------------------------------------
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+// --------------------------------------------------------------------------
+
+namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Extractor.Models
+{
+ public class ApiParameterProperty
+ {
+ public string Oauth2Scope { get; }
+
+ public string ServiceUrl { get; }
+
+ public ApiParameterProperty(string oauth2Scope, string serviceUrl)
+ {
+ this.Oauth2Scope = oauth2Scope;
+ this.ServiceUrl = serviceUrl;
+ }
+ }
+}
diff --git a/src/ArmTemplates/Extractor/Models/ExtractorParameters.cs b/src/ArmTemplates/Extractor/Models/ExtractorParameters.cs
index 39e93b88..3e39ef14 100644
--- a/src/ArmTemplates/Extractor/Models/ExtractorParameters.cs
+++ b/src/ArmTemplates/Extractor/Models/ExtractorParameters.cs
@@ -5,6 +5,7 @@
using System;
using System.Collections.Generic;
+using System.Linq;
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Commands.Configurations;
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Extensions;
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.FileHandlers;
@@ -61,8 +62,6 @@ public record ExtractorParameters
public string ApiVersionSetName { get; private set; }
- public ServiceUrlProperty[] ServiceUrlParameters { get; private set; }
-
public bool ParameterizeServiceUrl { get; private set; }
public bool ParameterizeNamedValue { get; private set; }
@@ -85,6 +84,10 @@ public record ExtractorParameters
public bool OverrideProductGuids { get; set; }
+ public bool ParametrizeApiOauth2Scope { get; set; }
+
+ public Dictionary ApiParameters { get; private set; }
+
public ExtractorParameters(ExtractorConsoleAppConfiguration extractorConfig)
{
this.SourceApimName = extractorConfig.SourceApimName;
@@ -99,8 +102,6 @@ public ExtractorParameters(ExtractorConsoleAppConfiguration extractorConfig)
this.PolicyXMLSasToken = extractorConfig.PolicyXMLSasToken;
this.ApiVersionSetName = extractorConfig.ApiVersionSetName;
this.IncludeAllRevisions = extractorConfig.IncludeAllRevisions != null && extractorConfig.IncludeAllRevisions.Equals("true", StringComparison.OrdinalIgnoreCase);
- this.ServiceUrlParameters = extractorConfig.ServiceUrlParameters;
- this.ParameterizeServiceUrl = extractorConfig.ParamServiceUrl != null && extractorConfig.ParamServiceUrl.Equals("true", StringComparison.OrdinalIgnoreCase) || extractorConfig.ServiceUrlParameters != null;
this.ParameterizeNamedValue = extractorConfig.ParamNamedValue != null && extractorConfig.ParamNamedValue.Equals("true", StringComparison.OrdinalIgnoreCase);
this.ParameterizeApiLoggerId = extractorConfig.ParamApiLoggerId != null && extractorConfig.ParamApiLoggerId.Equals("true", StringComparison.OrdinalIgnoreCase);
this.ParameterizeLogResourceId = extractorConfig.ParamLogResourceId != null && extractorConfig.ParamLogResourceId.Equals("true", StringComparison.OrdinalIgnoreCase);
@@ -115,6 +116,9 @@ public ExtractorParameters(ExtractorConsoleAppConfiguration extractorConfig)
this.ExtractGateways = extractorConfig.ExtractGateways != null && extractorConfig.ExtractGateways.Equals("true", StringComparison.OrdinalIgnoreCase);
this.OverrideGroupGuids = extractorConfig.OverrideGroupGuids != null && extractorConfig.OverrideGroupGuids.Equals("true", StringComparison.OrdinalIgnoreCase);
this.OverrideProductGuids = extractorConfig.OverrideProductGuids != null && extractorConfig.OverrideProductGuids.Equals("true", StringComparison.OrdinalIgnoreCase);
+ this.ApiParameters = extractorConfig.ApiParameters;
+ this.ParameterizeServiceUrl = extractorConfig.ParamServiceUrl != null && extractorConfig.ParamServiceUrl.Equals("true", StringComparison.OrdinalIgnoreCase) || (extractorConfig.ApiParameters != null && extractorConfig.ApiParameters.Any(x => x.Value.ServiceUrl is not null));
+ this.ParametrizeApiOauth2Scope = (extractorConfig.ParamApiOauth2Scope != null && extractorConfig.ParamApiOauth2Scope.Equals("true", StringComparison.OrdinalIgnoreCase)) || (extractorConfig.ApiParameters != null && extractorConfig.ApiParameters.Any(x => x.Value.Oauth2Scope is not null));
}
public ExtractorParameters OverrideConfiguration(ExtractorConsoleAppConfiguration overridingConfig)
@@ -137,7 +141,7 @@ public ExtractorParameters OverrideConfiguration(ExtractorConsoleAppConfiguratio
// there can be no service url parameters in overriding configuration
// this.ServiceUrlParameters = overridingConfig.ServiceUrlParameters ?? this.ServiceUrlParameters;
- this.ParameterizeServiceUrl = !string.IsNullOrEmpty(overridingConfig.ParamServiceUrl) ? overridingConfig.ParamServiceUrl.Equals("true", StringComparison.OrdinalIgnoreCase) || overridingConfig.ServiceUrlParameters != null : this.ParameterizeServiceUrl;
+ this.ParameterizeServiceUrl = !string.IsNullOrEmpty(overridingConfig.ParamServiceUrl) ? overridingConfig.ParamServiceUrl.Equals("true", StringComparison.OrdinalIgnoreCase) : this.ParameterizeServiceUrl;
this.ParameterizeNamedValue = !string.IsNullOrEmpty(overridingConfig.ParamNamedValue) ? overridingConfig.ParamNamedValue.Equals("true", StringComparison.OrdinalIgnoreCase) : this.ParameterizeNamedValue;
this.ParameterizeApiLoggerId = !string.IsNullOrEmpty(overridingConfig.ParamApiLoggerId) ? overridingConfig.ParamApiLoggerId.Equals("true", StringComparison.OrdinalIgnoreCase) : this.ParameterizeApiLoggerId;
this.ParameterizeLogResourceId = !string.IsNullOrEmpty(overridingConfig.ParamLogResourceId) ? overridingConfig.ParamLogResourceId.Equals("true", StringComparison.OrdinalIgnoreCase) : this.ParameterizeLogResourceId;
@@ -147,6 +151,7 @@ public ExtractorParameters OverrideConfiguration(ExtractorConsoleAppConfiguratio
this.SplitApis = !string.IsNullOrEmpty(overridingConfig.SplitAPIs) ? overridingConfig.SplitAPIs.Equals("true", StringComparison.OrdinalIgnoreCase) : this.SplitApis;
this.IncludeAllRevisions = !string.IsNullOrEmpty(overridingConfig.IncludeAllRevisions) ? overridingConfig.IncludeAllRevisions.Equals("true", StringComparison.OrdinalIgnoreCase) : this.IncludeAllRevisions;
this.ExtractGateways = !string.IsNullOrEmpty(overridingConfig.ExtractGateways) ? overridingConfig.ExtractGateways.Equals("true", StringComparison.OrdinalIgnoreCase) : this.ExtractGateways;
+ this.ParametrizeApiOauth2Scope = !string.IsNullOrEmpty(overridingConfig.ParamApiOauth2Scope) ? overridingConfig.ParamApiOauth2Scope.Equals("true", StringComparison.OrdinalIgnoreCase) : this.ParametrizeApiOauth2Scope;
if (!string.IsNullOrEmpty(overridingConfig.BaseFileName))
{
diff --git a/src/README.md b/src/README.md
index 1f69c8f9..f6082713 100644
--- a/src/README.md
+++ b/src/README.md
@@ -408,9 +408,8 @@ You have two choices when specifying your settings:
| baseFileName | No | Specify base file name of the template files |
| policyXMLSasToken | No | Specify sasToken for fetching policy files |
| linkedTemplatesSasToken | No | Specify sasToken for fetching linkedTemplate files |
-| serviceUrlParameters | No | Parameterize service url in advance (you can replace serviceUrl afterwards as well, you can refer example for more information). |
| paramServiceUrl | No | Set to "true" will parameterize all serviceUrl for each api and generate serviceUrl parameter to api template/parameter template/master template files |
-| paramNamedValue | No | Set to "true" will parameterize all named values and add named values parameter to property template/parameter template/mastert emplate files |
+| paramNamedValue | No | Set to "true" will parameterize all named values and add named values parameter to property template/parameter template/mastert template files |
| paramApiLoggerId | No | Set to "true" will parameterize all logger ids in all apis (within api templates), Also includes the "All API" monitoring configuration |
| paramLogResourceId | No | Set to "true" will parameterize all loggers' resource ids (within logger template)|
| serviceBaseUrl | No | Specify the base url where you want to run your extractor |
@@ -420,6 +419,8 @@ You have two choices when specifying your settings:
| extractGateways | No | Set to true will attempt to extract the Self Hosted Gateways. |
| overrideGroupGuids | No | Set to true will override the group id in output template in case it does not match with system predefined values. |
| overrideProductGuids | No | Set to true will override the product id in output template in case it does not match with system predefined values. |
+| paramApiOauth2Scope | No | Set to true will parametrize the scope values for APIs in which User authorization setting set to OAuth 2.0. |
+| apiParameters | No | Parameterize api parameters (Oauth2 Scope/Service Url) values for APIs in advance. |
#### Note
* Can not use "splitAPIs" and "apiName" at the same time, since using "apiName" only extract one API
@@ -514,7 +515,8 @@ Extract **single API with baseFileName**, use the following parameters:
"baseFileName": ""
}
```
-Extract **all APIs with serviceUrlParameters**, use the following parameters:
+
+Extract **all APIs within paramServiceUrl**, use the following parameters:
```
{
"sourceApimName": "",
@@ -523,19 +525,10 @@ Extract **all APIs with serviceUrlParameters**, use the following parameters:
"fileFolder": "",
"linkedTemplatesBaseUrl": "",
"policyXMLBaseUrl": "",
- "serviceUrlParameters": [
- {
- "apiName": "test",
- "serviceUrl": "http://url.com"
- },
- {
- "apiName": "api2",
- "serviceUrl": "http://url2.com"
- }
- ]
+ "paramServiceUrl": "true"
}
```
-Extract **all APIs within parameterServiceUrl**, use the following parameters:
+Extract **all APIs within paramNamedValue**, use the following parameters:
```
{
"sourceApimName": "",
@@ -544,10 +537,10 @@ Extract **all APIs within parameterServiceUrl**, use the following parameters:
"fileFolder": "",
"linkedTemplatesBaseUrl": "",
"policyXMLBaseUrl": "",
- "paramServiceUrl": "true"
+ "paramNamedValue": "true"
}
```
-Extract **all APIs within parameterServiceUrl**, use the following parameters:
+Extract **all APIs with predefined values for Api parameters**, using the following Extractor configuration:
```
{
"sourceApimName": "",
@@ -555,8 +548,16 @@ Extract **all APIs within parameterServiceUrl**, use the following parameters:
"resourceGroup": "",
"fileFolder": "",
"linkedTemplatesBaseUrl": "",
- "policyXMLBaseUrl": "",
- "paramNamedValue": "true"
+ "apiParameters": {
+ "api-name1": {
+ "oauth2Scope": "scope-value-1",
+ "serviceUrl": "service-url-1"
+ },
+ "api-name2": {
+ "oauth2Scope": "scope-value-2",
+ "serviceUrl": "service-url-2"
+ }
+ }
}
```
diff --git a/tests/ArmTemplates.Tests/Extractor/Abstractions/ExtractorMockerTestsBase.cs b/tests/ArmTemplates.Tests/Extractor/Abstractions/ExtractorMockerTestsBase.cs
index 1157871e..7c8ebe10 100644
--- a/tests/ArmTemplates.Tests/Extractor/Abstractions/ExtractorMockerTestsBase.cs
+++ b/tests/ArmTemplates.Tests/Extractor/Abstractions/ExtractorMockerTestsBase.cs
@@ -3,6 +3,7 @@
// Licensed under the MIT License.
// --------------------------------------------------------------------------
+using System.Collections.Generic;
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Commands.Configurations;
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Extractor.Models;
@@ -26,6 +27,7 @@ public abstract class ExtractorMockerTestsBase : TestsBase
protected const bool MockIncludeAllRevisions = true;
protected const string MockBaseFileName = "test-base-file-name";
protected static ServiceUrlProperty[] MockServiceUrlParameters = new[] { new ServiceUrlProperty("test-service-url-property-api-name", "test-service-url-property-url") };
+ protected static Dictionary MockApiParameters = new Dictionary { { "api-name-1", new ApiParameterProperty("oauth2-scope-value", "test-service-url") } };
protected const bool MockParameterizeServiceUrl = true;
protected const bool MockParameterizeNamedValue = true;
protected const bool MockParameterizeApiLoggerId = true;
@@ -65,7 +67,6 @@ protected ExtractorConsoleAppConfiguration GetMockedExtractorConsoleAppConfigura
ApiVersionSetName = apiVersionSetName,
IncludeAllRevisions = includeAllRevisions.ToString(),
BaseFileName = MockBaseFileName,
- ServiceUrlParameters = MockServiceUrlParameters,
ParamServiceUrl = MockParameterizeServiceUrl.ToString(),
ParamNamedValue = MockParameterizeNamedValue.ToString(),
ParamApiLoggerId = toParameterizeApiLoggerId.ToString(),
@@ -75,7 +76,8 @@ protected ExtractorConsoleAppConfiguration GetMockedExtractorConsoleAppConfigura
ParamNamedValuesKeyVaultSecrets = MockToParameterizeNamedValuesKeyVaultSecrets.ToString(),
OperationBatchSize = MockOperationBatchSize,
ParamBackend = MockParameterizeBackendSettings.ToString(),
- ExtractGateways = MockExtractGateways.ToString()
+ ExtractGateways = MockExtractGateways.ToString(),
+ ApiParameters = MockApiParameters
};
}
@@ -95,7 +97,6 @@ protected ExtractorConsoleAppConfiguration GetDefaultExtractorConsoleAppConfigur
string apiVersionSetName = null,
string includeAllRevisions = null,
string baseFileName = null,
- ServiceUrlProperty[] serviceUrlParameters = null,
string paramServiceUrl = null,
string paramNamedValue = null,
string paramApiLoggerId = null,
@@ -107,7 +108,9 @@ protected ExtractorConsoleAppConfiguration GetDefaultExtractorConsoleAppConfigur
string paramBackend = null,
string extractGateways = null,
string overrideGroupGuids = null,
- string overrideProductGuids = null
+ string overrideProductGuids = null,
+ string paramApiOauth2Scope = null,
+ Dictionary apiParameters = null
)
{
@@ -128,7 +131,6 @@ protected ExtractorConsoleAppConfiguration GetDefaultExtractorConsoleAppConfigur
ApiVersionSetName = apiVersionSetName,
IncludeAllRevisions = includeAllRevisions,
BaseFileName = baseFileName,
- ServiceUrlParameters = serviceUrlParameters,
ParamServiceUrl = paramServiceUrl,
ParamNamedValue = paramNamedValue,
ParamApiLoggerId = paramApiLoggerId,
@@ -140,7 +142,9 @@ protected ExtractorConsoleAppConfiguration GetDefaultExtractorConsoleAppConfigur
ParamBackend = paramBackend,
ExtractGateways = extractGateways,
OverrideGroupGuids = overrideGroupGuids,
- OverrideProductGuids = overrideProductGuids
+ OverrideProductGuids = overrideProductGuids,
+ ParamApiOauth2Scope = paramApiOauth2Scope,
+ ApiParameters = apiParameters
};
}
}
diff --git a/tests/ArmTemplates.Tests/Extractor/Configuration/ExtractorParametersCreationTests.cs b/tests/ArmTemplates.Tests/Extractor/Configuration/ExtractorParametersCreationTests.cs
index 5ebfecbb..d01f0a0d 100644
--- a/tests/ArmTemplates.Tests/Extractor/Configuration/ExtractorParametersCreationTests.cs
+++ b/tests/ArmTemplates.Tests/Extractor/Configuration/ExtractorParametersCreationTests.cs
@@ -38,7 +38,6 @@ public void ExtractorConfigValidate_NoPropertiesSet_MissingParameterException()
extractorParameters.PolicyXMLBaseUrl.Should().Be(MockPolicyXMLBaseUrl);
extractorParameters.PolicyXMLSasToken.Should().Be(MockPolicyXMLSasToken);
extractorParameters.ApiVersionSetName.Should().Be(MockApiVersionSetName);
- extractorParameters.ServiceUrlParameters.Should().Contain(MockServiceUrlParameters);
extractorParameters.ParameterizeServiceUrl.Should().Be(MockParameterizeServiceUrl);
extractorParameters.ParameterizeNamedValue.Should().Be(MockParameterizeNamedValue);
extractorParameters.ParameterizeApiLoggerId.Should().Be(MockParameterizeApiLoggerId);
@@ -47,6 +46,7 @@ public void ExtractorConfigValidate_NoPropertiesSet_MissingParameterException()
extractorParameters.ParamNamedValuesKeyVaultSecrets.Should().Be(MockToParameterizeNamedValuesKeyVaultSecrets);
extractorParameters.OperationBatchSize.Should().Be(MockOperationBatchSize);
extractorParameters.ParameterizeBackend.Should().Be(MockParameterizeBackendSettings);
+ extractorParameters.ApiParameters.Should().Contain(MockApiParameters);
// more complicated assertions with parsing arguments
extractorParameters.MultipleApiNames.Should().Contain(new[] { "test-multiple-api-1", "test-multiple-api-2" });
diff --git a/tests/ArmTemplates.Tests/Extractor/Scenarios/ApiExtractorTests.cs b/tests/ArmTemplates.Tests/Extractor/Scenarios/ApiExtractorTests.cs
index 83de1b88..d3bae30a 100644
--- a/tests/ArmTemplates.Tests/Extractor/Scenarios/ApiExtractorTests.cs
+++ b/tests/ArmTemplates.Tests/Extractor/Scenarios/ApiExtractorTests.cs
@@ -33,11 +33,28 @@ public async Task GenerateApiTemplates_ProperlyLaysTheInformation()
// arrange
var currentTestDirectory = Path.Combine(this.OutputDirectory, nameof(GenerateApiTemplates_ProperlyLaysTheInformation));
- var extractorConfig = this.GetMockedExtractorConsoleAppConfiguration(
- splitApis: false,
+ var extractorConfig = this.GetDefaultExtractorConsoleAppConfiguration(
+ multipleAPIs: string.Empty,
apiVersionSetName: string.Empty,
- multipleApiNames: string.Empty,
- includeAllRevisions: false);
+ includeAllRevisions: "false",
+ splitAPIs: "false",
+ policyXmlBaseUrl: "policyXmlUrl",
+ policyXmlSasToken: "policyXmlSasToken",
+ linkedTemplatesBaseUrl: "linkedBaseUrl",
+ linkedTemplatesSasToken: "linkedUrlToken",
+ apiParameters: new Dictionary { { "test-service-url-property-api-name", new ApiParameterProperty(null, "test-service-url-property-url") } },
+ paramServiceUrl: "true",
+ paramNamedValue: "true",
+ paramApiLoggerId: "true",
+ paramLogResourceId: "true",
+ serviceBaseUrl: "test-service-base-url",
+ notIncludeNamedValue: "true",
+ paramNamedValuesKeyVaultSecrets: "true",
+ paramBackend: "true",
+ extractGateways: "true",
+ paramApiOauth2Scope: "true"
+ );
+
var extractorParameters = new ExtractorParameters(extractorConfig);
// mocked clients
diff --git a/tests/ArmTemplates.Tests/Extractor/Scenarios/MasterTemplateExtractorTests.cs b/tests/ArmTemplates.Tests/Extractor/Scenarios/MasterTemplateExtractorTests.cs
index 3d99ee92..8e0dca9f 100644
--- a/tests/ArmTemplates.Tests/Extractor/Scenarios/MasterTemplateExtractorTests.cs
+++ b/tests/ArmTemplates.Tests/Extractor/Scenarios/MasterTemplateExtractorTests.cs
@@ -35,13 +35,29 @@ public async Task GenerateMasterTemplates_ProperlyLaysTheInformation()
// arrange
var currentTestDirectory = Path.Combine(this.OutputDirectory, nameof(GenerateMasterTemplates_ProperlyLaysTheInformation));
- var extractorConfig = this.GetMockedExtractorConsoleAppConfiguration(
- splitApis: false,
+ var extractorConfig = this.GetDefaultExtractorConsoleAppConfiguration(
+ multipleAPIs: string.Empty,
apiVersionSetName: string.Empty,
- multipleApiNames: string.Empty,
- includeAllRevisions: false,
+ includeAllRevisions: "false",
+ splitAPIs: "false",
policyXmlBaseUrl: string.Empty,
- policyXmlSasToken: string.Empty);
+ policyXmlSasToken: string.Empty,
+ linkedTemplatesBaseUrl: "linkedBaseUrl",
+ linkedTemplatesSasToken: "linkedUrlToken",
+ linkedTemplatesUrlQueryString: "queryString",
+ apiParameters: new Dictionary { { "test-service-url-property-api-name", new ApiParameterProperty(null, "test-service-url-property-url") } },
+ paramServiceUrl: "true",
+ paramNamedValue: "true",
+ paramApiLoggerId: "true",
+ paramLogResourceId: "true",
+ serviceBaseUrl: "test-service-base-url",
+ notIncludeNamedValue: "true",
+ paramNamedValuesKeyVaultSecrets: "true",
+ paramBackend: "true",
+ extractGateways: "true",
+ paramApiOauth2Scope: "true"
+ );
+
var extractorParameters = new ExtractorParameters(extractorConfig);
var masterTemplateExtractor = new MasterTemplateExtractor(
@@ -104,6 +120,7 @@ public async Task GenerateMasterTemplates_ProperlyLaysTheInformation()
masterTemplate.Parameters.Should().ContainKey(ParameterNames.BackendSettings);
masterTemplate.Parameters.Should().ContainKey(ParameterNames.PolicyXMLBaseUrl);
masterTemplate.Parameters.Should().ContainKey(ParameterNames.PolicyXMLBaseUrl);
+ masterTemplate.Parameters.Should().ContainKey(ParameterNames.ApiOauth2ScopeSettings);
masterTemplate.TypedResources.DeploymentResources.Should().HaveCount(2);
masterTemplate.Resources.Should().HaveCount(2);
diff --git a/tests/ArmTemplates.Tests/Extractor/Scenarios/ParametersExtractorTests.cs b/tests/ArmTemplates.Tests/Extractor/Scenarios/ParametersExtractorTests.cs
index 31aa6742..43125b22 100644
--- a/tests/ArmTemplates.Tests/Extractor/Scenarios/ParametersExtractorTests.cs
+++ b/tests/ArmTemplates.Tests/Extractor/Scenarios/ParametersExtractorTests.cs
@@ -12,7 +12,11 @@
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Extractor.EntityExtractors;
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Extractor.Models;
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Tests.Extractor.Abstractions;
+using System.Collections.Generic;
using Xunit;
+using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.Abstractions;
+using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.API.Clients.Abstractions;
+using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Tests.Moqs.ApiClients;
namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Tests.Extractor.Scenarios
{
@@ -23,9 +27,9 @@ public ParametersExtractorTests() : base("parameters-tests")
{
}
- ExtractorExecutor GetExtractorInstance(ExtractorParameters extractorParameters)
+ ExtractorExecutor GetExtractorInstance(ExtractorParameters extractorParameters, IApisClient apisClient = null)
{
- var parametersExtractor = new ParametersExtractor(new TemplateBuilder(), null);
+ var parametersExtractor = new ParametersExtractor(new TemplateBuilder(), apisClient);
var loggerExtractor = new LoggerExtractor(
this.GetTestLogger(),
@@ -65,7 +69,6 @@ public async Task GenerateParametersTemplates_ProperlyLaysTheInformation()
parametersTemplate.Parameters.Should().ContainKey(ParameterNames.ApimServiceName);
parametersTemplate.Parameters.Should().ContainKey(ParameterNames.PolicyXMLBaseUrl);
parametersTemplate.Parameters.Should().ContainKey(ParameterNames.PolicyXMLSasToken);
-
}
[Fact]
@@ -92,5 +95,60 @@ public async Task GenerateParametersTemplates_ProperlyLaysTheInformation_PolicyE
parametersTemplate.Parameters.Should().NotContainKey(ParameterNames.PolicyXMLBaseUrl);
parametersTemplate.Parameters.Should().NotContainKey(ParameterNames.PolicyXMLSasToken);
}
+
+ [Fact]
+ public async Task GenerateParametersTemplates_ProperlyLaysTheInformation_ApiOauth2ScopeIncludedWSettings()
+ {
+ // arrange
+ var currentTestDirectory = Path.Combine(this.OutputDirectory, nameof(GenerateParametersTemplates_ProperlyLaysTheInformation_ApiOauth2ScopeIncludedWSettings));
+
+ var extractorConfig = this.GetDefaultExtractorConsoleAppConfiguration(
+ paramApiOauth2Scope: "true",
+ apiParameters: new Dictionary { { "api-name-2", new ApiParameterProperty(oauth2Scope: "scope_value2", serviceUrl: null) } }
+ );
+ var extractorParameters = new ExtractorParameters(extractorConfig);
+
+ var extractorExecutor = this.GetExtractorInstance(extractorParameters, apisClient: MockApisClient.GetMockedApiClientWithDefaultValues());
+
+ // act
+ var parametersTemplate = await extractorExecutor.GenerateParametersTemplateAsync(new List{ "api-name-1", "api-name-2" }, null, null, null, currentTestDirectory);
+
+ File.Exists(Path.Combine(currentTestDirectory, extractorParameters.FileNames.Parameters)).Should().BeTrue();
+
+ parametersTemplate.Parameters.Should().ContainKey(ParameterNames.ApiOauth2ScopeSettings);
+ var apiOauth2ScopeSettings = (TemplateObjectParameterProperties)parametersTemplate.Parameters[ParameterNames.ApiOauth2ScopeSettings];
+ var apiOauth2ScopeSettingsValue = (Dictionary) apiOauth2ScopeSettings.Value;
+
+ apiOauth2ScopeSettingsValue.Count.Should().Be(1);
+ apiOauth2ScopeSettingsValue.Should().ContainKey("apiname2");
+ apiOauth2ScopeSettingsValue["apiname2"].Should().BeEquivalentTo("scope_value2");
+ }
+
+ [Fact]
+ public async Task GenerateParametersTemplates_ProperlyLaysTheInformation_ApiOauth2ScopeIncludedWOSettings()
+ {
+ // arrange
+ var currentTestDirectory = Path.Combine(this.OutputDirectory, nameof(GenerateParametersTemplates_ProperlyLaysTheInformation_ApiOauth2ScopeIncludedWOSettings));
+
+ var extractorConfig = this.GetDefaultExtractorConsoleAppConfiguration(
+ paramApiOauth2Scope: "true"
+ );
+ var extractorParameters = new ExtractorParameters(extractorConfig);
+ var mockedApiClient = MockApisClient.GetMockedApiClientWithDefaultValues();
+ var extractorExecutor = this.GetExtractorInstance(extractorParameters, apisClient: mockedApiClient);
+
+ // act
+ var parametersTemplate = await extractorExecutor.GenerateParametersTemplateAsync(new List { "api-name-1", "api-name-2" }, null, null, null, currentTestDirectory);
+
+ File.Exists(Path.Combine(currentTestDirectory, extractorParameters.FileNames.Parameters)).Should().BeTrue();
+
+ parametersTemplate.Parameters.Should().ContainKey(ParameterNames.ApiOauth2ScopeSettings);
+ var apiOauth2ScopeSettings = (TemplateObjectParameterProperties)parametersTemplate.Parameters[ParameterNames.ApiOauth2ScopeSettings];
+ var apiOauth2ScopeSettingsValue = (Dictionary)apiOauth2ScopeSettings.Value;
+
+ apiOauth2ScopeSettingsValue.Count.Should().Be(1);
+ apiOauth2ScopeSettingsValue.Should().ContainKey("apiname2");
+ apiOauth2ScopeSettingsValue["apiname2"].Should().BeEquivalentTo("scope-default-value-2");
+ }
}
}
diff --git a/tests/ArmTemplates.Tests/Moqs/ApiClients/MockApisClient.cs b/tests/ArmTemplates.Tests/Moqs/ApiClients/MockApisClient.cs
index ce8eb8e3..c377d397 100644
--- a/tests/ArmTemplates.Tests/Moqs/ApiClients/MockApisClient.cs
+++ b/tests/ArmTemplates.Tests/Moqs/ApiClients/MockApisClient.cs
@@ -18,50 +18,67 @@ public class MockApisClient
public const string ServiceApiName1 = "api-name-1";
public const string ServiceApiName2 = "api-name-2";
- public static ApiProperties ServiceApiProperties1 = new ApiProperties
- {
- DisplayName = "api-display-name-1",
- ApiRevision = "1",
- Description = "api-description-1",
- SubscriptionRequired = true,
- ServiceUrl = "https://azure-service-1-url.com",
- Path = "path-1",
- Protocols = new [] { "https" },
- IsCurrent = true
- };
+ public static ApiProperties GetMockedServiceApiProperties2()
+ {
+ return new ApiProperties
+ {
+ DisplayName = "api-display-name-2",
+ ApiRevision = "2",
+ Description = "api-description-2",
+ SubscriptionRequired = true,
+ ServiceUrl = "https://azure-service-2-url.com",
+ Path = "path-2",
+ Protocols = new[] { "https" },
+ IsCurrent = true,
+ AuthenticationSettings = new ApiTemplateAuthenticationSettings
+ {
+ OAuth2 = new ApiTemplateOAuth2
+ {
+ Scope = "scope-default-value-2",
+ AuthorizationServerId = "auth-server-id-1"
+ }
+ }
+ };
+ }
- public static ApiProperties ServiceApiProperties2 = new ApiProperties
+ public static ApiProperties GetMockedServiceApiProperties1()
{
- DisplayName = "api-display-name-2",
- ApiRevision = "2",
- Description = "api-description-2",
- SubscriptionRequired = true,
- ServiceUrl = "https://azure-service-2-url.com",
- Path = "path-2",
- Protocols = new[] { "https" },
- IsCurrent = true
- };
+ return new ApiProperties
+ {
+ DisplayName = "api-display-name-1",
+ ApiRevision = "1",
+ Description = "api-description-1",
+ SubscriptionRequired = true,
+ ServiceUrl = "https://azure-service-1-url.com",
+ Path = "path-1",
+ Protocols = new[] { "https" },
+ IsCurrent = true
+ };
+ }
public static IApisClient GetMockedApiClientWithDefaultValues()
{
var mockServiceApiProductsApiClient = new Mock(MockBehavior.Strict);
+ var serviceProperties1 = GetMockedServiceApiProperties1();
+ var serviceProperties2 = GetMockedServiceApiProperties2();
+
mockServiceApiProductsApiClient
.Setup(x => x.GetAllAsync(It.IsAny()))
- .ReturnsAsync(new List
+ .ReturnsAsync((ExtractorParameters _) => new List
{
new ApiTemplateResource
{
Name = ServiceApiName1,
Type = TemplateType,
- Properties = ServiceApiProperties1
+ Properties = serviceProperties1
},
new ApiTemplateResource
{
Name = ServiceApiName2,
Type = TemplateType,
- Properties = ServiceApiProperties2
+ Properties = serviceProperties2
},
});
@@ -73,37 +90,35 @@ public static IApisClient GetMockedApiClientWithDefaultValues()
{
Name = $"{gatewayName}-{ServiceApiName1}",
Type = TemplateType,
- Properties = ServiceApiProperties1
+ Properties = serviceProperties1
},
new ApiTemplateResource
{
Name = $"{gatewayName}-{ServiceApiName2}",
Type = TemplateType,
- Properties = ServiceApiProperties2
+ Properties = serviceProperties2
},
});
mockServiceApiProductsApiClient
.Setup(x => x.GetSingleAsync(It.Is((o => o.Equals(ServiceApiName1))), It.IsAny()))
- .ReturnsAsync(new ApiTemplateResource
+ .ReturnsAsync((string _, ExtractorParameters _) => new ApiTemplateResource
{
Name = ServiceApiName1,
Type = TemplateType,
- Properties = ServiceApiProperties1
+ Properties = serviceProperties1
});
mockServiceApiProductsApiClient
.Setup(x => x.GetSingleAsync(It.Is((o => o.Equals(ServiceApiName2))), It.IsAny()))
- .ReturnsAsync(new ApiTemplateResource
+ .ReturnsAsync((string _, ExtractorParameters _) => new ApiTemplateResource
{
Name = ServiceApiName2,
Type = TemplateType,
- Properties = ServiceApiProperties2
+ Properties = serviceProperties2
});
-
-
mockServiceApiProductsApiClient
.Setup(x => x.GetAllLinkedToProductAsync(It.IsAny(), It.IsAny()))
.ReturnsAsync((string productName, ExtractorParameters _) => new List
@@ -112,14 +127,14 @@ public static IApisClient GetMockedApiClientWithDefaultValues()
{
Name = ServiceApiName1,
Type = TemplateType,
- Properties = ServiceApiProperties1
+ Properties = serviceProperties1
},
new ApiTemplateResource
{
Name = ServiceApiName2,
Type = TemplateType,
- Properties = ServiceApiProperties2
+ Properties = serviceProperties2
}
});