mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-06 21:27:10 +00:00
Merge pull request #1532 from rhythmbhiwani/get-only-value-from-cli
Feature to get only value of specific secret in `secrets get` command
This commit is contained in:
@@ -414,6 +414,11 @@ func getSecretsByNames(cmd *cobra.Command, args []string) {
|
|||||||
util.HandleError(err, "Unable to parse path flag")
|
util.HandleError(err, "Unable to parse path flag")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
showOnlyValue, err := cmd.Flags().GetBool("raw-value")
|
||||||
|
if err != nil {
|
||||||
|
util.HandleError(err, "Unable to parse path flag")
|
||||||
|
}
|
||||||
|
|
||||||
secrets, err := util.GetAllEnvironmentVariables(models.GetAllSecretsParameters{Environment: environmentName, InfisicalToken: infisicalToken, TagSlugs: tagSlugs, SecretsPath: secretsPath}, "")
|
secrets, err := util.GetAllEnvironmentVariables(models.GetAllSecretsParameters{Environment: environmentName, InfisicalToken: infisicalToken, TagSlugs: tagSlugs, SecretsPath: secretsPath}, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
util.HandleError(err, "To fetch all secrets")
|
util.HandleError(err, "To fetch all secrets")
|
||||||
@@ -435,7 +440,15 @@ func getSecretsByNames(cmd *cobra.Command, args []string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
visualize.PrintAllSecretDetails(requestedSecrets)
|
if showOnlyValue && len(requestedSecrets) > 1 {
|
||||||
|
util.PrintErrorMessageAndExit("--raw-value only works with one secret.")
|
||||||
|
}
|
||||||
|
|
||||||
|
if showOnlyValue {
|
||||||
|
fmt.Printf(requestedSecrets[0].Value)
|
||||||
|
} else {
|
||||||
|
visualize.PrintAllSecretDetails(requestedSecrets)
|
||||||
|
}
|
||||||
Telemetry.CaptureEvent("cli-command:secrets get", posthog.NewProperties().Set("secretCount", len(secrets)).Set("version", util.CLI_VERSION))
|
Telemetry.CaptureEvent("cli-command:secrets get", posthog.NewProperties().Set("secretCount", len(secrets)).Set("version", util.CLI_VERSION))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -669,6 +682,7 @@ func init() {
|
|||||||
secretsGetCmd.Flags().String("token", "", "Fetch secrets using the Infisical Token")
|
secretsGetCmd.Flags().String("token", "", "Fetch secrets using the Infisical Token")
|
||||||
secretsCmd.AddCommand(secretsGetCmd)
|
secretsCmd.AddCommand(secretsGetCmd)
|
||||||
secretsGetCmd.Flags().String("path", "/", "get secrets within a folder path")
|
secretsGetCmd.Flags().String("path", "/", "get secrets within a folder path")
|
||||||
|
secretsGetCmd.Flags().Bool("raw-value", false, "Returns only the value of secret, only works with one secret")
|
||||||
|
|
||||||
secretsCmd.Flags().Bool("secret-overriding", true, "Prioritizes personal secrets, if any, with the same name over shared secrets")
|
secretsCmd.Flags().Bool("secret-overriding", true, "Prioritizes personal secrets, if any, with the same name over shared secrets")
|
||||||
secretsCmd.AddCommand(secretsSetCmd)
|
secretsCmd.AddCommand(secretsSetCmd)
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ infisical secrets
|
|||||||
```
|
```
|
||||||
|
|
||||||
## Description
|
## Description
|
||||||
|
|
||||||
This command enables you to perform CRUD (create, read, update, delete) operations on secrets within your Infisical project. With it, you can view, create, update, and delete secrets in your environment.
|
This command enables you to perform CRUD (create, read, update, delete) operations on secrets within your Infisical project. With it, you can view, create, update, and delete secrets in your environment.
|
||||||
|
|
||||||
### Sub-commands
|
### Sub-commands
|
||||||
@@ -18,7 +19,8 @@ This command enables you to perform CRUD (create, read, update, delete) operatio
|
|||||||
$ infisical secrets
|
$ infisical secrets
|
||||||
```
|
```
|
||||||
|
|
||||||
### Environment variables
|
### Environment variables
|
||||||
|
|
||||||
<Accordion title="INFISICAL_TOKEN">
|
<Accordion title="INFISICAL_TOKEN">
|
||||||
Used to fetch secrets via a [service token](/documentation/platform/token) apposed to logged in credentials. Simply, export this variable in the terminal before running this command.
|
Used to fetch secrets via a [service token](/documentation/platform/token) apposed to logged in credentials. Simply, export this variable in the terminal before running this command.
|
||||||
|
|
||||||
@@ -26,6 +28,7 @@ This command enables you to perform CRUD (create, read, update, delete) operatio
|
|||||||
# Example
|
# Example
|
||||||
export INFISICAL_TOKEN=st.63e03c4a97cb4a747186c71e.ed5b46a34c078a8f94e8228f4ab0ff97.4f7f38034811995997d72badf44b42ec
|
export INFISICAL_TOKEN=st.63e03c4a97cb4a747186c71e.ed5b46a34c078a8f94e8228f4ab0ff97.4f7f38034811995997d72badf44b42ec
|
||||||
```
|
```
|
||||||
|
|
||||||
</Accordion>
|
</Accordion>
|
||||||
|
|
||||||
<Accordion title="INFISICAL_DISABLE_UPDATE_CHECK">
|
<Accordion title="INFISICAL_DISABLE_UPDATE_CHECK">
|
||||||
@@ -37,19 +40,23 @@ This command enables you to perform CRUD (create, read, update, delete) operatio
|
|||||||
# Example
|
# Example
|
||||||
export INFISICAL_DISABLE_UPDATE_CHECK=true
|
export INFISICAL_DISABLE_UPDATE_CHECK=true
|
||||||
```
|
```
|
||||||
|
|
||||||
</Accordion>
|
</Accordion>
|
||||||
|
|
||||||
### Flags
|
### Flags
|
||||||
|
|
||||||
<Accordion title="--expand">
|
<Accordion title="--expand">
|
||||||
Parse shell parameter expansions in your secrets
|
Parse shell parameter expansions in your secrets
|
||||||
|
|
||||||
Default value: `true`
|
Default value: `true`
|
||||||
|
|
||||||
</Accordion>
|
</Accordion>
|
||||||
|
|
||||||
<Accordion title="--env">
|
<Accordion title="--env">
|
||||||
Used to select the environment name on which actions should be taken on
|
Used to select the environment name on which actions should be taken on
|
||||||
|
|
||||||
Default value: `dev`
|
Default value: `dev`
|
||||||
|
|
||||||
</Accordion>
|
</Accordion>
|
||||||
<Accordion title="--path">
|
<Accordion title="--path">
|
||||||
The `--path` flag indicates which project folder secrets will be injected from.
|
The `--path` flag indicates which project folder secrets will be injected from.
|
||||||
@@ -58,6 +65,7 @@ This command enables you to perform CRUD (create, read, update, delete) operatio
|
|||||||
# Example
|
# Example
|
||||||
infisical secrets --path="/" --env=dev
|
infisical secrets --path="/" --env=dev
|
||||||
```
|
```
|
||||||
|
|
||||||
</Accordion>
|
</Accordion>
|
||||||
|
|
||||||
</Accordion>
|
</Accordion>
|
||||||
@@ -65,19 +73,34 @@ This command enables you to perform CRUD (create, read, update, delete) operatio
|
|||||||
<Accordion title="infisical secrets get">
|
<Accordion title="infisical secrets get">
|
||||||
This command allows you selectively print the requested secrets by name
|
This command allows you selectively print the requested secrets by name
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ infisical secrets get <secret-name-a> <secret-name-b> ...
|
$ infisical secrets get <secret-name-a> <secret-name-b> ...
|
||||||
|
|
||||||
# Example
|
# Example
|
||||||
$ infisical secrets get DOMAIN
|
$ infisical secrets get DOMAIN
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Flags
|
||||||
|
|
||||||
### Flags
|
|
||||||
<Accordion title="--env">
|
<Accordion title="--env">
|
||||||
Used to select the environment name on which actions should be taken on
|
Used to select the environment name on which actions should be taken on
|
||||||
|
|
||||||
Default value: `dev`
|
Default value: `dev`
|
||||||
|
|
||||||
|
</Accordion>
|
||||||
|
|
||||||
|
<Accordion title="--raw-value">
|
||||||
|
Used to print the plain value of a single requested secret without any table style.
|
||||||
|
|
||||||
|
Default value: `false`
|
||||||
|
|
||||||
|
Example: `infisical secrets get DOMAIN --value`
|
||||||
|
|
||||||
|
<Tip>
|
||||||
|
When running in CI/CD environments or in a script, set `INFISICAL_DISABLE_UPDATE_CHECK` env to `true`. This will help hide any CLI update messages and only show the secret value.
|
||||||
|
</Tip>
|
||||||
|
|
||||||
</Accordion>
|
</Accordion>
|
||||||
</Accordion>
|
</Accordion>
|
||||||
|
|
||||||
@@ -92,11 +115,13 @@ $ infisical secrets set <key1=value1> <key2=value2>...
|
|||||||
$ infisical secrets set STRIPE_API_KEY=sjdgwkeudyjwe DOMAIN=example.com HASH=jebhfbwe
|
$ infisical secrets set STRIPE_API_KEY=sjdgwkeudyjwe DOMAIN=example.com HASH=jebhfbwe
|
||||||
```
|
```
|
||||||
|
|
||||||
### Flags
|
### Flags
|
||||||
|
|
||||||
<Accordion title="--env">
|
<Accordion title="--env">
|
||||||
Used to select the environment name on which actions should be taken on
|
Used to select the environment name on which actions should be taken on
|
||||||
|
|
||||||
Default value: `dev`
|
Default value: `dev`
|
||||||
|
|
||||||
</Accordion>
|
</Accordion>
|
||||||
<Accordion title="--path">
|
<Accordion title="--path">
|
||||||
Used to select the project folder in which the secrets will be set. This is useful when creating new secrets under a particular path.
|
Used to select the project folder in which the secrets will be set. This is useful when creating new secrets under a particular path.
|
||||||
@@ -105,24 +130,27 @@ $ infisical secrets set STRIPE_API_KEY=sjdgwkeudyjwe DOMAIN=example.com HASH=jeb
|
|||||||
# Example
|
# Example
|
||||||
infisical secrets set DOMAIN=example.com --path="common/backend"
|
infisical secrets set DOMAIN=example.com --path="common/backend"
|
||||||
```
|
```
|
||||||
|
|
||||||
</Accordion>
|
</Accordion>
|
||||||
</Accordion>
|
</Accordion>
|
||||||
|
|
||||||
<Accordion title="infisical secrets delete">
|
<Accordion title="infisical secrets delete">
|
||||||
This command allows you to delete secrets by their name(s).
|
This command allows you to delete secrets by their name(s).
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ infisical secrets delete <keyName1> <keyName2>...
|
$ infisical secrets delete <keyName1> <keyName2>...
|
||||||
|
|
||||||
## Example
|
## Example
|
||||||
$ infisical secrets delete STRIPE_API_KEY DOMAIN HASH
|
$ infisical secrets delete STRIPE_API_KEY DOMAIN HASH
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Flags
|
||||||
|
|
||||||
### Flags
|
|
||||||
<Accordion title="--env">
|
<Accordion title="--env">
|
||||||
Used to select the environment name on which actions should be taken on
|
Used to select the environment name on which actions should be taken on
|
||||||
|
|
||||||
Default value: `dev`
|
Default value: `dev`
|
||||||
|
|
||||||
</Accordion>
|
</Accordion>
|
||||||
<Accordion title="--path">
|
<Accordion title="--path">
|
||||||
The `--path` flag indicates which project folder secrets will be injected from.
|
The `--path` flag indicates which project folder secrets will be injected from.
|
||||||
@@ -131,17 +159,19 @@ $ infisical secrets set STRIPE_API_KEY=sjdgwkeudyjwe DOMAIN=example.com HASH=jeb
|
|||||||
# Example
|
# Example
|
||||||
infisical secrets delete <keyName1> <keyName2>... --path="/"
|
infisical secrets delete <keyName1> <keyName2>... --path="/"
|
||||||
```
|
```
|
||||||
|
|
||||||
</Accordion>
|
</Accordion>
|
||||||
</Accordion>
|
</Accordion>
|
||||||
|
|
||||||
<Accordion title="infisical secrets folders">
|
<Accordion title="infisical secrets folders">
|
||||||
This command allows you to fetch, create and delete folders from within a path from a given project.
|
This command allows you to fetch, create and delete folders from within a path from a given project.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ infisical secrets folders
|
$ infisical secrets folders
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### sub commands
|
||||||
|
|
||||||
### sub commands
|
|
||||||
<Accordion title="get">
|
<Accordion title="get">
|
||||||
Used to fetch all folders within a path in a given project
|
Used to fetch all folders within a path in a given project
|
||||||
```
|
```
|
||||||
@@ -179,6 +209,7 @@ $ infisical secrets set STRIPE_API_KEY=sjdgwkeudyjwe DOMAIN=example.com HASH=jeb
|
|||||||
|
|
||||||
Default value: ``
|
Default value: ``
|
||||||
</Accordion>
|
</Accordion>
|
||||||
|
|
||||||
</Accordion>
|
</Accordion>
|
||||||
|
|
||||||
<Accordion title="delete">
|
<Accordion title="delete">
|
||||||
@@ -198,6 +229,7 @@ $ infisical secrets set STRIPE_API_KEY=sjdgwkeudyjwe DOMAIN=example.com HASH=jeb
|
|||||||
|
|
||||||
Default value: ``
|
Default value: ``
|
||||||
</Accordion>
|
</Accordion>
|
||||||
|
|
||||||
</Accordion>
|
</Accordion>
|
||||||
</Accordion>
|
</Accordion>
|
||||||
|
|
||||||
@@ -214,10 +246,12 @@ $ infisical secrets generate-example-env
|
|||||||
$ infisical secrets generate-example-env > .example-env
|
$ infisical secrets generate-example-env > .example-env
|
||||||
```
|
```
|
||||||
|
|
||||||
### Flags
|
### Flags
|
||||||
|
|
||||||
<Accordion title="--env">
|
<Accordion title="--env">
|
||||||
Used to select the environment name on which actions should be taken on
|
Used to select the environment name on which actions should be taken on
|
||||||
|
|
||||||
Default value: `dev`
|
Default value: `dev`
|
||||||
|
|
||||||
</Accordion>
|
</Accordion>
|
||||||
</Accordion>
|
</Accordion>
|
||||||
|
|||||||
Reference in New Issue
Block a user