mirror of https://github.com/harness/drone.git
feat: [PIPE-23710]: changed signature of RepoIdentifier to start taking session argument (#3345) (#3425)
* feat: [PIPE-23710]: changed signature of RepoIdentifier to start taking session argument (#3345) * argument changed to session * fixed failing go lint check * updated method usage * corrected spelling mistake * feat: [PIPE-23710]: changed signature of RepoIdentifier to start taking internal boolean argumentpull/3617/head
parent
5018aacfb7
commit
8b81b19c3d
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -198,12 +198,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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -135,14 +135,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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue