broken/ef
Paul Schneider 3 years ago
parent 5f0dfee768
commit ae114c68db
26 changed files with 99 additions and 38 deletions

@ -81,7 +81,7 @@ sudo chmod +x /usr/local/lib/isn/isn.exe
## TODO ## TODO
````bash ````bash
isn add
isn set-api-key isn set-api-key
isn add
isn sources isn sources
```` ````

@ -1,4 +1,4 @@
namespace nuget_cli namespace isn
{ {
internal static class Constants internal static class Constants
{ {

@ -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();
}
}
}

@ -1,8 +1,9 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using Mono.Options;
namespace nuget_cli namespace isn
{ {
partial class Program partial class Program
@ -34,15 +35,39 @@ namespace nuget_cli
} }
return pushReports; 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<string> str) public class IsnSourceSettings {
internal string Source { get; set; }
internal string[] Keys { get; set; }
}
public static IEnumerable<IsnSourceSettings> Sources{ get; protected set; }
private static object StoreApiKey(IEnumerable<string> 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(); throw new NotImplementedException();
} }
private static string LocalizeThis(string arg) private static void EnsureKeyStored(string source, string keyv)
{ {
return arg; throw new NotImplementedException();
} }
} }
} }

@ -4,7 +4,7 @@ using System.Linq;
using Mono.Options; using Mono.Options;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace nuget_cli namespace isn
{ {
partial class Program partial class Program
{ {
@ -15,6 +15,8 @@ namespace nuget_cli
private static string source = null; private static string source = null;
private static int pushKO = 0; private static int pushKO = 0;
private readonly isn.IDataProtector _protector;
static Program() static Program()
{ {
} }

@ -4,7 +4,7 @@ using System.Net;
using System.Threading.Tasks; using System.Threading.Tasks;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace nuget_cli namespace isn
{ {
internal class PushCommand internal class PushCommand
{ {

@ -1,6 +1,6 @@
using System.Net; using System.Net;
namespace nuget_cli namespace isn
{ {
public class PushReport public class PushReport
{ {

@ -5,7 +5,7 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace nuget_cli namespace isn
{ {
public class NugetdErrorMessage public class NugetdErrorMessage
{ {

@ -21,18 +21,18 @@ namespace isn.Controllers
public class ApiKeysController : Controller public class ApiKeysController : Controller
{ {
private readonly ApplicationDbContext dbContext; private readonly ApplicationDbContext dbContext;
private readonly NugetSettings nugetSettings; private readonly IsndSettings isndSettings;
private readonly UserManager<ApplicationUser> _userManager; private readonly UserManager<ApplicationUser> _userManager;
private readonly IDataProtector protector; private readonly IDataProtector protector;
public ApiKeysController(ApplicationDbContext dbContext, public ApiKeysController(ApplicationDbContext dbContext,
IOptions<NugetSettings> nugetSettingsOptions, IOptions<IsndSettings> isndSettingsOptions,
IDataProtectionProvider provider, IDataProtectionProvider provider,
UserManager<ApplicationUser> userManager) UserManager<ApplicationUser> userManager)
{ {
this.dbContext = dbContext; this.dbContext = dbContext;
this.nugetSettings = nugetSettingsOptions.Value; this.isndSettings = isndSettingsOptions.Value;
protector = provider.CreateProtector(nugetSettings.ProtectionTitle); protector = provider.CreateProtector(isndSettings.ProtectionTitle);
_userManager = userManager; _userManager = userManager;
} }
@ -59,7 +59,7 @@ namespace isn.Controllers
{ {
string userid = User.FindFirstValue(ClaimTypes.NameIdentifier); string userid = User.FindFirstValue(ClaimTypes.NameIdentifier);
IQueryable<ApiKey> userKeys = GetUserKeys(); IQueryable<ApiKey> userKeys = GetUserKeys();
if (userKeys.Count() >= nugetSettings.MaxUserKeyCount) if (userKeys.Count() >= isndSettings.MaxUserKeyCount)
{ {
ModelState.AddModelError(null, "Maximum key count reached"); ModelState.AddModelError(null, "Maximum key count reached");
return View(); return View();

@ -71,7 +71,7 @@ namespace isn.Controllers
pkgid = reader.GetId(); pkgid = reader.GetId();
version = reader.GetVersion(); version = reader.GetVersion();
string pkgidpath = Path.Combine(_nugetSettings.PackagesRootDir, string pkgidpath = Path.Combine(_isndSettings.PackagesRootDir,
pkgid); pkgid);
pkgpath = Path.Combine(pkgidpath, version.ToFullString()); pkgpath = Path.Combine(pkgidpath, version.ToFullString());
string name = $"{pkgid}-{version}.nupkg"; string name = $"{pkgid}-{version}.nupkg";

@ -32,7 +32,7 @@ namespace isn.Controllers
private readonly ILogger<PackagesController> _logger; private readonly ILogger<PackagesController> _logger;
private readonly IDataProtector _protector; private readonly IDataProtector _protector;
private readonly NugetSettings _nugetSettings; private readonly IsndSettings _isndSettings;
readonly ApplicationDbContext _dbContext; readonly ApplicationDbContext _dbContext;
private readonly PackageManager _packageManager; private readonly PackageManager _packageManager;
private readonly IUnleash _unleashĈlient; private readonly IUnleash _unleashĈlient;
@ -40,13 +40,13 @@ namespace isn.Controllers
public PackagesController( public PackagesController(
ILoggerFactory loggerFactory, ILoggerFactory loggerFactory,
IDataProtectionProvider provider, IDataProtectionProvider provider,
IOptions<NugetSettings> nugetOptions, IOptions<IsndSettings> isndOptions,
IUnleash unleashĈlient, IUnleash unleashĈlient,
ApplicationDbContext dbContext) ApplicationDbContext dbContext)
{ {
_logger = loggerFactory.CreateLogger<PackagesController>(); _logger = loggerFactory.CreateLogger<PackagesController>();
_nugetSettings = nugetOptions.Value; _isndSettings = isndOptions.Value;
_protector = provider.CreateProtector(_nugetSettings.ProtectionTitle); _protector = provider.CreateProtector(_isndSettings.ProtectionTitle);
_dbContext = dbContext; _dbContext = dbContext;
_packageManager = new PackageManager(dbContext); _packageManager = new PackageManager(dbContext);
_unleashĈlient = unleashĈlient; _unleashĈlient = unleashĈlient;
@ -158,7 +158,7 @@ namespace isn.Controllers
[FromRoute] string id, [FromRoute] string lower, [FromRoute] string id, [FromRoute] string lower,
[FromRoute] string idf, [FromRoute] string lowerf) [FromRoute] string idf, [FromRoute] string lowerf)
{ {
var pkgpath = Path.Combine(_nugetSettings.PackagesRootDir, var pkgpath = Path.Combine(_isndSettings.PackagesRootDir,
id, lower, $"{id}-{lower}.nupkg" id, lower, $"{id}-{lower}.nupkg"
); );
@ -180,7 +180,7 @@ namespace isn.Controllers
[FromRoute][SafeName][Required] string idf, [FromRoute][SafeName][Required] string idf,
[FromRoute][SafeName][Required] string lowerf) [FromRoute][SafeName][Required] string lowerf)
{ {
var pkgpath = Path.Combine(_nugetSettings.PackagesRootDir, var pkgpath = Path.Combine(_isndSettings.PackagesRootDir,
id, lower, $"{id}.nuspec"); id, lower, $"{id}.nuspec");
FileInfo pkgfi = new FileInfo(pkgpath); FileInfo pkgfi = new FileInfo(pkgpath);

@ -1,6 +1,6 @@
namespace isn.Entities namespace isn.Entities
{ {
public class NugetSettings public class IsndSettings
{ {
public string ProtectionTitle {get; set;} public string ProtectionTitle {get; set;}
public string PackagesRootDir {get; set;} public string PackagesRootDir {get; set;}

@ -7,7 +7,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using isn.Data; using isn.Data;
namespace nugethost.Migrations namespace isndhost.Migrations
{ {
[DbContext(typeof(ApplicationDbContext))] [DbContext(typeof(ApplicationDbContext))]
[Migration("20210424155323_init")] [Migration("20210424155323_init")]

@ -2,7 +2,7 @@
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace nugethost.Migrations namespace isndhost.Migrations
{ {
public partial class init : Migration public partial class init : Migration
{ {

@ -7,7 +7,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using isn.Data; using isn.Data;
namespace nugethost.Migrations namespace isndhost.Migrations
{ {
[DbContext(typeof(ApplicationDbContext))] [DbContext(typeof(ApplicationDbContext))]
[Migration("20210502153508_api-keys")] [Migration("20210502153508_api-keys")]

@ -1,6 +1,6 @@
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
namespace nugethost.Migrations namespace isndhost.Migrations
{ {
public partial class apikeys : Migration public partial class apikeys : Migration
{ {

@ -7,7 +7,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using isn.Data; using isn.Data;
namespace nugethost.Migrations namespace isndhost.Migrations
{ {
[DbContext(typeof(ApplicationDbContext))] [DbContext(typeof(ApplicationDbContext))]
[Migration("20210508012908_ApkiKey.CreationDate")] [Migration("20210508012908_ApkiKey.CreationDate")]

@ -1,7 +1,7 @@
using System; using System;
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
namespace nugethost.Migrations namespace isndhost.Migrations
{ {
public partial class ApkiKeyCreationDate : Migration public partial class ApkiKeyCreationDate : Migration
{ {

@ -7,7 +7,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using isn.Data; using isn.Data;
namespace nugethost.Migrations namespace isndhost.Migrations
{ {
[DbContext(typeof(ApplicationDbContext))] [DbContext(typeof(ApplicationDbContext))]
[Migration("20210516060430_packages")] [Migration("20210516060430_packages")]

@ -1,6 +1,6 @@
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
namespace nugethost.Migrations namespace isndhost.Migrations
{ {
public partial class packages : Migration public partial class packages : Migration
{ {

@ -7,7 +7,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using isn.Data; using isn.Data;
namespace nugethost.Migrations namespace isndhost.Migrations
{ {
[DbContext(typeof(ApplicationDbContext))] [DbContext(typeof(ApplicationDbContext))]
[Migration("20210522194803_packageVersionKey")] [Migration("20210522194803_packageVersionKey")]

@ -1,6 +1,6 @@
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
namespace nugethost.Migrations namespace isndhost.Migrations
{ {
public partial class packageVersionKey : Migration public partial class packageVersionKey : Migration
{ {

@ -7,7 +7,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using isn.Data; using isn.Data;
namespace nugethost.Migrations namespace isndhost.Migrations
{ {
[DbContext(typeof(ApplicationDbContext))] [DbContext(typeof(ApplicationDbContext))]
[Migration("20210621214109_version-types")] [Migration("20210621214109_version-types")]

@ -1,6 +1,6 @@
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
namespace nugethost.Migrations namespace isndhost.Migrations
{ {
public partial class versiontypes : Migration public partial class versiontypes : Migration
{ {

@ -6,7 +6,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using isn.Data; using isn.Data;
namespace nugethost.Migrations namespace isndhost.Migrations
{ {
[DbContext(typeof(ApplicationDbContext))] [DbContext(typeof(ApplicationDbContext))]
partial class ApplicationDbContextModelSnapshot : ModelSnapshot partial class ApplicationDbContextModelSnapshot : ModelSnapshot

@ -74,8 +74,8 @@ namespace isn
// _unleashĈlient = env.CreateUnleahClient(unleashClientSettings.Value); // _unleashĈlient = env.CreateUnleahClient(unleashClientSettings.Value);
var smtpSettingsconf = Configuration.GetSection("Smtp"); var smtpSettingsconf = Configuration.GetSection("Smtp");
services.Configure<SmtpSettings>(smtpSettingsconf); services.Configure<SmtpSettings>(smtpSettingsconf);
var nugetSettingsconf = Configuration.GetSection("Nuget"); var isndSettingsconf = Configuration.GetSection("Nuget");
services.Configure<NugetSettings>(nugetSettingsconf); services.Configure<IsndSettings>(isndSettingsconf);
var adminStartupListConf = Configuration.GetSection("AdminList"); var adminStartupListConf = Configuration.GetSection("AdminList");
services.Configure<AdminStartupList>(adminStartupListConf); services.Configure<AdminStartupList>(adminStartupListConf);
var unleashConf = Configuration.GetSection("Unleash"); var unleashConf = Configuration.GetSection("Unleash");

Loading…