From 2dc726ae4c1fb9c2a1aeed93ce540067f91cdb84 Mon Sep 17 00:00:00 2001 From: Mike Nolan Date: Mon, 8 Sep 2025 12:46:10 -0500 Subject: [PATCH] Add printing token support --- Tesses.CrossLang.Shell/src/default.tcross | 3 +- Tesses.CrossLang.Shell/src/login.tcross | 7 ++++ Tesses.CrossLang.Shell/src/main.tcross | 3 ++ Tesses.CrossLang.Shell/src/token.tcross | 43 +++++++++++++++++++++++ 4 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 Tesses.CrossLang.Shell/src/token.tcross diff --git a/Tesses.CrossLang.Shell/src/default.tcross b/Tesses.CrossLang.Shell/src/default.tcross index f49fdcc..e8426e3 100644 --- a/Tesses.CrossLang.Shell/src/default.tcross +++ b/Tesses.CrossLang.Shell/src/default.tcross @@ -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 diff --git a/Tesses.CrossLang.Shell/src/login.tcross b/Tesses.CrossLang.Shell/src/login.tcross index bc898b9..c07053e 100644 --- a/Tesses.CrossLang.Shell/src/login.tcross +++ b/Tesses.CrossLang.Shell/src/login.tcross @@ -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) { diff --git a/Tesses.CrossLang.Shell/src/main.tcross b/Tesses.CrossLang.Shell/src/main.tcross index e2ce017..7570c03 100644 --- a/Tesses.CrossLang.Shell/src/main.tcross +++ b/Tesses.CrossLang.Shell/src/main.tcross @@ -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; diff --git a/Tesses.CrossLang.Shell/src/token.tcross b/Tesses.CrossLang.Shell/src/token.tcross new file mode 100644 index 0000000..0702a36 --- /dev/null +++ b/Tesses.CrossLang.Shell/src/token.tcross @@ -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}"); + + } + +} \ No newline at end of file