purpleidea / mgmt

Next generation distributed, event-driven, parallel config management!
https://purpleidea.com/tags/mgmtconfig/
GNU General Public License v3.0
3.67k stars 315 forks source link

lang: structs: Fix duplicate resource field bug #605

Closed adamsigal closed 3 years ago

adamsigal commented 4 years ago

Add extra verification in Init() to prevent a resource with multiple instances of the same field from being validated.

Tips:

topic: Capitalized message with no trailing period

or:

topic, topic2: Capitalized message with no trailing period

make gofmt      # formats the entire project correctly

or format a single golang file correctly:

gofmt -w yourcode.go
git checkout master
git pull origin master
git checkout your-feature
git rebase master
git push your-remote your-feature
hub pull-request    # or submit with the github web ui
# make changes based on reviews...
git add -p      # add new changes
git commit --amend  # combine with existing commit
git push your-remote your-feature -f
# now ping @purpleidea in the github PR since it doesn't notify us automatically

Thanks for contributing to mgmt and welcome to the team!

purpleidea commented 4 years ago

@adamsigal FYI, this was never reviewed because the tests failed. The convention is that a PR will be ignored if the tests failed unless you leave a comment explaining why the failure is not your fault or you need help understanding it.

adamsigal commented 4 years ago

@adamsigal FYI, this was never reviewed because the tests failed. The convention is that a PR will be ignored if the tests failed unless you leave a comment explaining why the failure is not your fault or you need help understanding it.

I actually realised that the tests didn't pass, that's why I didn't mention it on IRC ¯_(ツ)_/¯

purpleidea commented 3 years ago

Heya, I've had to close this because I replaced it with a finished version.

I also added the meta dupes checking, so my version is a bit more complicated, but in case you're curious in the learning experience...

Here:

https://github.com/purpleidea/mgmt/commit/a45b7a1d8872d9fc3abbe8bccbb99df3aeea248f#diff-475d0aedee767145087b385c3ea097461792ffe83edac562c8263bb0e51e69b0R321

You can see how we look at the type of the thing, and switch into it before looking at it. We can't use foo.String() because:

1) That's a bigger representation that wouldn't guarantee us unique fields, and 2) We don't want to examine Edges for example.

If you have questions or want to jump back in, please LMK =D