Skip to content

Commit 796bd92

Browse files
authored
feat(RAIN-45215): Add Hidden Azure & GCP suppressions list commands (#1100)
* feat(RAIN-45215): Add Hidden Azure & GCP suppressions list commands Signed-off-by: Ross <ross.moles@lacework.net> * feat(RAIN-45215): Address review comment Signed-off-by: Ross <ross.moles@lacework.net> Signed-off-by: Ross <ross.moles@lacework.net>
1 parent 8ecf94b commit 796bd92

File tree

8 files changed

+206
-6
lines changed

8 files changed

+206
-6
lines changed

api/v2.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ func NewV2Endpoints(c *Client) *V2Endpoints {
9191
&AlertsService{c},
9292
&SuppressionsServiceV2{c,
9393
&AwsSuppressionsV2{c},
94-
//&AzureSuppressionsV2{c},
95-
//&GcpSuppressionsV2{c},
94+
&AzureSuppressionsV2{c},
95+
&GcpSuppressionsV2{c},
9696
},
9797
}
9898

api/v2_suppressions.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ import (
2929
type SuppressionsServiceV2 struct {
3030
client *Client
3131
Aws suppressionServiceV2
32-
//Azure suppressionServiceV2
33-
//Gcp suppressionServiceV2
32+
Azure suppressionServiceV2
33+
Gcp suppressionServiceV2
3434
}
3535

3636
type suppressionServiceV2 interface {
@@ -40,7 +40,9 @@ type suppressionServiceV2 interface {
4040
type SuppressionTypeV2 string
4141

4242
const (
43-
AwsSuppression SuppressionTypeV2 = "aws"
43+
AwsSuppression SuppressionTypeV2 = "aws"
44+
AzureSuppression SuppressionTypeV2 = "azure"
45+
GcpSuppression SuppressionTypeV2 = "gcp"
4446
)
4547

4648
func (svc *SuppressionsServiceV2) list(cloudType SuppressionTypeV2) (map[string]SuppressionV2,

api/v2_suppressions_azure.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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 api
20+
21+
// AzureSuppressionsV2 is a service that interacts with the V2 Suppressions
22+
// endpoints from the Lacework Server
23+
type AzureSuppressionsV2 struct {
24+
client *Client
25+
}
26+
27+
func (svc *AzureSuppressionsV2) List() (map[string]SuppressionV2, error) {
28+
return svc.client.V2.Suppressions.list(AzureSuppression)
29+
}

api/v2_suppressions_gcp.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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 api
20+
21+
// GcpSuppressionsV2 is a service that interacts with the V2 Suppressions
22+
// endpoints from the Lacework Server
23+
type GcpSuppressionsV2 struct {
24+
client *Client
25+
}
26+
27+
func (svc *GcpSuppressionsV2) List() (map[string]SuppressionV2, error) {
28+
return svc.client.V2.Suppressions.list(GcpSuppression)
29+
}

cli/cmd/suppressions.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,30 @@ var (
3737
Use: "aws",
3838
Short: "Manage legacy suppressions for aws",
3939
}
40+
41+
// suppressionsAzureCmd represents the aws sub-command inside the suppressions command
42+
suppressionsAzureCmd = &cobra.Command{
43+
Use: "azure",
44+
Short: "Manage legacy suppressions for azure",
45+
}
46+
47+
// suppressionsGcpCmd represents the aws sub-command inside the suppressions command
48+
suppressionsGcpCmd = &cobra.Command{
49+
Use: "gcp",
50+
Short: "Manage legacy suppressions for gcp",
51+
}
4052
)
4153

4254
func init() {
4355
rootCmd.AddCommand(suppressionsCommand)
56+
// aws
4457
suppressionsCommand.AddCommand(suppressionsAwsCmd)
4558
suppressionsAwsCmd.AddCommand(suppressionsListAwsCmd)
4659
suppressionsAwsCmd.AddCommand(suppressionsMigrateAwsCmd)
60+
// azure
61+
suppressionsCommand.AddCommand(suppressionsAzureCmd)
62+
suppressionsAzureCmd.AddCommand(suppressionsListAzureCmd)
63+
// gcp
64+
suppressionsCommand.AddCommand(suppressionsGcpCmd)
65+
suppressionsGcpCmd.AddCommand(suppressionsListGcpCmd)
4766
}

cli/cmd/suppressions_aws.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ func suppressionsAwsList(_ *cobra.Command, _ []string) error {
214214
if err != nil {
215215
if strings.Contains(err.Error(), "No active AWS accounts") {
216216
cli.OutputHuman("No active AWS accounts found. " +
217-
"Unable to get legacy aws suppressions")
217+
"Unable to get legacy aws suppressions\n")
218218
return nil
219219
}
220220
return errors.Wrap(err, "Unable to get legacy aws suppressions")

cli/cmd/suppressions_azure.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
}

cli/cmd/suppressions_gcp.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
// suppressionsListGcpCmd represents the gcp sub-command inside the suppressions list command
31+
suppressionsListGcpCmd = &cobra.Command{
32+
Use: "list",
33+
Aliases: []string{"ls"},
34+
Short: "List legacy suppressions for GCP",
35+
RunE: suppressionsGcpList,
36+
}
37+
)
38+
39+
func suppressionsGcpList(_ *cobra.Command, _ []string) error {
40+
var (
41+
suppressions map[string]api.SuppressionV2
42+
err error
43+
)
44+
45+
suppressions, err = cli.LwApi.V2.Suppressions.Gcp.List()
46+
if err != nil {
47+
if strings.Contains(err.Error(), "No active GCP accounts") {
48+
cli.OutputHuman("No active GCP accounts found. " +
49+
"Unable to get legacy GCP suppressions\n")
50+
return nil
51+
}
52+
return errors.Wrap(err, "Unable to get legacy GCP suppressions")
53+
}
54+
55+
if len(suppressions) == 0 {
56+
cli.OutputHuman("No legacy GCP suppressions found.\n")
57+
return nil
58+
}
59+
return cli.OutputJSON(suppressions)
60+
}

0 commit comments

Comments
 (0)