mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-06 18:27:19 +00:00
feat: added secret path to template and optional more arguments as json get secrets
This commit is contained in:
@@ -587,6 +587,7 @@ type GetRawSecretsV3Response struct {
|
|||||||
SecretKey string `json:"secretKey"`
|
SecretKey string `json:"secretKey"`
|
||||||
SecretValue string `json:"secretValue"`
|
SecretValue string `json:"secretValue"`
|
||||||
SecretComment string `json:"secretComment"`
|
SecretComment string `json:"secretComment"`
|
||||||
|
SecretPath string `json:"secretPath"`
|
||||||
} `json:"secrets"`
|
} `json:"secrets"`
|
||||||
Imports []ImportedRawSecretV3 `json:"imports"`
|
Imports []ImportedRawSecretV3 `json:"imports"`
|
||||||
ETag string
|
ETag string
|
||||||
@@ -610,6 +611,7 @@ type GetRawSecretV3ByNameResponse struct {
|
|||||||
SecretKey string `json:"secretKey"`
|
SecretKey string `json:"secretKey"`
|
||||||
SecretValue string `json:"secretValue"`
|
SecretValue string `json:"secretValue"`
|
||||||
SecretComment string `json:"secretComment"`
|
SecretComment string `json:"secretComment"`
|
||||||
|
SecretPath string `json:"secretPath"`
|
||||||
} `json:"secret"`
|
} `json:"secret"`
|
||||||
ETag string
|
ETag string
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
@@ -311,9 +312,22 @@ func ParseAgentConfig(configFile []byte) (*Config, error) {
|
|||||||
return config, nil
|
return config, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func secretTemplateFunction(accessToken string, existingEtag string, currentEtag *string) func(string, string, string) ([]models.SingleEnvironmentVariable, error) {
|
type secretArguments struct {
|
||||||
return func(projectID, envSlug, secretPath string) ([]models.SingleEnvironmentVariable, error) {
|
IsRecursive bool `json:"recursive"`
|
||||||
res, err := util.GetPlainTextSecretsV3(accessToken, projectID, envSlug, secretPath, false, false, "")
|
}
|
||||||
|
|
||||||
|
func secretTemplateFunction(accessToken string, existingEtag string, currentEtag *string) func(string, string, string, ...string) ([]models.SingleEnvironmentVariable, error) {
|
||||||
|
return func(projectID, envSlug, secretPath string, args ...string) ([]models.SingleEnvironmentVariable, error) {
|
||||||
|
var parsedArguments secretArguments
|
||||||
|
// to make it optional
|
||||||
|
if len(args) > 0 {
|
||||||
|
err := json.Unmarshal([]byte(args[0]), &parsedArguments)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := util.GetPlainTextSecretsV3(accessToken, projectID, envSlug, secretPath, false, parsedArguments.IsRecursive, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -456,7 +470,6 @@ func ProcessLiteralTemplate(templateId int, templateString string, data interfac
|
|||||||
return &buf, nil
|
return &buf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
type AgentManager struct {
|
type AgentManager struct {
|
||||||
accessToken string
|
accessToken string
|
||||||
accessTokenTTL time.Duration
|
accessTokenTTL time.Duration
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ type SingleEnvironmentVariable struct {
|
|||||||
Value string `json:"value"`
|
Value string `json:"value"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
ID string `json:"_id"`
|
ID string `json:"_id"`
|
||||||
|
SecretPath string `json:"secretPath"`
|
||||||
Tags []struct {
|
Tags []struct {
|
||||||
ID string `json:"_id"`
|
ID string `json:"_id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ func GetPlainTextSecretsV3(accessToken string, workspaceId string, environmentNa
|
|||||||
plainTextSecrets := []models.SingleEnvironmentVariable{}
|
plainTextSecrets := []models.SingleEnvironmentVariable{}
|
||||||
|
|
||||||
for _, secret := range rawSecrets.Secrets {
|
for _, secret := range rawSecrets.Secrets {
|
||||||
plainTextSecrets = append(plainTextSecrets, models.SingleEnvironmentVariable{Key: secret.SecretKey, Value: secret.SecretValue, Type: secret.Type, WorkspaceId: secret.Workspace})
|
plainTextSecrets = append(plainTextSecrets, models.SingleEnvironmentVariable{Key: secret.SecretKey, Value: secret.SecretValue, Type: secret.Type, WorkspaceId: secret.Workspace, SecretPath: secret.SecretPath})
|
||||||
}
|
}
|
||||||
|
|
||||||
if includeImports {
|
if includeImports {
|
||||||
@@ -145,6 +145,7 @@ func GetSinglePlainTextSecretByNameV3(accessToken string, workspaceId string, en
|
|||||||
Type: rawSecret.Secret.Type,
|
Type: rawSecret.Secret.Type,
|
||||||
ID: rawSecret.Secret.ID,
|
ID: rawSecret.Secret.ID,
|
||||||
Comment: rawSecret.Secret.SecretComment,
|
Comment: rawSecret.Secret.SecretComment,
|
||||||
|
SecretPath: rawSecret.Secret.SecretPath,
|
||||||
}
|
}
|
||||||
|
|
||||||
return formattedSecrets, rawSecret.ETag, nil
|
return formattedSecrets, rawSecret.ETag, nil
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{{- with secret "6553ccb2b7da580d7f6e7260" "dev" "/" }}
|
{{- with secret "ae06a663-2740-49c5-b998-bf4ceca2c120" "dev" "/" `{"recursive":true}` }}
|
||||||
{{- range . }}
|
{{- range . }}
|
||||||
{{ .Key }}={{ .Value }}
|
{{ .Key }}={{ .Value }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
|||||||
Reference in New Issue
Block a user