mirror of
https://github.com/harness/drone.git
synced 2025-04-28 05:36:58 +00:00
fix: [AH-818]: fix configure upstream proxy order change is not working (#3447)
* feat: [AH-818]: fix go lint errors * feat: [AH-818]: fix PR comments * feat: [AH-818]: fix PR comments * feat: [AH-818]: fix linting errors * feat: [AH-818]: fix failing lint test * fix: [AH-818]: fix configure upstream proxy order change is not working
This commit is contained in:
parent
cad0fbdf98
commit
563fedf028
registry
@ -269,8 +269,8 @@ func (c *APIController) setUpstreamProxyIDs(
|
|||||||
}
|
}
|
||||||
|
|
||||||
var upstreamProxies []int64
|
var upstreamProxies []int64
|
||||||
for _, repo := range *repos {
|
for _, proxy := range *virtualConfig.UpstreamProxies {
|
||||||
for _, proxy := range *virtualConfig.UpstreamProxies {
|
for _, repo := range *repos {
|
||||||
if repo.RegIdentifier == proxy {
|
if repo.RegIdentifier == proxy {
|
||||||
regID, err := strconv.ParseInt(repo.RegID, 10, 64)
|
regID, err := strconv.ParseInt(repo.RegID, 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -26,6 +26,7 @@ import (
|
|||||||
"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"
|
||||||
"github.com/harness/gitness/registry/types"
|
"github.com/harness/gitness/registry/types"
|
||||||
|
"github.com/harness/gitness/registry/utils"
|
||||||
gitnessstore "github.com/harness/gitness/store"
|
gitnessstore "github.com/harness/gitness/store"
|
||||||
databaseg "github.com/harness/gitness/store/database"
|
databaseg "github.com/harness/gitness/store/database"
|
||||||
"github.com/harness/gitness/store/database/dbtx"
|
"github.com/harness/gitness/store/database/dbtx"
|
||||||
@ -73,6 +74,11 @@ type registryDB struct {
|
|||||||
UpdatedBy int64 `db:"registry_updated_by"`
|
UpdatedBy int64 `db:"registry_updated_by"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type registryNameID struct {
|
||||||
|
ID int64 `db:"registry_id"`
|
||||||
|
Name string `db:"registry_name"`
|
||||||
|
}
|
||||||
|
|
||||||
func (r registryDao) Get(ctx context.Context, id int64) (*types.Registry, error) {
|
func (r registryDao) Get(ctx context.Context, id int64) (*types.Registry, error) {
|
||||||
stmt := databaseg.Builder.
|
stmt := databaseg.Builder.
|
||||||
Select(util.ArrToStringByDelimiter(util.GetDBTagsFromStruct(registryDB{}), ",")).
|
Select(util.ArrToStringByDelimiter(util.GetDBTagsFromStruct(registryDB{}), ",")).
|
||||||
@ -165,19 +171,21 @@ func (r registryDao) FetchUpstreamProxyKeys(
|
|||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
ids []int64,
|
ids []int64,
|
||||||
) (repokeys []string, err error) {
|
) (repokeys []string, err error) {
|
||||||
dst := make([]string, 0)
|
orderedRepoKeys := make([]string, 0)
|
||||||
|
|
||||||
if commons.IsEmpty(ids) {
|
if commons.IsEmpty(ids) {
|
||||||
return dst, nil
|
return orderedRepoKeys, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
stmt := databaseg.Builder.
|
stmt := databaseg.Builder.
|
||||||
Select("registry_name").
|
Select(util.ArrToStringByDelimiter(util.GetDBTagsFromStruct(registryNameID{}), ",")).
|
||||||
From("registries").
|
From("registries").
|
||||||
Where(sq.Eq{"registry_id": ids}).
|
Where(sq.Eq{"registry_id": ids}).
|
||||||
Where("registry_type = ?", artifact.RegistryTypeUPSTREAM)
|
Where("registry_type = ?", artifact.RegistryTypeUPSTREAM)
|
||||||
|
|
||||||
db := dbtx.GetAccessor(ctx, r.db)
|
db := dbtx.GetAccessor(ctx, r.db)
|
||||||
|
|
||||||
|
dst := []registryNameID{}
|
||||||
sql, args, err := stmt.ToSql()
|
sql, args, err := stmt.ToSql()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "Failed to convert query to sql")
|
return nil, errors.Wrap(err, "Failed to convert query to sql")
|
||||||
@ -186,7 +194,24 @@ func (r registryDao) FetchUpstreamProxyKeys(
|
|||||||
if err = db.SelectContext(ctx, &dst, sql, args...); err != nil {
|
if err = db.SelectContext(ctx, &dst, sql, args...); err != nil {
|
||||||
return nil, databaseg.ProcessSQLErrorf(ctx, err, "Failed to find repo")
|
return nil, databaseg.ProcessSQLErrorf(ctx, err, "Failed to find repo")
|
||||||
}
|
}
|
||||||
return dst, nil
|
|
||||||
|
// Create a map
|
||||||
|
recordMap := make(map[int64]registryNameID)
|
||||||
|
for _, record := range dst {
|
||||||
|
recordMap[record.ID] = record
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reorder the fetched records based on the ID list
|
||||||
|
for _, id := range ids {
|
||||||
|
if record, exists := recordMap[id]; exists {
|
||||||
|
orderedRepoKeys = append(orderedRepoKeys, record.Name)
|
||||||
|
} else {
|
||||||
|
log.Ctx(ctx).Error().Msgf("failed to map upstream registry: %d", id)
|
||||||
|
orderedRepoKeys = append(orderedRepoKeys, "")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return orderedRepoKeys, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r registryDao) GetByIDIn(ctx context.Context, ids []int64) (*[]types.Registry, error) {
|
func (r registryDao) GetByIDIn(ctx context.Context, ids []int64) (*[]types.Registry, error) {
|
||||||
@ -335,7 +360,7 @@ func (r registryDao) GetAll(
|
|||||||
} else {
|
} else {
|
||||||
query = query.OrderBy(fmt.Sprintf("r.registry_%s %s", sortByField, sortByOrder))
|
query = query.OrderBy(fmt.Sprintf("r.registry_%s %s", sortByField, sortByOrder))
|
||||||
}
|
}
|
||||||
query = query.Limit(uint64(limit)).Offset(uint64(offset))
|
query = query.Limit(utils.SafeUint64(limit)).Offset(utils.SafeUint64(offset))
|
||||||
|
|
||||||
// Convert query to SQL
|
// Convert query to SQL
|
||||||
sql, args, err := query.ToSql()
|
sql, args, err := query.ToSql()
|
||||||
|
@ -33,3 +33,10 @@ func HasAnySuffix(s string, prefixes []string) bool {
|
|||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func SafeUint64(n int) uint64 {
|
||||||
|
if n < 0 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return uint64(n)
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user