Skip to content

Commit 20cec14

Browse files
authored
model service network (#896)
* subtract 161.26.0.0/16 and 166.8.0.0/14 from PublicInternetAddressList * model service network --------- Signed-off-by: Ola Saadi <ola.saadi1@ibm.com>
1 parent 3691ffc commit 20cec14

File tree

127 files changed

+7418
-876
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+7418
-876
lines changed

cmd/analyzer/subcmds/vpcconfigs.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ func vpcConfigsFromFiles(fileNames []string, inArgs *inArgs) (*vpcmodel.Multiple
5858
var rc commonvpc.ResourcesContainer
5959
switch provider {
6060
case common.IBM:
61-
rc = &ibmvpc.IBMresourcesContainer{}
61+
rc = ibmvpc.NewIBMresourcesContainer()
6262
case common.AWS:
63-
rc = &awsvpc.AWSresourcesContainer{}
63+
rc = awsvpc.NewAWSresourcesContainer()
6464
default:
6565
return nil, fmt.Errorf(notSupportedYet, provider)
6666
}
@@ -78,9 +78,9 @@ func vpcConfigsFromAccount(inArgs *inArgs) (*vpcmodel.MultipleVPCConfigs, error)
7878
var commonRC commonvpc.ResourcesContainer
7979
switch inArgs.provider {
8080
case common.IBM:
81-
commonRC, err = ibmvpc.NewIBMresourcesContainer(rc)
81+
commonRC, err = ibmvpc.CopyIBMresourcesContainer(rc)
8282
case common.AWS:
83-
commonRC, err = awsvpc.NewAWSresourcesContainer(rc)
83+
commonRC, err = awsvpc.CopyAWSresourcesContainer(rc)
8484
default:
8585
return nil, fmt.Errorf(notSupportedYet, inArgs.provider.String())
8686
}

pkg/awsvpc/analysis_output_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ var tests = []*testfunc.VpcAnalysisTest{
6767
// tests is the list of tests to run
6868
for testIdx := range tests {
6969
tt := tests[testIdx]
70-
tt.TestAnalysisSingleTest(t, testfunc.OutputGeneration, &AWSresourcesContainer{}, analysisOut, tt.InputConfig)
70+
tt.TestAnalysisSingleTest(t, testfunc.OutputGeneration, NewAWSresourcesContainer(), analysisOut, tt.InputConfig)
7171
}
7272
fmt.Println("done")
7373
}*/
@@ -76,7 +76,7 @@ func TestReportWithComparison(t *testing.T) {
7676
// tests is the list of tests to run
7777
for testIdx := range tests {
7878
tt := tests[testIdx]
79-
tt.TestAnalysisSingleTest(t, testfunc.OutputComparison, &AWSresourcesContainer{}, analysisOut, tt.InputConfig)
79+
tt.TestAnalysisSingleTest(t, testfunc.OutputComparison, NewAWSresourcesContainer(), analysisOut, tt.InputConfig)
8080
}
8181
fmt.Println("done")
8282
}

pkg/awsvpc/examples/out/explain_out/from_external_public_subnet_all_vpcs_explain_detail.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Explaining connectivity from 147.235.0.0/16 to 10.240.0.96 within mixed
2-
Interpreted source(s): 147.235.0.0/16 (external)
2+
Interpreted source(s): 147.235.0.0/16 (Public Internet)
33
Interpreted destination(s): p3[10.240.0.96]
44
=======================================================================
55

pkg/awsvpc/examples/out/explain_out/to_external_blocked_only_private_subnet_all_vpcs_explain_detail.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Explaining connectivity from 10.240.20.245 to 161.26.0.0 within vpc0
22
Interpreted source(s): app1[10.240.20.245]
3-
Interpreted destination(s): 161.26.0.0 (external)
3+
Interpreted destination(s): 161.26.0.0 (Public Internet)
44
====================================================================
55

66
No connectivity from app1[10.240.20.245] to Public Internet 161.26.0.0/32;

pkg/awsvpc/examples/out/explain_out/to_external_private_subnet_all_vpcs_explain_detail.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Explaining connectivity from 10.240.20.245 to 161.26.0.0 within vpc0
22
Interpreted source(s): app1[10.240.20.245]
3-
Interpreted destination(s): 161.26.0.0 (external)
3+
Interpreted destination(s): 161.26.0.0 (Public Internet)
44
====================================================================
55

66
No connectivity from app1[10.240.20.245] to Public Internet 161.26.0.0/32;

pkg/awsvpc/examples/out/explain_out/to_external_public_subnet_all_vpcs_explain_detail.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Explaining connectivity from 10.240.10.42 to 161.26.0.0 within vpc0
22
Interpreted source(s): proxy[10.240.10.42]
3-
Interpreted destination(s): 161.26.0.0 (external)
3+
Interpreted destination(s): 161.26.0.0 (Public Internet)
44
===================================================================
55

66
Connections from proxy[10.240.10.42] to Public Internet 161.26.0.0/32: All Connections

pkg/awsvpc/explainability_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func TestExplainWithComparsion(t *testing.T) {
101101
// explainTests is the list of tests to run
102102
for testIdx := range explainTests {
103103
tt := explainTests[testIdx]
104-
tt.TestSingleExplain(t, testfunc.OutputComparison, &AWSresourcesContainer{}, tt.Name)
104+
tt.TestSingleExplain(t, testfunc.OutputComparison, NewAWSresourcesContainer(), tt.Name)
105105
}
106106
fmt.Println("done")
107107
}
@@ -112,7 +112,7 @@ func TestExplainWithComparsion(t *testing.T) {
112112
// tests is the list of tests to run
113113
for testIdx := range explainTests {
114114
tt := explainTests[testIdx]
115-
tt.TestSingleExplain(t, commonvpc.OutputGeneration, &AWSresourcesContainer{}, tt.Name)
115+
tt.TestSingleExplain(t, commonvpc.OutputGeneration, NewAWSresourcesContainer(), tt.Name)
116116
}
117117
fmt.Println("done")
118118
}*/

pkg/awsvpc/lint_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func TestLintWithComparsion(t *testing.T) {
4747
tt.Mode = testfunc.OutputComparison
4848
t.Run(tt.Name, func(t *testing.T) {
4949
t.Parallel()
50-
rc := &AWSresourcesContainer{}
50+
rc := NewAWSresourcesContainer()
5151
tt.TestSingleLint(t, rc)
5252
})
5353
}
@@ -63,7 +63,7 @@ func TestLintWithComparsion(t *testing.T) {
6363
tt.Mode = testfunc.OutputGeneration
6464
t.Run(tt.Name, func(t *testing.T) {
6565
t.Parallel()
66-
rc := &AWSresourcesContainer{}
66+
rc := NewAWSresourcesContainer()
6767
tt.TestSingleLint(t, rc)
6868
})
6969
}

pkg/awsvpc/parser.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,22 @@ type AWSresourcesContainer struct {
3131
aws.ResourcesContainer
3232
}
3333

34-
func NewAWSresourcesContainer(rc common.ResourcesContainerInf) (*AWSresourcesContainer, error) {
34+
// NewAWSresourcesContainer is used to return empty NewAWSresourcesContainer and also initialize
35+
// vpcmodel.NetworkAddressLists with aws Public internet and service network
36+
// if you do not use this function, you need to initialize vpcmodel.NetworkAddressLists
37+
func NewAWSresourcesContainer() *AWSresourcesContainer {
38+
vpcmodel.InitNetworkAddressLists(vpcmodel.GetDefaultPublicInternetAddressList(), []string{})
39+
return &AWSresourcesContainer{}
40+
}
41+
42+
func CopyAWSresourcesContainer(rc common.ResourcesContainerInf) (*AWSresourcesContainer, error) {
3543
awsResources, ok := rc.GetResources().(*aws.ResourcesContainer)
3644
if !ok {
3745
return nil, fmt.Errorf("error casting resources to *aws.ResourcesContainerModel type")
3846
}
39-
return &AWSresourcesContainer{ResourcesContainer: *awsResources}, nil
47+
awsRC := NewAWSresourcesContainer()
48+
awsRC.ResourcesContainer = *awsResources
49+
return awsRC, nil
4050
}
4151

4252
// parseResourcesFromFile returns aws.ResourcesContainer object, containing the configured resources structs
@@ -79,7 +89,7 @@ func mergeResourcesContainers(rc1, rc2 *AWSresourcesContainer) (*AWSresourcesCon
7989
func (rc *AWSresourcesContainer) VpcConfigsFromFiles(fileNames []string, resourceGroup string, vpcIDs, regions []string) (
8090
*vpcmodel.MultipleVPCConfigs, error) {
8191
for _, file := range fileNames {
82-
mergedRC := &AWSresourcesContainer{}
92+
mergedRC := NewAWSresourcesContainer()
8393
err1 := mergedRC.ParseResourcesFromFile(file)
8494
if err1 != nil {
8595
return nil, fmt.Errorf("error parsing input vpc resources file: %w", err1)

pkg/commonvpc/parser.go

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,23 @@ const (
3131

3232
// Resource types const strings, used in the generated resources of this pkg
3333
const (
34-
ResourceTypeVSI = "VSI"
35-
ResourceTypeNetworkInterface = "NetworkInterface"
36-
ResourceTypeSubnet = "Subnet"
37-
ResourceTypePublicGateway = "PublicGateway"
38-
ResourceTypeInternetGateway = "InternetGateway"
39-
ResourceTypeFloatingIP = "FloatingIP"
40-
ResourceTypeVPC = "VPC"
41-
ResourceTypeSG = "SG"
42-
ResourceTypeNACL = "NACL"
43-
ResourceTypeIKSNode = "IKSNodeNetworkInterface"
44-
ResourceTypeVPE = "VPE"
45-
ResourceTypeTGW = "TGW"
46-
ResourceTypeReservedIP = "ReservedIP"
47-
ResourceTypeLoadBalancer = "LoadBalancer"
48-
ResourceTypePrivateIP = "PrivateIP"
49-
ResourceTypeRoutingTable = "RoutingTable"
34+
ResourceTypeVSI = "VSI"
35+
ResourceTypeNetworkInterface = "NetworkInterface"
36+
ResourceTypeSubnet = "Subnet"
37+
ResourceTypePublicGateway = "PublicGateway"
38+
ResourceTypeInternetGateway = "InternetGateway"
39+
ResourceTypeFloatingIP = "FloatingIP"
40+
ResourceTypeVPC = "VPC"
41+
ResourceTypeSG = "SG"
42+
ResourceTypeNACL = "NACL"
43+
ResourceTypeIKSNode = "IKSNodeNetworkInterface"
44+
ResourceTypeVPE = "VPE"
45+
ResourceTypeTGW = "TGW"
46+
ResourceTypeReservedIP = "ReservedIP"
47+
ResourceTypeLoadBalancer = "LoadBalancer"
48+
ResourceTypePrivateIP = "PrivateIP"
49+
ResourceTypeRoutingTable = "RoutingTable"
50+
ResourceTypeServiceNetworkGateway = "ServiceGateway"
5051
)
5152

5253
// Implemented by AWSresourcesContainer and IBMresourcesContainer

0 commit comments

Comments
 (0)