Compare commits
3 Commits
e69462999e
...
8656bce151
Author | SHA1 | Date |
---|---|---|
Paul Schneider | 8656bce151 | 6 months ago |
Paul Schneider | d6180aa154 | 6 months ago |
Paul Schneider | 89e1b5a235 | 6 months ago |
@ -1,47 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace isn
|
||||
{
|
||||
public interface IDataProtector
|
||||
{
|
||||
string Protect(string data);
|
||||
string UnProtect(string data);
|
||||
}
|
||||
|
||||
public class DefaultDataProtector : IDataProtector
|
||||
{
|
||||
private byte delta = 145;
|
||||
|
||||
public DefaultDataProtector()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public string Protect(string data)
|
||||
{
|
||||
List<Byte> protd = new List<byte>();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach (byte c in Encoding.UTF8.GetBytes(data))
|
||||
{
|
||||
protd.Add((byte) (c ^ delta));
|
||||
}
|
||||
return System.Convert.ToBase64String(protd.ToArray());
|
||||
}
|
||||
|
||||
public string UnProtect(string data)
|
||||
{
|
||||
if (data==null) return null;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
List<byte> unps = new List<byte>();
|
||||
|
||||
foreach (byte c in System.Convert.FromBase64CharArray(data.ToCharArray(),0,data.Length))
|
||||
{
|
||||
unps.Add((byte) (c ^ delta));
|
||||
}
|
||||
return Encoding.UTF8.GetString(unps.ToArray());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using isnd.Entities;
|
||||
using isn.abst;
|
||||
using System.Threading.Tasks;
|
||||
using isnd.Data.Catalog;
|
||||
|
||||
namespace isnd.Controllers
|
||||
{
|
||||
// TODO /search GET {@id}?q={QUERY}&skip={SKIP}&take={TAKE}&prerelease={PRERELEASE}&semVerLevel={SEMVERLEVEL}&packageType={PACKAGETYPE}
|
||||
|
||||
public partial class PackagesController
|
||||
{
|
||||
// Web get the paquet
|
||||
[HttpGet("~" + Constants.ApiVersionPrefix + ApiConfig.Search)]
|
||||
[HttpHead("~" + Constants.ApiVersionPrefix + ApiConfig.Search)]
|
||||
public async Task<IActionResult> Search(
|
||||
string q=null,
|
||||
int skip=0,
|
||||
int take=25,
|
||||
bool prerelease=false,
|
||||
string semVerLevel = "2.0.0",
|
||||
string packageType = null)
|
||||
{
|
||||
PackageRegistrationQuery query = new PackageRegistrationQuery
|
||||
{
|
||||
Prerelease= prerelease,
|
||||
Query = q,
|
||||
Skip = skip,
|
||||
Take = take
|
||||
};
|
||||
var result = await packageManager.SearchPackageAsync(query);
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace isnd.Data.Packages
|
||||
{
|
||||
public interface IPackage
|
||||
{
|
||||
string Id { get; set; }
|
||||
string OwnerId { get; set; }
|
||||
string Description { get; set; }
|
||||
bool Public { get; set; }
|
||||
ApplicationUser Owner { get; set; }
|
||||
List<PackageVersion> Versions { get; set; }
|
||||
long CommitNId { get; set; }
|
||||
string CommitId { get; }
|
||||
Commit LatestCommit { get; set; }
|
||||
DateTimeOffset CommitTimeStamp { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using isnd.Data.ApiKeys;
|
||||
|
||||
|
||||
namespace isnd.Interfaces
|
||||
{
|
||||
public interface IApiKeyProvider
|
||||
{
|
||||
Task<ApiKey> CreateApiKeyAsync(CreateModel model);
|
||||
IQueryable<ApiKey> GetUserKeys(string identityName);
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using isnd.Data;
|
||||
using isnd.Data.ApiKeys;
|
||||
using isnd.Entities;
|
||||
using isnd.Interfaces;
|
||||
using Microsoft.AspNetCore.DataProtection;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace isnd;
|
||||
|
||||
|
||||
public class ApiKeyProvider : IApiKeyProvider
|
||||
{
|
||||
private readonly IsndSettings isndSettings;
|
||||
private readonly IDataProtector protector;
|
||||
private readonly ApplicationDbContext dbContext;
|
||||
|
||||
public ApiKeyProvider(
|
||||
ApplicationDbContext dbContext,
|
||||
IDataProtectionProvider dataProtectionProvider, IOptions<IsndSettings> isndSettingsOptions)
|
||||
{
|
||||
this.dbContext = dbContext;
|
||||
isndSettings = isndSettingsOptions.Value;
|
||||
protector = dataProtectionProvider.CreateProtector(isndSettings.ProtectionTitle);
|
||||
}
|
||||
|
||||
public async Task<ApiKey> CreateApiKeyAsync(CreateModel model)
|
||||
{
|
||||
var newKey = new ApiKey{
|
||||
UserId = model.UserId,
|
||||
CreationDate = DateTime.Now,
|
||||
Name = model.Name,
|
||||
ValidityPeriodInDays = model.ValidityPeriodInDays
|
||||
};
|
||||
|
||||
_ = dbContext.ApiKeys.Add(newKey);
|
||||
_ = await dbContext.SaveChangesAsync();
|
||||
return newKey;
|
||||
}
|
||||
|
||||
public IQueryable<ApiKey> GetUserKeys(string identityName)
|
||||
{
|
||||
return dbContext.ApiKeys.Include(k => k.User).Where(k => k.User.UserName == identityName);
|
||||
}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using isnd.Data.Catalog;
|
||||
using Newtonsoft.Json;
|
||||
using NuGet.Packaging.Core;
|
||||
using NuGet.Protocol.Core.Types;
|
||||
|
||||
namespace isnd.ViewModels
|
||||
{
|
||||
public class PackageHit : Permalink
|
||||
{
|
||||
public PackageHit(string id) : base(id, "Package")
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The full SemVer 2.0.0 version string of the package (could contain build metadata)
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
[Required]
|
||||
public string version { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// All of the versions of the package matching the prerelease parameter
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public SearchVersionInfo[] versions { get; set; }
|
||||
|
||||
public string description { get; set; }
|
||||
|
||||
public string[] authors { get; set; }
|
||||
public string iconUrl { get; set; }
|
||||
public string licenseUrl { get; set; }
|
||||
public string projectUrl { get; set; }
|
||||
/// <summary>
|
||||
/// The absolute URL to the associated registration index
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public string registration { get; set; }
|
||||
public string summary { get; set; }
|
||||
public string[] tags { get; set; }
|
||||
public string title { get; set; }
|
||||
/// <summary>
|
||||
/// This value can be inferred by the sum of downloads in the versions array
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public int totalDownloads { get; set; }
|
||||
/// <summary>
|
||||
/// boolean indicating whether the package is verified
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public bool verified { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The package types defined by the package author (added in SearchQueryService/3.5.0)
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
[Required]
|
||||
public PackageType[] packageTypes { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Reflection.Metadata.Ecma335;
|
||||
using System.Text.Json.Serialization;
|
||||
using isnd.Data.Packages;
|
||||
using isnd.Entities;
|
||||
|
||||
namespace isnd.ViewModels
|
||||
{
|
||||
public class PackageSearchResult
|
||||
{
|
||||
|
||||
public IEnumerable<Package> GetResults()
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
private IEnumerable<Package> result;
|
||||
|
||||
[JsonIgnore]
|
||||
public string ApiBase{get; private set;}
|
||||
|
||||
public PackageSearchResult(IEnumerable<Package> result, string apiBase, int totalHit)
|
||||
{
|
||||
this.result = result;
|
||||
this.ApiBase = apiBase;
|
||||
data=result.Select(r => NewPackageHit(apiBase, r)).ToArray();
|
||||
this.totalHits = totalHit;
|
||||
}
|
||||
|
||||
private static PackageHit NewPackageHit(string apiBase, Package package)
|
||||
{
|
||||
string regId = $"{apiBase}{ApiConfig.Registration}/{package.Id}/index.json";
|
||||
return new PackageHit(regId)
|
||||
{
|
||||
version = package.GetLatestVersion(),
|
||||
description = package.Description,
|
||||
title = package.Id,
|
||||
versions = package.Versions.Select(v => new SearchVersionInfo(regId, v)).ToArray()
|
||||
};
|
||||
}
|
||||
|
||||
public PackageHit[] data { get; protected set; }
|
||||
|
||||
public int totalHits { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
using isnd.Data.Catalog;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace isnd.ViewModels
|
||||
{
|
||||
public class SearchVersionInfo: Permalink
|
||||
{
|
||||
public SearchVersionInfo(string id, Data.PackageVersion v) : base(id, "VersionInfo")
|
||||
{
|
||||
Version = v.FullString;
|
||||
}
|
||||
|
||||
[JsonProperty("version")]
|
||||
public string Version { get; set; }
|
||||
|
||||
|
||||
[JsonProperty("downloads")]
|
||||
public long Downloads { get; set; }
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue