Skip to content

Commit

Permalink
feat: Remove RGv1 logic. Add KUBERNETES to ResourceGroups (#1666)
Browse files Browse the repository at this point in the history
* feat: Remove RGv1 logic

* fix: Fix the gosimple lint errors

Signed-off-by: Lei Jin <lei.jin@lacework.net>

* fix: Fix the build issue

Signed-off-by: Lei Jin <lei.jin@lacework.net>

* fix: Fix unit tests

Signed-off-by: Lei Jin <lei.jin@lacework.net>

* fix: Fix the rgv2 list bug

Signed-off-by: Lei Jin <lei.jin@lacework.net>

* fix: Add Kubernetes support

* fix: rg api tests

* fix: Remove ResourceGroupProps references

* fix: json parsing for integ test

* fix: Bugs. Remove v2 suffix everywhere

* fix: remove commented out code

* fix: linting

* fix: integration test

* fix: rename vars

* fix: tests

* fix: fix bug in integ test

* fix: try again to fix integ tests

---------

Signed-off-by: Lei Jin <lei.jin@lacework.net>
Co-authored-by: Lei Jin <lei.jin@lacework.net>
  • Loading branch information
zekisherif and leijin-lw authored Oct 30, 2024
1 parent cbebb62 commit 2b0ffd4
Show file tree
Hide file tree
Showing 35 changed files with 1,066 additions and 3,527 deletions.
49 changes: 9 additions & 40 deletions api/_examples/resource-groups/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,7 @@ func main() {
for _, account := range res.Data {
var resourceGuid string
resourceType := account.Type

if account.Props != nil {
resourceGuid = account.ResourceGuid
} else {
resourceGuid = account.ResourceGroupGuid
}
resourceGuid = account.ResourceGroupGuid

support := "Unsupported"
switch resourceType {
Expand All @@ -42,13 +37,15 @@ func main() {
support = "Supported"
case api.GcpResourceGroup.String():
support = "Supported"
case api.LwAccountResourceGroup.String():
support = "Supported"
case api.MachineResourceGroup.String():
support = "Supported"
case api.OciResourceGroup.String():
support = "Supported"
case api.KubernetesResourceGroup.String():
support = "Supported"
}

// Output: RESOURCE_GUID:RESOURCE_TYPE:[Supported|Unsupported]
// Output: RESOURCE_GROUP_GUID:RESOURCE_TYPE:[Supported|Unsupported]
fmt.Printf("%s:%s:%s\n", resourceGuid, resourceType, support)
}

Expand All @@ -74,7 +71,7 @@ func main() {
},
}

myResourceGroupWithQuery := api.NewResourceGroupWithQuery(
myResourceGroupWithQuery := api.NewResourceGroup(
"resource-group-with-query-from-golang",
api.AwsResourceGroup,
"Resource groups in `us` regions",
Expand All @@ -91,9 +88,9 @@ func main() {
fmt.Printf("Succesfully created resource group \n %+v\n", rgV2Resp)

println("Updating v2 resource group name")
rgV2Resp.Data.NameV2 = "resource-group-with-query-from-golang-updated"
rgV2Resp.Data.Name = "resource-group-with-query-from-golang-updated"

updatedResponse, err := lacework.V2.ResourceGroups.UpdateAws(&rgV2Resp.Data)
updatedResponse, err := lacework.V2.ResourceGroups.Update(&rgV2Resp.Data)

if err != nil {
log.Fatal(err)
Expand All @@ -106,32 +103,4 @@ func main() {
log.Fatal(err)
}
println("Successfully deleted resource group")

props := api.LwAccountResourceGroupProps{
Description: "All Lacework accounts",
LwAccounts: []string{"tech-ally"},
}

myResourceGroup := api.NewResourceGroup(
"resource-group-from-golang",
api.LwAccountResourceGroup,
props,
)

// LW_ACCOUNT resource groups are only allowed at Organization level,
// copy the client to make it an org client
orgLwClient, err := api.CopyClient(lacework,
api.WithOrgAccess(),
)
if err != nil {
log.Fatal(err)
}

response, err := orgLwClient.V2.ResourceGroups.Create(myResourceGroup)
if err != nil {
log.Fatal(err)
}

// Output: Resource Group created: RESOURCE_GUID
fmt.Printf("Resource Group created: %s", response.Data.ResourceGuid)
}
49 changes: 49 additions & 0 deletions api/_templates/resource_groups/kubernetes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"filters": {
"filter1": {
"field": "AWS Account",
"operation": "EQUALS",
"values": [
"123456789012"
]
},
"filter2": {
"field": "AWS Region",
"operation": "EQUALS",
"values": [
"us-west-2"
]
},
"filter3": {
"field": "Cluster Name",
"operation": "EQUALS",
"values": [
"*"
]
},
"filter4": {
"field": "Namespace",
"operation": "EQUALS",
"values": [
"prod"
]
}
},
"expression": {
"operator": "OR",
"children": [
{
"filterName": "filter1"
},
{
"filterName": "filter2"
},
{
"filterName": "filter3"
},
{
"filterName": "filter4"
}
]
}
}
2 changes: 0 additions & 2 deletions api/feature_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"fmt"
)

const ApiV2CliFeatureFlag = "PUBLIC.rgv2.cli"

type FeatureFlagsService struct {
client *Client
}
Expand Down
Loading

0 comments on commit 2b0ffd4

Please sign in to comment.