mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-06 11:27:07 +00:00
feat(cli): added template feature to cli export command
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
|||||||
"encoding/csv"
|
"encoding/csv"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/Infisical/infisical-merge/packages/models"
|
"github.com/Infisical/infisical-merge/packages/models"
|
||||||
@@ -59,6 +60,11 @@ var exportCmd = &cobra.Command{
|
|||||||
util.HandleError(err)
|
util.HandleError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
templatePath, err := cmd.Flags().GetString("template")
|
||||||
|
if err != nil {
|
||||||
|
util.HandleError(err)
|
||||||
|
}
|
||||||
|
|
||||||
secretOverriding, err := cmd.Flags().GetBool("secret-overriding")
|
secretOverriding, err := cmd.Flags().GetBool("secret-overriding")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
util.HandleError(err, "Unable to parse flag")
|
util.HandleError(err, "Unable to parse flag")
|
||||||
@@ -93,6 +99,31 @@ var exportCmd = &cobra.Command{
|
|||||||
request.UniversalAuthAccessToken = token.Token
|
request.UniversalAuthAccessToken = token.Token
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if templatePath != "" {
|
||||||
|
sigChan := make(chan os.Signal, 1)
|
||||||
|
dynamicSecretLeases := NewDynamicSecretLeaseManager(sigChan)
|
||||||
|
newEtag := ""
|
||||||
|
|
||||||
|
accessToken := ""
|
||||||
|
if token != nil {
|
||||||
|
accessToken = token.Token
|
||||||
|
} else {
|
||||||
|
log.Debug().Msg("GetAllEnvironmentVariables: Trying to fetch secrets using logged in details")
|
||||||
|
loggedInUserDetails, err := util.GetCurrentLoggedInUserDetails()
|
||||||
|
if err != nil {
|
||||||
|
util.HandleError(err)
|
||||||
|
}
|
||||||
|
accessToken = loggedInUserDetails.UserCredentials.JTWToken
|
||||||
|
}
|
||||||
|
|
||||||
|
processedTemplate, err := ProcessTemplate(1, templatePath, nil, accessToken, "", &newEtag, dynamicSecretLeases)
|
||||||
|
if err != nil {
|
||||||
|
util.HandleError(err)
|
||||||
|
}
|
||||||
|
fmt.Print(processedTemplate.String())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
secrets, err := util.GetAllEnvironmentVariables(request, "")
|
secrets, err := util.GetAllEnvironmentVariables(request, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
util.HandleError(err, "Unable to fetch secrets")
|
util.HandleError(err, "Unable to fetch secrets")
|
||||||
@@ -140,6 +171,7 @@ func init() {
|
|||||||
exportCmd.Flags().StringP("tags", "t", "", "filter secrets by tag slugs")
|
exportCmd.Flags().StringP("tags", "t", "", "filter secrets by tag slugs")
|
||||||
exportCmd.Flags().String("projectId", "", "manually set the projectId to fetch secrets from")
|
exportCmd.Flags().String("projectId", "", "manually set the projectId to fetch secrets from")
|
||||||
exportCmd.Flags().String("path", "/", "get secrets within a folder path")
|
exportCmd.Flags().String("path", "/", "get secrets within a folder path")
|
||||||
|
exportCmd.Flags().String("template", "", "The path to the template file to output secrets")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Format according to the format flag
|
// Format according to the format flag
|
||||||
|
|||||||
@@ -33,6 +33,9 @@ Export environment variables from the platform into a file format.
|
|||||||
|
|
||||||
# Export variables to a YAML file
|
# Export variables to a YAML file
|
||||||
infisical export --format=yaml > secrets.yaml
|
infisical export --format=yaml > secrets.yaml
|
||||||
|
|
||||||
|
# Export variables from a template
|
||||||
|
infisical export --template=<path to template>
|
||||||
```
|
```
|
||||||
|
|
||||||
### Environment variables
|
### Environment variables
|
||||||
@@ -57,6 +60,22 @@ Export environment variables from the platform into a file format.
|
|||||||
</Accordion>
|
</Accordion>
|
||||||
|
|
||||||
### flags
|
### flags
|
||||||
|
<Accordion title="--template">
|
||||||
|
The --template flag specifies the path to the template file used for rendering secrets. In template mode, you can omit the other flags since the settings are already configured within the template.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Example
|
||||||
|
infisical export --template="/path/to/template"
|
||||||
|
```
|
||||||
|
|
||||||
|
```text my-dot-env-secret-template
|
||||||
|
{{- with secret "<projectId>" "<environment slug>" "/" }}
|
||||||
|
{{- range . }}
|
||||||
|
{{ .Key }}={{ .Value }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
|
```
|
||||||
|
</Accordion>
|
||||||
<Accordion title="--env">
|
<Accordion title="--env">
|
||||||
Used to set the environment that secrets are pulled from.
|
Used to set the environment that secrets are pulled from.
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user