-
Notifications
You must be signed in to change notification settings - Fork 27
WIP: feat: add userdata api to SDK #17
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
Conversation
Shouldn't this code belong to the MetadataAPI object instead? |
scaleway/apis/api_userdata.py
Outdated
False, return a dictionary. | ||
""" | ||
with requests.Session() as s: | ||
s.mount('http://', SourcePortAdapter(random.randrange(1, 1024))) |
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.
IMO, we should loop from 1 to 1024 and catch errors instead of using random.randrange()
which could raise (even if it's unlikely). Using random could cause inconsistent results.
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.
With a loop, how do you handle the multiple runs of the SDK? As when you query the API with a specific port, this port is "block" and the socket remains open for a few minutes. Using a random.randrange
copy the functioning of the curl --local-port 1-1024 http://169.254.42.42/user_data
command.
scaleway/apis/api_userdata.py
Outdated
|
||
if as_shell: | ||
return s.get('%s/user_data' % self.base_url).text | ||
return s.get('%s/user_data?format=json' % self.base_url).text |
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.
You might want to return a dict here, not .text
scaleway/apis/api_userdata.py
Outdated
|
||
super(UserDataAPI, self).__init__(auth_token=None, **kwargs) | ||
|
||
def get_userdata(self, as_shell=False): |
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.
Actually this calls returns the list of userdata keys, not the values.
How do you want to handle the multiline values for a key with the
|
Codecov Report
@@ Coverage Diff @@
## develop #17 +/- ##
=======================================
- Coverage 100% 0% -100%
=======================================
Files 4 4
Lines 83 117 +34
Branches 15 19 +4
=======================================
- Hits 83 0 -83
- Misses 0 117 +117
Continue to review full report at Codecov.
|
Hello!
This PR implement the reading of
user_data
information from the SDK. As this feature need to call thebase_url
with a privileged port, I had to override the python requests object.Regarding the unit tests, I didn't find an elegant way to integrate them except mocking get
get_userdata
method and compare the result to a string (which is basically comparing two static strings). If you have any piece of advice about it, I would be more than happy to integrate them.