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

Split destinations by commas to handle comma-delimited lists #94

Merged
merged 1 commit into from
Apr 1, 2024
Merged
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
5 changes: 5 additions & 0 deletions models/security_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,12 @@ func (rule SecurityGroupRule) validateDestinations() error {

var validationError ValidationError

var destinations []string
for _, d := range rule.Destinations {
destinations = append(destinations, strings.Split(d, ",")...)
}

for _, d := range destinations {
n := strings.IndexAny(d, "-/")
if n == -1 {
if net.ParseIP(d) == nil {
Expand Down
11 changes: 11 additions & 0 deletions models/security_groups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ var _ = Describe("SecurityGroupRule", func() {
Expect(validationErr).To(MatchError(ContainSubstring("destination")))
})
})

})
}

Expand Down Expand Up @@ -262,6 +263,16 @@ var _ = Describe("SecurityGroupRule", func() {
})
})

Context("when it's a comma-delimited list of ips", func() {
BeforeEach(func() {
destination = "1.2.3.4,5.6.7.8"
})

It("passes validation and does not return an error", func() {
Expect(validationErr).NotTo(HaveOccurred())
})
})

Context("when its not valid", func() {
BeforeEach(func() {
destination = "8.8"
Expand Down