Skip to content

Commit

Permalink
Rename groups to projects in comments and logs (#1823)
Browse files Browse the repository at this point in the history
  • Loading branch information
eleftherias authored Dec 5, 2023
1 parent 422a42a commit b95e993
Show file tree
Hide file tree
Showing 19 changed files with 100 additions and 100 deletions.
8 changes: 4 additions & 4 deletions internal/auth/jwtauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,23 +143,23 @@ func WithPermissionsContext(ctx context.Context, claims UserPermissions) context
return context.WithValue(ctx, tokenContextKey, claims)
}

// GetDefaultProject returns the default group id for the user
// GetDefaultProject returns the default project id for the user
func GetDefaultProject(ctx context.Context) (uuid.UUID, error) {
permissions := GetPermissionsFromContext(ctx)
if len(permissions.ProjectIds) != 1 {
return uuid.UUID{}, errors.New("cannot get default group")
return uuid.UUID{}, errors.New("cannot get default project")
}
return permissions.ProjectIds[0], nil
}

// IsAuthorizedForProject returns true if the user is authorized for the given group
// IsAuthorizedForProject returns true if the user is authorized for the given project
func IsAuthorizedForProject(ctx context.Context, projectID uuid.UUID) bool {
permissions := GetPermissionsFromContext(ctx)

return slices.Contains(permissions.ProjectIds, projectID)
}

// GetUserProjects returns all the groups where an user belongs to
// GetUserProjects returns all the projects where a user belongs to
func GetUserProjects(ctx context.Context) ([]uuid.UUID, error) {
permissions := GetPermissionsFromContext(ctx)
return permissions.ProjectIds, nil
Expand Down
2 changes: 1 addition & 1 deletion internal/controlplane/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func providerError(err error) error {
}

func getProjectFromRequestOrDefault(ctx context.Context, in ProjectIDGetter) (uuid.UUID, error) {
// if we do not have a group, check if we can infer it
// if we do not have a project ID, check if we can infer it
if in.GetProjectId() == "" {
proj, err := auth.GetDefaultProject(ctx)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/controlplane/handlers_artifacts.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
pb "github.com/stacklok/minder/pkg/api/protobuf/go/minder/v1"
)

// ListArtifacts lists all artifacts for a given group and provider
// ListArtifacts lists all artifacts for a given project and provider
// nolint:gocyclo
func (s *Server) ListArtifacts(ctx context.Context, in *pb.ListArtifactsRequest) (*pb.ListArtifactsResponse, error) {
projectID, err := getProjectFromRequestOrDefault(ctx, in)
Expand All @@ -52,7 +52,7 @@ func (s *Server) ListArtifacts(ctx context.Context, in *pb.ListArtifactsRequest)
return nil, providerError(err)
}

// first read all the repositories for provider and group
// first read all the repositories for provider and project
repositories, err := s.store.ListRegisteredRepositoriesByProjectIDAndProvider(ctx,
db.ListRegisteredRepositoriesByProjectIDAndProviderParams{Provider: provider.Name, ProjectID: projectID})
if err != nil {
Expand Down
16 changes: 8 additions & 8 deletions internal/controlplane/handlers_authz.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ func lookupUserPermissions(ctx context.Context, store db.Store, tok openid.Token
return emptyPermissions, fmt.Errorf("failed to read user")
}

// read groups and add id to claims
// read projects and add id to claims
gs, err := store.GetUserProjects(ctx, userInfo.ID)
if err != nil {
return emptyPermissions, fmt.Errorf("failed to get groups")
return emptyPermissions, fmt.Errorf("failed to get projects")
}
var groups []uuid.UUID
var projects []uuid.UUID
for _, g := range gs {
groups = append(groups, g.ID)
projects = append(projects, g.ID)
}

// read roles and add details to claims
Expand All @@ -112,7 +112,7 @@ func lookupUserPermissions(ctx context.Context, store db.Store, tok openid.Token
claims := auth.UserPermissions{
UserId: userInfo.ID,
Roles: roles,
ProjectIds: groups,
ProjectIds: projects,
OrganizationId: userInfo.OrganizationID,
IsStaff: containsSuperadminRole(tok),
}
Expand All @@ -121,15 +121,15 @@ func lookupUserPermissions(ctx context.Context, store db.Store, tok openid.Token
}

// AuthorizedOnProject checks if the request is authorized for the given
// group, and returns an error if the request is not authorized.
// project, and returns an error if the request is not authorized.
func AuthorizedOnProject(ctx context.Context, projectID uuid.UUID) error {
claims := auth.GetPermissionsFromContext(ctx)
if isSuperadmin(claims) {
return nil
}
opts := getRpcOptions(ctx)
if opts.GetAuthScope() != minder.ObjectOwner_OBJECT_OWNER_PROJECT {
return status.Errorf(codes.Internal, "Called IsProjectAuthorized on non-group method, should be %v", opts.GetAuthScope())
return status.Errorf(codes.Internal, "Called IsProjectAuthorized on non-project method, should be %v", opts.GetAuthScope())
}

if !slices.Contains(claims.ProjectIds, projectID) {
Expand All @@ -141,7 +141,7 @@ func AuthorizedOnProject(ctx context.Context, projectID uuid.UUID) error {
}
return *role.ProjectID == projectID && role.IsAdmin
}
// check if is admin of group
// check if is admin of project
if opts.GetOwnerOnly() && !slices.ContainsFunc(claims.Roles, isOwner) {
return util.UserVisibleError(codes.PermissionDenied, "user is not an administrator on this project")
}
Expand Down
4 changes: 2 additions & 2 deletions internal/controlplane/handlers_githubwebhooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,7 @@ func getRepoInformationFromPayload(
return db.Repository{}, fmt.Errorf("error parsing repository ID: %w", err)
}

// At this point, we're unsure what the group ID is, so we need to look it up.
// At this point, we're unsure what the project ID is, so we need to look it up.
// It's the same case for the provider. We can gather this information from the
// repository ID.
dbrepo, err := store.GetRepositoryByRepoID(ctx, id)
Expand All @@ -1012,7 +1012,7 @@ func getRepoInformationFromPayload(
}

if dbrepo.ProjectID.String() == "" {
return db.Repository{}, fmt.Errorf("no group found for repository %s/%s: %w",
return db.Repository{}, fmt.Errorf("no project found for repository %s/%s: %w",
dbrepo.RepoOwner, dbrepo.RepoName, errRepoNotFound)
}

Expand Down
8 changes: 4 additions & 4 deletions internal/controlplane/handlers_oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (s *Server) GetAuthorizationURL(ctx context.Context,
Valid: true,
}

// Delete any existing session state for the group
// Delete any existing session state for the project
err = s.store.DeleteSessionStateByProjectID(ctx, db.DeleteSessionStateByProjectIDParams{
Provider: provider.Name,
ProjectID: projectID})
Expand All @@ -100,7 +100,7 @@ func (s *Server) GetAuthorizationURL(ctx context.Context,
owner = sql.NullString{Valid: true, String: *req.Owner}
}

// Insert the new session state into the database along with the user's group ID
// Insert the new session state into the database along with the user's project ID
// retrieved from the JWT token
_, err = s.store.CreateSessionState(ctx, db.CreateSessionStateParams{
Provider: provider.Name,
Expand Down Expand Up @@ -149,7 +149,7 @@ func (s *Server) ExchangeCodeForTokenCLI(ctx context.Context,
// get projectID from session along with state nonce from the database
stateData, err := s.store.GetProjectIDPortBySessionState(ctx, in.State)
if err != nil {
return nil, status.Errorf(codes.Unknown, "error getting group ID by session state: %s", err)
return nil, status.Errorf(codes.Unknown, "error getting project ID by session state: %s", err)
}

// get provider
Expand Down Expand Up @@ -281,7 +281,7 @@ func (s *Server) getProviderAccessToken(ctx context.Context, provider string,
return decryptedToken, encToken.OwnerFilter.String, nil
}

// StoreProviderToken stores the provider token for a group
// StoreProviderToken stores the provider token for a project
func (s *Server) StoreProviderToken(ctx context.Context,
in *pb.StoreProviderTokenRequest) (*pb.StoreProviderTokenResponse, error) {
projectID, err := getProjectFromRequestOrDefault(ctx, in)
Expand Down
32 changes: 16 additions & 16 deletions internal/controlplane/handlers_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ func (s *Server) authAndContextValidation(ctx context.Context, inout *minderv1.C
return engine.WithEntityContext(ctx, entityCtx), nil
}

// ensureDefaultProjectForContext ensures a valid group is set in the context or sets the default group
// if the group is not set in the incoming entity context, it'll set it.
// ensureDefaultProjectForContext ensures a valid project is set in the context or sets the default project
// if the project is not set in the incoming entity context, it'll set it.
func (s *Server) ensureDefaultProjectForContext(ctx context.Context, inout *minderv1.Context) error {
// Project is already set
if inout.GetProject() != "" {
Expand All @@ -78,19 +78,19 @@ func (s *Server) ensureDefaultProjectForContext(ctx context.Context, inout *mind

gid, err := auth.GetDefaultProject(ctx)
if err != nil {
return status.Errorf(codes.InvalidArgument, "cannot infer group id")
return status.Errorf(codes.InvalidArgument, "cannot infer project id")
}

g, err := s.store.GetProjectByID(ctx, gid)
if err != nil {
return status.Errorf(codes.InvalidArgument, "cannot infer group id")
return status.Errorf(codes.InvalidArgument, "cannot infer project id")
}

inout.Project = &g.Name
return nil
}

// verifyValidProject verifies that the group is valid and the user is authorized to access it
// verifyValidProject verifies that the project is valid and the user is authorized to access it
// TODO: This will have to change once we have the hierarchy tree in place.
func verifyValidProject(ctx context.Context, in *engine.EntityContext) error {
if !auth.IsAuthorizedForProject(ctx, in.GetProject().GetID()) {
Expand All @@ -116,14 +116,14 @@ func validateActionType(r string) db.NullActionType {
return db.NullActionType{Valid: false}
}

// CreateProfile creates a profile for a group
// CreateProfile creates a profile for a project
func (s *Server) CreateProfile(ctx context.Context,
cpr *minderv1.CreateProfileRequest) (*minderv1.CreateProfileResponse, error) {
in := cpr.GetProfile()

ctx, err := s.authAndContextValidation(ctx, in.GetContext())
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "error ensuring default group: %v", err)
return nil, status.Errorf(codes.InvalidArgument, "error ensuring default project: %v", err)
}

entityCtx := engine.EntityFromContext(ctx)
Expand Down Expand Up @@ -273,7 +273,7 @@ func (s *Server) DeleteProfile(ctx context.Context,
in *minderv1.DeleteProfileRequest) (*minderv1.DeleteProfileResponse, error) {
_, err := s.authAndContextValidation(ctx, in.GetContext())
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "error ensuring default group: %v", err)
return nil, status.Errorf(codes.InvalidArgument, "error ensuring default project: %v", err)
}

parsedProfileID, err := uuid.Parse(in.Id)
Expand All @@ -297,12 +297,12 @@ func (s *Server) DeleteProfile(ctx context.Context,
return &minderv1.DeleteProfileResponse{}, nil
}

// ListProfiles is a method to get all profiles for a group
// ListProfiles is a method to get all profiles for a project
func (s *Server) ListProfiles(ctx context.Context,
in *minderv1.ListProfilesRequest) (*minderv1.ListProfilesResponse, error) {
ctx, err := s.authAndContextValidation(ctx, in.GetContext())
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "error ensuring default group: %v", err)
return nil, status.Errorf(codes.InvalidArgument, "error ensuring default project: %v", err)
}

entityCtx := engine.EntityFromContext(ctx)
Expand All @@ -326,7 +326,7 @@ func (s *Server) GetProfileById(ctx context.Context,
in *minderv1.GetProfileByIdRequest) (*minderv1.GetProfileByIdResponse, error) {
ctx, err := s.authAndContextValidation(ctx, in.GetContext())
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "error ensuring default group: %v", err)
return nil, status.Errorf(codes.InvalidArgument, "error ensuring default project: %v", err)
}

entityCtx := engine.EntityFromContext(ctx)
Expand Down Expand Up @@ -422,7 +422,7 @@ func (s *Server) GetProfileStatusByName(ctx context.Context,
in *minderv1.GetProfileStatusByNameRequest) (*minderv1.GetProfileStatusByNameResponse, error) {
ctx, err := s.authAndContextValidation(ctx, in.GetContext())
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "error ensuring default group: %v", err)
return nil, status.Errorf(codes.InvalidArgument, "error ensuring default project: %v", err)
}

entityCtx := engine.EntityFromContext(ctx)
Expand Down Expand Up @@ -533,12 +533,12 @@ func (s *Server) GetProfileStatusByName(ctx context.Context,
}, nil
}

// GetProfileStatusByProject is a method to get profile status for a group
// GetProfileStatusByProject is a method to get profile status for a project
func (s *Server) GetProfileStatusByProject(ctx context.Context,
in *minderv1.GetProfileStatusByProjectRequest) (*minderv1.GetProfileStatusByProjectResponse, error) {
ctx, err := s.authAndContextValidation(ctx, in.GetContext())
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "error ensuring default group: %v", err)
return nil, status.Errorf(codes.InvalidArgument, "error ensuring default project: %v", err)
}

entityCtx := engine.EntityFromContext(ctx)
Expand All @@ -547,7 +547,7 @@ func (s *Server) GetProfileStatusByProject(ctx context.Context,
dbstats, err := s.store.GetProfileStatusByProject(ctx, entityCtx.Project.ID)
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
return nil, status.Errorf(codes.NotFound, "profile statuses not found for group")
return nil, status.Errorf(codes.NotFound, "profile statuses not found for project")
}
return nil, status.Errorf(codes.Unknown, "failed to get profile status: %s", err)
}
Expand Down Expand Up @@ -576,7 +576,7 @@ func (s *Server) UpdateProfile(ctx context.Context,

ctx, err := s.authAndContextValidation(ctx, in.GetContext())
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "error ensuring default group: %v", err)
return nil, status.Errorf(codes.InvalidArgument, "error ensuring default project: %v", err)
}

entityCtx := engine.EntityFromContext(ctx)
Expand Down
8 changes: 4 additions & 4 deletions internal/controlplane/handlers_repositories.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (
)

// RegisterRepository adds repositories to the database and registers a webhook
// Once a user had enrolled in a group (they have a valid token), they can register
// Once a user had enrolled in a project (they have a valid token), they can register
// repositories to be monitored by the minder by provisioning a webhook on the
// repositor(ies).
func (s *Server) RegisterRepository(ctx context.Context,
Expand Down Expand Up @@ -139,10 +139,10 @@ func (s *Server) RegisterRepository(ctx context.Context,
return response, nil
}

// ListRepositories returns a list of repositories for a given group
// ListRepositories returns a list of repositories for a given project
// This function will typically be called by the client to get a list of
// repositories that are registered present in the minder database
// The API is called with a group id, limit and offset
// The API is called with a project id, limit and offset
func (s *Server) ListRepositories(ctx context.Context,
in *pb.ListRepositoriesRequest) (*pb.ListRepositoriesResponse, error) {
projectID, err := getProjectFromRequestOrDefault(ctx, in)
Expand Down Expand Up @@ -251,7 +251,7 @@ func (s *Server) GetRepositoryById(ctx context.Context,
// GetRepositoryByName returns information about a repository.
// This function will typically be called by the client to get a
// repository which is already registered and present in the minder database
// The API is called with a group id
// The API is called with a project id
func (s *Server) GetRepositoryByName(ctx context.Context,
in *pb.GetRepositoryByNameRequest) (*pb.GetRepositoryByNameResponse, error) {
// split repo name in owner and name
Expand Down
12 changes: 6 additions & 6 deletions internal/controlplane/handlers_ruletype.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (s *Server) ListRuleTypes(
) (*minderv1.ListRuleTypesResponse, error) {
ctx, err := s.authAndContextValidation(ctx, in.GetContext())
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "error ensuring default group: %v", err)
return nil, status.Errorf(codes.InvalidArgument, "error ensuring default project: %v", err)
}

entityCtx := engine.EntityFromContext(ctx)
Expand Down Expand Up @@ -74,7 +74,7 @@ func (s *Server) GetRuleTypeByName(
) (*minderv1.GetRuleTypeByNameResponse, error) {
ctx, err := s.authAndContextValidation(ctx, in.GetContext())
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "error ensuring default group: %v", err)
return nil, status.Errorf(codes.InvalidArgument, "error ensuring default project: %v", err)
}

entityCtx := engine.EntityFromContext(ctx)
Expand Down Expand Up @@ -107,7 +107,7 @@ func (s *Server) GetRuleTypeById(
) (*minderv1.GetRuleTypeByIdResponse, error) {
ctx, err := s.authAndContextValidation(ctx, in.GetContext())
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "error ensuring default group: %v", err)
return nil, status.Errorf(codes.InvalidArgument, "error ensuring default project: %v", err)
}

entityCtx := engine.EntityFromContext(ctx)
Expand Down Expand Up @@ -143,7 +143,7 @@ func (s *Server) CreateRuleType(

ctx, err := s.authAndContextValidation(ctx, in.GetContext())
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "error ensuring default group: %v", err)
return nil, status.Errorf(codes.InvalidArgument, "error ensuring default project: %v", err)
}

entityCtx := engine.EntityFromContext(ctx)
Expand Down Expand Up @@ -201,7 +201,7 @@ func (s *Server) UpdateRuleType(

ctx, err := s.authAndContextValidation(ctx, in.GetContext())
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "error ensuring default group: %v", err)
return nil, status.Errorf(codes.InvalidArgument, "error ensuring default project: %v", err)
}

entityCtx := engine.EntityFromContext(ctx)
Expand Down Expand Up @@ -304,7 +304,7 @@ func (s *Server) DeleteRuleType(

ctx, err = s.authAndContextValidation(ctx, in.GetContext())
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "error ensuring default group: %v", err)
return nil, status.Errorf(codes.InvalidArgument, "error ensuring default project: %v", err)
}

profileInfo, err := s.store.ListProfilesInstantiatingRuleType(ctx, ruletype.ID)
Expand Down
6 changes: 3 additions & 3 deletions internal/db/entity_execution_lock.sql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ func TestQueries_LockIfThresholdNotExceeded(t *testing.T) {
t.Parallel()

org := createRandomOrganization(t)
group := createRandomProject(t, org.ID)
prov := createRandomProvider(t, group.ID)
repo := createRandomRepository(t, group.ID, prov.Name)
project := createRandomProject(t, org.ID)
prov := createRandomProvider(t, project.ID)
repo := createRandomRepository(t, project.ID, prov.Name)

threshold := 1
concurrentCalls := 10
Expand Down
Loading

0 comments on commit b95e993

Please sign in to comment.