refact(target): Change repository to take CredentialLibraries

This change removes the hard-coded credential purpose for the Credential
Libraries. It also moves the logic of creating CredentialLibraries from
CredentialSources out of the repository and into the targets.Service.
This refactor will allow for additional credential purposes to be
supported in both the service and the repository.
This commit is contained in:
Timothy Messier committed 2021-10-29 10:01:52 -04:00
1 parent 8ae6e9892f
commit 2cc58ff901
20 files changed
+1213 -133

No files matched your search

+18 -4
View File
@@ -4,19 +4,33 @@ import (
"context"
"testing"
"github.com/hashicorp/boundary/internal/credential"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/target/store"
"github.com/stretchr/testify/require"
)
// TestNewCredentialLibrary creates a new in memory CredentialLibrary
// representing the relationship between targetId and credentialLibraryId with
// the given purpose.
func TestNewCredentialLibrary(targetId, credentialLibraryId string, purpose credential.Purpose) *CredentialLibrary {
return &CredentialLibrary{
CredentialLibrary: &store.CredentialLibrary{
TargetId: targetId,
CredentialLibraryId: credentialLibraryId,
CredentialPurpose: string(purpose),
},
}
}
// TestCredentialLibrary creates a CredentialLibrary for targetId and
// libraryId.
// libraryId with the credential purpose of application.
func TestCredentialLibrary(t *testing.T, conn *db.DB, targetId, libraryId string) *CredentialLibrary {
t.Helper()
require := require.New(t)
rw := db.New(conn)
lib, err := NewCredentialLibrary(targetId, libraryId)
require.NoError(err)
err = rw.Create(context.Background(), lib)
lib := TestNewCredentialLibrary(targetId, libraryId, credential.ApplicationPurpose)
err := rw.Create(context.Background(), lib)
require.NoError(err)
return lib
}