Merge pull request #582 from thockin/v4_log_creds_md5

v4: log.V(9) md5sums of credentials
This commit is contained in:
Kubernetes Prow Robot 2022-07-14 10:04:57 -07:00 committed by GitHub
commit 9b5b8143b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 0 deletions

View File

@ -20,6 +20,7 @@ package main // import "k8s.io/git-sync/cmd/git-sync"
import (
"context"
"crypto/md5"
"fmt"
"io"
"io/ioutil"
@ -1316,9 +1317,16 @@ func (git *repoSync) GetRevs(ctx context.Context) (string, string, error) {
return local, remote, nil
}
func md5sum(s string) string {
h := md5.New()
io.WriteString(h, s)
return fmt.Sprintf("%x", h.Sum(nil))
}
// StoreCredentials stores the username and password for later use.
func (git *repoSync) StoreCredentials(ctx context.Context, username, password string) error {
git.log.V(3).Info("storing git credentials")
git.log.V(9).Info("md5 of credentials", "username", md5sum(username), "password", md5sum(password))
creds := fmt.Sprintf("url=%v\nusername=%v\npassword=%v\n", git.repo, username, password)
_, err := git.run.RunWithStdin(ctx, "", nil, creds, git.cmd, "credential", "approve")