Open
Conversation
brokensound77
commented
Aug 12, 2023
| creds: Optional[CRED_TYPES] | ||
| session: Optional[Credentials] | ||
|
|
||
| def session(self, scopes: Optional[list[str]] = None) -> Optional[Credentials]: |
Contributor
Author
There was a problem hiding this comment.
to get a session, just call this method, with optional scopes
brokensound77
commented
Aug 12, 2023
| self.custom_config = yaml.safe_load(custom_path.read_text()) if custom_path.exists() else {} | ||
|
|
||
| @property | ||
| def merged(self) -> dict: |
Contributor
Author
There was a problem hiding this comment.
when getting items, use this property
when setting, set directly to custom_config - these are all saved on exit
brokensound77
commented
Aug 12, 2023
| raise argparse.ArgumentError(self, f'invalid filter argument "{value}", expected "key=value"') | ||
| setattr(namespace, self.dest, {key: val}) | ||
|
|
||
|
|
Contributor
Author
There was a problem hiding this comment.
This command is failing, but I think unrelated?
brokensound77
commented
Aug 12, 2023
| self.folder_id = self.args.folder_id | ||
| self.service = build('drive', 'v3', credentials=self.obj.cred_store.store[self.args.session_key].session) | ||
| creds = self.obj.cred_store.get('default', validate_type='oauth') | ||
| self.service = build('drive', 'v3', credentials=creds.session()) |
Contributor
Author
There was a problem hiding this comment.
creds.session()!
brokensound77
commented
Aug 12, 2023
| def main(): | ||
| parser = argparse.ArgumentParser(description='SWAT CLI') | ||
| parser.add_argument('--debug', action='store_true', help='Debug mode') | ||
| parser.add_argument('--custom-config', type=Path, default=DEFAULT_CUSTOM_CONFIG_PATH, |
Contributor
Author
There was a problem hiding this comment.
default custom but optional param
brokensound77
commented
Aug 12, 2023
| finally: | ||
| if shell.save_on_exit: | ||
| shell.obj.cred_store.save() | ||
| shell.obj.config.save_custom() |
Contributor
Author
There was a problem hiding this comment.
saved on exit
329d857 to
559fe5c
Compare
Contributor
Author
gets error Looks like |
Contributor
class OAuthCreds(BaseCreds):
"""Data class for OAuth2.0 application credentials."""
auth_provider_x509_cert_url: str
auth_uri: str
client_id: str
client_secret: str
project_id: str
redirect_uris: list[str]
token_uri: str
refresh_token: str = None |
|
|
||
| def session(self, scopes: Optional[list[str]] = None) -> Optional[Credentials]: | ||
| if isinstance(self.creds, OAuthCreds): | ||
| session = Credentials.from_authorized_user_info(self.creds.to_dict(), scopes=scopes) |
Contributor
There was a problem hiding this comment.
Suggested change
| session = Credentials.from_authorized_user_info(self.creds.to_dict(), scopes=scopes) | |
| session = Credentials.from_authorized_user_info(self.creds.to_dict()['installed'], scopes=scopes) |
| if isinstance(self.creds, OAuthCreds): | ||
| session = Credentials.from_authorized_user_info(self.creds.to_dict(), scopes=scopes) | ||
| else: | ||
| session = ServiceCredentials.from_service_account_info(self.creds.to_dict(), scopes=scopes) |
Contributor
There was a problem hiding this comment.
Suggested change
| session = ServiceCredentials.from_service_account_info(self.creds.to_dict(), scopes=scopes) | |
| session = ServiceCredentials.from_service_account_info(self.creds.to_dict()['installed'], scopes=scopes) |
Contributor
|
Some additional thoughts here:
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The commands for scopes and auth have been removed.
Cred, simply by usingCred.session()with scopes as an optional parameter