Skip to content

Commit

Permalink
fix: use new CmdEnv
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Oct 18, 2023
1 parent a40b7ca commit 483bc3f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
15 changes: 14 additions & 1 deletion models/connections.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,17 @@ func (c Connection) AsEnv(ctx context.Context) EnvPrep {

if v, ok := c.Properties["region"]; ok {
envPrep.Env = append(envPrep.Env, fmt.Sprintf("AWS_DEFAULT_REGION=%s", v))

credentialFile.WriteString(fmt.Sprintf("region = %s\n", v))

envPrep.CmdEnvs = append(envPrep.CmdEnvs, fmt.Sprintf("AWS_DEFAULT_REGION=%s", v))
}

envPrep.Files[credentialFilePath] = credentialFile

envPrep.CmdEnvs = append(envPrep.CmdEnvs, "AWS_EC2_METADATA_DISABLED=true") // https://github.com/aws/aws-cli/issues/5262#issuecomment-705832151
envPrep.CmdEnvs = append(envPrep.CmdEnvs, fmt.Sprintf("AWS_SHARED_CREDENTIALS_FILE=%s", credentialFilePath))

case ConnectionTypeAzure:
args := []string{"login", "--service-principal", "--username", c.Username, "--password", c.Password}
if v, ok := c.Properties["tenant"]; ok {
Expand All @@ -214,6 +220,8 @@ func (c Connection) AsEnv(ctx context.Context) EnvPrep {
// we need to explicitly activate it
envPrep.PreRuns = append(envPrep.PreRuns, exec.CommandContext(ctx, "gcloud", "auth", "activate-service-account", "--key-file", credentialFilePath))
envPrep.Files[credentialFilePath] = credentialFile

envPrep.CmdEnvs = append(envPrep.CmdEnvs, fmt.Sprintf("GOOGLE_APPLICATION_CREDENTIALS=%s", credentialFilePath))
}

return envPrep
Expand All @@ -223,6 +231,11 @@ type EnvPrep struct {
// Env is the connection credentials in environment variables
Env []string

// CmdEnvs is a list of env vars that will be passed to the command
CmdEnvs []string

// List of commands that need to be run before the actual command.
// These commands will setup the connection.
PreRuns []*exec.Cmd

// File contains the content of the configuration file based on the connection
Expand All @@ -237,7 +250,7 @@ func (c *EnvPrep) Inject(ctx context.Context, cmd *exec.Cmd) ([]*exec.Cmd, error
}
}

cmd.Env = append(cmd.Env, c.Env...)
cmd.Env = append(cmd.Env, c.CmdEnvs...)

return c.PreRuns, nil
}
Expand Down
2 changes: 1 addition & 1 deletion models/connections_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func Test_Connection_AsGoGetterURL(t *testing.T) {
Certificate: "cert123",
Properties: map[string]string{"ref": "main"},
},
expectedURL: "https://github.com/repo.git?ref=main&sshkey=cert123",
expectedURL: "https://github.com/repo.git?ref=main&sshkey=Y2VydDEyMw%3D%3D",
expectedError: nil,
},
}
Expand Down

0 comments on commit 483bc3f

Please sign in to comment.