From cea1a5e7ea642e739da4da0a26a053e2358c7ee0 Mon Sep 17 00:00:00 2001 From: Maidul Islam Date: Tue, 30 Jul 2024 20:01:52 -0400 Subject: [PATCH] add docs for single and list secrets functions for agent --- cli/packages/cmd/agent.go | 3 +- .../platforms/infisical-agent.mdx | 43 ++++++++++++++++--- 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/cli/packages/cmd/agent.go b/cli/packages/cmd/agent.go index 537131bc2..59e496ec7 100644 --- a/cli/packages/cmd/agent.go +++ b/cli/packages/cmd/agent.go @@ -375,7 +375,8 @@ func ProcessTemplate(templateId int, templatePath string, data interface{}, acce dynamicSecretFunction := dynamicSecretTemplateFunction(accessToken, dynamicSecretManager, templateId) getSingleSecretFunction := getSingleSecretTemplateFunction(accessToken, existingEtag, currentEtag) funcs := template.FuncMap{ - "secret": secretFunction, + "secret": secretFunction, // depreciated + "listSecrets": secretFunction, "dynamic_secret": dynamicSecretFunction, "getSecretByName": getSingleSecretFunction, "minus": func(a, b int) int { diff --git a/docs/integrations/platforms/infisical-agent.mdx b/docs/integrations/platforms/infisical-agent.mdx index b397b7352..bb1261208 100644 --- a/docs/integrations/platforms/infisical-agent.mdx +++ b/docs/integrations/platforms/infisical-agent.mdx @@ -252,7 +252,7 @@ To install the Infisical agent, you must first install the [Infisical CLI](../cl Once you have the CLI installed, you will need to provision programmatic access for the agent via [Universal Auth](/documentation/platform/identities/universal-auth). To obtain a **Client ID** and a **Client Secret**, follow the step by step guide outlined [here](/documentation/platform/identities/universal-auth). -Next, create agent config file as shown below. +Next, create agent config file as shown below. The example agent configuration file that defines the token authentication method, one sink location, and a secret template. ```yaml example-agent-config-file.yaml infisical: @@ -277,8 +277,8 @@ templates: command: ./reload-app.sh ``` -Above is an example agent configuration file that defines the token authentication method, one sink location (where to deposit access tokens after renewal) and a secret template. - +The secret template below will be used to render the secrets with the key and the value separated by `=` sign. You'll notice that a custom function named `secret` is used to fetch the secrets. +This function takes the following arguments: `secret "" "" ""`. ```text my-dot-ev-secret-template {{- with secret "6553ccb2b7da580d7f6e7260" "dev" "/" }} @@ -288,11 +288,42 @@ Above is an example agent configuration file that defines the token authenticati {{- end }} ``` -The secret template above will be used to render the secrets where the key and the value are separated by `=` sign. You'll notice that a custom function named `secret` is used to fetch the secrets. -This function takes the following arguments: `secret "" "" ""`. +After defining the agent configuration file, run the command below pointing to the path where the agent configuration file is located. + ```bash infisical agent --config example-agent-config-file.yaml ``` -After defining the agent configuration file, run the command above pointing to the path where the agent configuration is located. + +### Available secret template functions + + ```bash + listSecrets "" "environment-slug" "" + ``` + ```bash example-template-usage + {{- with listSecrets "6553ccb2b7da580d7f6e7260" "dev" "/" }} + {{- range . }} + {{ .Key }}={{ .Value }} + {{- end }} + {{- end }} + ``` + This function can be used to render the full list of secrets within a given project, environment and secret path. + + + + + ```bash + getSecretByName "" "" "" "" + ``` + + ```bash example-template-usage + {{ with getSecretByName "d821f21d-aa90-453b-8448-8c78c1160a0e" "dev" "/" "POSTHOG_HOST"}} + {{ if .Value }} + password = "{{ .Value }}" + {{ end }} + {{ end }} + ``` + + This function can be used to render a single secret by it's name. +