Updates update service even more

This commit is contained in:
Karolis2011
2019-08-24 18:39:53 +03:00
parent 604fdbf21d
commit 402d1943c1
4 changed files with 188 additions and 10 deletions

View File

@@ -0,0 +1,34 @@
using LibGit2Sharp;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Text;
namespace ASS.Server.Services
{
class GitCredentialService
{
IConfiguration config;
ILogger logger;
public GitCredentialService(IConfiguration globalConfig, ILogger<GitCredentialService> log)
{
config = globalConfig;
logger = log;
}
public Credentials GetCredentials(string url, string usernameFromUrl, SupportedCredentialTypes types)
{
var uri = new Uri(url);
var cleaned = uri.Authority + uri.PathAndQuery + uri.Fragment;
var creds = config.GetSection("Repository:Credentials").GetSection(cleaned);
if (!string.IsNullOrEmpty(creds["Username"]) && !string.IsNullOrEmpty(creds["Password"]))
{
return new UsernamePasswordCredentials() { Username = creds["Username"], Password = creds["Password"] };
}
logger.LogWarning("Failed to get credentials for '{cleaned}'.", cleaned);
return null;
}
}
}