mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-25 03:35:21 +01:00
replace subject id with digest (#18278)
Since it has to support push subject and accessories in either order, it has to replace digest with id Signed-off-by: Wang Yan <wangyan@vmware.com>
This commit is contained in:
parent
fecee37439
commit
295260b7a3
@ -9382,10 +9382,9 @@ definitions:
|
||||
format: int64
|
||||
description: The artifact id of the accessory
|
||||
x-omitempty: false
|
||||
subject_artifact_id:
|
||||
type: integer
|
||||
format: int64
|
||||
description: The subject artifact id of the accessory
|
||||
subject_artifact_digest:
|
||||
type: string
|
||||
description: The subject artifact digest of the accessory
|
||||
x-omitempty: false
|
||||
size:
|
||||
type: integer
|
||||
|
@ -1,5 +1,26 @@
|
||||
/* remove the redundant data from table artifact_blob */
|
||||
delete from artifact_blob afb where not exists (select digest from blob b where b.digest = afb.digest_af);
|
||||
|
||||
/* replace subject_artifact_id with subject_artifact_digest*/
|
||||
alter table artifact_accessory add column subject_artifact_digest varchar(1024);
|
||||
|
||||
DO $$
|
||||
DECLARE
|
||||
acc RECORD;
|
||||
art RECORD;
|
||||
BEGIN
|
||||
FOR acc IN SELECT * FROM artifact_accessory
|
||||
LOOP
|
||||
SELECT * INTO art from artifact where id = acc.subject_artifact_id;
|
||||
UPDATE artifact_accessory SET subject_artifact_digest=art.digest WHERE subject_artifact_id = art.id;
|
||||
END LOOP;
|
||||
END $$;
|
||||
|
||||
alter table artifact_accessory drop CONSTRAINT artifact_accessory_subject_artifact_id_fkey;
|
||||
alter table artifact_accessory drop CONSTRAINT unique_artifact_accessory;
|
||||
alter table artifact_accessory add CONSTRAINT unique_artifact_accessory UNIQUE (artifact_id, subject_artifact_digest);
|
||||
alter table artifact_accessory drop column subject_artifact_id;
|
||||
|
||||
/* Update the registry and replication policy associated with the chartmuseum */
|
||||
UPDATE registry
|
||||
SET description = 'Chartmuseum has been deprecated in Harbor v2.8.0, please delete this registry.'
|
||||
|
@ -161,7 +161,7 @@ func (c *controller) Ensure(ctx context.Context, repository, digest string, opti
|
||||
}
|
||||
}
|
||||
for _, acc := range option.Accs {
|
||||
if err = c.accessoryMgr.Ensure(ctx, artifact.ID, acc.ArtifactID, acc.Size, acc.Digest, acc.Type); err != nil {
|
||||
if err = c.accessoryMgr.Ensure(ctx, artifact.Digest, acc.ArtifactID, acc.Size, acc.Digest, acc.Type); err != nil {
|
||||
return false, 0, err
|
||||
}
|
||||
}
|
||||
@ -722,7 +722,7 @@ func (c *controller) populateAdditionLinks(ctx context.Context, artifact *Artifa
|
||||
}
|
||||
|
||||
func (c *controller) populateAccessories(ctx context.Context, art *Artifact) {
|
||||
accs, err := c.accessoryMgr.List(ctx, q.New(q.KeyWords{"SubjectArtifactID": art.ID}))
|
||||
accs, err := c.accessoryMgr.List(ctx, q.New(q.KeyWords{"SubjectArtifactDigest": art.Digest}))
|
||||
if err != nil {
|
||||
log.Errorf("failed to list accessories of artifact %d: %v", art.ID, err)
|
||||
return
|
||||
|
@ -139,7 +139,7 @@ func (c *controllerTestSuite) TestAssembleArtifact() {
|
||||
Data: accessorymodel.AccessoryData{
|
||||
ID: 1,
|
||||
ArtifactID: 2,
|
||||
SubArtifactID: 1,
|
||||
SubArtifactDigest: "sha256:123",
|
||||
Type: accessorymodel.TypeCosignSignature,
|
||||
},
|
||||
}
|
||||
@ -548,7 +548,7 @@ func (c *controllerTestSuite) TestCopy() {
|
||||
Data: accessorymodel.AccessoryData{
|
||||
ID: 1,
|
||||
ArtifactID: 2,
|
||||
SubArtifactID: 1,
|
||||
SubArtifactDigest: "sha256:418fb88ec412e340cdbef913b8ca1bbe8f9e8dc705f9617414c1f2c8db980180",
|
||||
Type: accessorymodel.TypeCosignSignature,
|
||||
},
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
)
|
||||
|
||||
func TestUnmarshalJSONWithACC(t *testing.T) {
|
||||
data := []byte(`[{"accessories":[{"artifact_id":9,"creation_time":"2022-01-20T09:18:50.993Z","digest":"sha256:a7caa2636af890178a0b8c4cdbc47ced4dbdf29a1680e9e50823e85ce35b28d3","icon":"","id":4,"size":501,"subject_artifact_id":8,"type":"signature.cosign"}],
|
||||
data := []byte(`[{"accessories":[{"artifact_id":9,"creation_time":"2022-01-20T09:18:50.993Z","digest":"sha256:a7caa2636af890178a0b8c4cdbc47ced4dbdf29a1680e9e50823e85ce35b28d3","icon":"","id":4,"size":501,"subject_artifact_digest":"sha256:e4b315ad03a1d1d9ff0c111e648a1a91066c09ead8352d3d6a48fa971a82922c","type":"signature.cosign"}],
|
||||
"addition_links":{"build_history":{"absolute":false,"href":"/api/v2.0/projects/source_project011642670285/repositories/redis/artifacts/sha256:e4b315ad03a1d1d9ff0c111e648a1a91066c09ead8352d3d6a48fa971a82922c/additions/build_history"},
|
||||
"vulnerabilities":{"absolute":false,"href":"/api/v2.0/projects/source_project011642670285/repositories/redis/artifacts/sha256:e4b315ad03a1d1d9ff0c111e648a1a91066c09ead8352d3d6a48fa971a82922c/additions/vulnerabilities"}},
|
||||
"digest":"sha256:e4b315ad03a1d1d9ff0c111e648a1a91066c09ead8352d3d6a48fa971a82922c",
|
||||
@ -31,7 +31,7 @@ func TestUnmarshalJSONWithACC(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUnmarshalJSONWithACCPartial(t *testing.T) {
|
||||
data := []byte(`[{"accessories":[{"artifact_id":9,"creation_time":"2022-01-20T09:18:50.993Z","digest":"sha256:a7caa2636af890178a0b8c4cdbc47ced4dbdf29a1680e9e50823e85ce35b28d3","icon":"","id":4,"size":501,"subject_artifact_id":8,"type":"signature.cosign"}, {"artifact_id":2, "type":"signature.cosign"}],
|
||||
data := []byte(`[{"accessories":[{"artifact_id":9,"creation_time":"2022-01-20T09:18:50.993Z","digest":"sha256:a7caa2636af890178a0b8c4cdbc47ced4dbdf29a1680e9e50823e85ce35b28d3","icon":"","id":4,"size":501,"subject_artifact_digest":"sha256:a7caa2636af890178a0b8c4cdbc47ced4dbdf29a1680e9e50823e85ce35b28d3","type":"signature.cosign"}, {"artifact_id":2, "type":"signature.cosign"}],
|
||||
"digest":"sha256:e4b315ad03a1d1d9ff0c111e648a1a91066c09ead8352d3d6a48fa971a82922c","tags":[{"artifact_id":8,"id":6,"immutable":false,"name":"latest","pull_time":"2022-01-20T09:18:50.783Z","push_time":"2022-01-20T09:18:50.303Z","repository_id":5,"signed":false}],"type":"IMAGE"}]`)
|
||||
|
||||
var artifact []Artifact
|
||||
@ -47,7 +47,7 @@ func TestUnmarshalJSONWithACCPartial(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUnmarshalJSONWithACCUnknownType(t *testing.T) {
|
||||
data := []byte(`[{"accessories":[{"artifact_id":9,"creation_time":"2022-01-20T09:18:50.993Z","digest":"sha256:a7caa2636af890178a0b8c4cdbc47ced4dbdf29a1680e9e50823e85ce35b28d3","icon":"","id":4,"size":501,"subject_artifact_id":8}],
|
||||
data := []byte(`[{"accessories":[{"artifact_id":9,"creation_time":"2022-01-20T09:18:50.993Z","digest":"sha256:a7caa2636af890178a0b8c4cdbc47ced4dbdf29a1680e9e50823e85ce35b28d3","icon":"","id":4,"size":501,"subject_artifact_digest":"sha256:a7caa2636af890178a0b8c4cdbc47ced4dbdf29a1680e9e50823e85ce35b28d3"}],
|
||||
"digest":"sha256:e4b315ad03a1d1d9ff0c111e648a1a91066c09ead8352d3d6a48fa971a82922c","tags":[{"artifact_id":8,"id":6,"immutable":false,"name":"latest","pull_time":"2022-01-20T09:18:50.783Z","push_time":"2022-01-20T09:18:50.303Z","repository_id":5,"signed":false}],"type":"IMAGE"}]`)
|
||||
|
||||
var artifact []Artifact
|
||||
|
@ -95,11 +95,11 @@ func (d *dao) Create(ctx context.Context, acc *Accessory) (int64, error) {
|
||||
}
|
||||
id, err := ormer.Insert(acc)
|
||||
if err != nil {
|
||||
if e := orm.AsConflictError(err, "accessory %s already exists under the artifact %d",
|
||||
acc.Digest, acc.SubjectArtifactID); e != nil {
|
||||
if e := orm.AsConflictError(err, "accessory %s already exists under the artifact %s",
|
||||
acc.Digest, acc.SubjectArtifactDigest); e != nil {
|
||||
err = e
|
||||
} else if e := orm.AsForeignKeyError(err, "the accessory %s tries to attach to a non existing artifact %d",
|
||||
acc.Digest, acc.SubjectArtifactID); e != nil {
|
||||
} else if e := orm.AsForeignKeyError(err, "the accessory %s tries to attach to a non existing artifact %s",
|
||||
acc.Digest, acc.SubjectArtifactDigest); e != nil {
|
||||
err = e
|
||||
}
|
||||
}
|
||||
|
@ -36,6 +36,7 @@ type daoTestSuite struct {
|
||||
artDAO artdao.DAO
|
||||
artifactID int64
|
||||
subArtifactID int64
|
||||
subArtifactDigest string
|
||||
accID int64
|
||||
ctx context.Context
|
||||
}
|
||||
@ -47,16 +48,18 @@ func (d *daoTestSuite) SetupSuite() {
|
||||
d.ClearTables = []string{"artifact", "artifact_accessory"}
|
||||
|
||||
d.artDAO = artdao.New()
|
||||
artifactID, err := d.artDAO.Create(d.ctx, &artdao.Artifact{
|
||||
art := &artdao.Artifact{
|
||||
Type: "IMAGE",
|
||||
MediaType: "application/vnd.oci.image.config.v1+json",
|
||||
ManifestMediaType: "application/vnd.oci.image.manifest.v1+json",
|
||||
ProjectID: 1,
|
||||
RepositoryID: 1000,
|
||||
Digest: d.DigestString(),
|
||||
})
|
||||
d.Require().Nil(err)
|
||||
}
|
||||
artifactID, err := d.artDAO.Create(d.ctx, art)
|
||||
d.subArtifactID = artifactID
|
||||
d.Require().Nil(err)
|
||||
d.subArtifactDigest = art.Digest
|
||||
|
||||
d.artDAO = artdao.New()
|
||||
artifactID, err = d.artDAO.Create(d.ctx, &artdao.Artifact{
|
||||
@ -72,7 +75,7 @@ func (d *daoTestSuite) SetupSuite() {
|
||||
|
||||
accID, err := d.dao.Create(d.ctx, &Accessory{
|
||||
ArtifactID: d.artifactID,
|
||||
SubjectArtifactID: d.subArtifactID,
|
||||
SubjectArtifactDigest: d.subArtifactDigest,
|
||||
Digest: d.DigestString(),
|
||||
Size: 1234,
|
||||
Type: "cosign.signature",
|
||||
@ -103,7 +106,7 @@ func (d *daoTestSuite) TestCount() {
|
||||
d.True(total > 0)
|
||||
total, err = d.dao.Count(d.ctx, &q.Query{
|
||||
Keywords: map[string]interface{}{
|
||||
"SubjectArtifactID": d.subArtifactID,
|
||||
"SubjectArtifactDigest": d.subArtifactDigest,
|
||||
},
|
||||
})
|
||||
d.Require().Nil(err)
|
||||
@ -125,7 +128,7 @@ func (d *daoTestSuite) TestList() {
|
||||
|
||||
accs, err = d.dao.List(d.ctx, &q.Query{
|
||||
Keywords: map[string]interface{}{
|
||||
"SubjectArtifactID": d.subArtifactID,
|
||||
"SubjectArtifactDigest": d.subArtifactDigest,
|
||||
},
|
||||
})
|
||||
d.Require().Nil(err)
|
||||
@ -150,7 +153,7 @@ func (d *daoTestSuite) TestCreate() {
|
||||
// conflict
|
||||
acc := &Accessory{
|
||||
ArtifactID: d.artifactID,
|
||||
SubjectArtifactID: d.subArtifactID,
|
||||
SubjectArtifactDigest: d.subArtifactDigest,
|
||||
Digest: d.DigestString(),
|
||||
Size: 1234,
|
||||
Type: "cosign.signature",
|
||||
@ -158,18 +161,6 @@ func (d *daoTestSuite) TestCreate() {
|
||||
_, err := d.dao.Create(d.ctx, acc)
|
||||
d.Require().NotNil(err)
|
||||
d.True(errors.IsErr(err, errors.ConflictCode))
|
||||
|
||||
// violating foreign key constraint: the artifact that the tag tries to attach doesn't exist
|
||||
acc = &Accessory{
|
||||
ArtifactID: 999,
|
||||
SubjectArtifactID: 998,
|
||||
Digest: d.DigestString(),
|
||||
Size: 1234,
|
||||
Type: "cosign.signature",
|
||||
}
|
||||
_, err = d.dao.Create(d.ctx, acc)
|
||||
d.Require().NotNil(err)
|
||||
d.True(errors.IsErr(err, errors.ViolateForeignKeyConstraintCode))
|
||||
}
|
||||
|
||||
func (d *daoTestSuite) TestDelete() {
|
||||
@ -184,14 +175,15 @@ func (d *daoTestSuite) TestDelete() {
|
||||
}
|
||||
|
||||
func (d *daoTestSuite) TestDeleteOfArtifact() {
|
||||
subArtID, err := d.artDAO.Create(d.ctx, &artdao.Artifact{
|
||||
art := &artdao.Artifact{
|
||||
Type: "IMAGE",
|
||||
MediaType: "application/vnd.oci.image.config.v1+json",
|
||||
ManifestMediaType: "application/vnd.oci.image.manifest.v1+json",
|
||||
ProjectID: 1,
|
||||
RepositoryID: 1000,
|
||||
Digest: d.DigestString(),
|
||||
})
|
||||
}
|
||||
subArtID, err := d.artDAO.Create(d.ctx, art)
|
||||
d.Require().Nil(err)
|
||||
defer d.artDAO.Delete(d.ctx, subArtID)
|
||||
|
||||
@ -219,7 +211,7 @@ func (d *daoTestSuite) TestDeleteOfArtifact() {
|
||||
|
||||
acc1 := &Accessory{
|
||||
ArtifactID: artID1,
|
||||
SubjectArtifactID: subArtID,
|
||||
SubjectArtifactDigest: art.Digest,
|
||||
Digest: d.DigestString(),
|
||||
Size: 1234,
|
||||
Type: "cosign.signature",
|
||||
@ -229,7 +221,7 @@ func (d *daoTestSuite) TestDeleteOfArtifact() {
|
||||
|
||||
acc2 := &Accessory{
|
||||
ArtifactID: artID2,
|
||||
SubjectArtifactID: subArtID,
|
||||
SubjectArtifactDigest: art.Digest,
|
||||
Digest: d.DigestString(),
|
||||
Size: 1234,
|
||||
Type: "cosign.signature",
|
||||
@ -239,7 +231,7 @@ func (d *daoTestSuite) TestDeleteOfArtifact() {
|
||||
|
||||
accs, err := d.dao.List(d.ctx, &q.Query{
|
||||
Keywords: map[string]interface{}{
|
||||
"SubjectArtifactID": subArtID,
|
||||
"SubjectArtifactDigest": art.Digest,
|
||||
},
|
||||
})
|
||||
for _, acc := range accs {
|
||||
@ -250,14 +242,14 @@ func (d *daoTestSuite) TestDeleteOfArtifact() {
|
||||
|
||||
_, err = d.dao.DeleteAccessories(d.ctx, &q.Query{
|
||||
Keywords: map[string]interface{}{
|
||||
"SubjectArtifactID": subArtID,
|
||||
"SubjectArtifactDigest": art.Digest,
|
||||
},
|
||||
})
|
||||
d.Require().Nil(err)
|
||||
|
||||
accs, err = d.dao.List(d.ctx, &q.Query{
|
||||
Keywords: map[string]interface{}{
|
||||
"SubjectArtifactID": subArtID,
|
||||
"SubjectArtifactDigest": art.Digest,
|
||||
},
|
||||
})
|
||||
d.Require().Nil(err)
|
||||
|
@ -28,7 +28,7 @@ func init() {
|
||||
type Accessory struct {
|
||||
ID int64 `orm:"pk;auto;column(id)" json:"id"`
|
||||
ArtifactID int64 `orm:"column(artifact_id)" json:"artifact_id"`
|
||||
SubjectArtifactID int64 `orm:"column(subject_artifact_id)" json:"subject_artifact_id"`
|
||||
SubjectArtifactDigest string `orm:"column(subject_artifact_digest)" json:"subject_artifact_digest"`
|
||||
Type string `orm:"column(type)" json:"type"`
|
||||
Size int64 `orm:"column(size)" json:"size"`
|
||||
Digest string `orm:"column(digest)" json:"digest"`
|
||||
|
@ -38,7 +38,7 @@ var (
|
||||
// Manager is the only interface of artifact module to provide the management functions for artifacts
|
||||
type Manager interface {
|
||||
// Ensure ...
|
||||
Ensure(ctx context.Context, subArtID, artifactID, size int64, digest, accType string) error
|
||||
Ensure(ctx context.Context, subArtDigest string, artifactID, size int64, digest, accType string) error
|
||||
// Get the artifact specified by the ID
|
||||
Get(ctx context.Context, id int64) (accessory model.Accessory, err error)
|
||||
// Count returns the total count of accessory according to the query.
|
||||
@ -66,7 +66,7 @@ type manager struct {
|
||||
dao dao.DAO
|
||||
}
|
||||
|
||||
func (m *manager) Ensure(ctx context.Context, subArtID, artifactID, size int64, digest, accType string) error {
|
||||
func (m *manager) Ensure(ctx context.Context, subArtDigest string, artifactID, size int64, digest, accType string) error {
|
||||
accs, err := m.dao.List(ctx, q.New(q.KeyWords{"ArtifactID": artifactID, "Digest": digest}))
|
||||
if err != nil {
|
||||
return err
|
||||
@ -77,7 +77,7 @@ func (m *manager) Ensure(ctx context.Context, subArtID, artifactID, size int64,
|
||||
|
||||
acc := model.AccessoryData{
|
||||
ArtifactID: artifactID,
|
||||
SubArtifactID: subArtID,
|
||||
SubArtifactDigest: subArtDigest,
|
||||
Digest: digest,
|
||||
Size: size,
|
||||
Type: accType,
|
||||
@ -94,7 +94,7 @@ func (m *manager) Get(ctx context.Context, id int64) (model.Accessory, error) {
|
||||
return model.New(acc.Type, model.AccessoryData{
|
||||
ID: acc.ID,
|
||||
ArtifactID: acc.ArtifactID,
|
||||
SubArtifactID: acc.SubjectArtifactID,
|
||||
SubArtifactDigest: acc.SubjectArtifactDigest,
|
||||
Size: acc.Size,
|
||||
Digest: acc.Digest,
|
||||
CreatTime: acc.CreationTime,
|
||||
@ -116,7 +116,7 @@ func (m *manager) List(ctx context.Context, query *q.Query) ([]model.Accessory,
|
||||
acc, err := model.New(accD.Type, model.AccessoryData{
|
||||
ID: accD.ID,
|
||||
ArtifactID: accD.ArtifactID,
|
||||
SubArtifactID: accD.SubjectArtifactID,
|
||||
SubArtifactDigest: accD.SubjectArtifactDigest,
|
||||
Size: accD.Size,
|
||||
Digest: accD.Digest,
|
||||
CreatTime: accD.CreationTime,
|
||||
@ -133,7 +133,7 @@ func (m *manager) List(ctx context.Context, query *q.Query) ([]model.Accessory,
|
||||
func (m *manager) Create(ctx context.Context, accessory model.AccessoryData) (int64, error) {
|
||||
acc := &dao.Accessory{
|
||||
ArtifactID: accessory.ArtifactID,
|
||||
SubjectArtifactID: accessory.SubArtifactID,
|
||||
SubjectArtifactDigest: accessory.SubArtifactDigest,
|
||||
Size: accessory.Size,
|
||||
Digest: accessory.Digest,
|
||||
Type: accessory.Type,
|
||||
|
@ -45,7 +45,7 @@ func (m *managerTestSuite) SetupTest() {
|
||||
func (m *managerTestSuite) TestEnsure() {
|
||||
mock.OnAnything(m.dao, "List").Return([]*dao.Accessory{}, nil)
|
||||
mock.OnAnything(m.dao, "Create").Return(int64(1), nil)
|
||||
err := m.mgr.Ensure(nil, int64(1), int64(1), int64(1), "sha256:1234", model.TypeCosignSignature)
|
||||
err := m.mgr.Ensure(nil, string(""), int64(1), int64(1), "sha256:1234", model.TypeCosignSignature)
|
||||
m.Require().Nil(err)
|
||||
}
|
||||
|
||||
|
@ -75,7 +75,7 @@ const (
|
||||
type AccessoryData struct {
|
||||
ID int64 `json:"id"`
|
||||
ArtifactID int64 `json:"artifact_id"`
|
||||
SubArtifactID int64 `json:"subject_artifact_id"`
|
||||
SubArtifactDigest string `json:"subject_artifact_id"`
|
||||
Type string `json:"type"`
|
||||
Size int64 `json:"size"`
|
||||
Digest string `json:"digest"`
|
||||
|
@ -22,7 +22,7 @@ func (suite *BaseTestSuite) SetupSuite() {
|
||||
suite.accessory, _ = model.New(model.TypeNone,
|
||||
model.AccessoryData{
|
||||
ArtifactID: 1,
|
||||
SubArtifactID: 2,
|
||||
SubArtifactDigest: suite.subDigest,
|
||||
Size: 1234,
|
||||
Digest: suite.digest,
|
||||
})
|
||||
@ -37,7 +37,7 @@ func (suite *BaseTestSuite) TestGetArtID() {
|
||||
}
|
||||
|
||||
func (suite *BaseTestSuite) TestSubGetArtID() {
|
||||
suite.Equal(int64(2), suite.accessory.GetData().SubArtifactID)
|
||||
suite.Equal(suite.subDigest, suite.accessory.GetData().SubArtifactDigest)
|
||||
}
|
||||
|
||||
func (suite *BaseTestSuite) TestSubGetSize() {
|
||||
|
@ -13,14 +13,16 @@ type CosignTestSuite struct {
|
||||
htesting.Suite
|
||||
accessory model.Accessory
|
||||
digest string
|
||||
subDigest string
|
||||
}
|
||||
|
||||
func (suite *CosignTestSuite) SetupSuite() {
|
||||
suite.digest = suite.DigestString()
|
||||
suite.subDigest = suite.DigestString()
|
||||
suite.accessory, _ = model.New(model.TypeCosignSignature,
|
||||
model.AccessoryData{
|
||||
ArtifactID: 1,
|
||||
SubArtifactID: 2,
|
||||
SubArtifactDigest: suite.subDigest,
|
||||
Size: 4321,
|
||||
Digest: suite.digest,
|
||||
})
|
||||
@ -35,7 +37,7 @@ func (suite *CosignTestSuite) TestGetArtID() {
|
||||
}
|
||||
|
||||
func (suite *CosignTestSuite) TestSubGetArtID() {
|
||||
suite.Equal(int64(2), suite.accessory.GetData().SubArtifactID)
|
||||
suite.Equal(suite.subDigest, suite.accessory.GetData().SubArtifactDigest)
|
||||
}
|
||||
|
||||
func (suite *CosignTestSuite) TestSubGetSize() {
|
||||
|
@ -13,14 +13,16 @@ type NydusTestSuite struct {
|
||||
htesting.Suite
|
||||
accessory model.Accessory
|
||||
digest string
|
||||
subDigest string
|
||||
}
|
||||
|
||||
func (suite *NydusTestSuite) SetupSuite() {
|
||||
suite.digest = suite.DigestString()
|
||||
suite.subDigest = suite.DigestString()
|
||||
suite.accessory, _ = model.New(model.TypeNydusAccelerator,
|
||||
model.AccessoryData{
|
||||
ArtifactID: 1,
|
||||
SubArtifactID: 2,
|
||||
SubArtifactDigest: suite.subDigest,
|
||||
Size: 4321,
|
||||
Digest: suite.digest,
|
||||
})
|
||||
@ -35,7 +37,7 @@ func (suite *NydusTestSuite) TestGetArtID() {
|
||||
}
|
||||
|
||||
func (suite *NydusTestSuite) TestSubGetArtID() {
|
||||
suite.Equal(int64(2), suite.accessory.GetData().SubArtifactID)
|
||||
suite.Equal(suite.subDigest, suite.accessory.GetData().SubArtifactDigest)
|
||||
}
|
||||
|
||||
func (suite *NydusTestSuite) TestSubGetSize() {
|
||||
|
@ -229,7 +229,7 @@ func (suite *CosignMiddlewareTestSuite) TestSignaturePulling() {
|
||||
Data: accessorymodel.AccessoryData{
|
||||
ID: 1,
|
||||
ArtifactID: 2,
|
||||
SubArtifactID: 1,
|
||||
SubArtifactDigest: suite.artifact.Digest,
|
||||
Type: accessorymodel.TypeCosignSignature,
|
||||
},
|
||||
}
|
||||
|
@ -212,7 +212,7 @@ func (suite *MiddlewareTestSuite) TestSignaturePulling() {
|
||||
Data: accessorymodel.AccessoryData{
|
||||
ID: 1,
|
||||
ArtifactID: 2,
|
||||
SubArtifactID: 1,
|
||||
SubArtifactDigest: suite.artifact.Digest,
|
||||
Type: accessorymodel.TypeCosignSignature,
|
||||
},
|
||||
}
|
||||
|
@ -111,7 +111,7 @@ func SignatureMiddleware() func(http.Handler) http.Handler {
|
||||
if err := orm.WithTransaction(func(ctx context.Context) error {
|
||||
_, err := accessory.Mgr.Create(ctx, model.AccessoryData{
|
||||
ArtifactID: art.ID,
|
||||
SubArtifactID: subjectArt.ID,
|
||||
SubArtifactDigest: subjectArt.Digest,
|
||||
Size: desc.Size,
|
||||
Digest: desc.Digest.String(),
|
||||
Type: model.TypeCosignSignature,
|
||||
|
@ -15,8 +15,8 @@ import (
|
||||
"github.com/goharbor/harbor/src/lib/q"
|
||||
"github.com/goharbor/harbor/src/pkg"
|
||||
"github.com/goharbor/harbor/src/pkg/accessory"
|
||||
accessorymodel "github.com/goharbor/harbor/src/pkg/accessory/model"
|
||||
"github.com/goharbor/harbor/src/pkg/accessory/model"
|
||||
accessorymodel "github.com/goharbor/harbor/src/pkg/accessory/model"
|
||||
_ "github.com/goharbor/harbor/src/pkg/accessory/model/base"
|
||||
_ "github.com/goharbor/harbor/src/pkg/accessory/model/cosign"
|
||||
"github.com/goharbor/harbor/src/pkg/artifact"
|
||||
@ -98,7 +98,7 @@ func (suite *MiddlewareTestSuite) addArtAcc(pid, repositoryID int64, repositoryN
|
||||
PushTime: time.Now(),
|
||||
PullTime: time.Now(),
|
||||
}
|
||||
subafid, err := pkg.ArtifactMgr.Create(suite.Context(), subaf)
|
||||
_, err := pkg.ArtifactMgr.Create(suite.Context(), subaf)
|
||||
suite.Nil(err, fmt.Sprintf("Add artifact failed for %d", repositoryID))
|
||||
|
||||
af := &artifact.Artifact{
|
||||
@ -117,7 +117,7 @@ func (suite *MiddlewareTestSuite) addArtAcc(pid, repositoryID int64, repositoryN
|
||||
accid, err := accessory.Mgr.Create(suite.Context(), accessorymodel.AccessoryData{
|
||||
ID: 1,
|
||||
ArtifactID: afid,
|
||||
SubArtifactID: subafid,
|
||||
SubArtifactDigest: subaf.Digest,
|
||||
Digest: accdgt,
|
||||
Type: accessorymodel.TypeCosignSignature,
|
||||
})
|
||||
@ -134,7 +134,7 @@ func (suite *MiddlewareTestSuite) TestCosignSignature() {
|
||||
|
||||
_, repoId, err := repository.Ctl.Ensure(suite.Context(), name)
|
||||
suite.Nil(err)
|
||||
subjectArtID := suite.addArt(projectID, repoId, name, subArtDigest)
|
||||
suite.addArt(projectID, repoId, name, subArtDigest)
|
||||
artID := suite.addArt(projectID, repoId, name, descriptor.Digest.String())
|
||||
suite.Nil(err)
|
||||
|
||||
@ -145,11 +145,11 @@ func (suite *MiddlewareTestSuite) TestCosignSignature() {
|
||||
|
||||
accs, err := accessory.Mgr.List(suite.Context(), &q.Query{
|
||||
Keywords: map[string]interface{}{
|
||||
"SubjectArtifactID": subjectArtID,
|
||||
"SubjectArtifactDigest": subArtDigest,
|
||||
},
|
||||
})
|
||||
suite.Equal(1, len(accs))
|
||||
suite.Equal(subjectArtID, accs[0].GetData().SubArtifactID)
|
||||
suite.Equal(subArtDigest, accs[0].GetData().SubArtifactDigest)
|
||||
suite.Equal(artID, accs[0].GetData().ArtifactID)
|
||||
suite.True(accs[0].IsHard())
|
||||
suite.Equal(model.TypeCosignSignature, accs[0].GetData().Type)
|
||||
|
@ -130,7 +130,7 @@ func AcceleratorMiddleware() func(http.Handler) http.Handler {
|
||||
if err := orm.WithTransaction(func(ctx context.Context) error {
|
||||
id, err := accessory.Mgr.Create(ctx, model.AccessoryData{
|
||||
ArtifactID: art.ID,
|
||||
SubArtifactID: subjectArt.ID,
|
||||
SubArtifactDigest: subjectArt.Digest,
|
||||
Size: desc.Size,
|
||||
Digest: desc.Digest.String(),
|
||||
Type: model.TypeNydusAccelerator,
|
||||
|
@ -15,8 +15,8 @@ import (
|
||||
"github.com/goharbor/harbor/src/lib/q"
|
||||
"github.com/goharbor/harbor/src/pkg"
|
||||
"github.com/goharbor/harbor/src/pkg/accessory"
|
||||
accessorymodel "github.com/goharbor/harbor/src/pkg/accessory/model"
|
||||
"github.com/goharbor/harbor/src/pkg/accessory/model"
|
||||
accessorymodel "github.com/goharbor/harbor/src/pkg/accessory/model"
|
||||
_ "github.com/goharbor/harbor/src/pkg/accessory/model/base"
|
||||
_ "github.com/goharbor/harbor/src/pkg/accessory/model/nydus"
|
||||
"github.com/goharbor/harbor/src/pkg/artifact"
|
||||
@ -114,7 +114,7 @@ func (suite *MiddlewareTestSuite) addArtAcc(pid, repositoryID int64, repositoryN
|
||||
PushTime: time.Now(),
|
||||
PullTime: time.Now(),
|
||||
}
|
||||
subafid, err := pkg.ArtifactMgr.Create(suite.Context(), subaf)
|
||||
_, err := pkg.ArtifactMgr.Create(suite.Context(), subaf)
|
||||
suite.Nil(err, fmt.Sprintf("Add artifact failed for %d", repositoryID))
|
||||
|
||||
af := &artifact.Artifact{
|
||||
@ -133,7 +133,7 @@ func (suite *MiddlewareTestSuite) addArtAcc(pid, repositoryID int64, repositoryN
|
||||
accid, err := accessory.Mgr.Create(suite.Context(), accessorymodel.AccessoryData{
|
||||
ID: 1,
|
||||
ArtifactID: afid,
|
||||
SubArtifactID: subafid,
|
||||
SubArtifactDigest: subaf.Digest,
|
||||
Digest: accdgt,
|
||||
Type: accessorymodel.TypeNydusAccelerator,
|
||||
})
|
||||
@ -152,7 +152,7 @@ func (suite *MiddlewareTestSuite) TestNydusAccelerator() {
|
||||
suite.Nil(err)
|
||||
|
||||
// add subject artifact
|
||||
subjectArtID := suite.addArt(projectID, repoId, name, subArtDigest)
|
||||
suite.addArt(projectID, repoId, name, subArtDigest)
|
||||
|
||||
// add nydus artifact
|
||||
artID := suite.addArt(projectID, repoId, name, descriptor.Digest.String())
|
||||
@ -165,11 +165,11 @@ func (suite *MiddlewareTestSuite) TestNydusAccelerator() {
|
||||
|
||||
accs, _ := accessory.Mgr.List(suite.Context(), &q.Query{
|
||||
Keywords: map[string]interface{}{
|
||||
"SubjectArtifactID": subjectArtID,
|
||||
"SubjectArtifactDigest": subArtDigest,
|
||||
},
|
||||
})
|
||||
suite.Equal(1, len(accs))
|
||||
suite.Equal(subjectArtID, accs[0].GetData().SubArtifactID)
|
||||
suite.Equal(subArtDigest, accs[0].GetData().SubArtifactDigest)
|
||||
suite.Equal(artID, accs[0].GetData().ArtifactID)
|
||||
suite.True(accs[0].IsHard())
|
||||
suite.Equal(model.TypeNydusAccelerator, accs[0].GetData().Type)
|
||||
|
@ -385,7 +385,7 @@ func (suite *MiddlewareTestSuite) TestSignaturePulling() {
|
||||
Data: accessorymodel.AccessoryData{
|
||||
ID: 1,
|
||||
ArtifactID: 2,
|
||||
SubArtifactID: 1,
|
||||
SubArtifactDigest: suite.artifact.Digest,
|
||||
Type: accessorymodel.TypeCosignSignature,
|
||||
},
|
||||
}
|
||||
|
@ -372,7 +372,7 @@ func (a *artifactAPI) ListAccessories(ctx context.Context, params operation.List
|
||||
if err != nil {
|
||||
return a.SendError(ctx, err)
|
||||
}
|
||||
query.Keywords["SubjectArtifactID"] = artifact.ID
|
||||
query.Keywords["SubjectArtifactDigest"] = artifact.Digest
|
||||
|
||||
// list accessories according to the query
|
||||
total, err := a.accMgr.Count(ctx, query)
|
||||
|
@ -17,7 +17,7 @@ func (a *Accessory) ToSwagger() *models.Accessory {
|
||||
return &models.Accessory{
|
||||
ID: a.ID,
|
||||
ArtifactID: a.ArtifactID,
|
||||
SubjectArtifactID: a.SubArtifactID,
|
||||
SubjectArtifactDigest: a.SubArtifactDigest,
|
||||
Size: a.Size,
|
||||
Digest: a.Digest,
|
||||
Type: a.Type,
|
||||
|
@ -86,13 +86,13 @@ func (_m *Manager) DeleteAccessories(ctx context.Context, _a1 *q.Query) error {
|
||||
return r0
|
||||
}
|
||||
|
||||
// Ensure provides a mock function with given fields: ctx, subArtID, artifactID, size, digest, accType
|
||||
func (_m *Manager) Ensure(ctx context.Context, subArtID int64, artifactID int64, size int64, digest string, accType string) error {
|
||||
ret := _m.Called(ctx, subArtID, artifactID, size, digest, accType)
|
||||
// Ensure provides a mock function with given fields: ctx, subArtDigest, artifactID, size, digest, accType
|
||||
func (_m *Manager) Ensure(ctx context.Context, subArtDigest string, artifactID int64, size int64, digest string, accType string) error {
|
||||
ret := _m.Called(ctx, subArtDigest, artifactID, size, digest, accType)
|
||||
|
||||
var r0 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, int64, int64, int64, string, string) error); ok {
|
||||
r0 = rf(ctx, subArtID, artifactID, size, digest, accType)
|
||||
if rf, ok := ret.Get(0).(func(context.Context, string, int64, int64, string, string) error); ok {
|
||||
r0 = rf(ctx, subArtDigest, artifactID, size, digest, accType)
|
||||
} else {
|
||||
r0 = ret.Error(0)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user