From 31d4f701bc02135c55e2cfe5b5a917c1c92e9753 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Wed, 28 Sep 2022 00:22:14 +0300 Subject: [PATCH 1/6] Update AbpIoSourceCodeStore.cs --- .../Volo/Abp/Cli/ProjectBuilding/AbpIoSourceCodeStore.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/AbpIoSourceCodeStore.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/AbpIoSourceCodeStore.cs index 636324f0f6..e0817d8a45 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/AbpIoSourceCodeStore.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/AbpIoSourceCodeStore.cs @@ -205,7 +205,7 @@ public class AbpIoSourceCodeStore : ISourceCodeStore, ITransientDependency private async Task IsVersionExists(string templateName, string version) { - var url = $"{CliUrls.WwwAbpIo}api/download/versions?includePreReleases=true"; + var url = $"{CliUrls.WwwAbpIo}api/download/all-versions?includePreReleases=true"; try { From 25057a1ae9502f8abe8ca659e5cbf438062df129 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Thu, 29 Sep 2022 11:39:37 +0300 Subject: [PATCH 2/6] Check latest version one time per day --- .../Volo/Abp/Cli/CliConsts.cs | 14 +++--- .../Volo/Abp/Cli/CliPaths.cs | 1 + .../Volo/Abp/Cli/CliService.cs | 34 ++++++++++++- .../Volo/Abp/Cli/Commands/GetSourceCommand.cs | 5 -- .../Services/SourceCodeDownloadService.cs | 3 +- .../Volo/Abp/Cli/Memory/MemoryService.cs | 50 +++++++++++++++++++ 6 files changed, 91 insertions(+), 16 deletions(-) create mode 100644 framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Memory/MemoryService.cs diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/CliConsts.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/CliConsts.cs index ac4747de5d..1c0cd3ace4 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/CliConsts.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/CliConsts.cs @@ -1,11 +1,4 @@ -using System.Collections.Generic; -using System.Security.Policy; -using Volo.Abp.Cli.ProjectBuilding.Templates.App; -using Volo.Abp.Cli.ProjectBuilding.Templates.Microservice; -using Volo.Abp.Cli.ProjectBuilding.Templates.Module; -using Volo.Abp.Cli.ProjectBuilding.Templates.MvcModule; - -namespace Volo.Abp.Cli; +namespace Volo.Abp.Cli; public static class CliConsts { @@ -24,4 +17,9 @@ public static class CliConsts public const string AppSettingsJsonFileName = "appsettings.json"; public const string AppSettingsSecretJsonFileName = "appsettings.secrets.json"; + + public static class MemoryKeys + { + public const string LatestCliVersionCheckDate = "LatestCliVersionCheckDate"; + } } diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/CliPaths.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/CliPaths.cs index e4cec4e2c4..e2e362b4cc 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/CliPaths.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/CliPaths.cs @@ -10,6 +10,7 @@ public static class CliPaths public static string Log => Path.Combine(AbpRootPath, "cli", "logs"); public static string Root => Path.Combine(AbpRootPath, "cli"); public static string AccessToken => Path.Combine(AbpRootPath, "cli", "access-token.bin"); + public static string Memory => Path.Combine(AbpRootPath, "cli", "memory.bin"); public static string Build => Path.Combine(AbpRootPath, "build"); public static string Lic => Path.Combine(Path.GetTempPath(), Encoding.ASCII.GetString(new byte[] { 65, 98, 112, 76, 105, 99, 101, 110, 115, 101, 46, 98, 105, 110 })); diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/CliService.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/CliService.cs index f03ae851c1..9444381a0d 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/CliService.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/CliService.cs @@ -4,6 +4,7 @@ using Microsoft.Extensions.Logging.Abstractions; using NuGet.Versioning; using System; using System.Collections.Generic; +using System.Globalization; using System.IO; using System.Linq; using System.Reflection; @@ -11,14 +12,17 @@ using System.Text; using System.Threading.Tasks; using Volo.Abp.Cli.Args; using Volo.Abp.Cli.Commands; +using Volo.Abp.Cli.Memory; using Volo.Abp.Cli.NuGet; using Volo.Abp.Cli.Utils; using Volo.Abp.DependencyInjection; +using Volo.Abp.IO; namespace Volo.Abp.Cli; public class CliService : ITransientDependency { + private readonly MemoryService _memoryService; public ILogger Logger { get; set; } protected ICommandLineArgumentParser CommandLineArgumentParser { get; } protected ICommandSelector CommandSelector { get; } @@ -31,8 +35,10 @@ public class CliService : ITransientDependency ICommandSelector commandSelector, IServiceScopeFactory serviceScopeFactory, NuGetService nugetService, - ICmdHelper cmdHelper) + ICmdHelper cmdHelper, + MemoryService memoryService) { + _memoryService = memoryService; CommandLineArgumentParser = commandLineArgumentParser; CommandSelector = commandSelector; ServiceScopeFactory = serviceScopeFactory; @@ -164,6 +170,11 @@ public class CliService : ITransientDependency private async Task CheckCliVersionAsync() { + if (!await IsLatestVersionCheckExpiredAsync()) + { + return; + } + var assembly = typeof(CliService).Assembly; var toolPath = GetToolPath(assembly); var currentCliVersion = await GetCurrentCliVersionInternalAsync(assembly); @@ -187,6 +198,27 @@ public class CliService : ITransientDependency } } + private async Task IsLatestVersionCheckExpiredAsync() + { + try + { + var latestTime = await _memoryService.GetAsync(CliConsts.MemoryKeys.LatestCliVersionCheckDate); + + if (latestTime != null && DateTime.Now - DateTime.Parse(latestTime, CultureInfo.InvariantCulture) < TimeSpan.FromDays(1)) + { + return false; + } + + await _memoryService.SetAsync(CliConsts.MemoryKeys.LatestCliVersionCheckDate, DateTime.Now.ToString(CultureInfo.InvariantCulture)); + + return true; + } + catch (Exception) + { + return true; + } + } + private string GetToolPath(Assembly assembly) { if (!assembly.Location.Contains(".store")) diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/GetSourceCommand.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/GetSourceCommand.cs index 1cccf87f7b..82f5bd11ba 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/GetSourceCommand.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/GetSourceCommand.cs @@ -39,13 +39,8 @@ public class GetSourceCommand : IConsoleCommand, ITransientDependency } var version = commandLineArgs.Options.GetOrNull(Options.Version.Short, Options.Version.Long); - if (version != null) - { - Logger.LogInformation("Version: " + version); - } var outputFolder = GetOutPutFolder(commandLineArgs); - Logger.LogInformation("Output folder: " + outputFolder); var gitHubAbpLocalRepositoryPath = commandLineArgs.Options.GetOrNull(Options.GitHubAbpLocalRepositoryPath.Long); if (gitHubAbpLocalRepositoryPath != null) diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Services/SourceCodeDownloadService.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Services/SourceCodeDownloadService.cs index c9a4a7098b..bee03b9c1f 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Services/SourceCodeDownloadService.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Services/SourceCodeDownloadService.cs @@ -33,8 +33,7 @@ public class SourceCodeDownloadService : ITransientDependency public async Task DownloadModuleAsync(string moduleName, string outputFolder, string version, string gitHubAbpLocalRepositoryPath, string gitHubVoloLocalRepositoryPath, AbpCommandLineOptions options) { - Logger.LogInformation("Downloading source code of " + moduleName); - Logger.LogInformation("Version: " + (version ?? "Latest")); + Logger.LogInformation($"Downloading source code of {moduleName} (v{version ?? "Latest"})"); Logger.LogInformation("Output folder: " + outputFolder); var result = await ModuleProjectBuilder.BuildAsync( diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Memory/MemoryService.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Memory/MemoryService.cs new file mode 100644 index 0000000000..5f8b18cf99 --- /dev/null +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Memory/MemoryService.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using JetBrains.Annotations; +using Volo.Abp.DependencyInjection; +using Volo.Abp.IO; + +namespace Volo.Abp.Cli.Memory; + +public class MemoryService : ITransientDependency +{ + private const string KeyValueSeparator = "|||"; + + [ItemCanBeNull] + public async Task GetAsync(string key) + { + if (!File.Exists(CliPaths.Memory)) + { + return null; + } + + return (await FileHelper.ReadAllTextAsync(CliPaths.Memory)) + .Split(new[] { Environment.NewLine, "\n" }, StringSplitOptions.None) + .FirstOrDefault(x => x.StartsWith($"{key} "))?.Split(KeyValueSeparator).Last().Trim(); + } + + public async Task SetAsync(string key, string value) + { + if (!File.Exists(CliPaths.Memory)) + { + File.WriteAllText(CliPaths.Memory, + $"{key} {KeyValueSeparator} {value}" + ); + return; + } + + var memoryContentLines = (await FileHelper.ReadAllTextAsync(CliPaths.Memory)) + .Split(new[] { Environment.NewLine, "\n" }, StringSplitOptions.None) + .ToList(); + + memoryContentLines.RemoveAll(x => x.StartsWith(key)); + memoryContentLines.Add($"{key} {KeyValueSeparator} {value}"); + + File.WriteAllText(CliPaths.Memory, + memoryContentLines.JoinAsString(Environment.NewLine) + ); + } +} \ No newline at end of file From 69398329a64a934b1def653561f95ac8c26ec907 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Thu, 29 Sep 2022 13:00:09 +0300 Subject: [PATCH 3/6] Cli: Update memory file path --- framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/CliPaths.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/CliPaths.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/CliPaths.cs index e2e362b4cc..99ba8fbe7e 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/CliPaths.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/CliPaths.cs @@ -10,7 +10,7 @@ public static class CliPaths public static string Log => Path.Combine(AbpRootPath, "cli", "logs"); public static string Root => Path.Combine(AbpRootPath, "cli"); public static string AccessToken => Path.Combine(AbpRootPath, "cli", "access-token.bin"); - public static string Memory => Path.Combine(AbpRootPath, "cli", "memory.bin"); + public static string Memory => Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)!, "memory.bin"); public static string Build => Path.Combine(AbpRootPath, "build"); public static string Lic => Path.Combine(Path.GetTempPath(), Encoding.ASCII.GetString(new byte[] { 65, 98, 112, 76, 105, 99, 101, 110, 115, 101, 46, 98, 105, 110 })); From 6706499fa3bf048fc735139addd68f964618959e Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Thu, 29 Sep 2022 13:57:15 +0300 Subject: [PATCH 4/6] Added policy options for document discovery --- .../IdentityClientConfiguration.cs | 18 ++++++++++++++++++ .../IdentityModelAuthenticationService.cs | 4 +++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/framework/src/Volo.Abp.IdentityModel/Volo/Abp/IdentityModel/IdentityClientConfiguration.cs b/framework/src/Volo.Abp.IdentityModel/Volo/Abp/IdentityModel/IdentityClientConfiguration.cs index 325491685b..d31b95e231 100644 --- a/framework/src/Volo.Abp.IdentityModel/Volo/Abp/IdentityModel/IdentityClientConfiguration.cs +++ b/framework/src/Volo.Abp.IdentityModel/Volo/Abp/IdentityModel/IdentityClientConfiguration.cs @@ -83,6 +83,24 @@ public class IdentityClientConfiguration : Dictionary get => this.GetOrDefault(nameof(CacheAbsoluteExpiration))?.To() ?? 60 * 30; set => this[nameof(CacheAbsoluteExpiration)] = value.ToString(CultureInfo.InvariantCulture); } + + /// + /// ValidateIssuerName. + /// Default: true. + /// + public bool ValidateIssuerName { + get => this.GetOrDefault(nameof(ValidateIssuerName))?.To() ?? true; + set => this[nameof(ValidateIssuerName)] = value.ToString().ToLowerInvariant(); + } + + /// + /// ValidateEndpoints. + /// Default: true. + /// + public bool ValidateEndpoints { + get => this.GetOrDefault(nameof(ValidateEndpoints))?.To() ?? true; + set => this[nameof(ValidateEndpoints)] = value.ToString().ToLowerInvariant(); + } public IdentityClientConfiguration() { diff --git a/framework/src/Volo.Abp.IdentityModel/Volo/Abp/IdentityModel/IdentityModelAuthenticationService.cs b/framework/src/Volo.Abp.IdentityModel/Volo/Abp/IdentityModel/IdentityModelAuthenticationService.cs index 6e98a047bb..db59346465 100644 --- a/framework/src/Volo.Abp.IdentityModel/Volo/Abp/IdentityModel/IdentityModelAuthenticationService.cs +++ b/framework/src/Volo.Abp.IdentityModel/Volo/Abp/IdentityModel/IdentityModelAuthenticationService.cs @@ -127,7 +127,9 @@ public class IdentityModelAuthenticationService : IIdentityModelAuthenticationSe Address = configuration.Authority, Policy = { - RequireHttps = configuration.RequireHttps + RequireHttps = configuration.RequireHttps, + ValidateIssuerName = configuration.ValidateIssuerName, + ValidateEndpoints = configuration.ValidateEndpoints } }; IdentityModelHttpRequestMessageOptions.ConfigureHttpRequestMessage?.Invoke(request); From 2e4206413706d92ceace620e2b9257465c21843f Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Thu, 29 Sep 2022 13:59:48 +0300 Subject: [PATCH 5/6] Update IdentityClientConfiguration.cs --- .../Volo/Abp/IdentityModel/IdentityClientConfiguration.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/framework/src/Volo.Abp.IdentityModel/Volo/Abp/IdentityModel/IdentityClientConfiguration.cs b/framework/src/Volo.Abp.IdentityModel/Volo/Abp/IdentityModel/IdentityClientConfiguration.cs index d31b95e231..8faf3225ab 100644 --- a/framework/src/Volo.Abp.IdentityModel/Volo/Abp/IdentityModel/IdentityClientConfiguration.cs +++ b/framework/src/Volo.Abp.IdentityModel/Volo/Abp/IdentityModel/IdentityClientConfiguration.cs @@ -116,7 +116,9 @@ public class IdentityClientConfiguration : Dictionary string userName = null, string userPassword = null, bool requireHttps = true, - int cacheAbsoluteExpiration = 60 * 30) + int cacheAbsoluteExpiration = 60 * 30, + bool validateIssuerName = true, + bool validateEndpoints = true) { this[nameof(Authority)] = authority; this[nameof(Scope)] = scope; @@ -127,5 +129,7 @@ public class IdentityClientConfiguration : Dictionary this[nameof(UserPassword)] = userPassword; this[nameof(RequireHttps)] = requireHttps.ToString().ToLowerInvariant(); this[nameof(CacheAbsoluteExpiration)] = cacheAbsoluteExpiration.ToString(CultureInfo.InvariantCulture); + this[nameof(ValidateIssuerName)] = validateIssuerName.ToString().ToLowerInvariant(); + this[nameof(ValidateEndpoints)] = validateEndpoints.ToString().ToLowerInvariant(); } } From 57d1c06c3942d856de19bf1eae2a1a31d96064f9 Mon Sep 17 00:00:00 2001 From: Berkan Sasmaz Date: Thu, 29 Sep 2022 15:29:15 +0300 Subject: [PATCH 6/6] Update Index.cshtml.cs --- .../Pages/Public/CmsKit/Blogs/Index.cshtml.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/Index.cshtml.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/Index.cshtml.cs index f5f2cc2f7a..e83eb03153 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/Index.cshtml.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/Index.cshtml.cs @@ -27,11 +27,11 @@ public class IndexModel : CmsKitPublicPageModelBase [BindProperty(SupportsGet = true)] public Guid? TagId { get; set; } - public PagedResultDto Blogs { get; private set; } + public PagedResultDto Blogs { get; protected set; } public PagerModel PagerModel => new PagerModel(Blogs.TotalCount, Blogs.Items.Count, CurrentPage, PageSize, Request.Path.ToString()); - public CmsUserDto SelectedAuthor { get; set; } + public CmsUserDto SelectedAuthor { get; protected set; } protected IBlogPostPublicAppService BlogPostPublicAppService { get; } @@ -40,7 +40,7 @@ public class IndexModel : CmsKitPublicPageModelBase BlogPostPublicAppService = blogPostPublicAppService; } - public async Task OnGetAsync() + public virtual async Task OnGetAsync() { Blogs = await BlogPostPublicAppService.GetListAsync( BlogSlug, @@ -56,5 +56,7 @@ public class IndexModel : CmsKitPublicPageModelBase { SelectedAuthor = await BlogPostPublicAppService.GetAuthorHasBlogPostAsync(AuthorId.Value); } + + return Page(); } }