forked from goharbor/harbor
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move retention types and interfaces to their own namespace
Signed-off-by: Nathan Lowe <public@nlowe.me>
- Loading branch information
Showing
3 changed files
with
131 additions
and
101 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |