mirror of
https://github.com/harness/drone.git
synced 2025-05-04 20:41:06 +08:00
feat: [PIPE-24894]: Restrict lifecycle operations for reserved repo identifiers (#3426)
* feat: [PIPE-24894]: Restrict lifecycle operations for reserved repo identifiers
This commit is contained in:
parent
13f6558ca3
commit
f85b6c45c3
@ -36,6 +36,10 @@ func (c *Controller) Archive(
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err = c.repoCheck.LifecycleRestriction(ctx, session, repo); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return c.git.Archive(ctx, git.ArchiveParams{
|
return c.git.Archive(ctx, git.ArchiveParams{
|
||||||
ReadParams: git.CreateReadParams(repo),
|
ReadParams: git.CreateReadParams(repo),
|
||||||
ArchiveParams: params,
|
ArchiveParams: params,
|
||||||
|
@ -18,10 +18,12 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/harness/gitness/app/auth"
|
"github.com/harness/gitness/app/auth"
|
||||||
|
"github.com/harness/gitness/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Check defines the interface for adding extra checks during repository operations.
|
// Check defines the interface for adding extra checks during repository operations.
|
||||||
type Check interface {
|
type Check interface {
|
||||||
// Create allows adding extra check during create repo operations
|
// Create allows adding extra check during create repo operations
|
||||||
Create(ctx context.Context, session *auth.Session, in *CreateInput) error
|
Create(ctx context.Context, session *auth.Session, in *CreateInput) error
|
||||||
|
LifecycleRestriction(ctx context.Context, session *auth.Session, repo *types.RepositoryCore) error
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/harness/gitness/app/auth"
|
"github.com/harness/gitness/app/auth"
|
||||||
|
"github.com/harness/gitness/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ Check = (*NoOpRepoChecks)(nil)
|
var _ Check = (*NoOpRepoChecks)(nil)
|
||||||
@ -32,3 +33,7 @@ func NewNoOpRepoChecks() *NoOpRepoChecks {
|
|||||||
func (c *NoOpRepoChecks) Create(_ context.Context, _ *auth.Session, _ *CreateInput) error {
|
func (c *NoOpRepoChecks) Create(_ context.Context, _ *auth.Session, _ *CreateInput) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *NoOpRepoChecks) LifecycleRestriction(_ context.Context, _ *auth.Session, _ *types.RepositoryCore) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@ -46,6 +46,10 @@ func (c *Controller) Purge(
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err = c.repoCheck.LifecycleRestriction(ctx, session, repo.Core()); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
log.Ctx(ctx).Info().
|
log.Ctx(ctx).Info().
|
||||||
Int64("repo.id", repo.ID).
|
Int64("repo.id", repo.ID).
|
||||||
Str("repo.path", repo.Path).
|
Str("repo.path", repo.Path).
|
||||||
|
@ -50,6 +50,10 @@ func (c *Controller) Restore(
|
|||||||
return nil, fmt.Errorf("access check failed: %w", err)
|
return nil, fmt.Errorf("access check failed: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err = c.repoCheck.LifecycleRestriction(ctx, session, repo.Core()); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
if repo.Deleted == nil {
|
if repo.Deleted == nil {
|
||||||
return nil, usererror.BadRequest("cannot restore a repo that hasn't been deleted")
|
return nil, usererror.BadRequest("cannot restore a repo that hasn't been deleted")
|
||||||
}
|
}
|
||||||
|
@ -50,6 +50,10 @@ func (c *Controller) SoftDelete(
|
|||||||
return nil, fmt.Errorf("access check failed: %w", err)
|
return nil, fmt.Errorf("access check failed: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err = c.repoCheck.LifecycleRestriction(ctx, session, repoCore); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
repo, err := c.repoStore.Find(ctx, repoCore.ID)
|
repo, err := c.repoStore.Find(ctx, repoCore.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to find the repo by ID: %w", err)
|
return nil, fmt.Errorf("failed to find the repo by ID: %w", err)
|
||||||
|
Loading…
Reference in New Issue
Block a user