Skip to content

Commit

Permalink
Merge pull request #47 from buildkite/keithduncan/fix-credential-path…
Browse files Browse the repository at this point in the history
…-windows

Fix credential.helper path when it includes spaces
  • Loading branch information
keithduncan authored Aug 31, 2021
2 parents d498373 + 9d82456 commit e844384
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions s3secrets-helper/secrets/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,15 +205,31 @@ func handleGitCredentials(conf Config, results <-chan getResult) error {
continue
}
log.Printf("Adding git-credentials in %s/%s as a credential helper", r.bucket, r.key)
helpers = append(helpers, fmt.Sprintf(
"'credential.helper=%s %s %s'",
conf.GitCredentialHelper, r.bucket, r.key,
))

// Replace spaces ' ' in the helper path with an escaped space '\ '
escapedCredentialHelper := strings.ReplaceAll(conf.GitCredentialHelper, " ", "\\ ")

helper := fmt.Sprintf("credential.helper=%s %s %s", escapedCredentialHelper, r.bucket, r.key)

helpers = append(helpers, helper)
}
if len(helpers) == 0 {
return nil
}
env := "GIT_CONFIG_PARAMETERS=\"" + strings.Join(helpers, " ") + "\"\n"

// Build an environment variable for interpretation by a shell
var singleQuotedHelpers []string
for _, helper := range helpers {
// Escape any escape sequences, the shell will interpret the first level
// of escaping.

// Replace backslash '\' with double backslash '\\'
helper = strings.ReplaceAll(helper, "\\", "\\\\")

singleQuotedHelpers = append(singleQuotedHelpers, "'" + helper + "'")
}
env := "GIT_CONFIG_PARAMETERS=\"" + strings.Join(singleQuotedHelpers, " ") + "\"\n"

if _, err := io.WriteString(conf.EnvSink, env); err != nil {
return fmt.Errorf("writing GIT_CONFIG_PARAMETERS env: %w", err)
}
Expand Down

0 comments on commit e844384

Please sign in to comment.