From 2f1e2acc69564c7b4aaf76f13a10176ce443fe78 Mon Sep 17 00:00:00 2001 From: Maidul Islam Date: Sun, 20 Nov 2022 18:47:21 -0500 Subject: [PATCH 1/3] Update to new backend --- cli/README.md | 102 ------------------------------- cli/packages/cmd/login.go | 14 ++--- cli/packages/cmd/root.go | 2 +- cli/packages/util/common.go | 2 +- cli/packages/util/credentials.go | 2 +- cli/packages/util/secrets.go | 8 ++- 6 files changed, 13 insertions(+), 117 deletions(-) delete mode 100644 cli/README.md diff --git a/cli/README.md b/cli/README.md deleted file mode 100644 index 469134152..000000000 --- a/cli/README.md +++ /dev/null @@ -1,102 +0,0 @@ -## Install -#### Windows -Use [Scoop](https://scoop.sh/) package manager - -``` -$ scoop bucket add org https://github.com/Infisical/scoop-infisical.git -$ scoop install infisical -$ infisical --version -``` - -To update: - -``` -$ scoop update infisical -``` - -#### Mac OS -Use [brew](https://brew.sh/) package manager - -``` -$ brew install infisical/get-cli/infisical -$ infisical --version -``` - -To update: - -``` -$ brew upgrade infisical -``` - -#### Linux -##### Debian/Ubuntu (package manager: apt) - -``` -Add Infisical apt repo -$ echo "deb [trusted=yes] https://apt.fury.io/infisical/ /" | tee -a /etc/apt/sources.list.d/infisical.list - -Add prerequisites -$ apt update && apt -y install ca-certificates sudo - -Install infisical cli -$ sudo apt update && apt install infisical - -To make sure the CLI has been installed, you may run this command. -$ infisical --version -``` - -We do not yet have repositores setup for APK, YUM and APT package managers. However, we have several binaries which can be downloaded manually for your Linux. Please vist the [release age](https://github.com/Infisical/infisical/releases) - -#### Install via bash and curl -This script will attempt to download the correct version of Infisical CLI and add it to your path. No package manager needed. - -``` -curl https://raw.githubusercontent.com/Infisical/infisical/main/scripts/install.sh | sh -``` - -## Local Usage -Once you have the CLI installed, using it is easy. - -#### Steps 1 -Create a project at https://infisical.com/ if you haven't already add your secrets to it. - -#### Step 2 -Login to the CLI by running the following command in your terminal - -``` -infisical login -``` - -#### Step 3 -After logging in, `CD` to the root of the project where you would like to inject your secrets into. Once you are in the root, run the following command in the terminal to link your Infisical project to your local project. - -``` -infisical init -``` - -#### Step 3 -To inject the secrets from the project you have selected into your application process, run the following command. - -``` -infisical run -- -``` - -Example: - -``` -infisical run -- npm run dev -``` - -## General production Usage -Once you have the binary installed in your production environment, injecting secrets is easy. - -#### Steps 1 -Get a Infisical Token for your project by visiting BLANK. Also note down the project ID for which you created the token for. - -#### Steps 2 -Ensure your application has the environment variable `INFISICAL_TOKEN` asigned to the token you received in step one. Then run - -``` -infisical run --projectId= -- -``` - diff --git a/cli/packages/cmd/login.go b/cli/packages/cmd/login.go index 7f68c5cd1..86b74c664 100644 --- a/cli/packages/cmd/login.go +++ b/cli/packages/cmd/login.go @@ -28,8 +28,9 @@ var loginCmd = &cobra.Command{ PreRun: toggleDebug, Run: func(cmd *cobra.Command, args []string) { hasUserLoggedInbefore, currentLoggedInUserEmail, err := util.IsUserLoggedIn() + if err != nil { - log.Debugln(err) + log.Debugln("Unable to get current logged in user.", err) } if hasUserLoggedInbefore { @@ -45,12 +46,6 @@ var loginCmd = &cobra.Command{ } } - if err != nil { - log.Errorln("Unable to get current logged in user.") - log.Debugln(err) - return - } - email, password, err := askForLoginCredentials() if err != nil { log.Errorln("Unable to parse email and password for authentication") @@ -160,6 +155,7 @@ func askForLoginCredentials() (email string, password string, err error) { } func getFreshUserCredentials(email string, password string) (*models.LoginTwoResponse, error) { + log.Debugln("getFreshUserCredentials:", "email", email, "password", password) httpClient := resty.New() httpClient.SetRetryCount(5) @@ -180,7 +176,7 @@ func getFreshUserCredentials(email string, password string) (*models.LoginTwoRes R(). SetBody(loginOneRequest). SetResult(&loginOneResponseResult). - Post(fmt.Sprintf("%v/%v", util.INFISICAL_URL, "login1")) + Post(fmt.Sprintf("%v/v1/auth/login1", util.INFISICAL_URL)) if err != nil { return nil, err @@ -216,7 +212,7 @@ func getFreshUserCredentials(email string, password string) (*models.LoginTwoRes R(). SetBody(LoginTwoRequest). SetResult(&loginTwoResponseResult). - Post(fmt.Sprintf("%v/%v", util.INFISICAL_URL, "login2")) + Post(fmt.Sprintf("%v/v1/auth/login2", util.INFISICAL_URL)) if err != nil { return nil, err diff --git a/cli/packages/cmd/root.go b/cli/packages/cmd/root.go index 0c6d31aa6..1fa6e5abc 100644 --- a/cli/packages/cmd/root.go +++ b/cli/packages/cmd/root.go @@ -30,5 +30,5 @@ func Execute() { func init() { rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") rootCmd.PersistentFlags().BoolVarP(&debugLogging, "debug", "d", false, "Enable verbose logging") - rootCmd.PersistentFlags().StringVar(&util.INFISICAL_URL, "domain", "http://localhost:4000", "Point the CLI to your own backend") + rootCmd.PersistentFlags().StringVar(&util.INFISICAL_URL, "domain", "https://app.infisical.com/api", "Point the CLI to your own backend") } diff --git a/cli/packages/util/common.go b/cli/packages/util/common.go index bfe61c388..05b3497d2 100644 --- a/cli/packages/util/common.go +++ b/cli/packages/util/common.go @@ -12,7 +12,7 @@ const ( INFISICAL_SERVICE_TOKEN = "INFISICAL_SERVICE_TOKEN" ) -var INFISICAL_URL = "https://api.infisical.com" +var INFISICAL_URL = "https://app.infisical.com/api" func GetHomeDir() (string, error) { directory, err := os.UserHomeDir() diff --git a/cli/packages/util/credentials.go b/cli/packages/util/credentials.go index 984d5a0d1..c5396f698 100644 --- a/cli/packages/util/credentials.go +++ b/cli/packages/util/credentials.go @@ -81,7 +81,7 @@ func IsUserLoggedIn() (hasUserLoggedIn bool, theUsersEmail string, err error) { response, err := httpClient. R(). - Post(fmt.Sprintf("%v/%v", INFISICAL_URL, "checkAuth")) + Post(fmt.Sprintf("%v/v1/auth/checkAuth", INFISICAL_URL)) if err != nil { return false, "", err diff --git a/cli/packages/util/secrets.go b/cli/packages/util/secrets.go index 2bff58b62..475640713 100644 --- a/cli/packages/util/secrets.go +++ b/cli/packages/util/secrets.go @@ -31,7 +31,9 @@ func GetSecretsFromAPIUsingCurrentLoggedInUser(envName string, userCreds models. SetQueryParam("environment", envName). SetQueryParam("channel", "cli"). SetResult(&pullSecretsRequestResponse). - Get(fmt.Sprintf("%v/%v/%v", INFISICAL_URL, "secret", workspace.WorkspaceId)) // need to change workspace id + Get(fmt.Sprintf("%v/v1/secret/%v", INFISICAL_URL, workspace.WorkspaceId)) // need to change workspace id + + log.Debugln("Response from get secrets:", response) if err != nil { return nil, err @@ -116,7 +118,7 @@ func GetSecretsFromAPIUsingInfisicalToken(infisicalToken string, envName string, SetQueryParam("environment", envName). SetQueryParam("channel", "cli"). SetResult(&pullSecretsByInfisicalTokenResponse). - Get(fmt.Sprintf("%v/secret/%v/service-token", INFISICAL_URL, projectId)) + Get(fmt.Sprintf("%v/v1/secret/%v/service-token", INFISICAL_URL, projectId)) if err != nil { return nil, err @@ -191,7 +193,7 @@ func GetWorkSpacesFromAPI(userCreds models.UserCredentials) (workspaces []models response, err := httpClient. R(). SetResult(&getWorkSpacesResponse). - Get(fmt.Sprintf("%v/%v", INFISICAL_URL, "workspace")) + Get(fmt.Sprintf("%v/v1/workspace", INFISICAL_URL)) if err != nil { return nil, err From 16061a0b8dd0b6fb19e04b3de51431b8059ee564 Mon Sep 17 00:00:00 2001 From: Maidul Islam Date: Sun, 20 Nov 2022 22:50:40 -0500 Subject: [PATCH 2/3] increase version and fix infisical token name --- cli/packages/cmd/root.go | 2 +- cli/packages/cmd/run.go | 2 +- cli/packages/util/common.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cli/packages/cmd/root.go b/cli/packages/cmd/root.go index 1fa6e5abc..dfb150072 100644 --- a/cli/packages/cmd/root.go +++ b/cli/packages/cmd/root.go @@ -15,7 +15,7 @@ var rootCmd = &cobra.Command{ Short: "Infisical CLI is used to inject environment variables into any process", Long: `Infisical is a simple, end-to-end encrypted service that enables teams to sync and manage their environment variables across their development life cycle.`, CompletionOptions: cobra.CompletionOptions{DisableDefaultCmd: true}, - Version: "1.0.0", + Version: "1.0.1", } // Execute adds all child commands to the root command and sets flags appropriately. diff --git a/cli/packages/cmd/run.go b/cli/packages/cmd/run.go index 89dda0162..1c07f06c8 100644 --- a/cli/packages/cmd/run.go +++ b/cli/packages/cmd/run.go @@ -41,7 +41,7 @@ var runCmd = &cobra.Command{ } var envsFromApi []models.SingleEnvironmentVariable - infisicalToken := os.Getenv(util.INFISICAL_SERVICE_TOKEN) + infisicalToken := os.Getenv(util.INFISICAL_TOKEN_NAME) if infisicalToken == "" { hasUserLoggedInbefore, loggedInUserEmail, err := util.IsUserLoggedIn() if err != nil { diff --git a/cli/packages/util/common.go b/cli/packages/util/common.go index 05b3497d2..37c881994 100644 --- a/cli/packages/util/common.go +++ b/cli/packages/util/common.go @@ -9,7 +9,7 @@ const ( CONFIG_FILE_NAME = "infisical-config.json" CONFIG_FOLDER_NAME = ".infisical" INFISICAL_WORKSPACE_CONFIG_FILE_NAME = ".infisical.json" - INFISICAL_SERVICE_TOKEN = "INFISICAL_SERVICE_TOKEN" + INFISICAL_TOKEN_NAME = "INFISICAL_TOKEN" ) var INFISICAL_URL = "https://app.infisical.com/api" From 11b7309301ecf8e9cbba34392df1711f7faf13a1 Mon Sep 17 00:00:00 2001 From: Maidul Islam Date: Sun, 20 Nov 2022 22:51:57 -0500 Subject: [PATCH 3/3] ignore .infisical.json --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 10c764fba..f32a51384 100644 --- a/.gitignore +++ b/.gitignore @@ -49,3 +49,6 @@ yarn-error.log* .env.production.local .vercel .env.infisical + +# Infisical init +.infisical.json