mirror of https://github.com/harness/drone.git
fix: [AH-306c]: fix anonymous flow (#2573)
* lint fixes * fix: [AH-306]: fix anonymous flow - address review comments * fix: [AH-306c]: fix anonymous flow - address review comments * fix: [AH-306c]: fix anonymous flow * fix: [AH-306c]: fix anonymous flow * fix: [AH-306c]: fix anonymous flowpull/3545/head
parent
af6e94ba2c
commit
d52a142cdb
|
@ -315,9 +315,13 @@ 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
|
||||||
// FIXME: Mask this password.
|
auth.SecretIdentifier = &upstreamproxy.SecretIdentifier.String
|
||||||
auth.SecretIdentifier = &upstreamproxy.SecretIdentifier
|
auth.SecretSpaceId = nil
|
||||||
auth.SecretSpaceId = &upstreamproxy.SecretSpaceID
|
if upstreamproxy.SecretSpaceID.Valid {
|
||||||
|
// Convert int32 to int and assign to the expected field
|
||||||
|
secretSpaceID := int(upstreamproxy.SecretSpaceID.Int32)
|
||||||
|
auth.SecretSpaceId = &secretSpaceID
|
||||||
|
}
|
||||||
_ = configAuth.FromUserPassword(auth)
|
_ = configAuth.FromUserPassword(auth)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -156,11 +156,12 @@ func ValidateIdentifier(identifier string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func ValidateUpstream(config *api.RegistryConfig) error {
|
func ValidateUpstream(config *api.RegistryConfig) error {
|
||||||
if !commons.IsEmpty(config.Type) && config.Type == api.RegistryTypeUPSTREAM {
|
|
||||||
upstreamConfig, err := config.AsUpstreamConfig()
|
upstreamConfig, err := config.AsUpstreamConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if !commons.IsEmpty(config.Type) && config.Type == api.RegistryTypeUPSTREAM &&
|
||||||
|
*upstreamConfig.Source != api.UpstreamConfigSourceDockerhub {
|
||||||
if commons.IsEmpty(upstreamConfig.Url) {
|
if commons.IsEmpty(upstreamConfig.Url) {
|
||||||
return errors.New("URL is required for upstream repository")
|
return errors.New("URL is required for upstream repository")
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,7 +71,16 @@ func getPwd(
|
||||||
) string {
|
) string {
|
||||||
password := ""
|
password := ""
|
||||||
if api.AuthType(reg.RepoAuthType) == api.AuthTypeUserPassword {
|
if api.AuthType(reg.RepoAuthType) == api.AuthTypeUserPassword {
|
||||||
secret, err := secretStore.FindByIdentifier(ctx, int64(reg.SecretSpaceID), reg.SecretIdentifier)
|
secretSpaceID := int64(0)
|
||||||
|
if reg.SecretSpaceID.Valid {
|
||||||
|
secretSpaceID = int64(reg.SecretSpaceID.Int32)
|
||||||
|
}
|
||||||
|
|
||||||
|
secretIdentifier := ""
|
||||||
|
if reg.SecretIdentifier.Valid {
|
||||||
|
secretIdentifier = reg.SecretIdentifier.String
|
||||||
|
}
|
||||||
|
secret, err := secretStore.FindByIdentifier(ctx, secretSpaceID, secretIdentifier)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Msgf("failed to find secret: %v", err)
|
log.Error().Msgf("failed to find secret: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -286,7 +286,7 @@ func (a ArtifactDao) mapToInternalArtifact(ctx context.Context, in *types.Artifa
|
||||||
ID: in.ID,
|
ID: in.ID,
|
||||||
Name: in.Name,
|
Name: in.Name,
|
||||||
RegistryID: in.RegistryID,
|
RegistryID: in.RegistryID,
|
||||||
Labels: getEmptySQLString(util.ArrToString(in.Labels)),
|
Labels: util.GetEmptySQLString(util.ArrToString(in.Labels)),
|
||||||
Enabled: in.Enabled,
|
Enabled: in.Enabled,
|
||||||
CreatedAt: in.CreatedAt.UnixMilli(),
|
CreatedAt: in.CreatedAt.UnixMilli(),
|
||||||
UpdatedAt: in.UpdatedAt.UnixMilli(),
|
UpdatedAt: in.UpdatedAt.UnixMilli(),
|
||||||
|
|
|
@ -376,13 +376,13 @@ func mapToInternalRegistry(ctx context.Context, in *types.Registry) *registryDB
|
||||||
Name: in.Name,
|
Name: in.Name,
|
||||||
ParentID: in.ParentID,
|
ParentID: in.ParentID,
|
||||||
RootParentID: in.RootParentID,
|
RootParentID: in.RootParentID,
|
||||||
Description: getEmptySQLString(in.Description),
|
Description: util.GetEmptySQLString(in.Description),
|
||||||
Type: in.Type,
|
Type: in.Type,
|
||||||
PackageType: in.PackageType,
|
PackageType: in.PackageType,
|
||||||
UpstreamProxies: getEmptySQLString(util.Int64ArrToString(in.UpstreamProxies)),
|
UpstreamProxies: util.GetEmptySQLString(util.Int64ArrToString(in.UpstreamProxies)),
|
||||||
AllowedPattern: getEmptySQLString(util.ArrToString(in.AllowedPattern)),
|
AllowedPattern: util.GetEmptySQLString(util.ArrToString(in.AllowedPattern)),
|
||||||
BlockedPattern: getEmptySQLString(util.ArrToString(in.BlockedPattern)),
|
BlockedPattern: util.GetEmptySQLString(util.ArrToString(in.BlockedPattern)),
|
||||||
Labels: getEmptySQLString(util.ArrToString(in.Labels)),
|
Labels: util.GetEmptySQLString(util.ArrToString(in.Labels)),
|
||||||
CreatedAt: in.CreatedAt.UnixMilli(),
|
CreatedAt: in.CreatedAt.UnixMilli(),
|
||||||
UpdatedAt: in.UpdatedAt.UnixMilli(),
|
UpdatedAt: in.UpdatedAt.UnixMilli(),
|
||||||
CreatedBy: in.CreatedBy,
|
CreatedBy: in.CreatedBy,
|
||||||
|
@ -390,13 +390,6 @@ func mapToInternalRegistry(ctx context.Context, in *types.Registry) *registryDB
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getEmptySQLString(str string) sql.NullString {
|
|
||||||
if commons.IsEmpty(str) {
|
|
||||||
return sql.NullString{String: str, Valid: false}
|
|
||||||
}
|
|
||||||
return sql.NullString{String: str, Valid: true}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r registryDao) Delete(ctx context.Context, parentID int64, name string) (err error) {
|
func (r registryDao) Delete(ctx context.Context, parentID int64, name string) (err error) {
|
||||||
stmt := databaseg.Builder.Delete("registries").
|
stmt := databaseg.Builder.Delete("registries").
|
||||||
Where("registry_parent_id = ? AND registry_name = ?", parentID, name)
|
Where("registry_parent_id = ? AND registry_name = ?", parentID, name)
|
||||||
|
|
|
@ -374,7 +374,7 @@ func (t tagDao) GetAllArtifactsByParentID(
|
||||||
|
|
||||||
if len(labels) > 0 {
|
if len(labels) > 0 {
|
||||||
sort.Strings(labels)
|
sort.Strings(labels)
|
||||||
labelsVal := getEmptySQLString(util.ArrToString(labels))
|
labelsVal := util.GetEmptySQLString(util.ArrToString(labels))
|
||||||
|
|
||||||
labelsVal.String = labelSeparatorStart + labelsVal.String + labelSeparatorEnd
|
labelsVal.String = labelSeparatorStart + labelsVal.String + labelSeparatorEnd
|
||||||
q = q.Where("'^_' || ar.artifact_labels || '^_' LIKE ?", labelsVal)
|
q = q.Where("'^_' || ar.artifact_labels || '^_' LIKE ?", labelsVal)
|
||||||
|
@ -430,7 +430,7 @@ func (t tagDao) CountAllArtifactsByParentID(
|
||||||
|
|
||||||
if len(labels) > 0 {
|
if len(labels) > 0 {
|
||||||
sort.Strings(labels)
|
sort.Strings(labels)
|
||||||
labelsVal := getEmptySQLString(util.ArrToString(labels))
|
labelsVal := util.GetEmptySQLString(util.ArrToString(labels))
|
||||||
labelsVal.String = labelSeparatorStart + labelsVal.String + labelSeparatorEnd
|
labelsVal.String = labelSeparatorStart + labelsVal.String + labelSeparatorEnd
|
||||||
q = q.Where("'^_' || ar.artifact_labels || '^_' LIKE ?", labelsVal)
|
q = q.Where("'^_' || ar.artifact_labels || '^_' LIKE ?", labelsVal)
|
||||||
}
|
}
|
||||||
|
@ -645,7 +645,7 @@ func (t tagDao) GetAllArtifactsByRepo(
|
||||||
|
|
||||||
if len(labels) > 0 {
|
if len(labels) > 0 {
|
||||||
sort.Strings(labels)
|
sort.Strings(labels)
|
||||||
labelsVal := getEmptySQLString(util.ArrToString(labels))
|
labelsVal := util.GetEmptySQLString(util.ArrToString(labels))
|
||||||
labelsVal.String = labelSeparatorStart + labelsVal.String + labelSeparatorEnd
|
labelsVal.String = labelSeparatorStart + labelsVal.String + labelSeparatorEnd
|
||||||
q = q.Where("'^_' || ar.artifact_labels || '^_' LIKE ?", labelsVal)
|
q = q.Where("'^_' || ar.artifact_labels || '^_' LIKE ?", labelsVal)
|
||||||
}
|
}
|
||||||
|
@ -691,7 +691,7 @@ func (t tagDao) CountAllArtifactsByRepo(
|
||||||
|
|
||||||
if len(labels) > 0 {
|
if len(labels) > 0 {
|
||||||
sort.Strings(labels)
|
sort.Strings(labels)
|
||||||
labelsVal := getEmptySQLString(util.ArrToString(labels))
|
labelsVal := util.GetEmptySQLString(util.ArrToString(labels))
|
||||||
labelsVal.String = labelSeparatorStart + labelsVal.String + labelSeparatorEnd
|
labelsVal.String = labelSeparatorStart + labelsVal.String + labelSeparatorEnd
|
||||||
q = q.Where("'^_' || ar.artifact_labels || '^_' LIKE ?", labelsVal)
|
q = q.Where("'^_' || ar.artifact_labels || '^_' LIKE ?", labelsVal)
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,8 +54,8 @@ type upstreamProxyConfigDB struct {
|
||||||
URL string `db:"upstream_proxy_config_url"`
|
URL string `db:"upstream_proxy_config_url"`
|
||||||
AuthType string `db:"upstream_proxy_config_auth_type"`
|
AuthType string `db:"upstream_proxy_config_auth_type"`
|
||||||
UserName string `db:"upstream_proxy_config_user_name"`
|
UserName string `db:"upstream_proxy_config_user_name"`
|
||||||
SecretIdentifier string `db:"upstream_proxy_config_secret_identifier"`
|
SecretIdentifier sql.NullString `db:"upstream_proxy_config_secret_identifier"`
|
||||||
SecretSpaceID int `db:"upstream_proxy_config_secret_space_id"`
|
SecretSpaceID sql.NullInt32 `db:"upstream_proxy_config_secret_space_id"`
|
||||||
Token string `db:"upstream_proxy_config_token"`
|
Token string `db:"upstream_proxy_config_token"`
|
||||||
CreatedAt int64 `db:"upstream_proxy_config_created_at"`
|
CreatedAt int64 `db:"upstream_proxy_config_created_at"`
|
||||||
UpdatedAt int64 `db:"upstream_proxy_config_updated_at"`
|
UpdatedAt int64 `db:"upstream_proxy_config_updated_at"`
|
||||||
|
@ -75,8 +75,8 @@ type upstreamProxyDB struct {
|
||||||
RepoURL string `db:"repo_url"`
|
RepoURL string `db:"repo_url"`
|
||||||
RepoAuthType string `db:"repo_auth_type"`
|
RepoAuthType string `db:"repo_auth_type"`
|
||||||
UserName string `db:"user_name"`
|
UserName string `db:"user_name"`
|
||||||
SecretIdentifier string `db:"secret_identifier"`
|
SecretIdentifier sql.NullString `db:"secret_identifier"`
|
||||||
SecretSpaceID int `db:"secret_space_id"`
|
SecretSpaceID sql.NullInt32 `db:"secret_space_id"`
|
||||||
Token string `db:"token"`
|
Token string `db:"token"`
|
||||||
CreatedAt int64 `db:"created_at"`
|
CreatedAt int64 `db:"created_at"`
|
||||||
UpdatedAt int64 `db:"updated_at"`
|
UpdatedAt int64 `db:"updated_at"`
|
||||||
|
@ -360,8 +360,8 @@ func (r UpstreamproxyDao) mapToInternalUpstreamProxy(
|
||||||
URL: in.URL,
|
URL: in.URL,
|
||||||
AuthType: in.AuthType,
|
AuthType: in.AuthType,
|
||||||
UserName: in.UserName,
|
UserName: in.UserName,
|
||||||
SecretIdentifier: in.SecretIdentifier,
|
SecretIdentifier: util.GetEmptySQLString(in.SecretIdentifier),
|
||||||
SecretSpaceID: in.SecretSpaceID,
|
SecretSpaceID: util.GetEmptySQLInt32(in.SecretSpaceID),
|
||||||
Token: in.Token,
|
Token: in.Token,
|
||||||
CreatedAt: in.CreatedAt.UnixMilli(),
|
CreatedAt: in.CreatedAt.UnixMilli(),
|
||||||
UpdatedAt: in.UpdatedAt.UnixMilli(),
|
UpdatedAt: in.UpdatedAt.UnixMilli(),
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
// 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 util
|
||||||
|
|
||||||
|
import (
|
||||||
|
"database/sql"
|
||||||
|
|
||||||
|
"github.com/harness/gitness/registry/app/pkg/commons"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetEmptySQLString(str string) sql.NullString {
|
||||||
|
if commons.IsEmpty(str) {
|
||||||
|
return sql.NullString{String: str, Valid: false}
|
||||||
|
}
|
||||||
|
return sql.NullString{String: str, Valid: true}
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetEmptySQLInt32(i int) sql.NullInt32 {
|
||||||
|
if i == 0 {
|
||||||
|
return sql.NullInt32{Int32: int32(i), Valid: false}
|
||||||
|
}
|
||||||
|
return sql.NullInt32{Int32: int32(i), Valid: true}
|
||||||
|
}
|
|
@ -15,6 +15,7 @@
|
||||||
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"
|
||||||
|
@ -50,8 +51,8 @@ type UpstreamProxy struct {
|
||||||
RepoURL string
|
RepoURL string
|
||||||
RepoAuthType string
|
RepoAuthType string
|
||||||
UserName string
|
UserName string
|
||||||
SecretIdentifier string
|
SecretIdentifier sql.NullString
|
||||||
SecretSpaceID int
|
SecretSpaceID sql.NullInt32
|
||||||
Token string
|
Token string
|
||||||
CreatedAt time.Time
|
CreatedAt time.Time
|
||||||
UpdatedAt time.Time
|
UpdatedAt time.Time
|
||||||
|
|
Loading…
Reference in New Issue