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

Validate against forbidden fields #232

Merged
merged 4 commits into from
Sep 12, 2024
Merged

Conversation

wejdross
Copy link
Member

Summary

  • Stackgres refuses usage of few configuration options and our customers shouldn't be able to set them. This PR ensures there're no possibility to create instance with broken parameters.

Checklist

  • Categorize the PR by setting a good title and adding one of the labels:
    bug, enhancement, documentation, change, breaking, dependency
    as they show up in the changelog
  • Update tests.
  • Link this PR to related issues.

}

for key, _ := range pgConf {
if key == "listen_addresses" {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you please define a list of forbidden pg parameters on top of this file and instead of having multiple if clauses to just have one? I would also consider create a new go file to separate the concerns and make it a bit more readable

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree, having a map of forbidden keys would be more readable. You can use the maps key for the field name, so you can efficiently do checks. Then use the value of the map to store the specifics of the error.

It would also be easier to extend or change in the future.

Copy link
Collaborator

@zugao zugao Sep 12, 2024

Choose a reason for hiding this comment

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

The errors seems to be almost the same, only the name is added to a field. I would still go with just a list.

}

for key, _ := range pgConf {
if key == "listen_addresses" {
Copy link
Contributor

Choose a reason for hiding this comment

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

I agree, having a map of forbidden keys would be more readable. You can use the maps key for the field name, so you can efficiently do checks. Then use the value of the map to store the specifics of the error.

It would also be easier to extend or change in the future.

zugao
zugao previously requested changes Sep 12, 2024
}
}

blocklist := map[string]string{
Copy link
Collaborator

Choose a reason for hiding this comment

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

why did you create a map if the values are empty? Please change to a list and move it outside the function at the top of the file. Our code is already very confusing, lets not make it a pain to read.

Copy link
Contributor

Choose a reason for hiding this comment

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

The idea for the map is that we don't have nested loops, so I would keep it as such.

But I agree to move it to the top.

Copy link
Collaborator

@zugao zugao Sep 12, 2024

Choose a reason for hiding this comment

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

You meant that there's no good way to search in the list? I forgot how bad go is in that regard... but there are packages that help with finding an object in the list... I would still have gone with the list... it hearts my eyes to see empty strings there, it feels like they will be filled during a for loop....

Copy link
Member Author

Choose a reason for hiding this comment

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

finding an element in array is the same operation in each language, finding key in map is O(1) . O(n^2) You suggest would hurt my eyes ;p

@wejdross wejdross dismissed stale reviews from zugao and Kidswiss September 12, 2024 11:36

solved

Copy link
Collaborator

@zugao zugao left a comment

Choose a reason for hiding this comment

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

LGTM

@wejdross wejdross merged commit 2ec5fab into master Sep 12, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working patch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants