change flag --stage to --env

This commit is contained in:
Maidul Islam
2022-11-19 11:35:13 -05:00
parent 321b040fe7
commit 2062d667e8
4 changed files with 90 additions and 13 deletions

View File

@@ -22,13 +22,13 @@ var runCmd = &cobra.Command{
Use: "run [any infisical run command flags] -- [your application start command]",
Short: "Used to inject environments variables into your application process",
DisableFlagsInUseLine: true,
Example: "infisical run --stage=prod -- npm run dev",
Example: "infisical run --env=prod -- npm run dev",
Args: cobra.MinimumNArgs(1),
PreRun: toggleDebug,
Run: func(cmd *cobra.Command, args []string) {
stageName, err := cmd.Flags().GetString("stage")
envName, err := cmd.Flags().GetString("env")
if err != nil {
log.Errorln("Unable to parse the stage flag")
log.Errorln("Unable to parse the environment flag")
log.Debugln(err)
return
}
@@ -67,14 +67,14 @@ var runCmd = &cobra.Command{
return
}
envsFromApi, err = util.GetSecretsFromAPIUsingCurrentLoggedInUser(stageName, userCreds)
envsFromApi, err = util.GetSecretsFromAPIUsingCurrentLoggedInUser(envName, userCreds)
if err != nil {
log.Errorln("Something went wrong when pulling secrets using your logged in credentials. If the issue persists, double check your project id/try logging in again.")
log.Debugln(err)
return
}
} else {
envsFromApi, err = util.GetSecretsFromAPIUsingInfisicalToken(infisicalToken, stageName, projectId)
envsFromApi, err = util.GetSecretsFromAPIUsingInfisicalToken(infisicalToken, envName, projectId)
if err != nil {
log.Errorln("Something went wrong when pulling secrets using your Infisical token. Double check the token, project id or environment name (dev, prod, ect.)")
log.Debugln(err)
@@ -88,7 +88,7 @@ var runCmd = &cobra.Command{
func init() {
rootCmd.AddCommand(runCmd)
runCmd.Flags().StringP("stage", "s", "dev", "Set the stage (dev, prod, etc.) from which your secrets should be pulled from")
runCmd.Flags().StringP("env", "e", "dev", "Set the environment (dev, prod, etc.) from which your secrets should be pulled from")
runCmd.Flags().String("projectId", "", "The project ID from which your secrets should be pulled from")
}

View File

@@ -12,8 +12,8 @@ import (
"golang.org/x/crypto/nacl/box"
)
func GetSecretsFromAPIUsingCurrentLoggedInUser(stageName string, userCreds models.UserCredentials) ([]models.SingleEnvironmentVariable, error) {
log.Debugln("stageName", stageName, "userCreds", userCreds)
func GetSecretsFromAPIUsingCurrentLoggedInUser(envName string, userCreds models.UserCredentials) ([]models.SingleEnvironmentVariable, error) {
log.Debugln("envName", envName, "userCreds", userCreds)
// check if user has configured a workspace
workspace, err := GetWorkSpaceFromFile()
if err != nil {
@@ -28,7 +28,7 @@ func GetSecretsFromAPIUsingCurrentLoggedInUser(stageName string, userCreds model
var pullSecretsRequestResponse models.PullSecretsResponse
response, err := httpClient.
R().
SetQueryParam("environment", stageName).
SetQueryParam("environment", envName).
SetQueryParam("channel", "cli").
SetResult(&pullSecretsRequestResponse).
Get(fmt.Sprintf("%v/%v/%v", INFISICAL_URL, "secret", workspace.WorkspaceId)) // need to change workspace id
@@ -97,9 +97,9 @@ func GetSecretsFromAPIUsingCurrentLoggedInUser(stageName string, userCreds model
return listOfEnv, nil
}
func GetSecretsFromAPIUsingInfisicalToken(infisicalToken string, stageName string, projectId string) ([]models.SingleEnvironmentVariable, error) {
if infisicalToken == "" || projectId == "" || stageName == "" {
return nil, errors.New("infisical token, project id and or stage name cannot be empty")
func GetSecretsFromAPIUsingInfisicalToken(infisicalToken string, envName string, projectId string) ([]models.SingleEnvironmentVariable, error) {
if infisicalToken == "" || projectId == "" || envName == "" {
return nil, errors.New("infisical token, project id and or environment name cannot be empty")
}
splitToken := strings.Split(infisicalToken, ",")
JTWToken := splitToken[0]
@@ -113,7 +113,7 @@ func GetSecretsFromAPIUsingInfisicalToken(infisicalToken string, stageName strin
var pullSecretsByInfisicalTokenResponse models.PullSecretsByInfisicalTokenResponse
response, err := httpClient.
R().
SetQueryParam("environment", stageName).
SetQueryParam("environment", envName).
SetQueryParam("channel", "cli").
SetResult(&pullSecretsByInfisicalTokenResponse).
Get(fmt.Sprintf("%v/secret/%v/service-token", INFISICAL_URL, projectId))

View File

@@ -1,3 +1,23 @@
---
title: "Docker Compose"
---
## Instructions
### Step 1: Open the integrations csonsole
Open the Infisical Dashboard. Choose the project in which you want to set up the intergation. Go to the integrations tab in the left sidebar.
### Step 2: Authenticate with Heroku
Click on Heroku in the list of available integrations. Log in if asked by Heroku and provide the necessary permissions to Infisical. You will afterwards be redirected back to the integrations page.
Note: during an integration with Heroku, for security reasons, it is impossible to maintain end-to-end encryption. In theory, this lets Infisical decrypt yor environment variables. In practice, we can assure you that this will never be done, and it allows us to protect your secrets from bad actors online. The core Infisical service will always stay end-to-end encrypted. With any questions, reach out support@infisical.com.
### Step 3: Start integration
Once the integration is set up, choose a Heroku App that you want to sync the secrets to, and the Infisical project environment that you would to sync the secrets from. Click on the "Start Integration" button.
### Step 4: You're good to go!
The integration should now show status 'In Sync'. Every time you edit the secrets, they will be automatically pushed to Heroku. If you want to update anything in your integration, you will have to delete the current one and create a new one.

View File

@@ -1,3 +1,60 @@
---
title: "Docker"
---
### Step 1: Add CLI to your Dockerfile
<Tabs>
<Tab title="Alpine">
```dockerfile
RUN apk add --no-cache bash curl && curl -1sLf \
'https://dl.cloudsmith.io/public/infisical/infisical-cli/setup.alpine.sh' | bash \
&& apk add infisical
```
</Tab>
<Tab title="RedHat/CentOs/Amazon-linux">
```dockerfile
RUN curl -1sLf \
'https://dl.cloudsmith.io/public/infisical/infisical-cli/setup.rpm.sh' | sh \
&& yum install -y infisical
```
</Tab>
<Tab title="Debian/Ubuntu">
```dockerfile
RUN apt-get update && apt-get install -y bash curl && curl -1sLf \
'https://dl.cloudsmith.io/public/infisical/infisical-cli/setup.deb.sh' | bash \
&& apt-get update && apt-get install -y infisical
```
</Tab>
</Tabs>
### Step 2: Generate Infisical Token
In order for Infisical CLI to authenticate and retrieve your project's secrets without exposing your login credentials, you must generate a Infisical Token.
To learn how, visit [Infisical Token](../getting-started/cli/infisical-token). Once you have generated the token, keep it handy.
### Step 3: Set start command of your container
```dockerfile
CMD ["infisical", "--env=<you-project-env-name>", "projectId=<your-project-id>", "run", "---", "<your application start command>"]
```
Example
```dockerfile
CMD ["infisical", "--env=prod", "projectId=62faf98ae0b05e83239b5da41", "run", "---", "npm run start"]
```
| flag | Description |
| ------------ | ----------------------------------- |
| `--env` | This is the environment name the CLI will use to pull secrets from your project.
| `--projectId` | This is the project id of the token you generated in step 2. |
To learn more about the flags used above, please visit our [CLI guide](../getting-started/cli/cli-guide)
### Last step: Tell Docker your Infisical Token
The Infisical CLI looks out for a environment variable called `INFISICAL_TOKEN`. To expose this environment variable to
your container do the following when running the `docker run` command. Remember, the `INFISICAL_TOKEN` is the token you generated in
step 2.
```bash
docker run --env INFISICAL_TOKEN=<the-token-you-got-from-step-2>...
```