mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-22 08:38:03 +01:00
Merge pull request #10945 from ywk253100/200305_swagger_model
Remove the "x-go-type" for artifact definition in swagger
This commit is contained in:
commit
dcaccbc757
@ -763,10 +763,6 @@ definitions:
|
|||||||
description: The update time of the repository
|
description: The update time of the repository
|
||||||
Artifact:
|
Artifact:
|
||||||
type: object
|
type: object
|
||||||
x-go-type:
|
|
||||||
import:
|
|
||||||
package: "github.com/goharbor/harbor/src/server/v2.0/handler/model"
|
|
||||||
type: "Artifact"
|
|
||||||
properties:
|
properties:
|
||||||
id:
|
id:
|
||||||
type: integer
|
type: integer
|
||||||
@ -897,6 +893,13 @@ definitions:
|
|||||||
description: The digest of the child artifact
|
description: The digest of the child artifact
|
||||||
platform:
|
platform:
|
||||||
$ref: '#/definitions/Platform'
|
$ref: '#/definitions/Platform'
|
||||||
|
annotations:
|
||||||
|
$ref: '#/definitions/Annotations'
|
||||||
|
urls:
|
||||||
|
type: array
|
||||||
|
description: The download URLs
|
||||||
|
items:
|
||||||
|
type: string
|
||||||
Platform:
|
Platform:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
@ -948,9 +951,6 @@ definitions:
|
|||||||
type: string
|
type: string
|
||||||
format: date-time
|
format: date-time
|
||||||
description: The update time of the label
|
description: The update time of the label
|
||||||
deleted:
|
|
||||||
type: boolean
|
|
||||||
description: Whether the label is deleted or not
|
|
||||||
ScanOverview:
|
ScanOverview:
|
||||||
type: object
|
type: object
|
||||||
description: 'The scan overview attached in the metadata of tag'
|
description: 'The scan overview attached in the metadata of tag'
|
||||||
|
@ -16,6 +16,7 @@ package artifact
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/goharbor/harbor/src/server/v2.0/models"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/api/tag"
|
"github.com/goharbor/harbor/src/api/tag"
|
||||||
cmodels "github.com/goharbor/harbor/src/common/models"
|
cmodels "github.com/goharbor/harbor/src/common/models"
|
||||||
@ -49,6 +50,14 @@ type AdditionLink struct {
|
|||||||
Absolute bool `json:"absolute"` // specify the href is an absolute URL or not
|
Absolute bool `json:"absolute"` // specify the href is an absolute URL or not
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ToSwagger converts the addition link to the swagger model
|
||||||
|
func (a *AdditionLink) ToSwagger() models.AdditionLink {
|
||||||
|
return models.AdditionLink{
|
||||||
|
Absolute: a.Absolute,
|
||||||
|
Href: a.HREF,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Option is used to specify the properties returned when listing/getting artifacts
|
// Option is used to specify the properties returned when listing/getting artifacts
|
||||||
type Option struct {
|
type Option struct {
|
||||||
WithTag bool
|
WithTag bool
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
package tag
|
package tag
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/go-openapi/strfmt"
|
||||||
"github.com/goharbor/harbor/src/pkg/signature"
|
"github.com/goharbor/harbor/src/pkg/signature"
|
||||||
"github.com/goharbor/harbor/src/pkg/tag/model/tag"
|
"github.com/goharbor/harbor/src/pkg/tag/model/tag"
|
||||||
|
"github.com/goharbor/harbor/src/server/v2.0/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Tag is the overall view of tag
|
// Tag is the overall view of tag
|
||||||
@ -12,6 +14,20 @@ type Tag struct {
|
|||||||
Signed bool `json:"signed"`
|
Signed bool `json:"signed"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ToSwagger converts the tag to the swagger model
|
||||||
|
func (t *Tag) ToSwagger() *models.Tag {
|
||||||
|
return &models.Tag{
|
||||||
|
ArtifactID: t.ArtifactID,
|
||||||
|
ID: t.ID,
|
||||||
|
Name: t.Name,
|
||||||
|
PullTime: strfmt.DateTime(t.PullTime),
|
||||||
|
PushTime: strfmt.DateTime(t.PushTime),
|
||||||
|
RepositoryID: t.RepositoryID,
|
||||||
|
Immutable: t.Immutable,
|
||||||
|
Signed: t.Signed,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Option is used to specify the properties returned when listing/getting tags
|
// Option is used to specify the properties returned when listing/getting tags
|
||||||
type Option struct {
|
type Option struct {
|
||||||
WithImmutableStatus bool
|
WithImmutableStatus bool
|
||||||
|
@ -16,6 +16,8 @@ package models
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/go-openapi/strfmt"
|
||||||
|
"github.com/goharbor/harbor/src/server/v2.0/models"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/astaxie/beego/validation"
|
"github.com/astaxie/beego/validation"
|
||||||
@ -36,6 +38,20 @@ type Label struct {
|
|||||||
Deleted bool `orm:"column(deleted)" json:"deleted"`
|
Deleted bool `orm:"column(deleted)" json:"deleted"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ToSwagger converts the label to the swagger model
|
||||||
|
func (l *Label) ToSwagger() *models.Label {
|
||||||
|
return &models.Label{
|
||||||
|
Color: l.Color,
|
||||||
|
CreationTime: strfmt.DateTime(l.CreationTime),
|
||||||
|
Description: l.Description,
|
||||||
|
ID: l.ID,
|
||||||
|
Name: l.Name,
|
||||||
|
ProjectID: l.ProjectID,
|
||||||
|
Scope: l.Scope,
|
||||||
|
UpdateTime: strfmt.DateTime(l.UpdateTime),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TableName ...
|
// TableName ...
|
||||||
func (l *Label) TableName() string {
|
func (l *Label) TableName() string {
|
||||||
return "harbor_label"
|
return "harbor_label"
|
||||||
|
@ -16,6 +16,7 @@ package artifact
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"github.com/goharbor/harbor/src/server/v2.0/models"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/docker/distribution/manifest/manifestlist"
|
"github.com/docker/distribution/manifest/manifestlist"
|
||||||
@ -177,3 +178,24 @@ func (r *Reference) To() *dao.ArtifactReference {
|
|||||||
}
|
}
|
||||||
return ref
|
return ref
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ToSwagger converts the reference to the swagger model
|
||||||
|
func (r *Reference) ToSwagger() *models.Reference {
|
||||||
|
ref := &models.Reference{
|
||||||
|
ChildDigest: r.ChildDigest,
|
||||||
|
ChildID: r.ChildID,
|
||||||
|
ParentID: r.ParentID,
|
||||||
|
Annotations: r.Annotations,
|
||||||
|
Urls: r.URLs,
|
||||||
|
}
|
||||||
|
if r.Platform != nil {
|
||||||
|
ref.Platform = &models.Platform{
|
||||||
|
Architecture: r.Platform.Architecture,
|
||||||
|
Os: r.Platform.OS,
|
||||||
|
OsFeatures: r.Platform.OSFeatures,
|
||||||
|
OsVersion: r.Platform.OSVersion,
|
||||||
|
Variant: r.Platform.Variant,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ref
|
||||||
|
}
|
||||||
|
@ -118,8 +118,7 @@ describe("ArtifactListTabComponent (inline template)", () => {
|
|||||||
"scope": "g",
|
"scope": "g",
|
||||||
"project_id": 0,
|
"project_id": 0,
|
||||||
"creation_time": "2020-01-13T05:44:00.580198Z",
|
"creation_time": "2020-01-13T05:44:00.580198Z",
|
||||||
"update_time": "2020-01-13T05:44:00.580198Z",
|
"update_time": "2020-01-13T05:44:00.580198Z"
|
||||||
"deleted": false
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": 6,
|
"id": 6,
|
||||||
@ -129,8 +128,7 @@ describe("ArtifactListTabComponent (inline template)", () => {
|
|||||||
"scope": "g",
|
"scope": "g",
|
||||||
"project_id": 0,
|
"project_id": 0,
|
||||||
"creation_time": "2020-01-13T08:27:19.279123Z",
|
"creation_time": "2020-01-13T08:27:19.279123Z",
|
||||||
"update_time": "2020-01-13T08:27:19.279123Z",
|
"update_time": "2020-01-13T08:27:19.279123Z"
|
||||||
"deleted": false
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"push_time": "2020-01-07T03:33:41.162319Z",
|
"push_time": "2020-01-07T03:33:41.162319Z",
|
||||||
@ -176,8 +174,7 @@ describe("ArtifactListTabComponent (inline template)", () => {
|
|||||||
"scope": "g",
|
"scope": "g",
|
||||||
"project_id": 0,
|
"project_id": 0,
|
||||||
"creation_time": "2020-01-13T05:44:00.580198Z",
|
"creation_time": "2020-01-13T05:44:00.580198Z",
|
||||||
"update_time": "2020-01-13T05:44:00.580198Z",
|
"update_time": "2020-01-13T05:44:00.580198Z"
|
||||||
"deleted": false
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": 6,
|
"id": 6,
|
||||||
@ -187,8 +184,7 @@ describe("ArtifactListTabComponent (inline template)", () => {
|
|||||||
"scope": "g",
|
"scope": "g",
|
||||||
"project_id": 0,
|
"project_id": 0,
|
||||||
"creation_time": "2020-01-13T08:27:19.279123Z",
|
"creation_time": "2020-01-13T08:27:19.279123Z",
|
||||||
"update_time": "2020-01-13T08:27:19.279123Z",
|
"update_time": "2020-01-13T08:27:19.279123Z"
|
||||||
"deleted": false
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"push_time": "2020-01-07T03:33:41.162319Z",
|
"push_time": "2020-01-07T03:33:41.162319Z",
|
||||||
|
@ -17,8 +17,6 @@ package handler
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/goharbor/harbor/src/api/event"
|
|
||||||
evt "github.com/goharbor/harbor/src/pkg/notifier/event"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -28,15 +26,18 @@ import (
|
|||||||
"github.com/go-openapi/runtime/middleware"
|
"github.com/go-openapi/runtime/middleware"
|
||||||
"github.com/goharbor/harbor/src/api/artifact"
|
"github.com/goharbor/harbor/src/api/artifact"
|
||||||
"github.com/goharbor/harbor/src/api/artifact/abstractor/resolver"
|
"github.com/goharbor/harbor/src/api/artifact/abstractor/resolver"
|
||||||
|
"github.com/goharbor/harbor/src/api/event"
|
||||||
"github.com/goharbor/harbor/src/api/repository"
|
"github.com/goharbor/harbor/src/api/repository"
|
||||||
"github.com/goharbor/harbor/src/api/scan"
|
"github.com/goharbor/harbor/src/api/scan"
|
||||||
"github.com/goharbor/harbor/src/api/tag"
|
"github.com/goharbor/harbor/src/api/tag"
|
||||||
"github.com/goharbor/harbor/src/common/rbac"
|
"github.com/goharbor/harbor/src/common/rbac"
|
||||||
"github.com/goharbor/harbor/src/common/utils"
|
"github.com/goharbor/harbor/src/common/utils"
|
||||||
ierror "github.com/goharbor/harbor/src/internal/error"
|
ierror "github.com/goharbor/harbor/src/internal/error"
|
||||||
|
evt "github.com/goharbor/harbor/src/pkg/notifier/event"
|
||||||
v1 "github.com/goharbor/harbor/src/pkg/scan/rest/v1"
|
v1 "github.com/goharbor/harbor/src/pkg/scan/rest/v1"
|
||||||
"github.com/goharbor/harbor/src/server/v2.0/handler/assembler"
|
"github.com/goharbor/harbor/src/server/v2.0/handler/assembler"
|
||||||
"github.com/goharbor/harbor/src/server/v2.0/handler/model"
|
"github.com/goharbor/harbor/src/server/v2.0/handler/model"
|
||||||
|
"github.com/goharbor/harbor/src/server/v2.0/models"
|
||||||
operation "github.com/goharbor/harbor/src/server/v2.0/restapi/operations/artifact"
|
operation "github.com/goharbor/harbor/src/server/v2.0/restapi/operations/artifact"
|
||||||
"github.com/opencontainers/go-digest"
|
"github.com/opencontainers/go-digest"
|
||||||
)
|
)
|
||||||
@ -97,15 +98,15 @@ func (a *artifactAPI) ListArtifacts(ctx context.Context, params operation.ListAr
|
|||||||
return a.SendError(ctx, err)
|
return a.SendError(ctx, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var artifacts []*model.Artifact
|
assembler := assembler.NewVulAssembler(boolValue(params.WithScanOverview))
|
||||||
|
var artifacts []*models.Artifact
|
||||||
for _, art := range arts {
|
for _, art := range arts {
|
||||||
artifact := &model.Artifact{}
|
artifact := &model.Artifact{}
|
||||||
artifact.Artifact = *art
|
artifact.Artifact = *art
|
||||||
artifacts = append(artifacts, artifact)
|
assembler.WithArtifacts(artifact).Assemble(ctx)
|
||||||
|
artifacts = append(artifacts, artifact.ToSwagger())
|
||||||
}
|
}
|
||||||
|
|
||||||
assembler.NewVulAssembler(boolValue(params.WithScanOverview)).WithArtifacts(artifacts...).Assemble(ctx)
|
|
||||||
|
|
||||||
return operation.NewListArtifactsOK().
|
return operation.NewListArtifactsOK().
|
||||||
WithXTotalCount(total).
|
WithXTotalCount(total).
|
||||||
WithLink(a.Links(ctx, params.HTTPRequest.URL, total, query.PageNumber, query.PageSize).String()).
|
WithLink(a.Links(ctx, params.HTTPRequest.URL, total, query.PageNumber, query.PageSize).String()).
|
||||||
@ -130,7 +131,7 @@ func (a *artifactAPI) GetArtifact(ctx context.Context, params operation.GetArtif
|
|||||||
|
|
||||||
assembler.NewVulAssembler(boolValue(params.WithScanOverview)).WithArtifacts(art).Assemble(ctx)
|
assembler.NewVulAssembler(boolValue(params.WithScanOverview)).WithArtifacts(art).Assemble(ctx)
|
||||||
|
|
||||||
return operation.NewGetArtifactOK().WithPayload(art)
|
return operation.NewGetArtifactOK().WithPayload(art.ToSwagger())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *artifactAPI) DeleteArtifact(ctx context.Context, params operation.DeleteArtifactParams) middleware.Responder {
|
func (a *artifactAPI) DeleteArtifact(ctx context.Context, params operation.DeleteArtifactParams) middleware.Responder {
|
||||||
|
@ -14,10 +14,48 @@
|
|||||||
|
|
||||||
package model
|
package model
|
||||||
|
|
||||||
import "github.com/goharbor/harbor/src/api/artifact"
|
import (
|
||||||
|
"github.com/go-openapi/strfmt"
|
||||||
|
"github.com/goharbor/harbor/src/api/artifact"
|
||||||
|
"github.com/goharbor/harbor/src/server/v2.0/models"
|
||||||
|
)
|
||||||
|
|
||||||
// Artifact model
|
// Artifact model
|
||||||
type Artifact struct {
|
type Artifact struct {
|
||||||
artifact.Artifact
|
artifact.Artifact
|
||||||
ScanOverview map[string]interface{} `json:"scan_overview"`
|
ScanOverview map[string]interface{} `json:"scan_overview"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ToSwagger converts the artifact to the swagger model
|
||||||
|
func (a *Artifact) ToSwagger() *models.Artifact {
|
||||||
|
art := &models.Artifact{
|
||||||
|
ID: a.ID,
|
||||||
|
Type: a.Type,
|
||||||
|
MediaType: a.MediaType,
|
||||||
|
ManifestMediaType: a.ManifestMediaType,
|
||||||
|
ProjectID: a.ProjectID,
|
||||||
|
RepositoryID: a.RepositoryID,
|
||||||
|
Digest: a.Digest,
|
||||||
|
Size: a.Size,
|
||||||
|
PullTime: strfmt.DateTime(a.PullTime),
|
||||||
|
PushTime: strfmt.DateTime(a.PushTime),
|
||||||
|
ExtraAttrs: a.ExtraAttrs,
|
||||||
|
Annotations: a.Annotations,
|
||||||
|
}
|
||||||
|
for _, reference := range a.References {
|
||||||
|
art.References = append(art.References, reference.ToSwagger())
|
||||||
|
}
|
||||||
|
for _, tag := range a.Tags {
|
||||||
|
art.Tags = append(art.Tags, tag.ToSwagger())
|
||||||
|
}
|
||||||
|
for addition, link := range a.AdditionLinks {
|
||||||
|
if art.AdditionLinks == nil {
|
||||||
|
art.AdditionLinks = make(map[string]models.AdditionLink)
|
||||||
|
}
|
||||||
|
art.AdditionLinks[addition] = link.ToSwagger()
|
||||||
|
}
|
||||||
|
for _, label := range a.Labels {
|
||||||
|
art.Labels = append(art.Labels, label.ToSwagger())
|
||||||
|
}
|
||||||
|
return art
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user