mirror of https://github.com/harness/drone.git
feat: [AH-364]: SSCA/STO integrations - global artifacts, summary card (#2752)
* feat: [AH-364]: SSCA/STO integrations - global artifacts, summary card: review comments * feat: [AH-364]: SSCA/STO integrations - global artifacts, summary cardabhinav-harness-patch-1
parent
3e7ee33b94
commit
b761fa9de1
|
@ -25,8 +25,8 @@ import (
|
|||
"github.com/harness/gitness/app/api/request"
|
||||
"github.com/harness/gitness/registry/app/api/openapi/contracts/artifact"
|
||||
ml "github.com/harness/gitness/registry/app/manifest/manifestlist"
|
||||
os "github.com/harness/gitness/registry/app/manifest/ocischema"
|
||||
s2 "github.com/harness/gitness/registry/app/manifest/schema2"
|
||||
"github.com/harness/gitness/registry/app/manifest/ocischema"
|
||||
"github.com/harness/gitness/registry/app/manifest/schema2"
|
||||
"github.com/harness/gitness/registry/app/pkg/docker"
|
||||
"github.com/harness/gitness/registry/types"
|
||||
store2 "github.com/harness/gitness/store"
|
||||
|
@ -74,47 +74,16 @@ func (c *APIController) GetDockerArtifactManifests(
|
|||
|
||||
image := string(r.Artifact)
|
||||
version := string(r.Version)
|
||||
registry, err := c.RegistryRepository.GetByParentIDAndName(ctx, regInfo.parentID, regInfo.RegistryIdentifier)
|
||||
manifestDetailsList, err := c.ProcessManifest(ctx, regInfo, image, version)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
t, err := c.TagStore.FindTag(ctx, registry.ID, image, version)
|
||||
if err != nil && !errors.Is(err, sql.ErrNoRows) {
|
||||
return nil, err
|
||||
}
|
||||
m, err := c.ManifestStore.Get(ctx, t.ManifestID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
manifest, err := docker.DBManifestToManifest(m)
|
||||
manifestDetailsList := []artifact.DockerManifestDetails{}
|
||||
switch reqManifest := manifest.(type) {
|
||||
case *s2.DeserializedManifest:
|
||||
mConfig, err := getManifestConfig(ctx, reqManifest.Config().Digest, regInfo.RootIdentifier, c.StorageDriver)
|
||||
if err != nil {
|
||||
return artifactManifestsErrorRs(err), nil
|
||||
}
|
||||
manifestDetailsList = append(manifestDetailsList, getManifestDetails(m, mConfig))
|
||||
case *os.DeserializedManifest:
|
||||
mConfig, err := getManifestConfig(ctx, reqManifest.Config().Digest, regInfo.RootIdentifier, c.StorageDriver)
|
||||
if err != nil {
|
||||
return artifactManifestsErrorRs(err), nil
|
||||
}
|
||||
manifestDetailsList = append(manifestDetailsList, getManifestDetails(m, mConfig))
|
||||
case *ml.DeserializedManifestList:
|
||||
manifestDetailsList, err = c.getManifestList(ctx, reqManifest, registry, image, regInfo)
|
||||
if err != nil {
|
||||
return artifactManifestsErrorRs(err), nil
|
||||
}
|
||||
default:
|
||||
log.Ctx(ctx).Error().Stack().Err(err).Msgf("Unknown manifest type: %T", manifest)
|
||||
return artifactManifestsErrorRs(err), nil
|
||||
}
|
||||
|
||||
return artifact.GetDockerArtifactManifests200JSONResponse{
|
||||
DockerManifestsResponseJSONResponse: artifact.DockerManifestsResponseJSONResponse{
|
||||
Data: artifact.DockerManifests{
|
||||
ImageName: t.ImageName,
|
||||
Version: t.Name,
|
||||
ImageName: image,
|
||||
Version: version,
|
||||
Manifests: &manifestDetailsList,
|
||||
},
|
||||
Status: artifact.StatusSUCCESS,
|
||||
|
@ -176,3 +145,53 @@ func getManifestDetails(m *types.Manifest, mConfig *manifestConfig) artifact.Doc
|
|||
}
|
||||
return manifestDetails
|
||||
}
|
||||
|
||||
// ProcessManifest processes a Docker artifact manifest by retrieving the manifest details from the database,
|
||||
// converting it to the appropriate format, and extracting the necessary information based on the manifest type.
|
||||
// It handles different types of manifests, including schema2, OCI schema, and manifest lists, and returns a list
|
||||
// of Docker manifest details.
|
||||
func (c *APIController) ProcessManifest(
|
||||
ctx context.Context,
|
||||
regInfo *RegistryRequestBaseInfo,
|
||||
image, version string,
|
||||
) ([]artifact.DockerManifestDetails, error) {
|
||||
registry, err := c.RegistryRepository.Get(ctx, regInfo.rootIdentifierID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
t, err := c.TagStore.FindTag(ctx, registry.ID, image, version)
|
||||
if err != nil && !errors.Is(err, sql.ErrNoRows) {
|
||||
return nil, err
|
||||
}
|
||||
m, err := c.ManifestStore.Get(ctx, t.ManifestID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
manifest, err := docker.DBManifestToManifest(m)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
manifestDetailsList := []artifact.DockerManifestDetails{}
|
||||
switch reqManifest := manifest.(type) {
|
||||
case *schema2.DeserializedManifest:
|
||||
mConfig, err := getManifestConfig(ctx, reqManifest.Config().Digest, regInfo.RootIdentifier, c.StorageDriver)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
manifestDetailsList = append(manifestDetailsList, getManifestDetails(m, mConfig))
|
||||
case *ocischema.DeserializedManifest:
|
||||
mConfig, err := getManifestConfig(ctx, reqManifest.Config().Digest, regInfo.RootIdentifier, c.StorageDriver)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
manifestDetailsList = append(manifestDetailsList, getManifestDetails(m, mConfig))
|
||||
case *ml.DeserializedManifestList:
|
||||
manifestDetailsList, err = c.getManifestList(ctx, reqManifest, registry, image, regInfo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
default:
|
||||
log.Ctx(ctx).Error().Stack().Err(err).Msgf("Unknown manifest type: %T", manifest)
|
||||
}
|
||||
return manifestDetailsList, nil
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
api "github.com/harness/gitness/registry/app/api/openapi/contracts/artifact"
|
||||
a "github.com/harness/gitness/registry/app/api/openapi/contracts/artifact"
|
||||
"github.com/harness/gitness/registry/app/pkg/commons"
|
||||
"github.com/harness/gitness/types"
|
||||
"github.com/harness/gitness/types/enum"
|
||||
|
@ -93,19 +93,19 @@ var artifactVersionSortMap = map[string]string{
|
|||
}
|
||||
|
||||
var validRepositoryTypes = []string{
|
||||
string(api.RegistryTypeUPSTREAM),
|
||||
string(api.RegistryTypeVIRTUAL),
|
||||
string(a.RegistryTypeUPSTREAM),
|
||||
string(a.RegistryTypeVIRTUAL),
|
||||
}
|
||||
|
||||
var validPackageTypes = []string{
|
||||
string(api.PackageTypeDOCKER),
|
||||
string(api.PackageTypeHELM),
|
||||
string(api.PackageTypeMAVEN),
|
||||
string(a.PackageTypeDOCKER),
|
||||
string(a.PackageTypeHELM),
|
||||
string(a.PackageTypeMAVEN),
|
||||
}
|
||||
|
||||
var validUpstreamSources = []string{
|
||||
string(api.UpstreamConfigSourceCustom),
|
||||
string(api.UpstreamConfigSourceDockerhub),
|
||||
string(a.UpstreamConfigSourceCustom),
|
||||
string(a.UpstreamConfigSourceDockerhub),
|
||||
}
|
||||
|
||||
func ValidatePackageTypes(packageTypes []string) error {
|
||||
|
@ -155,13 +155,13 @@ func ValidateIdentifier(identifier string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func ValidateUpstream(config *api.RegistryConfig) error {
|
||||
func ValidateUpstream(config *a.RegistryConfig) error {
|
||||
upstreamConfig, err := config.AsUpstreamConfig()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !commons.IsEmpty(config.Type) && config.Type == api.RegistryTypeUPSTREAM &&
|
||||
*upstreamConfig.Source != api.UpstreamConfigSourceDockerhub {
|
||||
if !commons.IsEmpty(config.Type) && config.Type == a.RegistryTypeUPSTREAM &&
|
||||
*upstreamConfig.Source != a.UpstreamConfigSourceDockerhub {
|
||||
if commons.IsEmpty(upstreamConfig.Url) {
|
||||
return errors.New("URL is required for upstream repository")
|
||||
}
|
||||
|
@ -223,8 +223,8 @@ func GetTimeInMs(t time.Time) string {
|
|||
return fmt.Sprint(t.UnixMilli())
|
||||
}
|
||||
|
||||
func GetErrorResponse(code int, message string) *api.Error {
|
||||
return &api.Error{
|
||||
func GetErrorResponse(code int, message string) *a.Error {
|
||||
return &a.Error{
|
||||
Code: fmt.Sprint(code),
|
||||
Message: message,
|
||||
}
|
||||
|
@ -266,7 +266,7 @@ func GetSortByField(sortByField string, resource string) string {
|
|||
return "created_at"
|
||||
}
|
||||
|
||||
func GetPageLimit(pageSize *api.PageSize) int {
|
||||
func GetPageLimit(pageSize *a.PageSize) int {
|
||||
defaultPageSize := 10
|
||||
if pageSize != nil {
|
||||
return int(*pageSize)
|
||||
|
@ -274,7 +274,7 @@ func GetPageLimit(pageSize *api.PageSize) int {
|
|||
return defaultPageSize
|
||||
}
|
||||
|
||||
func GetOffset(pageSize *api.PageSize, pageNumber *api.PageNumber) int {
|
||||
func GetOffset(pageSize *a.PageSize, pageNumber *a.PageNumber) int {
|
||||
defaultOffset := 0
|
||||
if pageSize == nil || pageNumber == nil {
|
||||
return defaultOffset
|
||||
|
@ -285,7 +285,7 @@ func GetOffset(pageSize *api.PageSize, pageNumber *api.PageNumber) int {
|
|||
return (int(*pageSize)) * int(*pageNumber)
|
||||
}
|
||||
|
||||
func GetPageNumber(pageNumber *api.PageNumber) int64 {
|
||||
func GetPageNumber(pageNumber *a.PageNumber) int64 {
|
||||
defaultPageNumber := int64(1)
|
||||
if pageNumber == nil {
|
||||
return defaultPageNumber
|
||||
|
@ -293,9 +293,9 @@ func GetPageNumber(pageNumber *api.PageNumber) int64 {
|
|||
return int64(*pageNumber)
|
||||
}
|
||||
|
||||
func GetSuccessResponse() *api.Success {
|
||||
return &api.Success{
|
||||
Status: api.StatusSUCCESS,
|
||||
func GetSuccessResponse() *a.Success {
|
||||
return &a.Success{
|
||||
Status: a.StatusSUCCESS,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue