mirror of
https://onedev.site.tesses.net/crosslang/crosslangextras
synced 2026-02-08 09:05:46 +00:00
Add printing token support
This commit is contained in:
@@ -29,7 +29,8 @@ func Tesses.CrossLang.Shell.Default(dd)
|
||||
Console.WriteLine("add-project: add project as a dependency");
|
||||
Console.WriteLine("add-dependency: add package as dependency");
|
||||
Console.WriteLine("upload-package: upload package to cpkg");
|
||||
Console.WriteLine("login: login to cpkg");
|
||||
Console.WriteLine("token: get a session token for CI/CD pipeline (its interactive), you would put the token in the secrets manually.");
|
||||
Console.WriteLine("login: login to cpkg");
|
||||
Console.WriteLine("logout: logout from cpkg");
|
||||
Console.WriteLine("configdir: print the config directory");
|
||||
Console.WriteLine("update-shell: update the shell"); //this command is handled by runtime so we don't have to implement it here
|
||||
|
||||
@@ -18,6 +18,13 @@ func Tesses.CrossLang.Shell.Login(dd)
|
||||
if(dd.Arguments.Length < 3)
|
||||
{
|
||||
//not valid
|
||||
Console.WriteLine("USAGE: crosslang login [name] [host]");
|
||||
Console.WriteLine("USAGE: crosslang login [name] [host] [token]");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("ARGUMENTS:");
|
||||
Console.WriteLine("name: the session name");
|
||||
Console.WriteLine("host: the host of the package server such as https://cpkg.tesseslanguage.com/");
|
||||
Console.WriteLIne("token: allows you to login from an existing session token, if it is not included this will ask for email and password");
|
||||
}
|
||||
else if(dd.Arguments.Length == 3)
|
||||
{
|
||||
|
||||
@@ -62,6 +62,9 @@ func main(args)
|
||||
case "upload-package":
|
||||
return Tesses.CrossLang.Shell.UploadPackage(dd);
|
||||
break;
|
||||
case "token":
|
||||
return Tesses.CrossLang.Shell.Token(dd);
|
||||
break;
|
||||
case "login":
|
||||
return Tesses.CrossLang.Shell.Login(dd);
|
||||
break;
|
||||
|
||||
43
Tesses.CrossLang.Shell/src/token.tcross
Normal file
43
Tesses.CrossLang.Shell/src/token.tcross
Normal file
@@ -0,0 +1,43 @@
|
||||
func Tesses.CrossLang.Shell.Token(dd)
|
||||
{
|
||||
Console.Write("Host: ");
|
||||
var host = Console.ReadLine();
|
||||
Console.Write("Email: ");
|
||||
var email = Console.ReadLine();
|
||||
Console.Write("Password: ");
|
||||
|
||||
var echo = Console.Echo;
|
||||
Console.Echo = false;
|
||||
var password = Console.ReadLine();
|
||||
Console.Echo = echo;
|
||||
Console.WriteLine();
|
||||
|
||||
|
||||
|
||||
var accountRequest = {
|
||||
email,
|
||||
password
|
||||
};
|
||||
|
||||
var req = {
|
||||
Method="POST",
|
||||
Body = Net.Http.TextHttpRequestBody(accountRequest.ToString(),"application/json")
|
||||
};
|
||||
|
||||
var http = Net.Http.MakeRequest($"{host.TrimEnd('/')}/api/v1/login",req);
|
||||
if(http.StatusCode == 401 && http.ResponseHeaders.TryGetFirst("Content-Type") == "application/json")
|
||||
{
|
||||
|
||||
var json = Json.Decode(http.ReadAsString());
|
||||
Console.WriteLined($"Failed to login, reason={json.reason}");
|
||||
return 1;
|
||||
}
|
||||
else if(http.ResponseHeaders.TryGetFirst("Content-Type") == "application/json")
|
||||
{
|
||||
var json = Json.Decode(http.ReadAsString());
|
||||
Console.WriteLine("This will only be shown once");
|
||||
Console.WriteLine($"Here you go: {json.token}");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user