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

Commit

Permalink
Add extractIdentityProvider Parameter (#783)
Browse files Browse the repository at this point in the history
* Add extractIdentityProviderParameter, to extract identityProviders

Co-authored-by: Farhad Alizada <[email protected]>
  • Loading branch information
f-alizada and Farhad Alizada authored Jul 27, 2022
1 parent 75efd0c commit 24d09ab
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ public class ExtractorConsoleAppConfiguration
[Option(longName: "extractSecrets", HelpText = "Extract secrets from the services if applies")]
public string ExtractSecrets { get; set; }

[Option(longName: "extractIdentityProviders", HelpText = "Extract identity providers from the service if applies")]
public string ExtractIdentityProviders { get; set; }

/// <summary>
/// Api parameter properties for overriding Api OAuth2 scope or/and Service urloverride. Available via extractor-config file only.
/// </summary>
Expand Down
6 changes: 6 additions & 0 deletions src/ArmTemplates/Commands/Executors/ExtractorExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,12 @@ await FileWriter.SaveAsJsonAsync(
/// <returns>generated identity provider template</returns>
public async Task<Template<IdentityProviderResources>> GenerateIdentityProviderTemplateAsync(string baseFilesGenerationDirectory)
{
if (!this.extractorParameters.ExtractIdentityProviders)
{
this.logger.LogInformation($"Skipping identityProvider extraction due to the setting parameter");
return Template<IdentityProviderResources>.Empty;
}

this.logger.LogInformation("Started generation of identity provider template...");

var identityProviderTemplate = await this.identityProviderExtractor.GenerateIdentityProvidersTemplateAsync(this.extractorParameters);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,10 @@ public class Template<TTemplateResources> : Template

return this.TypedResources.HasContent();
}

public static Template<TTemplateResources> Empty => new Template<TTemplateResources>()
{
TypedResources = new TTemplateResources()
};
}
}
4 changes: 4 additions & 0 deletions src/ArmTemplates/Extractor/Models/ExtractorParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ public record ExtractorParameters

public bool ExtractSecrets { get; set; }

public bool ExtractIdentityProviders { get; set; }

public Dictionary<string, ApiParameterProperty> ApiParameters { get; private set; }

public ExtractorParameters(ExtractorConsoleAppConfiguration extractorConfig)
Expand Down Expand Up @@ -122,6 +124,7 @@ public ExtractorParameters(ExtractorConsoleAppConfiguration extractorConfig)
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));
this.ExtractSecrets = extractorConfig.ExtractSecrets != null && extractorConfig.ExtractSecrets.Equals("true", StringComparison.OrdinalIgnoreCase);
this.ExtractIdentityProviders = extractorConfig.ExtractIdentityProviders != null && extractorConfig.ExtractIdentityProviders.Equals("true", StringComparison.OrdinalIgnoreCase);
}

public ExtractorParameters OverrideConfiguration(ExtractorConsoleAppConfiguration overridingConfig)
Expand Down Expand Up @@ -155,6 +158,7 @@ public ExtractorParameters OverrideConfiguration(ExtractorConsoleAppConfiguratio
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;
this.ExtractIdentityProviders = !string.IsNullOrEmpty(overridingConfig.ExtractIdentityProviders) ? overridingConfig.ExtractIdentityProviders.Equals("true", StringComparison.OrdinalIgnoreCase) : this.ExtractIdentityProviders;

if (!string.IsNullOrEmpty(overridingConfig.BaseFileName))
{
Expand Down
1 change: 1 addition & 0 deletions src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ You have two choices when specifying your settings:
| 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. |
| 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. |
| extractIdentityProviders | No | By default false. Set to true will attempt to extract the identity providers from service. |


#### Note
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ protected ExtractorConsoleAppConfiguration GetDefaultExtractorConsoleAppConfigur
string overrideProductGuids = null,
string paramApiOauth2Scope = null,
Dictionary<string, ApiParameterProperty> apiParameters = null,
string extractSecrets = null
string extractSecrets = null,
string extractIdentityProviders = null
)
{

Expand Down Expand Up @@ -146,7 +147,8 @@ protected ExtractorConsoleAppConfiguration GetDefaultExtractorConsoleAppConfigur
OverrideProductGuids = overrideProductGuids,
ParamApiOauth2Scope = paramApiOauth2Scope,
ApiParameters = apiParameters,
ExtractSecrets = extractSecrets
ExtractSecrets = extractSecrets,
ExtractIdentityProviders = extractIdentityProviders
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public async Task GenerateIdentityProviderTemplates_ProperlyLaysTheInformation()
// arrange
var currentTestDirectory = Path.Combine(this.OutputDirectory, nameof(GenerateIdentityProviderTemplates_ProperlyLaysTheInformation));

var extractorConfig = this.GetDefaultExtractorConsoleAppConfiguration();
var extractorConfig = this.GetDefaultExtractorConsoleAppConfiguration(
extractIdentityProviders: "true");
var extractorParameters = new ExtractorParameters(extractorConfig);

var identityProviderNames = new List<string>()
Expand Down

0 comments on commit 24d09ab

Please sign in to comment.