-
Notifications
You must be signed in to change notification settings - Fork 339
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
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
aa8207d
Add get_users() bulk lookup method
rsgowman a83f66e
Add delete_users() bulk deletion method
rsgowman c5f57d0
add last_refresh_timestamp
rsgowman 0e282f7
Fix lint error
rsgowman 070c1a8
fixup! Add delete_users() bulk deletion method
rsgowman 466890b
Remove force_delete flag
rsgowman 598ffc9
review feedback (except iso8601)
rsgowman 1993007
Add (missing) bulk lookup by provider
rsgowman 0b18203
Remove iso8601 dependency.
rsgowman 65d7d63
review feedback 2
rsgowman b21f23e
review feedback 3
rsgowman d4a8a3e
(mostly) doc review feedback
rsgowman 3c6b776
Merge remote-tracking branch 'origin/master' into rsgowman/bulk_getde…
rsgowman 2167764
Merge remote-tracking branch 'origin/master' into rsgowman/bulk_getde…
rsgowman 9ade7a8
Fixes to address changes since last merge master
rsgowman 278ee4a
Doc nits
rsgowman 7087016
lint
rsgowman 5990d44
Merge remote-tracking branch 'origin/master' into rsgowman/bulk_getde…
rsgowman ba60c65
more review feedback
rsgowman e9dafc1
combine validate/assign in ctor
rsgowman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# 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): | ||
"""Parse 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; 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: | ||
return datetime.strptime(datestr_modified, '%Y-%m-%dT%H:%M:%S.%f%z') | ||
except ValueError: | ||
pass | ||
|
||
try: | ||
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)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
# 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.""" | ||
|
||
from firebase_admin import _auth_utils | ||
|
||
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` object. | ||
|
||
Args: | ||
uid: A user ID string. | ||
""" | ||
self._uid = _auth_utils.validate_uid(uid, required=True) | ||
|
||
@property | ||
def uid(self): | ||
return self._uid | ||
|
||
|
||
class EmailIdentifier(UserIdentifier): | ||
"""Used for looking up an account by email. | ||
|
||
See ``auth.get_user()``. | ||
""" | ||
|
||
def __init__(self, email): | ||
"""Constructs a new `EmailIdentifier` object. | ||
|
||
Args: | ||
email: A user email address string. | ||
""" | ||
self._email = _auth_utils.validate_email(email, required=True) | ||
|
||
@property | ||
def email(self): | ||
return self._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` object. | ||
|
||
Args: | ||
phone_number: A phone number string. | ||
""" | ||
self._phone_number = _auth_utils.validate_phone(phone_number, required=True) | ||
|
||
@property | ||
def phone_number(self): | ||
return self._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` object. | ||
|
||
Args: | ||
provider_id: A provider ID string. | ||
provider_uid: A provider UID string. | ||
""" | ||
self._provider_id = _auth_utils.validate_provider_id(provider_id, required=True) | ||
self._provider_uid = _auth_utils.validate_provider_uid( | ||
provider_uid, required=True) | ||
|
||
@property | ||
def provider_id(self): | ||
return self._provider_id | ||
|
||
@property | ||
def provider_uid(self): | ||
return self._provider_uid |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -472,7 +472,12 @@ def standard_scrypt(cls, memory_cost, parallelization, block_size, derived_key_l | |
|
||
|
||
class ErrorInfo: | ||
"""Represents an error encountered while importing an ``ImportUserRecord``.""" | ||
"""Represents an error encountered while performing a batch operation such | ||
as importing users or deleting multiple user accounts. | ||
""" | ||
# TODO(rsgowman): This class used to be specific to importing users (hence | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. _auth_utils could be a good place. But feel free to defer that to future PR. |
||
# it's home in _user_import.py). It's now also used by bulk deletion of | ||
# users. Move this to a more common location. | ||
|
||
def __init__(self, error): | ||
self._index = error['index'] | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.