-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into writeChoice
- Loading branch information
Showing
86 changed files
with
7,027 additions
and
636 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .account_management import * # noqa |
40 changes: 1 addition & 39 deletions
40
cli/medperf/account_management.py → .../account_management/account_management.py
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 @@ | ||
from .filesystem import FilesystemTokenStore as TokenStore # noqa |
50 changes: 50 additions & 0 deletions
50
cli/medperf/account_management/token_storage/filesystem.py
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,50 @@ | ||
import os | ||
import base64 | ||
from medperf.utils import base_storage_path, remove_path | ||
from medperf import config | ||
|
||
|
||
class FilesystemTokenStore: | ||
def __init__(self): | ||
self.creds_folder = base_storage_path(config.creds_folder) | ||
os.makedirs(self.creds_folder, exist_ok=True) | ||
|
||
def __get_paths(self, account_id): | ||
# Base64 encoding is used just to avoid facing a filesystem that doesn't support | ||
# special characters used in emails. | ||
account_id_encoded = base64.b64encode(account_id.encode("utf-8")).decode( | ||
"utf-8" | ||
) | ||
account_folder = os.path.join(self.creds_folder, account_id_encoded) | ||
os.makedirs(account_folder, exist_ok=True) | ||
|
||
access_token_file = os.path.join(account_folder, config.access_token_storage_id) | ||
refresh_token_file = os.path.join( | ||
account_folder, config.refresh_token_storage_id | ||
) | ||
|
||
return access_token_file, refresh_token_file | ||
|
||
def set_tokens(self, account_id, access_token, refresh_token): | ||
access_token_file, refresh_token_file = self.__get_paths(account_id) | ||
|
||
fd = os.open(access_token_file, os.O_CREAT | os.O_WRONLY, 0o600) | ||
os.write(fd, access_token.encode("utf-8")) | ||
os.close(fd) | ||
|
||
fd = os.open(refresh_token_file, os.O_CREAT | os.O_WRONLY, 0o600) | ||
os.write(fd, refresh_token.encode("utf-8")) | ||
os.close(fd) | ||
|
||
def read_tokens(self, account_id): | ||
access_token_file, refresh_token_file = self.__get_paths(account_id) | ||
with open(access_token_file) as f: | ||
access_token = f.read() | ||
with open(refresh_token_file) as f: | ||
refresh_token = f.read() | ||
return access_token, refresh_token | ||
|
||
def delete_tokens(self, account_id): | ||
access_token_file, refresh_token_file = self.__get_paths(account_id) | ||
remove_path(access_token_file) | ||
remove_path(refresh_token_file) |
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,43 @@ | ||
"""Keyring token storage is NOT used. We used it before this commit but | ||
users who connect to remote machines through passwordless SSH faced some issues.""" | ||
|
||
import keyring | ||
from medperf import config | ||
|
||
|
||
class KeyringTokenStore: | ||
def __init__(self): | ||
pass | ||
|
||
def set_tokens(self, account_id, access_token, refresh_token): | ||
keyring.set_password( | ||
config.access_token_storage_id, | ||
account_id, | ||
access_token, | ||
) | ||
keyring.set_password( | ||
config.refresh_token_storage_id, | ||
account_id, | ||
refresh_token, | ||
) | ||
|
||
def read_tokens(self, account_id): | ||
access_token = keyring.get_password( | ||
config.access_token_storage_id, | ||
account_id, | ||
) | ||
refresh_token = keyring.get_password( | ||
config.refresh_token_storage_id, | ||
account_id, | ||
) | ||
return access_token, refresh_token | ||
|
||
def delete_tokens(self, account_id): | ||
keyring.delete_password( | ||
config.access_token_storage_id, | ||
account_id, | ||
) | ||
keyring.delete_password( | ||
config.refresh_token_storage_id, | ||
account_id, | ||
) |
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
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
Oops, something went wrong.