mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-27 04:35:16 +01:00
Merge pull request #10857 from bitsf/remove_pkg_art
feat(oci) remove dead code pkg/art
This commit is contained in:
commit
70dcca6579
@ -5,8 +5,8 @@ import (
|
|||||||
"github.com/goharbor/harbor/src/common/utils"
|
"github.com/goharbor/harbor/src/common/utils"
|
||||||
"github.com/goharbor/harbor/src/common/utils/log"
|
"github.com/goharbor/harbor/src/common/utils/log"
|
||||||
ierror "github.com/goharbor/harbor/src/internal/error"
|
ierror "github.com/goharbor/harbor/src/internal/error"
|
||||||
"github.com/goharbor/harbor/src/pkg/art"
|
|
||||||
"github.com/goharbor/harbor/src/pkg/artifact"
|
"github.com/goharbor/harbor/src/pkg/artifact"
|
||||||
|
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
||||||
"github.com/goharbor/harbor/src/pkg/immutabletag/match"
|
"github.com/goharbor/harbor/src/pkg/immutabletag/match"
|
||||||
"github.com/goharbor/harbor/src/pkg/immutabletag/match/rule"
|
"github.com/goharbor/harbor/src/pkg/immutabletag/match/rule"
|
||||||
"github.com/goharbor/harbor/src/pkg/q"
|
"github.com/goharbor/harbor/src/pkg/q"
|
||||||
@ -201,7 +201,7 @@ func (c *controller) populateImmutableStatus(ctx context.Context, tag *Tag) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
_, repoName := utils.ParseRepository(artifact.RepositoryName)
|
_, repoName := utils.ParseRepository(artifact.RepositoryName)
|
||||||
matched, err := c.immutableMtr.Match(artifact.ProjectID, art.Candidate{
|
matched, err := c.immutableMtr.Match(artifact.ProjectID, artifactselector.Candidate{
|
||||||
Repository: repoName,
|
Repository: repoName,
|
||||||
Tags: []string{tag.Name},
|
Tags: []string{tag.Name},
|
||||||
NamespaceID: artifact.ProjectID,
|
NamespaceID: artifact.ProjectID,
|
||||||
|
@ -1,40 +0,0 @@
|
|||||||
// Copyright Project Harbor Authors
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package art
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/goharbor/harbor/src/common/models"
|
|
||||||
"github.com/goharbor/harbor/src/pkg/q"
|
|
||||||
)
|
|
||||||
|
|
||||||
// DefaultController for easy referring as a singleton instance
|
|
||||||
var DefaultController = NewController()
|
|
||||||
|
|
||||||
// basicController is the default implementation of controller
|
|
||||||
type basicController struct {
|
|
||||||
m Manager
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewController ...
|
|
||||||
func NewController() Controller {
|
|
||||||
return &basicController{
|
|
||||||
m: NewManager(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// List artifacts
|
|
||||||
func (b *basicController) List(query *q.Query) ([]*models.Artifact, error) {
|
|
||||||
return b.m.List(query)
|
|
||||||
}
|
|
@ -1,87 +0,0 @@
|
|||||||
// Copyright Project Harbor Authors
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package art
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/common/models"
|
|
||||||
"github.com/goharbor/harbor/src/pkg/q"
|
|
||||||
"github.com/stretchr/testify/mock"
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
"github.com/stretchr/testify/suite"
|
|
||||||
)
|
|
||||||
|
|
||||||
// TestControllerSuite is a test suite for testing controller.
|
|
||||||
type TestControllerSuite struct {
|
|
||||||
suite.Suite
|
|
||||||
|
|
||||||
c *basicController
|
|
||||||
m *MockManager
|
|
||||||
}
|
|
||||||
|
|
||||||
// TestController is the entry point of TestControllerSuite.
|
|
||||||
func TestController(t *testing.T) {
|
|
||||||
suite.Run(t, &TestControllerSuite{})
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetupSuite prepares env for test suite.
|
|
||||||
func (suite *TestControllerSuite) SetupSuite() {
|
|
||||||
suite.m = &MockManager{}
|
|
||||||
suite.c = &basicController{
|
|
||||||
m: suite.m,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TestControllerList ...
|
|
||||||
func (suite *TestControllerSuite) TestControllerList() {
|
|
||||||
kws := make(map[string]interface{})
|
|
||||||
kws["digest"] = "digest-code"
|
|
||||||
query := &q.Query{
|
|
||||||
Keywords: kws,
|
|
||||||
}
|
|
||||||
|
|
||||||
artifacts := []*models.Artifact{
|
|
||||||
{
|
|
||||||
ID: 1000,
|
|
||||||
PID: 1,
|
|
||||||
Repo: "library/busybox",
|
|
||||||
Tag: "dev",
|
|
||||||
Digest: "digest-code",
|
|
||||||
Kind: "image",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
suite.m.On("List", query).Return(artifacts, nil)
|
|
||||||
|
|
||||||
arts, err := suite.c.List(query)
|
|
||||||
require.NoError(suite.T(), err)
|
|
||||||
suite.Equal(1, len(arts))
|
|
||||||
}
|
|
||||||
|
|
||||||
// MockManager ...
|
|
||||||
type MockManager struct {
|
|
||||||
mock.Mock
|
|
||||||
}
|
|
||||||
|
|
||||||
// List ...
|
|
||||||
func (mm *MockManager) List(query *q.Query) ([]*models.Artifact, error) {
|
|
||||||
args := mm.Called(query)
|
|
||||||
if args.Get(0) == nil {
|
|
||||||
return nil, args.Error(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
return args.Get(0).([]*models.Artifact), args.Error(1)
|
|
||||||
}
|
|
@ -1,72 +0,0 @@
|
|||||||
// Copyright Project Harbor Authors
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package art
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/goharbor/harbor/src/common/dao"
|
|
||||||
"github.com/goharbor/harbor/src/common/models"
|
|
||||||
"github.com/goharbor/harbor/src/pkg/q"
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
)
|
|
||||||
|
|
||||||
// basicManager is the default implementation of artifact manager
|
|
||||||
type basicManager struct{}
|
|
||||||
|
|
||||||
// NewManager creates a new basic manager as the default one.
|
|
||||||
func NewManager() Manager {
|
|
||||||
return &basicManager{}
|
|
||||||
}
|
|
||||||
|
|
||||||
// List artifacts
|
|
||||||
func (b *basicManager) List(query *q.Query) ([]*models.Artifact, error) {
|
|
||||||
aq := &models.ArtifactQuery{}
|
|
||||||
makeArtQuery(aq, query)
|
|
||||||
|
|
||||||
l, err := dao.ListArtifacts(aq)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "artifact manager: list")
|
|
||||||
}
|
|
||||||
|
|
||||||
return l, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func makeArtQuery(aq *models.ArtifactQuery, query *q.Query) {
|
|
||||||
if aq == nil {
|
|
||||||
return // do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
if query != nil {
|
|
||||||
if len(query.Keywords) > 0 {
|
|
||||||
for k, v := range query.Keywords {
|
|
||||||
switch k {
|
|
||||||
case "project_id":
|
|
||||||
aq.PID = v.(int64)
|
|
||||||
case "repo":
|
|
||||||
aq.Repo = v.(string)
|
|
||||||
case "tag":
|
|
||||||
aq.Tag = v.(string)
|
|
||||||
case "digest":
|
|
||||||
aq.Digest = v.(string)
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if query.PageNumber > 0 && query.PageSize > 0 {
|
|
||||||
aq.Page = query.PageNumber
|
|
||||||
aq.Size = query.PageSize
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,56 +0,0 @@
|
|||||||
// Copyright Project Harbor Authors
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package art
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/common/dao"
|
|
||||||
"github.com/goharbor/harbor/src/pkg/q"
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
"github.com/stretchr/testify/suite"
|
|
||||||
)
|
|
||||||
|
|
||||||
// TestManagerSuite is a test suite for testing manager
|
|
||||||
type TestManagerSuite struct {
|
|
||||||
suite.Suite
|
|
||||||
|
|
||||||
m *basicManager
|
|
||||||
}
|
|
||||||
|
|
||||||
// TestManager is the entry point of TestManagerSuite
|
|
||||||
func TestManager(t *testing.T) {
|
|
||||||
suite.Run(t, &TestManagerSuite{})
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetupSuite prepares env for test suite
|
|
||||||
func (suite *TestManagerSuite) SetupSuite() {
|
|
||||||
dao.PrepareTestForPostgresSQL()
|
|
||||||
|
|
||||||
suite.m = &basicManager{}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TestManagerSuiteList ...
|
|
||||||
func (suite *TestManagerSuite) TestManagerSuiteList() {
|
|
||||||
kws := make(map[string]interface{})
|
|
||||||
kws["digest"] = "fake-digest"
|
|
||||||
|
|
||||||
l, err := suite.m.List(&q.Query{
|
|
||||||
Keywords: kws,
|
|
||||||
})
|
|
||||||
|
|
||||||
require.NoError(suite.T(), err)
|
|
||||||
suite.Equal(0, len(l))
|
|
||||||
}
|
|
@ -1,33 +0,0 @@
|
|||||||
// Copyright Project Harbor Authors
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package art
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/goharbor/harbor/src/common/models"
|
|
||||||
"github.com/goharbor/harbor/src/pkg/q"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Controller for artifact
|
|
||||||
type Controller interface {
|
|
||||||
// List the artifacts with queries
|
|
||||||
//
|
|
||||||
// Arguments:
|
|
||||||
// query *q.Query : optional query parameters
|
|
||||||
//
|
|
||||||
// Returns:
|
|
||||||
// []*models.Artifact : the queried artifacts
|
|
||||||
// error : non nil error if any errors occurred
|
|
||||||
List(query *q.Query) ([]*models.Artifact, error)
|
|
||||||
}
|
|
@ -1,33 +0,0 @@
|
|||||||
// Copyright Project Harbor Authors
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package art
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/goharbor/harbor/src/common/models"
|
|
||||||
"github.com/goharbor/harbor/src/pkg/q"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Manager is designed to manage the artifact
|
|
||||||
type Manager interface {
|
|
||||||
// List the artifacts with queries
|
|
||||||
//
|
|
||||||
// Arguments:
|
|
||||||
// query *q.Query : optional query parameters
|
|
||||||
//
|
|
||||||
// Returns:
|
|
||||||
// []*models.Artifact : the queried artifacts
|
|
||||||
// error : non nil error if any errors occurred
|
|
||||||
List(query *q.Query) ([]*models.Artifact, error)
|
|
||||||
}
|
|
@ -12,7 +12,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package art
|
package artifactselector
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
@ -12,7 +12,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package art
|
package artifactselector
|
||||||
|
|
||||||
// Result keeps the action result
|
// Result keeps the action result
|
||||||
type Result struct {
|
type Result struct {
|
@ -12,7 +12,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package art
|
package artifactselector
|
||||||
|
|
||||||
// Selector is used to filter the inputting list
|
// Selector is used to filter the inputting list
|
||||||
type Selector interface {
|
type Selector interface {
|
@ -16,7 +16,7 @@ package doublestar
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/bmatcuk/doublestar"
|
"github.com/bmatcuk/doublestar"
|
||||||
"github.com/goharbor/harbor/src/pkg/art"
|
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -46,7 +46,7 @@ type selector struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Select candidates by regular expressions
|
// Select candidates by regular expressions
|
||||||
func (s *selector) Select(artifacts []*art.Candidate) (selected []*art.Candidate, err error) {
|
func (s *selector) Select(artifacts []*artifactselector.Candidate) (selected []*artifactselector.Candidate, err error) {
|
||||||
value := ""
|
value := ""
|
||||||
excludes := false
|
excludes := false
|
||||||
|
|
||||||
@ -96,7 +96,7 @@ func (s *selector) Select(artifacts []*art.Candidate) (selected []*art.Candidate
|
|||||||
return selected, nil
|
return selected, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *selector) tagSelectMatch(artifact *art.Candidate) (selected bool, err error) {
|
func (s *selector) tagSelectMatch(artifact *artifactselector.Candidate) (selected bool, err error) {
|
||||||
for _, t := range artifact.Tags {
|
for _, t := range artifact.Tags {
|
||||||
matched, err := match(s.pattern, t)
|
matched, err := match(s.pattern, t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -109,7 +109,7 @@ func (s *selector) tagSelectMatch(artifact *art.Candidate) (selected bool, err e
|
|||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *selector) tagSelectExclude(artifact *art.Candidate) (selected bool, err error) {
|
func (s *selector) tagSelectExclude(artifact *artifactselector.Candidate) (selected bool, err error) {
|
||||||
for _, t := range artifact.Tags {
|
for _, t := range artifact.Tags {
|
||||||
matched, err := match(s.pattern, t)
|
matched, err := match(s.pattern, t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -123,7 +123,7 @@ func (s *selector) tagSelectExclude(artifact *art.Candidate) (selected bool, err
|
|||||||
}
|
}
|
||||||
|
|
||||||
// New is factory method for doublestar selector
|
// New is factory method for doublestar selector
|
||||||
func New(decoration string, pattern string) art.Selector {
|
func New(decoration string, pattern string) artifactselector.Selector {
|
||||||
return &selector{
|
return &selector{
|
||||||
decoration: decoration,
|
decoration: decoration,
|
||||||
pattern: pattern,
|
pattern: pattern,
|
@ -16,7 +16,7 @@ package doublestar
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/goharbor/harbor/src/pkg/art"
|
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
@ -28,7 +28,7 @@ import (
|
|||||||
type RegExpSelectorTestSuite struct {
|
type RegExpSelectorTestSuite struct {
|
||||||
suite.Suite
|
suite.Suite
|
||||||
|
|
||||||
artifacts []*art.Candidate
|
artifacts []*artifactselector.Candidate
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestRegExpSelector is entrance for RegExpSelectorTestSuite
|
// TestRegExpSelector is entrance for RegExpSelectorTestSuite
|
||||||
@ -38,13 +38,13 @@ func TestRegExpSelector(t *testing.T) {
|
|||||||
|
|
||||||
// SetupSuite to do preparation work
|
// SetupSuite to do preparation work
|
||||||
func (suite *RegExpSelectorTestSuite) SetupSuite() {
|
func (suite *RegExpSelectorTestSuite) SetupSuite() {
|
||||||
suite.artifacts = []*art.Candidate{
|
suite.artifacts = []*artifactselector.Candidate{
|
||||||
{
|
{
|
||||||
NamespaceID: 1,
|
NamespaceID: 1,
|
||||||
Namespace: "library",
|
Namespace: "library",
|
||||||
Repository: "harbor",
|
Repository: "harbor",
|
||||||
Tags: []string{"latest"},
|
Tags: []string{"latest"},
|
||||||
Kind: art.Image,
|
Kind: artifactselector.Image,
|
||||||
PushedTime: time.Now().Unix() - 3600,
|
PushedTime: time.Now().Unix() - 3600,
|
||||||
PulledTime: time.Now().Unix(),
|
PulledTime: time.Now().Unix(),
|
||||||
CreationTime: time.Now().Unix() - 7200,
|
CreationTime: time.Now().Unix() - 7200,
|
||||||
@ -55,7 +55,7 @@ func (suite *RegExpSelectorTestSuite) SetupSuite() {
|
|||||||
Namespace: "retention",
|
Namespace: "retention",
|
||||||
Repository: "redis",
|
Repository: "redis",
|
||||||
Tags: []string{"4.0"},
|
Tags: []string{"4.0"},
|
||||||
Kind: art.Image,
|
Kind: artifactselector.Image,
|
||||||
PushedTime: time.Now().Unix() - 3600,
|
PushedTime: time.Now().Unix() - 3600,
|
||||||
PulledTime: time.Now().Unix(),
|
PulledTime: time.Now().Unix(),
|
||||||
CreationTime: time.Now().Unix() - 7200,
|
CreationTime: time.Now().Unix() - 7200,
|
||||||
@ -66,7 +66,7 @@ func (suite *RegExpSelectorTestSuite) SetupSuite() {
|
|||||||
Namespace: "retention",
|
Namespace: "retention",
|
||||||
Repository: "redis",
|
Repository: "redis",
|
||||||
Tags: []string{"4.1"},
|
Tags: []string{"4.1"},
|
||||||
Kind: art.Image,
|
Kind: artifactselector.Image,
|
||||||
PushedTime: time.Now().Unix() - 3600,
|
PushedTime: time.Now().Unix() - 3600,
|
||||||
PulledTime: time.Now().Unix(),
|
PulledTime: time.Now().Unix(),
|
||||||
CreationTime: time.Now().Unix() - 7200,
|
CreationTime: time.Now().Unix() - 7200,
|
||||||
@ -235,7 +235,7 @@ func (suite *RegExpSelectorTestSuite) TestNSExcludes() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check whether the returned result matched the expected ones (only check repo:tag)
|
// Check whether the returned result matched the expected ones (only check repo:tag)
|
||||||
func expect(expected []string, candidates []*art.Candidate) bool {
|
func expect(expected []string, candidates []*artifactselector.Candidate) bool {
|
||||||
hash := make(map[string]bool)
|
hash := make(map[string]bool)
|
||||||
|
|
||||||
for _, art := range candidates {
|
for _, art := range candidates {
|
@ -15,10 +15,10 @@
|
|||||||
package index
|
package index
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/pkg/art"
|
"github.com/goharbor/harbor/src/pkg/artifactselector/selectors/doublestar"
|
||||||
"github.com/goharbor/harbor/src/pkg/art/selectors/doublestar"
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -49,11 +49,11 @@ type IndexedMeta struct {
|
|||||||
// indexedItem defined item kept in the index
|
// indexedItem defined item kept in the index
|
||||||
type indexedItem struct {
|
type indexedItem struct {
|
||||||
Meta *IndexedMeta
|
Meta *IndexedMeta
|
||||||
Factory art.SelectorFactory
|
Factory artifactselector.SelectorFactory
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register the selector with the corresponding selector kind and decoration
|
// Register the selector with the corresponding selector kind and decoration
|
||||||
func Register(kind string, decorations []string, factory art.SelectorFactory) {
|
func Register(kind string, decorations []string, factory artifactselector.SelectorFactory) {
|
||||||
if len(kind) == 0 || factory == nil {
|
if len(kind) == 0 || factory == nil {
|
||||||
// do nothing
|
// do nothing
|
||||||
return
|
return
|
||||||
@ -69,7 +69,7 @@ func Register(kind string, decorations []string, factory art.SelectorFactory) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get selector with the provided kind and decoration
|
// Get selector with the provided kind and decoration
|
||||||
func Get(kind, decoration, pattern string) (art.Selector, error) {
|
func Get(kind, decoration, pattern string) (artifactselector.Selector, error) {
|
||||||
if len(kind) == 0 || len(decoration) == 0 {
|
if len(kind) == 0 || len(decoration) == 0 {
|
||||||
return nil, errors.New("empty selector kind or decoration")
|
return nil, errors.New("empty selector kind or decoration")
|
||||||
}
|
}
|
@ -15,9 +15,8 @@
|
|||||||
package label
|
package label
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/pkg/art"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -39,7 +38,7 @@ type selector struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Select candidates by the labels
|
// Select candidates by the labels
|
||||||
func (s *selector) Select(artifacts []*art.Candidate) (selected []*art.Candidate, err error) {
|
func (s *selector) Select(artifacts []*artifactselector.Candidate) (selected []*artifactselector.Candidate, err error) {
|
||||||
for _, art := range artifacts {
|
for _, art := range artifacts {
|
||||||
if isMatched(s.labels, art.Labels, s.decoration) {
|
if isMatched(s.labels, art.Labels, s.decoration) {
|
||||||
selected = append(selected, art)
|
selected = append(selected, art)
|
||||||
@ -50,7 +49,7 @@ func (s *selector) Select(artifacts []*art.Candidate) (selected []*art.Candidate
|
|||||||
}
|
}
|
||||||
|
|
||||||
// New is factory method for list selector
|
// New is factory method for list selector
|
||||||
func New(decoration string, pattern string) art.Selector {
|
func New(decoration string, pattern string) artifactselector.Selector {
|
||||||
labels := make([]string, 0)
|
labels := make([]string, 0)
|
||||||
if len(pattern) > 0 {
|
if len(pattern) > 0 {
|
||||||
labels = append(labels, strings.Split(pattern, ",")...)
|
labels = append(labels, strings.Split(pattern, ",")...)
|
@ -16,7 +16,7 @@ package label
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/goharbor/harbor/src/pkg/art"
|
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
@ -28,7 +28,7 @@ import (
|
|||||||
type LabelSelectorTestSuite struct {
|
type LabelSelectorTestSuite struct {
|
||||||
suite.Suite
|
suite.Suite
|
||||||
|
|
||||||
artifacts []*art.Candidate
|
artifacts []*artifactselector.Candidate
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestLabelSelector is entrance for LabelSelectorTestSuite
|
// TestLabelSelector is entrance for LabelSelectorTestSuite
|
||||||
@ -38,13 +38,13 @@ func TestLabelSelector(t *testing.T) {
|
|||||||
|
|
||||||
// SetupSuite to do preparation work
|
// SetupSuite to do preparation work
|
||||||
func (suite *LabelSelectorTestSuite) SetupSuite() {
|
func (suite *LabelSelectorTestSuite) SetupSuite() {
|
||||||
suite.artifacts = []*art.Candidate{
|
suite.artifacts = []*artifactselector.Candidate{
|
||||||
{
|
{
|
||||||
NamespaceID: 1,
|
NamespaceID: 1,
|
||||||
Namespace: "library",
|
Namespace: "library",
|
||||||
Repository: "harbor",
|
Repository: "harbor",
|
||||||
Tags: []string{"1.9"},
|
Tags: []string{"1.9"},
|
||||||
Kind: art.Image,
|
Kind: artifactselector.Image,
|
||||||
PushedTime: time.Now().Unix() - 3600,
|
PushedTime: time.Now().Unix() - 3600,
|
||||||
PulledTime: time.Now().Unix(),
|
PulledTime: time.Now().Unix(),
|
||||||
CreationTime: time.Now().Unix() - 7200,
|
CreationTime: time.Now().Unix() - 7200,
|
||||||
@ -55,7 +55,7 @@ func (suite *LabelSelectorTestSuite) SetupSuite() {
|
|||||||
Namespace: "library",
|
Namespace: "library",
|
||||||
Repository: "harbor",
|
Repository: "harbor",
|
||||||
Tags: []string{"dev"},
|
Tags: []string{"dev"},
|
||||||
Kind: art.Image,
|
Kind: artifactselector.Image,
|
||||||
PushedTime: time.Now().Unix() - 3600,
|
PushedTime: time.Now().Unix() - 3600,
|
||||||
PulledTime: time.Now().Unix(),
|
PulledTime: time.Now().Unix(),
|
||||||
CreationTime: time.Now().Unix() - 7200,
|
CreationTime: time.Now().Unix() - 7200,
|
||||||
@ -131,7 +131,7 @@ func (suite *LabelSelectorTestSuite) TestWithoutNoneExistingLabels() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check whether the returned result matched the expected ones (only check repo:tag)
|
// Check whether the returned result matched the expected ones (only check repo:tag)
|
||||||
func expect(expected []string, candidates []*art.Candidate) bool {
|
func expect(expected []string, candidates []*artifactselector.Candidate) bool {
|
||||||
hash := make(map[string]bool)
|
hash := make(map[string]bool)
|
||||||
|
|
||||||
for _, art := range candidates {
|
for _, art := range candidates {
|
@ -1,11 +1,11 @@
|
|||||||
package match
|
package match
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/goharbor/harbor/src/pkg/art"
|
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ImmutableTagMatcher ...
|
// ImmutableTagMatcher ...
|
||||||
type ImmutableTagMatcher interface {
|
type ImmutableTagMatcher interface {
|
||||||
// Match whether the candidate is in the immutable list
|
// Match whether the candidate is in the immutable list
|
||||||
Match(pid int64, c art.Candidate) (bool, error)
|
Match(pid int64, c artifactselector.Candidate) (bool, error)
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package rule
|
package rule
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/goharbor/harbor/src/pkg/art"
|
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
||||||
"github.com/goharbor/harbor/src/pkg/art/selectors/index"
|
"github.com/goharbor/harbor/src/pkg/artifactselector/selectors/index"
|
||||||
"github.com/goharbor/harbor/src/pkg/immutabletag"
|
"github.com/goharbor/harbor/src/pkg/immutabletag"
|
||||||
"github.com/goharbor/harbor/src/pkg/immutabletag/match"
|
"github.com/goharbor/harbor/src/pkg/immutabletag/match"
|
||||||
"github.com/goharbor/harbor/src/pkg/immutabletag/model"
|
"github.com/goharbor/harbor/src/pkg/immutabletag/model"
|
||||||
@ -14,19 +14,19 @@ type Matcher struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Match ...
|
// Match ...
|
||||||
func (rm *Matcher) Match(pid int64, c art.Candidate) (bool, error) {
|
func (rm *Matcher) Match(pid int64, c artifactselector.Candidate) (bool, error) {
|
||||||
if err := rm.getImmutableRules(pid); err != nil {
|
if err := rm.getImmutableRules(pid); err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
cands := []*art.Candidate{&c}
|
cands := []*artifactselector.Candidate{&c}
|
||||||
for _, r := range rm.rules {
|
for _, r := range rm.rules {
|
||||||
if r.Disabled {
|
if r.Disabled {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// match repositories according to the repository selectors
|
// match repositories according to the repository selectors
|
||||||
var repositoryCandidates []*art.Candidate
|
var repositoryCandidates []*artifactselector.Candidate
|
||||||
repositorySelectors := r.ScopeSelectors["repository"]
|
repositorySelectors := r.ScopeSelectors["repository"]
|
||||||
if len(repositorySelectors) < 1 {
|
if len(repositorySelectors) < 1 {
|
||||||
continue
|
continue
|
||||||
@ -46,7 +46,7 @@ func (rm *Matcher) Match(pid int64, c art.Candidate) (bool, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// match tag according to the tag selectors
|
// match tag according to the tag selectors
|
||||||
var tagCandidates []*art.Candidate
|
var tagCandidates []*artifactselector.Candidate
|
||||||
tagSelectors := r.TagSelectors
|
tagSelectors := r.TagSelectors
|
||||||
if len(tagSelectors) < 0 {
|
if len(tagSelectors) < 0 {
|
||||||
continue
|
continue
|
||||||
|
@ -2,7 +2,7 @@ package rule
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/goharbor/harbor/src/common/dao"
|
"github.com/goharbor/harbor/src/common/dao"
|
||||||
"github.com/goharbor/harbor/src/pkg/art"
|
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
||||||
"github.com/goharbor/harbor/src/pkg/immutabletag"
|
"github.com/goharbor/harbor/src/pkg/immutabletag"
|
||||||
"github.com/goharbor/harbor/src/pkg/immutabletag/model"
|
"github.com/goharbor/harbor/src/pkg/immutabletag/model"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
@ -87,7 +87,7 @@ func (s *MatchTestSuite) TestImmuMatch() {
|
|||||||
|
|
||||||
match := NewRuleMatcher()
|
match := NewRuleMatcher()
|
||||||
|
|
||||||
c1 := art.Candidate{
|
c1 := artifactselector.Candidate{
|
||||||
NamespaceID: 1,
|
NamespaceID: 1,
|
||||||
Namespace: "library",
|
Namespace: "library",
|
||||||
Repository: "redis",
|
Repository: "redis",
|
||||||
@ -97,34 +97,34 @@ func (s *MatchTestSuite) TestImmuMatch() {
|
|||||||
s.require.Equal(isMatch, true)
|
s.require.Equal(isMatch, true)
|
||||||
s.require.Nil(err)
|
s.require.Nil(err)
|
||||||
|
|
||||||
c2 := art.Candidate{
|
c2 := artifactselector.Candidate{
|
||||||
NamespaceID: 1,
|
NamespaceID: 1,
|
||||||
Namespace: "library",
|
Namespace: "library",
|
||||||
Repository: "redis",
|
Repository: "redis",
|
||||||
Tags: []string{"1.10"},
|
Tags: []string{"1.10"},
|
||||||
Kind: art.Image,
|
Kind: artifactselector.Image,
|
||||||
}
|
}
|
||||||
isMatch, err = match.Match(1, c2)
|
isMatch, err = match.Match(1, c2)
|
||||||
s.require.Equal(isMatch, false)
|
s.require.Equal(isMatch, false)
|
||||||
s.require.Nil(err)
|
s.require.Nil(err)
|
||||||
|
|
||||||
c3 := art.Candidate{
|
c3 := artifactselector.Candidate{
|
||||||
NamespaceID: 1,
|
NamespaceID: 1,
|
||||||
Namespace: "immutable",
|
Namespace: "immutable",
|
||||||
Repository: "mysql",
|
Repository: "mysql",
|
||||||
Tags: []string{"9.4.8"},
|
Tags: []string{"9.4.8"},
|
||||||
Kind: art.Image,
|
Kind: artifactselector.Image,
|
||||||
}
|
}
|
||||||
isMatch, err = match.Match(1, c3)
|
isMatch, err = match.Match(1, c3)
|
||||||
s.require.Equal(isMatch, true)
|
s.require.Equal(isMatch, true)
|
||||||
s.require.Nil(err)
|
s.require.Nil(err)
|
||||||
|
|
||||||
c4 := art.Candidate{
|
c4 := artifactselector.Candidate{
|
||||||
NamespaceID: 1,
|
NamespaceID: 1,
|
||||||
Namespace: "immutable",
|
Namespace: "immutable",
|
||||||
Repository: "hello",
|
Repository: "hello",
|
||||||
Tags: []string{"world"},
|
Tags: []string{"world"},
|
||||||
Kind: art.Image,
|
Kind: artifactselector.Image,
|
||||||
}
|
}
|
||||||
isMatch, err = match.Match(1, c4)
|
isMatch, err = match.Match(1, c4)
|
||||||
s.require.Equal(isMatch, false)
|
s.require.Equal(isMatch, false)
|
||||||
|
@ -17,12 +17,12 @@ package dep
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/common/http/modifier/auth"
|
"github.com/goharbor/harbor/src/common/http/modifier/auth"
|
||||||
"github.com/goharbor/harbor/src/jobservice/config"
|
"github.com/goharbor/harbor/src/jobservice/config"
|
||||||
"github.com/goharbor/harbor/src/pkg/art"
|
|
||||||
"github.com/goharbor/harbor/src/pkg/clients/core"
|
"github.com/goharbor/harbor/src/pkg/clients/core"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ type Client interface {
|
|||||||
// Returns:
|
// Returns:
|
||||||
// []*art.Candidate : candidates returned
|
// []*art.Candidate : candidates returned
|
||||||
// error : common error if any errors occurred
|
// error : common error if any errors occurred
|
||||||
GetCandidates(repo *art.Repository) ([]*art.Candidate, error)
|
GetCandidates(repo *artifactselector.Repository) ([]*artifactselector.Candidate, error)
|
||||||
|
|
||||||
// Delete the given repository
|
// Delete the given repository
|
||||||
//
|
//
|
||||||
@ -48,7 +48,7 @@ type Client interface {
|
|||||||
//
|
//
|
||||||
// Returns:
|
// Returns:
|
||||||
// error : common error if any errors occurred
|
// error : common error if any errors occurred
|
||||||
DeleteRepository(repo *art.Repository) error
|
DeleteRepository(repo *artifactselector.Repository) error
|
||||||
|
|
||||||
// Delete the specified candidate
|
// Delete the specified candidate
|
||||||
//
|
//
|
||||||
@ -57,7 +57,7 @@ type Client interface {
|
|||||||
//
|
//
|
||||||
// Returns:
|
// Returns:
|
||||||
// error : common error if any errors occurred
|
// error : common error if any errors occurred
|
||||||
Delete(candidate *art.Candidate) error
|
Delete(candidate *artifactselector.Candidate) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewClient new a basic client
|
// NewClient new a basic client
|
||||||
@ -89,29 +89,29 @@ type basicClient struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetCandidates gets the tag candidates under the repository
|
// GetCandidates gets the tag candidates under the repository
|
||||||
func (bc *basicClient) GetCandidates(repository *art.Repository) ([]*art.Candidate, error) {
|
func (bc *basicClient) GetCandidates(repository *artifactselector.Repository) ([]*artifactselector.Candidate, error) {
|
||||||
if repository == nil {
|
if repository == nil {
|
||||||
return nil, errors.New("repository is nil")
|
return nil, errors.New("repository is nil")
|
||||||
}
|
}
|
||||||
candidates := make([]*art.Candidate, 0)
|
candidates := make([]*artifactselector.Candidate, 0)
|
||||||
switch repository.Kind {
|
switch repository.Kind {
|
||||||
case art.Image:
|
case artifactselector.Image:
|
||||||
artifacts, err := bc.coreClient.ListAllArtifacts(repository.Namespace, repository.Name)
|
artifacts, err := bc.coreClient.ListAllArtifacts(repository.Namespace, repository.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
for _, artifact := range artifacts {
|
for _, art := range artifacts {
|
||||||
if artifact.Digest == "" {
|
if art.Digest == "" {
|
||||||
return nil, fmt.Errorf("Lack Digest of Candidate for %s/%s", repository.Namespace, repository.Name)
|
return nil, fmt.Errorf("Lack Digest of Candidate for %s/%s", repository.Namespace, repository.Name)
|
||||||
}
|
}
|
||||||
labels := make([]string, 0)
|
labels := make([]string, 0)
|
||||||
for _, label := range artifact.Labels {
|
for _, label := range art.Labels {
|
||||||
labels = append(labels, label.Name)
|
labels = append(labels, label.Name)
|
||||||
}
|
}
|
||||||
tags := make([]string, 0)
|
tags := make([]string, 0)
|
||||||
var lastPulledTime time.Time
|
var lastPulledTime time.Time
|
||||||
var lastPushedTime time.Time
|
var lastPushedTime time.Time
|
||||||
for _, t := range artifact.Tags {
|
for _, t := range art.Tags {
|
||||||
tags = append(tags, t.Name)
|
tags = append(tags, t.Name)
|
||||||
if t.PullTime.After(lastPulledTime) {
|
if t.PullTime.After(lastPulledTime) {
|
||||||
lastPulledTime = t.PullTime
|
lastPulledTime = t.PullTime
|
||||||
@ -120,15 +120,15 @@ func (bc *basicClient) GetCandidates(repository *art.Repository) ([]*art.Candida
|
|||||||
lastPushedTime = t.PushTime
|
lastPushedTime = t.PushTime
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
candidate := &art.Candidate{
|
candidate := &artifactselector.Candidate{
|
||||||
Kind: art.Image,
|
Kind: artifactselector.Image,
|
||||||
NamespaceID: repository.NamespaceID,
|
NamespaceID: repository.NamespaceID,
|
||||||
Namespace: repository.Namespace,
|
Namespace: repository.Namespace,
|
||||||
Repository: repository.Name,
|
Repository: repository.Name,
|
||||||
Tags: tags,
|
Tags: tags,
|
||||||
Digest: artifact.Digest,
|
Digest: art.Digest,
|
||||||
Labels: labels,
|
Labels: labels,
|
||||||
CreationTime: artifact.PushTime.Unix(),
|
CreationTime: art.PushTime.Unix(),
|
||||||
PulledTime: lastPulledTime.Unix(),
|
PulledTime: lastPulledTime.Unix(),
|
||||||
PushedTime: lastPushedTime.Unix(),
|
PushedTime: lastPushedTime.Unix(),
|
||||||
}
|
}
|
||||||
@ -165,12 +165,12 @@ func (bc *basicClient) GetCandidates(repository *art.Repository) ([]*art.Candida
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DeleteRepository deletes the specified repository
|
// DeleteRepository deletes the specified repository
|
||||||
func (bc *basicClient) DeleteRepository(repo *art.Repository) error {
|
func (bc *basicClient) DeleteRepository(repo *artifactselector.Repository) error {
|
||||||
if repo == nil {
|
if repo == nil {
|
||||||
return errors.New("repository is nil")
|
return errors.New("repository is nil")
|
||||||
}
|
}
|
||||||
switch repo.Kind {
|
switch repo.Kind {
|
||||||
case art.Image:
|
case artifactselector.Image:
|
||||||
return bc.coreClient.DeleteArtifactRepository(repo.Namespace, repo.Name)
|
return bc.coreClient.DeleteArtifactRepository(repo.Namespace, repo.Name)
|
||||||
/*
|
/*
|
||||||
case art.Chart:
|
case art.Chart:
|
||||||
@ -182,12 +182,12 @@ func (bc *basicClient) DeleteRepository(repo *art.Repository) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Deletes the specified candidate
|
// Deletes the specified candidate
|
||||||
func (bc *basicClient) Delete(candidate *art.Candidate) error {
|
func (bc *basicClient) Delete(candidate *artifactselector.Candidate) error {
|
||||||
if candidate == nil {
|
if candidate == nil {
|
||||||
return errors.New("candidate is nil")
|
return errors.New("candidate is nil")
|
||||||
}
|
}
|
||||||
switch candidate.Kind {
|
switch candidate.Kind {
|
||||||
case art.Image:
|
case artifactselector.Image:
|
||||||
return bc.coreClient.DeleteArtifact(candidate.Namespace, candidate.Repository, candidate.Digest)
|
return bc.coreClient.DeleteArtifact(candidate.Namespace, candidate.Repository, candidate.Digest)
|
||||||
/*
|
/*
|
||||||
case art.Chart:
|
case art.Chart:
|
||||||
|
@ -17,13 +17,13 @@ package dep
|
|||||||
import (
|
import (
|
||||||
modelsv2 "github.com/goharbor/harbor/src/api/artifact"
|
modelsv2 "github.com/goharbor/harbor/src/api/artifact"
|
||||||
"github.com/goharbor/harbor/src/api/tag"
|
"github.com/goharbor/harbor/src/api/tag"
|
||||||
|
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
||||||
model_tag "github.com/goharbor/harbor/src/pkg/tag/model/tag"
|
model_tag "github.com/goharbor/harbor/src/pkg/tag/model/tag"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/chartserver"
|
"github.com/goharbor/harbor/src/chartserver"
|
||||||
jmodels "github.com/goharbor/harbor/src/common/job/models"
|
jmodels "github.com/goharbor/harbor/src/common/job/models"
|
||||||
"github.com/goharbor/harbor/src/jobservice/job"
|
"github.com/goharbor/harbor/src/jobservice/job"
|
||||||
"github.com/goharbor/harbor/src/pkg/art"
|
|
||||||
"github.com/goharbor/harbor/src/testing/clients"
|
"github.com/goharbor/harbor/src/testing/clients"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
@ -82,20 +82,20 @@ type clientTestSuite struct {
|
|||||||
func (c *clientTestSuite) TestGetCandidates() {
|
func (c *clientTestSuite) TestGetCandidates() {
|
||||||
client := &basicClient{}
|
client := &basicClient{}
|
||||||
client.coreClient = &fakeCoreClient{}
|
client.coreClient = &fakeCoreClient{}
|
||||||
var repository *art.Repository
|
var repository *artifactselector.Repository
|
||||||
// nil repository
|
// nil repository
|
||||||
candidates, err := client.GetCandidates(repository)
|
candidates, err := client.GetCandidates(repository)
|
||||||
require.NotNil(c.T(), err)
|
require.NotNil(c.T(), err)
|
||||||
|
|
||||||
// image repository
|
// image repository
|
||||||
repository = &art.Repository{}
|
repository = &artifactselector.Repository{}
|
||||||
repository.Kind = art.Image
|
repository.Kind = artifactselector.Image
|
||||||
repository.Namespace = "library"
|
repository.Namespace = "library"
|
||||||
repository.Name = "hello-world"
|
repository.Name = "hello-world"
|
||||||
candidates, err = client.GetCandidates(repository)
|
candidates, err = client.GetCandidates(repository)
|
||||||
require.Nil(c.T(), err)
|
require.Nil(c.T(), err)
|
||||||
assert.Equal(c.T(), 1, len(candidates))
|
assert.Equal(c.T(), 1, len(candidates))
|
||||||
assert.Equal(c.T(), art.Image, candidates[0].Kind)
|
assert.Equal(c.T(), artifactselector.Image, candidates[0].Kind)
|
||||||
assert.Equal(c.T(), "library", candidates[0].Namespace)
|
assert.Equal(c.T(), "library", candidates[0].Namespace)
|
||||||
assert.Equal(c.T(), "hello-world", candidates[0].Repository)
|
assert.Equal(c.T(), "hello-world", candidates[0].Repository)
|
||||||
assert.Equal(c.T(), "latest", candidates[0].Tags[0])
|
assert.Equal(c.T(), "latest", candidates[0].Tags[0])
|
||||||
@ -118,14 +118,14 @@ func (c *clientTestSuite) TestDelete() {
|
|||||||
client := &basicClient{}
|
client := &basicClient{}
|
||||||
client.coreClient = &fakeCoreClient{}
|
client.coreClient = &fakeCoreClient{}
|
||||||
|
|
||||||
var candidate *art.Candidate
|
var candidate *artifactselector.Candidate
|
||||||
// nil candidate
|
// nil candidate
|
||||||
err := client.Delete(candidate)
|
err := client.Delete(candidate)
|
||||||
require.NotNil(c.T(), err)
|
require.NotNil(c.T(), err)
|
||||||
|
|
||||||
// image
|
// image
|
||||||
candidate = &art.Candidate{}
|
candidate = &artifactselector.Candidate{}
|
||||||
candidate.Kind = art.Image
|
candidate.Kind = artifactselector.Image
|
||||||
err = client.Delete(candidate)
|
err = client.Delete(candidate)
|
||||||
require.Nil(c.T(), err)
|
require.Nil(c.T(), err)
|
||||||
|
|
||||||
|
@ -18,12 +18,12 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/jobservice/job"
|
"github.com/goharbor/harbor/src/jobservice/job"
|
||||||
"github.com/goharbor/harbor/src/jobservice/logger"
|
"github.com/goharbor/harbor/src/jobservice/logger"
|
||||||
"github.com/goharbor/harbor/src/pkg/art"
|
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/dep"
|
"github.com/goharbor/harbor/src/pkg/retention/dep"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy"
|
"github.com/goharbor/harbor/src/pkg/retention/policy"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/lwp"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/lwp"
|
||||||
@ -117,7 +117,7 @@ func (pj *Job) Run(ctx job.Context, params job.Parameters) error {
|
|||||||
return saveRetainNum(ctx, results, allCandidates)
|
return saveRetainNum(ctx, results, allCandidates)
|
||||||
}
|
}
|
||||||
|
|
||||||
func saveRetainNum(ctx job.Context, results []*art.Result, allCandidates []*art.Candidate) error {
|
func saveRetainNum(ctx job.Context, results []*artifactselector.Result, allCandidates []*artifactselector.Candidate) error {
|
||||||
var delNum int
|
var delNum int
|
||||||
for _, r := range results {
|
for _, r := range results {
|
||||||
if r.Error == nil {
|
if r.Error == nil {
|
||||||
@ -139,7 +139,7 @@ func saveRetainNum(ctx job.Context, results []*art.Result, allCandidates []*art.
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func logResults(logger logger.Interface, all []*art.Candidate, results []*art.Result) {
|
func logResults(logger logger.Interface, all []*artifactselector.Candidate, results []*artifactselector.Result) {
|
||||||
hash := make(map[string]error, len(results))
|
hash := make(map[string]error, len(results))
|
||||||
for _, r := range results {
|
for _, r := range results {
|
||||||
if r.Target != nil {
|
if r.Target != nil {
|
||||||
@ -147,10 +147,10 @@ func logResults(logger logger.Interface, all []*art.Candidate, results []*art.Re
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
op := func(c *art.Candidate) string {
|
op := func(c *artifactselector.Candidate) string {
|
||||||
if e, exists := hash[c.Hash()]; exists {
|
if e, exists := hash[c.Hash()]; exists {
|
||||||
if e != nil {
|
if e != nil {
|
||||||
if _, ok := e.(*art.ImmutableError); ok {
|
if _, ok := e.(*artifactselector.ImmutableError); ok {
|
||||||
return actionMarkImmutable
|
return actionMarkImmutable
|
||||||
}
|
}
|
||||||
return actionMarkError
|
return actionMarkError
|
||||||
@ -198,7 +198,7 @@ func logResults(logger logger.Interface, all []*art.Candidate, results []*art.Re
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func arn(art *art.Candidate) string {
|
func arn(art *artifactselector.Candidate) string {
|
||||||
return fmt.Sprintf("%s/%s:%s", art.Namespace, art.Repository, art.Digest)
|
return fmt.Sprintf("%s/%s:%s", art.Namespace, art.Repository, art.Digest)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -241,7 +241,7 @@ func getParamDryRun(params job.Parameters) (bool, error) {
|
|||||||
return dryRun, nil
|
return dryRun, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getParamRepo(params job.Parameters) (*art.Repository, error) {
|
func getParamRepo(params job.Parameters) (*artifactselector.Repository, error) {
|
||||||
v, ok := params[ParamRepo]
|
v, ok := params[ParamRepo]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, errors.Errorf("missing parameter: %s", ParamRepo)
|
return nil, errors.Errorf("missing parameter: %s", ParamRepo)
|
||||||
@ -252,7 +252,7 @@ func getParamRepo(params job.Parameters) (*art.Repository, error) {
|
|||||||
return nil, errors.Errorf("invalid parameter: %s", ParamRepo)
|
return nil, errors.Errorf("invalid parameter: %s", ParamRepo)
|
||||||
}
|
}
|
||||||
|
|
||||||
repo := &art.Repository{}
|
repo := &artifactselector.Repository{}
|
||||||
if err := repo.FromJSON(repoJSON); err != nil {
|
if err := repo.FromJSON(repoJSON); err != nil {
|
||||||
return nil, errors.Wrap(err, "parse repository from JSON")
|
return nil, errors.Wrap(err, "parse repository from JSON")
|
||||||
}
|
}
|
||||||
|
@ -17,13 +17,13 @@ package retention
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/jobservice/job"
|
"github.com/goharbor/harbor/src/jobservice/job"
|
||||||
"github.com/goharbor/harbor/src/jobservice/logger"
|
"github.com/goharbor/harbor/src/jobservice/logger"
|
||||||
"github.com/goharbor/harbor/src/pkg/art"
|
"github.com/goharbor/harbor/src/pkg/artifactselector/selectors/doublestar"
|
||||||
"github.com/goharbor/harbor/src/pkg/art/selectors/doublestar"
|
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/dep"
|
"github.com/goharbor/harbor/src/pkg/retention/dep"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy"
|
"github.com/goharbor/harbor/src/pkg/retention/policy"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/action"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/action"
|
||||||
@ -60,10 +60,10 @@ func (suite *JobTestSuite) TearDownSuite() {
|
|||||||
func (suite *JobTestSuite) TestRunSuccess() {
|
func (suite *JobTestSuite) TestRunSuccess() {
|
||||||
params := make(job.Parameters)
|
params := make(job.Parameters)
|
||||||
params[ParamDryRun] = false
|
params[ParamDryRun] = false
|
||||||
repository := &art.Repository{
|
repository := &artifactselector.Repository{
|
||||||
Namespace: "library",
|
Namespace: "library",
|
||||||
Name: "harbor",
|
Name: "harbor",
|
||||||
Kind: art.Image,
|
Kind: artifactselector.Image,
|
||||||
}
|
}
|
||||||
repoJSON, err := repository.ToJSON()
|
repoJSON, err := repository.ToJSON()
|
||||||
require.Nil(suite.T(), err)
|
require.Nil(suite.T(), err)
|
||||||
@ -112,8 +112,8 @@ func (suite *JobTestSuite) TestRunSuccess() {
|
|||||||
type fakeRetentionClient struct{}
|
type fakeRetentionClient struct{}
|
||||||
|
|
||||||
// GetCandidates ...
|
// GetCandidates ...
|
||||||
func (frc *fakeRetentionClient) GetCandidates(repo *art.Repository) ([]*art.Candidate, error) {
|
func (frc *fakeRetentionClient) GetCandidates(repo *artifactselector.Repository) ([]*artifactselector.Candidate, error) {
|
||||||
return []*art.Candidate{
|
return []*artifactselector.Candidate{
|
||||||
{
|
{
|
||||||
Namespace: "library",
|
Namespace: "library",
|
||||||
Repository: "harbor",
|
Repository: "harbor",
|
||||||
@ -140,12 +140,12 @@ func (frc *fakeRetentionClient) GetCandidates(repo *art.Repository) ([]*art.Cand
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Delete ...
|
// Delete ...
|
||||||
func (frc *fakeRetentionClient) Delete(candidate *art.Candidate) error {
|
func (frc *fakeRetentionClient) Delete(candidate *artifactselector.Candidate) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SubmitTask ...
|
// SubmitTask ...
|
||||||
func (frc *fakeRetentionClient) DeleteRepository(repo *art.Repository) error {
|
func (frc *fakeRetentionClient) DeleteRepository(repo *artifactselector.Repository) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,10 +18,11 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
beegoorm "github.com/astaxie/beego/orm"
|
beegoorm "github.com/astaxie/beego/orm"
|
||||||
"github.com/goharbor/harbor/src/internal/orm"
|
"github.com/goharbor/harbor/src/internal/orm"
|
||||||
|
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/jobservice/job"
|
"github.com/goharbor/harbor/src/jobservice/job"
|
||||||
"github.com/goharbor/harbor/src/pkg/art/selectors/index"
|
"github.com/goharbor/harbor/src/pkg/artifactselector/selectors/index"
|
||||||
|
|
||||||
cjob "github.com/goharbor/harbor/src/common/job"
|
cjob "github.com/goharbor/harbor/src/common/job"
|
||||||
"github.com/goharbor/harbor/src/common/job/models"
|
"github.com/goharbor/harbor/src/common/job/models"
|
||||||
@ -29,7 +30,6 @@ import (
|
|||||||
"github.com/goharbor/harbor/src/common/utils"
|
"github.com/goharbor/harbor/src/common/utils"
|
||||||
"github.com/goharbor/harbor/src/common/utils/log"
|
"github.com/goharbor/harbor/src/common/utils/log"
|
||||||
"github.com/goharbor/harbor/src/core/config"
|
"github.com/goharbor/harbor/src/core/config"
|
||||||
"github.com/goharbor/harbor/src/pkg/art"
|
|
||||||
"github.com/goharbor/harbor/src/pkg/project"
|
"github.com/goharbor/harbor/src/pkg/project"
|
||||||
pq "github.com/goharbor/harbor/src/pkg/q"
|
pq "github.com/goharbor/harbor/src/pkg/q"
|
||||||
"github.com/goharbor/harbor/src/pkg/repository"
|
"github.com/goharbor/harbor/src/pkg/repository"
|
||||||
@ -87,7 +87,7 @@ func NewLauncher(projectMgr project.Manager, repositoryMgr repository.Manager,
|
|||||||
|
|
||||||
type jobData struct {
|
type jobData struct {
|
||||||
TaskID int64
|
TaskID int64
|
||||||
Repository art.Repository
|
Repository artifactselector.Repository
|
||||||
JobName string
|
JobName string
|
||||||
JobParams map[string]interface{}
|
JobParams map[string]interface{}
|
||||||
}
|
}
|
||||||
@ -114,9 +114,9 @@ func (l *launcher) Launch(ply *policy.Metadata, executionID int64, isDryRun bool
|
|||||||
if scope == nil {
|
if scope == nil {
|
||||||
return 0, launcherError(fmt.Errorf("the scope of policy is nil"))
|
return 0, launcherError(fmt.Errorf("the scope of policy is nil"))
|
||||||
}
|
}
|
||||||
repositoryRules := make(map[art.Repository]*lwp.Metadata, 0)
|
repositoryRules := make(map[artifactselector.Repository]*lwp.Metadata, 0)
|
||||||
level := scope.Level
|
level := scope.Level
|
||||||
var allProjects []*art.Candidate
|
var allProjects []*artifactselector.Candidate
|
||||||
var err error
|
var err error
|
||||||
if level == "system" {
|
if level == "system" {
|
||||||
// get projects
|
// get projects
|
||||||
@ -147,12 +147,12 @@ func (l *launcher) Launch(ply *policy.Metadata, executionID int64, isDryRun bool
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
case "project":
|
case "project":
|
||||||
projectCandidates = append(projectCandidates, &art.Candidate{
|
projectCandidates = append(projectCandidates, &artifactselector.Candidate{
|
||||||
NamespaceID: scope.Reference,
|
NamespaceID: scope.Reference,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
var repositoryCandidates []*art.Candidate
|
var repositoryCandidates []*artifactselector.Candidate
|
||||||
// get repositories of projects
|
// get repositories of projects
|
||||||
for _, projectCandidate := range projectCandidates {
|
for _, projectCandidate := range projectCandidates {
|
||||||
repositories, err := getRepositories(l.projectMgr, l.repositoryMgr, projectCandidate.NamespaceID, l.chartServerEnabled)
|
repositories, err := getRepositories(l.projectMgr, l.repositoryMgr, projectCandidate.NamespaceID, l.chartServerEnabled)
|
||||||
@ -177,7 +177,7 @@ func (l *launcher) Launch(ply *policy.Metadata, executionID int64, isDryRun bool
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, repositoryCandidate := range repositoryCandidates {
|
for _, repositoryCandidate := range repositoryCandidates {
|
||||||
reposit := art.Repository{
|
reposit := artifactselector.Repository{
|
||||||
NamespaceID: repositoryCandidate.NamespaceID,
|
NamespaceID: repositoryCandidate.NamespaceID,
|
||||||
Namespace: repositoryCandidate.Namespace,
|
Namespace: repositoryCandidate.Namespace,
|
||||||
Name: repositoryCandidate.Repository,
|
Name: repositoryCandidate.Repository,
|
||||||
@ -218,7 +218,7 @@ func (l *launcher) Launch(ply *policy.Metadata, executionID int64, isDryRun bool
|
|||||||
return int64(len(jobDatas)), nil
|
return int64(len(jobDatas)), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func createJobs(repositoryRules map[art.Repository]*lwp.Metadata, isDryRun bool) ([]*jobData, error) {
|
func createJobs(repositoryRules map[artifactselector.Repository]*lwp.Metadata, isDryRun bool) ([]*jobData, error) {
|
||||||
jobDatas := []*jobData{}
|
jobDatas := []*jobData{}
|
||||||
for repository, policy := range repositoryRules {
|
for repository, policy := range repositoryRules {
|
||||||
jobData := &jobData{
|
jobData := &jobData{
|
||||||
@ -324,14 +324,14 @@ func launcherError(err error) error {
|
|||||||
return errors.Wrap(err, "launcher")
|
return errors.Wrap(err, "launcher")
|
||||||
}
|
}
|
||||||
|
|
||||||
func getProjects(projectMgr project.Manager) ([]*art.Candidate, error) {
|
func getProjects(projectMgr project.Manager) ([]*artifactselector.Candidate, error) {
|
||||||
projects, err := projectMgr.List()
|
projects, err := projectMgr.List()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var candidates []*art.Candidate
|
var candidates []*artifactselector.Candidate
|
||||||
for _, pro := range projects {
|
for _, pro := range projects {
|
||||||
candidates = append(candidates, &art.Candidate{
|
candidates = append(candidates, &artifactselector.Candidate{
|
||||||
NamespaceID: pro.ProjectID,
|
NamespaceID: pro.ProjectID,
|
||||||
Namespace: pro.Name,
|
Namespace: pro.Name,
|
||||||
})
|
})
|
||||||
@ -340,8 +340,8 @@ func getProjects(projectMgr project.Manager) ([]*art.Candidate, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getRepositories(projectMgr project.Manager, repositoryMgr repository.Manager,
|
func getRepositories(projectMgr project.Manager, repositoryMgr repository.Manager,
|
||||||
projectID int64, chartServerEnabled bool) ([]*art.Candidate, error) {
|
projectID int64, chartServerEnabled bool) ([]*artifactselector.Candidate, error) {
|
||||||
var candidates []*art.Candidate
|
var candidates []*artifactselector.Candidate
|
||||||
/*
|
/*
|
||||||
pro, err := projectMgr.Get(projectID)
|
pro, err := projectMgr.Get(projectID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -360,7 +360,7 @@ func getRepositories(projectMgr project.Manager, repositoryMgr repository.Manage
|
|||||||
}
|
}
|
||||||
for _, r := range imageRepositories {
|
for _, r := range imageRepositories {
|
||||||
namespace, repo := utils.ParseRepository(r.Name)
|
namespace, repo := utils.ParseRepository(r.Name)
|
||||||
candidates = append(candidates, &art.Candidate{
|
candidates = append(candidates, &artifactselector.Candidate{
|
||||||
NamespaceID: projectID,
|
NamespaceID: projectID,
|
||||||
Namespace: namespace,
|
Namespace: namespace,
|
||||||
Repository: repo,
|
Repository: repo,
|
||||||
|
@ -18,7 +18,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"github.com/goharbor/harbor/src/common/job"
|
"github.com/goharbor/harbor/src/common/job"
|
||||||
"github.com/goharbor/harbor/src/common/models"
|
"github.com/goharbor/harbor/src/common/models"
|
||||||
_ "github.com/goharbor/harbor/src/pkg/art/selectors/doublestar"
|
_ "github.com/goharbor/harbor/src/pkg/artifactselector/selectors/doublestar"
|
||||||
"github.com/goharbor/harbor/src/pkg/project"
|
"github.com/goharbor/harbor/src/pkg/project"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy"
|
"github.com/goharbor/harbor/src/pkg/retention/policy"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
||||||
|
@ -15,10 +15,10 @@
|
|||||||
package index
|
package index
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/pkg/art"
|
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/action"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/action"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
@ -29,7 +29,7 @@ import (
|
|||||||
type IndexTestSuite struct {
|
type IndexTestSuite struct {
|
||||||
suite.Suite
|
suite.Suite
|
||||||
|
|
||||||
candidates []*art.Candidate
|
candidates []*artifactselector.Candidate
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestIndexEntry is entry of IndexTestSuite
|
// TestIndexEntry is entry of IndexTestSuite
|
||||||
@ -41,7 +41,7 @@ func TestIndexEntry(t *testing.T) {
|
|||||||
func (suite *IndexTestSuite) SetupSuite() {
|
func (suite *IndexTestSuite) SetupSuite() {
|
||||||
Register("fakeAction", newFakePerformer)
|
Register("fakeAction", newFakePerformer)
|
||||||
|
|
||||||
suite.candidates = []*art.Candidate{{
|
suite.candidates = []*artifactselector.Candidate{{
|
||||||
Namespace: "library",
|
Namespace: "library",
|
||||||
Repository: "harbor",
|
Repository: "harbor",
|
||||||
Kind: "image",
|
Kind: "image",
|
||||||
@ -77,9 +77,9 @@ type fakePerformer struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Perform the artifacts
|
// Perform the artifacts
|
||||||
func (p *fakePerformer) Perform(candidates []*art.Candidate) (results []*art.Result, err error) {
|
func (p *fakePerformer) Perform(candidates []*artifactselector.Candidate) (results []*artifactselector.Result, err error) {
|
||||||
for _, c := range candidates {
|
for _, c := range candidates {
|
||||||
results = append(results, &art.Result{
|
results = append(results, &artifactselector.Result{
|
||||||
Target: c,
|
Target: c,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ package action
|
|||||||
import (
|
import (
|
||||||
"github.com/goharbor/harbor/src/common/utils"
|
"github.com/goharbor/harbor/src/common/utils"
|
||||||
"github.com/goharbor/harbor/src/common/utils/log"
|
"github.com/goharbor/harbor/src/common/utils/log"
|
||||||
"github.com/goharbor/harbor/src/pkg/art"
|
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
||||||
"github.com/goharbor/harbor/src/pkg/immutabletag/match/rule"
|
"github.com/goharbor/harbor/src/pkg/immutabletag/match/rule"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/dep"
|
"github.com/goharbor/harbor/src/pkg/retention/dep"
|
||||||
)
|
)
|
||||||
@ -37,7 +37,7 @@ type Performer interface {
|
|||||||
// Returns:
|
// Returns:
|
||||||
// []*art.Result : result infos
|
// []*art.Result : result infos
|
||||||
// error : common error if any errors occurred
|
// error : common error if any errors occurred
|
||||||
Perform(candidates []*art.Candidate) ([]*art.Result, error)
|
Perform(candidates []*artifactselector.Candidate) ([]*artifactselector.Result, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// PerformerFactory is factory method for creating Performer
|
// PerformerFactory is factory method for creating Performer
|
||||||
@ -45,13 +45,13 @@ type PerformerFactory func(params interface{}, isDryRun bool) Performer
|
|||||||
|
|
||||||
// retainAction make sure all the candidates will be retained and others will be cleared
|
// retainAction make sure all the candidates will be retained and others will be cleared
|
||||||
type retainAction struct {
|
type retainAction struct {
|
||||||
all []*art.Candidate
|
all []*artifactselector.Candidate
|
||||||
// Indicate if it is a dry run
|
// Indicate if it is a dry run
|
||||||
isDryRun bool
|
isDryRun bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Perform the action
|
// Perform the action
|
||||||
func (ra *retainAction) Perform(candidates []*art.Candidate) (results []*art.Result, err error) {
|
func (ra *retainAction) Perform(candidates []*artifactselector.Candidate) (results []*artifactselector.Result, err error) {
|
||||||
retainedShare := make(map[string]bool)
|
retainedShare := make(map[string]bool)
|
||||||
immutableShare := make(map[string]bool)
|
immutableShare := make(map[string]bool)
|
||||||
for _, c := range candidates {
|
for _, c := range candidates {
|
||||||
@ -71,11 +71,11 @@ func (ra *retainAction) Perform(candidates []*art.Candidate) (results []*art.Res
|
|||||||
if len(ra.all) > 0 {
|
if len(ra.all) > 0 {
|
||||||
for _, c := range ra.all {
|
for _, c := range ra.all {
|
||||||
if _, ok := retainedShare[c.Hash()]; !ok {
|
if _, ok := retainedShare[c.Hash()]; !ok {
|
||||||
result := &art.Result{
|
result := &artifactselector.Result{
|
||||||
Target: c,
|
Target: c,
|
||||||
}
|
}
|
||||||
if _, ok = immutableShare[c.Hash()]; ok {
|
if _, ok = immutableShare[c.Hash()]; ok {
|
||||||
result.Error = &art.ImmutableError{}
|
result.Error = &artifactselector.ImmutableError{}
|
||||||
} else {
|
} else {
|
||||||
if !ra.isDryRun {
|
if !ra.isDryRun {
|
||||||
if err := dep.DefaultClient.Delete(c); err != nil {
|
if err := dep.DefaultClient.Delete(c); err != nil {
|
||||||
@ -91,11 +91,11 @@ func (ra *retainAction) Perform(candidates []*art.Candidate) (results []*art.Res
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func isImmutable(c *art.Candidate) bool {
|
func isImmutable(c *artifactselector.Candidate) bool {
|
||||||
projectID := c.NamespaceID
|
projectID := c.NamespaceID
|
||||||
repo := c.Repository
|
repo := c.Repository
|
||||||
_, repoName := utils.ParseRepository(repo)
|
_, repoName := utils.ParseRepository(repo)
|
||||||
matched, err := rule.NewRuleMatcher().Match(projectID, art.Candidate{
|
matched, err := rule.NewRuleMatcher().Match(projectID, artifactselector.Candidate{
|
||||||
Repository: repoName,
|
Repository: repoName,
|
||||||
Tags: c.Tags,
|
Tags: c.Tags,
|
||||||
NamespaceID: projectID,
|
NamespaceID: projectID,
|
||||||
@ -110,7 +110,7 @@ func isImmutable(c *art.Candidate) bool {
|
|||||||
// NewRetainAction is factory method for RetainAction
|
// NewRetainAction is factory method for RetainAction
|
||||||
func NewRetainAction(params interface{}, isDryRun bool) Performer {
|
func NewRetainAction(params interface{}, isDryRun bool) Performer {
|
||||||
if params != nil {
|
if params != nil {
|
||||||
if all, ok := params.([]*art.Candidate); ok {
|
if all, ok := params.([]*artifactselector.Candidate); ok {
|
||||||
return &retainAction{
|
return &retainAction{
|
||||||
all: all,
|
all: all,
|
||||||
isDryRun: isDryRun,
|
isDryRun: isDryRun,
|
||||||
@ -119,7 +119,7 @@ func NewRetainAction(params interface{}, isDryRun bool) Performer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &retainAction{
|
return &retainAction{
|
||||||
all: make([]*art.Candidate, 0),
|
all: make([]*artifactselector.Candidate, 0),
|
||||||
isDryRun: isDryRun,
|
isDryRun: isDryRun,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,11 +16,11 @@ package action
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/goharbor/harbor/src/common/dao"
|
"github.com/goharbor/harbor/src/common/dao"
|
||||||
|
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
||||||
"github.com/goharbor/harbor/src/pkg/immutabletag"
|
"github.com/goharbor/harbor/src/pkg/immutabletag"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/pkg/art"
|
|
||||||
immumodel "github.com/goharbor/harbor/src/pkg/immutabletag/model"
|
immumodel "github.com/goharbor/harbor/src/pkg/immutabletag/model"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/dep"
|
"github.com/goharbor/harbor/src/pkg/retention/dep"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
@ -34,7 +34,7 @@ type TestPerformerSuite struct {
|
|||||||
suite.Suite
|
suite.Suite
|
||||||
|
|
||||||
oldClient dep.Client
|
oldClient dep.Client
|
||||||
all []*art.Candidate
|
all []*artifactselector.Candidate
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestPerformer is the entry of the TestPerformerSuite
|
// TestPerformer is the entry of the TestPerformerSuite
|
||||||
@ -44,7 +44,7 @@ func TestPerformer(t *testing.T) {
|
|||||||
|
|
||||||
// SetupSuite ...
|
// SetupSuite ...
|
||||||
func (suite *TestPerformerSuite) SetupSuite() {
|
func (suite *TestPerformerSuite) SetupSuite() {
|
||||||
suite.all = []*art.Candidate{
|
suite.all = []*artifactselector.Candidate{
|
||||||
{
|
{
|
||||||
Namespace: "library",
|
Namespace: "library",
|
||||||
Repository: "harbor",
|
Repository: "harbor",
|
||||||
@ -81,7 +81,7 @@ func (suite *TestPerformerSuite) TestPerform() {
|
|||||||
all: suite.all,
|
all: suite.all,
|
||||||
}
|
}
|
||||||
|
|
||||||
candidates := []*art.Candidate{
|
candidates := []*artifactselector.Candidate{
|
||||||
{
|
{
|
||||||
Namespace: "library",
|
Namespace: "library",
|
||||||
Repository: "harbor",
|
Repository: "harbor",
|
||||||
@ -103,7 +103,7 @@ func (suite *TestPerformerSuite) TestPerform() {
|
|||||||
|
|
||||||
// TestPerform tests Perform action
|
// TestPerform tests Perform action
|
||||||
func (suite *TestPerformerSuite) TestPerformImmutable() {
|
func (suite *TestPerformerSuite) TestPerformImmutable() {
|
||||||
all := []*art.Candidate{
|
all := []*artifactselector.Candidate{
|
||||||
{
|
{
|
||||||
NamespaceID: 1,
|
NamespaceID: 1,
|
||||||
Namespace: "library",
|
Namespace: "library",
|
||||||
@ -177,7 +177,7 @@ func (suite *TestPerformerSuite) TestPerformImmutable() {
|
|||||||
assert.NoError(suite.T(), immutabletag.ImmuCtr.DeleteImmutableRule(imid))
|
assert.NoError(suite.T(), immutabletag.ImmuCtr.DeleteImmutableRule(imid))
|
||||||
}()
|
}()
|
||||||
|
|
||||||
candidates := []*art.Candidate{
|
candidates := []*artifactselector.Candidate{
|
||||||
{
|
{
|
||||||
NamespaceID: 1,
|
NamespaceID: 1,
|
||||||
Namespace: "library",
|
Namespace: "library",
|
||||||
@ -200,7 +200,7 @@ func (suite *TestPerformerSuite) TestPerformImmutable() {
|
|||||||
require.Equal(suite.T(), "dev", r.Target.Tags[0])
|
require.Equal(suite.T(), "dev", r.Target.Tags[0])
|
||||||
} else if r.Target.Digest == "d2" {
|
} else if r.Target.Digest == "d2" {
|
||||||
require.Error(suite.T(), r.Error)
|
require.Error(suite.T(), r.Error)
|
||||||
require.IsType(suite.T(), (*art.ImmutableError)(nil), r.Error)
|
require.IsType(suite.T(), (*artifactselector.ImmutableError)(nil), r.Error)
|
||||||
} else {
|
} else {
|
||||||
require.Fail(suite.T(), "should not delete "+r.Target.Hash())
|
require.Fail(suite.T(), "should not delete "+r.Target.Hash())
|
||||||
}
|
}
|
||||||
@ -213,16 +213,16 @@ func (suite *TestPerformerSuite) TestPerformImmutable() {
|
|||||||
type fakeRetentionClient struct{}
|
type fakeRetentionClient struct{}
|
||||||
|
|
||||||
// GetCandidates ...
|
// GetCandidates ...
|
||||||
func (frc *fakeRetentionClient) GetCandidates(repo *art.Repository) ([]*art.Candidate, error) {
|
func (frc *fakeRetentionClient) GetCandidates(repo *artifactselector.Repository) ([]*artifactselector.Candidate, error) {
|
||||||
return nil, errors.New("not implemented")
|
return nil, errors.New("not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete ...
|
// Delete ...
|
||||||
func (frc *fakeRetentionClient) Delete(candidate *art.Candidate) error {
|
func (frc *fakeRetentionClient) Delete(candidate *artifactselector.Candidate) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteRepository ...
|
// DeleteRepository ...
|
||||||
func (frc *fakeRetentionClient) DeleteRepository(repo *art.Repository) error {
|
func (frc *fakeRetentionClient) DeleteRepository(repo *artifactselector.Repository) error {
|
||||||
panic("implement me")
|
panic("implement me")
|
||||||
}
|
}
|
||||||
|
@ -15,10 +15,10 @@
|
|||||||
package or
|
package or
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/common/utils/log"
|
"github.com/goharbor/harbor/src/common/utils/log"
|
||||||
"github.com/goharbor/harbor/src/pkg/art"
|
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/action"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/action"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/alg"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/alg"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
||||||
@ -29,7 +29,7 @@ import (
|
|||||||
type processor struct {
|
type processor struct {
|
||||||
// keep evaluator and its related selector if existing
|
// keep evaluator and its related selector if existing
|
||||||
// attentions here, the selectors can be empty/nil, that means match all "**"
|
// attentions here, the selectors can be empty/nil, that means match all "**"
|
||||||
evaluators map[*rule.Evaluator][]art.Selector
|
evaluators map[*rule.Evaluator][]artifactselector.Selector
|
||||||
// action performer
|
// action performer
|
||||||
performers map[string]action.Performer
|
performers map[string]action.Performer
|
||||||
}
|
}
|
||||||
@ -37,7 +37,7 @@ type processor struct {
|
|||||||
// New processor
|
// New processor
|
||||||
func New(parameters []*alg.Parameter) alg.Processor {
|
func New(parameters []*alg.Parameter) alg.Processor {
|
||||||
p := &processor{
|
p := &processor{
|
||||||
evaluators: make(map[*rule.Evaluator][]art.Selector),
|
evaluators: make(map[*rule.Evaluator][]artifactselector.Selector),
|
||||||
performers: make(map[string]action.Performer),
|
performers: make(map[string]action.Performer),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,10 +59,10 @@ func New(parameters []*alg.Parameter) alg.Processor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Process the candidates with the rules
|
// Process the candidates with the rules
|
||||||
func (p *processor) Process(artifacts []*art.Candidate) ([]*art.Result, error) {
|
func (p *processor) Process(artifacts []*artifactselector.Candidate) ([]*artifactselector.Result, error) {
|
||||||
if len(artifacts) == 0 {
|
if len(artifacts) == 0 {
|
||||||
log.Debug("no artifacts to retention")
|
log.Debug("no artifacts to retention")
|
||||||
return make([]*art.Result, 0), nil
|
return make([]*artifactselector.Result, 0), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -75,7 +75,7 @@ func (p *processor) Process(artifacts []*art.Candidate) ([]*art.Result, error) {
|
|||||||
// for sync
|
// for sync
|
||||||
type chanItem struct {
|
type chanItem struct {
|
||||||
action string
|
action string
|
||||||
processed []*art.Candidate
|
processed []*artifactselector.Candidate
|
||||||
}
|
}
|
||||||
|
|
||||||
resChan := make(chan *chanItem, 1)
|
resChan := make(chan *chanItem, 1)
|
||||||
@ -124,9 +124,9 @@ func (p *processor) Process(artifacts []*art.Candidate) ([]*art.Result, error) {
|
|||||||
for eva, selectors := range p.evaluators {
|
for eva, selectors := range p.evaluators {
|
||||||
var evaluator = *eva
|
var evaluator = *eva
|
||||||
|
|
||||||
go func(evaluator rule.Evaluator, selectors []art.Selector) {
|
go func(evaluator rule.Evaluator, selectors []artifactselector.Selector) {
|
||||||
var (
|
var (
|
||||||
processed []*art.Candidate
|
processed []*artifactselector.Candidate
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -173,7 +173,7 @@ func (p *processor) Process(artifacts []*art.Candidate) ([]*art.Result, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
results := make([]*art.Result, 0)
|
results := make([]*artifactselector.Result, 0)
|
||||||
// Perform actions
|
// Perform actions
|
||||||
for act, hash := range processedCandidates {
|
for act, hash := range processedCandidates {
|
||||||
var attachedErr error
|
var attachedErr error
|
||||||
@ -192,7 +192,7 @@ func (p *processor) Process(artifacts []*art.Candidate) ([]*art.Result, error) {
|
|||||||
|
|
||||||
if attachedErr != nil {
|
if attachedErr != nil {
|
||||||
for _, c := range cl {
|
for _, c := range cl {
|
||||||
results = append(results, &art.Result{
|
results = append(results, &artifactselector.Result{
|
||||||
Target: c,
|
Target: c,
|
||||||
Error: attachedErr,
|
Error: attachedErr,
|
||||||
})
|
})
|
||||||
@ -203,10 +203,10 @@ func (p *processor) Process(artifacts []*art.Candidate) ([]*art.Result, error) {
|
|||||||
return results, nil
|
return results, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type cHash map[string]*art.Candidate
|
type cHash map[string]*artifactselector.Candidate
|
||||||
|
|
||||||
func (ch cHash) toList() []*art.Candidate {
|
func (ch cHash) toList() []*artifactselector.Candidate {
|
||||||
l := make([]*art.Candidate, 0)
|
l := make([]*artifactselector.Candidate, 0)
|
||||||
|
|
||||||
for _, v := range ch {
|
for _, v := range ch {
|
||||||
l = append(l, v)
|
l = append(l, v)
|
||||||
|
@ -17,12 +17,12 @@ package or
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/goharbor/harbor/src/common/dao"
|
"github.com/goharbor/harbor/src/common/dao"
|
||||||
|
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/pkg/art"
|
"github.com/goharbor/harbor/src/pkg/artifactselector/selectors/doublestar"
|
||||||
"github.com/goharbor/harbor/src/pkg/art/selectors/doublestar"
|
"github.com/goharbor/harbor/src/pkg/artifactselector/selectors/label"
|
||||||
"github.com/goharbor/harbor/src/pkg/art/selectors/label"
|
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/dep"
|
"github.com/goharbor/harbor/src/pkg/retention/dep"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/action"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/action"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/alg"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/alg"
|
||||||
@ -39,7 +39,7 @@ import (
|
|||||||
type ProcessorTestSuite struct {
|
type ProcessorTestSuite struct {
|
||||||
suite.Suite
|
suite.Suite
|
||||||
|
|
||||||
all []*art.Candidate
|
all []*artifactselector.Candidate
|
||||||
|
|
||||||
oldClient dep.Client
|
oldClient dep.Client
|
||||||
}
|
}
|
||||||
@ -52,7 +52,7 @@ func TestProcessor(t *testing.T) {
|
|||||||
// SetupSuite ...
|
// SetupSuite ...
|
||||||
func (suite *ProcessorTestSuite) SetupSuite() {
|
func (suite *ProcessorTestSuite) SetupSuite() {
|
||||||
dao.PrepareTestForPostgresSQL()
|
dao.PrepareTestForPostgresSQL()
|
||||||
suite.all = []*art.Candidate{
|
suite.all = []*artifactselector.Candidate{
|
||||||
{
|
{
|
||||||
Namespace: "library",
|
Namespace: "library",
|
||||||
Repository: "harbor",
|
Repository: "harbor",
|
||||||
@ -92,7 +92,7 @@ func (suite *ProcessorTestSuite) TestProcess() {
|
|||||||
lastxParams[lastx.ParameterX] = 10
|
lastxParams[lastx.ParameterX] = 10
|
||||||
params = append(params, &alg.Parameter{
|
params = append(params, &alg.Parameter{
|
||||||
Evaluator: lastx.New(lastxParams),
|
Evaluator: lastx.New(lastxParams),
|
||||||
Selectors: []art.Selector{
|
Selectors: []artifactselector.Selector{
|
||||||
doublestar.New(doublestar.Matches, "*dev*"),
|
doublestar.New(doublestar.Matches, "*dev*"),
|
||||||
label.New(label.With, "L1,L2"),
|
label.New(label.With, "L1,L2"),
|
||||||
},
|
},
|
||||||
@ -103,7 +103,7 @@ func (suite *ProcessorTestSuite) TestProcess() {
|
|||||||
latestKParams[latestps.ParameterK] = 10
|
latestKParams[latestps.ParameterK] = 10
|
||||||
params = append(params, &alg.Parameter{
|
params = append(params, &alg.Parameter{
|
||||||
Evaluator: latestps.New(latestKParams),
|
Evaluator: latestps.New(latestKParams),
|
||||||
Selectors: []art.Selector{
|
Selectors: []artifactselector.Selector{
|
||||||
label.New(label.With, "L3"),
|
label.New(label.With, "L3"),
|
||||||
},
|
},
|
||||||
Performer: perf,
|
Performer: perf,
|
||||||
@ -133,7 +133,7 @@ func (suite *ProcessorTestSuite) TestProcess2() {
|
|||||||
alwaysParams := make(map[string]rule.Parameter)
|
alwaysParams := make(map[string]rule.Parameter)
|
||||||
params = append(params, &alg.Parameter{
|
params = append(params, &alg.Parameter{
|
||||||
Evaluator: always.New(alwaysParams),
|
Evaluator: always.New(alwaysParams),
|
||||||
Selectors: []art.Selector{
|
Selectors: []artifactselector.Selector{
|
||||||
doublestar.New(doublestar.Matches, "latest"),
|
doublestar.New(doublestar.Matches, "latest"),
|
||||||
label.New(label.With, ""),
|
label.New(label.With, ""),
|
||||||
},
|
},
|
||||||
@ -165,16 +165,16 @@ func (suite *ProcessorTestSuite) TestProcess2() {
|
|||||||
type fakeRetentionClient struct{}
|
type fakeRetentionClient struct{}
|
||||||
|
|
||||||
// GetCandidates ...
|
// GetCandidates ...
|
||||||
func (frc *fakeRetentionClient) GetCandidates(repo *art.Repository) ([]*art.Candidate, error) {
|
func (frc *fakeRetentionClient) GetCandidates(repo *artifactselector.Repository) ([]*artifactselector.Candidate, error) {
|
||||||
return nil, errors.New("not implemented")
|
return nil, errors.New("not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete ...
|
// Delete ...
|
||||||
func (frc *fakeRetentionClient) Delete(candidate *art.Candidate) error {
|
func (frc *fakeRetentionClient) Delete(candidate *artifactselector.Candidate) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteRepository ...
|
// DeleteRepository ...
|
||||||
func (frc *fakeRetentionClient) DeleteRepository(repo *art.Repository) error {
|
func (frc *fakeRetentionClient) DeleteRepository(repo *artifactselector.Repository) error {
|
||||||
panic("implement me")
|
panic("implement me")
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
package alg
|
package alg
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/goharbor/harbor/src/pkg/art"
|
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/action"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/action"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
||||||
)
|
)
|
||||||
@ -32,7 +32,7 @@ type Processor interface {
|
|||||||
// Returns:
|
// Returns:
|
||||||
// []*art.Result : the processed results
|
// []*art.Result : the processed results
|
||||||
// error : common error object if any errors occurred
|
// error : common error object if any errors occurred
|
||||||
Process(artifacts []*art.Candidate) ([]*art.Result, error)
|
Process(artifacts []*artifactselector.Candidate) ([]*artifactselector.Result, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parameter for constructing a processor
|
// Parameter for constructing a processor
|
||||||
@ -42,7 +42,7 @@ type Parameter struct {
|
|||||||
Evaluator rule.Evaluator
|
Evaluator rule.Evaluator
|
||||||
|
|
||||||
// Selectors for the rule
|
// Selectors for the rule
|
||||||
Selectors []art.Selector
|
Selectors []artifactselector.Selector
|
||||||
|
|
||||||
// Performer for the rule evaluator
|
// Performer for the rule evaluator
|
||||||
Performer action.Performer
|
Performer action.Performer
|
||||||
|
@ -16,16 +16,16 @@ package policy
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
||||||
|
|
||||||
index4 "github.com/goharbor/harbor/src/pkg/retention/policy/action/index"
|
index4 "github.com/goharbor/harbor/src/pkg/retention/policy/action/index"
|
||||||
|
|
||||||
index3 "github.com/goharbor/harbor/src/pkg/retention/policy/alg/index"
|
index3 "github.com/goharbor/harbor/src/pkg/retention/policy/alg/index"
|
||||||
|
|
||||||
index2 "github.com/goharbor/harbor/src/pkg/art/selectors/index"
|
index2 "github.com/goharbor/harbor/src/pkg/artifactselector/selectors/index"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/rule/index"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/rule/index"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/pkg/art"
|
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/alg"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/alg"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/lwp"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/lwp"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
@ -46,7 +46,7 @@ type Builder interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewBuilder news a basic builder
|
// NewBuilder news a basic builder
|
||||||
func NewBuilder(all []*art.Candidate) Builder {
|
func NewBuilder(all []*artifactselector.Candidate) Builder {
|
||||||
return &basicBuilder{
|
return &basicBuilder{
|
||||||
allCandidates: all,
|
allCandidates: all,
|
||||||
}
|
}
|
||||||
@ -54,7 +54,7 @@ func NewBuilder(all []*art.Candidate) Builder {
|
|||||||
|
|
||||||
// basicBuilder is default implementation of Builder interface
|
// basicBuilder is default implementation of Builder interface
|
||||||
type basicBuilder struct {
|
type basicBuilder struct {
|
||||||
allCandidates []*art.Candidate
|
allCandidates []*artifactselector.Candidate
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build policy processor from the raw policy
|
// Build policy processor from the raw policy
|
||||||
@ -76,7 +76,7 @@ func (bb *basicBuilder) Build(policy *lwp.Metadata, isDryRun bool) (alg.Processo
|
|||||||
return nil, errors.Wrap(err, "get action performer by metadata")
|
return nil, errors.Wrap(err, "get action performer by metadata")
|
||||||
}
|
}
|
||||||
|
|
||||||
sl := make([]art.Selector, 0)
|
sl := make([]artifactselector.Selector, 0)
|
||||||
for _, s := range r.TagSelectors {
|
for _, s := range r.TagSelectors {
|
||||||
sel, err := index2.Get(s.Kind, s.Decoration, s.Pattern)
|
sel, err := index2.Get(s.Kind, s.Decoration, s.Pattern)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -16,6 +16,7 @@ package policy
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/goharbor/harbor/src/common/dao"
|
"github.com/goharbor/harbor/src/common/dao"
|
||||||
|
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -23,7 +24,7 @@ import (
|
|||||||
|
|
||||||
index2 "github.com/goharbor/harbor/src/pkg/retention/policy/alg/index"
|
index2 "github.com/goharbor/harbor/src/pkg/retention/policy/alg/index"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/pkg/art/selectors/index"
|
"github.com/goharbor/harbor/src/pkg/artifactselector/selectors/index"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/dep"
|
"github.com/goharbor/harbor/src/pkg/retention/dep"
|
||||||
|
|
||||||
@ -31,9 +32,9 @@ import (
|
|||||||
|
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/alg/or"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/alg/or"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/pkg/art/selectors/label"
|
"github.com/goharbor/harbor/src/pkg/artifactselector/selectors/label"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/pkg/art/selectors/doublestar"
|
"github.com/goharbor/harbor/src/pkg/artifactselector/selectors/doublestar"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/rule/latestps"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/rule/latestps"
|
||||||
|
|
||||||
@ -47,8 +48,6 @@ import (
|
|||||||
|
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/lwp"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/lwp"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/pkg/art"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -56,7 +55,7 @@ import (
|
|||||||
type TestBuilderSuite struct {
|
type TestBuilderSuite struct {
|
||||||
suite.Suite
|
suite.Suite
|
||||||
|
|
||||||
all []*art.Candidate
|
all []*artifactselector.Candidate
|
||||||
oldClient dep.Client
|
oldClient dep.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,7 +67,7 @@ func TestBuilder(t *testing.T) {
|
|||||||
// SetupSuite prepares the testing content if needed
|
// SetupSuite prepares the testing content if needed
|
||||||
func (suite *TestBuilderSuite) SetupSuite() {
|
func (suite *TestBuilderSuite) SetupSuite() {
|
||||||
dao.PrepareTestForPostgresSQL()
|
dao.PrepareTestForPostgresSQL()
|
||||||
suite.all = []*art.Candidate{
|
suite.all = []*artifactselector.Candidate{
|
||||||
{
|
{
|
||||||
NamespaceID: 1,
|
NamespaceID: 1,
|
||||||
Namespace: "library",
|
Namespace: "library",
|
||||||
@ -165,21 +164,21 @@ func (suite *TestBuilderSuite) TestBuild() {
|
|||||||
|
|
||||||
type fakeRetentionClient struct{}
|
type fakeRetentionClient struct{}
|
||||||
|
|
||||||
func (frc *fakeRetentionClient) DeleteRepository(repo *art.Repository) error {
|
func (frc *fakeRetentionClient) DeleteRepository(repo *artifactselector.Repository) error {
|
||||||
panic("implement me")
|
panic("implement me")
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetCandidates ...
|
// GetCandidates ...
|
||||||
func (frc *fakeRetentionClient) GetCandidates(repo *art.Repository) ([]*art.Candidate, error) {
|
func (frc *fakeRetentionClient) GetCandidates(repo *artifactselector.Repository) ([]*artifactselector.Candidate, error) {
|
||||||
return nil, errors.New("not implemented")
|
return nil, errors.New("not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete ...
|
// Delete ...
|
||||||
func (frc *fakeRetentionClient) Delete(candidate *art.Candidate) error {
|
func (frc *fakeRetentionClient) Delete(candidate *artifactselector.Candidate) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SubmitTask ...
|
// SubmitTask ...
|
||||||
func (frc *fakeRetentionClient) SubmitTask(taskID int64, repository *art.Repository, meta *lwp.Metadata) (string, error) {
|
func (frc *fakeRetentionClient) SubmitTask(taskID int64, repository *artifactselector.Repository, meta *lwp.Metadata) (string, error) {
|
||||||
return "", errors.New("not implemented")
|
return "", errors.New("not implemented")
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
package always
|
package always
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/goharbor/harbor/src/pkg/art"
|
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/action"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/action"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
||||||
)
|
)
|
||||||
@ -28,7 +28,7 @@ const (
|
|||||||
type evaluator struct{}
|
type evaluator struct{}
|
||||||
|
|
||||||
// Process for the "always" Evaluator simply returns the input with no error
|
// Process for the "always" Evaluator simply returns the input with no error
|
||||||
func (e *evaluator) Process(artifacts []*art.Candidate) ([]*art.Candidate, error) {
|
func (e *evaluator) Process(artifacts []*artifactselector.Candidate) ([]*artifactselector.Candidate, error) {
|
||||||
return artifacts, nil
|
return artifacts, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,9 +15,9 @@
|
|||||||
package always
|
package always
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/pkg/art"
|
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
@ -36,7 +36,7 @@ func (e *EvaluatorTestSuite) TestNew() {
|
|||||||
|
|
||||||
func (e *EvaluatorTestSuite) TestProcess() {
|
func (e *EvaluatorTestSuite) TestProcess() {
|
||||||
sut := New(rule.Parameters{})
|
sut := New(rule.Parameters{})
|
||||||
input := []*art.Candidate{{PushedTime: 0}, {PushedTime: 1}, {PushedTime: 2}, {PushedTime: 3}}
|
input := []*artifactselector.Candidate{{PushedTime: 0}, {PushedTime: 1}, {PushedTime: 2}, {PushedTime: 3}}
|
||||||
|
|
||||||
result, err := sut.Process(input)
|
result, err := sut.Process(input)
|
||||||
|
|
||||||
|
@ -17,10 +17,10 @@ package dayspl
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/goharbor/harbor/src/common/utils"
|
"github.com/goharbor/harbor/src/common/utils"
|
||||||
|
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/common/utils/log"
|
"github.com/goharbor/harbor/src/common/utils/log"
|
||||||
"github.com/goharbor/harbor/src/pkg/art"
|
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/action"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/action"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
||||||
)
|
)
|
||||||
@ -41,7 +41,7 @@ type evaluator struct {
|
|||||||
n int
|
n int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *evaluator) Process(artifacts []*art.Candidate) (result []*art.Candidate, err error) {
|
func (e *evaluator) Process(artifacts []*artifactselector.Candidate) (result []*artifactselector.Candidate, err error) {
|
||||||
minPullTime := time.Now().UTC().Add(time.Duration(-1*24*e.n) * time.Hour).Unix()
|
minPullTime := time.Now().UTC().Add(time.Duration(-1*24*e.n) * time.Hour).Unix()
|
||||||
for _, a := range artifacts {
|
for _, a := range artifacts {
|
||||||
if a.PulledTime >= minPullTime {
|
if a.PulledTime >= minPullTime {
|
||||||
|
@ -17,11 +17,11 @@ package dayspl
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/pkg/art"
|
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
@ -54,7 +54,7 @@ func (e *EvaluatorTestSuite) TestNew() {
|
|||||||
|
|
||||||
func (e *EvaluatorTestSuite) TestProcess() {
|
func (e *EvaluatorTestSuite) TestProcess() {
|
||||||
now := time.Now().UTC()
|
now := time.Now().UTC()
|
||||||
data := []*art.Candidate{
|
data := []*artifactselector.Candidate{
|
||||||
{PulledTime: daysAgo(now, 1, time.Hour)},
|
{PulledTime: daysAgo(now, 1, time.Hour)},
|
||||||
{PulledTime: daysAgo(now, 2, time.Hour)},
|
{PulledTime: daysAgo(now, 2, time.Hour)},
|
||||||
{PulledTime: daysAgo(now, 3, time.Hour)},
|
{PulledTime: daysAgo(now, 3, time.Hour)},
|
||||||
|
@ -17,10 +17,10 @@ package daysps
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/goharbor/harbor/src/common/utils"
|
"github.com/goharbor/harbor/src/common/utils"
|
||||||
|
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/common/utils/log"
|
"github.com/goharbor/harbor/src/common/utils/log"
|
||||||
"github.com/goharbor/harbor/src/pkg/art"
|
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/action"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/action"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
||||||
)
|
)
|
||||||
@ -41,7 +41,7 @@ type evaluator struct {
|
|||||||
n int
|
n int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *evaluator) Process(artifacts []*art.Candidate) (result []*art.Candidate, err error) {
|
func (e *evaluator) Process(artifacts []*artifactselector.Candidate) (result []*artifactselector.Candidate, err error) {
|
||||||
minPushTime := time.Now().UTC().Add(time.Duration(-1*24*e.n) * time.Hour).Unix()
|
minPushTime := time.Now().UTC().Add(time.Duration(-1*24*e.n) * time.Hour).Unix()
|
||||||
for _, a := range artifacts {
|
for _, a := range artifacts {
|
||||||
if a.PushedTime >= minPushTime {
|
if a.PushedTime >= minPushTime {
|
||||||
|
@ -17,10 +17,10 @@ package daysps
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/pkg/art"
|
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
@ -54,7 +54,7 @@ func (e *EvaluatorTestSuite) TestNew() {
|
|||||||
|
|
||||||
func (e *EvaluatorTestSuite) TestProcess() {
|
func (e *EvaluatorTestSuite) TestProcess() {
|
||||||
now := time.Now().UTC()
|
now := time.Now().UTC()
|
||||||
data := []*art.Candidate{
|
data := []*artifactselector.Candidate{
|
||||||
{PushedTime: daysAgo(now, 1, time.Hour)},
|
{PushedTime: daysAgo(now, 1, time.Hour)},
|
||||||
{PushedTime: daysAgo(now, 2, time.Hour)},
|
{PushedTime: daysAgo(now, 2, time.Hour)},
|
||||||
{PushedTime: daysAgo(now, 3, time.Hour)},
|
{PushedTime: daysAgo(now, 3, time.Hour)},
|
||||||
|
@ -14,7 +14,9 @@
|
|||||||
|
|
||||||
package rule
|
package rule
|
||||||
|
|
||||||
import "github.com/goharbor/harbor/src/pkg/art"
|
import (
|
||||||
|
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
||||||
|
)
|
||||||
|
|
||||||
// Evaluator defines method of executing rule
|
// Evaluator defines method of executing rule
|
||||||
type Evaluator interface {
|
type Evaluator interface {
|
||||||
@ -26,7 +28,7 @@ type Evaluator interface {
|
|||||||
// Returns:
|
// Returns:
|
||||||
// []*art.Candidate : matched candidates for next stage
|
// []*art.Candidate : matched candidates for next stage
|
||||||
// error : common error object if any errors occurred
|
// error : common error object if any errors occurred
|
||||||
Process(artifacts []*art.Candidate) ([]*art.Candidate, error)
|
Process(artifacts []*artifactselector.Candidate) ([]*artifactselector.Candidate, error)
|
||||||
|
|
||||||
// Specify what action is performed to the candidates processed by this evaluator
|
// Specify what action is performed to the candidates processed by this evaluator
|
||||||
Action() string
|
Action() string
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
package index
|
package index
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -22,7 +23,6 @@ import (
|
|||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/pkg/art"
|
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
||||||
|
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
@ -63,7 +63,7 @@ func (suite *IndexTestSuite) TestGet() {
|
|||||||
require.NoError(suite.T(), err)
|
require.NoError(suite.T(), err)
|
||||||
require.NotNil(suite.T(), evaluator)
|
require.NotNil(suite.T(), evaluator)
|
||||||
|
|
||||||
candidates := []*art.Candidate{{
|
candidates := []*artifactselector.Candidate{{
|
||||||
Namespace: "library",
|
Namespace: "library",
|
||||||
Repository: "harbor",
|
Repository: "harbor",
|
||||||
Kind: "image",
|
Kind: "image",
|
||||||
@ -102,7 +102,7 @@ type fakeEvaluator struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Process rule
|
// Process rule
|
||||||
func (e *fakeEvaluator) Process(artifacts []*art.Candidate) ([]*art.Candidate, error) {
|
func (e *fakeEvaluator) Process(artifacts []*artifactselector.Candidate) ([]*artifactselector.Candidate, error) {
|
||||||
return artifacts, nil
|
return artifacts, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,10 +16,10 @@ package lastx
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/goharbor/harbor/src/common/utils"
|
"github.com/goharbor/harbor/src/common/utils"
|
||||||
|
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/common/utils/log"
|
"github.com/goharbor/harbor/src/common/utils/log"
|
||||||
"github.com/goharbor/harbor/src/pkg/art"
|
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/action"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/action"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
||||||
)
|
)
|
||||||
@ -40,7 +40,7 @@ type evaluator struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Process the candidates based on the rule definition
|
// Process the candidates based on the rule definition
|
||||||
func (e *evaluator) Process(artifacts []*art.Candidate) (retain []*art.Candidate, err error) {
|
func (e *evaluator) Process(artifacts []*artifactselector.Candidate) (retain []*artifactselector.Candidate, err error) {
|
||||||
cutoff := time.Now().Add(time.Duration(e.x*-24) * time.Hour)
|
cutoff := time.Now().Add(time.Duration(e.x*-24) * time.Hour)
|
||||||
for _, a := range artifacts {
|
for _, a := range artifacts {
|
||||||
if time.Unix(a.PushedTime, 0).UTC().After(cutoff) {
|
if time.Unix(a.PushedTime, 0).UTC().After(cutoff) {
|
||||||
|
@ -2,10 +2,10 @@ package lastx
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/pkg/art"
|
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
@ -38,7 +38,7 @@ func (e *EvaluatorTestSuite) TestNew() {
|
|||||||
|
|
||||||
func (e *EvaluatorTestSuite) TestProcess() {
|
func (e *EvaluatorTestSuite) TestProcess() {
|
||||||
now := time.Now().UTC()
|
now := time.Now().UTC()
|
||||||
data := []*art.Candidate{
|
data := []*artifactselector.Candidate{
|
||||||
{PushedTime: now.Add(time.Duration(1*-24) * time.Hour).Unix()},
|
{PushedTime: now.Add(time.Duration(1*-24) * time.Hour).Unix()},
|
||||||
{PushedTime: now.Add(time.Duration(2*-24) * time.Hour).Unix()},
|
{PushedTime: now.Add(time.Duration(2*-24) * time.Hour).Unix()},
|
||||||
{PushedTime: now.Add(time.Duration(3*-24) * time.Hour).Unix()},
|
{PushedTime: now.Add(time.Duration(3*-24) * time.Hour).Unix()},
|
||||||
|
@ -16,10 +16,10 @@ package latestk
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/goharbor/harbor/src/common/utils"
|
"github.com/goharbor/harbor/src/common/utils"
|
||||||
|
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/common/utils/log"
|
"github.com/goharbor/harbor/src/common/utils/log"
|
||||||
"github.com/goharbor/harbor/src/pkg/art"
|
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/action"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/action"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
||||||
)
|
)
|
||||||
@ -40,7 +40,7 @@ type evaluator struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Process the candidates based on the rule definition
|
// Process the candidates based on the rule definition
|
||||||
func (e *evaluator) Process(artifacts []*art.Candidate) ([]*art.Candidate, error) {
|
func (e *evaluator) Process(artifacts []*artifactselector.Candidate) ([]*artifactselector.Candidate, error) {
|
||||||
// Sort artifacts by their "active time"
|
// Sort artifacts by their "active time"
|
||||||
//
|
//
|
||||||
// Active time is defined as the selection of c.PulledTime or c.PushedTime,
|
// Active time is defined as the selection of c.PulledTime or c.PushedTime,
|
||||||
@ -81,7 +81,7 @@ func New(params rule.Parameters) rule.Evaluator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func activeTime(c *art.Candidate) int64 {
|
func activeTime(c *artifactselector.Candidate) int64 {
|
||||||
if c.PulledTime > c.PushedTime {
|
if c.PulledTime > c.PushedTime {
|
||||||
return c.PulledTime
|
return c.PulledTime
|
||||||
}
|
}
|
||||||
|
@ -16,24 +16,24 @@ package latestk
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/pkg/art"
|
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
)
|
)
|
||||||
|
|
||||||
type EvaluatorTestSuite struct {
|
type EvaluatorTestSuite struct {
|
||||||
suite.Suite
|
suite.Suite
|
||||||
|
|
||||||
artifacts []*art.Candidate
|
artifacts []*artifactselector.Candidate
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *EvaluatorTestSuite) SetupSuite() {
|
func (e *EvaluatorTestSuite) SetupSuite() {
|
||||||
e.artifacts = []*art.Candidate{
|
e.artifacts = []*artifactselector.Candidate{
|
||||||
{PulledTime: 1, PushedTime: 2},
|
{PulledTime: 1, PushedTime: 2},
|
||||||
{PulledTime: 3, PushedTime: 4},
|
{PulledTime: 3, PushedTime: 4},
|
||||||
{PulledTime: 6, PushedTime: 5},
|
{PulledTime: 6, PushedTime: 5},
|
||||||
|
@ -17,11 +17,11 @@ package latestpl
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/goharbor/harbor/src/common/utils"
|
"github.com/goharbor/harbor/src/common/utils"
|
||||||
|
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
||||||
"math"
|
"math"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/common/utils/log"
|
"github.com/goharbor/harbor/src/common/utils/log"
|
||||||
"github.com/goharbor/harbor/src/pkg/art"
|
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/action"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/action"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
||||||
)
|
)
|
||||||
@ -41,7 +41,7 @@ type evaluator struct {
|
|||||||
n int
|
n int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *evaluator) Process(artifacts []*art.Candidate) ([]*art.Candidate, error) {
|
func (e *evaluator) Process(artifacts []*artifactselector.Candidate) ([]*artifactselector.Candidate, error) {
|
||||||
sort.Slice(artifacts, func(i, j int) bool {
|
sort.Slice(artifacts, func(i, j int) bool {
|
||||||
return artifacts[i].PulledTime > artifacts[j].PulledTime
|
return artifacts[i].PulledTime > artifacts[j].PulledTime
|
||||||
})
|
})
|
||||||
|
@ -17,10 +17,10 @@ package latestpl
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/pkg/art"
|
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
@ -52,7 +52,7 @@ func (e *EvaluatorTestSuite) TestNew() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e *EvaluatorTestSuite) TestProcess() {
|
func (e *EvaluatorTestSuite) TestProcess() {
|
||||||
data := []*art.Candidate{{PulledTime: 0}, {PulledTime: 1}, {PulledTime: 2}, {PulledTime: 3}, {PulledTime: 4}}
|
data := []*artifactselector.Candidate{{PulledTime: 0}, {PulledTime: 1}, {PulledTime: 2}, {PulledTime: 3}, {PulledTime: 4}}
|
||||||
rand.Shuffle(len(data), func(i, j int) {
|
rand.Shuffle(len(data), func(i, j int) {
|
||||||
data[i], data[j] = data[j], data[i]
|
data[i], data[j] = data[j], data[i]
|
||||||
})
|
})
|
||||||
|
@ -17,11 +17,11 @@ package latestps
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/goharbor/harbor/src/common/utils"
|
"github.com/goharbor/harbor/src/common/utils"
|
||||||
|
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
||||||
"math"
|
"math"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/common/utils/log"
|
"github.com/goharbor/harbor/src/common/utils/log"
|
||||||
"github.com/goharbor/harbor/src/pkg/art"
|
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/action"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/action"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
||||||
)
|
)
|
||||||
@ -42,7 +42,7 @@ type evaluator struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Process the candidates based on the rule definition
|
// Process the candidates based on the rule definition
|
||||||
func (e *evaluator) Process(artifacts []*art.Candidate) ([]*art.Candidate, error) {
|
func (e *evaluator) Process(artifacts []*artifactselector.Candidate) ([]*artifactselector.Candidate, error) {
|
||||||
// The updated proposal does not guarantee the order artifacts are provided, so we have to sort them first
|
// The updated proposal does not guarantee the order artifacts are provided, so we have to sort them first
|
||||||
sort.Slice(artifacts, func(i, j int) bool {
|
sort.Slice(artifacts, func(i, j int) bool {
|
||||||
return artifacts[i].PushedTime > artifacts[j].PushedTime
|
return artifacts[i].PushedTime > artifacts[j].PushedTime
|
||||||
|
@ -3,12 +3,12 @@ package latestps
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/pkg/art"
|
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
@ -39,7 +39,7 @@ func (e *EvaluatorTestSuite) TestNew() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e *EvaluatorTestSuite) TestProcess() {
|
func (e *EvaluatorTestSuite) TestProcess() {
|
||||||
data := []*art.Candidate{{PushedTime: 0}, {PushedTime: 1}, {PushedTime: 2}, {PushedTime: 3}, {PushedTime: 4}}
|
data := []*artifactselector.Candidate{{PushedTime: 0}, {PushedTime: 1}, {PushedTime: 2}, {PushedTime: 3}, {PushedTime: 4}}
|
||||||
rand.Shuffle(len(data), func(i, j int) {
|
rand.Shuffle(len(data), func(i, j int) {
|
||||||
data[i], data[j] = data[j], data[i]
|
data[i], data[j] = data[j], data[i]
|
||||||
})
|
})
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
package nothing
|
package nothing
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/goharbor/harbor/src/pkg/art"
|
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/action"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/action"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
||||||
)
|
)
|
||||||
@ -28,7 +28,7 @@ const (
|
|||||||
type evaluator struct{}
|
type evaluator struct{}
|
||||||
|
|
||||||
// Process for the "nothing" Evaluator simply returns the input with no error
|
// Process for the "nothing" Evaluator simply returns the input with no error
|
||||||
func (e *evaluator) Process(artifacts []*art.Candidate) (processed []*art.Candidate, err error) {
|
func (e *evaluator) Process(artifacts []*artifactselector.Candidate) (processed []*artifactselector.Candidate, err error) {
|
||||||
return processed, err
|
return processed, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,9 +15,9 @@
|
|||||||
package nothing
|
package nothing
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/pkg/art"
|
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
@ -36,7 +36,7 @@ func (e *EvaluatorTestSuite) TestNew() {
|
|||||||
|
|
||||||
func (e *EvaluatorTestSuite) TestProcess() {
|
func (e *EvaluatorTestSuite) TestProcess() {
|
||||||
sut := New(rule.Parameters{})
|
sut := New(rule.Parameters{})
|
||||||
input := []*art.Candidate{{PushedTime: 0}, {PushedTime: 1}, {PushedTime: 2}, {PushedTime: 3}}
|
input := []*artifactselector.Candidate{{PushedTime: 0}, {PushedTime: 1}, {PushedTime: 2}, {PushedTime: 3}}
|
||||||
|
|
||||||
result, err := sut.Process(input)
|
result, err := sut.Process(input)
|
||||||
|
|
||||||
|
@ -15,9 +15,12 @@
|
|||||||
package event
|
package event
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
bo "github.com/astaxie/beego/orm"
|
||||||
|
"github.com/goharbor/harbor/src/api/artifact"
|
||||||
"github.com/goharbor/harbor/src/api/scan"
|
"github.com/goharbor/harbor/src/api/scan"
|
||||||
"github.com/goharbor/harbor/src/common/utils/log"
|
"github.com/goharbor/harbor/src/common/utils/log"
|
||||||
"github.com/goharbor/harbor/src/pkg/art"
|
"github.com/goharbor/harbor/src/internal/orm"
|
||||||
"github.com/goharbor/harbor/src/pkg/notifier"
|
"github.com/goharbor/harbor/src/pkg/notifier"
|
||||||
"github.com/goharbor/harbor/src/pkg/notifier/model"
|
"github.com/goharbor/harbor/src/pkg/notifier/model"
|
||||||
"github.com/goharbor/harbor/src/pkg/q"
|
"github.com/goharbor/harbor/src/pkg/q"
|
||||||
@ -28,7 +31,7 @@ import (
|
|||||||
type scanCtlGetter func() scan.Controller
|
type scanCtlGetter func() scan.Controller
|
||||||
|
|
||||||
// artCtlGetter for getting a artifact controller reference to avoid package importing order issue.
|
// artCtlGetter for getting a artifact controller reference to avoid package importing order issue.
|
||||||
type artCtlGetter func() art.Controller
|
type artCtlGetter func() artifact.Controller
|
||||||
|
|
||||||
// onDelImageHandler is a handler to listen to the internal delete image event.
|
// onDelImageHandler is a handler to listen to the internal delete image event.
|
||||||
type onDelImageHandler struct {
|
type onDelImageHandler struct {
|
||||||
@ -44,8 +47,8 @@ func NewOnDelImageHandler() notifier.NotificationHandler {
|
|||||||
scanCtl: func() scan.Controller {
|
scanCtl: func() scan.Controller {
|
||||||
return scan.DefaultController
|
return scan.DefaultController
|
||||||
},
|
},
|
||||||
artCtl: func() art.Controller {
|
artCtl: func() artifact.Controller {
|
||||||
return art.DefaultController
|
return artifact.Ctl
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -67,10 +70,11 @@ func (o *onDelImageHandler) Handle(value interface{}) error {
|
|||||||
Keywords: make(map[string]interface{}),
|
Keywords: make(map[string]interface{}),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ctx := orm.NewContext(context.TODO(), bo.NewOrm())
|
||||||
for _, res := range evt.Resource {
|
for _, res := range evt.Resource {
|
||||||
// Check if it is safe to delete the reports.
|
// Check if it is safe to delete the reports.
|
||||||
query.Keywords["digest"] = res.Digest
|
query.Keywords["digest"] = res.Digest
|
||||||
l, err := o.artCtl().List(query)
|
l, err := o.artCtl().List(ctx, query, nil)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Just logged
|
// Just logged
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package immutabletag
|
package immutabletag
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/goharbor/harbor/src/pkg/art"
|
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
||||||
"github.com/stretchr/testify/mock"
|
"github.com/stretchr/testify/mock"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -11,7 +11,7 @@ type FakeMatcher struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Match ...
|
// Match ...
|
||||||
func (f *FakeMatcher) Match(pid int64, c art.Candidate) (bool, error) {
|
func (f *FakeMatcher) Match(pid int64, c artifactselector.Candidate) (bool, error) {
|
||||||
args := f.Called()
|
args := f.Called()
|
||||||
return args.Bool(0), args.Error(1)
|
return args.Bool(0), args.Error(1)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user