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 variables endpoint #141

Merged
merged 9 commits into from
Nov 29, 2022
Merged

Conversation

nikita-b
Copy link
Collaborator

@nikita-b nikita-b commented Nov 15, 2022

Added support for /var and /vars endpoints:
https://developer.hashicorp.com/nomad/api-docs/variables

Copy link

@ViViDboarder ViViDboarder left a 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.

Comment on lines 62 to 63
if cas:
params["cas"] = cas

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

Copy link
Collaborator Author

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!

Comment on lines 87 to 88
if cas:
params["cas"] = cas

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):

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.

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.

Copy link
Collaborator Author

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.

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.

Copy link
Collaborator Author

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-commenter
Copy link

codecov-commenter commented Nov 20, 2022

Codecov Report

Merging #141 (2f20dad) into master (da760de) will increase coverage by 0.79%.
The diff coverage is 97.45%.

@@            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     
Impacted Files Coverage Δ
nomad/api/namespaces.py 57.50% <0.00%> (ø)
nomad/api/search.py 95.83% <95.83%> (ø)
nomad/__init__.py 98.50% <100.00%> (+0.14%) ⬆️
nomad/api/__init__.py 100.00% <100.00%> (ø)
nomad/api/base.py 96.62% <100.00%> (+0.07%) ⬆️
nomad/api/exceptions.py 100.00% <100.00%> (ø)
nomad/api/variable.py 100.00% <100.00%> (ø)
nomad/api/variables.py 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@nikita-b nikita-b marked this pull request as ready for review November 20, 2022 21:19
@nikita-b
Copy link
Collaborator Author

@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 😄

CHANGELOG.md Show resolved Hide resolved
docs/api/variables.md Outdated Show resolved Hide resolved
nomad/api/variables.py Show resolved Hide resolved
Copy link

@ViViDboarder ViViDboarder left a comment

Choose a reason for hiding this comment

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

Great! Thanks!

Copy link
Collaborator

@jonathanrcross jonathanrcross left a comment

Choose a reason for hiding this comment

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

+1 looks good!

@nikita-b nikita-b merged commit 1463307 into jrxFive:master Nov 29, 2022
@nikita-b nikita-b deleted the add_variables_endpoint branch November 29, 2022 12:06
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.

4 participants