Merge branch 'mg/small-fixes' of _OKE5H2PQKOUfzFFDuD4FA/default/CODE/gitness (#224)

This commit is contained in:
Marko Gacesa 2023-07-24 13:11:42 +00:00 committed by Harness
commit 6fb9b67404
9 changed files with 45 additions and 52 deletions

View File

@ -25,13 +25,12 @@ var (
ErrParentResourceTypeUnknown = errors.New("Unknown parent resource type")
)
/*
* Check checks if a resource specific permission is granted for the current auth session in the scope.
* Returns nil if the permission is granted, otherwise returns an error.
* NotAuthenticated, NotAuthorized, or any unerlaying error.
*/
// Check checks if a resource specific permission is granted for the current auth session in the scope.
// Returns nil if the permission is granted, otherwise returns an error.
// NotAuthenticated, NotAuthorized, or any underlying error.
func Check(ctx context.Context, authorizer authz.Authorizer, session *auth.Session,
scope *types.Scope, resource *types.Resource, permission enum.Permission) error {
scope *types.Scope, resource *types.Resource, permission enum.Permission,
) error {
if session == nil {
return ErrNotAuthenticated
}
@ -53,12 +52,10 @@ func Check(ctx context.Context, authorizer authz.Authorizer, session *auth.Sessi
return nil
}
/*
* CheckChild checks if a resource specific permission is granted for the current auth session
* in the scope of a parent.
* Returns nil if the permission is granted, otherwise returns an error.
* NotAuthenticated, NotAuthorized, or any unerlaying error.
*/
// CheckChild checks if a resource specific permission is granted for the current auth session
// in the scope of a parent.
// Returns nil if the permission is granted, otherwise returns an error.
// NotAuthenticated, NotAuthorized, or any underlying error.
func CheckChild(ctx context.Context, authorizer authz.Authorizer, session *auth.Session,
spaceStore store.SpaceStore, repoStore store.RepoStore, parentType enum.ParentResourceType, parentID int64,
resourceType enum.ResourceType, resourceName string, permission enum.Permission) error {

View File

@ -16,14 +16,13 @@ import (
"github.com/pkg/errors"
)
/*
* CheckRepo checks if a repo specific permission is granted for the current auth session
* in the scope of its parent.
* Returns nil if the permission is granted, otherwise returns an error.
* NotAuthenticated, NotAuthorized, or any unerlaying error.
*/
// CheckRepo checks if a repo specific permission is granted for the current auth session
// in the scope of its parent.
// Returns nil if the permission is granted, otherwise returns an error.
// NotAuthenticated, NotAuthorized, or any underlying error.
func CheckRepo(ctx context.Context, authorizer authz.Authorizer, session *auth.Session,
repo *types.Repository, permission enum.Permission, orPublic bool) error {
repo *types.Repository, permission enum.Permission, orPublic bool,
) error {
if orPublic && repo.IsPublic {
return nil
}

View File

@ -13,14 +13,13 @@ import (
"github.com/harness/gitness/types/enum"
)
/*
* CheckService checks if a service specific permission is granted for the current auth session.
* Returns nil if the permission is granted, otherwise returns an error.
* NotAuthenticated, NotAuthorized, or any unerlaying error.
*/
// CheckService checks if a service specific permission is granted for the current auth session.
// Returns nil if the permission is granted, otherwise returns an error.
// NotAuthenticated, NotAuthorized, or any underlying error.
func CheckService(ctx context.Context, authorizer authz.Authorizer, session *auth.Session,
svc *types.Service, permission enum.Permission) error {
// a service exists outside of any scope
svc *types.Service, permission enum.Permission,
) error {
// a service exists outside any scope
scope := &types.Scope{}
resource := &types.Resource{
Type: enum.ResourceTypeService,

View File

@ -13,15 +13,15 @@ import (
"github.com/harness/gitness/types/enum"
)
/*
* CheckServiceAccount checks if a service account specific permission is granted for the current auth session
* in the scope of the parent.
* Returns nil if the permission is granted, otherwise returns an error.
* NotAuthenticated, NotAuthorized, or any unerlaying error.
*/
// CheckServiceAccount checks if a service account specific permission is granted for the current auth session
// in the scope of the parent.
// Returns nil if the permission is granted, otherwise returns an error.
// NotAuthenticated, NotAuthorized, or any underlying error.
func CheckServiceAccount(ctx context.Context, authorizer authz.Authorizer, session *auth.Session,
spaceStore store.SpaceStore, repoStore store.RepoStore, parentType enum.ParentResourceType, parentID int64,
saUID string, permission enum.Permission) error {
return CheckChild(ctx, authorizer, session, spaceStore, repoStore, parentType, parentID,
saUID string, permission enum.Permission,
) error {
return CheckChild(ctx, authorizer, session,
spaceStore, repoStore, parentType, parentID,
enum.ResourceTypeServiceAccount, saUID, permission)
}

View File

@ -16,14 +16,13 @@ import (
"github.com/pkg/errors"
)
/*
* CheckSpace checks if a space specific permission is granted for the current auth session
* in the scope of its parent.
* Returns nil if the permission is granted, otherwise returns an error.
* NotAuthenticated, NotAuthorized, or any unerlaying error.
*/
// CheckSpace checks if a space specific permission is granted for the current auth session
// in the scope of its parent.
// Returns nil if the permission is granted, otherwise returns an error.
// NotAuthenticated, NotAuthorized, or any underlying error.
func CheckSpace(ctx context.Context, authorizer authz.Authorizer, session *auth.Session,
space *types.Space, permission enum.Permission, orPublic bool) error {
space *types.Space, permission enum.Permission, orPublic bool,
) error {
if orPublic && space.IsPublic {
return nil
}

View File

@ -13,14 +13,13 @@ import (
"github.com/harness/gitness/types/enum"
)
/*
* CheckUser checks if a user specific permission is granted for the current auth session.
* Returns nil if the permission is granted, otherwise returns an error.
* NotAuthenticated, NotAuthorized, or any unerlaying error.
*/
// CheckUser checks if a user specific permission is granted for the current auth session.
// Returns nil if the permission is granted, otherwise returns an error.
// NotAuthenticated, NotAuthorized, or any underlying error.
func CheckUser(ctx context.Context, authorizer authz.Authorizer, session *auth.Session,
user *types.User, permission enum.Permission) error {
// a user exists outside of any scope
user *types.User, permission enum.Permission,
) error {
// a user exists outside any scope
scope := &types.Scope{}
resource := &types.Resource{
Type: enum.ResourceTypeUser,

View File

@ -83,7 +83,7 @@ func (c *Controller) MembershipAdd(ctx context.Context,
Role: in.Role,
Principal: *user.ToPrincipalInfo(),
AdddedBy: *session.Principal.ToPrincipalInfo(),
AddedBy: *session.Principal.ToPrincipalInfo(),
}
err = c.membershipStore.Create(ctx, membership)

View File

@ -213,7 +213,7 @@ func (s *MembershipStore) mapToMembership(ctx context.Context, m *membership) *t
log.Ctx(ctx).Error().Err(err).Msg("failed to load membership creator")
}
if addedBy != nil {
res.AdddedBy = *addedBy
res.AddedBy = *addedBy
}
principal, err := s.pCache.Get(ctx, res.PrincipalID)
@ -245,7 +245,7 @@ func (s *MembershipStore) mapToMemberships(ctx context.Context, ms []*membership
for i, m := range ms {
res[i] = mapToMembershipNoPrincipalInfo(m)
if addedBy, ok := infoMap[m.CreatedBy]; ok {
res[i].AdddedBy = *addedBy
res[i].AddedBy = *addedBy
}
if principal, ok := infoMap[m.PrincipalID]; ok {
res[i].Principal = *principal

View File

@ -26,5 +26,5 @@ type Membership struct {
Role enum.MembershipRole `json:"role"`
Principal PrincipalInfo `json:"principal"`
AdddedBy PrincipalInfo `json:"added_by"`
AddedBy PrincipalInfo `json:"added_by"`
}