mirror of
https://github.com/harness/drone.git
synced 2025-05-12 23:20:10 +08:00
fix: [AH-602]: fix registry urls (#2931)
* fix: [AH-602]: fix registry urls
This commit is contained in:
parent
3404495893
commit
0d65a0df3a
@ -19,6 +19,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/harness/gitness/app/url"
|
||||||
artifactapi "github.com/harness/gitness/registry/app/api/openapi/contracts/artifact"
|
artifactapi "github.com/harness/gitness/registry/app/api/openapi/contracts/artifact"
|
||||||
"github.com/harness/gitness/registry/types"
|
"github.com/harness/gitness/registry/types"
|
||||||
|
|
||||||
@ -26,11 +27,14 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func GetArtifactMetadata(
|
func GetArtifactMetadata(
|
||||||
|
ctx context.Context,
|
||||||
artifacts []types.ArtifactMetadata,
|
artifacts []types.ArtifactMetadata,
|
||||||
registryURL string,
|
rootIdentifier string,
|
||||||
|
urlProvider url.Provider,
|
||||||
) []artifactapi.ArtifactMetadata {
|
) []artifactapi.ArtifactMetadata {
|
||||||
artifactMetadataList := make([]artifactapi.ArtifactMetadata, 0, len(artifacts))
|
artifactMetadataList := make([]artifactapi.ArtifactMetadata, 0, len(artifacts))
|
||||||
for _, artifact := range artifacts {
|
for _, artifact := range artifacts {
|
||||||
|
registryURL := urlProvider.RegistryRefURL(ctx, GetRegistryRef(rootIdentifier, artifact.RepoName))
|
||||||
artifactMetadata := mapToArtifactMetadata(artifact, registryURL)
|
artifactMetadata := mapToArtifactMetadata(artifact, registryURL)
|
||||||
artifactMetadataList = append(artifactMetadataList, *artifactMetadata)
|
artifactMetadataList = append(artifactMetadataList, *artifactMetadata)
|
||||||
}
|
}
|
||||||
@ -129,17 +133,19 @@ func GetTagMetadata(
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetAllArtifactResponse(
|
func GetAllArtifactResponse(
|
||||||
|
ctx context.Context,
|
||||||
artifacts *[]types.ArtifactMetadata,
|
artifacts *[]types.ArtifactMetadata,
|
||||||
count int64,
|
count int64,
|
||||||
pageNumber int64,
|
pageNumber int64,
|
||||||
pageSize int,
|
pageSize int,
|
||||||
registryURL string,
|
rootIdentifier string,
|
||||||
|
urlProvider url.Provider,
|
||||||
) *artifactapi.ListArtifactResponseJSONResponse {
|
) *artifactapi.ListArtifactResponseJSONResponse {
|
||||||
var artifactMetadataList []artifactapi.ArtifactMetadata
|
var artifactMetadataList []artifactapi.ArtifactMetadata
|
||||||
if artifacts == nil {
|
if artifacts == nil {
|
||||||
artifactMetadataList = make([]artifactapi.ArtifactMetadata, 0)
|
artifactMetadataList = make([]artifactapi.ArtifactMetadata, 0)
|
||||||
} else {
|
} else {
|
||||||
artifactMetadataList = GetArtifactMetadata(*artifacts, registryURL)
|
artifactMetadataList = GetArtifactMetadata(ctx, *artifacts, rootIdentifier, urlProvider)
|
||||||
}
|
}
|
||||||
pageCount := GetPageCount(count, pageSize)
|
pageCount := GetPageCount(count, pageSize)
|
||||||
listArtifact := &artifactapi.ListArtifact{
|
listArtifact := &artifactapi.ListArtifact{
|
||||||
|
@ -143,11 +143,11 @@ func (c *APIController) createVirtualRegistry(
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return throwCreateRegistry400Error(err), nil
|
return throwCreateRegistry400Error(err), nil
|
||||||
}
|
}
|
||||||
|
repoURL := c.URLProvider.RegistryRefURL(ctx, GetRegistryRef(regInfo.RootIdentifier, repoEntity.Name))
|
||||||
return artifact.CreateRegistry201JSONResponse{
|
return artifact.CreateRegistry201JSONResponse{
|
||||||
RegistryResponseJSONResponse: *CreateVirtualRepositoryResponse(
|
RegistryResponseJSONResponse: *CreateVirtualRepositoryResponse(
|
||||||
repoEntity, c.getUpstreamProxyKeys(ctx, repoEntity.UpstreamProxies),
|
repoEntity, c.getUpstreamProxyKeys(ctx, repoEntity.UpstreamProxies),
|
||||||
cleanupPolicies, c.URLProvider.RegistryRefURL(ctx, regInfo.RegistryRef),
|
cleanupPolicies, repoURL,
|
||||||
),
|
),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
@ -88,8 +88,8 @@ func (c *APIController) GetAllArtifacts(
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
return artifact.GetAllArtifacts200JSONResponse{
|
return artifact.GetAllArtifacts200JSONResponse{
|
||||||
ListArtifactResponseJSONResponse: *GetAllArtifactResponse(artifacts, count, regInfo.pageNumber, regInfo.limit,
|
ListArtifactResponseJSONResponse: *GetAllArtifactResponse(ctx, artifacts, count, regInfo.pageNumber, regInfo.limit,
|
||||||
c.URLProvider.RegistryRefURL(ctx, regInfo.RegistryRef)),
|
regInfo.RootIdentifier, c.URLProvider),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@ import (
|
|||||||
|
|
||||||
apiauth "github.com/harness/gitness/app/api/auth"
|
apiauth "github.com/harness/gitness/app/api/auth"
|
||||||
"github.com/harness/gitness/app/api/request"
|
"github.com/harness/gitness/app/api/request"
|
||||||
|
"github.com/harness/gitness/app/url"
|
||||||
"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/pkg/commons"
|
"github.com/harness/gitness/registry/app/pkg/commons"
|
||||||
"github.com/harness/gitness/registry/app/store"
|
"github.com/harness/gitness/registry/app/store"
|
||||||
@ -112,21 +113,23 @@ func (c *APIController) GetAllRegistries(
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
return artifact.GetAllRegistries200JSONResponse{
|
return artifact.GetAllRegistries200JSONResponse{
|
||||||
ListRegistryResponseJSONResponse: *GetAllRegistryResponse(
|
ListRegistryResponseJSONResponse: *GetAllRegistryResponse(ctx,
|
||||||
repos, count, regInfo.pageNumber,
|
repos, count, regInfo.pageNumber,
|
||||||
regInfo.limit, c.URLProvider.RegistryRefURL(ctx, regInfo.RegistryRef),
|
regInfo.limit, regInfo.RootIdentifier, c.URLProvider,
|
||||||
),
|
),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetAllRegistryResponse(
|
func GetAllRegistryResponse(
|
||||||
|
ctx context.Context,
|
||||||
repos *[]store.RegistryMetadata,
|
repos *[]store.RegistryMetadata,
|
||||||
count int64,
|
count int64,
|
||||||
pageNumber int64,
|
pageNumber int64,
|
||||||
pageSize int,
|
pageSize int,
|
||||||
registryURL string,
|
rootIdentifier string,
|
||||||
|
urlProvider url.Provider,
|
||||||
) *artifact.ListRegistryResponseJSONResponse {
|
) *artifact.ListRegistryResponseJSONResponse {
|
||||||
repoMetadataList := GetRegistryMetadata(repos, registryURL)
|
repoMetadataList := GetRegistryMetadata(ctx, repos, rootIdentifier, urlProvider)
|
||||||
pageCount := GetPageCount(count, pageSize)
|
pageCount := GetPageCount(count, pageSize)
|
||||||
listRepository := &artifact.ListRegistry{
|
listRepository := &artifact.ListRegistry{
|
||||||
ItemCount: &count,
|
ItemCount: &count,
|
||||||
@ -143,8 +146,10 @@ func GetAllRegistryResponse(
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetRegistryMetadata(
|
func GetRegistryMetadata(
|
||||||
|
ctx context.Context,
|
||||||
registryMetadatas *[]store.RegistryMetadata,
|
registryMetadatas *[]store.RegistryMetadata,
|
||||||
registryURL string,
|
rootIdentifier string,
|
||||||
|
urlProvider url.Provider,
|
||||||
) []artifact.RegistryMetadata {
|
) []artifact.RegistryMetadata {
|
||||||
repoMetadataList := []artifact.RegistryMetadata{}
|
repoMetadataList := []artifact.RegistryMetadata{}
|
||||||
for _, reg := range *registryMetadatas {
|
for _, reg := range *registryMetadatas {
|
||||||
@ -174,7 +179,7 @@ func GetRegistryMetadata(
|
|||||||
PackageType: reg.PackageType,
|
PackageType: reg.PackageType,
|
||||||
Type: reg.Type,
|
Type: reg.Type,
|
||||||
LastModified: &modifiedAt,
|
LastModified: &modifiedAt,
|
||||||
Url: registryURL,
|
Url: urlProvider.RegistryRefURL(ctx, GetRegistryRef(rootIdentifier, reg.RegIdentifier)),
|
||||||
ArtifactsCount: artifactCount,
|
ArtifactsCount: artifactCount,
|
||||||
DownloadsCount: downloadCount,
|
DownloadsCount: downloadCount,
|
||||||
RegistrySize: &size,
|
RegistrySize: &size,
|
||||||
|
@ -19,7 +19,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"net/url"
|
"net/url"
|
||||||
"path"
|
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -313,14 +312,8 @@ func GetSize(sizeVal int64) string {
|
|||||||
return size.String()
|
return size.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetRepoURL(rootIdentifier, registry string, registryURL string) string {
|
func GetRegistryRef(rootIdentifier string, registryName string) string {
|
||||||
parsedURL, err := url.Parse(registryURL)
|
return rootIdentifier + "/" + registryName
|
||||||
if err != nil {
|
|
||||||
log.Error().Err(err).Msgf("Error parsing URL: %s", registryURL)
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
parsedURL.Path = path.Join(parsedURL.Path, strings.ToLower(rootIdentifier), registry)
|
|
||||||
return parsedURL.String()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetRepoURLWithoutProtocol(registryURL string) string {
|
func GetRepoURLWithoutProtocol(registryURL string) string {
|
||||||
|
Loading…
Reference in New Issue
Block a user