Add printing token support

This commit is contained in:
2025-09-08 12:46:10 -05:00
parent 12536a5572
commit 2dc726ae4c
4 changed files with 55 additions and 1 deletions

View File

@@ -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

View File

@@ -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)
{

View File

@@ -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;

View 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}");
}
}