mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-10 21:29:20 +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")
|
||||
}
|
||||
|
||||
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}, "")
|
||||
if err != nil {
|
||||
util.HandleError(err, "To fetch all secrets")
|
||||
@@ -435,7 +440,15 @@ func getSecretsByNames(cmd *cobra.Command, args []string) {
|
||||
}
|
||||
}
|
||||
|
||||
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))
|
||||
}
|
||||
|
||||
@@ -669,6 +682,7 @@ func init() {
|
||||
secretsGetCmd.Flags().String("token", "", "Fetch secrets using the Infisical Token")
|
||||
secretsCmd.AddCommand(secretsGetCmd)
|
||||
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.AddCommand(secretsSetCmd)
|
||||
|
||||
@@ -8,6 +8,7 @@ infisical secrets
|
||||
```
|
||||
|
||||
## 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.
|
||||
|
||||
### Sub-commands
|
||||
@@ -19,6 +20,7 @@ This command enables you to perform CRUD (create, read, update, delete) operatio
|
||||
```
|
||||
|
||||
### Environment variables
|
||||
|
||||
<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.
|
||||
|
||||
@@ -26,6 +28,7 @@ This command enables you to perform CRUD (create, read, update, delete) operatio
|
||||
# Example
|
||||
export INFISICAL_TOKEN=st.63e03c4a97cb4a747186c71e.ed5b46a34c078a8f94e8228f4ab0ff97.4f7f38034811995997d72badf44b42ec
|
||||
```
|
||||
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="INFISICAL_DISABLE_UPDATE_CHECK">
|
||||
@@ -37,19 +40,23 @@ This command enables you to perform CRUD (create, read, update, delete) operatio
|
||||
# Example
|
||||
export INFISICAL_DISABLE_UPDATE_CHECK=true
|
||||
```
|
||||
|
||||
</Accordion>
|
||||
|
||||
### Flags
|
||||
|
||||
<Accordion title="--expand">
|
||||
Parse shell parameter expansions in your secrets
|
||||
|
||||
Default value: `true`
|
||||
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="--env">
|
||||
Used to select the environment name on which actions should be taken on
|
||||
|
||||
Default value: `dev`
|
||||
|
||||
</Accordion>
|
||||
<Accordion title="--path">
|
||||
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
|
||||
infisical secrets --path="/" --env=dev
|
||||
```
|
||||
|
||||
</Accordion>
|
||||
|
||||
</Accordion>
|
||||
@@ -74,10 +82,25 @@ This command enables you to perform CRUD (create, read, update, delete) operatio
|
||||
```
|
||||
|
||||
### Flags
|
||||
|
||||
<Accordion title="--env">
|
||||
Used to select the environment name on which actions should be taken on
|
||||
|
||||
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>
|
||||
|
||||
@@ -93,10 +116,12 @@ $ infisical secrets set STRIPE_API_KEY=sjdgwkeudyjwe DOMAIN=example.com HASH=jeb
|
||||
```
|
||||
|
||||
### Flags
|
||||
|
||||
<Accordion title="--env">
|
||||
Used to select the environment name on which actions should be taken on
|
||||
|
||||
Default value: `dev`
|
||||
|
||||
</Accordion>
|
||||
<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.
|
||||
@@ -105,6 +130,7 @@ $ infisical secrets set STRIPE_API_KEY=sjdgwkeudyjwe DOMAIN=example.com HASH=jeb
|
||||
# Example
|
||||
infisical secrets set DOMAIN=example.com --path="common/backend"
|
||||
```
|
||||
|
||||
</Accordion>
|
||||
</Accordion>
|
||||
|
||||
@@ -119,10 +145,12 @@ $ infisical secrets set STRIPE_API_KEY=sjdgwkeudyjwe DOMAIN=example.com HASH=jeb
|
||||
```
|
||||
|
||||
### Flags
|
||||
|
||||
<Accordion title="--env">
|
||||
Used to select the environment name on which actions should be taken on
|
||||
|
||||
Default value: `dev`
|
||||
|
||||
</Accordion>
|
||||
<Accordion title="--path">
|
||||
The `--path` flag indicates which project folder secrets will be injected from.
|
||||
@@ -131,6 +159,7 @@ $ infisical secrets set STRIPE_API_KEY=sjdgwkeudyjwe DOMAIN=example.com HASH=jeb
|
||||
# Example
|
||||
infisical secrets delete <keyName1> <keyName2>... --path="/"
|
||||
```
|
||||
|
||||
</Accordion>
|
||||
</Accordion>
|
||||
|
||||
@@ -142,6 +171,7 @@ $ infisical secrets set STRIPE_API_KEY=sjdgwkeudyjwe DOMAIN=example.com HASH=jeb
|
||||
```
|
||||
|
||||
### sub commands
|
||||
|
||||
<Accordion title="get">
|
||||
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: ``
|
||||
</Accordion>
|
||||
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="delete">
|
||||
@@ -198,6 +229,7 @@ $ infisical secrets set STRIPE_API_KEY=sjdgwkeudyjwe DOMAIN=example.com HASH=jeb
|
||||
|
||||
Default value: ``
|
||||
</Accordion>
|
||||
|
||||
</Accordion>
|
||||
</Accordion>
|
||||
|
||||
@@ -215,9 +247,11 @@ $ infisical secrets generate-example-env > .example-env
|
||||
```
|
||||
|
||||
### Flags
|
||||
|
||||
<Accordion title="--env">
|
||||
Used to select the environment name on which actions should be taken on
|
||||
|
||||
Default value: `dev`
|
||||
|
||||
</Accordion>
|
||||
</Accordion>
|
||||
|
||||
Reference in New Issue
Block a user