refactoring + [WIP/ci]

This commit is contained in:
2018-07-28 01:55:13 +02:00
parent 77bad2356e
commit 46d7a57169
12 changed files with 167 additions and 71 deletions

View File

@ -0,0 +1,58 @@
using System.ComponentModel.DataAnnotations;
public class CiBuildSettings
{
/// <summary>
/// A command specification (a system command),
/// in order to reference some trusted server-side process
/// </summary>
public class Command
{
[Required]
public string Path { get; set; }
public string[] Args { get; set; }
/// <summary>
/// Specific variables to this process
/// </summary>
/// <value></value>
public string[] Environment { get; set; }
public string WorkingDir { get; set; }
}
/// <summary>
/// The global process environment variables
/// </summary>
/// <value></value>
public string[] Environment { get; set; }
/// <summary>
/// The required building command.
/// </summary>
/// <value></value>
[Required]
public Command Build { get; set; }
/// <summary>
/// A preparing command.
/// It is optional, but when specified,
/// must end ok in order to launch the build.
/// </summary>
/// <value></value>
public Command Prepare { get; set; }
/// <summary>
/// A post-production command,
/// for an example, some publishing,
/// push in prod env ...
/// only fired on successful build.
/// </summary>
/// <value></value>
public Command PostProduction { get; set; }
/// <summary>
/// Additional emails, as dest of notifications
/// </summary>
/// <value></value>
public string[] Emails { get; set; }
}

View File

@ -0,0 +1,56 @@
namespace cli
{
using Yavsc.Abstract.Identity;
using Yavsc;
using System.ComponentModel.DataAnnotations.Schema;
using Newtonsoft.Json;
using Yavsc.Authentication;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
public class ConnectionSettings
{
public TokenInfo UserToken { get; set; }
public SiteSettings Site { get; set; }
public OAuth2AppSettings ServerApiKey { get; set; }
public string SiteAccessSheme { get; set; } = "http";
public string Scope { get; set; } = "profile";
[NotMapped]
[JsonIgnore]
public string AuthorizeUrl {get {
return $"{SiteAccessSheme}://{Site.Authority}/authorize";
} }
[NotMapped]
[JsonIgnore]
public string RedirectUrl {get {
return $"{SiteAccessSheme}://{Site.Authority}/oauth/success";
} }
[NotMapped]
[JsonIgnore]
public string AccessTokenUrl {get {
return $"{SiteAccessSheme}://{Site.Authority}/token";
} }
public async Task InitUserTokenFromLoginPass(string login, string pass)
{
var oauthor =new OAuthenticator( ServerApiKey.ClientId, ServerApiKey.ClientSecret, Scope,
new Uri( AuthorizeUrl) , new Uri(RedirectUrl) , new Uri(AccessTokenUrl));
var query = new Dictionary<string,string>();
query["username"]=login;
query["password"]=pass;
query["grant_type"]="password";
var result = await oauthor.RequestAccessTokenAsync(query);
UserToken = new TokenInfo {
AccessToken = result["access_token"],
RefreshToken = result["refresh_token"],
Received = DateTime.Now,
ExpiresIn = int.Parse(result["expires_in"]),
TokenType = result["token_type"]
};
}
}
}