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);
|
||||
settings = JsonConvert.DeserializeObject<Settings>(json);
|
||||
currentSource = settings.DefaultSource;
|
||||
currentSource = settings.DefaultSourceKey;
|
||||
}
|
||||
}
|
||||
static readonly OptionSet storeoptions = new OptionSet {
|
||||
|
|
@ -58,13 +58,11 @@ namespace isn
|
|||
private static bool shouldShowPushHelp;
|
||||
private static string apiKey = null;
|
||||
private static string currentSource = null;
|
||||
private static int pushKO = 0;
|
||||
private static bool storApiKey = false;
|
||||
public static IDataProtector Protector { get; set; } = new DefaultDataProtector();
|
||||
|
||||
static Settings settings = null;
|
||||
|
||||
|
||||
public static Settings Settings
|
||||
{
|
||||
get
|
||||
|
|
@ -170,7 +168,6 @@ namespace isn
|
|||
}
|
||||
List<PushReport> reports = PushPkg(pargs);
|
||||
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);
|
||||
}
|
||||
|
||||
int runCode = commandSet.Run(args);
|
||||
return (runCode == 0 && pushKO > 0) ? 500 : runCode;
|
||||
return commandSet.Run(args);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,26 +17,25 @@ namespace isn
|
|||
|
||||
public bool AutoUpdateApiKey { get; set; } = false;
|
||||
|
||||
private string source;
|
||||
private string defSourceKey;
|
||||
|
||||
/// <summary>
|
||||
/// Default Url or alias for the source
|
||||
/// Default source by its alias
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public string DefaultSource
|
||||
public string DefaultSourceKey
|
||||
{
|
||||
get => source;
|
||||
get => defSourceKey;
|
||||
set
|
||||
{
|
||||
if (Sources.ContainsKey(value))
|
||||
if (!Sources.ContainsKey(value))
|
||||
{
|
||||
source = value;
|
||||
return;
|
||||
}
|
||||
if (Sources.Values.Any(s => s.Alias == value))
|
||||
Sources[value]=new SourceSettings
|
||||
{
|
||||
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
|
||||
{
|
||||
public class PushCommand
|
||||
public static class PushCommand
|
||||
{
|
||||
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");
|
||||
string apikey = Program.Protector.UnProtect(Program.Settings.Sources[source].ApiKey);
|
||||
var resources = SourceHelpers.GetServerResources(source);
|
||||
|
|
|
|||
|
|
@ -30,9 +30,9 @@ namespace isn
|
|||
{
|
||||
if (currentSource == null)
|
||||
{
|
||||
if (Settings.DefaultSource == null)
|
||||
if (Settings.DefaultSourceKey == null)
|
||||
return;
|
||||
currentSource = Settings.DefaultSource;
|
||||
currentSource = Settings.DefaultSourceKey;
|
||||
}
|
||||
|
||||
if (Settings.Sources.ContainsKey(currentSource))
|
||||
|
|
@ -41,14 +41,14 @@ namespace isn
|
|||
{
|
||||
// Une suppression
|
||||
Settings.Sources.Remove(currentSource);
|
||||
if (Settings.DefaultSource == currentSource) Settings.DefaultSource = null;
|
||||
if (Settings.DefaultSourceKey == currentSource) Settings.DefaultSourceKey = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Une mise À jour
|
||||
string ptd = Protector.Protect(apiKey);
|
||||
Settings.Sources[currentSource].ApiKey = ptd;
|
||||
if (Settings.DefaultSource == null) Settings.DefaultSource = currentSource;
|
||||
if (Settings.DefaultSourceKey == null) Settings.DefaultSourceKey = currentSource;
|
||||
}
|
||||
}
|
||||
else if (apiKey != null)
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ namespace isn
|
|||
Settings.Sources[arg] :
|
||||
Settings.Sources.Values.FirstOrDefault((s)=> s.Alias == arg) ;
|
||||
if (settings==null) throw new InvalidOperationException(arg);
|
||||
Settings.DefaultSource = arg;
|
||||
Settings.DefaultSourceKey = arg;
|
||||
SaveConfig();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -44,13 +44,29 @@ namespace isnd.Controllers
|
|||
return Ok(leaf.First());
|
||||
}
|
||||
|
||||
|
||||
[HttpGet(_pkgRootPrefix + ApiConfig.CatalogLeaf + "/{id}/{version}/{lower}/index.json")]
|
||||
public IActionResult CatalogLeaf(string id, string pversion, string lower)
|
||||
/// <summary>
|
||||
/// Catalog Leaf,
|
||||
/// 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;
|
||||
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();
|
||||
List<string> types = pkgvs.Select(
|
||||
v => v.Type ?? "Dependency"
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ namespace isnd.Interfaces
|
|||
Task<PackageDeletionReport> DeletePackageAsync(string pkgid, string version, string type);
|
||||
Task<PackageDeletionReport> UserAskForPackageDeletionAsync(string userid, string pkgId, string lower, 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);
|
||||
|
||||
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
|
||||
.Include(v => v.Package)
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ using isnd.Helpers;
|
|||
using Microsoft.IdentityModel.Tokens;
|
||||
using System;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using System.IO;
|
||||
|
||||
namespace isnd
|
||||
{
|
||||
|
|
@ -96,6 +97,7 @@ namespace isnd
|
|||
};
|
||||
});
|
||||
services.AddSwaggerGen(options =>
|
||||
{
|
||||
options.SwaggerDoc("v1", new OpenApiInfo
|
||||
{
|
||||
Version = "v1",
|
||||
|
|
@ -112,7 +114,10 @@ namespace isnd
|
|||
Name = "Example 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.
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
<FileVersion>1.0.5.0</FileVersion>
|
||||
<InformationalVersion>1.0.5+Branch.main.Sha.14206ac477d0f07566d5e8125dc52cbd7f474ca2</InformationalVersion>
|
||||
<Version>1.0.5</Version>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="2.1.1" />
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue