mirror of
https://github.com/harness/drone.git
synced 2025-05-07 23:01:10 +08:00
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 argument
This commit is contained in:
parent
bc125029ff
commit
a5f510c4b2
@ -47,7 +47,7 @@ func (c *Controller) CreateRepo(
|
|||||||
session *auth.Session,
|
session *auth.Session,
|
||||||
in *CreateRepoInput,
|
in *CreateRepoInput,
|
||||||
) (*repoCtrl.RepositoryOutput, error) {
|
) (*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)
|
return nil, fmt.Errorf("failed to sanitize input: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -193,12 +193,12 @@ func (c *Controller) spaceCheckAuth(
|
|||||||
return space, nil
|
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 {
|
if err := repoCtrl.ValidateParentRef(in.ParentRef); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := c.identifierCheck(in.Identifier); err != nil {
|
if err := c.identifierCheck(in.Identifier, session); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ type CreateInput struct {
|
|||||||
//
|
//
|
||||||
//nolint:gocognit
|
//nolint:gocognit
|
||||||
func (c *Controller) Create(ctx context.Context, session *auth.Session, in *CreateInput) (*RepositoryOutput, error) {
|
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)
|
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
|
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.
|
// TODO [CODE-1363]: remove after identifier migration.
|
||||||
if in.Identifier == "" {
|
if in.Identifier == "" {
|
||||||
in.Identifier = in.UID
|
in.Identifier = in.UID
|
||||||
@ -199,7 +199,7 @@ func (c *Controller) sanitizeCreateInput(in *CreateInput) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := c.identifierCheck(in.Identifier); err != nil {
|
if err := c.identifierCheck(in.Identifier, session); err != nil {
|
||||||
return err
|
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.
|
// 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) {
|
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)
|
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
|
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.
|
// TODO [CODE-1363]: remove after identifier migration.
|
||||||
if in.Identifier == "" {
|
if in.Identifier == "" {
|
||||||
in.Identifier = in.UID
|
in.Identifier = in.UID
|
||||||
@ -141,7 +141,7 @@ func (c *Controller) sanitizeImportInput(in *ImportInput) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := c.identifierCheck(in.Identifier); err != nil {
|
if err := c.identifierCheck(in.Identifier, session); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ func (c *Controller) Move(ctx context.Context,
|
|||||||
repoRef string,
|
repoRef string,
|
||||||
in *MoveInput,
|
in *MoveInput,
|
||||||
) (*RepositoryOutput, error) {
|
) (*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)
|
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)
|
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.
|
// TODO [CODE-1363]: remove after identifier migration.
|
||||||
if in.Identifier == nil {
|
if in.Identifier == nil {
|
||||||
in.Identifier = in.UID
|
in.Identifier = in.UID
|
||||||
}
|
}
|
||||||
|
|
||||||
if in.Identifier != nil {
|
if in.Identifier != nil {
|
||||||
if err := c.identifierCheck(*in.Identifier); err != nil {
|
if err := c.identifierCheck(*in.Identifier, session); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ import (
|
|||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/harness/gitness/app/auth"
|
||||||
"github.com/harness/gitness/types"
|
"github.com/harness/gitness/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -129,10 +130,10 @@ func Identifier(identifier string) error {
|
|||||||
return nil
|
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.
|
// 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 {
|
if err := Identifier(identifier); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user