From ae114c68db12d3832b9e982ae7ddf5c0dd1f039a Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Sun, 15 Aug 2021 01:50:07 +0100 Subject: [PATCH] refacts --- README.md | 2 +- src/isn/Constants.cs | 2 +- src/isn/IDataProtector.cs | 34 +++++++++++++++++++ src/isn/Program.Commands.cs | 33 +++++++++++++++--- src/isn/Program.cs | 4 ++- src/isn/PushCommand.cs | 2 +- src/isn/PushReport.cs | 2 +- src/isn/UploadFilesToServerUsingWebRequest.cs | 2 +- src/isnd/Controllers/ApiKeysController.cs | 10 +++--- .../Controllers/PackagesController.Put.cs | 2 +- src/isnd/Controllers/PackagesController.cs | 12 +++---- src/isnd/Entities/NugetSettings.cs | 2 +- .../20210424155323_init.Designer.cs | 2 +- src/isnd/Migrations/20210424155323_init.cs | 2 +- .../20210502153508_api-keys.Designer.cs | 2 +- .../Migrations/20210502153508_api-keys.cs | 2 +- ...508012908_ApkiKey.CreationDate.Designer.cs | 2 +- .../20210508012908_ApkiKey.CreationDate.cs | 2 +- .../20210516060430_packages.Designer.cs | 2 +- .../Migrations/20210516060430_packages.cs | 2 +- ...210522194803_packageVersionKey.Designer.cs | 2 +- .../20210522194803_packageVersionKey.cs | 2 +- .../20210621214109_version-types.Designer.cs | 2 +- .../20210621214109_version-types.cs | 2 +- .../ApplicationDbContextModelSnapshot.cs | 2 +- src/isnd/Startup.cs | 4 +-- 26 files changed, 99 insertions(+), 38 deletions(-) create mode 100644 src/isn/IDataProtector.cs diff --git a/README.md b/README.md index ca94d4d..c9dc4f8 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,7 @@ sudo chmod +x /usr/local/lib/isn/isn.exe ## TODO ````bash -isn add isn set-api-key +isn add isn sources ```` diff --git a/src/isn/Constants.cs b/src/isn/Constants.cs index 496faac..e68c94c 100644 --- a/src/isn/Constants.cs +++ b/src/isn/Constants.cs @@ -1,4 +1,4 @@ -namespace nuget_cli +namespace isn { internal static class Constants { diff --git a/src/isn/IDataProtector.cs b/src/isn/IDataProtector.cs new file mode 100644 index 0000000..0c385da --- /dev/null +++ b/src/isn/IDataProtector.cs @@ -0,0 +1,34 @@ +using System.Text; + +namespace isn +{ + internal interface IDataProtector + { + string Protect(string data); + string UnProtect(string data); + } + class DefaultDataProtector : IDataProtector + { + public string Protect(string data) + { + StringBuilder sb = new StringBuilder(); + foreach (char c in data) + { + sb.Append(c+13); + } + return sb.ToString(); + } + + public string UnProtect(string data) + { + + StringBuilder sb = new StringBuilder(); + foreach (char c in data) + { + sb.Append(c-13); + } + return sb.ToString(); + } + } + +} \ No newline at end of file diff --git a/src/isn/Program.Commands.cs b/src/isn/Program.Commands.cs index fd4a14c..6ecf241 100644 --- a/src/isn/Program.Commands.cs +++ b/src/isn/Program.Commands.cs @@ -1,8 +1,9 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; +using Mono.Options; -namespace nuget_cli +namespace isn { partial class Program @@ -34,15 +35,39 @@ namespace nuget_cli } return pushReports; } + static OptionSet storeoptions = new OptionSet { + { "s|source=", "use source", val => source = source ?? val }, + { "h|help", "show this message and exit", h => shouldShowPushHelp = h != null }, + }; - private static object StoreApiKey(IEnumerable str) + public class IsnSourceSettings { + internal string Source { get; set; } + + internal string[] Keys { get; set; } + } + public static IEnumerable Sources{ get; protected set; } + + private static object StoreApiKey(IEnumerable storeArgs) { + var args = storeoptions.Parse(storeArgs); + if (shouldShowPushHelp) + { + // output the options + Console.Error.WriteLine("Push Options:"); + storeoptions.WriteOptionDescriptions(Console.Out); + } + else { + foreach (string keyv in storeArgs) + { + EnsureKeyStored(source,keyv); + } + } throw new NotImplementedException(); } - private static string LocalizeThis(string arg) + private static void EnsureKeyStored(string source, string keyv) { - return arg; + throw new NotImplementedException(); } } } \ No newline at end of file diff --git a/src/isn/Program.cs b/src/isn/Program.cs index 05087d9..7099049 100644 --- a/src/isn/Program.cs +++ b/src/isn/Program.cs @@ -4,7 +4,7 @@ using System.Linq; using Mono.Options; using Newtonsoft.Json; -namespace nuget_cli +namespace isn { partial class Program { @@ -15,6 +15,8 @@ namespace nuget_cli private static string source = null; private static int pushKO = 0; + private readonly isn.IDataProtector _protector; + static Program() { } diff --git a/src/isn/PushCommand.cs b/src/isn/PushCommand.cs index b4fc04d..6e5881b 100644 --- a/src/isn/PushCommand.cs +++ b/src/isn/PushCommand.cs @@ -4,7 +4,7 @@ using System.Net; using System.Threading.Tasks; using Newtonsoft.Json; -namespace nuget_cli +namespace isn { internal class PushCommand { diff --git a/src/isn/PushReport.cs b/src/isn/PushReport.cs index 4d316d8..1611230 100644 --- a/src/isn/PushReport.cs +++ b/src/isn/PushReport.cs @@ -1,6 +1,6 @@ using System.Net; -namespace nuget_cli +namespace isn { public class PushReport { diff --git a/src/isn/UploadFilesToServerUsingWebRequest.cs b/src/isn/UploadFilesToServerUsingWebRequest.cs index 1218dde..6538906 100644 --- a/src/isn/UploadFilesToServerUsingWebRequest.cs +++ b/src/isn/UploadFilesToServerUsingWebRequest.cs @@ -5,7 +5,7 @@ using System.Text; using System.Threading.Tasks; using Newtonsoft.Json; -namespace nuget_cli +namespace isn { public class NugetdErrorMessage { diff --git a/src/isnd/Controllers/ApiKeysController.cs b/src/isnd/Controllers/ApiKeysController.cs index 9a28997..36db0eb 100644 --- a/src/isnd/Controllers/ApiKeysController.cs +++ b/src/isnd/Controllers/ApiKeysController.cs @@ -21,18 +21,18 @@ namespace isn.Controllers public class ApiKeysController : Controller { private readonly ApplicationDbContext dbContext; - private readonly NugetSettings nugetSettings; + private readonly IsndSettings isndSettings; private readonly UserManager _userManager; private readonly IDataProtector protector; public ApiKeysController(ApplicationDbContext dbContext, - IOptions nugetSettingsOptions, + IOptions isndSettingsOptions, IDataProtectionProvider provider, UserManager userManager) { this.dbContext = dbContext; - this.nugetSettings = nugetSettingsOptions.Value; - protector = provider.CreateProtector(nugetSettings.ProtectionTitle); + this.isndSettings = isndSettingsOptions.Value; + protector = provider.CreateProtector(isndSettings.ProtectionTitle); _userManager = userManager; } @@ -59,7 +59,7 @@ namespace isn.Controllers { string userid = User.FindFirstValue(ClaimTypes.NameIdentifier); IQueryable userKeys = GetUserKeys(); - if (userKeys.Count() >= nugetSettings.MaxUserKeyCount) + if (userKeys.Count() >= isndSettings.MaxUserKeyCount) { ModelState.AddModelError(null, "Maximum key count reached"); return View(); diff --git a/src/isnd/Controllers/PackagesController.Put.cs b/src/isnd/Controllers/PackagesController.Put.cs index bd71bda..b5464d4 100644 --- a/src/isnd/Controllers/PackagesController.Put.cs +++ b/src/isnd/Controllers/PackagesController.Put.cs @@ -71,7 +71,7 @@ namespace isn.Controllers pkgid = reader.GetId(); version = reader.GetVersion(); - string pkgidpath = Path.Combine(_nugetSettings.PackagesRootDir, + string pkgidpath = Path.Combine(_isndSettings.PackagesRootDir, pkgid); pkgpath = Path.Combine(pkgidpath, version.ToFullString()); string name = $"{pkgid}-{version}.nupkg"; diff --git a/src/isnd/Controllers/PackagesController.cs b/src/isnd/Controllers/PackagesController.cs index eb9e954..d54d625 100644 --- a/src/isnd/Controllers/PackagesController.cs +++ b/src/isnd/Controllers/PackagesController.cs @@ -32,7 +32,7 @@ namespace isn.Controllers private readonly ILogger _logger; private readonly IDataProtector _protector; - private readonly NugetSettings _nugetSettings; + private readonly IsndSettings _isndSettings; readonly ApplicationDbContext _dbContext; private readonly PackageManager _packageManager; private readonly IUnleash _unleashĈlient; @@ -40,13 +40,13 @@ namespace isn.Controllers public PackagesController( ILoggerFactory loggerFactory, IDataProtectionProvider provider, - IOptions nugetOptions, + IOptions isndOptions, IUnleash unleashĈlient, ApplicationDbContext dbContext) { _logger = loggerFactory.CreateLogger(); - _nugetSettings = nugetOptions.Value; - _protector = provider.CreateProtector(_nugetSettings.ProtectionTitle); + _isndSettings = isndOptions.Value; + _protector = provider.CreateProtector(_isndSettings.ProtectionTitle); _dbContext = dbContext; _packageManager = new PackageManager(dbContext); _unleashĈlient = unleashĈlient; @@ -158,7 +158,7 @@ namespace isn.Controllers [FromRoute] string id, [FromRoute] string lower, [FromRoute] string idf, [FromRoute] string lowerf) { - var pkgpath = Path.Combine(_nugetSettings.PackagesRootDir, + var pkgpath = Path.Combine(_isndSettings.PackagesRootDir, id, lower, $"{id}-{lower}.nupkg" ); @@ -180,7 +180,7 @@ namespace isn.Controllers [FromRoute][SafeName][Required] string idf, [FromRoute][SafeName][Required] string lowerf) { - var pkgpath = Path.Combine(_nugetSettings.PackagesRootDir, + var pkgpath = Path.Combine(_isndSettings.PackagesRootDir, id, lower, $"{id}.nuspec"); FileInfo pkgfi = new FileInfo(pkgpath); diff --git a/src/isnd/Entities/NugetSettings.cs b/src/isnd/Entities/NugetSettings.cs index bbd2f38..0fe82b1 100644 --- a/src/isnd/Entities/NugetSettings.cs +++ b/src/isnd/Entities/NugetSettings.cs @@ -1,6 +1,6 @@ namespace isn.Entities { - public class NugetSettings + public class IsndSettings { public string ProtectionTitle {get; set;} public string PackagesRootDir {get; set;} diff --git a/src/isnd/Migrations/20210424155323_init.Designer.cs b/src/isnd/Migrations/20210424155323_init.Designer.cs index 40bcec4..84a10c2 100644 --- a/src/isnd/Migrations/20210424155323_init.Designer.cs +++ b/src/isnd/Migrations/20210424155323_init.Designer.cs @@ -7,7 +7,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; using isn.Data; -namespace nugethost.Migrations +namespace isndhost.Migrations { [DbContext(typeof(ApplicationDbContext))] [Migration("20210424155323_init")] diff --git a/src/isnd/Migrations/20210424155323_init.cs b/src/isnd/Migrations/20210424155323_init.cs index 2ea3648..98fc269 100644 --- a/src/isnd/Migrations/20210424155323_init.cs +++ b/src/isnd/Migrations/20210424155323_init.cs @@ -2,7 +2,7 @@ using Microsoft.EntityFrameworkCore.Migrations; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; -namespace nugethost.Migrations +namespace isndhost.Migrations { public partial class init : Migration { diff --git a/src/isnd/Migrations/20210502153508_api-keys.Designer.cs b/src/isnd/Migrations/20210502153508_api-keys.Designer.cs index cf29853..f7f7681 100644 --- a/src/isnd/Migrations/20210502153508_api-keys.Designer.cs +++ b/src/isnd/Migrations/20210502153508_api-keys.Designer.cs @@ -7,7 +7,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; using isn.Data; -namespace nugethost.Migrations +namespace isndhost.Migrations { [DbContext(typeof(ApplicationDbContext))] [Migration("20210502153508_api-keys")] diff --git a/src/isnd/Migrations/20210502153508_api-keys.cs b/src/isnd/Migrations/20210502153508_api-keys.cs index 11866e2..844a35a 100644 --- a/src/isnd/Migrations/20210502153508_api-keys.cs +++ b/src/isnd/Migrations/20210502153508_api-keys.cs @@ -1,6 +1,6 @@ using Microsoft.EntityFrameworkCore.Migrations; -namespace nugethost.Migrations +namespace isndhost.Migrations { public partial class apikeys : Migration { diff --git a/src/isnd/Migrations/20210508012908_ApkiKey.CreationDate.Designer.cs b/src/isnd/Migrations/20210508012908_ApkiKey.CreationDate.Designer.cs index e510f68..652110d 100644 --- a/src/isnd/Migrations/20210508012908_ApkiKey.CreationDate.Designer.cs +++ b/src/isnd/Migrations/20210508012908_ApkiKey.CreationDate.Designer.cs @@ -7,7 +7,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; using isn.Data; -namespace nugethost.Migrations +namespace isndhost.Migrations { [DbContext(typeof(ApplicationDbContext))] [Migration("20210508012908_ApkiKey.CreationDate")] diff --git a/src/isnd/Migrations/20210508012908_ApkiKey.CreationDate.cs b/src/isnd/Migrations/20210508012908_ApkiKey.CreationDate.cs index 45b6a6c..77420d9 100644 --- a/src/isnd/Migrations/20210508012908_ApkiKey.CreationDate.cs +++ b/src/isnd/Migrations/20210508012908_ApkiKey.CreationDate.cs @@ -1,7 +1,7 @@ using System; using Microsoft.EntityFrameworkCore.Migrations; -namespace nugethost.Migrations +namespace isndhost.Migrations { public partial class ApkiKeyCreationDate : Migration { diff --git a/src/isnd/Migrations/20210516060430_packages.Designer.cs b/src/isnd/Migrations/20210516060430_packages.Designer.cs index eb6193e..4200392 100644 --- a/src/isnd/Migrations/20210516060430_packages.Designer.cs +++ b/src/isnd/Migrations/20210516060430_packages.Designer.cs @@ -7,7 +7,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; using isn.Data; -namespace nugethost.Migrations +namespace isndhost.Migrations { [DbContext(typeof(ApplicationDbContext))] [Migration("20210516060430_packages")] diff --git a/src/isnd/Migrations/20210516060430_packages.cs b/src/isnd/Migrations/20210516060430_packages.cs index 4544e9f..62a4e76 100644 --- a/src/isnd/Migrations/20210516060430_packages.cs +++ b/src/isnd/Migrations/20210516060430_packages.cs @@ -1,6 +1,6 @@ using Microsoft.EntityFrameworkCore.Migrations; -namespace nugethost.Migrations +namespace isndhost.Migrations { public partial class packages : Migration { diff --git a/src/isnd/Migrations/20210522194803_packageVersionKey.Designer.cs b/src/isnd/Migrations/20210522194803_packageVersionKey.Designer.cs index c6663c4..ef4c1e6 100644 --- a/src/isnd/Migrations/20210522194803_packageVersionKey.Designer.cs +++ b/src/isnd/Migrations/20210522194803_packageVersionKey.Designer.cs @@ -7,7 +7,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; using isn.Data; -namespace nugethost.Migrations +namespace isndhost.Migrations { [DbContext(typeof(ApplicationDbContext))] [Migration("20210522194803_packageVersionKey")] diff --git a/src/isnd/Migrations/20210522194803_packageVersionKey.cs b/src/isnd/Migrations/20210522194803_packageVersionKey.cs index bed68db..d9885ba 100644 --- a/src/isnd/Migrations/20210522194803_packageVersionKey.cs +++ b/src/isnd/Migrations/20210522194803_packageVersionKey.cs @@ -1,6 +1,6 @@ using Microsoft.EntityFrameworkCore.Migrations; -namespace nugethost.Migrations +namespace isndhost.Migrations { public partial class packageVersionKey : Migration { diff --git a/src/isnd/Migrations/20210621214109_version-types.Designer.cs b/src/isnd/Migrations/20210621214109_version-types.Designer.cs index 9d3adc0..dee5f4d 100644 --- a/src/isnd/Migrations/20210621214109_version-types.Designer.cs +++ b/src/isnd/Migrations/20210621214109_version-types.Designer.cs @@ -7,7 +7,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; using isn.Data; -namespace nugethost.Migrations +namespace isndhost.Migrations { [DbContext(typeof(ApplicationDbContext))] [Migration("20210621214109_version-types")] diff --git a/src/isnd/Migrations/20210621214109_version-types.cs b/src/isnd/Migrations/20210621214109_version-types.cs index dd4b8d5..0dd6d38 100644 --- a/src/isnd/Migrations/20210621214109_version-types.cs +++ b/src/isnd/Migrations/20210621214109_version-types.cs @@ -1,6 +1,6 @@ using Microsoft.EntityFrameworkCore.Migrations; -namespace nugethost.Migrations +namespace isndhost.Migrations { public partial class versiontypes : Migration { diff --git a/src/isnd/Migrations/ApplicationDbContextModelSnapshot.cs b/src/isnd/Migrations/ApplicationDbContextModelSnapshot.cs index de848ba..37015c4 100644 --- a/src/isnd/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/src/isnd/Migrations/ApplicationDbContextModelSnapshot.cs @@ -6,7 +6,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; using isn.Data; -namespace nugethost.Migrations +namespace isndhost.Migrations { [DbContext(typeof(ApplicationDbContext))] partial class ApplicationDbContextModelSnapshot : ModelSnapshot diff --git a/src/isnd/Startup.cs b/src/isnd/Startup.cs index 6e9834a..bcd6725 100644 --- a/src/isnd/Startup.cs +++ b/src/isnd/Startup.cs @@ -74,8 +74,8 @@ namespace isn // _unleashĈlient = env.CreateUnleahClient(unleashClientSettings.Value); var smtpSettingsconf = Configuration.GetSection("Smtp"); services.Configure(smtpSettingsconf); - var nugetSettingsconf = Configuration.GetSection("Nuget"); - services.Configure(nugetSettingsconf); + var isndSettingsconf = Configuration.GetSection("Nuget"); + services.Configure(isndSettingsconf); var adminStartupListConf = Configuration.GetSection("AdminList"); services.Configure(adminStartupListConf); var unleashConf = Configuration.GetSection("Unleash");