|
|
|
|
@ -438,7 +438,7 @@ func (r *Repository) ListProjects(ctx context.Context, withOrgId string, opt ...
|
|
|
|
|
return projects, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ListOrgs and supports the WithLimit option.
|
|
|
|
|
// ListOrgs supports the WithLimit option.
|
|
|
|
|
func (r *Repository) ListOrgs(ctx context.Context, opt ...Option) ([]*Scope, error) {
|
|
|
|
|
const op = "iam.(Repository).ListOrgs"
|
|
|
|
|
var orgs []*Scope
|
|
|
|
|
@ -448,3 +448,33 @@ func (r *Repository) ListOrgs(ctx context.Context, opt ...Option) ([]*Scope, err
|
|
|
|
|
}
|
|
|
|
|
return orgs, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ListRecursively allows for recursive listing of scopes based on a root scope
|
|
|
|
|
// ID. It returns the root scope ID as a part of the set.
|
|
|
|
|
func (r *Repository) ListRecursively(ctx context.Context, rootScopeId string, opt ...Option) ([]*Scope, error) {
|
|
|
|
|
const op = "iam.(Repository).ListRecursively"
|
|
|
|
|
var orgs []*Scope
|
|
|
|
|
var where string
|
|
|
|
|
var args []interface{}
|
|
|
|
|
switch {
|
|
|
|
|
case rootScopeId == "global":
|
|
|
|
|
// Nothing -- we want all scopes
|
|
|
|
|
case strings.HasPrefix(rootScopeId, "o_"):
|
|
|
|
|
// The org itself and any projects that have it as parent
|
|
|
|
|
where = "public_id = ? or parent_id = ?"
|
|
|
|
|
args = append(args, rootScopeId, rootScopeId)
|
|
|
|
|
case strings.HasPrefix(rootScopeId, "p_"):
|
|
|
|
|
// No scopes can (currently) live under projects, so just the project
|
|
|
|
|
// itself
|
|
|
|
|
where = "public_id = ?"
|
|
|
|
|
args = append(args, rootScopeId)
|
|
|
|
|
default:
|
|
|
|
|
// We have no idea what scope type this is so bail
|
|
|
|
|
return nil, errors.New(errors.InvalidPublicId, op+":TypeSwitch", "invalid scope ID")
|
|
|
|
|
}
|
|
|
|
|
err := r.list(ctx, &orgs, where, args, opt...)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, errors.Wrap(err, op+":ListQuery")
|
|
|
|
|
}
|
|
|
|
|
return orgs, nil
|
|
|
|
|
}
|
|
|
|
|
|