remove: env support

This commit is contained in:
jcbirdwell 2023-12-19 13:59:35 -06:00
commit 5f1945ae05
2 changed files with 2 additions and 32 deletions

View file

@ -2,7 +2,6 @@ import json
import time import time
import webbrowser import webbrowser
from typing import Dict, Optional, Any from typing import Dict, Optional, Any
from os import environ as env
import os import os
import requests import requests
@ -88,23 +87,6 @@ class OAuthToken:
class OAuthCredentials: class OAuthCredentials:
@classmethod
def from_env(cls,
session: Optional[requests.Session] = None,
proxies: Optional[Dict] = None,
*,
client_id_key='YTMA_OAUTH_CLIENT_ID',
client_secret_key='YTMA_OAUTH_CLIENT_SECRET'):
missing_keys = [x for x in [client_id_key, client_secret_key] if x not in env]
if missing_keys:
raise KeyError('Failed to build credentials from environment. Missing required keys: ',
missing_keys)
return cls(client_id=env[client_id_key],
client_secret=env[client_secret_key],
session=session,
proxies=proxies)
def __init__(self, def __init__(self,
client_id: Optional[str] = OAUTH_CLIENT_ID, client_id: Optional[str] = OAUTH_CLIENT_ID,
client_secret: Optional[str] = OAUTH_CLIENT_SECRET, client_secret: Optional[str] = OAUTH_CLIENT_SECRET,

View file

@ -26,7 +26,6 @@ def setup_oauth(filepath: str = None,
session: requests.Session = None, session: requests.Session = None,
proxies: dict = None, proxies: dict = None,
open_browser: bool = False, open_browser: bool = False,
env_credentials: bool = False,
client_id: str = None, client_id: str = None,
client_secret: str = None) -> Dict: client_secret: str = None) -> Dict:
""" """
@ -37,13 +36,8 @@ def setup_oauth(filepath: str = None,
:param proxies: Proxies to use for authentication :param proxies: Proxies to use for authentication
:param filepath: Optional filepath to store headers to. :param filepath: Optional filepath to store headers to.
:param open_browser: If True, open the default browser with the setup link :param open_browser: If True, open the default browser with the setup link
:param env_credentials: Optional. Specifies if client_id and client_secret should be
pulled from the environment. Modifies client_id and client_secret parameters to
instead specify the keys to search environment for. Default keys are
YTMA_OAUTH_CLIENT_ID for client_id and YTMA_OAUTH_CLIENT_SECRET for secret.
:param client_id: Optional. Used to specify the client_id oauth should use for authentication :param client_id: Optional. Used to specify the client_id oauth should use for authentication
flow. If used with env_credentials, instead specifies the environmental key of client_id. flow. If provided, client_secret MUST also be passed or both will be ignored.
If not used with env_credentials, client_secret MUST also be passed or both will be ignored.
:param client_secret: Optional. Same as client_id but for the oauth client secret. :param client_secret: Optional. Same as client_id but for the oauth client secret.
:return: configuration headers string :return: configuration headers string
@ -51,13 +45,7 @@ def setup_oauth(filepath: str = None,
if not session: if not session:
session = requests.Session() session = requests.Session()
if env_credentials: if client_id and client_secret:
oauth_credentials = OAuthCredentials.from_env(session,
proxies,
client_id_key=client_id,
client_secret_key=client_secret)
elif client_id and client_secret:
oauth_credentials = OAuthCredentials(client_id, client_secret, session, proxies) oauth_credentials = OAuthCredentials(client_id, client_secret, session, proxies)
else: else: