diff --git a/internal/api/auth/auth.go b/internal/api/auth/auth.go index d19e8dce1..499164c04 100644 --- a/internal/api/auth/auth.go +++ b/internal/api/auth/auth.go @@ -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 { diff --git a/internal/api/auth/repo.go b/internal/api/auth/repo.go index ddf0a8b8d..67b8c454b 100644 --- a/internal/api/auth/repo.go +++ b/internal/api/auth/repo.go @@ -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 } diff --git a/internal/api/auth/service.go b/internal/api/auth/service.go index 03673bcc3..acc21fc24 100644 --- a/internal/api/auth/service.go +++ b/internal/api/auth/service.go @@ -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, diff --git a/internal/api/auth/serviceAccount.go b/internal/api/auth/service_account.go similarity index 66% rename from internal/api/auth/serviceAccount.go rename to internal/api/auth/service_account.go index 7a9c65a3b..332e79bc2 100644 --- a/internal/api/auth/serviceAccount.go +++ b/internal/api/auth/service_account.go @@ -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) } diff --git a/internal/api/auth/space.go b/internal/api/auth/space.go index 78e46bded..68c28ebe3 100644 --- a/internal/api/auth/space.go +++ b/internal/api/auth/space.go @@ -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 } diff --git a/internal/api/auth/user.go b/internal/api/auth/user.go index c0f766d51..d795eb5e3 100644 --- a/internal/api/auth/user.go +++ b/internal/api/auth/user.go @@ -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, diff --git a/internal/api/controller/space/membership_add.go b/internal/api/controller/space/membership_add.go index b3a8601c6..8538c1013 100644 --- a/internal/api/controller/space/membership_add.go +++ b/internal/api/controller/space/membership_add.go @@ -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) diff --git a/internal/store/database/membership.go b/internal/store/database/membership.go index a91c83f74..26c750b7b 100644 --- a/internal/store/database/membership.go +++ b/internal/store/database/membership.go @@ -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 diff --git a/types/membership.go b/types/membership.go index 6520ff378..350572ed5 100644 --- a/types/membership.go +++ b/types/membership.go @@ -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"` }