Add `RandomizeAuthServerPassPhraseStep`.

pull/16268/head
maliming 3 years ago
parent 121e923c0a
commit f8f405e744
No known key found for this signature in database
GPG Key ID: A646B9CB645ECEA4

@ -107,6 +107,7 @@ public abstract class AppNoLayersTemplateBase : AppTemplateBase
steps.Add(new RemoveFolderStep("/aspnet-core/MyCompanyName.MyProjectName.Host/Migrations"));
RandomizeSslPorts(context, steps);
RandomizeStringEncryption(context, steps);
RandomizeAuthServerPassPhrase(context, steps);
UpdateNuGetConfig(context, steps);
ChangeConnectionString(context, steps);
ConfigureDockerFiles(context, steps);

@ -41,6 +41,7 @@ public abstract class AppTemplateBase : TemplateInfo
RemoveUnnecessaryPorts(context, steps);
RandomizeSslPorts(context, steps);
RandomizeStringEncryption(context, steps);
RandomizeAuthServerPassPhrase(context, steps);
UpdateNuGetConfig(context, steps);
ConfigureDockerFiles(context, steps);
ChangeConnectionString(context, steps);
@ -610,6 +611,11 @@ public abstract class AppTemplateBase : TemplateInfo
steps.Add(new RandomizeStringEncryptionStep());
}
protected static void RandomizeAuthServerPassPhrase(ProjectBuildContext context, List<ProjectBuildPipelineStep> steps)
{
steps.Add(new RandomizeAuthServerPassPhraseStep());
}
protected void UpdateNuGetConfig(ProjectBuildContext context, List<ProjectBuildPipelineStep> steps)
{
steps.Add(new UpdateNuGetConfigStep("/aspnet-core/NuGet.Config"));

@ -38,6 +38,7 @@ public abstract class MicroserviceServiceTemplateBase : TemplateInfo
DeleteUnrelatedUiProject(context, steps);
SetRandomPortForHostProject(context, steps);
RandomizeStringEncryption(context, steps);
RandomizeAuthServerPassPhrase(context, steps);
return steps;
}
@ -69,4 +70,9 @@ public abstract class MicroserviceServiceTemplateBase : TemplateInfo
{
steps.Add(new MicroserviceServiceStringEncryptionStep());
}
private static void RandomizeAuthServerPassPhrase(ProjectBuildContext context, List<ProjectBuildPipelineStep> steps)
{
steps.Add(new RandomizeAuthServerPassPhraseStep());
}
}

@ -23,6 +23,7 @@ public abstract class MicroserviceTemplateBase : TemplateInfo
DeleteUnrelatedProjects(context, steps);
RandomizeStringEncryption(context, steps);
RandomizeAuthServerPassPhrase(context, steps);
UpdateNuGetConfig(context, steps);
ConfigureTheme(context, steps);
@ -215,4 +216,9 @@ public abstract class MicroserviceTemplateBase : TemplateInfo
{
steps.Add(new UpdateNuGetConfigStep("/NuGet.Config"));
}
private static void RandomizeAuthServerPassPhrase(ProjectBuildContext context, List<ProjectBuildPipelineStep> steps)
{
steps.Add(new RandomizeAuthServerPassPhraseStep());
}
}

@ -0,0 +1,35 @@
using System;
using System.Linq;
using Volo.Abp.Cli.ProjectBuilding.Building;
namespace Volo.Abp.Cli.ProjectBuilding.Templates;
public class RandomizeAuthServerPassPhraseStep : ProjectBuildPipelineStep
{
protected const string DefaultPassPhrase = "00000000-0000-0000-0000-000000000000";
public override void Execute(ProjectBuildContext context)
{
var appSettings = context.Files
.Where(x => !x.IsDirectory)
.Where(x => x.Content.IndexOf(DefaultPassPhrase, StringComparison.InvariantCultureIgnoreCase) >= 0)
.ToList();
var randomPassPhrase = Guid.NewGuid().ToString("D");
foreach (var appSetting in appSettings)
{
appSetting.NormalizeLineEndings();
var appSettingLines = appSetting.GetLines();
for (var i = 0; i < appSettingLines.Length; i++)
{
if (appSettingLines[i].Contains(DefaultPassPhrase))
{
appSettingLines[i] = appSettingLines[i].Replace(DefaultPassPhrase, randomPassPhrase);
}
}
appSetting.SetLines(appSettingLines);
}
}
}
Loading…
Cancel
Save