Skip to content
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

handling Rule.destinationsExcluded #136

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ schemas/*.json

# For tests output
pkg/*/out/*
pkg/*/*/actual_output/*
cmd/examples/output/*

# For temporary examples and pkgs
Expand Down
46 changes: 46 additions & 0 deletions pkg/collector/data/examples.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,52 @@ var Example2 = Example{
},
}

var ExampleExclude = Example{
Name: "ExampleExclude",
VMs: []string{"Slytherin1", "Slytherin2", "Hufflepuff1", "Hufflepuff2",
"Gryffindor1", "Gryffindor2", "Dumbledore1", "Dumbledore2", "Aladdin"},
Groups: map[string][]string{
"Slytherin": {"Slytherin1", "Slytherin2"},
"Hufflepuff": {"Hufflepuff1", "Hufflepuff2"},
"Gryffindor": {"Gryffindor1", "Gryffindor2"},
"Dumbledore": {"Dumbledore1", "Dumbledore2"},
"Aladdin": {"Aladdin", "Aladdin"},
},
Policies: []Category{
{
Name: "AladdinTalks",
CategoryType: "Environment",
Rules: []Rule{
{
Name: "allow-Aladdin-to-others",
ID: 10218,
Source: "Aladdin",
Dest: "Aladdin",
DestinationsExcluded: true,
Services: []string{"ANY"},
Action: Allow,
},
{
Name: "allow-others-to-Aladdin",
ID: 10219,
Source: "Aladdin",
Dest: "Aladdin",
SourcesExcluded: true,
Services: []string{"ANY"},
Action: Allow,
},
},
},
{
Name: "Default-L3-Section",
CategoryType: "Application",
Rules: []Rule{
DefaultDenyRule(denyRuleIDApp),
},
},
},
}

var Example3 = example3FromExample2()

func example3FromExample2() Example {
Expand Down
34 changes: 19 additions & 15 deletions pkg/collector/data/examples_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,25 +189,29 @@ func DefaultDenyRule(id int) Rule {
}

type Rule struct {
Name string
ID int
Source string
Dest string
Services []string
Action string
Direction string // if not set, used as default with "IN_OUT"
Name string
ID int
Source string
SourcesExcluded bool
DestinationsExcluded bool
Dest string
Services []string
Action string
Direction string // if not set, used as default with "IN_OUT"
}

func (r *Rule) toNSXRule() *nsx.Rule {
return &nsx.Rule{
DisplayName: &r.Name,
RuleId: &r.ID,
Action: (*nsx.RuleAction)(&r.Action),
SourceGroups: []string{r.Source},
DestinationGroups: []string{r.Dest},
Services: r.Services,
Direction: r.directionStr(),
Scope: []string{AnyStr}, // TODO: add scope as configurable
DisplayName: &r.Name,
RuleId: &r.ID,
Action: (*nsx.RuleAction)(&r.Action),
SourceGroups: []string{r.Source},
DestinationGroups: []string{r.Dest},
SourcesExcluded: r.SourcesExcluded,
DestinationsExcluded: r.DestinationsExcluded,
Services: r.Services,
Direction: r.directionStr(),
Scope: []string{AnyStr}, // TODO: add scope as configurable
}
}

Expand Down
17 changes: 17 additions & 0 deletions pkg/collector/data/expected_output/ExampleExclude.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Analyzed connectivity::
Aladdin => Dumbledore1: All Connections
Aladdin => Dumbledore2: All Connections
Aladdin => Gryffindor1: All Connections
Aladdin => Gryffindor2: All Connections
Aladdin => Hufflepuff1: All Connections
Aladdin => Hufflepuff2: All Connections
Aladdin => Slytherin1: All Connections
Aladdin => Slytherin2: All Connections
Dumbledore1 => Aladdin: All Connections
Dumbledore2 => Aladdin: All Connections
Gryffindor1 => Aladdin: All Connections
Gryffindor2 => Aladdin: All Connections
Hufflepuff1 => Aladdin: All Connections
Hufflepuff2 => Aladdin: All Connections
Slytherin1 => Aladdin: All Connections
Slytherin2 => Aladdin: All Connections
Loading
Loading