Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add Support for Prefixing Secrets during Injection #2849

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions cli/packages/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ var runCmd = &cobra.Command{
util.HandleError(err, "Unable to parse flag")
}

prefix, err := cmd.Flags().GetString("prefix")
if err != nil {
util.HandleError(err, "Unable to parse prefix flag")
}

request := models.GetAllSecretsParameters{
Environment: environmentName,
WorkspaceId: projectId,
Expand All @@ -151,6 +156,17 @@ var runCmd = &cobra.Command{
util.HandleError(err, "Could not fetch secrets", "If you are using a service token to fetch secrets, please ensure it is valid")
}

if prefix != "" {
for _, variable := range injectableEnvironment.Variables {
parts := strings.SplitN(variable, "=", 2)
if len(parts) == 2 {
prefixedKey := prefix + parts[0]
prefixedVariable := prefixedKey + "=" + parts[1]
injectableEnvironment.Variables = append(injectableEnvironment.Variables, prefixedVariable)
}
}
}

log.Debug().Msgf("injecting the following environment variables into shell: %v", injectableEnvironment.Variables)

if watchMode {
Expand Down Expand Up @@ -222,6 +238,7 @@ func init() {
runCmd.Flags().StringP("tags", "t", "", "filter secrets by tag slugs ")
runCmd.Flags().String("path", "/", "get secrets within a folder path")
runCmd.Flags().String("project-config-dir", "", "explicitly set the directory where the .infisical.json resides")
runCmd.Flags().String("prefix", "", "add a prefix to all injected environment variable names")
}

// Will execute a single command and pass in the given secrets into the process
Expand Down