Skip to content

Commit

Permalink
Split destinations by commas to handle comma-delimited lists (#94)
Browse files Browse the repository at this point in the history
Signed-off-by: Josh Russett <[email protected]>
  • Loading branch information
dsabeti authored Apr 1, 2024
1 parent 9b9671a commit ed87f49
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
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

0 comments on commit ed87f49

Please sign in to comment.