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

keys API #212

Merged
merged 1 commit into from
Jun 7, 2018
Merged

keys API #212

merged 1 commit into from
Jun 7, 2018

Conversation

Zil0
Copy link
Contributor

@Zil0 Zil0 commented May 19, 2018

Follows #209 and is based on the work of @pik at pik@f855cb8.

This can already be looked at, I tagged it WIP because I didn't add tests yet.

Copy link
Collaborator

@non-Jedi non-Jedi left a comment

Choose a reason for hiding this comment

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

Still need to review substance of PR, but if you could correct same set of stylistic nits as pointed out in #210, that'd be fantastic. Also signoff please. Thanks!


def key_changes(self, from_token, to_token):
"""Gets a list of users who have updated their device identity keys
since a previous sync token.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should be a single line summary.

@non-Jedi non-Jedi self-requested a review May 20, 2018 22:19
@Zil0 Zil0 force-pushed the API_key branch 2 times, most recently from 921ff67 to fd2c43a Compare May 21, 2018 12:54
@Zil0 Zil0 changed the title [WIP] keys API keys API May 21, 2018
@Zil0
Copy link
Contributor Author

Zil0 commented May 21, 2018

Addressed stylistic issues and added tests.

@non-Jedi non-Jedi assigned non-Jedi and unassigned Zil0 May 21, 2018
@non-Jedi non-Jedi self-requested a review May 21, 2018 14:11
@non-Jedi
Copy link
Collaborator

@Zil0 could you rebase on master please to make review easier?

@Zil0
Copy link
Contributor Author

Zil0 commented May 21, 2018

done :)

Copy link
Collaborator

@non-Jedi non-Jedi left a comment

Choose a reason for hiding this comment

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

Other than that, LGTM. Thanks!

@@ -836,3 +836,76 @@ def delete_devices(self, auth_body, devices):
"devices": devices
}
return self._send("POST", "/delete_devices", content=content)

def upload_keys(self, device_keys={}, one_time_keys={}):
Copy link
Collaborator

Choose a reason for hiding this comment

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

kwargs shouldn't have mutable objects as their default argument. We do this elsewhere in the sdk, and it's wrong. What effectively happens is that the same dictionary (which is mutable) gets reused each time this method is called and could potentially be non-empty in the future.

Said device must be the one used when logging in.

Args:
device_keys (dict): Optional. Identity keys for the device.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should give info about the format of this arg in the docstring. Same for below.

content["one_time_keys"] = one_time_keys
return self._send("POST", "/keys/upload", content=content)

def query_user_keys(self, user_id):
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is a higher level method that I don't think belongs in this class.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

right, same for claim_key then?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

assumed it was

"""Query HS for public keys by user and optionally device.

Args:
user_devices (dict): The devices whose keys to download. Should be
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please format these for rst as seen in other method docstrings where args need multi-line explanations.

"""
return self.query_keys({user_id: []})

def query_keys(self, user_devices, timeout=None):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, I wasn't looking at unstable :)

"""Gets a list of users who have updated their device identity keys.

Args:
from_token (str): The desired start point of the list.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please explicitly state that this should be taken from next_batch field of a sync response.


@responses.activate
@pytest.mark.parametrize("args", [
{},
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't really entirely understand pytest. Where is this empty dict going? upload_keys only takes two arguments, not three.

Copy link
Contributor Author

@Zil0 Zil0 May 22, 2018

Choose a reason for hiding this comment

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

https://docs.pytest.org/en/latest/parametrize.html
The test is called 3 times, one with {} which stands for no argument, then with device_keys set, then with one_time_keys. Not sure why I didn't do a fourth test with both set. Then we call the API method with the arguments found in args.
If this is too confusing for what it is, I can go back to copy-pasting, which won't make much difference seeing the rest of the file :)

@Zil0
Copy link
Contributor Author

Zil0 commented May 22, 2018

Making the changes but before I forget again:
Signed-off-by: Valentin Deniaud <valentin.deniaud@inpt.fr>

along with some helpers
@Zil0
Copy link
Contributor Author

Zil0 commented May 22, 2018

fixed :)

@non-Jedi non-Jedi assigned non-Jedi and unassigned Zil0 May 22, 2018
@non-Jedi
Copy link
Collaborator

non-Jedi commented Jun 7, 2018

LGTM. Thanks!

@non-Jedi non-Jedi merged commit 882cdfe into matrix-org:master Jun 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants