Skip to content

aws sg analysis #648

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 46 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
c62b142
aws sg analysis
olasaadi99 Jun 23, 2024
3691fd3
fix
olasaadi99 Jun 25, 2024
5b2bc82
fix lnt
olasaadi99 Jun 25, 2024
2fbcec9
fix test
olasaadi99 Jun 25, 2024
6c0b0dc
fix
olasaadi99 Jul 1, 2024
eb344e3
fix
olasaadi99 Jul 1, 2024
27a75e8
rename file, and add resource name to config
olasaadi99 Jul 1, 2024
4dabafb
remove explain test
olasaadi99 Jul 1, 2024
b6072d6
common code
olasaadi99 Jul 2, 2024
01d65f8
fix
olasaadi99 Jul 2, 2024
ccc09f1
add test based on objects rather than input JSON files
olasaadi99 Jul 2, 2024
3477f56
add aws sg test with non trivial sg rules
olasaadi99 Jul 2, 2024
961d832
add test
olasaadi99 Jul 3, 2024
a7fc42e
add test
olasaadi99 Jul 4, 2024
8d29f18
fix comments
olasaadi99 Jul 4, 2024
759dd8e
capture commonn code parsing file
olasaadi99 Jul 8, 2024
312939f
fix
olasaadi99 Jul 8, 2024
474df9a
unused field
olasaadi99 Jul 10, 2024
9f64e4d
add interface for resource container
olasaadi99 Jul 10, 2024
2e2ae81
Merge branch 'main' into 641_sg
olasaadi99 Jul 11, 2024
c777c71
fix
olasaadi99 Jul 11, 2024
f147d09
resolve conflicts
olasaadi99 Jul 17, 2024
df88cf0
fix
olasaadi99 Jul 17, 2024
8018ea0
fix
olasaadi99 Jul 17, 2024
75c9058
fix
olasaadi99 Jul 17, 2024
c4da692
:fix:
olasaadi99 Jul 17, 2024
4a94dab
common code
olasaadi99 Jul 17, 2024
a5835f5
more common code
olasaadi99 Jul 17, 2024
392b6ca
merge
olasaadi99 Jul 18, 2024
7b2ec8a
fix
olasaadi99 Jul 18, 2024
0060e92
remove files, add sg members to print
olasaadi99 Jul 18, 2024
93db977
fix printing
olasaadi99 Jul 21, 2024
ad5b7b7
fix
olasaadi99 Jul 21, 2024
9651029
merge
olasaadi99 Jul 21, 2024
a133754
fix
olasaadi99 Jul 21, 2024
2b8e92b
fix handling ipRanges field
olasaadi99 Jul 22, 2024
d30e63f
fix
olasaadi99 Jul 22, 2024
deb9368
merge
olasaadi99 Jul 22, 2024
b65aae7
fix print line section
olasaadi99 Jul 22, 2024
6566fec
fix
olasaadi99 Jul 22, 2024
808d5ba
fix
olasaadi99 Jul 22, 2024
086889d
change analyzer name
olasaadi99 Jul 22, 2024
0d06fb6
add description for getProperty
olasaadi99 Jul 22, 2024
ae4f9fd
rename specificAnalyzer interface to SpecificSGAnalyzer
olasaadi99 Jul 22, 2024
d8721ac
update doc to filter by vpc
olasaadi99 Jul 22, 2024
8a3f708
fix
olasaadi99 Jul 23, 2024
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: 6 additions & 0 deletions cmd/analyzer/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ func TestMain(t *testing.T) {
name string
args string
}{
// aws
{
name: "aws_all_endpoints",
args: "report endpoints -f aws.txt -c ../../pkg/awsvpc/examples/input/input_basic_config_with_sg.json -o txt",
},
// drawio
{
name: "drawio_multi_vpc_all_subnets",
args: "report subnets -f multi_vpc.drawio --config ../../pkg/ibmvpc/examples/input/input_multiple_vpcs.json -o drawio",
Expand Down
67 changes: 17 additions & 50 deletions cmd/analyzer/subcmds/vpcconfigs.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,14 @@ import (
"github.com/np-guard/cloud-resource-collector/pkg/common"
"github.com/np-guard/cloud-resource-collector/pkg/factory"
"github.com/np-guard/cloud-resource-collector/pkg/ibm/datamodel"
"github.com/np-guard/vpc-network-config-analyzer/pkg/awsvpc"
"github.com/np-guard/vpc-network-config-analyzer/pkg/commonvpc"
"github.com/np-guard/vpc-network-config-analyzer/pkg/ibmvpc"
"github.com/np-guard/vpc-network-config-analyzer/pkg/vpcmodel"
)

const notSupportedYet = "provider %s is not supported yet"

func mergeResourcesContainers(rc1, rc2 *datamodel.ResourcesContainerModel) (*datamodel.ResourcesContainerModel, error) {
if rc2 == nil && rc1 != nil {
return rc1, nil
}
if rc2 != nil && rc1 == nil {
return rc2, nil
}
if rc2 == nil && rc1 == nil {
return nil, fmt.Errorf("error merging input vpc resources files")
}
rc1.VpcList = append(rc1.VpcList, rc2.VpcList...)
rc1.SubnetList = append(rc1.SubnetList, rc2.SubnetList...)
rc1.PublicGWList = append(rc1.PublicGWList, rc2.PublicGWList...)
rc1.FloatingIPList = append(rc1.FloatingIPList, rc2.FloatingIPList...)
rc1.NetworkACLList = append(rc1.NetworkACLList, rc2.NetworkACLList...)
rc1.SecurityGroupList = append(rc1.SecurityGroupList, rc2.SecurityGroupList...)
rc1.EndpointGWList = append(rc1.EndpointGWList, rc2.EndpointGWList...)
rc1.InstanceList = append(rc1.InstanceList, rc2.InstanceList...)
rc1.RoutingTableList = append(rc1.RoutingTableList, rc2.RoutingTableList...)
rc1.LBList = append(rc1.LBList, rc2.LBList...)
rc1.TransitConnectionList = append(rc1.TransitConnectionList, rc2.TransitConnectionList...)
rc1.TransitGatewayList = append(rc1.TransitGatewayList, rc2.TransitGatewayList...)
rc1.IKSClusters = append(rc1.IKSClusters, rc2.IKSClusters...)

return rc1, nil
}

// Helper function for unmarshalling
func jsonToMap(jsonStr []byte) (map[string]json.RawMessage, error) {
var result map[string]json.RawMessage
Expand Down Expand Up @@ -76,30 +51,21 @@ func parseProviderFromFile(fileName string) (common.Provider, error) {
}

func vpcConfigsFromFiles(fileNames []string, inArgs *inArgs) (*vpcmodel.MultipleVPCConfigs, error) {
var mergedRC *datamodel.ResourcesContainerModel
for _, file := range fileNames {
provider, err := parseProviderFromFile(file)
if err != nil {
return nil, err
}
if provider == common.IBM {
rc, err1 := ibmvpc.ParseResourcesFromFile(file)
if err1 != nil {
return nil, fmt.Errorf("error parsing input vpc resources file: %w", err1)
}
mergedRC, err1 = mergeResourcesContainers(mergedRC, rc)
if err1 != nil {
return nil, err1
}
} else {
return nil, fmt.Errorf(notSupportedYet, provider)
}
// len(fileNames) can not be zero
provider, err := parseProviderFromFile(fileNames[0])
if err != nil {
return nil, err
}
vpcConfigs, err2 := ibmvpc.VPCConfigsFromResources(mergedRC, inArgs.vpc, inArgs.resourceGroup, inArgs.regionList)
if err2 != nil {
return nil, fmt.Errorf("error generating cloud config from input vpc resources file: %w", err2)
var rc commonvpc.ResourcesContainer
switch provider {
case common.IBM:
rc = &ibmvpc.IBMresourcesContainer{}
case common.AWS:
rc = &awsvpc.AWSresourcesContainer{}
default:
return nil, fmt.Errorf(notSupportedYet, provider)
}
return vpcConfigs, nil
return rc.VpcConfigsFromFiles(fileNames, inArgs.vpc, inArgs.resourceGroup, inArgs.regionList)
}

func vpcConfigsFromAccount(inArgs *inArgs) (*vpcmodel.MultipleVPCConfigs, error) {
Expand All @@ -117,7 +83,8 @@ func vpcConfigsFromAccount(inArgs *inArgs) (*vpcmodel.MultipleVPCConfigs, error)
if !ok {
return nil, fmt.Errorf("error casting resources to *datamodel.ResourcesContainerModel type")
}
vpcConfigs, err = ibmvpc.VPCConfigsFromResources(ibmResources, inArgs.vpc, inArgs.resourceGroup, inArgs.regionList)
rc := ibmvpc.IBMresourcesContainer{ResourcesContainerModel: *ibmResources}
vpcConfigs, err = rc.VPCConfigsFromResources(inArgs.vpc, inArgs.resourceGroup, inArgs.regionList)
if err != nil {
return nil, err
}
Expand Down
Loading