-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Migrate API key-related functions to API Keys service, deprecated in User service - Migrate unit tests, re-record cassettes as needed
- Loading branch information
Showing
12 changed files
with
246 additions
and
110 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,45 @@ | ||
from typing import ( | ||
Any, | ||
Dict, | ||
List, | ||
) | ||
|
||
from easypost.easypost_object import convert_to_easypost_object | ||
from easypost.models import ApiKey | ||
from easypost.requestor import ( | ||
RequestMethod, | ||
Requestor, | ||
) | ||
from easypost.services.base_service import BaseService | ||
|
||
|
||
class ApiKeyService(BaseService): | ||
def __init__(self, client): | ||
self._client = client | ||
self._model_class = ApiKey.__name__ | ||
|
||
def all(self) -> Dict[str, Any]: | ||
"""Retrieve a list of all API keys.""" | ||
url = "/api_keys" | ||
|
||
response = Requestor(self._client).request(method=RequestMethod.GET, url=url) | ||
|
||
return convert_to_easypost_object(response=response) | ||
|
||
def retrieve_api_keys_for(self, id: str) -> List[ApiKey]: | ||
"""Retrieve a list of API keys (works for the authenticated User or a child User).""" | ||
api_keys = self.all() | ||
my_api_keys = [] | ||
|
||
if api_keys["id"] == id: | ||
# This function was called on the authenticated user | ||
my_api_keys = api_keys["keys"] | ||
else: | ||
# This function was called on a child user (authenticated as parent, only return | ||
# this child user's details). | ||
for child in api_keys["children"]: | ||
if child.id == id: | ||
my_api_keys = child.keys | ||
break | ||
|
||
return my_api_keys |
This file contains 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
14 changes: 8 additions & 6 deletions
14
tests/cassettes/test_user_all_api_keys.yaml → tests/cassettes/test_all_api_keys.yaml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.