Merge pull request #10857 from bitsf/remove_pkg_art

feat(oci) remove dead code pkg/art
This commit is contained in:
Ziming 2020-03-03 11:50:15 +08:00 committed by GitHub
commit 70dcca6579
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
52 changed files with 225 additions and 542 deletions

View File

@ -5,8 +5,8 @@ import (
"github.com/goharbor/harbor/src/common/utils"
"github.com/goharbor/harbor/src/common/utils/log"
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/artifactselector"
"github.com/goharbor/harbor/src/pkg/immutabletag/match"
"github.com/goharbor/harbor/src/pkg/immutabletag/match/rule"
"github.com/goharbor/harbor/src/pkg/q"
@ -201,7 +201,7 @@ func (c *controller) populateImmutableStatus(ctx context.Context, tag *Tag) {
return
}
_, 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,
Tags: []string{tag.Name},
NamespaceID: artifact.ProjectID,

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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
}
}
}

View File

@ -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))
}

View File

@ -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)
}

View File

@ -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)
}

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package art
package artifactselector
import (
"encoding/base64"

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package art
package artifactselector
// Result keeps the action result
type Result struct {

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package art
package artifactselector
// Selector is used to filter the inputting list
type Selector interface {

View File

@ -16,7 +16,7 @@ package doublestar
import (
"github.com/bmatcuk/doublestar"
"github.com/goharbor/harbor/src/pkg/art"
"github.com/goharbor/harbor/src/pkg/artifactselector"
)
const (
@ -46,7 +46,7 @@ type selector struct {
}
// 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 := ""
excludes := false
@ -96,7 +96,7 @@ func (s *selector) Select(artifacts []*art.Candidate) (selected []*art.Candidate
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 {
matched, err := match(s.pattern, t)
if err != nil {
@ -109,7 +109,7 @@ func (s *selector) tagSelectMatch(artifact *art.Candidate) (selected bool, err e
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 {
matched, err := match(s.pattern, t)
if err != nil {
@ -123,7 +123,7 @@ func (s *selector) tagSelectExclude(artifact *art.Candidate) (selected bool, err
}
// 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{
decoration: decoration,
pattern: pattern,

View File

@ -16,7 +16,7 @@ package doublestar
import (
"fmt"
"github.com/goharbor/harbor/src/pkg/art"
"github.com/goharbor/harbor/src/pkg/artifactselector"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
@ -28,7 +28,7 @@ import (
type RegExpSelectorTestSuite struct {
suite.Suite
artifacts []*art.Candidate
artifacts []*artifactselector.Candidate
}
// TestRegExpSelector is entrance for RegExpSelectorTestSuite
@ -38,13 +38,13 @@ func TestRegExpSelector(t *testing.T) {
// SetupSuite to do preparation work
func (suite *RegExpSelectorTestSuite) SetupSuite() {
suite.artifacts = []*art.Candidate{
suite.artifacts = []*artifactselector.Candidate{
{
NamespaceID: 1,
Namespace: "library",
Repository: "harbor",
Tags: []string{"latest"},
Kind: art.Image,
Kind: artifactselector.Image,
PushedTime: time.Now().Unix() - 3600,
PulledTime: time.Now().Unix(),
CreationTime: time.Now().Unix() - 7200,
@ -55,7 +55,7 @@ func (suite *RegExpSelectorTestSuite) SetupSuite() {
Namespace: "retention",
Repository: "redis",
Tags: []string{"4.0"},
Kind: art.Image,
Kind: artifactselector.Image,
PushedTime: time.Now().Unix() - 3600,
PulledTime: time.Now().Unix(),
CreationTime: time.Now().Unix() - 7200,
@ -66,7 +66,7 @@ func (suite *RegExpSelectorTestSuite) SetupSuite() {
Namespace: "retention",
Repository: "redis",
Tags: []string{"4.1"},
Kind: art.Image,
Kind: artifactselector.Image,
PushedTime: time.Now().Unix() - 3600,
PulledTime: time.Now().Unix(),
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)
func expect(expected []string, candidates []*art.Candidate) bool {
func expect(expected []string, candidates []*artifactselector.Candidate) bool {
hash := make(map[string]bool)
for _, art := range candidates {

View File

@ -15,10 +15,10 @@
package index
import (
"github.com/goharbor/harbor/src/pkg/artifactselector"
"sync"
"github.com/goharbor/harbor/src/pkg/art"
"github.com/goharbor/harbor/src/pkg/art/selectors/doublestar"
"github.com/goharbor/harbor/src/pkg/artifactselector/selectors/doublestar"
"github.com/pkg/errors"
)
@ -49,11 +49,11 @@ type IndexedMeta struct {
// indexedItem defined item kept in the index
type indexedItem struct {
Meta *IndexedMeta
Factory art.SelectorFactory
Factory artifactselector.SelectorFactory
}
// 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 {
// do nothing
return
@ -69,7 +69,7 @@ func Register(kind string, decorations []string, factory art.SelectorFactory) {
}
// 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 {
return nil, errors.New("empty selector kind or decoration")
}

View File

@ -15,9 +15,8 @@
package label
import (
"github.com/goharbor/harbor/src/pkg/artifactselector"
"strings"
"github.com/goharbor/harbor/src/pkg/art"
)
const (
@ -39,7 +38,7 @@ type selector struct {
}
// 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 {
if isMatched(s.labels, art.Labels, s.decoration) {
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
func New(decoration string, pattern string) art.Selector {
func New(decoration string, pattern string) artifactselector.Selector {
labels := make([]string, 0)
if len(pattern) > 0 {
labels = append(labels, strings.Split(pattern, ",")...)

View File

@ -16,7 +16,7 @@ package label
import (
"fmt"
"github.com/goharbor/harbor/src/pkg/art"
"github.com/goharbor/harbor/src/pkg/artifactselector"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
@ -28,7 +28,7 @@ import (
type LabelSelectorTestSuite struct {
suite.Suite
artifacts []*art.Candidate
artifacts []*artifactselector.Candidate
}
// TestLabelSelector is entrance for LabelSelectorTestSuite
@ -38,13 +38,13 @@ func TestLabelSelector(t *testing.T) {
// SetupSuite to do preparation work
func (suite *LabelSelectorTestSuite) SetupSuite() {
suite.artifacts = []*art.Candidate{
suite.artifacts = []*artifactselector.Candidate{
{
NamespaceID: 1,
Namespace: "library",
Repository: "harbor",
Tags: []string{"1.9"},
Kind: art.Image,
Kind: artifactselector.Image,
PushedTime: time.Now().Unix() - 3600,
PulledTime: time.Now().Unix(),
CreationTime: time.Now().Unix() - 7200,
@ -55,7 +55,7 @@ func (suite *LabelSelectorTestSuite) SetupSuite() {
Namespace: "library",
Repository: "harbor",
Tags: []string{"dev"},
Kind: art.Image,
Kind: artifactselector.Image,
PushedTime: time.Now().Unix() - 3600,
PulledTime: time.Now().Unix(),
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)
func expect(expected []string, candidates []*art.Candidate) bool {
func expect(expected []string, candidates []*artifactselector.Candidate) bool {
hash := make(map[string]bool)
for _, art := range candidates {

View File

@ -1,11 +1,11 @@
package match
import (
"github.com/goharbor/harbor/src/pkg/art"
"github.com/goharbor/harbor/src/pkg/artifactselector"
)
// ImmutableTagMatcher ...
type ImmutableTagMatcher interface {
// 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)
}

View File

@ -1,8 +1,8 @@
package rule
import (
"github.com/goharbor/harbor/src/pkg/art"
"github.com/goharbor/harbor/src/pkg/art/selectors/index"
"github.com/goharbor/harbor/src/pkg/artifactselector"
"github.com/goharbor/harbor/src/pkg/artifactselector/selectors/index"
"github.com/goharbor/harbor/src/pkg/immutabletag"
"github.com/goharbor/harbor/src/pkg/immutabletag/match"
"github.com/goharbor/harbor/src/pkg/immutabletag/model"
@ -14,19 +14,19 @@ type Matcher struct {
}
// 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 {
return false, err
}
cands := []*art.Candidate{&c}
cands := []*artifactselector.Candidate{&c}
for _, r := range rm.rules {
if r.Disabled {
continue
}
// match repositories according to the repository selectors
var repositoryCandidates []*art.Candidate
var repositoryCandidates []*artifactselector.Candidate
repositorySelectors := r.ScopeSelectors["repository"]
if len(repositorySelectors) < 1 {
continue
@ -46,7 +46,7 @@ func (rm *Matcher) Match(pid int64, c art.Candidate) (bool, error) {
}
// match tag according to the tag selectors
var tagCandidates []*art.Candidate
var tagCandidates []*artifactselector.Candidate
tagSelectors := r.TagSelectors
if len(tagSelectors) < 0 {
continue

View File

@ -2,7 +2,7 @@ package rule
import (
"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/model"
"github.com/stretchr/testify/assert"
@ -87,7 +87,7 @@ func (s *MatchTestSuite) TestImmuMatch() {
match := NewRuleMatcher()
c1 := art.Candidate{
c1 := artifactselector.Candidate{
NamespaceID: 1,
Namespace: "library",
Repository: "redis",
@ -97,34 +97,34 @@ func (s *MatchTestSuite) TestImmuMatch() {
s.require.Equal(isMatch, true)
s.require.Nil(err)
c2 := art.Candidate{
c2 := artifactselector.Candidate{
NamespaceID: 1,
Namespace: "library",
Repository: "redis",
Tags: []string{"1.10"},
Kind: art.Image,
Kind: artifactselector.Image,
}
isMatch, err = match.Match(1, c2)
s.require.Equal(isMatch, false)
s.require.Nil(err)
c3 := art.Candidate{
c3 := artifactselector.Candidate{
NamespaceID: 1,
Namespace: "immutable",
Repository: "mysql",
Tags: []string{"9.4.8"},
Kind: art.Image,
Kind: artifactselector.Image,
}
isMatch, err = match.Match(1, c3)
s.require.Equal(isMatch, true)
s.require.Nil(err)
c4 := art.Candidate{
c4 := artifactselector.Candidate{
NamespaceID: 1,
Namespace: "immutable",
Repository: "hello",
Tags: []string{"world"},
Kind: art.Image,
Kind: artifactselector.Image,
}
isMatch, err = match.Match(1, c4)
s.require.Equal(isMatch, false)

View File

@ -17,12 +17,12 @@ package dep
import (
"errors"
"fmt"
"github.com/goharbor/harbor/src/pkg/artifactselector"
"net/http"
"time"
"github.com/goharbor/harbor/src/common/http/modifier/auth"
"github.com/goharbor/harbor/src/jobservice/config"
"github.com/goharbor/harbor/src/pkg/art"
"github.com/goharbor/harbor/src/pkg/clients/core"
)
@ -39,7 +39,7 @@ type Client interface {
// Returns:
// []*art.Candidate : candidates returned
// 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
//
@ -48,7 +48,7 @@ type Client interface {
//
// Returns:
// error : common error if any errors occurred
DeleteRepository(repo *art.Repository) error
DeleteRepository(repo *artifactselector.Repository) error
// Delete the specified candidate
//
@ -57,7 +57,7 @@ type Client interface {
//
// Returns:
// error : common error if any errors occurred
Delete(candidate *art.Candidate) error
Delete(candidate *artifactselector.Candidate) error
}
// NewClient new a basic client
@ -89,29 +89,29 @@ type basicClient struct {
}
// 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 {
return nil, errors.New("repository is nil")
}
candidates := make([]*art.Candidate, 0)
candidates := make([]*artifactselector.Candidate, 0)
switch repository.Kind {
case art.Image:
case artifactselector.Image:
artifacts, err := bc.coreClient.ListAllArtifacts(repository.Namespace, repository.Name)
if err != nil {
return nil, err
}
for _, artifact := range artifacts {
if artifact.Digest == "" {
for _, art := range artifacts {
if art.Digest == "" {
return nil, fmt.Errorf("Lack Digest of Candidate for %s/%s", repository.Namespace, repository.Name)
}
labels := make([]string, 0)
for _, label := range artifact.Labels {
for _, label := range art.Labels {
labels = append(labels, label.Name)
}
tags := make([]string, 0)
var lastPulledTime time.Time
var lastPushedTime time.Time
for _, t := range artifact.Tags {
for _, t := range art.Tags {
tags = append(tags, t.Name)
if t.PullTime.After(lastPulledTime) {
lastPulledTime = t.PullTime
@ -120,15 +120,15 @@ func (bc *basicClient) GetCandidates(repository *art.Repository) ([]*art.Candida
lastPushedTime = t.PushTime
}
}
candidate := &art.Candidate{
Kind: art.Image,
candidate := &artifactselector.Candidate{
Kind: artifactselector.Image,
NamespaceID: repository.NamespaceID,
Namespace: repository.Namespace,
Repository: repository.Name,
Tags: tags,
Digest: artifact.Digest,
Digest: art.Digest,
Labels: labels,
CreationTime: artifact.PushTime.Unix(),
CreationTime: art.PushTime.Unix(),
PulledTime: lastPulledTime.Unix(),
PushedTime: lastPushedTime.Unix(),
}
@ -165,12 +165,12 @@ func (bc *basicClient) GetCandidates(repository *art.Repository) ([]*art.Candida
}
// DeleteRepository deletes the specified repository
func (bc *basicClient) DeleteRepository(repo *art.Repository) error {
func (bc *basicClient) DeleteRepository(repo *artifactselector.Repository) error {
if repo == nil {
return errors.New("repository is nil")
}
switch repo.Kind {
case art.Image:
case artifactselector.Image:
return bc.coreClient.DeleteArtifactRepository(repo.Namespace, repo.Name)
/*
case art.Chart:
@ -182,12 +182,12 @@ func (bc *basicClient) DeleteRepository(repo *art.Repository) error {
}
// Deletes the specified candidate
func (bc *basicClient) Delete(candidate *art.Candidate) error {
func (bc *basicClient) Delete(candidate *artifactselector.Candidate) error {
if candidate == nil {
return errors.New("candidate is nil")
}
switch candidate.Kind {
case art.Image:
case artifactselector.Image:
return bc.coreClient.DeleteArtifact(candidate.Namespace, candidate.Repository, candidate.Digest)
/*
case art.Chart:

View File

@ -17,13 +17,13 @@ package dep
import (
modelsv2 "github.com/goharbor/harbor/src/api/artifact"
"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"
"testing"
"github.com/goharbor/harbor/src/chartserver"
jmodels "github.com/goharbor/harbor/src/common/job/models"
"github.com/goharbor/harbor/src/jobservice/job"
"github.com/goharbor/harbor/src/pkg/art"
"github.com/goharbor/harbor/src/testing/clients"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@ -82,20 +82,20 @@ type clientTestSuite struct {
func (c *clientTestSuite) TestGetCandidates() {
client := &basicClient{}
client.coreClient = &fakeCoreClient{}
var repository *art.Repository
var repository *artifactselector.Repository
// nil repository
candidates, err := client.GetCandidates(repository)
require.NotNil(c.T(), err)
// image repository
repository = &art.Repository{}
repository.Kind = art.Image
repository = &artifactselector.Repository{}
repository.Kind = artifactselector.Image
repository.Namespace = "library"
repository.Name = "hello-world"
candidates, err = client.GetCandidates(repository)
require.Nil(c.T(), err)
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(), "hello-world", candidates[0].Repository)
assert.Equal(c.T(), "latest", candidates[0].Tags[0])
@ -118,14 +118,14 @@ func (c *clientTestSuite) TestDelete() {
client := &basicClient{}
client.coreClient = &fakeCoreClient{}
var candidate *art.Candidate
var candidate *artifactselector.Candidate
// nil candidate
err := client.Delete(candidate)
require.NotNil(c.T(), err)
// image
candidate = &art.Candidate{}
candidate.Kind = art.Image
candidate = &artifactselector.Candidate{}
candidate.Kind = artifactselector.Image
err = client.Delete(candidate)
require.Nil(c.T(), err)

View File

@ -18,12 +18,12 @@ import (
"bytes"
"encoding/json"
"fmt"
"github.com/goharbor/harbor/src/pkg/artifactselector"
"strings"
"time"
"github.com/goharbor/harbor/src/jobservice/job"
"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/policy"
"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)
}
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
for _, r := range results {
if r.Error == nil {
@ -139,7 +139,7 @@ func saveRetainNum(ctx job.Context, results []*art.Result, allCandidates []*art.
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))
for _, r := range results {
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 != nil {
if _, ok := e.(*art.ImmutableError); ok {
if _, ok := e.(*artifactselector.ImmutableError); ok {
return actionMarkImmutable
}
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)
}
@ -241,7 +241,7 @@ func getParamDryRun(params job.Parameters) (bool, error) {
return dryRun, nil
}
func getParamRepo(params job.Parameters) (*art.Repository, error) {
func getParamRepo(params job.Parameters) (*artifactselector.Repository, error) {
v, ok := params[ParamRepo]
if !ok {
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)
}
repo := &art.Repository{}
repo := &artifactselector.Repository{}
if err := repo.FromJSON(repoJSON); err != nil {
return nil, errors.Wrap(err, "parse repository from JSON")
}

View File

@ -17,13 +17,13 @@ package retention
import (
"context"
"fmt"
"github.com/goharbor/harbor/src/pkg/artifactselector"
"testing"
"time"
"github.com/goharbor/harbor/src/jobservice/job"
"github.com/goharbor/harbor/src/jobservice/logger"
"github.com/goharbor/harbor/src/pkg/art"
"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/dep"
"github.com/goharbor/harbor/src/pkg/retention/policy"
"github.com/goharbor/harbor/src/pkg/retention/policy/action"
@ -60,10 +60,10 @@ func (suite *JobTestSuite) TearDownSuite() {
func (suite *JobTestSuite) TestRunSuccess() {
params := make(job.Parameters)
params[ParamDryRun] = false
repository := &art.Repository{
repository := &artifactselector.Repository{
Namespace: "library",
Name: "harbor",
Kind: art.Image,
Kind: artifactselector.Image,
}
repoJSON, err := repository.ToJSON()
require.Nil(suite.T(), err)
@ -112,8 +112,8 @@ func (suite *JobTestSuite) TestRunSuccess() {
type fakeRetentionClient struct{}
// GetCandidates ...
func (frc *fakeRetentionClient) GetCandidates(repo *art.Repository) ([]*art.Candidate, error) {
return []*art.Candidate{
func (frc *fakeRetentionClient) GetCandidates(repo *artifactselector.Repository) ([]*artifactselector.Candidate, error) {
return []*artifactselector.Candidate{
{
Namespace: "library",
Repository: "harbor",
@ -140,12 +140,12 @@ func (frc *fakeRetentionClient) GetCandidates(repo *art.Repository) ([]*art.Cand
}
// Delete ...
func (frc *fakeRetentionClient) Delete(candidate *art.Candidate) error {
func (frc *fakeRetentionClient) Delete(candidate *artifactselector.Candidate) error {
return nil
}
// SubmitTask ...
func (frc *fakeRetentionClient) DeleteRepository(repo *art.Repository) error {
func (frc *fakeRetentionClient) DeleteRepository(repo *artifactselector.Repository) error {
return nil
}

View File

@ -18,10 +18,11 @@ import (
"fmt"
beegoorm "github.com/astaxie/beego/orm"
"github.com/goharbor/harbor/src/internal/orm"
"github.com/goharbor/harbor/src/pkg/artifactselector"
"time"
"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"
"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/log"
"github.com/goharbor/harbor/src/core/config"
"github.com/goharbor/harbor/src/pkg/art"
"github.com/goharbor/harbor/src/pkg/project"
pq "github.com/goharbor/harbor/src/pkg/q"
"github.com/goharbor/harbor/src/pkg/repository"
@ -87,7 +87,7 @@ func NewLauncher(projectMgr project.Manager, repositoryMgr repository.Manager,
type jobData struct {
TaskID int64
Repository art.Repository
Repository artifactselector.Repository
JobName string
JobParams map[string]interface{}
}
@ -114,9 +114,9 @@ func (l *launcher) Launch(ply *policy.Metadata, executionID int64, isDryRun bool
if scope == 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
var allProjects []*art.Candidate
var allProjects []*artifactselector.Candidate
var err error
if level == "system" {
// get projects
@ -147,12 +147,12 @@ func (l *launcher) Launch(ply *policy.Metadata, executionID int64, isDryRun bool
}
}
case "project":
projectCandidates = append(projectCandidates, &art.Candidate{
projectCandidates = append(projectCandidates, &artifactselector.Candidate{
NamespaceID: scope.Reference,
})
}
var repositoryCandidates []*art.Candidate
var repositoryCandidates []*artifactselector.Candidate
// get repositories of projects
for _, projectCandidate := range projectCandidates {
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 {
reposit := art.Repository{
reposit := artifactselector.Repository{
NamespaceID: repositoryCandidate.NamespaceID,
Namespace: repositoryCandidate.Namespace,
Name: repositoryCandidate.Repository,
@ -218,7 +218,7 @@ func (l *launcher) Launch(ply *policy.Metadata, executionID int64, isDryRun bool
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{}
for repository, policy := range repositoryRules {
jobData := &jobData{
@ -324,14 +324,14 @@ func launcherError(err error) error {
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()
if err != nil {
return nil, err
}
var candidates []*art.Candidate
var candidates []*artifactselector.Candidate
for _, pro := range projects {
candidates = append(candidates, &art.Candidate{
candidates = append(candidates, &artifactselector.Candidate{
NamespaceID: pro.ProjectID,
Namespace: pro.Name,
})
@ -340,8 +340,8 @@ func getProjects(projectMgr project.Manager) ([]*art.Candidate, error) {
}
func getRepositories(projectMgr project.Manager, repositoryMgr repository.Manager,
projectID int64, chartServerEnabled bool) ([]*art.Candidate, error) {
var candidates []*art.Candidate
projectID int64, chartServerEnabled bool) ([]*artifactselector.Candidate, error) {
var candidates []*artifactselector.Candidate
/*
pro, err := projectMgr.Get(projectID)
if err != nil {
@ -360,7 +360,7 @@ func getRepositories(projectMgr project.Manager, repositoryMgr repository.Manage
}
for _, r := range imageRepositories {
namespace, repo := utils.ParseRepository(r.Name)
candidates = append(candidates, &art.Candidate{
candidates = append(candidates, &artifactselector.Candidate{
NamespaceID: projectID,
Namespace: namespace,
Repository: repo,

View File

@ -18,7 +18,7 @@ import (
"fmt"
"github.com/goharbor/harbor/src/common/job"
"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/retention/policy"
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"

View File

@ -15,10 +15,10 @@
package index
import (
"github.com/goharbor/harbor/src/pkg/artifactselector"
"testing"
"time"
"github.com/goharbor/harbor/src/pkg/art"
"github.com/goharbor/harbor/src/pkg/retention/policy/action"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@ -29,7 +29,7 @@ import (
type IndexTestSuite struct {
suite.Suite
candidates []*art.Candidate
candidates []*artifactselector.Candidate
}
// TestIndexEntry is entry of IndexTestSuite
@ -41,7 +41,7 @@ func TestIndexEntry(t *testing.T) {
func (suite *IndexTestSuite) SetupSuite() {
Register("fakeAction", newFakePerformer)
suite.candidates = []*art.Candidate{{
suite.candidates = []*artifactselector.Candidate{{
Namespace: "library",
Repository: "harbor",
Kind: "image",
@ -77,9 +77,9 @@ type fakePerformer struct {
}
// 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 {
results = append(results, &art.Result{
results = append(results, &artifactselector.Result{
Target: c,
})
}

View File

@ -17,7 +17,7 @@ package action
import (
"github.com/goharbor/harbor/src/common/utils"
"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/retention/dep"
)
@ -37,7 +37,7 @@ type Performer interface {
// Returns:
// []*art.Result : result infos
// 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
@ -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
type retainAction struct {
all []*art.Candidate
all []*artifactselector.Candidate
// Indicate if it is a dry run
isDryRun bool
}
// 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)
immutableShare := make(map[string]bool)
for _, c := range candidates {
@ -71,11 +71,11 @@ func (ra *retainAction) Perform(candidates []*art.Candidate) (results []*art.Res
if len(ra.all) > 0 {
for _, c := range ra.all {
if _, ok := retainedShare[c.Hash()]; !ok {
result := &art.Result{
result := &artifactselector.Result{
Target: c,
}
if _, ok = immutableShare[c.Hash()]; ok {
result.Error = &art.ImmutableError{}
result.Error = &artifactselector.ImmutableError{}
} else {
if !ra.isDryRun {
if err := dep.DefaultClient.Delete(c); err != nil {
@ -91,11 +91,11 @@ func (ra *retainAction) Perform(candidates []*art.Candidate) (results []*art.Res
return
}
func isImmutable(c *art.Candidate) bool {
func isImmutable(c *artifactselector.Candidate) bool {
projectID := c.NamespaceID
repo := c.Repository
_, repoName := utils.ParseRepository(repo)
matched, err := rule.NewRuleMatcher().Match(projectID, art.Candidate{
matched, err := rule.NewRuleMatcher().Match(projectID, artifactselector.Candidate{
Repository: repoName,
Tags: c.Tags,
NamespaceID: projectID,
@ -110,7 +110,7 @@ func isImmutable(c *art.Candidate) bool {
// NewRetainAction is factory method for RetainAction
func NewRetainAction(params interface{}, isDryRun bool) Performer {
if params != nil {
if all, ok := params.([]*art.Candidate); ok {
if all, ok := params.([]*artifactselector.Candidate); ok {
return &retainAction{
all: all,
isDryRun: isDryRun,
@ -119,7 +119,7 @@ func NewRetainAction(params interface{}, isDryRun bool) Performer {
}
return &retainAction{
all: make([]*art.Candidate, 0),
all: make([]*artifactselector.Candidate, 0),
isDryRun: isDryRun,
}
}

View File

@ -16,11 +16,11 @@ package action
import (
"github.com/goharbor/harbor/src/common/dao"
"github.com/goharbor/harbor/src/pkg/artifactselector"
"github.com/goharbor/harbor/src/pkg/immutabletag"
"testing"
"time"
"github.com/goharbor/harbor/src/pkg/art"
immumodel "github.com/goharbor/harbor/src/pkg/immutabletag/model"
"github.com/goharbor/harbor/src/pkg/retention/dep"
"github.com/pkg/errors"
@ -34,7 +34,7 @@ type TestPerformerSuite struct {
suite.Suite
oldClient dep.Client
all []*art.Candidate
all []*artifactselector.Candidate
}
// TestPerformer is the entry of the TestPerformerSuite
@ -44,7 +44,7 @@ func TestPerformer(t *testing.T) {
// SetupSuite ...
func (suite *TestPerformerSuite) SetupSuite() {
suite.all = []*art.Candidate{
suite.all = []*artifactselector.Candidate{
{
Namespace: "library",
Repository: "harbor",
@ -81,7 +81,7 @@ func (suite *TestPerformerSuite) TestPerform() {
all: suite.all,
}
candidates := []*art.Candidate{
candidates := []*artifactselector.Candidate{
{
Namespace: "library",
Repository: "harbor",
@ -103,7 +103,7 @@ func (suite *TestPerformerSuite) TestPerform() {
// TestPerform tests Perform action
func (suite *TestPerformerSuite) TestPerformImmutable() {
all := []*art.Candidate{
all := []*artifactselector.Candidate{
{
NamespaceID: 1,
Namespace: "library",
@ -177,7 +177,7 @@ func (suite *TestPerformerSuite) TestPerformImmutable() {
assert.NoError(suite.T(), immutabletag.ImmuCtr.DeleteImmutableRule(imid))
}()
candidates := []*art.Candidate{
candidates := []*artifactselector.Candidate{
{
NamespaceID: 1,
Namespace: "library",
@ -200,7 +200,7 @@ func (suite *TestPerformerSuite) TestPerformImmutable() {
require.Equal(suite.T(), "dev", r.Target.Tags[0])
} else if r.Target.Digest == "d2" {
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 {
require.Fail(suite.T(), "should not delete "+r.Target.Hash())
}
@ -213,16 +213,16 @@ func (suite *TestPerformerSuite) TestPerformImmutable() {
type fakeRetentionClient struct{}
// 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")
}
// Delete ...
func (frc *fakeRetentionClient) Delete(candidate *art.Candidate) error {
func (frc *fakeRetentionClient) Delete(candidate *artifactselector.Candidate) error {
return nil
}
// DeleteRepository ...
func (frc *fakeRetentionClient) DeleteRepository(repo *art.Repository) error {
func (frc *fakeRetentionClient) DeleteRepository(repo *artifactselector.Repository) error {
panic("implement me")
}

View File

@ -15,10 +15,10 @@
package or
import (
"github.com/goharbor/harbor/src/pkg/artifactselector"
"sync"
"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/alg"
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
@ -29,7 +29,7 @@ import (
type processor struct {
// keep evaluator and its related selector if existing
// 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
performers map[string]action.Performer
}
@ -37,7 +37,7 @@ type processor struct {
// New processor
func New(parameters []*alg.Parameter) alg.Processor {
p := &processor{
evaluators: make(map[*rule.Evaluator][]art.Selector),
evaluators: make(map[*rule.Evaluator][]artifactselector.Selector),
performers: make(map[string]action.Performer),
}
@ -59,10 +59,10 @@ func New(parameters []*alg.Parameter) alg.Processor {
}
// 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 {
log.Debug("no artifacts to retention")
return make([]*art.Result, 0), nil
return make([]*artifactselector.Result, 0), nil
}
var (
@ -75,7 +75,7 @@ func (p *processor) Process(artifacts []*art.Candidate) ([]*art.Result, error) {
// for sync
type chanItem struct {
action string
processed []*art.Candidate
processed []*artifactselector.Candidate
}
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 {
var evaluator = *eva
go func(evaluator rule.Evaluator, selectors []art.Selector) {
go func(evaluator rule.Evaluator, selectors []artifactselector.Selector) {
var (
processed []*art.Candidate
processed []*artifactselector.Candidate
err error
)
@ -173,7 +173,7 @@ func (p *processor) Process(artifacts []*art.Candidate) ([]*art.Result, error) {
return nil, err
}
results := make([]*art.Result, 0)
results := make([]*artifactselector.Result, 0)
// Perform actions
for act, hash := range processedCandidates {
var attachedErr error
@ -192,7 +192,7 @@ func (p *processor) Process(artifacts []*art.Candidate) ([]*art.Result, error) {
if attachedErr != nil {
for _, c := range cl {
results = append(results, &art.Result{
results = append(results, &artifactselector.Result{
Target: c,
Error: attachedErr,
})
@ -203,10 +203,10 @@ func (p *processor) Process(artifacts []*art.Candidate) ([]*art.Result, error) {
return results, nil
}
type cHash map[string]*art.Candidate
type cHash map[string]*artifactselector.Candidate
func (ch cHash) toList() []*art.Candidate {
l := make([]*art.Candidate, 0)
func (ch cHash) toList() []*artifactselector.Candidate {
l := make([]*artifactselector.Candidate, 0)
for _, v := range ch {
l = append(l, v)

View File

@ -17,12 +17,12 @@ package or
import (
"errors"
"github.com/goharbor/harbor/src/common/dao"
"github.com/goharbor/harbor/src/pkg/artifactselector"
"testing"
"time"
"github.com/goharbor/harbor/src/pkg/art"
"github.com/goharbor/harbor/src/pkg/art/selectors/doublestar"
"github.com/goharbor/harbor/src/pkg/art/selectors/label"
"github.com/goharbor/harbor/src/pkg/artifactselector/selectors/doublestar"
"github.com/goharbor/harbor/src/pkg/artifactselector/selectors/label"
"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/alg"
@ -39,7 +39,7 @@ import (
type ProcessorTestSuite struct {
suite.Suite
all []*art.Candidate
all []*artifactselector.Candidate
oldClient dep.Client
}
@ -52,7 +52,7 @@ func TestProcessor(t *testing.T) {
// SetupSuite ...
func (suite *ProcessorTestSuite) SetupSuite() {
dao.PrepareTestForPostgresSQL()
suite.all = []*art.Candidate{
suite.all = []*artifactselector.Candidate{
{
Namespace: "library",
Repository: "harbor",
@ -92,7 +92,7 @@ func (suite *ProcessorTestSuite) TestProcess() {
lastxParams[lastx.ParameterX] = 10
params = append(params, &alg.Parameter{
Evaluator: lastx.New(lastxParams),
Selectors: []art.Selector{
Selectors: []artifactselector.Selector{
doublestar.New(doublestar.Matches, "*dev*"),
label.New(label.With, "L1,L2"),
},
@ -103,7 +103,7 @@ func (suite *ProcessorTestSuite) TestProcess() {
latestKParams[latestps.ParameterK] = 10
params = append(params, &alg.Parameter{
Evaluator: latestps.New(latestKParams),
Selectors: []art.Selector{
Selectors: []artifactselector.Selector{
label.New(label.With, "L3"),
},
Performer: perf,
@ -133,7 +133,7 @@ func (suite *ProcessorTestSuite) TestProcess2() {
alwaysParams := make(map[string]rule.Parameter)
params = append(params, &alg.Parameter{
Evaluator: always.New(alwaysParams),
Selectors: []art.Selector{
Selectors: []artifactselector.Selector{
doublestar.New(doublestar.Matches, "latest"),
label.New(label.With, ""),
},
@ -165,16 +165,16 @@ func (suite *ProcessorTestSuite) TestProcess2() {
type fakeRetentionClient struct{}
// 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")
}
// Delete ...
func (frc *fakeRetentionClient) Delete(candidate *art.Candidate) error {
func (frc *fakeRetentionClient) Delete(candidate *artifactselector.Candidate) error {
return nil
}
// DeleteRepository ...
func (frc *fakeRetentionClient) DeleteRepository(repo *art.Repository) error {
func (frc *fakeRetentionClient) DeleteRepository(repo *artifactselector.Repository) error {
panic("implement me")
}

View File

@ -15,7 +15,7 @@
package alg
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/rule"
)
@ -32,7 +32,7 @@ type Processor interface {
// Returns:
// []*art.Result : the processed results
// 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
@ -42,7 +42,7 @@ type Parameter struct {
Evaluator rule.Evaluator
// Selectors for the rule
Selectors []art.Selector
Selectors []artifactselector.Selector
// Performer for the rule evaluator
Performer action.Performer

View File

@ -16,16 +16,16 @@ package policy
import (
"fmt"
"github.com/goharbor/harbor/src/pkg/artifactselector"
index4 "github.com/goharbor/harbor/src/pkg/retention/policy/action/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/art"
"github.com/goharbor/harbor/src/pkg/retention/policy/alg"
"github.com/goharbor/harbor/src/pkg/retention/policy/lwp"
"github.com/pkg/errors"
@ -46,7 +46,7 @@ type Builder interface {
}
// NewBuilder news a basic builder
func NewBuilder(all []*art.Candidate) Builder {
func NewBuilder(all []*artifactselector.Candidate) Builder {
return &basicBuilder{
allCandidates: all,
}
@ -54,7 +54,7 @@ func NewBuilder(all []*art.Candidate) Builder {
// basicBuilder is default implementation of Builder interface
type basicBuilder struct {
allCandidates []*art.Candidate
allCandidates []*artifactselector.Candidate
}
// 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")
}
sl := make([]art.Selector, 0)
sl := make([]artifactselector.Selector, 0)
for _, s := range r.TagSelectors {
sel, err := index2.Get(s.Kind, s.Decoration, s.Pattern)
if err != nil {

View File

@ -16,6 +16,7 @@ package policy
import (
"github.com/goharbor/harbor/src/common/dao"
"github.com/goharbor/harbor/src/pkg/artifactselector"
"testing"
"time"
@ -23,7 +24,7 @@ import (
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"
@ -31,9 +32,9 @@ import (
"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"
@ -47,8 +48,6 @@ import (
"github.com/goharbor/harbor/src/pkg/retention/policy/lwp"
"github.com/goharbor/harbor/src/pkg/art"
"github.com/stretchr/testify/suite"
)
@ -56,7 +55,7 @@ import (
type TestBuilderSuite struct {
suite.Suite
all []*art.Candidate
all []*artifactselector.Candidate
oldClient dep.Client
}
@ -68,7 +67,7 @@ func TestBuilder(t *testing.T) {
// SetupSuite prepares the testing content if needed
func (suite *TestBuilderSuite) SetupSuite() {
dao.PrepareTestForPostgresSQL()
suite.all = []*art.Candidate{
suite.all = []*artifactselector.Candidate{
{
NamespaceID: 1,
Namespace: "library",
@ -165,21 +164,21 @@ func (suite *TestBuilderSuite) TestBuild() {
type fakeRetentionClient struct{}
func (frc *fakeRetentionClient) DeleteRepository(repo *art.Repository) error {
func (frc *fakeRetentionClient) DeleteRepository(repo *artifactselector.Repository) error {
panic("implement me")
}
// 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")
}
// Delete ...
func (frc *fakeRetentionClient) Delete(candidate *art.Candidate) error {
func (frc *fakeRetentionClient) Delete(candidate *artifactselector.Candidate) error {
return nil
}
// 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")
}

View File

@ -15,7 +15,7 @@
package always
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/rule"
)
@ -28,7 +28,7 @@ const (
type evaluator struct{}
// 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
}

View File

@ -15,9 +15,9 @@
package always
import (
"github.com/goharbor/harbor/src/pkg/artifactselector"
"testing"
"github.com/goharbor/harbor/src/pkg/art"
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
@ -36,7 +36,7 @@ func (e *EvaluatorTestSuite) TestNew() {
func (e *EvaluatorTestSuite) TestProcess() {
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)

View File

@ -17,10 +17,10 @@ package dayspl
import (
"fmt"
"github.com/goharbor/harbor/src/common/utils"
"github.com/goharbor/harbor/src/pkg/artifactselector"
"time"
"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/rule"
)
@ -41,7 +41,7 @@ type evaluator struct {
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()
for _, a := range artifacts {
if a.PulledTime >= minPullTime {

View File

@ -17,11 +17,11 @@ package dayspl
import (
"errors"
"fmt"
"github.com/goharbor/harbor/src/pkg/artifactselector"
"github.com/stretchr/testify/assert"
"testing"
"time"
"github.com/goharbor/harbor/src/pkg/art"
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
@ -54,7 +54,7 @@ func (e *EvaluatorTestSuite) TestNew() {
func (e *EvaluatorTestSuite) TestProcess() {
now := time.Now().UTC()
data := []*art.Candidate{
data := []*artifactselector.Candidate{
{PulledTime: daysAgo(now, 1, time.Hour)},
{PulledTime: daysAgo(now, 2, time.Hour)},
{PulledTime: daysAgo(now, 3, time.Hour)},

View File

@ -17,10 +17,10 @@ package daysps
import (
"fmt"
"github.com/goharbor/harbor/src/common/utils"
"github.com/goharbor/harbor/src/pkg/artifactselector"
"time"
"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/rule"
)
@ -41,7 +41,7 @@ type evaluator struct {
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()
for _, a := range artifacts {
if a.PushedTime >= minPushTime {

View File

@ -17,10 +17,10 @@ package daysps
import (
"errors"
"fmt"
"github.com/goharbor/harbor/src/pkg/artifactselector"
"testing"
"time"
"github.com/goharbor/harbor/src/pkg/art"
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@ -54,7 +54,7 @@ func (e *EvaluatorTestSuite) TestNew() {
func (e *EvaluatorTestSuite) TestProcess() {
now := time.Now().UTC()
data := []*art.Candidate{
data := []*artifactselector.Candidate{
{PushedTime: daysAgo(now, 1, time.Hour)},
{PushedTime: daysAgo(now, 2, time.Hour)},
{PushedTime: daysAgo(now, 3, time.Hour)},

View File

@ -14,7 +14,9 @@
package rule
import "github.com/goharbor/harbor/src/pkg/art"
import (
"github.com/goharbor/harbor/src/pkg/artifactselector"
)
// Evaluator defines method of executing rule
type Evaluator interface {
@ -26,7 +28,7 @@ type Evaluator interface {
// Returns:
// []*art.Candidate : matched candidates for next stage
// 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
Action() string

View File

@ -15,6 +15,7 @@
package index
import (
"github.com/goharbor/harbor/src/pkg/artifactselector"
"testing"
"time"
@ -22,7 +23,6 @@ import (
"github.com/stretchr/testify/require"
"github.com/goharbor/harbor/src/pkg/art"
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
"github.com/stretchr/testify/suite"
@ -63,7 +63,7 @@ func (suite *IndexTestSuite) TestGet() {
require.NoError(suite.T(), err)
require.NotNil(suite.T(), evaluator)
candidates := []*art.Candidate{{
candidates := []*artifactselector.Candidate{{
Namespace: "library",
Repository: "harbor",
Kind: "image",
@ -102,7 +102,7 @@ type fakeEvaluator struct {
}
// 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
}

View File

@ -16,10 +16,10 @@ package lastx
import (
"github.com/goharbor/harbor/src/common/utils"
"github.com/goharbor/harbor/src/pkg/artifactselector"
"time"
"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/rule"
)
@ -40,7 +40,7 @@ type evaluator struct {
}
// 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)
for _, a := range artifacts {
if time.Unix(a.PushedTime, 0).UTC().After(cutoff) {

View File

@ -2,10 +2,10 @@ package lastx
import (
"fmt"
"github.com/goharbor/harbor/src/pkg/artifactselector"
"testing"
"time"
"github.com/goharbor/harbor/src/pkg/art"
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
@ -38,7 +38,7 @@ func (e *EvaluatorTestSuite) TestNew() {
func (e *EvaluatorTestSuite) TestProcess() {
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(2*-24) * time.Hour).Unix()},
{PushedTime: now.Add(time.Duration(3*-24) * time.Hour).Unix()},

View File

@ -16,10 +16,10 @@ package latestk
import (
"github.com/goharbor/harbor/src/common/utils"
"github.com/goharbor/harbor/src/pkg/artifactselector"
"sort"
"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/rule"
)
@ -40,7 +40,7 @@ type evaluator struct {
}
// 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"
//
// 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 {
return c.PulledTime
}

View File

@ -16,24 +16,24 @@ package latestk
import (
"fmt"
"github.com/goharbor/harbor/src/pkg/artifactselector"
"testing"
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/goharbor/harbor/src/pkg/art"
"github.com/stretchr/testify/suite"
)
type EvaluatorTestSuite struct {
suite.Suite
artifacts []*art.Candidate
artifacts []*artifactselector.Candidate
}
func (e *EvaluatorTestSuite) SetupSuite() {
e.artifacts = []*art.Candidate{
e.artifacts = []*artifactselector.Candidate{
{PulledTime: 1, PushedTime: 2},
{PulledTime: 3, PushedTime: 4},
{PulledTime: 6, PushedTime: 5},

View File

@ -17,11 +17,11 @@ package latestpl
import (
"fmt"
"github.com/goharbor/harbor/src/common/utils"
"github.com/goharbor/harbor/src/pkg/artifactselector"
"math"
"sort"
"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/rule"
)
@ -41,7 +41,7 @@ type evaluator struct {
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 {
return artifacts[i].PulledTime > artifacts[j].PulledTime
})

View File

@ -17,10 +17,10 @@ package latestpl
import (
"errors"
"fmt"
"github.com/goharbor/harbor/src/pkg/artifactselector"
"math/rand"
"testing"
"github.com/goharbor/harbor/src/pkg/art"
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
@ -52,7 +52,7 @@ func (e *EvaluatorTestSuite) TestNew() {
}
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) {
data[i], data[j] = data[j], data[i]
})

View File

@ -17,11 +17,11 @@ package latestps
import (
"fmt"
"github.com/goharbor/harbor/src/common/utils"
"github.com/goharbor/harbor/src/pkg/artifactselector"
"math"
"sort"
"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/rule"
)
@ -42,7 +42,7 @@ type evaluator struct {
}
// 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
sort.Slice(artifacts, func(i, j int) bool {
return artifacts[i].PushedTime > artifacts[j].PushedTime

View File

@ -3,12 +3,12 @@ package latestps
import (
"errors"
"fmt"
"github.com/goharbor/harbor/src/pkg/artifactselector"
"math/rand"
"testing"
"github.com/stretchr/testify/suite"
"github.com/goharbor/harbor/src/pkg/art"
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
"github.com/stretchr/testify/require"
)
@ -39,7 +39,7 @@ func (e *EvaluatorTestSuite) TestNew() {
}
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) {
data[i], data[j] = data[j], data[i]
})

View File

@ -15,7 +15,7 @@
package nothing
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/rule"
)
@ -28,7 +28,7 @@ const (
type evaluator struct{}
// 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
}

View File

@ -15,9 +15,9 @@
package nothing
import (
"github.com/goharbor/harbor/src/pkg/artifactselector"
"testing"
"github.com/goharbor/harbor/src/pkg/art"
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
@ -36,7 +36,7 @@ func (e *EvaluatorTestSuite) TestNew() {
func (e *EvaluatorTestSuite) TestProcess() {
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)

View File

@ -15,9 +15,12 @@
package event
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/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/model"
"github.com/goharbor/harbor/src/pkg/q"
@ -28,7 +31,7 @@ import (
type scanCtlGetter func() scan.Controller
// 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.
type onDelImageHandler struct {
@ -44,8 +47,8 @@ func NewOnDelImageHandler() notifier.NotificationHandler {
scanCtl: func() scan.Controller {
return scan.DefaultController
},
artCtl: func() art.Controller {
return art.DefaultController
artCtl: func() artifact.Controller {
return artifact.Ctl
},
}
}
@ -67,10 +70,11 @@ func (o *onDelImageHandler) Handle(value interface{}) error {
Keywords: make(map[string]interface{}),
}
ctx := orm.NewContext(context.TODO(), bo.NewOrm())
for _, res := range evt.Resource {
// Check if it is safe to delete the reports.
query.Keywords["digest"] = res.Digest
l, err := o.artCtl().List(query)
l, err := o.artCtl().List(ctx, query, nil)
if err != nil {
// Just logged

View File

@ -1,7 +1,7 @@
package immutabletag
import (
"github.com/goharbor/harbor/src/pkg/art"
"github.com/goharbor/harbor/src/pkg/artifactselector"
"github.com/stretchr/testify/mock"
)
@ -11,7 +11,7 @@ type FakeMatcher struct {
}
// 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()
return args.Bool(0), args.Error(1)
}