mirror of
https://github.com/harness/drone.git
synced 2025-05-05 15:32:56 +00:00
[fix]: [AH-952]: fix override of files for maven artifacts (#3692)
* [fix]: [AH-952]: Fixed pr check * [fix]: [AH-952]: Fixed pr check * [fix]: [AH-952]: Fixed pr check * [fix]: [AH-952]: Fixed pr check * [fix]: [AH-952]: Fixed pr check * [fix]: [AH-952]: Fixed pr check * [fix]: [AH-952]: fix override of files for maven artifacts
This commit is contained in:
parent
8d13a4beb3
commit
2ec6fb8a58
@ -528,8 +528,10 @@ func initSystem(ctx context.Context, config *types.Config) (*server.System, erro
|
||||
registryHelper := rpm.LocalRegistryHelperProvider(fileManager, artifactRepository)
|
||||
indexService := index.ProvideService(registryHelper, lockerLocker)
|
||||
apiHandler := router.APIHandlerProvider(registryRepository, upstreamProxyConfigRepository, fileManager, tagRepository, manifestRepository, cleanupPolicyRepository, imageRepository, storageDriver, spaceFinder, transactor, authenticator, provider, authorizer, auditService, artifactRepository, webhooksRepository, webhooksExecutionRepository, service2, spacePathStore, reporter10, downloadStatRepository, indexService, config, registryBlobRepository)
|
||||
packageTagRepository := database2.ProvidePackageTagDao(db)
|
||||
localBase := base.LocalBaseProvider(registryRepository, fileManager, transactor, imageRepository, artifactRepository, nodesRepository, packageTagRepository)
|
||||
mavenDBStore := maven.DBStoreProvider(registryRepository, imageRepository, artifactRepository, spaceStore, bandwidthStatRepository, downloadStatRepository, nodesRepository, upstreamProxyConfigRepository)
|
||||
mavenLocalRegistry := maven.LocalRegistryProvider(mavenDBStore, transactor, fileManager)
|
||||
mavenLocalRegistry := maven.LocalRegistryProvider(localBase, mavenDBStore, transactor, fileManager)
|
||||
mavenController := maven.ProvideProxyController(mavenLocalRegistry, secretService, spaceFinder)
|
||||
mavenRemoteRegistry := maven.RemoteRegistryProvider(mavenDBStore, transactor, mavenLocalRegistry, mavenController)
|
||||
controller2 := maven.ControllerProvider(mavenLocalRegistry, mavenRemoteRegistry, authorizer, mavenDBStore)
|
||||
@ -540,8 +542,6 @@ func initSystem(ctx context.Context, config *types.Config) (*server.System, erro
|
||||
packagesHandler := api2.NewPackageHandlerProvider(registryRepository, downloadStatRepository, spaceStore, tokenStore, controller, authenticator, provider, authorizer)
|
||||
genericHandler := api2.NewGenericHandlerProvider(spaceStore, genericController, tokenStore, controller, authenticator, provider, authorizer, packagesHandler)
|
||||
handler3 := router.GenericHandlerProvider(genericHandler)
|
||||
packageTagRepository := database2.ProvidePackageTagDao(db)
|
||||
localBase := base.LocalBaseProvider(registryRepository, fileManager, transactor, imageRepository, artifactRepository, nodesRepository, packageTagRepository)
|
||||
pythonLocalRegistry := python.LocalRegistryProvider(localBase, fileManager, upstreamProxyConfigRepository, transactor, registryRepository, imageRepository, artifactRepository, provider)
|
||||
localRegistryHelper := python.LocalRegistryHelperProvider(pythonLocalRegistry, localBase)
|
||||
proxy := python.ProxyProvider(upstreamProxyConfigRepository, registryRepository, imageRepository, artifactRepository, fileManager, transactor, provider, spaceFinder, secretService, localRegistryHelper)
|
||||
|
@ -112,14 +112,18 @@ func (h *Handler) GetArtifactInfo(r *http.Request, remoteSupport bool) (pkg.Mave
|
||||
pathRoot := getPathRoot(r.Context())
|
||||
|
||||
info := &pkg.MavenArtifactInfo{
|
||||
ArtifactInfo: &pkg.ArtifactInfo{
|
||||
BaseInfo: &pkg.BaseInfo{
|
||||
PathRoot: pathRoot,
|
||||
RootIdentifier: rootIdentifier,
|
||||
RootParentID: rootSpace.ID,
|
||||
ParentID: registry.ParentID,
|
||||
},
|
||||
Registry: *registry,
|
||||
RegIdentifier: registryIdentifier,
|
||||
RegistryID: registry.ID,
|
||||
Image: groupID + ":" + artifactID,
|
||||
},
|
||||
GroupID: groupID,
|
||||
ArtifactID: artifactID,
|
||||
Version: version,
|
||||
|
@ -80,6 +80,8 @@ type LocalBase interface {
|
||||
|
||||
Exists(ctx context.Context, info pkg.ArtifactInfo, version string, fileName string) bool
|
||||
|
||||
ExistsByFilePath(ctx context.Context, registryID int64, filePath string) (bool, error)
|
||||
|
||||
CheckIfVersionExists(ctx context.Context, info pkg.PackageArtifactInfo) (bool, error)
|
||||
|
||||
DeletePackage(ctx context.Context, info pkg.PackageArtifactInfo) error
|
||||
@ -311,6 +313,11 @@ func (l *localBase) Exists(ctx context.Context, info pkg.ArtifactInfo, version s
|
||||
return exists
|
||||
}
|
||||
|
||||
func (l *localBase) ExistsByFilePath(ctx context.Context, registryID int64, filePath string) (bool, error) {
|
||||
exists, _, err := l.GetSHA256ByPath(ctx, registryID, filePath)
|
||||
return exists, err
|
||||
}
|
||||
|
||||
func (l *localBase) CheckIfVersionExists(ctx context.Context, info pkg.PackageArtifactInfo) (bool, error) {
|
||||
artifacts, err := l.artifactDao.GetArtifactMetadata(ctx,
|
||||
info.BaseArtifactInfo().ParentID, info.BaseArtifactInfo().RegIdentifier,
|
||||
|
@ -58,9 +58,7 @@ func (a *ArtifactInfo) SetRepoKey(key string) {
|
||||
}
|
||||
|
||||
type MavenArtifactInfo struct {
|
||||
*BaseInfo
|
||||
RegIdentifier string
|
||||
RegistryID int64
|
||||
*ArtifactInfo
|
||||
GroupID string
|
||||
ArtifactID string
|
||||
Version string
|
||||
|
@ -18,6 +18,7 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
@ -26,6 +27,7 @@ import (
|
||||
"github.com/harness/gitness/registry/app/dist_temp/errcode"
|
||||
"github.com/harness/gitness/registry/app/metadata"
|
||||
"github.com/harness/gitness/registry/app/pkg"
|
||||
"github.com/harness/gitness/registry/app/pkg/base"
|
||||
"github.com/harness/gitness/registry/app/pkg/commons"
|
||||
"github.com/harness/gitness/registry/app/pkg/filemanager"
|
||||
"github.com/harness/gitness/registry/app/pkg/maven/utils"
|
||||
@ -39,11 +41,13 @@ const (
|
||||
)
|
||||
|
||||
func NewLocalRegistry(
|
||||
dBStore *DBStore, tx dbtx.Transactor,
|
||||
|
||||
localBase base.LocalBase,
|
||||
dBStore *DBStore,
|
||||
tx dbtx.Transactor,
|
||||
fileManager filemanager.FileManager,
|
||||
) Registry {
|
||||
return &LocalRegistry{
|
||||
localBase: localBase,
|
||||
DBStore: dBStore,
|
||||
tx: tx,
|
||||
fileManager: fileManager,
|
||||
@ -51,6 +55,7 @@ func NewLocalRegistry(
|
||||
}
|
||||
|
||||
type LocalRegistry struct {
|
||||
localBase base.LocalBase
|
||||
DBStore *DBStore
|
||||
tx dbtx.Transactor
|
||||
fileManager filemanager.FileManager
|
||||
@ -120,6 +125,21 @@ func (r *LocalRegistry) PutArtifact(ctx context.Context, info pkg.MavenArtifactI
|
||||
responseHeaders *commons.ResponseHeaders, errs []error,
|
||||
) {
|
||||
filePath := utils.GetFilePath(info)
|
||||
fileExists, err := r.localBase.ExistsByFilePath(ctx, info.RegistryID, strings.TrimPrefix(filePath, "/"))
|
||||
if err != nil {
|
||||
return responseHeaders, []error{
|
||||
fmt.Errorf("error occurred while checking file existence for GroupID: %s, "+
|
||||
"ArtifactID: %s and Version: %s with file name: %s in registry: %s with error: %w",
|
||||
info.GroupID, info.ArtifactID, info.Version, info.FileName, info.RegIdentifier, err)}
|
||||
}
|
||||
if fileExists {
|
||||
return responseHeaders, []error{
|
||||
fmt.Errorf("file already exists for GroupID: %s, "+
|
||||
"ArtifactID: %s and Version: %s with file name: %s in registry: %s. "+
|
||||
"Try deleting this version and push it again", info.GroupID, info.ArtifactID,
|
||||
info.Version, info.FileName, info.RegIdentifier)}
|
||||
}
|
||||
|
||||
fileInfo, err := r.fileManager.UploadFile(ctx, filePath,
|
||||
info.RegistryID, info.RootParentID, info.RootIdentifier, nil, fileReader, info.FileName)
|
||||
if err != nil {
|
||||
|
@ -18,6 +18,7 @@ import (
|
||||
"github.com/harness/gitness/app/auth/authz"
|
||||
"github.com/harness/gitness/app/services/refcache"
|
||||
corestore "github.com/harness/gitness/app/store"
|
||||
"github.com/harness/gitness/registry/app/pkg/base"
|
||||
"github.com/harness/gitness/registry/app/pkg/filemanager"
|
||||
"github.com/harness/gitness/registry/app/remote/controller/proxy/maven"
|
||||
"github.com/harness/gitness/registry/app/store"
|
||||
@ -28,12 +29,14 @@ import (
|
||||
)
|
||||
|
||||
func LocalRegistryProvider(
|
||||
localBase base.LocalBase,
|
||||
dBStore *DBStore,
|
||||
tx dbtx.Transactor,
|
||||
fileManager filemanager.FileManager,
|
||||
) *LocalRegistry {
|
||||
//nolint:errcheck
|
||||
return NewLocalRegistry(dBStore,
|
||||
return NewLocalRegistry(localBase,
|
||||
dBStore,
|
||||
tx,
|
||||
fileManager,
|
||||
).(*LocalRegistry)
|
||||
|
@ -119,6 +119,11 @@ func (m *MockLocalBase) Exists(ctx context.Context, info pkg.ArtifactInfo, versi
|
||||
return args.Bool(0)
|
||||
}
|
||||
|
||||
func (m *MockLocalBase) ExistsByFilePath(ctx context.Context, registryID int64, filePath string) (bool, error) {
|
||||
args := m.Called(ctx, registryID, filePath)
|
||||
return args.Bool(0), args.Error(1)
|
||||
}
|
||||
|
||||
func (m *MockLocalBase) Download(ctx context.Context, info pkg.ArtifactInfo, version, filename string) (
|
||||
*commons.ResponseHeaders, *storage.FileReader, string, error,
|
||||
) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user