settings
This commit is contained in:
parent
18b67bd725
commit
282b0277ae
10 changed files with 51 additions and 34 deletions
|
|
@ -17,7 +17,7 @@ namespace isn
|
||||||
{
|
{
|
||||||
var json = File.ReadAllText(cfgSettingIf.FullName);
|
var json = File.ReadAllText(cfgSettingIf.FullName);
|
||||||
settings = JsonConvert.DeserializeObject<Settings>(json);
|
settings = JsonConvert.DeserializeObject<Settings>(json);
|
||||||
currentSource = settings.DefaultSource;
|
currentSource = settings.DefaultSourceKey;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static readonly OptionSet storeoptions = new OptionSet {
|
static readonly OptionSet storeoptions = new OptionSet {
|
||||||
|
|
@ -58,13 +58,11 @@ namespace isn
|
||||||
private static bool shouldShowPushHelp;
|
private static bool shouldShowPushHelp;
|
||||||
private static string apiKey = null;
|
private static string apiKey = null;
|
||||||
private static string currentSource = null;
|
private static string currentSource = null;
|
||||||
private static int pushKO = 0;
|
|
||||||
private static bool storApiKey = false;
|
private static bool storApiKey = false;
|
||||||
public static IDataProtector Protector { get; set; } = new DefaultDataProtector();
|
public static IDataProtector Protector { get; set; } = new DefaultDataProtector();
|
||||||
|
|
||||||
static Settings settings = null;
|
static Settings settings = null;
|
||||||
|
|
||||||
|
|
||||||
public static Settings Settings
|
public static Settings Settings
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
|
@ -170,7 +168,6 @@ namespace isn
|
||||||
}
|
}
|
||||||
List<PushReport> reports = PushPkg(pargs);
|
List<PushReport> reports = PushPkg(pargs);
|
||||||
Console.WriteLine(JsonConvert.SerializeObject(reports));
|
Console.WriteLine(JsonConvert.SerializeObject(reports));
|
||||||
pushKO = reports.Count(r => !r.OK && !r.AlreadyPresent);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -212,8 +209,7 @@ namespace isn
|
||||||
Console.WriteLine("isn version " + GitVersionInformation.AssemblySemFileVer);
|
Console.WriteLine("isn version " + GitVersionInformation.AssemblySemFileVer);
|
||||||
}
|
}
|
||||||
|
|
||||||
int runCode = commandSet.Run(args);
|
return commandSet.Run(args);
|
||||||
return (runCode == 0 && pushKO > 0) ? 500 : runCode;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,26 +17,25 @@ namespace isn
|
||||||
|
|
||||||
public bool AutoUpdateApiKey { get; set; } = false;
|
public bool AutoUpdateApiKey { get; set; } = false;
|
||||||
|
|
||||||
private string source;
|
private string defSourceKey;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Default Url or alias for the source
|
/// Default source by its alias
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value></value>
|
/// <value></value>
|
||||||
public string DefaultSource
|
public string DefaultSourceKey
|
||||||
{
|
{
|
||||||
get => source;
|
get => defSourceKey;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (Sources.ContainsKey(value))
|
if (!Sources.ContainsKey(value))
|
||||||
{
|
{
|
||||||
source = value;
|
Sources[value]=new SourceSettings
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (Sources.Values.Any(s => s.Alias == value))
|
|
||||||
{
|
{
|
||||||
source = Sources[value].Alias;
|
Alias = defSourceKey
|
||||||
|
};
|
||||||
}
|
}
|
||||||
throw new InvalidOperationException("Add it to Sources before, with an API key, as source or alias .");
|
defSourceKey = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,11 +8,11 @@ using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace isn
|
namespace isn
|
||||||
{
|
{
|
||||||
public class PushCommand
|
public static class PushCommand
|
||||||
{
|
{
|
||||||
static public PushReport Run(string pkg, string source)
|
static public PushReport Run(string pkg, string source)
|
||||||
{
|
{
|
||||||
if (source == null) source = Program.Settings.DefaultSource;
|
if (source == null) source = Program.Settings.DefaultSourceKey;
|
||||||
if (source == null) throw new InvalidOperationException("source is null");
|
if (source == null) throw new InvalidOperationException("source is null");
|
||||||
string apikey = Program.Protector.UnProtect(Program.Settings.Sources[source].ApiKey);
|
string apikey = Program.Protector.UnProtect(Program.Settings.Sources[source].ApiKey);
|
||||||
var resources = SourceHelpers.GetServerResources(source);
|
var resources = SourceHelpers.GetServerResources(source);
|
||||||
|
|
|
||||||
|
|
@ -30,9 +30,9 @@ namespace isn
|
||||||
{
|
{
|
||||||
if (currentSource == null)
|
if (currentSource == null)
|
||||||
{
|
{
|
||||||
if (Settings.DefaultSource == null)
|
if (Settings.DefaultSourceKey == null)
|
||||||
return;
|
return;
|
||||||
currentSource = Settings.DefaultSource;
|
currentSource = Settings.DefaultSourceKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Settings.Sources.ContainsKey(currentSource))
|
if (Settings.Sources.ContainsKey(currentSource))
|
||||||
|
|
@ -41,14 +41,14 @@ namespace isn
|
||||||
{
|
{
|
||||||
// Une suppression
|
// Une suppression
|
||||||
Settings.Sources.Remove(currentSource);
|
Settings.Sources.Remove(currentSource);
|
||||||
if (Settings.DefaultSource == currentSource) Settings.DefaultSource = null;
|
if (Settings.DefaultSourceKey == currentSource) Settings.DefaultSourceKey = null;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Une mise À jour
|
// Une mise À jour
|
||||||
string ptd = Protector.Protect(apiKey);
|
string ptd = Protector.Protect(apiKey);
|
||||||
Settings.Sources[currentSource].ApiKey = ptd;
|
Settings.Sources[currentSource].ApiKey = ptd;
|
||||||
if (Settings.DefaultSource == null) Settings.DefaultSource = currentSource;
|
if (Settings.DefaultSourceKey == null) Settings.DefaultSourceKey = currentSource;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (apiKey != null)
|
else if (apiKey != null)
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ namespace isn
|
||||||
Settings.Sources[arg] :
|
Settings.Sources[arg] :
|
||||||
Settings.Sources.Values.FirstOrDefault((s)=> s.Alias == arg) ;
|
Settings.Sources.Values.FirstOrDefault((s)=> s.Alias == arg) ;
|
||||||
if (settings==null) throw new InvalidOperationException(arg);
|
if (settings==null) throw new InvalidOperationException(arg);
|
||||||
Settings.DefaultSource = arg;
|
Settings.DefaultSourceKey = arg;
|
||||||
SaveConfig();
|
SaveConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -44,13 +44,29 @@ namespace isnd.Controllers
|
||||||
return Ok(leaf.First());
|
return Ok(leaf.First());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
[HttpGet(_pkgRootPrefix + ApiConfig.CatalogLeaf + "/{id}/{version}/{lower}/index.json")]
|
/// Catalog Leaf,
|
||||||
public IActionResult CatalogLeaf(string id, string pversion, string lower)
|
/// Get info about given package id, and optional lower part .
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">Given Package Id</param>
|
||||||
|
/// <param name="lower">lower part, a semantic version for the package,
|
||||||
|
/// and eventually followed by the "package type"</param>
|
||||||
|
/// <returns>Info about concerned packages, in order to be able and download them</returns>
|
||||||
|
[HttpGet(_pkgRootPrefix + ApiConfig.CatalogLeaf + "/{id}/{lower?}/index.json")]
|
||||||
|
public IActionResult CatalogLeaf(string id, string lower = null)
|
||||||
{
|
{
|
||||||
|
Data.PackageVersion[] pkgvs = null;
|
||||||
|
if (lower == "{lower}") lower = null;
|
||||||
bool askForindex = lower == null;
|
bool askForindex = lower == null;
|
||||||
var pkgvs = this.packageManager.GetCatalogLeaf(id, pversion, lower).ToArray();
|
if (lower != null && lower.IndexOf('/') > 0 )
|
||||||
|
{
|
||||||
|
string version = lower.Substring(lower.IndexOf('/'));
|
||||||
|
pkgvs = this.packageManager.GetCatalogLeaf(id, version, lower).ToArray();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
pkgvs = this.packageManager.GetCatalogLeaf(id, null, lower).ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
if (pkgvs.Count() == 0) return NotFound();
|
if (pkgvs.Count() == 0) return NotFound();
|
||||||
List<string> types = pkgvs.Select(
|
List<string> types = pkgvs.Select(
|
||||||
v => v.Type ?? "Dependency"
|
v => v.Type ?? "Dependency"
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ namespace isnd.Interfaces
|
||||||
Task<PackageDeletionReport> DeletePackageAsync(string pkgid, string version, string type);
|
Task<PackageDeletionReport> DeletePackageAsync(string pkgid, string version, string type);
|
||||||
Task<PackageDeletionReport> UserAskForPackageDeletionAsync(string userid, string pkgId, string lower, string type);
|
Task<PackageDeletionReport> UserAskForPackageDeletionAsync(string userid, string pkgId, string lower, string type);
|
||||||
Task<PackageVersion> GetPackageAsync(string pkgid, string version, string type);
|
Task<PackageVersion> GetPackageAsync(string pkgid, string version, string type);
|
||||||
IEnumerable<PackageVersion> GetCatalogLeaf(string pkgId, string semver, string pkgType);
|
IEnumerable<PackageVersion> GetCatalogLeaf(string pkgId, string version, string pkgType);
|
||||||
IEnumerable<RegistrationLeaf> SearchById(string pkgId, string semver, string pkgType);
|
IEnumerable<RegistrationLeaf> SearchById(string pkgId, string semver, string pkgType);
|
||||||
|
|
||||||
RegistrationPageIndex GetCatalogIndex();
|
RegistrationPageIndex GetCatalogIndex();
|
||||||
|
|
|
||||||
|
|
@ -287,7 +287,7 @@ namespace isnd.Services
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<PackageVersion> GetCatalogLeaf(string pkgId, string semver, string pkgType)
|
public IEnumerable<PackageVersion> GetCatalogLeaf(string pkgId, string semver=null, string pkgType=null)
|
||||||
{
|
{
|
||||||
return dbContext.PackageVersions
|
return dbContext.PackageVersions
|
||||||
.Include(v => v.Package)
|
.Include(v => v.Package)
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ using isnd.Helpers;
|
||||||
using Microsoft.IdentityModel.Tokens;
|
using Microsoft.IdentityModel.Tokens;
|
||||||
using System;
|
using System;
|
||||||
using Microsoft.OpenApi.Models;
|
using Microsoft.OpenApi.Models;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
namespace isnd
|
namespace isnd
|
||||||
{
|
{
|
||||||
|
|
@ -96,6 +97,7 @@ namespace isnd
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
services.AddSwaggerGen(options =>
|
services.AddSwaggerGen(options =>
|
||||||
|
{
|
||||||
options.SwaggerDoc("v1", new OpenApiInfo
|
options.SwaggerDoc("v1", new OpenApiInfo
|
||||||
{
|
{
|
||||||
Version = "v1",
|
Version = "v1",
|
||||||
|
|
@ -112,7 +114,10 @@ namespace isnd
|
||||||
Name = "Example License",
|
Name = "Example License",
|
||||||
Url = new Uri("https://isn.pschneider.fr/license")
|
Url = new Uri("https://isn.pschneider.fr/license")
|
||||||
}
|
}
|
||||||
}));
|
});
|
||||||
|
var xmlFilename = $"{typeof(Startup).Assembly.GetName().Name}.xml";
|
||||||
|
options.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, xmlFilename));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@
|
||||||
<FileVersion>1.0.5.0</FileVersion>
|
<FileVersion>1.0.5.0</FileVersion>
|
||||||
<InformationalVersion>1.0.5+Branch.main.Sha.14206ac477d0f07566d5e8125dc52cbd7f474ca2</InformationalVersion>
|
<InformationalVersion>1.0.5+Branch.main.Sha.14206ac477d0f07566d5e8125dc52cbd7f474ca2</InformationalVersion>
|
||||||
<Version>1.0.5</Version>
|
<Version>1.0.5</Version>
|
||||||
|
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="2.1.1" />
|
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="2.1.1" />
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue