Skip to content

Commit

Permalink
export-credentials: fix exec not support read data from stdin
Browse files Browse the repository at this point in the history
  • Loading branch information
mozillazg committed Nov 27, 2024
1 parent 1cf4b03 commit 4b538fd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/ctl/exportcredentials/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var cmd = &cobra.Command{
ctlcommon.ExitIfError(err)

if opt.format == formatEnvironmentVariables && len(args) > 0 {
err = runUserCommands(context.Background(), *cred, args, nil, nil)
err = runUserCommands(context.Background(), *cred, args, nil, nil, nil)
ctlcommon.ExitIfError(err)
return
}
Expand Down
7 changes: 6 additions & 1 deletion pkg/ctl/exportcredentials/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@ var (
}
)

func runUserCommands(ctx context.Context, cred Credentials, args []string, stdout io.Writer, stderr io.Writer) error {
func runUserCommands(ctx context.Context, cred Credentials, args []string,
stdin io.Reader, stdout io.Writer, stderr io.Writer) error {
cmd := exec.CommandContext(ctx, args[0], args[1:]...) // #nosec G204
if stdin == nil {
stdin = os.Stdin
}
if stdout == nil {
stdout = os.Stdout
}
Expand All @@ -42,6 +46,7 @@ func runUserCommands(ctx context.Context, cred Credentials, args []string, stdou
envs := getCredentialsEnvsWithCurrentEnvs(cred)
envs = append(envs, "ALIBABACLOUD_IGNORE_PROFILE=TRUE")
cmd.Env = envs
cmd.Stdin = stdin
cmd.Stdout = stdout
cmd.Stderr = stderr

Expand Down

0 comments on commit 4b538fd

Please sign in to comment.