Skip to content

Commit

Permalink
Validate LookupSubjectsRequest request body (#99)
Browse files Browse the repository at this point in the history
* Validate LookupSubjectsRequest request body

Signed-off-by: Jonathan Marcantonio <[email protected]>

* Validate ResourceType and ResourceId

Signed-off-by: Jonathan Marcantonio <[email protected]>

* Validate relation

Signed-off-by: Jonathan Marcantonio <[email protected]>

---------

Signed-off-by: Jonathan Marcantonio <[email protected]>
  • Loading branch information
lennysgarage authored Jun 14, 2024
1 parent f7d05a0 commit 791e3ba
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion internal/biz/lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,36 @@ func (s *GetSubjectsUsecase) Get(ctx context.Context, req *v0.LookupSubjectsRequ
}

if req.Resource == nil {
s.log.WithContext(ctx).Infof("Missing Resource in request %v", req)
return nil, nil, errors.BadRequest("Invalid request", "Object is required")
}

if req.SubjectRelation != nil {
subjectRelation = *req.SubjectRelation
}

if req.SubjectType == nil {
s.log.WithContext(ctx).Infof("Missing SubjectType in request %v", req)
return nil, nil, errors.BadRequest("Invalid request", "Subject type is required")
}

if req.Relation == "" {
s.log.WithContext(ctx).Infof("Missing relation in request %v", req)
return nil, nil, errors.BadRequest("Invalid request", "Relation is required")
}

if req.Resource.Type == nil {
s.log.WithContext(ctx).Infof("Missing Resource Type in request %v", req)
return nil, nil, errors.BadRequest("Invalid request", "Resource Type is required")
}

if req.Resource.Id == "" {
s.log.WithContext(ctx).Infof("Missing Resource Id in request %v", req)
return nil, nil, errors.BadRequest("Invalid request", "Resource Id is required")
}

subs, errs, err := s.repo.LookupSubjects(ctx, req.SubjectType, subjectRelation, req.Relation, &v0.ObjectReference{
Type: req.Resource.Type, //Need null check
Type: req.Resource.Type,
Id: req.Resource.Id,
}, limit, continuation)

Expand Down

0 comments on commit 791e3ba

Please sign in to comment.