Skip to content

Commit 71b4c10

Browse files
committed
feat: ssh credentials
1 parent 6147d8a commit 71b4c10

File tree

2 files changed

+8
-14
lines changed

2 files changed

+8
-14
lines changed

internal/flux_deployer/deployer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func TestDeployFluxController(t *testing.T) {
2424
namespace := "flux-system-test"
2525

2626
d := flux_deployer.NewFluxDeployer("", "", "",
27-
"", ocmcli.NoOcmConfig, "", namespace, "", platformCluster, logging.GetLogger())
27+
"", "", ocmcli.NoOcmConfig, "", namespace, "", platformCluster, logging.GetLogger())
2828

2929
// Create a deployment
3030
err := d.DeployFluxControllers(t.Context(), rootComponentVersion1, downloadDir)

internal/flux_deployer/git_credentials.go

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
2828
func 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

Comments
 (0)