refact
parent
5de53a3cba
commit
476d35ae8a
@ -1,11 +1,9 @@
|
||||
/packages/
|
||||
/bin/
|
||||
/obj/
|
||||
test/nuget.host.tests/bin/
|
||||
test/nuget.host.tests/obj
|
||||
src/appled/bin/
|
||||
src/appled/obj/
|
||||
src/applec/obj
|
||||
src/applec/bin
|
||||
src/isnd/bin/
|
||||
src/isnd/obj/
|
||||
src/isn/obj
|
||||
src/isn/bin
|
||||
.vscode/launch.json
|
||||
src/applec/.vscode/
|
||||
src/isn/.vscode/
|
||||
test/isnd.tests/obj/
|
||||
test/isnd.tests/bin/
|
||||
|
@ -1,7 +0,0 @@
|
||||
{
|
||||
"msbuild": {
|
||||
"Configuration": "Debug",
|
||||
"CscToolPath": "/usr/bin",
|
||||
"CscToolExe": "csc"
|
||||
}
|
||||
}
|
@ -1,68 +0,0 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace nuget_cli
|
||||
{
|
||||
public class HttpClientServerQueryHandler
|
||||
{
|
||||
internal async Task UploadFilesToServerAsync(
|
||||
PushReport report, Uri uri,
|
||||
FileInfo fi, string apikey)
|
||||
|
||||
{
|
||||
try
|
||||
{
|
||||
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
|
||||
|
||||
using (var formdata = new MultipartFormDataContent("NKdKd9Yk"))
|
||||
{
|
||||
using (HttpClient client = new HttpClient())
|
||||
{
|
||||
var dispo = new ContentDispositionHeaderValue("file")
|
||||
{
|
||||
FileName = fi.Name,
|
||||
CreationDate = fi.CreationTime,
|
||||
DispositionType = "form-data",
|
||||
Size = fi.Length,
|
||||
ModificationDate = fi.LastAccessTime
|
||||
};
|
||||
|
||||
Stream fileStream = fi.OpenRead();
|
||||
var streamcontent = new StreamContent(fileStream);
|
||||
streamcontent.Headers.ContentDisposition = dispo;
|
||||
formdata.Add(streamcontent, "file", fi.Name);
|
||||
|
||||
client.BaseAddress = uri;
|
||||
HttpRequestMessage put = new HttpRequestMessage(HttpMethod.Put, uri)
|
||||
{
|
||||
Content = formdata
|
||||
};
|
||||
put.Headers.Add("X-NuGet-Client-Version", Constants.ClientVersion);
|
||||
put.Headers.Add("X-NuGet-ApiKey", apikey);
|
||||
put.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
|
||||
HttpResponseMessage response = await client.SendAsync(put);
|
||||
|
||||
response.EnsureSuccessStatusCode();
|
||||
report.StatusCode = response.StatusCode.ToString();
|
||||
var respstream = await response.Content.ReadAsStreamAsync();
|
||||
var sr = new StreamReader(respstream);
|
||||
report.Message = await sr.ReadToEndAsync();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception rex)
|
||||
{
|
||||
report.Message = rex.Message;
|
||||
report.StatusCode = "internal error";
|
||||
report.OK = false;
|
||||
Console.Error.WriteLine(rex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
@using nuget_host.Data
|
||||
@using nuget_host.ViewModels
|
||||
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
File diff suppressed because one or more lines are too long
@ -1,8 +0,0 @@
|
||||
/*!
|
||||
* Bootstrap Reboot v4.4.1 (https://getbootstrap.com/)
|
||||
* Copyright 2011-2019 The Bootstrap Authors
|
||||
* Copyright 2011-2019 Twitter, Inc.
|
||||
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
|
||||
* Forked from Normalize.css, licensed MIT (https://github.com/necolas/normalize.css/blob/master/LICENSE.md)
|
||||
*/*,::after,::before{box-sizing:border-box}html{font-family:sans-serif;line-height:1.15;-webkit-text-size-adjust:100%;-webkit-tap-highlight-color:transparent}article,aside,figcaption,figure,footer,header,hgroup,main,nav,section{display:block}body{margin:0;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,"Noto Sans",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";font-size:1rem;font-weight:400;line-height:1.5;color:#212529;text-align:left;background-color:#fff}[tabindex="-1"]:focus:not(:focus-visible){outline:0!important}hr{box-sizing:content-box;height:0;overflow:visible}h1,h2,h3,h4,h5,h6{margin-top:0;margin-bottom:.5rem}p{margin-top:0;margin-bottom:1rem}abbr[data-original-title],abbr[title]{text-decoration:underline;-webkit-text-decoration:underline dotted;text-decoration:underline dotted;cursor:help;border-bottom:0;-webkit-text-decoration-skip-ink:none;text-decoration-skip-ink:none}address{margin-bottom:1rem;font-style:normal;line-height:inherit}dl,ol,ul{margin-top:0;margin-bottom:1rem}ol ol,ol ul,ul ol,ul ul{margin-bottom:0}dt{font-weight:700}dd{margin-bottom:.5rem;margin-left:0}blockquote{margin:0 0 1rem}b,strong{font-weight:bolder}small{font-size:80%}sub,sup{position:relative;font-size:75%;line-height:0;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}a{color:#007bff;text-decoration:none;background-color:transparent}a:hover{color:#0056b3;text-decoration:underline}a:not([href]){color:inherit;text-decoration:none}a:not([href]):hover{color:inherit;text-decoration:none}code,kbd,pre,samp{font-family:SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace;font-size:1em}pre{margin-top:0;margin-bottom:1rem;overflow:auto}figure{margin:0 0 1rem}img{vertical-align:middle;border-style:none}svg{overflow:hidden;vertical-align:middle}table{border-collapse:collapse}caption{padding-top:.75rem;padding-bottom:.75rem;color:#6c757d;text-align:left;caption-side:bottom}th{text-align:inherit}label{display:inline-block;margin-bottom:.5rem}button{border-radius:0}button:focus{outline:1px dotted;outline:5px auto -webkit-focus-ring-color}button,input,optgroup,select,textarea{margin:0;font-family:inherit;font-size:inherit;line-height:inherit}button,input{overflow:visible}button,select{text-transform:none}select{word-wrap:normal}[type=button],[type=reset],[type=submit],button{-webkit-appearance:button}[type=button]:not(:disabled),[type=reset]:not(:disabled),[type=submit]:not(:disabled),button:not(:disabled){cursor:pointer}[type=button]::-moz-focus-inner,[type=reset]::-moz-focus-inner,[type=submit]::-moz-focus-inner,button::-moz-focus-inner{padding:0;border-style:none}input[type=checkbox],input[type=radio]{box-sizing:border-box;padding:0}input[type=date],input[type=datetime-local],input[type=month],input[type=time]{-webkit-appearance:listbox}textarea{overflow:auto;resize:vertical}fieldset{min-width:0;padding:0;margin:0;border:0}legend{display:block;width:100%;max-width:100%;padding:0;margin-bottom:.5rem;font-size:1.5rem;line-height:inherit;color:inherit;white-space:normal}progress{vertical-align:baseline}[type=number]::-webkit-inner-spin-button,[type=number]::-webkit-outer-spin-button{height:auto}[type=search]{outline-offset:-2px;-webkit-appearance:none}[type=search]::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{font:inherit;-webkit-appearance:button}output{display:inline-block}summary{display:list-item;cursor:pointer}template{display:none}[hidden]{display:none!important}
|
||||
/*# sourceMappingURL=bootstrap-reboot.min.css.map */
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Binary file not shown.
@ -1,6 +1,6 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
|
||||
namespace nuget_host.Authorization
|
||||
namespace isn.Authorization
|
||||
{
|
||||
internal class ValidApiKeyRequirement : IAuthorizationRequirement
|
||||
{
|
@ -1,7 +1,7 @@
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
|
||||
namespace nuget_host.Authorization
|
||||
namespace isn.Authorization
|
||||
{
|
||||
internal class ValidApiKeyRequirementHandler : AuthorizationHandler<ValidApiKeyRequirement>
|
||||
{
|
@ -1,4 +1,4 @@
|
||||
namespace nuget_host
|
||||
namespace isn
|
||||
{
|
||||
public static class Constants
|
||||
{
|
@ -1,9 +1,9 @@
|
||||
using System;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using nuget_host.Data;
|
||||
using isn.Data;
|
||||
|
||||
namespace nuget_host.Controllers
|
||||
namespace isn.Controllers
|
||||
{
|
||||
|
||||
public class NewUpdateController : Controller
|
@ -1,4 +1,4 @@
|
||||
namespace nuget_host.Controllers
|
||||
namespace isn.Controllers
|
||||
{
|
||||
internal class Resource
|
||||
{
|
@ -1,6 +1,6 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace nuget_host.Data.ApiKeys
|
||||
namespace isn.Data.ApiKeys
|
||||
{
|
||||
public class ApiKeyViewModel
|
||||
{
|
@ -1,6 +1,6 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace nuget_host.Data.ApiKeys
|
||||
namespace isn.Data.ApiKeys
|
||||
{
|
||||
public class CreateModel
|
||||
{
|
@ -1,4 +1,4 @@
|
||||
namespace nuget_host.Data.ApiKeys
|
||||
namespace isn.Data.ApiKeys
|
||||
{
|
||||
public class DeleteModel
|
||||
{
|
@ -1,4 +1,4 @@
|
||||
namespace nuget_host.Data.ApiKeys
|
||||
namespace isn.Data.ApiKeys
|
||||
{
|
||||
public class DetailModel : ApiKeyViewModel
|
||||
{
|
@ -1,4 +1,4 @@
|
||||
namespace nuget_host.Data.ApiKeys
|
||||
namespace isn.Data.ApiKeys
|
||||
{
|
||||
public class EditModel
|
||||
{
|
@ -1,6 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace nuget_host.Data.ApiKeys
|
||||
namespace isn.Data.ApiKeys
|
||||
{
|
||||
public class IndexModel
|
||||
{
|
@ -1,6 +1,6 @@
|
||||
using System;
|
||||
|
||||
namespace nuget_host.Data
|
||||
namespace isn.Data
|
||||
{
|
||||
public class NewReleaseInfo
|
||||
{
|
@ -1,4 +1,4 @@
|
||||
namespace nuget_host.Data.Roles
|
||||
namespace isn.Data.Roles
|
||||
{
|
||||
public class AdminStartupList
|
||||
{
|
@ -1,4 +1,4 @@
|
||||
namespace nuget_host.Entities
|
||||
namespace isn.Entities
|
||||
{
|
||||
public class NugetSettings
|
||||
{
|
@ -1,4 +1,4 @@
|
||||
namespace nuget_host.Entities
|
||||
namespace isn.Entities
|
||||
{
|
||||
public class SmtpSettings
|
||||
{
|
@ -0,0 +1,8 @@
|
||||
namespace isnd.Entities
|
||||
{
|
||||
public class UnleashClientSettings
|
||||
{
|
||||
public string ClientApiKey { get; set; }
|
||||
public string ApiUrl { get; set; }
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace nuget_host.Data
|
||||
namespace isn.Data
|
||||
{
|
||||
public static class Extensions
|
||||
{
|
@ -1,7 +1,7 @@
|
||||
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace nuget_host.Interfaces
|
||||
namespace isn.Interfaces
|
||||
{
|
||||
public interface IMailer
|
||||
{
|
@ -0,0 +1,140 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using isn.Controllers;
|
||||
using isn.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using NuGet.Versioning;
|
||||
using Unleash;
|
||||
|
||||
namespace isnd.Services
|
||||
{
|
||||
public class PackageManager
|
||||
{
|
||||
ApplicationDbContext dbContext;
|
||||
public PackageManager(ApplicationDbContext dbContext)
|
||||
{
|
||||
this.dbContext = dbContext;
|
||||
}
|
||||
public IndexResult SearchByName(string query,
|
||||
int skip, int take,bool prerelease = false,
|
||||
string packageType = null)
|
||||
{
|
||||
var scope = dbContext.Packages
|
||||
.Include(p => p.Versions)
|
||||
.Where(
|
||||
p => (CamelCaseMatch(p.Id, query) || SeparatedByMinusMatch(p.Id, query))
|
||||
&& (prerelease || p.Versions.Any(v => !v.IsPrerelease))
|
||||
&& (packageType == null || p.Versions.Any(v => v.Type == packageType))
|
||||
);
|
||||
return new IndexResult
|
||||
{
|
||||
totalHits = scope.Count(),
|
||||
data = scope.OrderBy(p => p.Id)
|
||||
.Skip(skip).Take(take).ToArray()
|
||||
};
|
||||
}
|
||||
public AutoCompleteResult AutoComplete (string id,
|
||||
int skip, int take, bool prerelease = false,
|
||||
string packageType = null)
|
||||
{
|
||||
var scope = dbContext.PackageVersions.Where(
|
||||
v => v.PackageId == id
|
||||
&& (prerelease || !v.IsPrerelease)
|
||||
&& (packageType == null || v.Type == packageType)
|
||||
)
|
||||
.OrderBy(v => v.FullString);
|
||||
return new AutoCompleteResult
|
||||
{
|
||||
totalHits = scope.Count(),
|
||||
data = scope.Select(v => v.FullString)
|
||||
.Skip(skip).Take(take).ToArray()
|
||||
};
|
||||
}
|
||||
|
||||
// TODO stocker MetaData plutôt que FullString en base,
|
||||
// et en profiter pour corriger ce listing
|
||||
public string[] GetVersions(
|
||||
string id,
|
||||
NuGetVersion parsedVersion,
|
||||
bool prerelease = false,
|
||||
string packageType = null,
|
||||
int skip = 0,
|
||||
int take = 25)
|
||||
{
|
||||
return dbContext.PackageVersions.Where(
|
||||
v => v.PackageId == id
|
||||
&& (prerelease || !v.IsPrerelease)
|
||||
&& (packageType == null || v.Type == packageType)
|
||||
&& (parsedVersion.CompareTo(new SemanticVersion(v.Major, v.Minor, v.Patch)) < 0)
|
||||
)
|
||||
.OrderBy(v => v.FullString)
|
||||
.Select(v => v.FullString)
|
||||
.Skip(skip).Take(take).ToArray();
|
||||
}
|
||||
|
||||
protected static bool CamelCaseMatch(string id, string q)
|
||||
{
|
||||
// Assert.False (q==null);
|
||||
string query = q;
|
||||
if (query.Length == 0) return false;
|
||||
|
||||
while (id.Length > 0)
|
||||
{
|
||||
int i = 0;
|
||||
while (id.Length > i && char.IsLower(id[i])) i++;
|
||||
if (i == 0) break;
|
||||
id = id.Substring(i);
|
||||
if (id.StartsWith(q, System.StringComparison.OrdinalIgnoreCase)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
protected static bool SeparatedByMinusMatch(string id, string q)
|
||||
{
|
||||
foreach (var part in id.Split('-'))
|
||||
{
|
||||
if (part.StartsWith(q, System.StringComparison.OrdinalIgnoreCase)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
internal List<Resource> GetResources(IUnleash unleashClient)
|
||||
{
|
||||
var res = new List<Resource>();
|
||||
if (unleashClient.IsEnabled("pkg-push"))
|
||||
res.Add(
|
||||
new Resource
|
||||
{
|
||||
id = "package",
|
||||
type = "PackagePublish/2.0.0",
|
||||
comment = "Package Publish service"
|
||||
});
|
||||
if (unleashClient.IsEnabled("pkg-get"))
|
||||
res.Add(
|
||||
new Resource
|
||||
{
|
||||
id = "package",
|
||||
type = "PackageBaseAddress/3.0.0",
|
||||
comment = "Package Base Address service"
|
||||
});
|
||||
if (unleashClient.IsEnabled("pkg-autocomplete"))
|
||||
res.Add(
|
||||
new Resource
|
||||
{
|
||||
id = "package/index.json",
|
||||
type = "SearchAutocompleteService/3.5.0",
|
||||
comment = "Auto complete service"
|
||||
});
|
||||
if (unleashClient.IsEnabled("pkg-search"))
|
||||
res.Add(
|
||||
new Resource
|
||||
{
|
||||
id = "package/index.json",
|
||||
type = "SearchQueryService/3.5.0",
|
||||
comment = "Search Query service"
|
||||
});
|
||||
return res;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using isn.Data;
|
||||
|
||||
namespace isnd.Services
|
||||
{
|
||||
public class IndexResult
|
||||
{
|
||||
public int totalHits { get; set; }
|
||||
public Package[] data { get; set; }
|
||||
}
|
||||
|
||||
public class AutoCompleteResult
|
||||
{
|
||||
public int totalHits { get; set; }
|
||||
public string[] data { get; set; }
|
||||
}
|
||||
}
|
@ -1,7 +1,11 @@
|
||||
namespace nuget_host.ViewModels
|
||||
using Unleash;
|
||||
|
||||
namespace isn.ViewModels
|
||||
{
|
||||
public class HomeIndexViewModel
|
||||
{
|
||||
public int PkgCount { get; set; }
|
||||
public IUnleash UnleashClient;
|
||||
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using nuget_host.Data;
|
||||
using isn.Data;
|
||||
|
||||
namespace nuget_host.ViewModels
|
||||
namespace isn.ViewModels
|
||||
{
|
||||
public class PackageVersionIndexViewModel
|
||||
{
|
@ -1,5 +1,5 @@
|
||||
|
||||
@model nuget_host.Data.ApiKeys.CreateModel
|
||||
@model isn.Data.ApiKeys.CreateModel
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Create";
|
@ -1,5 +1,5 @@
|
||||
|
||||
@model nuget_host.Data.ApiKeys.DeleteModel
|
||||
@model isn.Data.ApiKeys.DeleteModel
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Delete";
|
@ -1,5 +1,5 @@
|
||||
|
||||
@model nuget_host.Data.ApiKeys.DetailModel
|
||||
@model isn.Data.ApiKeys.DetailModel
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Details";
|
@ -1,5 +1,5 @@
|
||||
|
||||
@model nuget_host.Data.ApiKeys.EditModel
|
||||
@model isn.Data.ApiKeys.EditModel
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Edit";
|
@ -1,5 +1,5 @@
|
||||
|
||||
@model nuget_host.Data.ApiKeys.IndexModel
|
||||
@model isn.Data.ApiKeys.IndexModel
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Index";
|
@ -1,13 +1,27 @@
|
||||
@model HomeIndexViewModel
|
||||
@{
|
||||
ViewData["Title"] = "Home Page";
|
||||
|
||||
}
|
||||
|
||||
<div class="text-center">
|
||||
<h1 class="display-4">Welcome</h1>
|
||||
<h1>
|
||||
<img src="~/icon.jpg">
|
||||
Welcome to Apple
|
||||
Welcome to isn
|
||||
</h1>
|
||||
<strong>@Model.PkgCount identifiant(s) de paquet dans le SI</strong>
|
||||
|
||||
@{
|
||||
if (Model.UnleashClient.IsEnabled("Demo"))
|
||||
{
|
||||
//do some magic
|
||||
<p>Demo</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
//do old boring stuff
|
||||
<p>No demo (disabled)</p>
|
||||
}
|
||||
}
|
||||
</div>
|
@ -1,4 +1,4 @@
|
||||
@model nuget_host.Data.PackageVersion
|
||||
@model isn.Data.PackageVersion
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Delete";
|
@ -1,4 +1,4 @@
|
||||
@model nuget_host.Data.PackageVersion
|
||||
@model isn.Data.PackageVersion
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Details";
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue