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/app/api/request"
|
||||||
"github.com/harness/gitness/registry/app/api/openapi/contracts/artifact"
|
"github.com/harness/gitness/registry/app/api/openapi/contracts/artifact"
|
||||||
ml "github.com/harness/gitness/registry/app/manifest/manifestlist"
|
ml "github.com/harness/gitness/registry/app/manifest/manifestlist"
|
||||||
os "github.com/harness/gitness/registry/app/manifest/ocischema"
|
"github.com/harness/gitness/registry/app/manifest/ocischema"
|
||||||
s2 "github.com/harness/gitness/registry/app/manifest/schema2"
|
"github.com/harness/gitness/registry/app/manifest/schema2"
|
||||||
"github.com/harness/gitness/registry/app/pkg/docker"
|
"github.com/harness/gitness/registry/app/pkg/docker"
|
||||||
"github.com/harness/gitness/registry/types"
|
"github.com/harness/gitness/registry/types"
|
||||||
store2 "github.com/harness/gitness/store"
|
store2 "github.com/harness/gitness/store"
|
||||||
|
@ -74,47 +74,16 @@ func (c *APIController) GetDockerArtifactManifests(
|
||||||
|
|
||||||
image := string(r.Artifact)
|
image := string(r.Artifact)
|
||||||
version := string(r.Version)
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return artifactManifestsErrorRs(err), nil
|
||||||
}
|
|
||||||
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 artifact.GetDockerArtifactManifests200JSONResponse{
|
return artifact.GetDockerArtifactManifests200JSONResponse{
|
||||||
DockerManifestsResponseJSONResponse: artifact.DockerManifestsResponseJSONResponse{
|
DockerManifestsResponseJSONResponse: artifact.DockerManifestsResponseJSONResponse{
|
||||||
Data: artifact.DockerManifests{
|
Data: artifact.DockerManifests{
|
||||||
ImageName: t.ImageName,
|
ImageName: image,
|
||||||
Version: t.Name,
|
Version: version,
|
||||||
Manifests: &manifestDetailsList,
|
Manifests: &manifestDetailsList,
|
||||||
},
|
},
|
||||||
Status: artifact.StatusSUCCESS,
|
Status: artifact.StatusSUCCESS,
|
||||||
|
@ -176,3 +145,53 @@ func getManifestDetails(m *types.Manifest, mConfig *manifestConfig) artifact.Doc
|
||||||
}
|
}
|
||||||
return manifestDetails
|
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"
|
"strings"
|
||||||
"time"
|
"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/registry/app/pkg/commons"
|
||||||
"github.com/harness/gitness/types"
|
"github.com/harness/gitness/types"
|
||||||
"github.com/harness/gitness/types/enum"
|
"github.com/harness/gitness/types/enum"
|
||||||
|
@ -93,19 +93,19 @@ var artifactVersionSortMap = map[string]string{
|
||||||
}
|
}
|
||||||
|
|
||||||
var validRepositoryTypes = []string{
|
var validRepositoryTypes = []string{
|
||||||
string(api.RegistryTypeUPSTREAM),
|
string(a.RegistryTypeUPSTREAM),
|
||||||
string(api.RegistryTypeVIRTUAL),
|
string(a.RegistryTypeVIRTUAL),
|
||||||
}
|
}
|
||||||
|
|
||||||
var validPackageTypes = []string{
|
var validPackageTypes = []string{
|
||||||
string(api.PackageTypeDOCKER),
|
string(a.PackageTypeDOCKER),
|
||||||
string(api.PackageTypeHELM),
|
string(a.PackageTypeHELM),
|
||||||
string(api.PackageTypeMAVEN),
|
string(a.PackageTypeMAVEN),
|
||||||
}
|
}
|
||||||
|
|
||||||
var validUpstreamSources = []string{
|
var validUpstreamSources = []string{
|
||||||
string(api.UpstreamConfigSourceCustom),
|
string(a.UpstreamConfigSourceCustom),
|
||||||
string(api.UpstreamConfigSourceDockerhub),
|
string(a.UpstreamConfigSourceDockerhub),
|
||||||
}
|
}
|
||||||
|
|
||||||
func ValidatePackageTypes(packageTypes []string) error {
|
func ValidatePackageTypes(packageTypes []string) error {
|
||||||
|
@ -155,13 +155,13 @@ func ValidateIdentifier(identifier string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ValidateUpstream(config *api.RegistryConfig) error {
|
func ValidateUpstream(config *a.RegistryConfig) error {
|
||||||
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 &&
|
if !commons.IsEmpty(config.Type) && config.Type == a.RegistryTypeUPSTREAM &&
|
||||||
*upstreamConfig.Source != api.UpstreamConfigSourceDockerhub {
|
*upstreamConfig.Source != a.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")
|
||||||
}
|
}
|
||||||
|
@ -223,8 +223,8 @@ func GetTimeInMs(t time.Time) string {
|
||||||
return fmt.Sprint(t.UnixMilli())
|
return fmt.Sprint(t.UnixMilli())
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetErrorResponse(code int, message string) *api.Error {
|
func GetErrorResponse(code int, message string) *a.Error {
|
||||||
return &api.Error{
|
return &a.Error{
|
||||||
Code: fmt.Sprint(code),
|
Code: fmt.Sprint(code),
|
||||||
Message: message,
|
Message: message,
|
||||||
}
|
}
|
||||||
|
@ -266,7 +266,7 @@ func GetSortByField(sortByField string, resource string) string {
|
||||||
return "created_at"
|
return "created_at"
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetPageLimit(pageSize *api.PageSize) int {
|
func GetPageLimit(pageSize *a.PageSize) int {
|
||||||
defaultPageSize := 10
|
defaultPageSize := 10
|
||||||
if pageSize != nil {
|
if pageSize != nil {
|
||||||
return int(*pageSize)
|
return int(*pageSize)
|
||||||
|
@ -274,7 +274,7 @@ func GetPageLimit(pageSize *api.PageSize) int {
|
||||||
return defaultPageSize
|
return defaultPageSize
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetOffset(pageSize *api.PageSize, pageNumber *api.PageNumber) int {
|
func GetOffset(pageSize *a.PageSize, pageNumber *a.PageNumber) int {
|
||||||
defaultOffset := 0
|
defaultOffset := 0
|
||||||
if pageSize == nil || pageNumber == nil {
|
if pageSize == nil || pageNumber == nil {
|
||||||
return defaultOffset
|
return defaultOffset
|
||||||
|
@ -285,7 +285,7 @@ func GetOffset(pageSize *api.PageSize, pageNumber *api.PageNumber) int {
|
||||||
return (int(*pageSize)) * int(*pageNumber)
|
return (int(*pageSize)) * int(*pageNumber)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetPageNumber(pageNumber *api.PageNumber) int64 {
|
func GetPageNumber(pageNumber *a.PageNumber) int64 {
|
||||||
defaultPageNumber := int64(1)
|
defaultPageNumber := int64(1)
|
||||||
if pageNumber == nil {
|
if pageNumber == nil {
|
||||||
return defaultPageNumber
|
return defaultPageNumber
|
||||||
|
@ -293,9 +293,9 @@ func GetPageNumber(pageNumber *api.PageNumber) int64 {
|
||||||
return int64(*pageNumber)
|
return int64(*pageNumber)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetSuccessResponse() *api.Success {
|
func GetSuccessResponse() *a.Success {
|
||||||
return &api.Success{
|
return &a.Success{
|
||||||
Status: api.StatusSUCCESS,
|
Status: a.StatusSUCCESS,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue