Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions cmd/harbor/root/tag/retention/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,17 @@ within a project. Tag retention rules help in managing and controlling the lifec
of tags by defining rules for automatic cleanup and retention.

A user can only create up to 15 tag retention rules per project.`,
Example: ` harbor tag retention create # Create a new tag retention rule
harbor tag retention list # List all tag retention rules in the project
harbor tag retention delete # Delete a specific tag retention rules`,
Example: ` harbor tag retention create # Create a new tag retention rule
harbor tag retention list # List all tag retention rules in the project
harbor tag retention delete # Delete a specific tag retention rules
harbor tag retention tasks list # List retention execution tasks`,
}

cmd.AddCommand(
CreateRetentionCommand(),
ListRetentionRulesCommand(),
DeleteRetentionRuleCommand(),
TasksCommand(),
)
return cmd
}
23 changes: 23 additions & 0 deletions cmd/harbor/root/tag/retention/tasks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// 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 retention

import (
tasksub "github.com/goharbor/harbor-cli/cmd/harbor/root/tag/retention/tasks"
"github.com/spf13/cobra"
)

func TasksCommand() *cobra.Command {
return tasksub.TasksCommand()
}
30 changes: 30 additions & 0 deletions cmd/harbor/root/tag/retention/tasks/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// 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 retention

import "github.com/spf13/cobra"

func TasksCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "tasks",
Short: "Manage retention execution tasks",
Long: "List retention execution tasks",
}

cmd.AddCommand(
ListCommand(),
)

return cmd
}
95 changes: 95 additions & 0 deletions cmd/harbor/root/tag/retention/tasks/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// 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 retention

import (
"fmt"
"strconv"

"github.com/goharbor/harbor-cli/pkg/api"
"github.com/goharbor/harbor-cli/pkg/prompt"
"github.com/goharbor/harbor-cli/pkg/utils"
taskview "github.com/goharbor/harbor-cli/pkg/views/retention/tasks"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

func ListCommand() *cobra.Command {
var projectName string
var projectID int
var executionID int64

cmd := &cobra.Command{
Use: "list [PROJECT_NAME]",
Short: "List retention tasks for an execution",
Long: "List repository-level retention tasks for a specific retention execution",
Args: cobra.MaximumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) > 0 {
projectName = args[0]
}

if projectID != -1 && projectName != "" {
return fmt.Errorf("cannot specify both --project-id and --project-name flags")
}

if projectID == -1 && projectName == "" {
name, err := prompt.GetProjectNameFromUser()
if err != nil {
return err
}
projectName = name
}

projectIDStr := projectName
isName := true
if projectID != -1 {
projectIDStr = strconv.Itoa(projectID)
isName = false
}

retentionID, err := api.GetRetentionId(projectIDStr, isName)
if err != nil {
return fmt.Errorf("failed to resolve retention policy: %w", err)
}

if executionID == -1 {
executionID = prompt.GetRetentionExecutionIDFromUser(retentionID)
}
if executionID == 0 {
fmt.Println("No retention executions found")
return nil
}

resp, err := api.ListRetentionTasks(retentionID, executionID)
if err != nil {
return fmt.Errorf("failed to list retention tasks: %w", err)
}

if viper.GetString("output-format") != "" {
utils.PrintPayloadInJSONFormat(resp.Payload)
return nil
}

taskview.ListRetentionTasks(resp.Payload)
return nil
},
}

cmd.Flags().StringVarP(&projectName, "project-name", "p", "", "Project name")
cmd.Flags().IntVarP(&projectID, "project-id", "i", -1, "Project ID")
cmd.Flags().Int64VarP(&executionID, "execution-id", "e", -1, "Retention execution ID")

return cmd
}
39 changes: 39 additions & 0 deletions doc/cli-docs/harbor-tag-retention-tasks-list.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
title: harbor tag retention tasks list
weight: 50
---
## harbor tag retention tasks list

### Description

##### List retention tasks for an execution

### Synopsis

List repository-level retention tasks for a specific retention execution

```sh
harbor tag retention tasks list [PROJECT_NAME] [flags]
```

### Options

```sh
-e, --execution-id int Retention execution ID (default -1)
-h, --help help for list
-i, --project-id int Project ID (default -1)
-p, --project-name string Project name
```

### Options inherited from parent commands

```sh
-c, --config string config file (default is $HOME/.config/harbor-cli/config.yaml)
-o, --output-format string Output format. One of: json|yaml|csv
-v, --verbose verbose output
```

### SEE ALSO

* [harbor tag retention tasks](harbor-tag-retention-tasks.md) - Manage retention execution tasks

33 changes: 33 additions & 0 deletions doc/cli-docs/harbor-tag-retention-tasks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
title: harbor tag retention tasks
weight: 70
---
## harbor tag retention tasks

### Description

##### Manage retention execution tasks

### Synopsis

List retention execution tasks

### Options

```sh
-h, --help help for tasks
```

### Options inherited from parent commands

```sh
-c, --config string config file (default is $HOME/.config/harbor-cli/config.yaml)
-o, --output-format string Output format. One of: json|yaml|csv
-v, --verbose verbose output
```

### SEE ALSO

* [harbor tag retention](harbor-tag-retention.md) - Manage tag retention rules in the project
* [harbor tag retention tasks list](harbor-tag-retention-tasks-list.md) - List retention tasks for an execution

8 changes: 5 additions & 3 deletions doc/cli-docs/harbor-tag-retention.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ A user can only create up to 15 tag retention rules per project.
### Examples

```sh
harbor tag retention create # Create a new tag retention rule
harbor tag retention list # List all tag retention rules in the project
harbor tag retention delete # Delete a specific tag retention rules
harbor tag retention create # Create a new tag retention rule
harbor tag retention list # List all tag retention rules in the project
harbor tag retention delete # Delete a specific tag retention rules
harbor tag retention tasks list # List retention execution tasks
```

### Options
Expand All @@ -46,4 +47,5 @@ A user can only create up to 15 tag retention rules per project.
* [harbor tag retention create](harbor-tag-retention-create.md) - Create a tag retention rule in a project
* [harbor tag retention delete](harbor-tag-retention-delete.md) - Delete a tag retention rule for a project
* [harbor tag retention list](harbor-tag-retention-list.md) - List tag retention rules of a project
* [harbor tag retention tasks](harbor-tag-retention-tasks.md) - Manage retention execution tasks

47 changes: 47 additions & 0 deletions doc/man-docs/man1/harbor-tag-retention-tasks-list.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
.nh
.TH "HARBOR" "1" "Harbor Community" "Harbor User Manuals"

.SH NAME
harbor-tag-retention-tasks-list - List retention tasks for an execution


.SH SYNOPSIS
\fBharbor tag retention tasks list [PROJECT_NAME] [flags]\fP


.SH DESCRIPTION
List repository-level retention tasks for a specific retention execution


.SH OPTIONS
\fB-e\fP, \fB--execution-id\fP=-1
Retention execution ID

.PP
\fB-h\fP, \fB--help\fP[=false]
help for list

.PP
\fB-i\fP, \fB--project-id\fP=-1
Project ID

.PP
\fB-p\fP, \fB--project-name\fP=""
Project name


.SH OPTIONS INHERITED FROM PARENT COMMANDS
\fB-c\fP, \fB--config\fP=""
config file (default is $HOME/.config/harbor-cli/config.yaml)

.PP
\fB-o\fP, \fB--output-format\fP=""
Output format. One of: json|yaml|csv

.PP
\fB-v\fP, \fB--verbose\fP[=false]
verbose output


.SH SEE ALSO
\fBharbor-tag-retention-tasks(1)\fP
35 changes: 35 additions & 0 deletions doc/man-docs/man1/harbor-tag-retention-tasks.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
.nh
.TH "HARBOR" "1" "Harbor Community" "Harbor User Manuals"

.SH NAME
harbor-tag-retention-tasks - Manage retention execution tasks


.SH SYNOPSIS
\fBharbor tag retention tasks [flags]\fP


.SH DESCRIPTION
List retention execution tasks


.SH OPTIONS
\fB-h\fP, \fB--help\fP[=false]
help for tasks


.SH OPTIONS INHERITED FROM PARENT COMMANDS
\fB-c\fP, \fB--config\fP=""
config file (default is $HOME/.config/harbor-cli/config.yaml)

.PP
\fB-o\fP, \fB--output-format\fP=""
Output format. One of: json|yaml|csv

.PP
\fB-v\fP, \fB--verbose\fP[=false]
verbose output


.SH SEE ALSO
\fBharbor-tag-retention(1)\fP, \fBharbor-tag-retention-tasks-list(1)\fP
9 changes: 5 additions & 4 deletions doc/man-docs/man1/harbor-tag-retention.1
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@ A user can only create up to 15 tag retention rules per project.

.SH EXAMPLE
.EX
harbor tag retention create # Create a new tag retention rule
harbor tag retention list # List all tag retention rules in the project
harbor tag retention delete # Delete a specific tag retention rules
harbor tag retention create # Create a new tag retention rule
harbor tag retention list # List all tag retention rules in the project
harbor tag retention delete # Delete a specific tag retention rules
harbor tag retention tasks list # List retention execution tasks
.EE


.SH SEE ALSO
\fBharbor-tag(1)\fP, \fBharbor-tag-retention-create(1)\fP, \fBharbor-tag-retention-delete(1)\fP, \fBharbor-tag-retention-list(1)\fP
\fBharbor-tag(1)\fP, \fBharbor-tag-retention-create(1)\fP, \fBharbor-tag-retention-delete(1)\fP, \fBharbor-tag-retention-list(1)\fP, \fBharbor-tag-retention-tasks(1)\fP
Loading