Skip to content

Commit

Permalink
feat(*): upgrade to NArchitecture v1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmet-cetinkaya committed Feb 15, 2024
1 parent 6734468 commit a318378
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ [EnumeratorCancellation] CancellationToken cancellationToken
private async Task downloadStarterProject(string projectName)
{
// Download zip on url
string releaseUrl = "https://github.com/kodlamaio-projects/nArchitecture/archive/refs/tags/v1.0.0.zip";
string releaseUrl = "https://github.com/kodlamaio-projects/nArchitecture/archive/refs/tags/v1.1.0.zip";
using HttpClient client = new();
using HttpResponseMessage response = await client.GetAsync(releaseUrl);
response.EnsureSuccessStatusCode();
Expand All @@ -78,7 +78,7 @@ private async Task downloadStarterProject(string projectName)
ZipFile.ExtractToDirectory(zipPath, Environment.CurrentDirectory);
File.Delete(zipPath);
Directory.Move(
sourceDirName: $"{Environment.CurrentDirectory}/nArchitecture-1.0.0",
sourceDirName: $"{Environment.CurrentDirectory}/nArchitecture-1.1.0",
$"{Environment.CurrentDirectory}/{projectName}"
);
}
Expand Down Expand Up @@ -204,6 +204,7 @@ private async Task removeSecurityMechanism(string projectName)
$"{projectSourcePath}/Application/Services/OperationClaims",
$"{projectSourcePath}/Application/Services/UserOperationClaims",
$"{projectSourcePath}/Application/Services/UsersService",
$"{projectSourcePath}/Domain/Entities",
$"{projectTestsPath}/{projectName.ToPascalCase()}.Application.Tests/Features/Auth",
$"{projectTestsPath}/{projectName.ToPascalCase()}.Application.Tests/Features/Users",
$"{projectTestsPath}/{projectName.ToPascalCase()}.Application.Tests/Mocks/Repositories/Auth",
Expand Down Expand Up @@ -258,16 +259,31 @@ await FileHelper.RemoveLinesAsync(
"using Application.Services.UsersService;",
"services.AddScoped<IAuthService, AuthManager>();",
"services.AddScoped<IAuthenticatorService, AuthenticatorManager>();",
"services.AddScoped<IUserService, UserManager>();"
"services.AddScoped<IUserService, UserManager>();",
"using NArchitecture.Core.Security.DependencyInjection;",
"services.AddSecurityServices<Guid, int>();",
}
).Any(line.Contains)
);
await FileHelper.RemoveLinesAsync(
filePath: $"{projectSourcePath}/Application/Application.csproj",
predicate: line =>
(new[] { "<PackageReference Include=\"NArchitecture.Core.Security.DependencyInjection\" Version=\"1.0.0\" />", }).Any(
line.Contains
)
);
await FileHelper.RemoveLinesAsync(
filePath: $"{projectSourcePath}/Domain/Domain.csproj",
predicate: line =>
(new[] { "<PackageReference Include=\"NArchitecture.Core.Security\" Version=\"1.1.1\" />" }).Any(line.Contains)
);
await FileHelper.RemoveLinesAsync(
filePath: $"{projectSourcePath}/Persistence/Contexts/BaseDbContext.cs",
predicate: line =>
(
new[]
{
"using Domain.Entities;",
"DbSet<EmailAuthenticator> EmailAuthenticators",
"DbSet<OperationClaim> OperationClaim",
"DbSet<OtpAuthenticator> OtpAuthenticator",
Expand Down Expand Up @@ -321,13 +337,16 @@ await FileHelper.RemoveContentAsync(
"using Microsoft.AspNetCore.Authentication.JwtBearer;\n",
"using Microsoft.IdentityModel.Tokens;\n",
"using Microsoft.OpenApi.Models;\n",
"builder.Services.AddSecurityServices();\n",
"const string tokenOptionsConfigurationSection = \"TokenOptions\";\nTokenOptions tokenOptions =\n builder.Configuration.GetSection(tokenOptionsConfigurationSection).Get<TokenOptions>()\n ?? throw new InvalidOperationException($\"\\\"{tokenOptionsConfigurationSection}\\\" section cannot found in configuration.\");\nbuilder\n .Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)\n .AddJwtBearer(options =>\n {\n options.TokenValidationParameters = new TokenValidationParameters\n {\n ValidateIssuer = true,\n ValidateAudience = true,\n ValidateLifetime = true,\n ValidIssuer = tokenOptions.Issuer,\n ValidAudience = tokenOptions.Audience,\n ValidateIssuerSigningKey = true,\n IssuerSigningKey = SecurityKeyHelper.CreateSecurityKey(tokenOptions.SecurityKey)\n };\n });\n\n",
" opt.AddSecurityDefinition(\n name: \"Bearer\",\n securityScheme: new OpenApiSecurityScheme\n {\n Name = \"Authorization\",\n Type = SecuritySchemeType.Http,\n Scheme = \"Bearer\",\n BearerFormat = \"JWT\",\n In = ParameterLocation.Header,\n Description =\n \"JWT Authorization header using the Bearer scheme. Example: \\\"Authorization: Bearer YOUR_TOKEN\\\". \\r\\n\\r\\n\"\n + \"`Enter your token in the text input below.`\"\n }\n );\n opt.OperationFilter<BearerSecurityRequirementOperationFilter>();\n",
"app.UseAuthentication();\n",
"app.UseAuthorization();\n"
}
);
await FileHelper.RemoveContentAsync(
filePath: $"{projectSourcePath}/WebAPI/WebAPI.csproj",
contents: new[] { "<PackageReference Include=\"NArchitecture.Core.Security.WebApi.Swagger\" Version=\"1.0.0\" />;", }
);
}

private async Task initializeGitRepository(string projectName)
Expand Down
2 changes: 1 addition & 1 deletion src/nArchGen/ConsoleUI/ConsoleUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<PackageIcon>n-architecture-logo.png</PackageIcon>
<RepositoryUrl>https://github.com/kodlamaio-projects/nArchitecture.Gen</RepositoryUrl>
<PackageTags>nArchitecture, nArchGen, cli, framework, tool, code generation</PackageTags>
<Version>1.0.2</Version>
<Version>1.1.0</Version>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
Expand Down

0 comments on commit a318378

Please sign in to comment.