Refactor Target Repository (#3092)

- Refactor the Target domain repository functions so that they no longer return 4 different types.

`Target` struct now contains `HostSource` & `CredentialSources` with Getters & Setters

- Extending `Target` to contain `HostSource` & `CredentialSources` enables `funcs` to just return `Target` instead of multiple return types.
This also allows easy future refactors and extensions of `Target`
This commit is contained in:
Elim Tsiagbey authored and GitHub committed 2023-03-30 15:19:30 -04:00
1 parent 743bbf88ac
commit 16f48686a7
20 files changed
+335 -173

No files matched your search

+3 -3
View File
@@ -999,7 +999,7 @@ func TestRepository_CancelSession(t *testing.T) {
targetRepo, err := target.NewRepository(ctx, rw, rw, testKms)
require.NoError(t, err)
_, _, _, err = targetRepo.AddTargetHostSources(ctx, tcpTarget.GetPublicId(), tcpTarget.GetVersion(), []string{sets[0].PublicId})
_, err = targetRepo.AddTargetHostSources(ctx, tcpTarget.GetPublicId(), tcpTarget.GetVersion(), []string{sets[0].PublicId})
require.NoError(t, err)
authMethod := password.TestAuthMethods(t, conn, org.PublicId, 1)[0]
@@ -1527,7 +1527,7 @@ func testSessionCredentialParams(t *testing.T, conn *db.DB, wrapper wrapping.Wra
kms := kms.TestKms(t, conn, wrapper)
targetRepo, err := target.NewRepository(ctx, rw, rw, kms)
require.NoError(err)
tar, _, _, err := targetRepo.LookupTarget(ctx, params.TargetId)
tar, err := targetRepo.LookupTarget(ctx, params.TargetId)
require.NoError(err)
require.NotNil(tar)
@@ -1540,7 +1540,7 @@ func testSessionCredentialParams(t *testing.T, conn *db.DB, wrapper wrapping.Wra
ids := target.CredentialSources{
BrokeredCredentialIds: []string{libIds[0].GetPublicId(), libIds[1].GetPublicId(), upCreds[0].GetPublicId(), upCreds[1].GetPublicId()},
}
_, _, _, err = targetRepo.AddTargetCredentialSources(ctx, tar.GetPublicId(), tar.GetVersion(), ids)
_, err = targetRepo.AddTargetCredentialSources(ctx, tar.GetPublicId(), tar.GetVersion(), ids)
require.NoError(err)
dynamicCreds := []*DynamicCredential{
NewDynamicCredential(libIds[0].GetPublicId(), cred.BrokeredPurpose),
@@ -95,7 +95,7 @@ func TestService_AuthorizeConnection(t *testing.T) {
targetRepo, err := target.NewRepository(ctx, rw, rw, testKms)
require.NoError(t, err)
_, _, _, err = targetRepo.AddTargetHostSources(ctx, tcpTarget.GetPublicId(), tcpTarget.GetVersion(), []string{sets[0].PublicId})
_, err = targetRepo.AddTargetHostSources(ctx, tcpTarget.GetPublicId(), tcpTarget.GetVersion(), []string{sets[0].PublicId})
require.NoError(t, err)
authMethod := password.TestAuthMethods(t, conn, org.PublicId, 1)[0]
@@ -56,7 +56,7 @@ func TestServiceCloseConnections(t *testing.T) {
targetRepo, err := target.NewRepository(ctx, rw, rw, testKms)
require.NoError(t, err)
_, _, _, err = targetRepo.AddTargetHostSources(ctx, tcpTarget.GetPublicId(), tcpTarget.GetVersion(), []string{sets[0].PublicId})
_, err = targetRepo.AddTargetHostSources(ctx, tcpTarget.GetPublicId(), tcpTarget.GetVersion(), []string{sets[0].PublicId})
require.NoError(t, err)
authMethod := password.TestAuthMethods(t, conn, org.PublicId, 1)[0]
+1 -1
View File
@@ -222,7 +222,7 @@ func TestSessionParams(t testing.TB, conn *db.DB, wrapper wrapping.Wrapper, iamR
kms := kms.TestKms(t, conn, wrapper)
targetRepo, err := target.NewRepository(ctx, rw, rw, kms)
require.NoError(err)
_, _, _, err = targetRepo.AddTargetHostSources(ctx, tcpTarget.GetPublicId(), tcpTarget.GetVersion(), []string{sets[0].PublicId})
_, err = targetRepo.AddTargetHostSources(ctx, tcpTarget.GetPublicId(), tcpTarget.GetVersion(), []string{sets[0].PublicId})
require.NoError(err)
authMethod := password.TestAuthMethods(t, conn, org.PublicId, 1)[0]