GetMetaData OK
This commit is contained in:
@ -26,7 +26,6 @@ namespace isn
|
|||||||
{
|
{
|
||||||
Settings= Settings.Create();
|
Settings= Settings.Create();
|
||||||
}
|
}
|
||||||
rsa = RSA.Create(Settings.RSAParameters);
|
|
||||||
}
|
}
|
||||||
static readonly OptionSet storeoptions = new OptionSet {
|
static readonly OptionSet storeoptions = new OptionSet {
|
||||||
{ "s|source=", "use source", val => Settings.CurrentSourceKey ??= val },
|
{ "s|source=", "use source", val => Settings.CurrentSourceKey ??= val },
|
||||||
@ -47,7 +46,7 @@ namespace isn
|
|||||||
};
|
};
|
||||||
|
|
||||||
static readonly OptionSet pushoptions = new OptionSet {
|
static readonly OptionSet pushoptions = new OptionSet {
|
||||||
{ "k|api-key=", "use api key", val => Settings.CurrentSource.SetApiKey(rsa, val)},
|
{ "k|api-key=", "use api key", val => Settings.CurrentSource.SetApiKey(val)},
|
||||||
{ "s|source=", "use source", val => Settings.CurrentSourceKey = val },
|
{ "s|source=", "use source", val => Settings.CurrentSourceKey = val },
|
||||||
{ "h|help", "show this message and exit", h => shouldShowPushHelp = h != null },
|
{ "h|help", "show this message and exit", h => shouldShowPushHelp = h != null },
|
||||||
};
|
};
|
||||||
@ -63,7 +62,6 @@ namespace isn
|
|||||||
private static bool shouldShowVersion;
|
private static bool shouldShowVersion;
|
||||||
private static bool shouldShowSourceHelp;
|
private static bool shouldShowSourceHelp;
|
||||||
private static bool shouldShowPushHelp;
|
private static bool shouldShowPushHelp;
|
||||||
public static RSA rsa;
|
|
||||||
|
|
||||||
public static Settings Settings
|
public static Settings Settings
|
||||||
{
|
{
|
||||||
|
@ -14,7 +14,7 @@ namespace isn
|
|||||||
/// Protected API Key
|
/// Protected API Key
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value></value>
|
/// <value></value>
|
||||||
public string ProtectedApiKey { get; set; }
|
public string ApiKey { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Key alias
|
/// Key alias
|
||||||
@ -26,16 +26,14 @@ namespace isn
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetClearApiKey(RSA rsa)
|
public string GetClearApiKey()
|
||||||
{
|
{
|
||||||
var decrypted = rsa.Decrypt(System.Convert.FromBase64String(ProtectedApiKey), RSAEncryptionPadding.Pkcs1);
|
return ApiKey;
|
||||||
return Encoding.Default.GetString(decrypted);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetApiKey(RSA rsa, string key)
|
public void SetApiKey(string key)
|
||||||
{
|
{
|
||||||
var ciphered =rsa.Encrypt(Encoding.Default.GetBytes(key), RSAEncryptionPadding.Pkcs1);
|
ApiKey = key;
|
||||||
ProtectedApiKey = System.Convert.ToBase64String(ciphered);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,14 +46,11 @@ namespace isn
|
|||||||
|
|
||||||
public static Settings Create()
|
public static Settings Create()
|
||||||
{
|
{
|
||||||
var rsaParams = CreateCipheringParameters();
|
|
||||||
return new Settings {
|
return new Settings {
|
||||||
RSAParameters = rsaParams,
|
|
||||||
Sources = new Dictionary<string, SourceSettings>()
|
Sources = new Dictionary<string, SourceSettings>()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public RSAParameters RSAParameters { get; set; }
|
|
||||||
public Dictionary<string, SourceSettings> Sources { get; set; }
|
public Dictionary<string, SourceSettings> Sources { get; set; }
|
||||||
|
|
||||||
private string defSourceKey;
|
private string defSourceKey;
|
||||||
@ -77,16 +72,19 @@ namespace isn
|
|||||||
[JsonIgnore, NotMapped]
|
[JsonIgnore, NotMapped]
|
||||||
public string CurrentSourceKey {get; set;}
|
public string CurrentSourceKey {get; set;}
|
||||||
|
|
||||||
private static RSAParameters CreateCipheringParameters()
|
|
||||||
{
|
|
||||||
var provider = new RSACryptoServiceProvider(2048);
|
|
||||||
return provider.ExportParameters(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
[JsonIgnore, NotMapped]
|
[JsonIgnore, NotMapped]
|
||||||
public SourceSettings CurrentSource
|
public SourceSettings CurrentSource
|
||||||
{
|
{
|
||||||
get => this.Sources[CurrentSourceKey];
|
get
|
||||||
|
{
|
||||||
|
if (CurrentSourceKey==null) return null;
|
||||||
|
if (!Sources.ContainsKey(CurrentSourceKey))
|
||||||
|
{
|
||||||
|
Sources.Add(CurrentSourceKey, new SourceSettings());
|
||||||
|
}
|
||||||
|
return Sources[CurrentSourceKey];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ namespace isn
|
|||||||
))
|
))
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return client.UploadFilesToServer(new Uri(pubRes.Id), fi, settings.Sources[source].GetClearApiKey(Program.rsa));
|
return client.UploadFilesToServer(new Uri(pubRes.Id), fi, settings.Sources[source].ApiKey);
|
||||||
}
|
}
|
||||||
catch (HttpRequestException httpEx)
|
catch (HttpRequestException httpEx)
|
||||||
{
|
{
|
||||||
|
@ -18,7 +18,7 @@ namespace isn
|
|||||||
var source = Settings.CurrentSource;
|
var source = Settings.CurrentSource;
|
||||||
foreach (string pkg in pkgs)
|
foreach (string pkg in pkgs)
|
||||||
{
|
{
|
||||||
var report = cmd.Run(pkg, source.Url, source.GetClearApiKey(rsa));
|
var report = cmd.Run(pkg, source.Url, source.ApiKey);
|
||||||
pushReports.Add(report);
|
pushReports.Add(report);
|
||||||
}
|
}
|
||||||
return pushReports;
|
return pushReports;
|
||||||
|
@ -25,7 +25,7 @@ namespace isn
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Settings.Sources[Settings.CurrentSourceKey].SetApiKey(Program.rsa, args[0]);
|
Settings.CurrentSource.SetApiKey(args[0]);
|
||||||
SaveConfig();
|
SaveConfig();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,8 +35,7 @@ namespace isnd.Data.Catalog
|
|||||||
IsListed = !pkg.IsDeleted && pkg.Package.Public;
|
IsListed = !pkg.IsDeleted && pkg.Package.Public;
|
||||||
if (pkg.DependencyGroups!=null)
|
if (pkg.DependencyGroups!=null)
|
||||||
{
|
{
|
||||||
DependencySets = pkg.DependencyGroups.ToDepSetInfo();
|
DependencySets = pkg.DependencyGroups;
|
||||||
|
|
||||||
}
|
}
|
||||||
PackageDetailsUrl = new Uri(this.id);
|
PackageDetailsUrl = new Uri(this.id);
|
||||||
|
|
||||||
@ -210,7 +209,8 @@ namespace isnd.Data.Catalog
|
|||||||
|
|
||||||
public LicenseMetadata LicenseMetadata { get; set; }
|
public LicenseMetadata LicenseMetadata { get; set; }
|
||||||
|
|
||||||
public IEnumerable<PackageDependencyGroupInfo> DependencySets {get; set;}
|
[JsonProperty("dependencyGroups")]
|
||||||
|
public IEnumerable<PackageDependencyGroup> DependencySets {get; set;}
|
||||||
|
|
||||||
IEnumerable<NuGet.Packaging.PackageDependencyGroup> IPackageSearchMetadata.DependencySets => throw new NotImplementedException();
|
IEnumerable<NuGet.Packaging.PackageDependencyGroup> IPackageSearchMetadata.DependencySets => throw new NotImplementedException();
|
||||||
|
|
||||||
@ -225,13 +225,4 @@ namespace isnd.Data.Catalog
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class PackageDependencyGroupInfo
|
|
||||||
{
|
|
||||||
private PackageDependencyGroup group;
|
|
||||||
|
|
||||||
public PackageDependencyGroupInfo(PackageDependencyGroup group)
|
|
||||||
{
|
|
||||||
this.group = group;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -14,13 +14,6 @@ using NuGet.Versioning;
|
|||||||
|
|
||||||
namespace isnd.Data
|
namespace isnd.Data
|
||||||
{
|
{
|
||||||
static class Helpers
|
|
||||||
{
|
|
||||||
public static PackageDependencyGroupInfo[] ToDepSetInfo(this IEnumerable<PackageDependencyGroup> groups)
|
|
||||||
{
|
|
||||||
return groups.Select(group => new PackageDependencyGroupInfo(group)).ToArray();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public class PackageDependencyGroup
|
public class PackageDependencyGroup
|
||||||
{
|
{
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
@ -28,7 +21,7 @@ namespace isnd.Data
|
|||||||
public string Id { get ; set;}
|
public string Id { get ; set;}
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
[JsonProperty("id")]
|
[JsonIgnore]
|
||||||
public string PackageId { get ; set;}
|
public string PackageId { get ; set;}
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
@ -39,7 +32,7 @@ namespace isnd.Data
|
|||||||
[Required]
|
[Required]
|
||||||
public string TargetFramework { get; set; }
|
public string TargetFramework { get; set; }
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonProperty("dependencies")]
|
||||||
[ForeignKey("DependencyGroupId")]
|
[ForeignKey("DependencyGroupId")]
|
||||||
public virtual List<Dependency> Dependencies { get; set; }
|
public virtual List<Dependency> Dependencies { get; set; }
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ public class ApiKeyProvider : IApiKeyProvider
|
|||||||
{
|
{
|
||||||
var newKey = new ApiKey{
|
var newKey = new ApiKey{
|
||||||
UserId = model.UserId,
|
UserId = model.UserId,
|
||||||
CreationDate = DateTime.Now,
|
CreationDate = DateTime.Now.ToUniversalTime(),
|
||||||
Name = model.Name,
|
Name = model.Name,
|
||||||
ValidityPeriodInDays = model.ValidityPeriodInDays
|
ValidityPeriodInDays = model.ValidityPeriodInDays
|
||||||
};
|
};
|
||||||
|
@ -13,14 +13,11 @@ using isnd.Data;
|
|||||||
using isnd.Data.Catalog;
|
using isnd.Data.Catalog;
|
||||||
using isnd.Data.Packages;
|
using isnd.Data.Packages;
|
||||||
using isnd.Entities;
|
using isnd.Entities;
|
||||||
using isnd.Helpers;
|
|
||||||
using isnd.Interfaces;
|
using isnd.Interfaces;
|
||||||
using isnd.ViewModels;
|
using isnd.ViewModels;
|
||||||
using NuGet.Packaging.Core;
|
|
||||||
using NuGet.Versioning;
|
using NuGet.Versioning;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
using System.Threading;
|
|
||||||
using NuGet.Protocol;
|
using NuGet.Protocol;
|
||||||
|
|
||||||
namespace isnd.Services
|
namespace isnd.Services
|
||||||
@ -241,6 +238,7 @@ namespace isnd.Services
|
|||||||
&& v.LatestCommit != null
|
&& v.LatestCommit != null
|
||||||
&& (pkgType == null || pkgType == v.Type)
|
&& (pkgType == null || pkgType == v.Type)
|
||||||
).SingleOrDefaultAsync();
|
).SingleOrDefaultAsync();
|
||||||
|
if (version==null) return null;
|
||||||
foreach (var g in version.DependencyGroups)
|
foreach (var g in version.DependencyGroups)
|
||||||
{
|
{
|
||||||
g.Dependencies = dbContext.Dependencies.Where(d => d.DependencyGroupId == g.Id).ToList();
|
g.Dependencies = dbContext.Dependencies.Where(d => d.DependencyGroupId == g.Id).ToList();
|
||||||
|
@ -34,16 +34,20 @@ namespace isnd.ViewModels
|
|||||||
private static PackageHit NewPackageHit(string apiBase, Package package)
|
private static PackageHit NewPackageHit(string apiBase, Package package)
|
||||||
{
|
{
|
||||||
string regId = $"{apiBase}{ApiConfig.Registration}/{package.Id}/index.json";
|
string regId = $"{apiBase}{ApiConfig.Registration}/{package.Id}/index.json";
|
||||||
return new PackageHit(regId, package.Id)
|
|
||||||
|
var pkgHit = new PackageHit(regId, package.Id)
|
||||||
{
|
{
|
||||||
version = package.GetLatestVersion(),
|
version = package.GetLatestVersion(),
|
||||||
description = package.Description,
|
description = package.Description,
|
||||||
versions = package.Versions.Select(v => new SearchVersionInfo(apiBase, v)).ToArray(),
|
};
|
||||||
packageTypes = package.Versions.Select(v=>new PackageType(v.Type, new System.Version(v.Major,v.Minor,v.Patch, v.Revision)))
|
if (package.Versions!=null)
|
||||||
.ToArray(),
|
{
|
||||||
|
pkgHit.versions = package.Versions
|
||||||
|
.Select(v => new SearchVersionInfo(apiBase, v)).ToArray();
|
||||||
};
|
pkgHit.packageTypes = package.Versions
|
||||||
|
.Select(v=>new PackageType(v.Type ?? "Legacy", new System.Version(v.Major,v.Minor,v.Patch, v.Revision)))?.ToArray();
|
||||||
|
}
|
||||||
|
return pkgHit;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PackageHit[] data { get; protected set; }
|
public PackageHit[] data { get; protected set; }
|
||||||
|
@ -12,7 +12,4 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="isn.abst" Version="*" />
|
|
||||||
</ItemGroup>
|
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -30,7 +30,7 @@ namespace isn.tests
|
|||||||
public void TestPush()
|
public void TestPush()
|
||||||
{
|
{
|
||||||
Program.LoadConfig();
|
Program.LoadConfig();
|
||||||
var report = Program.PushPkg(new string[] { "./src/isn.abst/bin/Debug/isn.abst.1.0.1.nupkg" });
|
var report = Program.PushPkg(new string[] { "./src/isn.abst/bin/Release/isn.abst.1.0.24.nupkg" });
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@ -50,9 +50,8 @@ namespace isn.tests
|
|||||||
var setting = Settings.Create();
|
var setting = Settings.Create();
|
||||||
setting.Sources[source] = new SourceSettings{ Url=source };
|
setting.Sources[source] = new SourceSettings{ Url=source };
|
||||||
string testingKey = "CfDJ8LF3SbIJ4FJAgs7uIQKhdCAYCNVXRwU6TEoaXOo1_ZpG2u8TCGFP2z13hw9xR0LC0gdbr1QGwNndiXUl4DI74nxyBi-T1oC33PWtE-5vgiJWeCH223PYtoSEdzDiWovwJZWJbQON0WqoG8vSfbrBXTmicD6oxF4ghwXXexY0RiRR";
|
string testingKey = "CfDJ8LF3SbIJ4FJAgs7uIQKhdCAYCNVXRwU6TEoaXOo1_ZpG2u8TCGFP2z13hw9xR0LC0gdbr1QGwNndiXUl4DI74nxyBi-T1oC33PWtE-5vgiJWeCH223PYtoSEdzDiWovwJZWJbQON0WqoG8vSfbrBXTmicD6oxF4ghwXXexY0RiRR";
|
||||||
var rsa = RSA.Create(setting.RSAParameters);
|
|
||||||
setting.Sources[source].SetApiKey(rsa,testingKey);
|
Assert.Equal(testingKey, setting.Sources[source].ApiKey);
|
||||||
Assert.Equal(testingKey, setting.Sources[source].GetClearApiKey(rsa));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ namespace isnd.host.tests
|
|||||||
string pkgSourceUrl = isnSettings.ExternalUrl + apiindex + ".json";
|
string pkgSourceUrl = isnSettings.ExternalUrl + apiindex + ".json";
|
||||||
ProcessStartInfo psi = new ProcessStartInfo("nuget");
|
ProcessStartInfo psi = new ProcessStartInfo("nuget");
|
||||||
psi.ArgumentList.Add("install");
|
psi.ArgumentList.Add("install");
|
||||||
psi.ArgumentList.Add("isnd");
|
psi.ArgumentList.Add("isn.abst");
|
||||||
psi.ArgumentList.Add("-PreRelease");
|
psi.ArgumentList.Add("-PreRelease");
|
||||||
psi.ArgumentList.Add("-Source");
|
psi.ArgumentList.Add("-Source");
|
||||||
psi.ArgumentList.Add(pkgSourceUrl);
|
psi.ArgumentList.Add(pkgSourceUrl);
|
||||||
@ -128,7 +128,7 @@ namespace isnd.host.tests
|
|||||||
PackageMetadataResource resource = await repository.GetResourceAsync<PackageMetadataResource>();
|
PackageMetadataResource resource = await repository.GetResourceAsync<PackageMetadataResource>();
|
||||||
|
|
||||||
IEnumerable<IPackageSearchMetadata> packages = await resource.GetMetadataAsync(
|
IEnumerable<IPackageSearchMetadata> packages = await resource.GetMetadataAsync(
|
||||||
"isnd",
|
"isn.abst",
|
||||||
includePrerelease: true,
|
includePrerelease: true,
|
||||||
includeUnlisted: true,
|
includeUnlisted: true,
|
||||||
cache,
|
cache,
|
||||||
@ -178,7 +178,7 @@ namespace isnd.host.tests
|
|||||||
PackageUpdateResource pushRes = await repository.GetResourceAsync<PackageUpdateResource>();
|
PackageUpdateResource pushRes = await repository.GetResourceAsync<PackageUpdateResource>();
|
||||||
SymbolPackageUpdateResourceV3 symbolPackageResource = await repository.GetResourceAsync<SymbolPackageUpdateResourceV3>();
|
SymbolPackageUpdateResourceV3 symbolPackageResource = await repository.GetResourceAsync<SymbolPackageUpdateResourceV3>();
|
||||||
|
|
||||||
await pushRes.Push(new List<string>{ "../../../../../src/isn.abst/bin/Release/isn.abst.1.0.1.nupkg" }, null,
|
await pushRes.Push(new List<string>{ "../../../../../src/isn.abst/bin/Release/isn.abst.1.0.24.nupkg" }, null,
|
||||||
5000, false, GetApiKey, GetSymbolsApiKey, false, false, symbolPackageResource, logger);
|
5000, false, GetApiKey, GetSymbolsApiKey, false, false, symbolPackageResource, logger);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -101,6 +101,7 @@ namespace isnd.tests
|
|||||||
Name = "Testing Key",
|
Name = "Testing Key",
|
||||||
UserId = TestingUser.Id,
|
UserId = TestingUser.Id,
|
||||||
ValidityPeriodInDays = 1
|
ValidityPeriodInDays = 1
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
testKey = keyProvider.CreateApiKeyAsync(apiKeyQuery).Result;
|
testKey = keyProvider.CreateApiKeyAsync(apiKeyQuery).Result;
|
||||||
|
Reference in New Issue
Block a user