[AH-310]: Updated secret flows so removing foreign key constraints (#2618)

* [AH-310]: Updated secret flows
* [AH-310]: Updated secret flows so removing foreign key constraints
CODE-2402
Arvind Choudhary 2024-09-06 20:48:12 +00:00 committed by Harness
parent 77b01718bd
commit ea3c2eda13
18 changed files with 233 additions and 68 deletions

View File

@ -0,0 +1,4 @@
alter table upstream_proxy_configs
add constraint fk_layers_secret_identifier_and_secret_space_id
foreign key (upstream_proxy_config_secret_identifier, upstream_proxy_config_secret_space_id)
references secrets(secret_uid, secret_space_id)

View File

@ -0,0 +1,2 @@
alter table upstream_proxy_configs
drop constraint fk_layers_secret_identifier_and_secret_space_id;

View File

@ -0,0 +1,54 @@
create table upstream_proxy_configs_dg_tmp
(
upstream_proxy_config_id INTEGER
primary key autoincrement,
upstream_proxy_config_registry_id INTEGER not null
constraint fk_upstream_proxy_config_registry_id
references registries
on delete cascade,
upstream_proxy_config_source text,
upstream_proxy_config_url text,
upstream_proxy_config_auth_type text not null,
upstream_proxy_config_user_name text,
upstream_proxy_config_secret_identifier text,
upstream_proxy_config_secret_space_id int,
upstream_proxy_config_token text,
upstream_proxy_config_created_at INTEGER,
upstream_proxy_config_updated_at INTEGER,
upstream_proxy_config_created_by INTEGER,
upstream_proxy_config_updated_by INTEGER,
constraint fk_layers_secret_identifier_and_secret_space_id
foreign key (upstream_proxy_config_secret_identifier,
upstream_proxy_config_secret_space_id) references secrets (secret_uid, secret_space_id)
);
insert into upstream_proxy_configs_dg_tmp(upstream_proxy_config_id, upstream_proxy_config_registry_id,
upstream_proxy_config_source, upstream_proxy_config_url,
upstream_proxy_config_auth_type, upstream_proxy_config_user_name,
upstream_proxy_config_secret_identifier,
upstream_proxy_config_secret_space_id, upstream_proxy_config_token,
upstream_proxy_config_created_at, upstream_proxy_config_updated_at,
upstream_proxy_config_created_by, upstream_proxy_config_updated_by)
select upstream_proxy_config_id,
upstream_proxy_config_registry_id,
upstream_proxy_config_source,
upstream_proxy_config_url,
upstream_proxy_config_auth_type,
upstream_proxy_config_user_name,
upstream_proxy_config_secret_identifier,
upstream_proxy_config_secret_space_id,
upstream_proxy_config_token,
upstream_proxy_config_created_at,
upstream_proxy_config_updated_at,
upstream_proxy_config_created_by,
upstream_proxy_config_updated_by
from upstream_proxy_configs;
drop table upstream_proxy_configs;
alter table upstream_proxy_configs_dg_tmp
rename to upstream_proxy_configs;
create index index_upstream_proxy_config_on_registry_id
on upstream_proxy_configs (upstream_proxy_config_registry_id);

View File

@ -0,0 +1,51 @@
create table upstream_proxy_configs_dg_tmp
(
upstream_proxy_config_id INTEGER
primary key autoincrement,
upstream_proxy_config_registry_id INTEGER not null
constraint fk_upstream_proxy_config_registry_id
references registries
on delete cascade,
upstream_proxy_config_source text,
upstream_proxy_config_url text,
upstream_proxy_config_auth_type text not null,
upstream_proxy_config_user_name text,
upstream_proxy_config_secret_identifier text,
upstream_proxy_config_secret_space_id int,
upstream_proxy_config_token text,
upstream_proxy_config_created_at INTEGER,
upstream_proxy_config_updated_at INTEGER,
upstream_proxy_config_created_by INTEGER,
upstream_proxy_config_updated_by INTEGER
);
insert into upstream_proxy_configs_dg_tmp(upstream_proxy_config_id, upstream_proxy_config_registry_id,
upstream_proxy_config_source, upstream_proxy_config_url,
upstream_proxy_config_auth_type, upstream_proxy_config_user_name,
upstream_proxy_config_secret_identifier,
upstream_proxy_config_secret_space_id, upstream_proxy_config_token,
upstream_proxy_config_created_at, upstream_proxy_config_updated_at,
upstream_proxy_config_created_by, upstream_proxy_config_updated_by)
select upstream_proxy_config_id,
upstream_proxy_config_registry_id,
upstream_proxy_config_source,
upstream_proxy_config_url,
upstream_proxy_config_auth_type,
upstream_proxy_config_user_name,
upstream_proxy_config_secret_identifier,
upstream_proxy_config_secret_space_id,
upstream_proxy_config_token,
upstream_proxy_config_created_at,
upstream_proxy_config_updated_at,
upstream_proxy_config_created_by,
upstream_proxy_config_updated_by
from upstream_proxy_configs;
drop table upstream_proxy_configs;
alter table upstream_proxy_configs_dg_tmp
rename to upstream_proxy_configs;
create index index_upstream_proxy_config_on_registry_id
on upstream_proxy_configs (upstream_proxy_config_registry_id);

View File

@ -435,7 +435,7 @@ func initSystem(ctx context.Context, config *types.Config) (*server.System, erro
manifestService := docker.ManifestServiceProvider(registryRepository, manifestRepository, blobRepository, mediaTypesRepository, manifestReferenceRepository, tagRepository, artifactRepository, artifactStatRepository, layerRepository, gcService, transactor) manifestService := docker.ManifestServiceProvider(registryRepository, manifestRepository, blobRepository, mediaTypesRepository, manifestReferenceRepository, tagRepository, artifactRepository, artifactStatRepository, layerRepository, gcService, transactor)
registryBlobRepository := database2.ProvideRegistryBlobDao(db) registryBlobRepository := database2.ProvideRegistryBlobDao(db)
localRegistry := docker.LocalRegistryProvider(app, manifestService, blobRepository, registryRepository, manifestRepository, registryBlobRepository, mediaTypesRepository, tagRepository, artifactRepository, artifactStatRepository, gcService, transactor) localRegistry := docker.LocalRegistryProvider(app, manifestService, blobRepository, registryRepository, manifestRepository, registryBlobRepository, mediaTypesRepository, tagRepository, artifactRepository, artifactStatRepository, gcService, transactor)
upstreamProxyConfigRepository := database2.ProvideUpstreamDao(db, registryRepository) upstreamProxyConfigRepository := database2.ProvideUpstreamDao(db, registryRepository, spacePathStore)
secretService := secret3.ProvideSecretService(secretStore, encrypter, spacePathStore) secretService := secret3.ProvideSecretService(secretStore, encrypter, spacePathStore)
remoteRegistry := docker.RemoteRegistryProvider(localRegistry, app, upstreamProxyConfigRepository, spacePathStore, secretService) remoteRegistry := docker.RemoteRegistryProvider(localRegistry, app, upstreamProxyConfigRepository, spacePathStore, secretService)
coreController := pkg.CoreControllerProvider(registryRepository) coreController := pkg.CoreControllerProvider(registryRepository)
@ -443,7 +443,7 @@ func initSystem(ctx context.Context, config *types.Config) (*server.System, erro
handler := api2.NewHandlerProvider(dockerController, spaceStore, tokenStore, controller, authenticator, provider, authorizer) handler := api2.NewHandlerProvider(dockerController, spaceStore, tokenStore, controller, authenticator, provider, authorizer)
registryOCIHandler := router.OCIHandlerProvider(handler) registryOCIHandler := router.OCIHandlerProvider(handler)
cleanupPolicyRepository := database2.ProvideCleanupPolicyDao(db, transactor) cleanupPolicyRepository := database2.ProvideCleanupPolicyDao(db, transactor)
apiHandler := router.APIHandlerProvider(registryRepository, upstreamProxyConfigRepository, tagRepository, manifestRepository, cleanupPolicyRepository, artifactRepository, storageDriver, spaceStore, transactor, authenticator, provider, authorizer, auditService) apiHandler := router.APIHandlerProvider(registryRepository, upstreamProxyConfigRepository, tagRepository, manifestRepository, cleanupPolicyRepository, artifactRepository, storageDriver, spaceStore, transactor, authenticator, provider, authorizer, auditService, spacePathStore)
appRouter := router.AppRouterProvider(registryOCIHandler, apiHandler) appRouter := router.AppRouterProvider(registryOCIHandler, apiHandler)
routerRouter := router2.ProvideRouter(ctx, config, authenticator, repoController, reposettingsController, executionController, logsController, spaceController, pipelineController, secretController, triggerController, connectorController, templateController, pluginController, pullreqController, webhookController, githookController, gitInterface, serviceaccountController, controller, principalController, usergroupController, checkController, systemController, uploadController, keywordsearchController, infraproviderController, gitspaceController, migrateController, aiagentController, capabilitiesController, provider, openapiService, appRouter) routerRouter := router2.ProvideRouter(ctx, config, authenticator, repoController, reposettingsController, executionController, logsController, spaceController, pipelineController, secretController, triggerController, connectorController, templateController, pluginController, pullreqController, webhookController, githookController, gitInterface, serviceaccountController, controller, principalController, usergroupController, checkController, systemController, uploadController, keywordsearchController, infraproviderController, gitspaceController, migrateController, aiagentController, capabilitiesController, provider, openapiService, appRouter)
serverServer := server2.ProvideServer(config, routerRouter) serverServer := server2.ProvideServer(config, routerRouter)

View File

@ -316,13 +316,10 @@ func CreateUpstreamProxyResponseJSONResponse(upstreamproxy *types.UpstreamProxy)
if api.AuthType(upstreamproxy.RepoAuthType) == api.AuthTypeUserPassword { if api.AuthType(upstreamproxy.RepoAuthType) == api.AuthTypeUserPassword {
auth := api.UserPassword{} auth := api.UserPassword{}
auth.UserName = upstreamproxy.UserName auth.UserName = upstreamproxy.UserName
auth.SecretIdentifier = &upstreamproxy.SecretIdentifier.String auth.SecretIdentifier = &upstreamproxy.SecretIdentifier
auth.SecretSpaceId = nil secretSpaceIDInt := int(upstreamproxy.SecretSpaceID)
if upstreamproxy.SecretSpaceID.Valid { auth.SecretSpaceId = &secretSpaceIDInt
// Convert int32 to int and assign to the expected field auth.SecretSpacePath = &upstreamproxy.SecretSpacePath
secretSpaceID := int(upstreamproxy.SecretSpaceID.Int32)
auth.SecretSpaceId = &secretSpaceID
}
_ = configAuth.FromUserPassword(auth) _ = configAuth.FromUserPassword(auth)
} }

View File

@ -38,6 +38,7 @@ type APIController struct {
URLProvider urlprovider.Provider URLProvider urlprovider.Provider
Authorizer authz.Authorizer Authorizer authz.Authorizer
AuditService audit.Service AuditService audit.Service
spacePathStore corestore.SpacePathStore
} }
func NewAPIController( func NewAPIController(
@ -53,6 +54,7 @@ func NewAPIController(
urlProvider urlprovider.Provider, urlProvider urlprovider.Provider,
authorizer authz.Authorizer, authorizer authz.Authorizer,
auditService audit.Service, auditService audit.Service,
spacePathStore corestore.SpacePathStore,
) *APIController { ) *APIController {
return &APIController{ return &APIController{
RegistryRepository: repositoryStore, RegistryRepository: repositoryStore,
@ -67,5 +69,6 @@ func NewAPIController(
URLProvider: urlProvider, URLProvider: urlProvider,
Authorizer: authorizer, Authorizer: authorizer,
AuditService: auditService, AuditService: auditService,
spacePathStore: spacePathStore,
} }
} }

View File

@ -75,7 +75,8 @@ func (c *APIController) CreateRegistry(
if registryRequest.Config.Type == artifact.RegistryTypeVIRTUAL { if registryRequest.Config.Type == artifact.RegistryTypeVIRTUAL {
return c.createVirtualRegistry(ctx, registryRequest, regInfo, session, parentRef) return c.createVirtualRegistry(ctx, registryRequest, regInfo, session, parentRef)
} }
registry, upstreamproxy, err := CreateUpstreamProxyEntity( registry, upstreamproxy, err := c.CreateUpstreamProxyEntity(
ctx,
registryRequest, registryRequest,
regInfo.parentID, regInfo.rootIdentifierID, regInfo.parentID, regInfo.rootIdentifierID,
) )
@ -254,10 +255,8 @@ func CreateRegistryEntity(
return entity, nil return entity, nil
} }
func CreateUpstreamProxyEntity( func (c *APIController) CreateUpstreamProxyEntity(
dto artifact.RegistryRequest, ctx context.Context, dto artifact.RegistryRequest, parentID int64, rootParentID int64,
parentID int64,
rootParentID int64,
) (*registrytypes.Registry, *registrytypes.UpstreamProxyConfig, error) { ) (*registrytypes.Registry, *registrytypes.UpstreamProxyConfig, error) {
allowedPattern := []string{} allowedPattern := []string{}
if dto.AllowedPattern != nil { if dto.AllowedPattern != nil {
@ -311,11 +310,32 @@ func CreateUpstreamProxyEntity(
return nil, nil, err return nil, nil, err
} }
upstreamProxyConfigEntity.UserName = res.UserName upstreamProxyConfigEntity.UserName = res.UserName
if res.SecretIdentifier == nil || res.SecretSpaceId == nil { if res.SecretIdentifier == nil {
return nil, nil, fmt.Errorf("failed to create upstream proxy: secret_identifier or secret_space_id missing") return nil, nil, fmt.Errorf("failed to create upstream proxy: secret_identifier missing")
} }
upstreamProxyConfigEntity.SecretIdentifier = *res.SecretIdentifier
upstreamProxyConfigEntity.SecretSpaceID, err = c.getSecretID(ctx, res.SecretSpaceId, res.SecretSpacePath)
if err != nil {
return nil, nil, err
}
upstreamProxyConfigEntity.SecretSpaceID = *res.SecretSpaceId upstreamProxyConfigEntity.SecretSpaceID = *res.SecretSpaceId
} }
return repoEntity, upstreamProxyConfigEntity, nil return repoEntity, upstreamProxyConfigEntity, nil
} }
func (c *APIController) getSecretID(ctx context.Context, secretSpaceID *int, secretSpacePath *string) (int, error) {
if secretSpaceID == nil && secretSpacePath == nil {
return -1, fmt.Errorf("failed to create upstream proxy: secret space missing")
}
if secretSpaceID != nil {
return *secretSpaceID, nil
}
path, err := c.spacePathStore.FindByPath(ctx, *secretSpacePath)
if err != nil {
return -1, fmt.Errorf("failed to get Space Path: %w", err)
}
return int(path.SpaceID), nil
}

View File

@ -89,7 +89,8 @@ func (c *APIController) ModifyRegistry(
if err != nil { if err != nil {
return throwModifyRegistry500Error(err), err return throwModifyRegistry500Error(err), err
} }
registry, upstreamproxy, err := UpdateUpstreamProxyEntity( registry, upstreamproxy, err := c.UpdateUpstreamProxyEntity(
ctx,
artifact.RegistryRequest(*r.Body), artifact.RegistryRequest(*r.Body),
regInfo.parentID, regInfo.rootIdentifierID, upstreamproxyEntity, regInfo.parentID, regInfo.rootIdentifierID, upstreamproxyEntity,
) )
@ -327,11 +328,8 @@ func UpdateRepoEntity(
return entity, nil return entity, nil
} }
func UpdateUpstreamProxyEntity( func (c *APIController) UpdateUpstreamProxyEntity(
dto artifact.RegistryRequest, ctx context.Context, dto artifact.RegistryRequest, parentID int64, rootParentID int64, u *types.UpstreamProxy,
parentID int64,
rootParentID int64,
u *types.UpstreamProxy,
) (*types.Registry, *types.UpstreamProxyConfig, error) { ) (*types.Registry, *types.UpstreamProxyConfig, error) {
allowedPattern := []string{} allowedPattern := []string{}
if dto.AllowedPattern != nil { if dto.AllowedPattern != nil {
@ -387,7 +385,14 @@ func UpdateUpstreamProxyEntity(
return nil, nil, err return nil, nil, err
} }
upstreamProxyConfigEntity.UserName = res.UserName upstreamProxyConfigEntity.UserName = res.UserName
upstreamProxyConfigEntity.SecretIdentifier = *res.SecretIdentifier if res.SecretIdentifier == nil {
return nil, nil, fmt.Errorf("failed to create upstream proxy: secret_identifier missing")
}
upstreamProxyConfigEntity.SecretSpaceID, err = c.getSecretID(ctx, res.SecretSpaceId, res.SecretSpacePath)
if err != nil {
return nil, nil, err
}
upstreamProxyConfigEntity.SecretSpaceID = *res.SecretSpaceId upstreamProxyConfigEntity.SecretSpaceID = *res.SecretSpaceId
} else { } else {
upstreamProxyConfigEntity.UserName = "" upstreamProxyConfigEntity.UserName = ""

View File

@ -1465,6 +1465,8 @@ components:
type: string type: string
secretSpaceId: secretSpaceId:
type: integer type: integer
secretSpacePath:
type: string
required: required:
- userName - userName
- password - password

View File

@ -3725,26 +3725,26 @@ var swaggerSpec = []string{
"ip1hMnGdRvryKd6QZ4TVhS3RCXgP9WRSlAHVNIdY4vqgO5x8NK2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vsN3V288cnDe",
"V4/Xbt99X+KPgxr9sp54PBk00BNXXKDtiuLIPO9AOkXzxaU61iBPfo9wHo0eXgv7lX217h27vRJ3Tahv", "evayee/q8drtu+9L/HFQo1/WE48ngwZ64ooLtF1RnJnnHUinaL64VMca5MnvEc6j0cNrYb+yr9bdZLdX",
"5clv5PkrXzWUwpSHzzUBOYjMvc2B+auf1NR6qINNZwfVHczZrPnBa62z1n6Uc58rX67VemwscS6/Lv8X", "4j4K9T09+R09f+XLh1KY8vC5JiAHkbm3OTB/9bObWg91sOnsoLqnOZs1P4qtddbaj3Luc+XrtlqPjSXO",
"AAD//4u67HhmjgAA", "5dfl/wIAAP//tvNQvIqOAAA=",
} }
// GetSwagger returns the content of the embedded swagger specification file // GetSwagger returns the content of the embedded swagger specification file

View File

@ -414,6 +414,7 @@ type UpstreamConfigSource string
type UserPassword struct { type UserPassword struct {
SecretIdentifier *string `json:"secretIdentifier,omitempty"` SecretIdentifier *string `json:"secretIdentifier,omitempty"`
SecretSpaceId *int `json:"secretSpaceId,omitempty"` SecretSpaceId *int `json:"secretSpaceId,omitempty"`
SecretSpacePath *string `json:"secretSpacePath,omitempty"`
UserName string `json:"userName"` UserName string `json:"userName"`
} }

View File

@ -65,6 +65,7 @@ func NewAPIHandler(
urlProvider urlprovider.Provider, urlProvider urlprovider.Provider,
authorizer authz.Authorizer, authorizer authz.Authorizer,
auditService audit.Service, auditService audit.Service,
spacePathStore corestore.SpacePathStore,
) APIHandler { ) APIHandler {
r := chi.NewRouter() r := chi.NewRouter()
r.Use(audit.Middleware()) r.Use(audit.Middleware())
@ -83,6 +84,7 @@ func NewAPIHandler(
urlProvider, urlProvider,
authorizer, authorizer,
auditService, auditService,
spacePathStore,
) )
handler := artifact.NewStrictHandler(apiController, []artifact.StrictMiddlewareFunc{}) handler := artifact.NewStrictHandler(apiController, []artifact.StrictMiddlewareFunc{})
muxHandler := artifact.HandlerFromMuxWithBaseURL(handler, r, baseURL) muxHandler := artifact.HandlerFromMuxWithBaseURL(handler, r, baseURL)

View File

@ -52,6 +52,7 @@ func APIHandlerProvider(
urlProvider urlprovider.Provider, urlProvider urlprovider.Provider,
authorizer authz.Authorizer, authorizer authz.Authorizer,
auditService audit.Service, auditService audit.Service,
spacePathStore corestore.SpacePathStore,
) harness.APIHandler { ) harness.APIHandler {
return harness.NewAPIHandler( return harness.NewAPIHandler(
repoDao, repoDao,
@ -68,6 +69,7 @@ func APIHandlerProvider(
urlProvider, urlProvider,
authorizer, authorizer,
auditService, auditService,
spacePathStore,
) )
} }

View File

@ -63,15 +63,8 @@ func getPwd(
ctx context.Context, spacePathStore store.SpacePathStore, secretService secret.Service, reg types.UpstreamProxy, ctx context.Context, spacePathStore store.SpacePathStore, secretService secret.Service, reg types.UpstreamProxy,
) string { ) string {
if api.AuthType(reg.RepoAuthType) == api.AuthTypeUserPassword { if api.AuthType(reg.RepoAuthType) == api.AuthTypeUserPassword {
secretSpaceID := int64(0) secretSpaceID := reg.SecretSpaceID
if reg.SecretSpaceID.Valid { secretIdentifier := reg.SecretIdentifier
secretSpaceID = int64(reg.SecretSpaceID.Int32)
}
secretIdentifier := ""
if reg.SecretIdentifier.Valid {
secretIdentifier = reg.SecretIdentifier.String
}
spacePath, err := spacePathStore.FindPrimaryBySpaceID(ctx, secretSpaceID) spacePath, err := spacePathStore.FindPrimaryBySpaceID(ctx, secretSpaceID)
if err != nil { if err != nil {

View File

@ -21,6 +21,7 @@ import (
"time" "time"
"github.com/harness/gitness/app/api/request" "github.com/harness/gitness/app/api/request"
corestore "github.com/harness/gitness/app/store"
"github.com/harness/gitness/registry/app/api/openapi/contracts/artifact" "github.com/harness/gitness/registry/app/api/openapi/contracts/artifact"
"github.com/harness/gitness/registry/app/store" "github.com/harness/gitness/registry/app/store"
"github.com/harness/gitness/registry/app/store/database/util" "github.com/harness/gitness/registry/app/store/database/util"
@ -37,12 +38,16 @@ import (
type UpstreamproxyDao struct { type UpstreamproxyDao struct {
registryDao store.RegistryRepository registryDao store.RegistryRepository
db *sqlx.DB db *sqlx.DB
spacePathStore corestore.SpacePathStore
} }
func NewUpstreamproxyDao(db *sqlx.DB, registryDao store.RegistryRepository) store.UpstreamProxyConfigRepository { func NewUpstreamproxyDao(
db *sqlx.DB, registryDao store.RegistryRepository, spacePathStore corestore.SpacePathStore,
) store.UpstreamProxyConfigRepository {
return &UpstreamproxyDao{ return &UpstreamproxyDao{
registryDao: registryDao, registryDao: registryDao,
db: db, db: db,
spacePathStore: spacePathStore,
} }
} }
@ -150,7 +155,8 @@ func (r UpstreamproxyDao) GetByRegistryIdentifier(
} }
func (r UpstreamproxyDao) GetByParentID(ctx context.Context, parentID string) ( func (r UpstreamproxyDao) GetByParentID(ctx context.Context, parentID string) (
upstreamProxies *[]types.UpstreamProxy, err error) { upstreamProxies *[]types.UpstreamProxy, err error,
) {
q := getUpstreamProxyQuery() q := getUpstreamProxyQuery()
q = q.Where("r.registry_parent_id = ? AND r.registry_type = 'UPSTREAM'", q = q.Where("r.registry_parent_id = ? AND r.registry_type = 'UPSTREAM'",
parentID) parentID)
@ -371,17 +377,35 @@ func (r UpstreamproxyDao) mapToInternalUpstreamProxy(
} }
func (r UpstreamproxyDao) mapToUpstreamProxy( func (r UpstreamproxyDao) mapToUpstreamProxy(
_ context.Context, ctx context.Context,
dst *upstreamProxyDB, dst *upstreamProxyDB,
) (*types.UpstreamProxy, error) { ) (*types.UpstreamProxy, error) {
createdBy := int64(-1) createdBy := int64(-1)
updatedBy := int64(-1) updatedBy := int64(-1)
secretIdentifier := ""
secretSpaceID := int64(-1)
if dst.CreatedBy.Valid { if dst.CreatedBy.Valid {
createdBy = dst.CreatedBy.Int64 createdBy = dst.CreatedBy.Int64
} }
if dst.UpdatedBy.Valid { if dst.UpdatedBy.Valid {
updatedBy = dst.UpdatedBy.Int64 updatedBy = dst.UpdatedBy.Int64
} }
if dst.SecretIdentifier.Valid {
secretIdentifier = dst.SecretIdentifier.String
}
if dst.SecretSpaceID.Valid {
secretSpaceID = int64(dst.SecretSpaceID.Int32)
}
secretSpacePath := ""
if dst.SecretSpaceID.Valid {
primary, err := r.spacePathStore.FindPrimaryBySpaceID(ctx, int64(dst.SecretSpaceID.Int32))
if err != nil {
return nil, fmt.Errorf("failed to get secret space path: %w", err)
}
secretSpacePath = primary.Value
}
return &types.UpstreamProxy{ return &types.UpstreamProxy{
ID: dst.ID, ID: dst.ID,
RegistryID: dst.RegistryID, RegistryID: dst.RegistryID,
@ -394,8 +418,9 @@ func (r UpstreamproxyDao) mapToUpstreamProxy(
RepoURL: dst.RepoURL, RepoURL: dst.RepoURL,
RepoAuthType: dst.RepoAuthType, RepoAuthType: dst.RepoAuthType,
UserName: dst.UserName, UserName: dst.UserName,
SecretIdentifier: dst.SecretIdentifier, SecretIdentifier: secretIdentifier,
SecretSpaceID: dst.SecretSpaceID, SecretSpaceID: secretSpaceID,
SecretSpacePath: secretSpacePath,
Token: dst.Token, Token: dst.Token,
CreatedAt: time.UnixMilli(dst.CreatedAt), CreatedAt: time.UnixMilli(dst.CreatedAt),
UpdatedAt: time.UnixMilli(dst.UpdatedAt), UpdatedAt: time.UnixMilli(dst.UpdatedAt),

View File

@ -15,6 +15,7 @@
package database package database
import ( import (
corestore "github.com/harness/gitness/app/store"
"github.com/harness/gitness/registry/app/store" "github.com/harness/gitness/registry/app/store"
"github.com/harness/gitness/store/database/dbtx" "github.com/harness/gitness/store/database/dbtx"
@ -22,9 +23,12 @@ import (
"github.com/jmoiron/sqlx" "github.com/jmoiron/sqlx"
) )
func ProvideUpstreamDao(db *sqlx.DB, func ProvideUpstreamDao(
registryDao store.RegistryRepository) store.UpstreamProxyConfigRepository { db *sqlx.DB,
return NewUpstreamproxyDao(db, registryDao) registryDao store.RegistryRepository,
spacePathStore corestore.SpacePathStore,
) store.UpstreamProxyConfigRepository {
return NewUpstreamproxyDao(db, registryDao, spacePathStore)
} }
func ProvideRepoDao(db *sqlx.DB, mtRepository store.MediaTypesRepository) store.RegistryRepository { func ProvideRepoDao(db *sqlx.DB, mtRepository store.MediaTypesRepository) store.RegistryRepository {

View File

@ -15,7 +15,6 @@
package types package types
import ( import (
"database/sql"
"time" "time"
"github.com/harness/gitness/registry/app/api/openapi/contracts/artifact" "github.com/harness/gitness/registry/app/api/openapi/contracts/artifact"
@ -51,8 +50,9 @@ type UpstreamProxy struct {
RepoURL string RepoURL string
RepoAuthType string RepoAuthType string
UserName string UserName string
SecretIdentifier sql.NullString SecretIdentifier string
SecretSpaceID sql.NullInt32 SecretSpaceID int64
SecretSpacePath string
Token string Token string
CreatedAt time.Time CreatedAt time.Time
UpdatedAt time.Time UpdatedAt time.Time