-
Couldn't load subscription status.
- Fork 344
feat(auth): Add bulk get/delete methods #400
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
Changes from 9 commits
aa8207d
a83f66e
c5f57d0
0e282f7
070c1a8
466890b
598ffc9
1993007
0b18203
65d7d63
b21f23e
d4a8a3e
3c6b776
2167764
9ade7a8
278ee4a
7087016
5990d44
ba60c65
e9dafc1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| # Copyright 2020 Google Inc. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| """Parse RFC3339 date strings""" | ||
|
|
||
| from datetime import datetime, timezone | ||
| import re | ||
|
|
||
| def parse_to_epoch(datestr): | ||
| """Parses an RFC3339 date string and return the number of seconds since the | ||
| epoch (as a float). | ||
|
|
||
| In particular, this method is meant to parse the strings returned by the | ||
| JSON mapping of protobuf google.protobuf.timestamp.Timestamp instances: | ||
| https://github.com/protocolbuffers/protobuf/blob/4cf5bfee9546101d98754d23ff378ff718ba8438/src/google/protobuf/timestamp.proto#L99 | ||
|
|
||
| This method has microsecond precision; i.e. nanoseconds will be truncated. | ||
|
||
|
|
||
| Args: | ||
| datestr: A string in RFC3339 format. | ||
| Returns: | ||
| Float: The number of seconds since the unix epoch. | ||
|
||
| Raises: | ||
| ValueError: Raised if the datestr is not a valid RFC3339 date string. | ||
|
||
| """ | ||
| return _parse_to_datetime(datestr).timestamp() | ||
|
|
||
|
|
||
| def _parse_to_datetime(datestr): | ||
| """Parse an RFC3339 date string and return a python datetime instance. | ||
|
|
||
| Args: | ||
| datestr: A string in RFC3339 format. | ||
| Returns: | ||
| datetime: The corresponding datetime (with timezone information). | ||
|
||
| Raises: | ||
| ValueError: Raised if the datestr is not a valid RFC3339 date string. | ||
|
||
| """ | ||
| # If more than 6 digits appear in the fractional seconds position, truncate | ||
| # to just the most significant 6. (i.e. we only have microsecond precision; | ||
| # nanos are truncated.) | ||
| datestr_modified = re.sub(r'(\.\d{6})\d*', r'\1', datestr) | ||
|
|
||
| # This format is the one we actually expect to occur from our backend. The | ||
| # others are only present because the spec says we *should* accept them. | ||
| try: | ||
| return datetime.strptime( | ||
| datestr_modified, '%Y-%m-%dT%H:%M:%S.%fZ' | ||
| ).replace(tzinfo=timezone.utc) | ||
| except ValueError: | ||
| pass | ||
|
|
||
| try: | ||
| return datetime.strptime( | ||
| datestr_modified, '%Y-%m-%dT%H:%M:%SZ' | ||
| ).replace(tzinfo=timezone.utc) | ||
| except ValueError: | ||
| pass | ||
|
|
||
| # Note: %z parses timezone offsets, but requires the timezone offset *not* | ||
| # include a separating ':'. As of python 3.7, this was relaxed. | ||
| # TODO(rsgowman): Once python3.7 becomes our floor, we can drop the regex | ||
| # replacement. | ||
| datestr_modified = re.sub(r'(\d\d):(\d\d)$', r'\1\2', datestr_modified) | ||
|
|
||
| try: | ||
| print("trying with micros") | ||
|
||
| return datetime.strptime(datestr_modified, '%Y-%m-%dT%H:%M:%S.%f%z') | ||
| except ValueError: | ||
| pass | ||
|
|
||
| try: | ||
| print("trying without micros") | ||
| return datetime.strptime(datestr_modified, '%Y-%m-%dT%H:%M:%S%z') | ||
| except ValueError: | ||
| pass | ||
|
|
||
| raise ValueError('time data {0} does not match RFC3339 format'.format(datestr)) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| # Copyright 2020 Google Inc. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| """Classes to uniquely identify a user.""" | ||
|
|
||
| class UserIdentifier: | ||
| """Identifies a user to be looked up.""" | ||
|
|
||
hiranya911 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| class UidIdentifier(UserIdentifier): | ||
| """Used for looking up an account by uid. | ||
|
|
||
| See ``auth.get_user()``. | ||
| """ | ||
|
|
||
| def __init__(self, uid): | ||
| """Constructs a new UidIdentifier. | ||
|
|
||
| Args: | ||
| uid: A user ID string. | ||
| """ | ||
| self.uid = uid | ||
|
||
|
|
||
|
|
||
| class EmailIdentifier(UserIdentifier): | ||
| """Used for looking up an account by email. | ||
|
|
||
| See ``auth.get_user()``. | ||
| """ | ||
|
|
||
| def __init__(self, email): | ||
| """Constructs a new EmailIdentifier. | ||
|
||
|
|
||
| Args: | ||
| email: A user email address string. | ||
| """ | ||
| self.email = email | ||
|
|
||
|
|
||
| class PhoneIdentifier(UserIdentifier): | ||
| """Used for looking up an account by phone number. | ||
|
|
||
| See ``auth.get_user()``. | ||
| """ | ||
|
|
||
| def __init__(self, phone_number): | ||
| """Constructs a new PhoneIdentifier. | ||
|
|
||
| Args: | ||
| phone_number: A phone number string. | ||
| """ | ||
| self.phone_number = phone_number | ||
|
|
||
|
|
||
| class ProviderIdentifier(UserIdentifier): | ||
| """Used for looking up an account by provider. | ||
|
|
||
| See ``auth.get_user()``. | ||
| """ | ||
|
|
||
| def __init__(self, provider_id, provider_uid): | ||
| """Constructs a new ProviderIdentifier. | ||
|
||
|
|
||
| Args: | ||
| provider_id: A provider ID string. | ||
| provider_uid: A provider UID string. | ||
| """ | ||
| self.provider_id = provider_id | ||
| self.provider_uid = provider_uid | ||
Uh oh!
There was an error while loading. Please reload this page.
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.
Suggest "Parse . . . and return"
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.
Done.