Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions util/db/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,15 @@ func TestRepositorySecretsTrim(t *testing.T) {
sshPrivateKeySecret:
name: managed-secret
key: sshPrivateKey
tlsClientCertDataSecret:
name: managed-secret
key: tlsClientCertData
tlsClientCertKeySecret:
name: managed-secret
key: tlsClientCertKey
githubAppPrivateKeySecret:
name: managed-secret
key: githubAppPrivateKey
`}
clientset := getClientset(config, &v1.Secret{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -391,9 +400,12 @@ func TestRepositorySecretsTrim(t *testing.T) {
},
},
Data: map[string][]byte{
username: []byte("test-username\n\n"),
password: []byte("test-password\r\r"),
sshPrivateKey: []byte("test-ssh-private-key\n\r"),
username: []byte("test-username\n\n"),
password: []byte("test-password\r\r"),
sshPrivateKey: []byte("test-ssh-private-key\n\r"),
tlsClientCertData: []byte("test-tls-client-cert-data\n\r"),
tlsClientCertKey: []byte("test-tls-client-cert-key\n\r"),
githubAppPrivateKey: []byte("test-github-app-private-key\n\r"),
},
})
db := NewDB(testNamespace, settings.NewSettingsManager(context.Background(), clientset, testNamespace), clientset)
Expand All @@ -416,6 +428,18 @@ func TestRepositorySecretsTrim(t *testing.T) {
"test-ssh-private-key",
repo.SSHPrivateKey,
},
{
"test-tls-client-cert-data",
repo.TLSClientCertData,
},
{
"test-tls-client-cert-key",
repo.TLSClientCertKey,
},
{
"test-github-app-private-key",
repo.GithubAppPrivateKey,
},
}
for _, tt := range teststruct {
assert.Equal(t, tt.expectedSecret, tt.retrievedSecret)
Expand Down
11 changes: 6 additions & 5 deletions util/db/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,12 @@ func (db *db) credentialsToRepositoryCredentials(repoInfo settings.RepositoryCre
EnableOCI: repoInfo.EnableOCI,
}
err := db.unmarshalFromSecretsStr(map[*SecretMaperValidation]*apiv1.SecretKeySelector{
&SecretMaperValidation{Dest: &creds.Username}: repoInfo.UsernameSecret,
&SecretMaperValidation{Dest: &creds.Password}: repoInfo.PasswordSecret,
&SecretMaperValidation{Dest: &creds.SSHPrivateKey}: repoInfo.SSHPrivateKeySecret,
&SecretMaperValidation{Dest: &creds.TLSClientCertData}: repoInfo.TLSClientCertDataSecret,
&SecretMaperValidation{Dest: &creds.TLSClientCertKey}: repoInfo.TLSClientCertKeySecret,
&SecretMaperValidation{Dest: &creds.Username}: repoInfo.UsernameSecret,
&SecretMaperValidation{Dest: &creds.Password}: repoInfo.PasswordSecret,
&SecretMaperValidation{Dest: &creds.SSHPrivateKey}: repoInfo.SSHPrivateKeySecret,
&SecretMaperValidation{Dest: &creds.TLSClientCertData}: repoInfo.TLSClientCertDataSecret,
&SecretMaperValidation{Dest: &creds.TLSClientCertKey}: repoInfo.TLSClientCertKeySecret,
&SecretMaperValidation{Dest: &creds.GithubAppPrivateKey}: repoInfo.GithubAppPrivateKeySecret,
}, make(map[string]*apiv1.Secret))
return creds, err
}
Expand Down