diff --git a/app/api/controller/migrate/create_repo.go b/app/api/controller/migrate/create_repo.go index 059b4b471..32ce990e6 100644 --- a/app/api/controller/migrate/create_repo.go +++ b/app/api/controller/migrate/create_repo.go @@ -47,7 +47,7 @@ func (c *Controller) CreateRepo( session *auth.Session, in *CreateRepoInput, ) (*repoCtrl.RepositoryOutput, error) { - if err := c.sanitizeCreateRepoInput(in); err != nil { + if err := c.sanitizeCreateRepoInput(in, session); err != nil { return nil, fmt.Errorf("failed to sanitize input: %w", err) } @@ -193,12 +193,12 @@ func (c *Controller) spaceCheckAuth( return space, nil } -func (c *Controller) sanitizeCreateRepoInput(in *CreateRepoInput) error { +func (c *Controller) sanitizeCreateRepoInput(in *CreateRepoInput, session *auth.Session) error { if err := repoCtrl.ValidateParentRef(in.ParentRef); err != nil { return err } - if err := c.identifierCheck(in.Identifier); err != nil { + if err := c.identifierCheck(in.Identifier, session); err != nil { return err } diff --git a/app/api/controller/repo/create.go b/app/api/controller/repo/create.go index 11590f039..9b7fc450f 100644 --- a/app/api/controller/repo/create.go +++ b/app/api/controller/repo/create.go @@ -63,7 +63,7 @@ type CreateInput struct { // //nolint:gocognit func (c *Controller) Create(ctx context.Context, session *auth.Session, in *CreateInput) (*RepositoryOutput, error) { - if err := c.sanitizeCreateInput(in); err != nil { + if err := c.sanitizeCreateInput(in, session); err != nil { return nil, fmt.Errorf("failed to sanitize input: %w", err) } @@ -189,7 +189,7 @@ func (c *Controller) Create(ctx context.Context, session *auth.Session, in *Crea return repoOutput, nil } -func (c *Controller) sanitizeCreateInput(in *CreateInput) error { +func (c *Controller) sanitizeCreateInput(in *CreateInput, session *auth.Session) error { // TODO [CODE-1363]: remove after identifier migration. if in.Identifier == "" { in.Identifier = in.UID @@ -199,7 +199,7 @@ func (c *Controller) sanitizeCreateInput(in *CreateInput) error { return err } - if err := c.identifierCheck(in.Identifier); err != nil { + if err := c.identifierCheck(in.Identifier, session); err != nil { return err } diff --git a/app/api/controller/repo/import.go b/app/api/controller/repo/import.go index 4fe459025..2dc0162f6 100644 --- a/app/api/controller/repo/import.go +++ b/app/api/controller/repo/import.go @@ -43,7 +43,7 @@ type ImportInput struct { // Import creates a new empty repository and starts git import to it from a remote repository. func (c *Controller) Import(ctx context.Context, session *auth.Session, in *ImportInput) (*RepositoryOutput, error) { - if err := c.sanitizeImportInput(in); err != nil { + if err := c.sanitizeImportInput(in, session); err != nil { return nil, fmt.Errorf("failed to sanitize input: %w", err) } @@ -131,7 +131,7 @@ func (c *Controller) Import(ctx context.Context, session *auth.Session, in *Impo return GetRepoOutputWithAccess(ctx, false, repo), nil } -func (c *Controller) sanitizeImportInput(in *ImportInput) error { +func (c *Controller) sanitizeImportInput(in *ImportInput, session *auth.Session) error { // TODO [CODE-1363]: remove after identifier migration. if in.Identifier == "" { in.Identifier = in.UID @@ -141,7 +141,7 @@ func (c *Controller) sanitizeImportInput(in *ImportInput) error { return err } - if err := c.identifierCheck(in.Identifier); err != nil { + if err := c.identifierCheck(in.Identifier, session); err != nil { return err } diff --git a/app/api/controller/repo/move.go b/app/api/controller/repo/move.go index 39d65084c..163265eaf 100644 --- a/app/api/controller/repo/move.go +++ b/app/api/controller/repo/move.go @@ -47,7 +47,7 @@ func (c *Controller) Move(ctx context.Context, repoRef string, in *MoveInput, ) (*RepositoryOutput, error) { - if err := c.sanitizeMoveInput(in); err != nil { + if err := c.sanitizeMoveInput(in, session); err != nil { return nil, fmt.Errorf("failed to sanitize input: %w", err) } @@ -126,14 +126,14 @@ func (c *Controller) Move(ctx context.Context, return GetRepoOutput(ctx, c.publicAccess, repo) } -func (c *Controller) sanitizeMoveInput(in *MoveInput) error { +func (c *Controller) sanitizeMoveInput(in *MoveInput, session *auth.Session) error { // TODO [CODE-1363]: remove after identifier migration. if in.Identifier == nil { in.Identifier = in.UID } if in.Identifier != nil { - if err := c.identifierCheck(*in.Identifier); err != nil { + if err := c.identifierCheck(*in.Identifier, session); err != nil { return err } } diff --git a/types/check/common.go b/types/check/common.go index b7f3bee08..2913db61a 100644 --- a/types/check/common.go +++ b/types/check/common.go @@ -19,6 +19,7 @@ import ( "regexp" "strings" + "github.com/harness/gitness/app/auth" "github.com/harness/gitness/types" ) @@ -129,10 +130,10 @@ func Identifier(identifier string) error { return nil } -type RepoIdentifier func(identifier string) error +type RepoIdentifier func(identifier string, session *auth.Session) error // RepoIdentifierDefault performs the default Identifier check and also blocks illegal repo identifiers. -func RepoIdentifierDefault(identifier string) error { +func RepoIdentifierDefault(identifier string, _ *auth.Session) error { if err := Identifier(identifier); err != nil { return err }