Skip to content

Commit

Permalink
Merge pull request #242 from asheliahut/add-domain-env
Browse files Browse the repository at this point in the history
Allow INFISICAL_URL to use domain for self-hosted
  • Loading branch information
maidul98 authored Jan 21, 2023
2 parents ffe66a3 + d3a6977 commit 7470cd7
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
15 changes: 13 additions & 2 deletions cli/packages/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ package cmd
import (
"os"

"github.com/Infisical/infisical-merge/packages/config"
"github.com/spf13/cobra"

"github.com/Infisical/infisical-merge/packages/config"
"github.com/Infisical/infisical-merge/packages/util"
)

var rootCmd = &cobra.Command{
Expand All @@ -30,7 +32,16 @@ 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(&config.INFISICAL_URL, "domain", "https://app.infisical.com/api", "Point the CLI to your own backend")
rootCmd.PersistentFlags().StringVar(&config.INFISICAL_URL, "domain", util.INFISICAL_DEFAULT_API_URL, "Point the CLI to your own backend [can also set via environment variable name: API_URL]")
// rootCmd.PersistentPreRun = func(cmd *cobra.Command, args []string) {
// }

// if config.INFISICAL_URL is set to the default value, check if INFISICAL_URL is set in the environment
// this is used to allow overrides of the default value
if !rootCmd.Flag("domain").Changed {
if envInfisicalBackendUrl, ok := os.LookupEnv("API_URL"); ok {
config.INFISICAL_URL = envInfisicalBackendUrl
}
}

}
2 changes: 1 addition & 1 deletion cli/packages/config/config.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package config

var INFISICAL_URL = "http://localhost:8080/api"
var INFISICAL_URL string
1 change: 1 addition & 0 deletions cli/packages/util/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package util
const (
CONFIG_FILE_NAME = "infisical-config.json"
CONFIG_FOLDER_NAME = ".infisical"
INFISICAL_DEFAULT_API_URL = "https://app.infisical.com/api"
INFISICAL_WORKSPACE_CONFIG_FILE_NAME = ".infisical.json"
INFISICAL_TOKEN_NAME = "INFISICAL_TOKEN"
SECRET_TYPE_PERSONAL = "personal"
Expand Down
26 changes: 23 additions & 3 deletions docs/cli/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The Infisical CLI provides a way to inject environment variables from the platfo
brew install infisical/get-cli/infisical
```

## Updates
### Updates

```bash
brew upgrade infisical
Expand All @@ -34,7 +34,7 @@ The Infisical CLI provides a way to inject environment variables from the platfo
scoop install infisical
```

## Updates
### Updates

```bash
scoop update infisical
Expand Down Expand Up @@ -99,8 +99,28 @@ The Infisical CLI provides a way to inject environment variables from the platfo
</Tab>
</Tabs>

## Log in to the Infisical CLI
### Log in to the Infisical CLI

```bash
infisical login
```

<Accordion title="Optional: point CLI to self-hosted">
The CLI is set to connect to Infisical Cloud by default, but if you're running your own instance of Infisical, you can direct the CLI to it using one of the methods provided below.

#### Export environment variable
You can point the CLI to the self hosted Infisical instance by exporting the environment variable `API_URL` in your terminal.

```bash
# Example
export API_URL="https://your-self-hosted-infisical.com/api"
```

#### Set manually on every command
Another option to point the CLI to your self hosted Infisical instance is to set it via a flag on every command you run.

```bash
# Example
infisical <any-command> --domain="https://your-self-hosted-infisical.com/api"
```
</Accordion>

0 comments on commit 7470cd7

Please sign in to comment.