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
6 changes: 4 additions & 2 deletions cmd/harbor/root/artifact/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ package artifact

import (
"github.com/goharbor/harbor-cli/cmd/harbor/root/artifact/label"
artifactscan "github.com/goharbor/harbor-cli/cmd/harbor/root/artifact/scan"
artifacttags "github.com/goharbor/harbor-cli/cmd/harbor/root/artifact/tags"
"github.com/spf13/cobra"
)

Expand All @@ -30,8 +32,8 @@ func Artifact() *cobra.Command {
ListArtifactCommand(),
ViewArtifactCommmand(),
DeleteArtifactCommand(),
ScanArtifactCommand(),
ArtifactTagsCmd(),
artifactscan.ScanArtifactCommand(),
artifacttags.ArtifactTagsCmd(),
label.LabelsArtifactCommmand(),
)

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

import "github.com/spf13/cobra"

func ScanArtifactCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "scan",
Short: "Scan an artifact",
Long: `Scan an artifact in Harbor Repository`,
Example: `harbor artifact scan start <project>/<repository>/<reference>`,
}

cmd.AddCommand(
StartScanArtifactCommand(),
StopScanArtifactCommand(),
// LogScanArtifactCommand(),
)

return cmd
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,17 @@
// 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 artifact
package artifactscan

import (
"fmt"

"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 ScanArtifactCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "scan",
Short: "Scan an artifact",
Long: `Scan an artifact in Harbor Repository`,
Example: `harbor artifact scan start <project>/<repository>/<reference>`,
}

cmd.AddCommand(
StartScanArtifactCommand(),
StopScanArtifactCommand(),
// LogScanArtifactCommand(),
)

return cmd
}

func StartScanArtifactCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "start",
Expand Down Expand Up @@ -72,36 +54,3 @@ func StartScanArtifactCommand() *cobra.Command {
}
return cmd
}

func StopScanArtifactCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "stop",
Short: "Stop a scan of an artifact",
Long: `Stop a scan of an artifact in Harbor Repository`,
Example: `harbor artifact scan stop <project>/<repository>/<reference>`,
Run: func(cmd *cobra.Command, args []string) {
var err error
var projectName, repoName, reference string

if len(args) > 0 {
projectName, repoName, reference, err = utils.ParseProjectRepoReference(args[0])
if err != nil {
log.Errorf("failed to parse project/repo/reference: %v", err)
}
} else {
projectName, err = prompt.GetProjectNameFromUser()
if err != nil {
log.Errorf("failed to get project name: %v", utils.ParseHarborErrorMsg(err))
}
repoName = prompt.GetRepoNameFromUser(projectName)
reference = prompt.GetReferenceFromUser(repoName, projectName)
}

err = api.StopScanArtifact(projectName, repoName, reference)
if err != nil {
log.Errorf("failed to stop scan of artifact: %v", err)
}
},
}
return cmd
}
58 changes: 58 additions & 0 deletions cmd/harbor/root/artifact/scan/stop.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// 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 artifactscan

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/spf13/cobra"
)

func StopScanArtifactCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "stop",
Short: "Stop a scan of an artifact",
Long: `Stop a scan of an artifact in Harbor Repository`,
Example: `harbor artifact scan stop <project>/<repository>/<reference>`,
RunE: func(cmd *cobra.Command, args []string) error {
var err error
var projectName, repoName, reference string

if len(args) > 0 {
projectName, repoName, reference, err = utils.ParseProjectRepoReference(args[0])
if err != nil {
return fmt.Errorf("failed to parse project/repo/reference: %v", err)
}
} else {
projectName, err = prompt.GetProjectNameFromUser()
if err != nil {
return fmt.Errorf("failed to get project name: %v", utils.ParseHarborErrorMsg(err))
}
repoName = prompt.GetRepoNameFromUser(projectName)
reference = prompt.GetReferenceFromUser(repoName, projectName)
}

err = api.StopScanArtifact(projectName, repoName, reference)
if err != nil {
return fmt.Errorf("failed to stop scan of artifact: %v", err)
}

return nil
},
}
return cmd
}
160 changes: 0 additions & 160 deletions cmd/harbor/root/artifact/tags.go

This file was deleted.

Loading
Loading