Skip to content

Commit

Permalink
Move retention types and interfaces to their own namespace
Browse files Browse the repository at this point in the history
Signed-off-by: Nathan Lowe <public@nlowe.me>
  • Loading branch information
nlowe committed Feb 16, 2019
1 parent 03047af commit b382a86
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 101 deletions.
101 changes: 0 additions & 101 deletions src/common/models/retention.go

This file was deleted.

68 changes: 68 additions & 0 deletions src/common/retention/filter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright 2019 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 retention

import (
"time"

"github.com/goharbor/harbor/src/common/models"
)

// FilterAction denotes the action a filter has taken for a given tag record
type FilterAction uint

const (
// FilterActionKeep explicitly marks the tag as kept
FilterActionKeep FilterAction = iota

// FilterActionDelete explicitly marks the tag as deleted
FilterActionDelete

// FilterActionNoDecision passes the tag onto the next filter in the chain
FilterActionNoDecision
)

// FilterMetadata defines the metadata needed to construct various Filter instances
type FilterMetadata struct {
ID int64
// The type of the filter to construct
Type string
// Parameters used to construct the filter
Options map[string]interface{}
}

// TagRecord represents all pertinent metadata about a tag
type TagRecord struct {
Project *models.Project
Repository *models.RepoRecord

Name string
CreatedAt time.Time
LastPullAt time.Time
Labels []*models.Label
}

// Filter is a tag filter in a Retention Policy Filter Chain
type Filter interface {
// Process determines what to do for a given tag record
Process(tag *TagRecord) (FilterAction, error)

// InitializeFor re-initializes the filter for tags from the specified project and repository
//
// Filters that maintain per-project or per-repository tracking metadata should reset it when
// this method is called. Every call to `Process` will be for the same project and repo until
// `InitializeFor` is called again.
InitializeFor(project *models.Project, repo *models.RepoRecord)
}
63 changes: 63 additions & 0 deletions src/common/retention/policy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright 2019 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 retention

import "time"

// Scope identifies the scope of a specific retention policy
type Scope int

const (
// ScopeServer identifies a retention policy defined server-wide
ScopeServer Scope = iota

// ScopeProject identifies a retention policy defined for a specific project
ScopeProject

// ScopeRepository identifies a retention policy defined for a specific repository
ScopeRepository
)

// FallThroughAction determines what action the policy should take when a tag has not
// been explicitly kept nor explicitly deleted by all filters in the filter chain
type FallThroughAction int

const (
// KeepExtraTags indicates that tags which are not explicitly kept or deleted are implicitly kept
KeepExtraTags FallThroughAction = iota
// DeleteExtraTags indicates that tags which are not explicitly kept or deleted are implicitly deleted
DeleteExtraTags
)

// Policy contains an ordered slice of FilterMetadata used to construct filter chains
// during tag retention procession
type Policy struct {
ID int64
Name string
Enabled bool

Scope Scope
FallThroughAction FallThroughAction

ProjectID int64
RepositoryID int64

// When a filter chain is constructed for this policy, these filters will
// be chained together in the order they appear in the slice
Filters []*FilterMetadata

CreatedAt time.Time
UpdatedAt time.Time
}

0 comments on commit b382a86

Please sign in to comment.