Migrate credential-library nomenclature around targets to credential-source (#1413)

See the CHANGELOG entry for more information.

Co-authored-by: Jim <jlambert@hashicorp.com>

Co-authored-by: Michael Gaffney <mgaffney@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2021-07-27 12:48:36 -04:00
1 parent 528d54b4ad
commit ab6f3eaeb4
36 files changed
+3284 -673

No files matched your search

+26 -2
View File
@@ -10,8 +10,10 @@ import (
"google.golang.org/protobuf/proto"
)
// A CredentialLibrary represents the relationship between a target
// and a credential library.
var _ CredentialSource = (*TargetLibrary)(nil)
// A CredentialLibrary is a CredentialSource that represents the relationship
// between a target and a credential library.
type CredentialLibrary struct {
*store.CredentialLibrary
tableName string `gorm:"-"`
@@ -76,6 +78,8 @@ func (t *CredentialLibrary) oplog(op oplog.OpType) oplog.Metadata {
// A TargetLibrary represents the relationship between a target and a
// credential library and includes the id of the credential store that the
// library is a part of and the library's name and description.
//
// It implements the target.CredentialSource interface.
type TargetLibrary struct {
*store.CredentialLibrary
StoreId string
@@ -85,3 +89,23 @@ type TargetLibrary struct {
func (ts *TargetLibrary) TableName() string {
return "target_library"
}
// Id returns the ID of the library
func (ts *TargetLibrary) Id() string {
return ts.CredentialLibraryId
}
// CredentialStoreId returns the ID of the store containing the library
func (ts *TargetLibrary) CredentialStoreId() string {
return ts.StoreId
}
// CredentialPurpose returns the purpose of the credential
func (ts *TargetLibrary) CredentialPurpose() credential.Purpose {
return credential.Purpose(ts.GetCredentialPurpose())
}
// TargetId returns the target linked to this credential source
func (ts *TargetLibrary) TargetId() string {
return ts.GetTargetId()
}
+12
View File
@@ -0,0 +1,12 @@
package target
import "github.com/hashicorp/boundary/internal/credential"
// CredentialSource is an interface that can be implemented by both a library
// and a singular credential.
type CredentialSource interface {
CredentialStoreId() string
Id() string
CredentialPurpose() credential.Purpose
TargetId() string
}
+5 -5
View File
@@ -26,7 +26,7 @@ type options struct {
withUserId string
withTargetType *TargetType
withHostSets []string
withCredentialLibraries []string
withCredentialSources []string
withSessionMaxSeconds uint32
withSessionConnectionLimit int32
withPublicId string
@@ -45,7 +45,7 @@ func getDefaultOptions() options {
withUserId: "",
withTargetType: nil,
withHostSets: nil,
withCredentialLibraries: nil,
withCredentialSources: nil,
withSessionMaxSeconds: uint32((8 * time.Hour).Seconds()),
withSessionConnectionLimit: 1,
withPublicId: "",
@@ -125,10 +125,10 @@ func WithHostSets(hs []string) Option {
}
}
// WithCredentialLibraries provides an option for providing a list of credential library ids
func WithCredentialLibraries(cl []string) Option {
// WithCredentialSources provides an option for providing a list of credential source ids
func WithCredentialSources(cl []string) Option {
return func(o *options) {
o.withCredentialLibraries = cl
o.withCredentialSources = cl
}
}
+3 -3
View File
@@ -104,11 +104,11 @@ func Test_GetOpts(t *testing.T) {
testOpts.withWorkerFilter = `"/foo" == "bar"`
assert.Equal(opts, testOpts)
})
t.Run("WithCredentialLibraries", func(t *testing.T) {
t.Run("WithCredentialSources", func(t *testing.T) {
assert := assert.New(t)
opts := getOpts(WithCredentialLibraries([]string{"alice", "bob"}))
opts := getOpts(WithCredentialSources([]string{"alice", "bob"}))
testOpts := getDefaultOptions()
testOpts.withCredentialLibraries = []string{"alice", "bob"}
testOpts.withCredentialSources = []string{"alice", "bob"}
assert.Equal(opts, testOpts)
})
}
+9 -9
View File
@@ -53,10 +53,10 @@ func NewRepository(r db.Reader, w db.Writer, kms *kms.Kms, opt ...Option) (*Repo
}
// LookupTarget will look up a target in the repository and return the target
// with its host set ids and credential library ids. If the target is not found,
// with its host set ids and credential source ids. If the target is not found,
// it will return nil, nil, nil, nil.
// No options are currently supported.
func (r *Repository) LookupTarget(ctx context.Context, publicIdOrName string, opt ...Option) (Target, []*TargetSet, []*TargetLibrary, error) {
func (r *Repository) LookupTarget(ctx context.Context, publicIdOrName string, opt ...Option) (Target, []*TargetSet, []CredentialSource, error) {
const op = "target.(Repository).LookupTarget"
opts := getOpts(opt...)
@@ -98,7 +98,7 @@ func (r *Repository) LookupTarget(ctx context.Context, publicIdOrName string, op
target := allocTargetView()
target.PublicId = publicIdOrName
var hostSets []*TargetSet
var credLibs []*TargetLibrary
var credSources []CredentialSource
_, err := r.writer.DoTx(
ctx,
db.StdRetryCnt,
@@ -119,7 +119,7 @@ func (r *Repository) LookupTarget(ctx context.Context, publicIdOrName string, op
if hostSets, err = fetchSets(ctx, read, target.PublicId); err != nil {
return errors.Wrap(err, op)
}
if credLibs, err = fetchLibraries(ctx, read, target.PublicId); err != nil {
if credSources, err = fetchCredentialSources(ctx, read, target.PublicId); err != nil {
return errors.Wrap(err, op)
}
return nil
@@ -135,7 +135,7 @@ func (r *Repository) LookupTarget(ctx context.Context, publicIdOrName string, op
if err != nil {
return nil, nil, nil, errors.Wrap(err, op)
}
return subtype, hostSets, credLibs, nil
return subtype, hostSets, credSources, nil
}
// ListTargets in targets in a scope. Supports the WithScopeId, WithLimit, WithTargetType options.
@@ -250,7 +250,7 @@ func (r *Repository) DeleteTarget(ctx context.Context, publicId string, _ ...Opt
// update a target in the db repository with an oplog entry.
// It currently supports no options.
func (r *Repository) update(ctx context.Context, target Target, version uint32, fieldMaskPaths []string, setToNullPaths []string, _ ...Option) (Target, []*TargetSet, []*TargetLibrary, int, error) {
func (r *Repository) update(ctx context.Context, target Target, version uint32, fieldMaskPaths []string, setToNullPaths []string, _ ...Option) (Target, []*TargetSet, []CredentialSource, int, error) {
const op = "target.(Repository).update"
if version == 0 {
return nil, nil, nil, db.NoRowsAffected, errors.New(errors.InvalidParameter, op, "missing version")
@@ -284,7 +284,7 @@ func (r *Repository) update(ctx context.Context, target Target, version uint32,
var rowsUpdated int
var returnedTarget interface{}
var hostSets []*TargetSet
var credLibs []*TargetLibrary
var credSources []CredentialSource
_, err = r.writer.DoTx(
ctx,
db.StdRetryCnt,
@@ -310,7 +310,7 @@ func (r *Repository) update(ctx context.Context, target Target, version uint32,
return errors.Wrap(err, op)
}
if credLibs, err = fetchLibraries(ctx, reader, target.GetPublicId()); err != nil {
if credSources, err = fetchCredentialSources(ctx, reader, target.GetPublicId()); err != nil {
return errors.Wrap(err, op)
}
return nil
@@ -319,5 +319,5 @@ func (r *Repository) update(ctx context.Context, target Target, version uint32,
if err != nil {
return nil, nil, nil, db.NoRowsAffected, errors.Wrap(err, op)
}
return returnedTarget.(Target), hostSets, credLibs, rowsUpdated, nil
return returnedTarget.(Target), hostSets, credSources, rowsUpdated, nil
}
@@ -11,24 +11,24 @@ import (
"github.com/hashicorp/boundary/internal/oplog"
)
// AddTargetCredentialLibraries adds the clIds to the targetId in the repository. The target
// and the list of credential libraries attached to the target, after clIds are added,
// AddTargetCredentialSources adds the cIds to the targetId in the repository. The target
// and the list of credential sources attached to the target, after cIds are added,
// will be returned on success.
// The targetVersion must match the current version of the targetId in the repository.
func (r *Repository) AddTargetCredentialLibraries(ctx context.Context, targetId string, targetVersion uint32, clIds []string, _ ...Option) (Target, []*TargetSet, []*TargetLibrary, error) {
const op = "target.(Repository).AddTargetCredentialLibraries"
func (r *Repository) AddTargetCredentialSources(ctx context.Context, targetId string, targetVersion uint32, cIds []string, _ ...Option) (Target, []*TargetSet, []CredentialSource, error) {
const op = "target.(Repository).AddTargetCredentialSources"
if targetId == "" {
return nil, nil, nil, errors.New(errors.InvalidParameter, op, "missing target id")
}
if targetVersion == 0 {
return nil, nil, nil, errors.New(errors.InvalidParameter, op, "missing version")
}
if len(clIds) == 0 {
return nil, nil, nil, errors.New(errors.InvalidParameter, op, "missing credential library ids")
if len(cIds) == 0 {
return nil, nil, nil, errors.New(errors.InvalidParameter, op, "missing credential source ids")
}
addCredLibs := make([]interface{}, 0, len(clIds))
for _, id := range clIds {
addCredLibs := make([]interface{}, 0, len(cIds))
for _, id := range cIds {
cl, err := NewCredentialLibrary(targetId, id)
if err != nil {
return nil, nil, nil, errors.Wrap(err, op, errors.WithMsg("unable to create in memory credential library"))
@@ -61,7 +61,7 @@ func (r *Repository) AddTargetCredentialLibraries(ctx context.Context, targetId
}
var hostSets []*TargetSet
var credLibs []*TargetLibrary
var credSources []CredentialSource
var updatedTarget interface{}
_, err = r.writer.DoTx(
ctx,
@@ -89,7 +89,7 @@ func (r *Repository) AddTargetCredentialLibraries(ctx context.Context, targetId
credLibsOplogMsgs := make([]*oplog.Message, 0, len(addCredLibs))
if err := w.CreateItems(ctx, addCredLibs, db.NewOplogMsgs(&credLibsOplogMsgs)); err != nil {
return errors.Wrap(err, op, errors.WithMsg("unable to create target credential libraries"))
return errors.Wrap(err, op, errors.WithMsg("unable to create target credential sources"))
}
msgs = append(msgs, credLibsOplogMsgs...)
@@ -98,11 +98,11 @@ func (r *Repository) AddTargetCredentialLibraries(ctx context.Context, targetId
}
hostSets, err = fetchSets(ctx, reader, targetId)
if err != nil {
return errors.Wrap(err, op, errors.WithMsg("unable to retrieve credential libraries after adding"))
return errors.Wrap(err, op, errors.WithMsg("unable to retrieve credential sources after adding"))
}
credLibs, err = fetchLibraries(ctx, reader, targetId)
credSources, err = fetchCredentialSources(ctx, reader, targetId)
if err != nil {
return errors.Wrap(err, op, errors.WithMsg("unable to retrieve credential libraries after adding"))
return errors.Wrap(err, op, errors.WithMsg("unable to retrieve credential sources after adding"))
}
return nil
},
@@ -110,25 +110,25 @@ func (r *Repository) AddTargetCredentialLibraries(ctx context.Context, targetId
if err != nil {
return nil, nil, nil, errors.Wrap(err, op)
}
return updatedTarget.(Target), hostSets, credLibs, nil
return updatedTarget.(Target), hostSets, credSources, nil
}
// DeleteTargetCredentialLibraries deletes credential libraries from a target in the repository.
// DeleteTargetCredentialSources deletes credential sources from a target in the repository.
// The target's current db version must match the targetVersion or an error will be returned.
func (r *Repository) DeleteTargetCredentialLibraries(ctx context.Context, targetId string, targetVersion uint32, clIds []string, _ ...Option) (int, error) {
const op = "target.(Repository).DeleteTargetCredentialLibraries"
func (r *Repository) DeleteTargetCredentialSources(ctx context.Context, targetId string, targetVersion uint32, csIds []string, _ ...Option) (int, error) {
const op = "target.(Repository).DeleteTargetCredentialSources"
if targetId == "" {
return db.NoRowsAffected, errors.New(errors.InvalidParameter, op, "missing target id")
}
if targetVersion == 0 {
return db.NoRowsAffected, errors.New(errors.InvalidParameter, op, "missing version")
}
if len(clIds) == 0 {
return db.NoRowsAffected, errors.New(errors.InvalidParameter, op, "missing credential library ids")
if len(csIds) == 0 {
return db.NoRowsAffected, errors.New(errors.InvalidParameter, op, "missing credential source ids")
}
deleteCredLibs := make([]interface{}, 0, len(clIds))
for _, id := range clIds {
deleteCredLibs := make([]interface{}, 0, len(csIds))
for _, id := range csIds {
cl, err := NewCredentialLibrary(targetId, id)
if err != nil {
return db.NoRowsAffected, errors.Wrap(err, op, errors.WithMsg("unable to create in memory credential library"))
@@ -188,10 +188,10 @@ func (r *Repository) DeleteTargetCredentialLibraries(ctx context.Context, target
credLibsOplogMsgs := make([]*oplog.Message, 0, len(deleteCredLibs))
rowsDeleted, err = w.DeleteItems(ctx, deleteCredLibs, db.NewOplogMsgs(&credLibsOplogMsgs))
if err != nil {
return errors.Wrap(err, op, errors.WithMsg("unable to delete target credential libraries"))
return errors.Wrap(err, op, errors.WithMsg("unable to delete target credential sources"))
}
if rowsDeleted != len(deleteCredLibs) {
return errors.New(errors.MultipleRecords, op, fmt.Sprintf("credential libraries deleted %d did not match request for %d", rowsDeleted, len(deleteCredLibs)))
return errors.New(errors.MultipleRecords, op, fmt.Sprintf("credential sources deleted %d did not match request for %d", rowsDeleted, len(deleteCredLibs)))
}
msgs = append(msgs, credLibsOplogMsgs...)
@@ -207,11 +207,11 @@ func (r *Repository) DeleteTargetCredentialLibraries(ctx context.Context, target
return rowsDeleted, nil
}
// SetTargetCredentialLibraries will set the target's credential libraries. Set will add
// and/or delete credential libraries as need to reconcile the existing credential libraries
// with the request. If clIds is empty, all the credential libraries will be cleared from the target.
func (r *Repository) SetTargetCredentialLibraries(ctx context.Context, targetId string, targetVersion uint32, clIds []string, _ ...Option) ([]*TargetSet, []*TargetLibrary, int, error) {
const op = "target.(Repository).SetTargetCredentialLibraries"
// SetTargetCredentialSources will set the target's credential sources. Set will add
// and/or delete credential sources as need to reconcile the existing credential sources
// with the request. If clIds is empty, all the credential sources will be cleared from the target.
func (r *Repository) SetTargetCredentialSources(ctx context.Context, targetId string, targetVersion uint32, csIds []string, _ ...Option) ([]*TargetSet, []CredentialSource, int, error) {
const op = "target.(Repository).SetTargetCredentialSources"
if targetId == "" {
return nil, nil, db.NoRowsAffected, errors.New(errors.InvalidParameter, op, "missing target id")
}
@@ -219,7 +219,7 @@ func (r *Repository) SetTargetCredentialLibraries(ctx context.Context, targetId
return nil, nil, db.NoRowsAffected, errors.New(errors.InvalidParameter, op, "missing version")
}
changes, err := r.changes(ctx, targetId, clIds)
changes, err := r.changes(ctx, targetId, csIds)
if err != nil {
return nil, nil, db.NoRowsAffected, errors.Wrap(err, op)
}
@@ -229,11 +229,11 @@ func (r *Repository) SetTargetCredentialLibraries(ctx context.Context, targetId
if err != nil {
return nil, nil, db.NoRowsAffected, errors.Wrap(err, op)
}
credLibs, err := fetchLibraries(ctx, r.reader, targetId)
credSources, err := fetchCredentialSources(ctx, r.reader, targetId)
if err != nil {
return nil, nil, db.NoRowsAffected, errors.Wrap(err, op)
}
return hostSets, credLibs, db.NoRowsAffected, nil
return hostSets, credSources, db.NoRowsAffected, nil
}
var deleteCredLibs, addCredLibs []interface{}
@@ -274,7 +274,7 @@ func (r *Repository) SetTargetCredentialLibraries(ctx context.Context, targetId
var rowsAffected int
var hostSets []*TargetSet
var credLibs []*TargetLibrary
var credSources []CredentialSource
_, err = r.writer.DoTx(
ctx,
db.StdRetryCnt,
@@ -332,9 +332,9 @@ func (r *Repository) SetTargetCredentialLibraries(ctx context.Context, targetId
if err != nil {
return errors.Wrap(err, op, errors.WithMsg("unable to retrieve current target host sets after add/delete"))
}
credLibs, err = fetchLibraries(ctx, reader, targetId)
credSources, err = fetchCredentialSources(ctx, reader, targetId)
if err != nil {
return errors.Wrap(err, op, errors.WithMsg("unable to retrieve current target credential libraries after add/delete"))
return errors.Wrap(err, op, errors.WithMsg("unable to retrieve current target credential sources after add/delete"))
}
return nil
},
@@ -342,7 +342,7 @@ func (r *Repository) SetTargetCredentialLibraries(ctx context.Context, targetId
if err != nil {
return nil, nil, db.NoRowsAffected, errors.Wrap(err, op)
}
return hostSets, credLibs, rowsAffected, nil
return hostSets, credSources, rowsAffected, nil
}
type change struct {
@@ -385,14 +385,21 @@ func (r *Repository) changes(ctx context.Context, targetId string, clIds []strin
return changes, nil
}
func fetchLibraries(ctx context.Context, r db.Reader, targetId string) ([]*TargetLibrary, error) {
const op = "target.fetchLibraries"
func fetchCredentialSources(ctx context.Context, r db.Reader, targetId string) ([]CredentialSource, error) {
const op = "target.fetchCredentialSources"
var libraries []*TargetLibrary
if err := r.SearchWhere(ctx, &libraries, "target_id = ?", []interface{}{targetId}); err != nil {
return nil, errors.Wrap(err, op)
}
// FIXME: When we have static creds, there will need to be an updated view
// that unions between libs and creds, at which point the type above will
// change. For now we just take the libraries and wrap them.
if len(libraries) == 0 {
return nil, nil
}
return libraries, nil
ret := make([]CredentialSource, len(libraries))
for i, lib := range libraries {
ret[i] = lib
}
return ret, nil
}
@@ -17,7 +17,7 @@ import (
"google.golang.org/protobuf/proto"
)
func TestRepository_AddTargetCredentialLibraries(t *testing.T) {
func TestRepository_AddTargetCredentialSources(t *testing.T) {
t.Parallel()
conn, _ := db.TestSetup(t, "postgres")
rw := db.New(conn)
@@ -55,7 +55,7 @@ func TestRepository_AddTargetCredentialLibraries(t *testing.T) {
wantErrCode: errors.InvalidParameter,
},
{
name: "no-cred-libs",
name: "no-cred-sources",
args: args{
targetVersion: 1,
},
@@ -63,7 +63,7 @@ func TestRepository_AddTargetCredentialLibraries(t *testing.T) {
wantErrCode: errors.InvalidParameter,
},
{
name: "valid-single-lib",
name: "valid-single-source",
args: args{
targetVersion: 1,
credLibIds: []string{lib1.PublicId},
@@ -72,7 +72,7 @@ func TestRepository_AddTargetCredentialLibraries(t *testing.T) {
wantErr: false,
},
{
name: "valid-multiple-libs",
name: "valid-multiple-sources",
args: args{
targetVersion: 1,
credLibIds: []string{lib1.PublicId, lib2.PublicId, lib3.PublicId},
@@ -81,10 +81,10 @@ func TestRepository_AddTargetCredentialLibraries(t *testing.T) {
wantErr: false,
},
{
name: "invalid-lib-id",
name: "invalid-source-id",
args: args{
targetVersion: 1,
credLibIds: []string{lib1.PublicId, lib2.PublicId, lib3.PublicId, "invalid-lib-id"},
credLibIds: []string{lib1.PublicId, lib2.PublicId, lib3.PublicId, "invalid-source-id"},
},
wantErr: true,
wantErrCode: errors.NotSpecificIntegrity,
@@ -104,78 +104,78 @@ func TestRepository_AddTargetCredentialLibraries(t *testing.T) {
assert, require := assert.New(t), require.New(t)
projTarget := TestTcpTarget(t, conn, staticProj.PublicId, tt.name)
gotTarget, _, gotCredLibs, err := repo.AddTargetCredentialLibraries(context.Background(), projTarget.PublicId, tt.args.targetVersion, tt.args.credLibIds)
gotTarget, _, gotCredSources, err := repo.AddTargetCredentialSources(context.Background(), projTarget.PublicId, tt.args.targetVersion, tt.args.credLibIds)
if tt.wantErr {
require.Error(err)
assert.Truef(errors.Match(errors.T(tt.wantErrCode), err), "unexpected error %s", err.Error())
return
}
require.NoError(err)
assert.Len(gotCredLibs, len(tt.wantCredLibIds))
gotCredLibsMap := map[string]*TargetLibrary{}
for _, s := range gotCredLibs {
gotCredLibsMap[s.CredentialLibraryId] = s
assert.Len(gotCredSources, len(tt.wantCredLibIds))
gotCredSourcesMap := map[string]CredentialSource{}
for _, s := range gotCredSources {
gotCredSourcesMap[s.Id()] = s
}
for _, id := range tt.wantCredLibIds {
assert.NotEmpty(gotCredLibsMap[id])
assert.NotEmpty(gotCredSourcesMap[id])
}
// test to see of the target version update oplog was created
err = db.TestVerifyOplog(t, rw, projTarget.PublicId, db.WithOperation(oplog.OpType_OP_TYPE_UPDATE), db.WithCreateNotBefore(10*time.Second))
assert.NoError(err)
foundCredLibs, err := fetchLibraries(context.Background(), rw, projTarget.PublicId)
foundCredSources, err := fetchCredentialSources(context.Background(), rw, projTarget.PublicId)
require.NoError(err)
assert.Len(foundCredLibs, len(gotCredLibsMap))
for _, s := range foundCredLibs {
assert.NotEmpty(gotCredLibsMap[s.CredentialLibraryId])
assert.Equal(projTarget.PublicId, s.TargetId)
assert.Len(foundCredSources, len(gotCredSourcesMap))
for _, s := range foundCredSources {
assert.NotEmpty(gotCredSourcesMap[s.Id()])
assert.Equal(projTarget.PublicId, s.TargetId())
}
target, _, lookupCredLibs, err := repo.LookupTarget(context.Background(), projTarget.PublicId)
target, _, lookupCredSources, err := repo.LookupTarget(context.Background(), projTarget.PublicId)
require.NoError(err)
assert.Equal(tt.args.targetVersion+1, target.GetVersion())
assert.Equal(projTarget.GetVersion(), target.GetVersion()-1)
assert.True(proto.Equal(gotTarget.(*TcpTarget), target.(*TcpTarget)))
assert.Equal(gotCredLibs, lookupCredLibs)
assert.Equal(gotCredSources, lookupCredSources)
})
}
t.Run("add-existing", func(t *testing.T) {
assert, require := assert.New(t), require.New(t)
projTarget := TestTcpTarget(t, conn, staticProj.PublicId, "add-existing")
_, _, gotCredLibs, err := repo.AddTargetCredentialLibraries(context.Background(), projTarget.PublicId, 1, []string{lib1.PublicId})
_, _, gotCredSources, err := repo.AddTargetCredentialSources(context.Background(), projTarget.PublicId, 1, []string{lib1.PublicId})
require.NoError(err)
assert.Len(gotCredLibs, 1)
assert.Equal(lib1.PublicId, gotCredLibs[0].CredentialLibraryId)
assert.Len(gotCredSources, 1)
assert.Equal(lib1.PublicId, gotCredSources[0].Id())
// Adding lib1 again should error
_, _, _, err = repo.AddTargetCredentialLibraries(context.Background(), projTarget.PublicId, 2, []string{lib1.PublicId})
_, _, _, err = repo.AddTargetCredentialSources(context.Background(), projTarget.PublicId, 2, []string{lib1.PublicId})
require.Error(err)
assert.True(errors.Match(errors.T(errors.NotUnique), err))
// Adding multiple with lib1 in set should error
_, _, _, err = repo.AddTargetCredentialLibraries(context.Background(), projTarget.PublicId, 2, []string{lib3.PublicId, lib2.PublicId, lib1.PublicId})
_, _, _, err = repo.AddTargetCredentialSources(context.Background(), projTarget.PublicId, 2, []string{lib3.PublicId, lib2.PublicId, lib1.PublicId})
require.Error(err)
assert.True(errors.Match(errors.T(errors.NotUnique), err))
// Previous transactions should have been rolled back and only lib1 should be associated
gotCredLibs, err = fetchLibraries(context.Background(), rw, projTarget.PublicId)
gotCredSources, err = fetchCredentialSources(context.Background(), rw, projTarget.PublicId)
require.NoError(err)
assert.Len(gotCredLibs, 1)
assert.Equal(lib1.PublicId, gotCredLibs[0].CredentialLibraryId)
assert.Len(gotCredSources, 1)
assert.Equal(lib1.PublicId, gotCredSources[0].Id())
})
t.Run("target-not-found", func(t *testing.T) {
assert, require := assert.New(t), require.New(t)
_, _, _, err := repo.AddTargetCredentialLibraries(context.Background(), "fake-target-id", 1, []string{lib1.PublicId})
_, _, _, err := repo.AddTargetCredentialSources(context.Background(), "fake-target-id", 1, []string{lib1.PublicId})
require.Error(err)
assert.Truef(errors.Match(errors.T(errors.RecordNotFound), err), "unexpected error %s", err.Error())
})
}
func TestRepository_DeleteTargetCredentialLibraries(t *testing.T) {
func TestRepository_DeleteTargetCredentialSources(t *testing.T) {
t.Parallel()
conn, _ := db.TestSetup(t, "postgres")
rw := db.New(conn)
@@ -286,13 +286,13 @@ func TestRepository_DeleteTargetCredentialLibraries(t *testing.T) {
clIds = append(clIds, cl.PublicId)
}
}
_, _, addedCredLibs, err := repo.AddTargetCredentialLibraries(context.Background(), target.GetPublicId(), 1, clIds)
_, _, addedCredSources, err := repo.AddTargetCredentialSources(context.Background(), target.GetPublicId(), 1, clIds)
require.NoError(err)
assert.Equal(tt.args.createCnt, len(addedCredLibs))
assert.Equal(tt.args.createCnt, len(addedCredSources))
deleteCredLibs := make([]string, 0, tt.args.deleteCnt)
deleteCredSources := make([]string, 0, tt.args.deleteCnt)
for i := 0; i < tt.args.deleteCnt; i++ {
deleteCredLibs = append(deleteCredLibs, clIds[i])
deleteCredSources = append(deleteCredSources, clIds[i])
}
var targetId string
switch {
@@ -308,7 +308,7 @@ func TestRepository_DeleteTargetCredentialLibraries(t *testing.T) {
default:
targetVersion = 2
}
deletedRows, err := repo.DeleteTargetCredentialLibraries(context.Background(), targetId, targetVersion, deleteCredLibs)
deletedRows, err := repo.DeleteTargetCredentialSources(context.Background(), targetId, targetVersion, deleteCredSources)
if tt.wantErr {
require.Error(err)
assert.Equal(0, deletedRows)
@@ -335,30 +335,30 @@ func TestRepository_DeleteTargetCredentialLibraries(t *testing.T) {
lib3 := libs[2]
projTarget := TestTcpTarget(t, conn, proj.PublicId, "add-existing")
_, _, gotCredLibs, err := repo.AddTargetCredentialLibraries(context.Background(), projTarget.PublicId, 1, []string{lib1.PublicId, lib2.PublicId})
_, _, gotCredSources, err := repo.AddTargetCredentialSources(context.Background(), projTarget.PublicId, 1, []string{lib1.PublicId, lib2.PublicId})
require.NoError(err)
assert.Len(gotCredLibs, 2)
assert.Len(gotCredSources, 2)
// Deleting an unassociated library should return an error
delCount, err := repo.DeleteTargetCredentialLibraries(context.Background(), projTarget.PublicId, 2, []string{lib3.PublicId})
// Deleting an unassociated source should return an error
delCount, err := repo.DeleteTargetCredentialSources(context.Background(), projTarget.PublicId, 2, []string{lib3.PublicId})
require.Error(err)
assert.True(errors.Match(errors.T(errors.MultipleRecords), err))
assert.Equal(0, delCount)
// Deleting libraries which includes an unassociated libary should return an error
delCount, err = repo.DeleteTargetCredentialLibraries(context.Background(), projTarget.PublicId, 2, []string{lib1.PublicId, lib2.PublicId, lib3.PublicId})
// Deleting sources which includes an unassociated source should return an error
delCount, err = repo.DeleteTargetCredentialSources(context.Background(), projTarget.PublicId, 2, []string{lib1.PublicId, lib2.PublicId, lib3.PublicId})
require.Error(err)
assert.True(errors.Match(errors.T(errors.MultipleRecords), err))
assert.Equal(0, delCount)
// Previous transactions should have been rolled back and only lib1 should be associated
gotCredLibs, err = fetchLibraries(context.Background(), rw, projTarget.PublicId)
gotCredSources, err = fetchCredentialSources(context.Background(), rw, projTarget.PublicId)
require.NoError(err)
assert.Len(gotCredLibs, 2)
assert.Len(gotCredSources, 2)
})
}
func TestRepository_SetTargetCredentialLibraries(t *testing.T) {
func TestRepository_SetTargetCredentialSources(t *testing.T) {
t.Parallel()
conn, _ := db.TestSetup(t, "postgres")
rw := db.New(conn)
@@ -375,14 +375,14 @@ func TestRepository_SetTargetCredentialLibraries(t *testing.T) {
lib1 := credLibs[0]
lib2 := credLibs[1]
setupFn := func(target Target) []*TargetLibrary {
setupFn := func(target Target) []CredentialSource {
credLibs := vault.TestCredentialLibraries(t, conn, wrapper, cs.GetPublicId(), 10)
clIds := make([]string, 0, len(credLibs))
for _, cl := range credLibs {
clIds = append(clIds, cl.PublicId)
}
_, _, created, err := repo.AddTargetCredentialLibraries(context.Background(), target.GetPublicId(), 1, clIds)
_, _, created, err := repo.AddTargetCredentialSources(context.Background(), target.GetPublicId(), 1, clIds)
require.NoError(t, err)
require.Equal(t, 10, len(created))
return created
@@ -394,7 +394,7 @@ func TestRepository_SetTargetCredentialLibraries(t *testing.T) {
}
tests := []struct {
name string
setup func(Target) []*TargetLibrary
setup func(Target) []CredentialSource
args args
wantAffectedRows int
wantErr bool
@@ -422,7 +422,7 @@ func TestRepository_SetTargetCredentialLibraries(t *testing.T) {
wantAffectedRows: 0,
},
{
name: "add-cred-libs",
name: "add-cred-sources",
setup: setupFn,
args: args{
targetVersion: 2,
@@ -472,23 +472,23 @@ func TestRepository_SetTargetCredentialLibraries(t *testing.T) {
target := TestTcpTarget(t, conn, proj.PublicId, tt.name)
var origCredLibs []*TargetLibrary
var origCredSources []CredentialSource
if tt.setup != nil {
origCredLibs = tt.setup(target)
origCredSources = tt.setup(target)
}
if tt.args.addToOrigLibs {
origIds := make([]string, 0, len(origCredLibs))
for _, cl := range origCredLibs {
origIds = append(origIds, cl.CredentialLibraryId)
origIds := make([]string, 0, len(origCredSources))
for _, cl := range origCredSources {
origIds = append(origIds, cl.Id())
}
tt.args.clIds = append(tt.args.clIds, origIds...)
}
origTarget, _, lookupCredLibs, err := repo.LookupTarget(context.Background(), target.GetPublicId())
origTarget, _, lookupCredSources, err := repo.LookupTarget(context.Background(), target.GetPublicId())
require.NoError(err)
assert.Equal(origCredLibs, lookupCredLibs)
assert.Equal(origCredSources, lookupCredSources)
_, got, affectedRows, err := repo.SetTargetCredentialLibraries(context.Background(), target.GetPublicId(), tt.args.targetVersion, tt.args.clIds)
_, got, affectedRows, err := repo.SetTargetCredentialSources(context.Background(), target.GetPublicId(), tt.args.targetVersion, tt.args.clIds)
if tt.wantErr {
require.Error(err)
assert.Equal(0, affectedRows)
@@ -508,7 +508,7 @@ func TestRepository_SetTargetCredentialLibraries(t *testing.T) {
if len(got) > 0 {
gotIds = make([]string, 0, len(got))
for _, s := range got {
gotIds = append(gotIds, s.CredentialLibraryId)
gotIds = append(gotIds, s.Id())
}
}
sort.Strings(gotIds)
@@ -525,7 +525,7 @@ func TestRepository_SetTargetCredentialLibraries(t *testing.T) {
t.Run("missing-target-id", func(t *testing.T) {
assert, require := assert.New(t), require.New(t)
_, _, _, err := repo.SetTargetCredentialLibraries(context.Background(), "", 1, []string{lib1.PublicId})
_, _, _, err := repo.SetTargetCredentialSources(context.Background(), "", 1, []string{lib1.PublicId})
require.Error(err)
assert.Truef(errors.Match(errors.T(errors.InvalidParameter), err), "unexpected error %s", err.Error())
@@ -533,7 +533,7 @@ func TestRepository_SetTargetCredentialLibraries(t *testing.T) {
t.Run("target-not-found", func(t *testing.T) {
assert, require := assert.New(t), require.New(t)
_, _, _, err := repo.SetTargetCredentialLibraries(context.Background(), "fake-target-id", 1, []string{lib1.PublicId})
_, _, _, err := repo.SetTargetCredentialSources(context.Background(), "fake-target-id", 1, []string{lib1.PublicId})
require.Error(err)
assert.Truef(errors.Match(errors.T(errors.RecordNotFound), err), "unexpected error %s", err.Error())
+10 -10
View File
@@ -15,7 +15,7 @@ import (
// targetVersion or an error will be returned. The target and a list of
// current host set ids will be returned on success. Zero is not a valid value
// for the WithVersion option and will return an error.
func (r *Repository) AddTargetHostSets(ctx context.Context, targetId string, targetVersion uint32, hostSetIds []string, _ ...Option) (Target, []*TargetSet, []*TargetLibrary, error) {
func (r *Repository) AddTargetHostSets(ctx context.Context, targetId string, targetVersion uint32, hostSetIds []string, _ ...Option) (Target, []*TargetSet, []CredentialSource, error) {
const op = "target.(Repository).AddTargetHostSets"
if targetId == "" {
return nil, nil, nil, errors.New(errors.InvalidParameter, op, "missing target id")
@@ -57,7 +57,7 @@ func (r *Repository) AddTargetHostSets(ctx context.Context, targetId string, tar
return nil, nil, nil, errors.Wrap(err, op, errors.WithMsg("unable to get oplog wrapper"))
}
var currentHostSets []*TargetSet
var currentCredLibs []*TargetLibrary
var currentCredSources []CredentialSource
var updatedTarget interface{}
_, err = r.writer.DoTx(
ctx,
@@ -93,9 +93,9 @@ func (r *Repository) AddTargetHostSets(ctx context.Context, targetId string, tar
if err != nil {
return errors.Wrap(err, op, errors.WithMsg("unable to retrieve current host sets after adds"))
}
currentCredLibs, err = fetchLibraries(ctx, reader, targetId)
currentCredSources, err = fetchCredentialSources(ctx, reader, targetId)
if err != nil {
return errors.Wrap(err, op, errors.WithMsg("unable to retrieve current credential libraries after adds"))
return errors.Wrap(err, op, errors.WithMsg("unable to retrieve current credential sources after adds"))
}
return nil
},
@@ -103,7 +103,7 @@ func (r *Repository) AddTargetHostSets(ctx context.Context, targetId string, tar
if err != nil {
return nil, nil, nil, errors.Wrap(err, op, errors.WithMsg("error creating sets"))
}
return updatedTarget.(Target), currentHostSets, currentCredLibs, nil
return updatedTarget.(Target), currentHostSets, currentCredSources, nil
}
// DeleteTargeHostSets deletes host sets from a target (targetId). The target's
@@ -203,7 +203,7 @@ func (r *Repository) DeleteTargeHostSets(ctx context.Context, targetId string, t
// target host sets as need to reconcile the existing sets with the sets
// requested. If hostSetIds is empty, the target host sets will be cleared. Zero
// is not a valid value for the WithVersion option and will return an error.
func (r *Repository) SetTargetHostSets(ctx context.Context, targetId string, targetVersion uint32, hostSetIds []string, _ ...Option) ([]*TargetSet, []*TargetLibrary, int, error) {
func (r *Repository) SetTargetHostSets(ctx context.Context, targetId string, targetVersion uint32, hostSetIds []string, _ ...Option) ([]*TargetSet, []CredentialSource, int, error) {
const op = "target.(Repository).SetTargetHostSets"
if targetId == "" {
return nil, nil, db.NoRowsAffected, errors.New(errors.InvalidParameter, op, "missing target id")
@@ -278,7 +278,7 @@ func (r *Repository) SetTargetHostSets(ctx context.Context, targetId string, tar
var totalRowsAffected int
var currentHostSets []*TargetSet
var currentCredLibs []*TargetLibrary
var currentCredSources []CredentialSource
_, err = r.writer.DoTx(
ctx,
db.StdRetryCnt,
@@ -333,9 +333,9 @@ func (r *Repository) SetTargetHostSets(ctx context.Context, targetId string, tar
if err != nil {
return errors.Wrap(err, op, errors.WithMsg("unable to retrieve current target host sets after set"))
}
currentCredLibs, err = fetchLibraries(ctx, reader, targetId)
currentCredSources, err = fetchCredentialSources(ctx, reader, targetId)
if err != nil {
return errors.Wrap(err, op, errors.WithMsg("unable to retrieve current target credential libraries after set"))
return errors.Wrap(err, op, errors.WithMsg("unable to retrieve current target credential sources after set"))
}
return nil
@@ -344,7 +344,7 @@ func (r *Repository) SetTargetHostSets(ctx context.Context, targetId string, tar
if err != nil {
return nil, nil, db.NoRowsAffected, errors.Wrap(err, op)
}
return currentHostSets, currentCredLibs, totalRowsAffected, nil
return currentHostSets, currentCredSources, totalRowsAffected, nil
}
func fetchSets(ctx context.Context, r db.Reader, targetId string) ([]*TargetSet, error) {
+13 -13
View File
@@ -14,8 +14,8 @@ import (
// CreateTcpTarget inserts into the repository and returns the new Target with
// its list of host sets and credential libraries.
// WithHostSets and WithCredentialLibraries are the only supported option.
func (r *Repository) CreateTcpTarget(ctx context.Context, target *TcpTarget, opt ...Option) (Target, []*TargetSet, []*TargetLibrary, error) {
// WithHostSets and WithCredentialSources are the only supported option.
func (r *Repository) CreateTcpTarget(ctx context.Context, target *TcpTarget, opt ...Option) (Target, []*TargetSet, []CredentialSource, error) {
const op = "target.(Repository).CreateTcpTarget"
opts := getOpts(opt...)
if target == nil {
@@ -63,8 +63,8 @@ func (r *Repository) CreateTcpTarget(ctx context.Context, target *TcpTarget, opt
newHostSets = append(newHostSets, hostSet)
}
newCredLibs := make([]interface{}, 0, len(opts.withCredentialLibraries))
for _, clId := range opts.withCredentialLibraries {
newCredLibs := make([]interface{}, 0, len(opts.withCredentialSources))
for _, clId := range opts.withCredentialSources {
credLib, err := NewCredentialLibrary(t.PublicId, clId)
if err != nil {
return nil, nil, nil, errors.Wrap(err, op, errors.WithMsg("unable to create in memory target credential library"))
@@ -75,7 +75,7 @@ func (r *Repository) CreateTcpTarget(ctx context.Context, target *TcpTarget, opt
metadata := t.oplog(oplog.OpType_OP_TYPE_CREATE)
var returnedTarget interface{}
var returnedHostSet []*TargetSet
var returnedCredLibs []*TargetLibrary
var returnedCredSources []CredentialSource
_, err = r.writer.DoTx(
ctx,
db.StdRetryCnt,
@@ -105,10 +105,10 @@ func (r *Repository) CreateTcpTarget(ctx context.Context, target *TcpTarget, opt
if len(newCredLibs) > 0 {
credLibOplogMsgs := make([]*oplog.Message, 0, len(newCredLibs))
if err := w.CreateItems(ctx, newCredLibs, db.NewOplogMsgs(&credLibOplogMsgs)); err != nil {
return errors.Wrap(err, op, errors.WithMsg("unable to add credential libraries"))
return errors.Wrap(err, op, errors.WithMsg("unable to add credential sources"))
}
if returnedCredLibs, err = fetchLibraries(ctx, read, t.PublicId); err != nil {
return errors.Wrap(err, op, errors.WithMsg("unable to read host sets"))
if returnedCredSources, err = fetchCredentialSources(ctx, read, t.PublicId); err != nil {
return errors.Wrap(err, op, errors.WithMsg("unable to read credential sources"))
}
msgs = append(msgs, credLibOplogMsgs...)
}
@@ -122,7 +122,7 @@ func (r *Repository) CreateTcpTarget(ctx context.Context, target *TcpTarget, opt
if err != nil {
return nil, nil, nil, errors.Wrap(err, op, errors.WithMsg(fmt.Sprintf("failed for %s target id", t.PublicId)))
}
return returnedTarget.(*TcpTarget), returnedHostSet, returnedCredLibs, nil
return returnedTarget.(*TcpTarget), returnedHostSet, returnedCredSources, nil
}
// UpdateTcpTarget will update a target in the repository and return the written
@@ -131,7 +131,7 @@ func (r *Repository) CreateTcpTarget(ctx context.Context, target *TcpTarget, opt
// included in fieldMask. Name, Description, and WorkerFilter are the only
// updatable fields. If no updatable fields are included in the fieldMaskPaths,
// then an error is returned.
func (r *Repository) UpdateTcpTarget(ctx context.Context, target *TcpTarget, version uint32, fieldMaskPaths []string, _ ...Option) (Target, []*TargetSet, []*TargetLibrary, int, error) {
func (r *Repository) UpdateTcpTarget(ctx context.Context, target *TcpTarget, version uint32, fieldMaskPaths []string, _ ...Option) (Target, []*TargetSet, []CredentialSource, int, error) {
const op = "target.(Repository).UpdateTcpTarget"
if target == nil {
return nil, nil, nil, db.NoRowsAffected, errors.New(errors.InvalidParameter, op, "missing target")
@@ -173,7 +173,7 @@ func (r *Repository) UpdateTcpTarget(ctx context.Context, target *TcpTarget, ver
var returnedTarget Target
var rowsUpdated int
var targetSets []*TargetSet
var credLibs []*TargetLibrary
var credSources []CredentialSource
_, err := r.writer.DoTx(
ctx,
db.StdRetryCnt,
@@ -181,7 +181,7 @@ func (r *Repository) UpdateTcpTarget(ctx context.Context, target *TcpTarget, ver
func(read db.Reader, w db.Writer) error {
var err error
t := target.Clone().(*TcpTarget)
returnedTarget, targetSets, credLibs, rowsUpdated, err = r.update(ctx, t, version, dbMask, nullFields)
returnedTarget, targetSets, credSources, rowsUpdated, err = r.update(ctx, t, version, dbMask, nullFields)
if err != nil {
return errors.Wrap(err, op)
}
@@ -194,5 +194,5 @@ func (r *Repository) UpdateTcpTarget(ctx context.Context, target *TcpTarget, ver
}
return nil, nil, nil, db.NoRowsAffected, errors.Wrap(err, op, errors.WithMsg(fmt.Sprintf("failed for %s", target.PublicId)))
}
return returnedTarget.(Target), targetSets, credLibs, rowsUpdated, nil
return returnedTarget, targetSets, credSources, rowsUpdated, nil
}
+14 -14
View File
@@ -36,9 +36,9 @@ func TestRepository_CreateTcpTarget(t *testing.T) {
}
cs := vault.TestCredentialStores(t, conn, wrapper, proj.GetPublicId(), 1)[0]
credLibs := vault.TestCredentialLibraries(t, conn, wrapper, cs.GetPublicId(), 2)
credSources := vault.TestCredentialLibraries(t, conn, wrapper, cs.GetPublicId(), 2)
var clIds []string
for _, cl := range credLibs {
for _, cl := range credSources {
clIds = append(clIds, cl.PublicId)
}
@@ -98,7 +98,7 @@ func TestRepository_CreateTcpTarget(t *testing.T) {
require.NoError(t, err)
return target
}(),
opt: []Option{WithCredentialLibraries(clIds)},
opt: []Option{WithCredentialSources(clIds)},
},
wantErr: false,
wantCredLibs: clIds,
@@ -117,7 +117,7 @@ func TestRepository_CreateTcpTarget(t *testing.T) {
}(),
opt: []Option{
WithHostSets(sets),
WithCredentialLibraries(clIds),
WithCredentialSources(clIds),
},
},
wantErr: false,
@@ -175,7 +175,7 @@ func TestRepository_CreateTcpTarget(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert, require := assert.New(t), require.New(t)
target, hostSets, credLibs, err := repo.CreateTcpTarget(context.Background(), tt.args.target, tt.args.opt...)
target, hostSets, credSources, err := repo.CreateTcpTarget(context.Background(), tt.args.target, tt.args.opt...)
if tt.wantErr {
assert.Error(err)
assert.Nil(target)
@@ -190,9 +190,9 @@ func TestRepository_CreateTcpTarget(t *testing.T) {
}
assert.Equal(tt.wantHostSets, hsIds)
clIds := make([]string, 0, len(credLibs))
for _, cl := range credLibs {
clIds = append(clIds, cl.CredentialLibraryId)
clIds := make([]string, 0, len(credSources))
for _, cl := range credSources {
clIds = append(clIds, cl.Id())
}
assert.Equal(tt.wantCredLibs, clIds)
@@ -200,7 +200,7 @@ func TestRepository_CreateTcpTarget(t *testing.T) {
assert.NoError(err)
assert.True(proto.Equal(target.(*TcpTarget), foundTarget.(*TcpTarget)))
assert.Equal(hostSets, foundHostSets)
assert.Equal(credLibs, foundCredLibs)
assert.Equal(credSources, foundCredLibs)
err = db.TestVerifyOplog(t, rw, target.GetPublicId(), db.WithOperation(oplog.OpType_OP_TYPE_CREATE), db.WithCreateNotBefore(10*time.Second))
assert.NoError(err)
@@ -439,7 +439,7 @@ func TestRepository_UpdateTcpTarget(t *testing.T) {
testClIds = append(testClIds, cl.PublicId)
}
tt.newTargetOpts = append(tt.newTargetOpts, WithHostSets(testHostSetIds), WithCredentialLibraries(testClIds))
tt.newTargetOpts = append(tt.newTargetOpts, WithHostSets(testHostSetIds), WithCredentialSources(testClIds))
name := tt.newName
if name == "" {
name = testId(t)
@@ -455,7 +455,7 @@ func TestRepository_UpdateTcpTarget(t *testing.T) {
updateTarget.Description = tt.args.description
updateTarget.DefaultPort = tt.args.port
targetAfterUpdate, hostSets, credLibs, updatedRows, err := repo.UpdateTcpTarget(context.Background(), &updateTarget, target.Version, tt.args.fieldMaskPaths, tt.args.opt...)
targetAfterUpdate, hostSets, credSources, updatedRows, err := repo.UpdateTcpTarget(context.Background(), &updateTarget, target.Version, tt.args.fieldMaskPaths, tt.args.opt...)
if tt.wantErr {
assert.Error(err)
assert.True(errors.Match(errors.T(tt.wantIsError), err))
@@ -476,9 +476,9 @@ func TestRepository_UpdateTcpTarget(t *testing.T) {
}
assert.Equal(testHostSetIds, afterUpdateIds)
afterUpdateIds = make([]string, 0, len(credLibs))
for _, cl := range credLibs {
afterUpdateIds = append(afterUpdateIds, cl.CredentialLibraryId)
afterUpdateIds = make([]string, 0, len(credSources))
for _, cl := range credSources {
afterUpdateIds = append(afterUpdateIds, cl.Id())
}
assert.Equal(testClIds, afterUpdateIds)
+3 -3
View File
@@ -35,9 +35,9 @@ func TestTcpTarget(t *testing.T, conn *gorm.DB, scopeId, name string, opt ...Opt
err := rw.CreateItems(context.Background(), newHostSets)
require.NoError(err)
}
if len(opts.withCredentialLibraries) > 0 {
newCredLibs := make([]interface{}, 0, len(opts.withCredentialLibraries))
for _, cl := range opts.withCredentialLibraries {
if len(opts.withCredentialSources) > 0 {
newCredLibs := make([]interface{}, 0, len(opts.withCredentialSources))
for _, cl := range opts.withCredentialSources {
newCl, err := NewCredentialLibrary(target.PublicId, cl)
require.NoError(err)
newCredLibs = append(newCredLibs, newCl)
+4 -4
View File
@@ -60,11 +60,11 @@ func Test_TestCredentialLibrary(t *testing.T) {
assert.Len(libs, 2)
rw := db.New(conn)
foundLibs, err := fetchLibraries(context.Background(), rw, target.PublicId)
foundSources, err := fetchCredentialSources(context.Background(), rw, target.PublicId)
require.NoError(err)
foundIds := make([]string, 0, len(foundLibs))
for _, s := range foundLibs {
foundIds = append(foundIds, s.CredentialLibraryId)
foundIds := make([]string, 0, len(foundSources))
for _, s := range foundSources {
foundIds = append(foundIds, s.Id())
}
require.Equal(libIds, foundIds)
}