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

✨ Add write_enabled in token resource #309

Merged

Conversation

keshy7
Copy link

@keshy7 keshy7 commented Dec 13, 2022

Add optional write_enabled in user's token resource.

Note that this change is dependent on PR 24 due to an inconsistency issue that currently exists in writable_token model: fbreckle/go-netbox#24

PR #24's description:
By default, Netbox's REST API sets User Token's write_enabled field to true. This means that if the field is not set explicitly in the request, Netbox would automatically set it to true.

This behavior results to an inconsistency if the value is set to false and omitempty is configured in the JSON tag. This is because by default, JSON Marshaller omits false booleans. Since the field is omitted, Netbox REST API would default it to true. Hence, an inconsistency would occur.

To fix this, simply remove the omitempty tag from the writable token.

References:

https://github.com/netbox-community/netbox/blob/21b9732f061b7e91fa77c10da66bd098510354fc/netbox/users/models.py#L216-L219

@fbreckle fbreckle marked this pull request as draft December 13, 2022 16:34
@keshy7 keshy7 marked this pull request as ready for review December 16, 2022 00:09
@keshy7
Copy link
Author

keshy7 commented Dec 20, 2022

Sorry, @fbreckle but this one requires a new release from https://github.com/fbreckle/go-netbox repo. May I please ask for a new release?

@keshy7 keshy7 marked this pull request as draft December 20, 2022 02:03
@fbreckle
Copy link
Collaborator

Hey! I do not do releases in the go-netbox library. You can just update the library ref by using go get github.com/fbreckle/go-netbox@<hash>
In this case, master is fbreckle/go-netbox@dfe7b62
So you can use go get github.com/fbreckle/go-netbox@dfe7b625a6fdbc0b62b69c3a10eb9c6d71f617fb to update the library on your branch. Then see if everything works. Please make a separate commit for the library update.

@keshy7 keshy7 force-pushed the AllowSetUserTokenWriteEnabledField branch from 738dddb to 5d28339 Compare December 21, 2022 00:55
@keshy7 keshy7 marked this pull request as ready for review December 21, 2022 00:55
Add optional write_enabled in user's token resource.

By default, Netbox's REST API sets User Token's write_enabled field to
true. This means that if the field is not set explicitly in the request,
Netbox would automatically set it to true.

This behavior results to an inconsistency if the value is set to false
and omitempty is configured in the JSON tag. This is because by default,
JSON Marshaller omits false booleans. Since the field is omitted,
Netbox REST API would default it to true. Hence, an inconsistency would
occur.

To fix this, simply remove the omitempty tag from the writable token.

References:
- fbreckle/go-netbox#24
- https://github.com/netbox-community/netbox/blob/21b9732f061b7e91fa77c10da66bd098510354fc/netbox/users/models.py#L216-L219
@keshy7 keshy7 force-pushed the AllowSetUserTokenWriteEnabledField branch from 5d28339 to 8715f4b Compare December 21, 2022 00:59
@keshy7
Copy link
Author

keshy7 commented Dec 21, 2022

Thank you again, @fbreckle! The changes are now in! 😄

@fbreckle
Copy link
Collaborator

Hm, the current master of go-netbox also contains fbreckle/go-netbox#23 which causes these errors.
I changed the order of the commits on go-netbox's master. Please use the go get... above with fbreckle/go-netbox@7a160aa
That does not contain the multi-tag changes.

Updated go-netbox dependency which included the change for
write_enabled.

References:
- fbreckle/go-netbox#24
@keshy7 keshy7 force-pushed the AllowSetUserTokenWriteEnabledField branch from 5d9886d to 59fcd2b Compare December 22, 2022 00:35
@keshy7
Copy link
Author

keshy7 commented Dec 22, 2022

Thank you @fbreckle! Sorry this taking too much work. The branch is now pointed one commit away (7a160aa9dcbb735a69936df9ee7ac45bc18719bd) from the master branch of go-netbox. Thank you again for your kind support

@fbreckle fbreckle merged commit 4de18f7 into e-breuninger:master Dec 22, 2022
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