Skip to content

Commit

Permalink
Merge pull request #87 from trickest/feat/platform-ux-improvements
Browse files Browse the repository at this point in the history
UX improvements for using the CLI as a Trickest workflow node
  • Loading branch information
mhmdiaa authored Jul 20, 2023
2 parents ca41821 + 3e74357 commit 1884613
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 14 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ docker run quay.io/trickest/trickest-cli

# Authentication

You can find your authentication token on [My Account](https://trickest.io/dashboard/settings/my-account) page inside the the Trickest platform.
You can find your authentication token on the [Token](https://trickest.io/dashboard/settings/token) page inside the Trickest platform.

The authentication token can be provided as a flag `--token` or an environment variable `TRICKEST_TOKEN` to the trickest-cli.
The authentication token can be provided through either a string flag `--token`, a file `--token-file`, or an environment variable `TRICKEST_TOKEN`.

The `TRICKEST_TOKEN` supplied as `--token` will take priority if both are present.
The token supplied as `--token` or `--token-file` will take priority over the environment variable if both are present.

# Usage

Expand Down
5 changes: 5 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package cmd

import (
"log"

"github.com/trickest/trickest-cli/cmd/create"
"github.com/trickest/trickest-cli/cmd/delete"
"github.com/trickest/trickest-cli/cmd/execute"
Expand All @@ -26,14 +28,17 @@ var RootCmd = &cobra.Command{
// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
log.SetFlags(0)
cobra.CheckErr(RootCmd.Execute())
}

func init() {
RootCmd.PersistentFlags().StringVar(&util.Cfg.User.Token, "token", "", "Trickest authentication token")
RootCmd.PersistentFlags().StringVar(&util.Cfg.User.TokenFilePath, "token-file", "", "Trickest authentication token file")
RootCmd.PersistentFlags().StringVar(&util.SpaceName, "space", "", "Space name")
RootCmd.PersistentFlags().StringVar(&util.ProjectName, "project", "", "Project name")
RootCmd.PersistentFlags().StringVar(&util.WorkflowName, "workflow", "", "Workflow name")
RootCmd.PersistentFlags().StringVar(&util.Cfg.Dependency, "node-dependency", "", "This flag doesn't affect the execution logic of the CLI in any way and is intended for controlling node execution order on the Trickest platform only.")

cobra.OnInitialize(util.CreateRequest, initVaultID)

Expand Down
8 changes: 5 additions & 3 deletions types/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import (

type Config struct {
User struct {
Token string
VaultId uuid.UUID
Token string
TokenFilePath string
VaultId uuid.UUID
}
BaseUrl string
BaseUrl string
Dependency string
}

type User struct {
Expand Down
27 changes: 19 additions & 8 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package util
import (
"encoding/json"
"fmt"
"log"
"net/http"
"os"
"strings"
Expand Down Expand Up @@ -47,16 +48,26 @@ func FormatPath() string {
}

func GetToken() string {
if Cfg.User.Token == "" {
tokenEnv, tokenSet := os.LookupEnv("TRICKEST_TOKEN")
if tokenSet {
Cfg.User.Token = tokenEnv
} else {
fmt.Println("Trickest authentication token not set! Use --token or TRICKEST_TOKEN environment variable.")
os.Exit(0)
if Cfg.User.Token != "" {
return Cfg.User.Token
}

if Cfg.User.TokenFilePath != "" {
token, err := os.ReadFile(Cfg.User.TokenFilePath)
if err != nil {
log.Fatal("Couldn't read the token file: ", err)
}
Cfg.User.Token = string(token)
return Cfg.User.Token
}
return Cfg.User.Token

if tokenEnv, tokenSet := os.LookupEnv("TRICKEST_TOKEN"); tokenSet {
Cfg.User.Token = tokenEnv
return tokenEnv
}

log.Fatal("Trickest authentication token not set! Use --token, --token-file, or TRICKEST_TOKEN environment variable.")
return ""
}

func GetVault() uuid.UUID {
Expand Down

0 comments on commit 1884613

Please sign in to comment.