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
107 changes: 0 additions & 107 deletions cmd/harbor/root/artifact/scan.go

This file was deleted.

52 changes: 52 additions & 0 deletions cmd/harbor/root/artifact/scan/scan.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// 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/goharbor/harbor-cli/pkg/prompt"
"github.com/goharbor/harbor-cli/pkg/utils"
"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 parseArgs(args []string) (string, string, string, error) {
if len(args) > 0 {
return utils.ParseProjectRepoReference(args[0])
} else {
projectName, err := prompt.GetProjectNameFromUser()
if err != nil {
return "", "", "", err
}
repoName := prompt.GetRepoNameFromUser(projectName)
reference := prompt.GetReferenceFromUser(repoName, projectName)

return projectName, repoName, reference, nil
}
}
43 changes: 43 additions & 0 deletions cmd/harbor/root/artifact/scan/start.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// 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/spf13/cobra"
)

func StartScanArtifactCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "start",
Short: "Start a scan of an artifact",
Long: `Start a scan of an artifact in Harbor Repository`,
Example: `harbor artifact scan start <project>/<repository>/<reference>`,
RunE: func(cmd *cobra.Command, args []string) error {
projectName, repoName, reference, err := parseArgs(args)
if err != nil {
return err
}

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

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

return nil
},
}
return cmd
}
Loading