@@ -26,13 +26,7 @@ const (
2626// The file should contain a YAML of a map[string]string, whose keys are described
2727// in https://fluxcd.io/flux/components/source/gitrepositories/#secret-reference, e.g. username and password.
2828func CreateGitCredentialsSecret (ctx context.Context , gitCredentials string , secretName , secretNamespace string , platformClient client.Client ) error {
29- gitCredentialsData := map [string ]string {
30- username : "" ,
31- password : "" ,
32- token : "" ,
33- identity : "" ,
34- knownHosts : "" ,
35- }
29+ gitCredentialsData := map [string ][]byte {}
3630
3731 if gitCredentials != "" {
3832 filepath := gitCredentials
@@ -46,19 +40,19 @@ func CreateGitCredentialsSecret(ctx context.Context, gitCredentials string, secr
4640 }
4741
4842 if config .Authentication .BasicAuth != nil {
49- gitCredentialsData [username ] = config .Authentication .BasicAuth .Username
50- gitCredentialsData [password ] = config .Authentication .BasicAuth .Password
43+ gitCredentialsData [username ] = [] byte ( config .Authentication .BasicAuth .Username )
44+ gitCredentialsData [password ] = [] byte ( config .Authentication .BasicAuth .Password )
5145 }
5246 if config .Authentication .BearerToken != nil {
53- gitCredentialsData [token ] = config .Authentication .BearerToken .Token
47+ gitCredentialsData [token ] = [] byte ( config .Authentication .BearerToken .Token )
5448 }
5549 if config .Authentication .SSHPrivateKey != nil {
5650 privateKey , err := base64 .StdEncoding .DecodeString (config .Authentication .SSHPrivateKey .PrivateKey )
5751 if err != nil {
5852 return fmt .Errorf ("error base64 decoding SSH private key: %w" , err )
5953 }
6054
61- gitCredentialsData [identity ] = string ( privateKey )
55+ gitCredentialsData [identity ] = privateKey
6256
6357 if config .Authentication .SSHPrivateKey .KnownHosts != "" {
6458 knownHostsPath := config .Authentication .SSHPrivateKey .KnownHosts
@@ -69,12 +63,12 @@ func CreateGitCredentialsSecret(ctx context.Context, gitCredentials string, secr
6963 if err != nil {
7064 return fmt .Errorf ("error reading known hosts file %s: %w" , knownHostsPath , err )
7165 }
72- gitCredentialsData [knownHosts ] = string ( knownHostsContent )
66+ gitCredentialsData [knownHosts ] = knownHostsContent
7367 }
7468 }
7569 }
7670
77- secretMutator := resources .NewSecretMutatorWithStringData (secretName , secretNamespace , gitCredentialsData , corev1 .SecretTypeOpaque )
71+ secretMutator := resources .NewSecretMutator (secretName , secretNamespace , gitCredentialsData , corev1 .SecretTypeOpaque )
7872 if err := resources .CreateOrUpdateResource (ctx , platformClient , secretMutator ); err != nil {
7973 return fmt .Errorf ("error creating or updating git credentials secret: %w" , err )
8074 }
0 commit comments