GetMetaData OK

This commit is contained in:
2024-10-09 23:19:38 +01:00
parent 7ca465d4a9
commit 2b45e421dd
14 changed files with 43 additions and 64 deletions

View File

@ -26,7 +26,6 @@ namespace isn
{
Settings= Settings.Create();
}
rsa = RSA.Create(Settings.RSAParameters);
}
static readonly OptionSet storeoptions = new OptionSet {
{ "s|source=", "use source", val => Settings.CurrentSourceKey ??= val },
@ -47,7 +46,7 @@ namespace isn
};
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 },
{ "h|help", "show this message and exit", h => shouldShowPushHelp = h != null },
};
@ -63,7 +62,6 @@ namespace isn
private static bool shouldShowVersion;
private static bool shouldShowSourceHelp;
private static bool shouldShowPushHelp;
public static RSA rsa;
public static Settings Settings
{

View File

@ -14,7 +14,7 @@ namespace isn
/// Protected API Key
/// </summary>
/// <value></value>
public string ProtectedApiKey { get; set; }
public string ApiKey { get; set; }
/// <summary>
/// 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 Encoding.Default.GetString(decrypted);
return ApiKey;
}
public void SetApiKey(RSA rsa, string key)
public void SetApiKey(string key)
{
var ciphered =rsa.Encrypt(Encoding.Default.GetBytes(key), RSAEncryptionPadding.Pkcs1);
ProtectedApiKey = System.Convert.ToBase64String(ciphered);
ApiKey = key;
}
}
@ -48,14 +46,11 @@ namespace isn
public static Settings Create()
{
var rsaParams = CreateCipheringParameters();
return new Settings {
RSAParameters = rsaParams,
Sources = new Dictionary<string, SourceSettings>()
};
}
public RSAParameters RSAParameters { get; set; }
public Dictionary<string, SourceSettings> Sources { get; set; }
private string defSourceKey;
@ -77,16 +72,19 @@ namespace isn
[JsonIgnore, NotMapped]
public string CurrentSourceKey {get; set;}
private static RSAParameters CreateCipheringParameters()
{
var provider = new RSACryptoServiceProvider(2048);
return provider.ExportParameters(true);
}
[JsonIgnore, NotMapped]
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];
}
}
}
}

View File

@ -45,7 +45,7 @@ namespace isn
))
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)
{

View File

@ -18,7 +18,7 @@ namespace isn
var source = Settings.CurrentSource;
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);
}
return pushReports;

View File

@ -25,7 +25,7 @@ namespace isn
}
else
{
Settings.Sources[Settings.CurrentSourceKey].SetApiKey(Program.rsa, args[0]);
Settings.CurrentSource.SetApiKey(args[0]);
SaveConfig();
}
}

View File

@ -35,8 +35,7 @@ namespace isnd.Data.Catalog
IsListed = !pkg.IsDeleted && pkg.Package.Public;
if (pkg.DependencyGroups!=null)
{
DependencySets = pkg.DependencyGroups.ToDepSetInfo();
DependencySets = pkg.DependencyGroups;
}
PackageDetailsUrl = new Uri(this.id);
@ -210,7 +209,8 @@ namespace isnd.Data.Catalog
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();
@ -225,13 +225,4 @@ namespace isnd.Data.Catalog
}
}
public class PackageDependencyGroupInfo
{
private PackageDependencyGroup group;
public PackageDependencyGroupInfo(PackageDependencyGroup group)
{
this.group = group;
}
}
}

View File

@ -14,13 +14,6 @@ using NuGet.Versioning;
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
{
[JsonIgnore]
@ -28,7 +21,7 @@ namespace isnd.Data
public string Id { get ; set;}
[Required]
[JsonProperty("id")]
[JsonIgnore]
public string PackageId { get ; set;}
[Required]
@ -39,7 +32,7 @@ namespace isnd.Data
[Required]
public string TargetFramework { get; set; }
[JsonIgnore]
[JsonProperty("dependencies")]
[ForeignKey("DependencyGroupId")]
public virtual List<Dependency> Dependencies { get; set; }

View File

@ -31,7 +31,7 @@ public class ApiKeyProvider : IApiKeyProvider
{
var newKey = new ApiKey{
UserId = model.UserId,
CreationDate = DateTime.Now,
CreationDate = DateTime.Now.ToUniversalTime(),
Name = model.Name,
ValidityPeriodInDays = model.ValidityPeriodInDays
};

View File

@ -13,14 +13,11 @@ using isnd.Data;
using isnd.Data.Catalog;
using isnd.Data.Packages;
using isnd.Entities;
using isnd.Helpers;
using isnd.Interfaces;
using isnd.ViewModels;
using NuGet.Packaging.Core;
using NuGet.Versioning;
using System.Xml;
using System.Xml.Linq;
using System.Threading;
using NuGet.Protocol;
namespace isnd.Services
@ -241,6 +238,7 @@ namespace isnd.Services
&& v.LatestCommit != null
&& (pkgType == null || pkgType == v.Type)
).SingleOrDefaultAsync();
if (version==null) return null;
foreach (var g in version.DependencyGroups)
{
g.Dependencies = dbContext.Dependencies.Where(d => d.DependencyGroupId == g.Id).ToList();

View File

@ -34,16 +34,20 @@ namespace isnd.ViewModels
private static PackageHit NewPackageHit(string apiBase, Package package)
{
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(),
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)))
.ToArray(),
};
};
if (package.Versions!=null)
{
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; }

View File

@ -12,7 +12,4 @@
</PropertyGroup>
<ItemGroup>
</ItemGroup>
<ItemGroup>
<PackageReference Include="isn.abst" Version="*" />
</ItemGroup>
</Project>

View File

@ -30,7 +30,7 @@ namespace isn.tests
public void TestPush()
{
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]
@ -50,9 +50,8 @@ namespace isn.tests
var setting = Settings.Create();
setting.Sources[source] = new SourceSettings{ Url=source };
string testingKey = "CfDJ8LF3SbIJ4FJAgs7uIQKhdCAYCNVXRwU6TEoaXOo1_ZpG2u8TCGFP2z13hw9xR0LC0gdbr1QGwNndiXUl4DI74nxyBi-T1oC33PWtE-5vgiJWeCH223PYtoSEdzDiWovwJZWJbQON0WqoG8vSfbrBXTmicD6oxF4ghwXXexY0RiRR";
var rsa = RSA.Create(setting.RSAParameters);
setting.Sources[source].SetApiKey(rsa,testingKey);
Assert.Equal(testingKey, setting.Sources[source].GetClearApiKey(rsa));
Assert.Equal(testingKey, setting.Sources[source].ApiKey);
}
}

View File

@ -67,7 +67,7 @@ namespace isnd.host.tests
string pkgSourceUrl = isnSettings.ExternalUrl + apiindex + ".json";
ProcessStartInfo psi = new ProcessStartInfo("nuget");
psi.ArgumentList.Add("install");
psi.ArgumentList.Add("isnd");
psi.ArgumentList.Add("isn.abst");
psi.ArgumentList.Add("-PreRelease");
psi.ArgumentList.Add("-Source");
psi.ArgumentList.Add(pkgSourceUrl);
@ -128,7 +128,7 @@ namespace isnd.host.tests
PackageMetadataResource resource = await repository.GetResourceAsync<PackageMetadataResource>();
IEnumerable<IPackageSearchMetadata> packages = await resource.GetMetadataAsync(
"isnd",
"isn.abst",
includePrerelease: true,
includeUnlisted: true,
cache,
@ -178,7 +178,7 @@ namespace isnd.host.tests
PackageUpdateResource pushRes = await repository.GetResourceAsync<PackageUpdateResource>();
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);
}

View File

@ -101,6 +101,7 @@ namespace isnd.tests
Name = "Testing Key",
UserId = TestingUser.Id,
ValidityPeriodInDays = 1
};
testKey = keyProvider.CreateApiKeyAsync(apiKeyQuery).Result;