mirror of
https://github.com/harness/drone.git
synced 2025-05-04 23:40:24 +08:00
feat: add repochecks (#1132)
This commit is contained in:
parent
cecfecdb06
commit
96f35b6e01
27
app/api/controller/repo/check.go
Normal file
27
app/api/controller/repo/check.go
Normal file
@ -0,0 +1,27 @@
|
||||
// Copyright 2023 Harness, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package repo
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/harness/gitness/app/auth"
|
||||
)
|
||||
|
||||
// Check defines the interface for adding extra checks during repository operations.
|
||||
type Check interface {
|
||||
// Create allows adding extra check during create repo operations
|
||||
Create(ctx context.Context, session *auth.Session, in *CreateInput) error
|
||||
}
|
@ -66,6 +66,7 @@ type Controller struct {
|
||||
resourceLimiter limiter.ResourceLimiter
|
||||
mtxManager lock.MutexManager
|
||||
identifierCheck check.RepoIdentifier
|
||||
repoCheck Check
|
||||
}
|
||||
|
||||
func NewController(
|
||||
@ -88,6 +89,7 @@ func NewController(
|
||||
limiter limiter.ResourceLimiter,
|
||||
mtxManager lock.MutexManager,
|
||||
identifierCheck check.RepoIdentifier,
|
||||
repoCheck Check,
|
||||
) *Controller {
|
||||
return &Controller{
|
||||
defaultBranch: config.Git.DefaultBranch,
|
||||
@ -110,6 +112,7 @@ func NewController(
|
||||
resourceLimiter: limiter,
|
||||
mtxManager: mtxManager,
|
||||
identifierCheck: identifierCheck,
|
||||
repoCheck: repoCheck,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -70,6 +70,11 @@ func (c *Controller) Create(ctx context.Context, session *auth.Session, in *Crea
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = c.repoCheck.Create(ctx, session, in)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var repo *types.Repository
|
||||
err = c.tx.WithTx(ctx, func(ctx context.Context) error {
|
||||
if err := c.resourceLimiter.RepoCount(ctx, parentSpace.ID, 1); err != nil {
|
||||
|
34
app/api/controller/repo/no_op_checks.go
Normal file
34
app/api/controller/repo/no_op_checks.go
Normal file
@ -0,0 +1,34 @@
|
||||
// Copyright 2023 Harness, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package repo
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/harness/gitness/app/auth"
|
||||
)
|
||||
|
||||
var _ Check = (*NoOpRepoChecks)(nil)
|
||||
|
||||
type NoOpRepoChecks struct {
|
||||
}
|
||||
|
||||
func NewNoOpRepoChecks() *NoOpRepoChecks {
|
||||
return &NoOpRepoChecks{}
|
||||
}
|
||||
|
||||
func (c *NoOpRepoChecks) Create(_ context.Context, _ *auth.Session, _ *CreateInput) error {
|
||||
return nil
|
||||
}
|
@ -58,10 +58,15 @@ func ProvideController(
|
||||
limiter limiter.ResourceLimiter,
|
||||
mtxManager lock.MutexManager,
|
||||
identifierCheck check.RepoIdentifier,
|
||||
repoChecks Check,
|
||||
) *Controller {
|
||||
return NewController(config, tx, urlProvider,
|
||||
authorizer, repoStore,
|
||||
spaceStore, pipelineStore,
|
||||
principalStore, ruleStore, principalInfoCache, protectionManager,
|
||||
rpcClient, importer, codeOwners, reporeporter, indexer, limiter, mtxManager, identifierCheck)
|
||||
rpcClient, importer, codeOwners, reporeporter, indexer, limiter, mtxManager, identifierCheck, repoChecks)
|
||||
}
|
||||
|
||||
func ProvideRepoCheck() Check {
|
||||
return NewNoOpRepoChecks()
|
||||
}
|
||||
|
@ -183,6 +183,7 @@ func initSystem(ctx context.Context, config *types.Config) (*cliserver.System, e
|
||||
controllerkeywordsearch.WireSet,
|
||||
usergroup.WireSet,
|
||||
openapi.WireSet,
|
||||
repo.ProvideRepoCheck,
|
||||
)
|
||||
return &cliserver.System{}, nil
|
||||
}
|
||||
|
@ -189,7 +189,8 @@ func initSystem(ctx context.Context, config *types.Config) (*server.System, erro
|
||||
return nil, err
|
||||
}
|
||||
repoIdentifier := check.ProvideRepoIdentifierCheck()
|
||||
repoController := repo.ProvideController(config, transactor, provider, authorizer, repoStore, spaceStore, pipelineStore, principalStore, ruleStore, principalInfoCache, protectionManager, gitInterface, repository, codeownersService, reporter, indexer, resourceLimiter, mutexManager, repoIdentifier)
|
||||
repoCheck := repo.ProvideRepoCheck()
|
||||
repoController := repo.ProvideController(config, transactor, provider, authorizer, repoStore, spaceStore, pipelineStore, principalStore, ruleStore, principalInfoCache, protectionManager, gitInterface, repository, codeownersService, reporter, indexer, resourceLimiter, mutexManager, repoIdentifier, repoCheck)
|
||||
executionStore := database.ProvideExecutionStore(db)
|
||||
checkStore := database.ProvideCheckStore(db, principalInfoCache)
|
||||
stageStore := database.ProvideStageStore(db)
|
||||
|
Loading…
Reference in New Issue
Block a user