|
| 1 | +// Copyright Project Harbor Authors |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | +package cve |
| 15 | + |
| 16 | +import ( |
| 17 | + "github.com/goharbor/harbor-cli/pkg/api" |
| 18 | + "github.com/goharbor/harbor-cli/pkg/views/cveallowlist/update" |
| 19 | + log "github.com/sirupsen/logrus" |
| 20 | + "github.com/spf13/cobra" |
| 21 | +) |
| 22 | + |
| 23 | +func AddCveAllowlistCommand() *cobra.Command { |
| 24 | + var opts update.UpdateView |
| 25 | + |
| 26 | + cmd := &cobra.Command{ |
| 27 | + Use: "add", |
| 28 | + Short: "Add cve allowlist", |
| 29 | + Long: "Create allowlist of CVEs to ignore during vulnerability scanning", |
| 30 | + Run: func(cmd *cobra.Command, args []string) { |
| 31 | + var err error |
| 32 | + updateView := &update.UpdateView{ |
| 33 | + CveId: opts.CveId, |
| 34 | + IsExpire: opts.IsExpire, |
| 35 | + ExpireDate: opts.ExpireDate, |
| 36 | + } |
| 37 | + |
| 38 | + err = updatecveView(updateView) |
| 39 | + if err != nil { |
| 40 | + log.Errorf("failed to add cveallowlist: %v", err) |
| 41 | + } |
| 42 | + }, |
| 43 | + } |
| 44 | + |
| 45 | + flags := cmd.Flags() |
| 46 | + flags.BoolVarP(&opts.IsExpire, "isexpire", "i", false, "Indicates whether the CVE entries should have an expiration date. Set to true to specify an expiration date") |
| 47 | + flags.StringVarP(&opts.CveId, "cveid", "n", "", "Comma-separated list of CVE IDs to be added to the allowlist") |
| 48 | + flags.StringVarP(&opts.ExpireDate, "expiredate", "d", "", "Specifies the expiration date for the CVE entries in the format 'YYYY-MM-DD'") |
| 49 | + |
| 50 | + return cmd |
| 51 | +} |
| 52 | + |
| 53 | +func updatecveView(updateView *update.UpdateView) error { |
| 54 | + if updateView == nil { |
| 55 | + updateView = &update.UpdateView{} |
| 56 | + } |
| 57 | + |
| 58 | + update.UpdateCveView(updateView) |
| 59 | + return api.UpdateSystemCve(*updateView) |
| 60 | +} |
0 commit comments