|
| 1 | +// |
| 2 | +// Author:: Ross Moles (<ross.moles@lacework.net>) |
| 3 | +// Copyright:: Copyright 2022, Lacework Inc. |
| 4 | +// License:: Apache License, Version 2.0 |
| 5 | +// |
| 6 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +// you may not use this file except in compliance with the License. |
| 8 | +// You may obtain a copy of the License at |
| 9 | +// |
| 10 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +// |
| 12 | +// Unless required by applicable law or agreed to in writing, software |
| 13 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +// See the License for the specific language governing permissions and |
| 16 | +// limitations under the License. |
| 17 | +// |
| 18 | + |
| 19 | +package cmd |
| 20 | + |
| 21 | +import ( |
| 22 | + "strings" |
| 23 | + |
| 24 | + "github.com/lacework/go-sdk/api" |
| 25 | + "github.com/pkg/errors" |
| 26 | + "github.com/spf13/cobra" |
| 27 | +) |
| 28 | + |
| 29 | +var ( |
| 30 | + // suppressionsListAzureCmd represents the azure sub-command inside the suppressions list |
| 31 | + //command |
| 32 | + suppressionsListAzureCmd = &cobra.Command{ |
| 33 | + Use: "list", |
| 34 | + Aliases: []string{"ls"}, |
| 35 | + Short: "List legacy suppressions for Azure", |
| 36 | + RunE: suppressionsAzureList, |
| 37 | + } |
| 38 | +) |
| 39 | + |
| 40 | +func suppressionsAzureList(_ *cobra.Command, _ []string) error { |
| 41 | + var ( |
| 42 | + suppressions map[string]api.SuppressionV2 |
| 43 | + err error |
| 44 | + ) |
| 45 | + |
| 46 | + suppressions, err = cli.LwApi.V2.Suppressions.Azure.List() |
| 47 | + if err != nil { |
| 48 | + if strings.Contains(err.Error(), "No active Azure accounts") { |
| 49 | + cli.OutputHuman("No active Azure accounts found. " + |
| 50 | + "Unable to get legacy Azure suppressions\n") |
| 51 | + return nil |
| 52 | + } |
| 53 | + return errors.Wrap(err, "Unable to get legacy Azure suppressions") |
| 54 | + } |
| 55 | + |
| 56 | + if len(suppressions) == 0 { |
| 57 | + cli.OutputHuman("No legacy Azure suppressions found.\n") |
| 58 | + return nil |
| 59 | + } |
| 60 | + return cli.OutputJSON(suppressions) |
| 61 | +} |
0 commit comments