Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
f399f86
feat(preheat): preheat policy list command
Sypher845 May 5, 2026
af599e8
docs(preheat): docs for preheat policy list command
Sypher845 May 5, 2026
1a0837c
feat(preheat): preheat policy view command
Sypher845 May 7, 2026
ee7dd5a
docs(preheat): docs for preheat policy view command
Sypher845 May 7, 2026
f3811ab
feat(preheat): preheat policy delete command
Sypher845 May 8, 2026
e7b1ec4
docs(preheat): docs for preheat policy delete command
Sypher845 May 8, 2026
105258b
feat(preheat): preheat policy start command
Sypher845 May 8, 2026
e8a07d2
docs(preheat): docs for preheat policy start command
Sypher845 May 8, 2026
33ef00a
feat(preheat): preheat policy create command
Sypher845 May 10, 2026
9355e62
docs(preheat): docs for preheat policy create command
Sypher845 May 10, 2026
9929fdc
feat(preheat): preheat policy update command
Sypher845 May 10, 2026
f11399d
refac(preheat): add examples to commands
Sypher845 May 10, 2026
df4a6d0
refac: add more validation
Sypher845 May 12, 2026
9bd5e8b
refac: solve minor logic issue
Sypher845 May 12, 2026
1a6bf4d
feat(preheat): preheat execution list command
Sypher845 May 12, 2026
aa6ced1
docs(preheat): docs for preheat execution list command
Sypher845 May 12, 2026
d35c1b0
feat(preheat): preheat execution view command
Sypher845 May 13, 2026
01e9859
docs(preheat): docs for preheat execution view command
Sypher845 May 13, 2026
38acf30
feat(preheat): preheat execution stop command
Sypher845 May 13, 2026
4e1b5ce
docs(preheat): docs for preheat execution stop command
Sypher845 May 13, 2026
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
1 change: 1 addition & 0 deletions cmd/harbor/root/project/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func Project() *cobra.Command {
SearchProjectCommand(),
Robot(),
Member(),
Preheat(),
)

return cmd
Expand Down
35 changes: 35 additions & 0 deletions cmd/harbor/root/project/preheat.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// 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 project

import (
"github.com/goharbor/harbor-cli/cmd/harbor/root/project/preheat"
"github.com/spf13/cobra"
)

func Preheat() *cobra.Command {
cmd := &cobra.Command{
Use: "preheat",
Aliases: []string{"p2p"},
Short: "Manage project preheat resources",
Long: "Manage project-scoped P2P preheat policies, executions, and tasks in Harbor",
Example: ` harbor project preheat policy list`,
}
cmd.AddCommand(
preheat.PolicyCommand(),
preheat.ExecutionCommand(),
)

return cmd
}
37 changes: 37 additions & 0 deletions cmd/harbor/root/project/preheat/execution.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// 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 preheat

import (
"github.com/goharbor/harbor-cli/cmd/harbor/root/project/preheat/execution"
"github.com/spf13/cobra"
)

func ExecutionCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "execution",
Aliases: []string{"exec"},
Short: "Manage preheat executions",
Long: "Manage P2P preheat executions under a project",
Example: ` harbor-cli project preheat execution list [NAME|ID] [POLICY_NAME]`,
}

cmd.AddCommand(
execution.ListExecutionCommand(),
execution.ViewExecutionCommand(),
execution.StopExecutionCommand(),
)

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

import (
"fmt"

"github.com/goharbor/harbor-cli/pkg/api"
"github.com/goharbor/harbor-cli/pkg/prompt"
"github.com/goharbor/harbor-cli/pkg/utils"
"github.com/goharbor/harbor-cli/pkg/views/preheat/execution/list"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

func ListExecutionCommand() *cobra.Command {
var opts api.ListFlags
var isID bool

cmd := &cobra.Command{
Use: "list",
Short: "List preheat executions",
Long: "List preheat executions under a project",
Example: ` harbor-cli project preheat execution list [NAME|ID] [POLICY_NAME]`,
Args: cobra.MaximumNArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
var err error
var projectName, policyName string

if opts.Page < 1 {
return fmt.Errorf("page number must be greater than or equal to 1")
}
if opts.PageSize <= 0 || opts.PageSize > 100 {
return fmt.Errorf("page size must be greater than 0 and less than or equal to 100")
}

if isID && len(args) == 0 {
return fmt.Errorf("project ID must be provided when using --id")
}

if len(args) >= 1 {
log.Debugf("Project name provided: %s", args[0])
projectName = args[0]
} else {
log.Debug("No project name provided, prompting user")
projectName, err = prompt.GetProjectNameFromUser()
if err != nil {
return fmt.Errorf("failed to get project name: %v", utils.ParseHarborErrorMsg(err))
}
}

if isID {
project, err := api.GetProject(projectName, true)
if err != nil {
return fmt.Errorf("failed to resolve project ID: %v", utils.ParseHarborErrorMsg(err))
}
projectName = project.Payload.Name
}

if len(args) >= 2 {
log.Debugf("Policy name provided: %s", args[1])
policyName = args[1]
} else {
log.Debug("No policy name provided, prompting user")
policyName, err = prompt.GetPreheatPolicyNameFromUser(projectName)
if err != nil {
return fmt.Errorf("failed to get policy name: %v", utils.ParseHarborErrorMsg(err))
}
}

log.Debug("Fetching preheat policy executions...")
resp, err := api.ListPreheatExecutions(projectName, policyName, opts)
if err != nil {
if utils.ParseHarborErrorCode(err) == "404" {
return fmt.Errorf("no executions found for policy %s in project %s", policyName, projectName)
}
return fmt.Errorf("failed to list preheat executions: %v", utils.ParseHarborErrorMsg(err))
}

if len(resp.Payload) == 0 {
fmt.Println("No executions found")
return nil
}

FormatFlag := viper.GetString("output-format")
if FormatFlag != "" {
err = utils.PrintFormat(resp.Payload, FormatFlag)
if err != nil {
return err
}
} else {
list.ListExecutions(resp.Payload)
}
return nil
},
}

flags := cmd.Flags()
flags.BoolVar(&isID, "id", false, "Get preheat executions by project id")
flags.Int64VarP(&opts.Page, "page", "", 1, "Page number")
flags.Int64VarP(&opts.PageSize, "page-size", "", 10, "Size of per page")
flags.StringVarP(&opts.Q, "query", "q", "", "Query string to query resources")
flags.StringVarP(&opts.Sort, "sort", "", "", "Sort the resource list in ascending or descending order")

return cmd
}
106 changes: 106 additions & 0 deletions cmd/harbor/root/project/preheat/execution/stop.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// 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 execution

import (
"fmt"
"strconv"

"github.com/goharbor/harbor-cli/pkg/api"
"github.com/goharbor/harbor-cli/pkg/prompt"
"github.com/goharbor/harbor-cli/pkg/utils"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

func StopExecutionCommand() *cobra.Command {
var isID bool

cmd := &cobra.Command{
Use: "stop [PROJECT_NAME|ID] [POLICY_NAME] [EXECUTION_ID]",
Short: "Stop preheat execution",
Long: "Stop a specific P2P preheat execution of a policy under a project",
Example: ` harbor-cli project preheat execution stop [NAME|ID] [POLICY_NAME] [EXECUTION_ID]`,
Args: cobra.MaximumNArgs(3),
RunE: func(cmd *cobra.Command, args []string) error {
var err error
var projectName, policyName string
var executionID int64

if isID && len(args) == 0 {
return fmt.Errorf("project ID must be provided when using --id")
}

if len(args) >= 1 {
log.Debugf("Project name provided: %s", args[0])
projectName = args[0]
} else {
log.Debug("No project name provided, prompting user")
projectName, err = prompt.GetProjectNameFromUser()
if err != nil {
return fmt.Errorf("failed to get project name: %v", utils.ParseHarborErrorMsg(err))
}
}
if isID {
project, err := api.GetProject(projectName, true)
if err != nil {
return fmt.Errorf("failed to resolve project ID: %v", utils.ParseHarborErrorMsg(err))
}
projectName = project.Payload.Name
}

if len(args) >= 2 {
log.Debugf("Policy name provided: %s", args[1])
policyName = args[1]
} else {
log.Debug("No policy name provided, prompting user")
policyName, err = prompt.GetPreheatPolicyNameFromUser(projectName)
if err != nil {
return fmt.Errorf("failed to get policy name: %v", utils.ParseHarborErrorMsg(err))
}
}

if len(args) >= 3 {
log.Debugf("Execution ID provided: %s", args[2])
executionID, err = strconv.ParseInt(args[2], 10, 64)
if err != nil {
return fmt.Errorf("invalid execution ID %q: %v", args[2], err)
}
} else {
log.Debug("No execution ID provided, prompting user")
executionID, err = prompt.GetPreheatPolicyExecIDFromUser(projectName, policyName)
if err != nil {
return fmt.Errorf("failed to get execution id: %v", utils.ParseHarborErrorMsg(err))
}
}

log.Debug("Stopping preheat execution...")
err = api.StopPreheatExecution(projectName, policyName, executionID)
if err != nil {
if utils.ParseHarborErrorCode(err) == "404" {
return fmt.Errorf("preheat execution %d not found for policy %s in project %s", executionID, policyName, projectName)
}
return fmt.Errorf("failed to stop preheat execution: %v", utils.ParseHarborErrorMsg(err))
}

fmt.Printf("Preheat execution %d stopped successfully for policy '%s' in project '%s'\n", executionID, policyName, projectName)
return nil
},
}

flags := cmd.Flags()
flags.BoolVar(&isID, "id", false, "Get preheat policy execution by project id")

return cmd
}
Loading
Loading