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

Commit 24d09ab

Browse files
f-alizadaFarhad Alizada
andauthored
Add extractIdentityProvider Parameter (#783)
* Add extractIdentityProviderParameter, to extract identityProviders Co-authored-by: Farhad Alizada <falizada@microsoft.com>
1 parent 75efd0c commit 24d09ab

File tree

7 files changed

+25
-3
lines changed

7 files changed

+25
-3
lines changed

src/ArmTemplates/Commands/Configurations/ExtractorConsoleAppConfiguration.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ public class ExtractorConsoleAppConfiguration
103103
[Option(longName: "extractSecrets", HelpText = "Extract secrets from the services if applies")]
104104
public string ExtractSecrets { get; set; }
105105

106+
[Option(longName: "extractIdentityProviders", HelpText = "Extract identity providers from the service if applies")]
107+
public string ExtractIdentityProviders { get; set; }
108+
106109
/// <summary>
107110
/// Api parameter properties for overriding Api OAuth2 scope or/and Service urloverride. Available via extractor-config file only.
108111
/// </summary>

src/ArmTemplates/Commands/Executors/ExtractorExecutor.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,12 @@ await FileWriter.SaveAsJsonAsync(
708708
/// <returns>generated identity provider template</returns>
709709
public async Task<Template<IdentityProviderResources>> GenerateIdentityProviderTemplateAsync(string baseFilesGenerationDirectory)
710710
{
711+
if (!this.extractorParameters.ExtractIdentityProviders)
712+
{
713+
this.logger.LogInformation($"Skipping identityProvider extraction due to the setting parameter");
714+
return Template<IdentityProviderResources>.Empty;
715+
}
716+
711717
this.logger.LogInformation("Started generation of identity provider template...");
712718

713719
var identityProviderTemplate = await this.identityProviderExtractor.GenerateIdentityProvidersTemplateAsync(this.extractorParameters);

src/ArmTemplates/Common/Templates/Abstractions/Template.Generic.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,10 @@ public class Template<TTemplateResources> : Template
3636

3737
return this.TypedResources.HasContent();
3838
}
39+
40+
public static Template<TTemplateResources> Empty => new Template<TTemplateResources>()
41+
{
42+
TypedResources = new TTemplateResources()
43+
};
3944
}
4045
}

src/ArmTemplates/Extractor/Models/ExtractorParameters.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ public record ExtractorParameters
8888

8989
public bool ExtractSecrets { get; set; }
9090

91+
public bool ExtractIdentityProviders { get; set; }
92+
9193
public Dictionary<string, ApiParameterProperty> ApiParameters { get; private set; }
9294

9395
public ExtractorParameters(ExtractorConsoleAppConfiguration extractorConfig)
@@ -122,6 +124,7 @@ public ExtractorParameters(ExtractorConsoleAppConfiguration extractorConfig)
122124
this.ParameterizeServiceUrl = extractorConfig.ParamServiceUrl != null && extractorConfig.ParamServiceUrl.Equals("true", StringComparison.OrdinalIgnoreCase) || (extractorConfig.ApiParameters != null && extractorConfig.ApiParameters.Any(x => x.Value.ServiceUrl is not null));
123125
this.ParametrizeApiOauth2Scope = (extractorConfig.ParamApiOauth2Scope != null && extractorConfig.ParamApiOauth2Scope.Equals("true", StringComparison.OrdinalIgnoreCase)) || (extractorConfig.ApiParameters != null && extractorConfig.ApiParameters.Any(x => x.Value.Oauth2Scope is not null));
124126
this.ExtractSecrets = extractorConfig.ExtractSecrets != null && extractorConfig.ExtractSecrets.Equals("true", StringComparison.OrdinalIgnoreCase);
127+
this.ExtractIdentityProviders = extractorConfig.ExtractIdentityProviders != null && extractorConfig.ExtractIdentityProviders.Equals("true", StringComparison.OrdinalIgnoreCase);
125128
}
126129

127130
public ExtractorParameters OverrideConfiguration(ExtractorConsoleAppConfiguration overridingConfig)
@@ -155,6 +158,7 @@ public ExtractorParameters OverrideConfiguration(ExtractorConsoleAppConfiguratio
155158
this.IncludeAllRevisions = !string.IsNullOrEmpty(overridingConfig.IncludeAllRevisions) ? overridingConfig.IncludeAllRevisions.Equals("true", StringComparison.OrdinalIgnoreCase) : this.IncludeAllRevisions;
156159
this.ExtractGateways = !string.IsNullOrEmpty(overridingConfig.ExtractGateways) ? overridingConfig.ExtractGateways.Equals("true", StringComparison.OrdinalIgnoreCase) : this.ExtractGateways;
157160
this.ParametrizeApiOauth2Scope = !string.IsNullOrEmpty(overridingConfig.ParamApiOauth2Scope) ? overridingConfig.ParamApiOauth2Scope.Equals("true", StringComparison.OrdinalIgnoreCase) : this.ParametrizeApiOauth2Scope;
161+
this.ExtractIdentityProviders = !string.IsNullOrEmpty(overridingConfig.ExtractIdentityProviders) ? overridingConfig.ExtractIdentityProviders.Equals("true", StringComparison.OrdinalIgnoreCase) : this.ExtractIdentityProviders;
158162

159163
if (!string.IsNullOrEmpty(overridingConfig.BaseFileName))
160164
{

src/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,7 @@ You have two choices when specifying your settings:
446446
| paramApiOauth2Scope | No | Set to true will parametrize the scope values for APIs in which User authorization setting set to OAuth 2.0. |
447447
| apiParameters | No | Parameterize api parameters (Oauth2 Scope/Service Url) values for APIs in advance. |
448448
| exctractSecrets | No | By default false. If set to "true" secrets will be extracted as well and parameters templated will be supplied with actual secret values. Currently applies to identityProvider service. |
449+
| extractIdentityProviders | No | By default false. Set to true will attempt to extract the identity providers from service. |
449450

450451

451452
#### Note

tests/ArmTemplates.Tests/Extractor/Abstractions/ExtractorMockerTestsBase.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ protected ExtractorConsoleAppConfiguration GetDefaultExtractorConsoleAppConfigur
111111
string overrideProductGuids = null,
112112
string paramApiOauth2Scope = null,
113113
Dictionary<string, ApiParameterProperty> apiParameters = null,
114-
string extractSecrets = null
114+
string extractSecrets = null,
115+
string extractIdentityProviders = null
115116
)
116117
{
117118

@@ -146,7 +147,8 @@ protected ExtractorConsoleAppConfiguration GetDefaultExtractorConsoleAppConfigur
146147
OverrideProductGuids = overrideProductGuids,
147148
ParamApiOauth2Scope = paramApiOauth2Scope,
148149
ApiParameters = apiParameters,
149-
ExtractSecrets = extractSecrets
150+
ExtractSecrets = extractSecrets,
151+
ExtractIdentityProviders = extractIdentityProviders
150152
};
151153
}
152154
}

tests/ArmTemplates.Tests/Extractor/Scenarios/IdentityProviderExtractorTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ public async Task GenerateIdentityProviderTemplates_ProperlyLaysTheInformation()
3232
// arrange
3333
var currentTestDirectory = Path.Combine(this.OutputDirectory, nameof(GenerateIdentityProviderTemplates_ProperlyLaysTheInformation));
3434

35-
var extractorConfig = this.GetDefaultExtractorConsoleAppConfiguration();
35+
var extractorConfig = this.GetDefaultExtractorConsoleAppConfiguration(
36+
extractIdentityProviders: "true");
3637
var extractorParameters = new ExtractorParameters(extractorConfig);
3738

3839
var identityProviderNames = new List<string>()

0 commit comments

Comments
 (0)