Add support for recursive listing (#885)
This commit is contained in:
1 parent
1f9fcad1cd
commit
6cd97a4a6e
77 files changed
+2244
-1448
No files matched your search
@@ -113,8 +113,8 @@ func (r *Repository) LookupAuthMethod(ctx context.Context, publicId string, opt
|
||||
}
|
||||
|
||||
// ListAuthMethods returns a slice of AuthMethods for the scopeId. WithLimit is the only option supported.
|
||||
func (r *Repository) ListAuthMethods(ctx context.Context, scopeId string, opt ...Option) ([]*AuthMethod, error) {
|
||||
if scopeId == "" {
|
||||
func (r *Repository) ListAuthMethods(ctx context.Context, scopeIds []string, opt ...Option) ([]*AuthMethod, error) {
|
||||
if len(scopeIds) == 0 {
|
||||
return nil, fmt.Errorf("list: password auth method: missing scope id: %w", errors.ErrInvalidParameter)
|
||||
}
|
||||
opts := getOpts(opt...)
|
||||
@@ -124,7 +124,7 @@ func (r *Repository) ListAuthMethods(ctx context.Context, scopeId string, opt ..
|
||||
limit = opts.withLimit
|
||||
}
|
||||
var authMethods []*AuthMethod
|
||||
err := r.reader.SearchWhere(ctx, &authMethods, "scope_id = ?", []interface{}{scopeId}, db.WithLimit(limit))
|
||||
err := r.reader.SearchWhere(ctx, &authMethods, "scope_id in (?)", []interface{}{scopeIds}, db.WithLimit(limit))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("list: password auth method: %w", err)
|
||||
}
|
||||
|
||||
@@ -370,7 +370,7 @@ func TestRepository_ListAuthMethods(t *testing.T) {
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
in string
|
||||
in []string
|
||||
opts []Option
|
||||
want []*AuthMethod
|
||||
wantIsErr error
|
||||
@@ -381,12 +381,12 @@ func TestRepository_ListAuthMethods(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "Scope with no auth methods",
|
||||
in: noAuthMethodOrg.GetPublicId(),
|
||||
in: []string{noAuthMethodOrg.GetPublicId()},
|
||||
want: []*AuthMethod{},
|
||||
},
|
||||
{
|
||||
name: "With populated scope id",
|
||||
in: o.GetPublicId(),
|
||||
in: []string{o.GetPublicId()},
|
||||
want: authMethods,
|
||||
},
|
||||
}
|
||||
@@ -410,6 +410,31 @@ func TestRepository_ListAuthMethods(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRepository_ListAuthMethods_Multiple_Scopes(t *testing.T) {
|
||||
conn, _ := db.TestSetup(t, "postgres")
|
||||
rw := db.New(conn)
|
||||
wrapper := db.TestWrapper(t)
|
||||
kms := kms.TestKms(t, conn, wrapper)
|
||||
iamRepo := iam.TestRepo(t, conn, wrapper)
|
||||
repo, err := NewRepository(rw, rw, kms)
|
||||
require.NoError(t, err)
|
||||
|
||||
var total int
|
||||
const numPerScope = 10
|
||||
TestAuthMethods(t, conn, "global", numPerScope)
|
||||
total += numPerScope
|
||||
scopeIds := []string{"global"}
|
||||
for i := 0; i < 10; i++ {
|
||||
o := iam.TestOrg(t, iamRepo)
|
||||
scopeIds = append(scopeIds, o.GetPublicId())
|
||||
TestAuthMethods(t, conn, o.GetPublicId(), numPerScope)
|
||||
total += numPerScope
|
||||
}
|
||||
got, err := repo.ListAuthMethods(context.Background(), scopeIds)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, total, len(got))
|
||||
}
|
||||
|
||||
func TestRepository_ListAuthMethods_Limits(t *testing.T) {
|
||||
conn, _ := db.TestSetup(t, "postgres")
|
||||
rw := db.New(conn)
|
||||
@@ -471,7 +496,7 @@ func TestRepository_ListAuthMethods_Limits(t *testing.T) {
|
||||
repo, err := NewRepository(rw, rw, kms, tt.repoOpts...)
|
||||
assert.NoError(err)
|
||||
require.NotNil(repo)
|
||||
got, err := repo.ListAuthMethods(context.Background(), ams[0].GetScopeId(), tt.listOpts...)
|
||||
got, err := repo.ListAuthMethods(context.Background(), []string{ams[0].GetScopeId()}, tt.listOpts...)
|
||||
require.NoError(err)
|
||||
assert.Len(got, tt.wantLen)
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user