mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-02 22:25:44 +00:00
add go lang add/minus functions and give better example
This commit is contained in:
@@ -381,6 +381,12 @@ func ProcessTemplate(templateId int, templatePath string, data interface{}, acce
|
|||||||
funcs := template.FuncMap{
|
funcs := template.FuncMap{
|
||||||
"secret": secretFunction,
|
"secret": secretFunction,
|
||||||
"dynamic_secret": dynamicSecretFunction,
|
"dynamic_secret": dynamicSecretFunction,
|
||||||
|
"minus": func(a, b int) int {
|
||||||
|
return a - b
|
||||||
|
},
|
||||||
|
"add": func(a, b int) int {
|
||||||
|
return a + b
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
templateName := path.Base(templatePath)
|
templateName := path.Base(templatePath)
|
||||||
|
|||||||
@@ -171,7 +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")
|
exportCmd.Flags().String("template", "", "The path to the template file used to render secrets")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Format according to the format flag
|
// Format according to the format flag
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ 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
|
# Render secrets using a custom template file
|
||||||
infisical export --template=<path to template>
|
infisical export --template=<path to template>
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -61,20 +61,24 @@ Export environment variables from the platform into a file format.
|
|||||||
|
|
||||||
### flags
|
### flags
|
||||||
<Accordion title="--template">
|
<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.
|
The `--template` flag specifies the path to the template file used for rendering secrets. When using templates, you can omit the other format flags.
|
||||||
|
|
||||||
|
```text my-template-file
|
||||||
|
{{$secrets := secret "<infisical-project-id>" "<environment-slug>" "<folder-path>"}}
|
||||||
|
{{$length := len $secrets}}
|
||||||
|
{{- "{"}}
|
||||||
|
{{- with $secrets }}
|
||||||
|
{{- range $index, $secret := . }}
|
||||||
|
"{{ $secret.Key }}": "{{ $secret.Value }}"{{if lt $index (minus $length 1)}},{{end}}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
|
{{ "}" -}}
|
||||||
|
```
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Example
|
# Example
|
||||||
infisical export --template="/path/to/template"
|
infisical export --template="/path/to/template/file"
|
||||||
```
|
```
|
||||||
|
|
||||||
```text my-dot-env-secret-template
|
|
||||||
{{- with secret "<projectId>" "<environment slug>" "/" }}
|
|
||||||
{{- range . }}
|
|
||||||
{{ .Key }}={{ .Value }}
|
|
||||||
{{- end }}
|
|
||||||
{{- end }}
|
|
||||||
```
|
|
||||||
</Accordion>
|
</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