Add ability to filter List*Requests (#952)
This commit is contained in:
1 parent
3c33d05c96
commit
97b404032b
53 files changed
+2624
-1748
No files matched your search
@@ -141,6 +141,10 @@ func (s Service) ListAuthMethods(ctx context.Context, req *pbs.ListAuthMethodsRe
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
filter, err := handlers.NewFilter(req.GetFilter())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
finalItems := make([]*pb.AuthMethod, 0, len(ul))
|
||||
res := &perms.Resource{
|
||||
Type: resource.AuthMethod,
|
||||
@@ -149,7 +153,10 @@ func (s Service) ListAuthMethods(ctx context.Context, req *pbs.ListAuthMethodsRe
|
||||
item.Scope = scopeInfoMap[item.GetScopeId()]
|
||||
res.ScopeId = item.Scope.Id
|
||||
item.AuthorizedActions = authResults.FetchActionSetForId(ctx, item.Id, IdActions, auth.WithResource(res)).Strings()
|
||||
if len(item.AuthorizedActions) > 0 {
|
||||
if len(item.AuthorizedActions) == 0 {
|
||||
continue
|
||||
}
|
||||
if filter.Match(item) {
|
||||
finalItems = append(finalItems, item)
|
||||
if err := populateCollectionAuthorizedActions(ctx, authResults, item); err != nil {
|
||||
return nil, err
|
||||
@@ -605,6 +612,9 @@ func validateListRequest(req *pbs.ListAuthMethodsRequest) error {
|
||||
req.GetScopeId() != scope.Global.String() {
|
||||
badFields["scope_id"] = "This field must be 'global' or a valid org scope id."
|
||||
}
|
||||
if _, err := handlers.NewFilter(req.GetFilter()); err != nil {
|
||||
badFields["filter"] = fmt.Sprintf("This field could not be parsed. %v", err)
|
||||
}
|
||||
if len(badFields) > 0 {
|
||||
return handlers.InvalidArgumentErrorf("Improperly formatted identifier.", badFields)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user