mirror of
https://github.com/harness/drone.git
synced 2025-05-17 01:20:13 +08:00
feat: [CODE-3150]: Validate repo identifier while importing repositories (#3445)
* feat: [CODE-3150]: Validate repo identifier while importing repositories
This commit is contained in:
parent
f3c646190f
commit
02fe8c076f
@ -74,34 +74,35 @@ func (s SpaceOutput) MarshalJSON() ([]byte, error) {
|
|||||||
type Controller struct {
|
type Controller struct {
|
||||||
nestedSpacesEnabled bool
|
nestedSpacesEnabled bool
|
||||||
|
|
||||||
tx dbtx.Transactor
|
tx dbtx.Transactor
|
||||||
urlProvider url.Provider
|
urlProvider url.Provider
|
||||||
sseStreamer sse.Streamer
|
sseStreamer sse.Streamer
|
||||||
identifierCheck check.SpaceIdentifier
|
identifierCheck check.SpaceIdentifier
|
||||||
authorizer authz.Authorizer
|
authorizer authz.Authorizer
|
||||||
spacePathStore store.SpacePathStore
|
spacePathStore store.SpacePathStore
|
||||||
pipelineStore store.PipelineStore
|
pipelineStore store.PipelineStore
|
||||||
secretStore store.SecretStore
|
secretStore store.SecretStore
|
||||||
connectorStore store.ConnectorStore
|
connectorStore store.ConnectorStore
|
||||||
templateStore store.TemplateStore
|
templateStore store.TemplateStore
|
||||||
spaceStore store.SpaceStore
|
spaceStore store.SpaceStore
|
||||||
repoStore store.RepoStore
|
repoStore store.RepoStore
|
||||||
principalStore store.PrincipalStore
|
principalStore store.PrincipalStore
|
||||||
repoCtrl *repo.Controller
|
repoCtrl *repo.Controller
|
||||||
membershipStore store.MembershipStore
|
membershipStore store.MembershipStore
|
||||||
prListService *pullreq.ListService
|
prListService *pullreq.ListService
|
||||||
spaceFinder refcache.SpaceFinder
|
spaceFinder refcache.SpaceFinder
|
||||||
importer *importer.Repository
|
importer *importer.Repository
|
||||||
exporter *exporter.Repository
|
exporter *exporter.Repository
|
||||||
resourceLimiter limiter.ResourceLimiter
|
resourceLimiter limiter.ResourceLimiter
|
||||||
publicAccess publicaccess.Service
|
publicAccess publicaccess.Service
|
||||||
auditService audit.Service
|
auditService audit.Service
|
||||||
gitspaceSvc *gitspace.Service
|
gitspaceSvc *gitspace.Service
|
||||||
labelSvc *label.Service
|
labelSvc *label.Service
|
||||||
instrumentation instrument.Service
|
instrumentation instrument.Service
|
||||||
executionStore store.ExecutionStore
|
executionStore store.ExecutionStore
|
||||||
rulesSvc *rules.Service
|
rulesSvc *rules.Service
|
||||||
usageMetricStore store.UsageMetricStore
|
usageMetricStore store.UsageMetricStore
|
||||||
|
repoIdentifierCheck check.RepoIdentifier
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewController(config *types.Config, tx dbtx.Transactor, urlProvider url.Provider,
|
func NewController(config *types.Config, tx dbtx.Transactor, urlProvider url.Provider,
|
||||||
@ -115,7 +116,7 @@ func NewController(config *types.Config, tx dbtx.Transactor, urlProvider url.Pro
|
|||||||
limiter limiter.ResourceLimiter, publicAccess publicaccess.Service, auditService audit.Service,
|
limiter limiter.ResourceLimiter, publicAccess publicaccess.Service, auditService audit.Service,
|
||||||
gitspaceSvc *gitspace.Service, labelSvc *label.Service,
|
gitspaceSvc *gitspace.Service, labelSvc *label.Service,
|
||||||
instrumentation instrument.Service, executionStore store.ExecutionStore,
|
instrumentation instrument.Service, executionStore store.ExecutionStore,
|
||||||
rulesSvc *rules.Service, usageMetricStore store.UsageMetricStore,
|
rulesSvc *rules.Service, usageMetricStore store.UsageMetricStore, repoIdentifierCheck check.RepoIdentifier,
|
||||||
) *Controller {
|
) *Controller {
|
||||||
return &Controller{
|
return &Controller{
|
||||||
nestedSpacesEnabled: config.NestedSpacesEnabled,
|
nestedSpacesEnabled: config.NestedSpacesEnabled,
|
||||||
@ -147,6 +148,7 @@ func NewController(config *types.Config, tx dbtx.Transactor, urlProvider url.Pro
|
|||||||
executionStore: executionStore,
|
executionStore: executionStore,
|
||||||
rulesSvc: rulesSvc,
|
rulesSvc: rulesSvc,
|
||||||
usageMetricStore: usageMetricStore,
|
usageMetricStore: usageMetricStore,
|
||||||
|
repoIdentifierCheck: repoIdentifierCheck,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,8 +43,7 @@ type ImportRepositoriesOutput struct {
|
|||||||
DuplicateRepos []*repoctrl.RepositoryOutput `json:"duplicate_repos"` // repos which already exist in the space.
|
DuplicateRepos []*repoctrl.RepositoryOutput `json:"duplicate_repos"` // repos which already exist in the space.
|
||||||
}
|
}
|
||||||
|
|
||||||
// ImportRepositories imports repositories into an existing space. It ignores and continues on
|
// ImportRepositories imports repositories into an existing space.
|
||||||
// repo naming conflicts.
|
|
||||||
//
|
//
|
||||||
//nolint:gocognit
|
//nolint:gocognit
|
||||||
func (c *Controller) ImportRepositories(
|
func (c *Controller) ImportRepositories(
|
||||||
@ -83,6 +82,10 @@ func (c *Controller) ImportRepositories(
|
|||||||
&session.Principal,
|
&session.Principal,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if err := c.repoIdentifierCheck(repo.Identifier, session); err != nil {
|
||||||
|
return ImportRepositoriesOutput{}, fmt.Errorf("failed to sanitize the repo %s: %w", repo.Identifier, err)
|
||||||
|
}
|
||||||
|
|
||||||
repos = append(repos, repo)
|
repos = append(repos, repo)
|
||||||
repoIsPublicVals = append(repoIsPublicVals, isPublic)
|
repoIsPublicVals = append(repoIsPublicVals, isPublic)
|
||||||
cloneURLs = append(cloneURLs, remoteRepository.CloneURL)
|
cloneURLs = append(cloneURLs, remoteRepository.CloneURL)
|
||||||
|
@ -54,7 +54,7 @@ func ProvideController(config *types.Config, tx dbtx.Transactor, urlProvider url
|
|||||||
limiter limiter.ResourceLimiter, publicAccess publicaccess.Service,
|
limiter limiter.ResourceLimiter, publicAccess publicaccess.Service,
|
||||||
auditService audit.Service, gitspaceService *gitspace.Service,
|
auditService audit.Service, gitspaceService *gitspace.Service,
|
||||||
labelSvc *label.Service, instrumentation instrument.Service, executionStore store.ExecutionStore,
|
labelSvc *label.Service, instrumentation instrument.Service, executionStore store.ExecutionStore,
|
||||||
rulesSvc *rules.Service, usageMetricStore store.UsageMetricStore,
|
rulesSvc *rules.Service, usageMetricStore store.UsageMetricStore, repoIdentifierCheck check.RepoIdentifier,
|
||||||
) *Controller {
|
) *Controller {
|
||||||
return NewController(config, tx, urlProvider,
|
return NewController(config, tx, urlProvider,
|
||||||
sseStreamer, identifierCheck, authorizer,
|
sseStreamer, identifierCheck, authorizer,
|
||||||
@ -66,6 +66,6 @@ func ProvideController(config *types.Config, tx dbtx.Transactor, urlProvider url
|
|||||||
importer, exporter, limiter, publicAccess,
|
importer, exporter, limiter, publicAccess,
|
||||||
auditService, gitspaceService,
|
auditService, gitspaceService,
|
||||||
labelSvc, instrumentation, executionStore,
|
labelSvc, instrumentation, executionStore,
|
||||||
rulesSvc, usageMetricStore,
|
rulesSvc, usageMetricStore, repoIdentifierCheck,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -340,7 +340,7 @@ func initSystem(ctx context.Context, config *types.Config) (*server.System, erro
|
|||||||
orchestratorOrchestrator := orchestrator.ProvideOrchestrator(scmSCM, platformConnector, infraProvisioner, containerOrchestrator, eventsReporter, orchestratorConfig, ideFactory, resolverFactory)
|
orchestratorOrchestrator := orchestrator.ProvideOrchestrator(scmSCM, platformConnector, infraProvisioner, containerOrchestrator, eventsReporter, orchestratorConfig, ideFactory, resolverFactory)
|
||||||
gitspaceService := gitspace.ProvideGitspace(transactor, gitspaceConfigStore, gitspaceInstanceStore, eventsReporter, gitspaceEventStore, spaceFinder, infraproviderService, orchestratorOrchestrator, scmSCM, config)
|
gitspaceService := gitspace.ProvideGitspace(transactor, gitspaceConfigStore, gitspaceInstanceStore, eventsReporter, gitspaceEventStore, spaceFinder, infraproviderService, orchestratorOrchestrator, scmSCM, config)
|
||||||
usageMetricStore := database.ProvideUsageMetricStore(db)
|
usageMetricStore := database.ProvideUsageMetricStore(db)
|
||||||
spaceController := space.ProvideController(config, transactor, provider, streamer, spaceIdentifier, authorizer, spacePathStore, pipelineStore, secretStore, connectorStore, templateStore, spaceStore, repoStore, principalStore, repoController, membershipStore, listService, spaceFinder, repository, exporterRepository, resourceLimiter, publicaccessService, auditService, gitspaceService, labelService, instrumentService, executionStore, rulesService, usageMetricStore)
|
spaceController := space.ProvideController(config, transactor, provider, streamer, spaceIdentifier, authorizer, spacePathStore, pipelineStore, secretStore, connectorStore, templateStore, spaceStore, repoStore, principalStore, repoController, membershipStore, listService, spaceFinder, repository, exporterRepository, resourceLimiter, publicaccessService, auditService, gitspaceService, labelService, instrumentService, executionStore, rulesService, usageMetricStore, repoIdentifier)
|
||||||
reporter3, err := events5.ProvideReporter(eventsSystem)
|
reporter3, err := events5.ProvideReporter(eventsSystem)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
Loading…
Reference in New Issue
Block a user