From d627ecf05d9d7ba61338dd65d9f0b0d225efa609 Mon Sep 17 00:00:00 2001 From: = Date: Sat, 18 Jan 2025 17:05:29 +0530 Subject: [PATCH 1/3] feat: added region flag for eu in cli --- cli/packages/cmd/login.go | 6 +++++- cli/packages/cmd/root.go | 10 ++++++++++ docs/cli/commands/commands.mdx | 14 ++++++++------ 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/cli/packages/cmd/login.go b/cli/packages/cmd/login.go index 8f29c907a..9c26502e6 100644 --- a/cli/packages/cmd/login.go +++ b/cli/packages/cmd/login.go @@ -315,7 +315,11 @@ var loginCmd = &cobra.Command{ credential, err := authStrategies[strategy](cmd, infisicalClient) if err != nil { - util.HandleError(fmt.Errorf("unable to authenticate with %s [err=%v]", formatAuthMethod(loginMethod), err)) + euErrorMessage := "" + if strings.HasPrefix(config.INFISICAL_URL, util.INFISICAL_DEFAULT_US_URL) { + euErrorMessage = "\nIf you are using the Infisical Cloud Europe Region, please switch to it by using the \"--region eu\" flag." + } + util.HandleError(fmt.Errorf("unable to authenticate with %s [err=%v].%s", formatAuthMethod(loginMethod), err, euErrorMessage)) } if plainOutput { diff --git a/cli/packages/cmd/root.go b/cli/packages/cmd/root.go index 04af9cce8..0cb606a50 100644 --- a/cli/packages/cmd/root.go +++ b/cli/packages/cmd/root.go @@ -39,6 +39,7 @@ func Execute() { func init() { cobra.OnInitialize(initLog) rootCmd.PersistentFlags().StringP("log-level", "l", "info", "log level (trace, debug, info, warn, error, fatal)") + rootCmd.PersistentFlags().StringP("region", "r", "us", "Select the Infisical Cloud Region (us or eu). If the domain option is provided, this setting will be ignored.") rootCmd.PersistentFlags().Bool("telemetry", true, "Infisical collects non-sensitive telemetry data to enhance features and improve user experience. Participation is voluntary") rootCmd.PersistentFlags().StringVar(&config.INFISICAL_URL, "domain", fmt.Sprintf("%s/api", util.INFISICAL_DEFAULT_US_URL), "Point the CLI to your own backend [can also set via environment variable name: INFISICAL_API_URL]") rootCmd.PersistentFlags().Bool("silent", false, "Disable output of tip/info messages. Useful when running in scripts or CI/CD pipelines.") @@ -48,6 +49,15 @@ func init() { util.HandleError(err) } + region, err := cmd.Flags().GetString("region") + if err != nil { + util.HandleError(err) + } + + if region == "eu" { + config.INFISICAL_URL = util.INFISICAL_DEFAULT_EU_URL + } + config.INFISICAL_URL = util.AppendAPIEndpoint(config.INFISICAL_URL) if !util.IsRunningInDocker() && !silent { diff --git a/docs/cli/commands/commands.mdx b/docs/cli/commands/commands.mdx index 78870defc..a020dc650 100644 --- a/docs/cli/commands/commands.mdx +++ b/docs/cli/commands/commands.mdx @@ -11,11 +11,13 @@ description: "Infisical CLI command overview" | `init` | Used to link a local project to the platform. | | `run` | Used to inject envars from the platform into an application process. | | `vault` | Used to manage where your login credentials are stored at rest | + ## Global options -| Option | Description | -| ----------------- | ----------------------------------------------- | -| `--help`, `-h` | List help for any command | -| `--debug`, `-d` | Enable verbose logging | -| `--domain` | Use to direct Infisical to a self-hosted domain | -| `--version`, `-v` | Print version information and quit | +| Option | Description | +| ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `--help`, `-h` | List help for any command | +| `--debug`, `-d` | Enable verbose logging | +| `--domain` | Use to direct Infisical to a self-hosted domain | +| `--version`, `-v` | Print version information and quit | +| `--region`, `-r` | By default, the Infisical domain points to the US cloud region at https://app.infisical.com. Setting the region flag to eu switches it to https://eu.infisical.com." | From a35d1aa72bcc0d9b6a2d99d7b2073572315fa296 Mon Sep 17 00:00:00 2001 From: = Date: Wed, 22 Jan 2025 12:18:58 +0530 Subject: [PATCH 2/3] feat: removed root flag and added description for domain --- cli/packages/cmd/login.go | 2 +- cli/packages/cmd/root.go | 10 ---------- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/cli/packages/cmd/login.go b/cli/packages/cmd/login.go index 9c26502e6..81bb0c754 100644 --- a/cli/packages/cmd/login.go +++ b/cli/packages/cmd/login.go @@ -317,7 +317,7 @@ var loginCmd = &cobra.Command{ if err != nil { euErrorMessage := "" if strings.HasPrefix(config.INFISICAL_URL, util.INFISICAL_DEFAULT_US_URL) { - euErrorMessage = "\nIf you are using the Infisical Cloud Europe Region, please switch to it by using the \"--region eu\" flag." + euErrorMessage = fmt.Sprintf("\nIf you are using the Infisical Cloud Europe Region, please switch to it by using the \"--domain %s\" flag.", util.INFISICAL_DEFAULT_EU_URL) } util.HandleError(fmt.Errorf("unable to authenticate with %s [err=%v].%s", formatAuthMethod(loginMethod), err, euErrorMessage)) } diff --git a/cli/packages/cmd/root.go b/cli/packages/cmd/root.go index 0cb606a50..04af9cce8 100644 --- a/cli/packages/cmd/root.go +++ b/cli/packages/cmd/root.go @@ -39,7 +39,6 @@ func Execute() { func init() { cobra.OnInitialize(initLog) rootCmd.PersistentFlags().StringP("log-level", "l", "info", "log level (trace, debug, info, warn, error, fatal)") - rootCmd.PersistentFlags().StringP("region", "r", "us", "Select the Infisical Cloud Region (us or eu). If the domain option is provided, this setting will be ignored.") rootCmd.PersistentFlags().Bool("telemetry", true, "Infisical collects non-sensitive telemetry data to enhance features and improve user experience. Participation is voluntary") rootCmd.PersistentFlags().StringVar(&config.INFISICAL_URL, "domain", fmt.Sprintf("%s/api", util.INFISICAL_DEFAULT_US_URL), "Point the CLI to your own backend [can also set via environment variable name: INFISICAL_API_URL]") rootCmd.PersistentFlags().Bool("silent", false, "Disable output of tip/info messages. Useful when running in scripts or CI/CD pipelines.") @@ -49,15 +48,6 @@ func init() { util.HandleError(err) } - region, err := cmd.Flags().GetString("region") - if err != nil { - util.HandleError(err) - } - - if region == "eu" { - config.INFISICAL_URL = util.INFISICAL_DEFAULT_EU_URL - } - config.INFISICAL_URL = util.AppendAPIEndpoint(config.INFISICAL_URL) if !util.IsRunningInDocker() && !silent { From b7be6bd1d96548f3d2943e4f6e31f82293019a08 Mon Sep 17 00:00:00 2001 From: = Date: Wed, 22 Jan 2025 14:41:24 +0530 Subject: [PATCH 3/3] feat: removed region flag in description --- docs/cli/commands/commands.mdx | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/docs/cli/commands/commands.mdx b/docs/cli/commands/commands.mdx index a020dc650..278f061b7 100644 --- a/docs/cli/commands/commands.mdx +++ b/docs/cli/commands/commands.mdx @@ -14,10 +14,9 @@ description: "Infisical CLI command overview" ## Global options -| Option | Description | -| ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `--help`, `-h` | List help for any command | -| `--debug`, `-d` | Enable verbose logging | -| `--domain` | Use to direct Infisical to a self-hosted domain | -| `--version`, `-v` | Print version information and quit | -| `--region`, `-r` | By default, the Infisical domain points to the US cloud region at https://app.infisical.com. Setting the region flag to eu switches it to https://eu.infisical.com." | +| Option | Description | +| ----------------- | ----------------------------------------------- | +| `--help`, `-h` | List help for any command | +| `--debug`, `-d` | Enable verbose logging | +| `--domain` | Use to direct Infisical to a self-hosted domain | +| `--version`, `-v` | Print version information and quit |