Skip to content

Conversation

@marsteg
Copy link
Contributor

@marsteg marsteg commented Dec 11, 2025

Is there a related GitHub Issue?

#4103

What is this change about?

Updating and enhancing the existing Validator for Security Groups

Does this PR introduce a breaking change?

It should not as Security Groups are not supported, yet.

Acceptance Steps

create sec-group.json:
E.g.:

{
  "name": "my-group0",
  "rules": [
    {
      "protocol": "tcp",
      "destination": "10.10.10.0/24",
      "ports": "443,80,8080"
    },
    {
      "protocol": "icmp",
      "destination": "10.10.10.0/24",
      "type": 8,
      "code": 0,
      "description": "Allow ping requests to private services"
    }
  ]
}

then create them:
cf curl -X POST "/v3/security_groups" [email protected]

Tag your pair, your PM, and/or team

@danail-branekov, @georgethebeatle

@marsteg marsteg force-pushed the ms/ValidateSecGroups branch from 8fbe095 to fa724b3 Compare January 19, 2026 16:22
Copy link
Member

@danail-branekov danail-branekov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added minor style comments. However, I believe we need tests for the new logic in the validator

for i, rule := range rules {
if err := validateRuleDestination(rule.Destination); err != nil {
return fmt.Errorf("rules[%d]: %w", i, err)
if strings.Contains(rule.Destination, ",") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You do not need to check whether the string contains a comma or not, SplitSeq would return an iterator with a single element if not, or an iterator with multiple elements if so.

Consider the following example:

func main() {
	stringWithoutComma := "foo"
	stringWithComma := "bar,baz"

	fmt.Printf("slices.Collect(strings.SplitSeq(stringWithoutComma, \",\")) = %+v\n", slices.Collect(strings.SplitSeq(stringWithoutComma, ",")))
	fmt.Printf("slices.Collect(strings.SplitSeq(stringWitComma, \",\")) = %+v\n", slices.Collect(strings.SplitSeq(stringWithComma, ",")))
}

it produces

slices.Collect(strings.SplitSeq(stringWithoutComma, ",")) = [foo]
slices.Collect(strings.SplitSeq(stringWitComma, ",")) = [bar baz]

Having said that, you could iterate over the iterator directly, it does not make a difference whether the string contains commas or not

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i fixed that but Copilot is telling me, that this is buggy and I should just use strings.Split. What do you think - it could be wrong of course...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My initial thought was to use strings.Split but as you used SplitSeq I thought it should be all right. Maybe strings.Split would be simpler.
Out of curiosity, why does copilot think it is buggy?

@marsteg
Copy link
Contributor Author

marsteg commented Jan 20, 2026

I added some more tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants