Docker-in-Docker (DinD) capabilities of public runners deactivated. More info

Unverified Commit 513c48d4 authored by Daniel Jiang's avatar Daniel Jiang Committed by GitHub
Browse files

Merge pull request #12936 from wy65701436/fix-swagger-dep

remove the dependency on swagger models
parents 5586fe86 a01e82d2
......@@ -16,8 +16,6 @@ package models
import (
"fmt"
"github.com/go-openapi/strfmt"
"github.com/goharbor/harbor/src/server/v2.0/models"
"time"
"github.com/astaxie/beego/validation"
......@@ -38,20 +36,6 @@ type Label struct {
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 ...
func (l *Label) TableName() string {
return "harbor_label"
......
......@@ -15,8 +15,6 @@
package models
import (
"github.com/go-openapi/strfmt"
"github.com/goharbor/harbor/src/server/v2.0/models"
"time"
"github.com/goharbor/harbor/src/pkg/signature/notary/model"
......@@ -40,19 +38,6 @@ type RepoRecord struct {
UpdateTime time.Time `orm:"column(update_time);auto_now" json:"update_time"`
}
// ToSwagger converts the repository into the swagger model
func (r *RepoRecord) ToSwagger() *models.Repository {
return &models.Repository{
CreationTime: strfmt.DateTime(r.CreationTime),
Description: r.Description,
ID: r.RepositoryID,
Name: r.Name,
ProjectID: r.ProjectID,
PullCount: r.PullCount,
UpdateTime: strfmt.DateTime(r.UpdateTime),
}
}
// TableName is required by by beego orm to map RepoRecord to table repository
func (r *RepoRecord) TableName() string {
return RepoTable
......
......@@ -21,7 +21,6 @@ import (
"github.com/goharbor/harbor/src/controller/tag"
"github.com/goharbor/harbor/src/lib/encode/repository"
"github.com/goharbor/harbor/src/pkg/artifact"
"github.com/goharbor/harbor/src/server/v2.0/models"
)
// Artifact is the overall view of artifact
......@@ -52,14 +51,6 @@ type AdditionLink struct {
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
type Option struct {
WithTag bool
......
package tag
import (
"github.com/go-openapi/strfmt"
"github.com/goharbor/harbor/src/pkg/signature"
"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
......@@ -14,20 +12,6 @@ type Tag struct {
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
type Option struct {
WithImmutableStatus bool
......
......@@ -21,7 +21,6 @@ import (
"github.com/docker/distribution/manifest/manifestlist"
"github.com/goharbor/harbor/src/lib/log"
"github.com/goharbor/harbor/src/pkg/artifact/dao"
"github.com/goharbor/harbor/src/server/v2.0/models"
v1 "github.com/opencontainers/image-spec/specs-go/v1"
)
......@@ -181,24 +180,3 @@ func (r *Reference) To() *dao.ArtifactReference {
}
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
}
......@@ -327,7 +327,7 @@ func (a *artifactAPI) ListTags(ctx context.Context, params operation.ListTagsPar
var ts []*models.Tag
for _, tag := range tags {
ts = append(ts, tag.ToSwagger())
ts = append(ts, model.NewTag(tag).ToSwagger())
}
return operation.NewListTagsOK().
WithXTotalCount(total).
......
......@@ -20,6 +20,7 @@ import (
"github.com/go-openapi/strfmt"
"github.com/goharbor/harbor/src/controller/artifact"
"github.com/goharbor/harbor/src/lib/log"
pkg_art "github.com/goharbor/harbor/src/pkg/artifact"
"github.com/goharbor/harbor/src/server/v2.0/models"
)
......@@ -46,20 +47,21 @@ func (a *Artifact) ToSwagger() *models.Artifact {
ExtraAttrs: a.ExtraAttrs,
Annotations: a.Annotations,
}
for _, reference := range a.References {
art.References = append(art.References, reference.ToSwagger())
art.References = append(art.References, NewReference(reference).ToSwagger())
}
for _, tag := range a.Tags {
art.Tags = append(art.Tags, tag.ToSwagger())
art.Tags = append(art.Tags, NewTag(tag).ToSwagger())
}
for addition, link := range a.AdditionLinks {
if art.AdditionLinks == nil {
art.AdditionLinks = make(map[string]models.AdditionLink)
}
art.AdditionLinks[addition] = link.ToSwagger()
art.AdditionLinks[addition] = NewAdditionLink(link).ToSwagger()
}
for _, label := range a.Labels {
art.Labels = append(art.Labels, label.ToSwagger())
art.Labels = append(art.Labels, NewLabel(label).ToSwagger())
}
if len(a.ScanOverview) > 0 {
art.ScanOverview = models.ScanOverview{}
......@@ -80,3 +82,52 @@ func (a *Artifact) ToSwagger() *models.Artifact {
}
return art
}
// AdditionLink is a link via that the addition can be fetched
type AdditionLink struct {
*artifact.AdditionLink
}
// ToSwagger converts the addition link to the swagger model
func (a *AdditionLink) ToSwagger() models.AdditionLink {
return models.AdditionLink{
Absolute: a.Absolute,
Href: a.HREF,
}
}
// NewAdditionLink ...
func NewAdditionLink(a *artifact.AdditionLink) *AdditionLink {
return &AdditionLink{AdditionLink: a}
}
// Reference records the child artifact referenced by parent artifact
type Reference struct {
*pkg_art.Reference
}
// 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
}
// NewReference ...
func NewReference(r *pkg_art.Reference) *Reference {
return &Reference{Reference: r}
}
package model
import (
"github.com/go-openapi/strfmt"
common_models "github.com/goharbor/harbor/src/common/models"
"github.com/goharbor/harbor/src/server/v2.0/models"
)
// Label model
type Label struct {
*common_models.Label
}
// 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),
}
}
// NewLabel ...
func NewLabel(l *common_models.Label) *Label {
return &Label{Label: l}
}
package model
import (
"github.com/go-openapi/strfmt"
common_models "github.com/goharbor/harbor/src/common/models"
"github.com/goharbor/harbor/src/server/v2.0/models"
)
// RepoRecord model
type RepoRecord struct {
*common_models.RepoRecord
}
// ToSwagger converts the repository into the swagger model
func (r *RepoRecord) ToSwagger() *models.Repository {
return &models.Repository{
CreationTime: strfmt.DateTime(r.CreationTime),
Description: r.Description,
ID: r.RepositoryID,
Name: r.Name,
ProjectID: r.ProjectID,
PullCount: r.PullCount,
UpdateTime: strfmt.DateTime(r.UpdateTime),
}
}
// NewRepoRecord ...
func NewRepoRecord(r *common_models.RepoRecord) *RepoRecord {
return &RepoRecord{RepoRecord: r}
}
package model
import (
"github.com/go-openapi/strfmt"
"github.com/goharbor/harbor/src/controller/tag"
"github.com/goharbor/harbor/src/server/v2.0/models"
)
// Tag model
type Tag struct {
*tag.Tag
}
// 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,
}
}
// NewTag ...
func NewTag(t *tag.Tag) *Tag {
return &Tag{Tag: t}
}
......@@ -28,6 +28,7 @@ import (
"github.com/goharbor/harbor/src/controller/repository"
"github.com/goharbor/harbor/src/lib/log"
"github.com/goharbor/harbor/src/lib/q"
"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/repository"
)
......@@ -81,7 +82,7 @@ func (r *repositoryAPI) ListRepositories(ctx context.Context, params operation.L
}
var repos []*models.Repository
for _, repository := range repositories {
repos = append(repos, r.assembleRepository(ctx, repository))
repos = append(repos, r.assembleRepository(ctx, model.NewRepoRecord(repository)))
}
return operation.NewListRepositoriesOK().
WithXTotalCount(total).
......@@ -97,10 +98,10 @@ func (r *repositoryAPI) GetRepository(ctx context.Context, params operation.GetR
if err != nil {
return r.SendError(ctx, err)
}
return operation.NewGetRepositoryOK().WithPayload(r.assembleRepository(ctx, repository))
return operation.NewGetRepositoryOK().WithPayload(r.assembleRepository(ctx, model.NewRepoRecord(repository)))
}
func (r *repositoryAPI) assembleRepository(ctx context.Context, repository *cmodels.RepoRecord) *models.Repository {
func (r *repositoryAPI) assembleRepository(ctx context.Context, repository *model.RepoRecord) *models.Repository {
repo := repository.ToSwagger()
total, err := r.artCtl.Count(ctx, &q.Query{
Keywords: map[string]interface{}{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment