-
Notifications
You must be signed in to change notification settings - Fork 74
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 variables endpoint #141
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for making this patch! I'm excited to use these features so I decided I'd offer some feedback.
nomad/api/variable.py
Outdated
if cas: | ||
params["cas"] = cas |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will prevent passing 0
as a cas
value. This should probably be cas is not None
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, it's a good point. I found it only when I wrote tests. Thanks!
nomad/api/variable.py
Outdated
if cas: | ||
params["cas"] = cas |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same feedback as before. This will prevent passing 0
as a cas
value. This should probably be cas is not None
except nomad.api.exceptions.URLNotFoundNomadException: | ||
return False | ||
|
||
def __getitem__(self, item): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it not be better to use the get_variable
API for this?
It also seems like, though convient, __getitem__
and __contains__
are expensive (making an API call and iterating through all variables) for every check. It also doesn't add value over using the Variable
interface.
There is some risk in making it convenient or too easy to do something expensive as it makes it more likely users will do the wrong thing. It might be worth considering either adding a cache or dropping these features in favor of Variable
. Or at least using Variable
under the hood to avoid the loop here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In reading through the rest of the library, it seems like this is a common pattern, so probably best to leave it as is for consistency baring a proposal to shift patterns.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was just a draft :)
I changed on get_variables
now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hah. Sorry for jumping the gun. I got excited.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NP :)
Thanks for your help!
Codecov Report
@@ Coverage Diff @@
## master #141 +/- ##
==========================================
+ Coverage 90.47% 91.26% +0.79%
==========================================
Files 28 31 +3
Lines 1155 1271 +116
==========================================
+ Hits 1045 1160 +115
- Misses 110 111 +1
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
@jonathanrcross @jrxFive I finished PR, could you review it, please? When we'll merge the PR I think we can release 1.5.0 (I changed the version in setup.py). @ViViDboarder Could you also re-review, please? It was just a draft and I wasn't ready for review 😄 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 looks good!
Added support for /var and /vars endpoints:
https://developer.hashicorp.com/nomad/api-docs/variables