diff --git a/.gitignore b/.gitignore index acb6bcd..5cdff3c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .idea/ **/__pycache__/ +**/.env* diff --git a/api-client/eg.py b/api-client/eg.py index b07c1ac..e5d38cf 100644 --- a/api-client/eg.py +++ b/api-client/eg.py @@ -1,6 +1,19 @@ from requests_oauthlib import OAuth2Session from oauthlib.oauth2 import BackendApplicationClient +from dotenv import load_dotenv +import os +environment_name = os.getenv('ENV_NAME', 'qa') # need to find a place for this +dotenv_path = f'.env.{environment_name}' +load_dotenv(dotenv_path) + +client_id = os.getenv('CLIENT_ID') +client_secret = os.getenv('CLIENT_SECRET') +token_url = os.getenv('TOKEN_URL') +username = os.getenv('USERNAME') +password = os.getenv('PASSWORD') +audience = os.getenv('AUDIENCE') +scope = os.getenv('SCOPE', '').split(',') def get_token(client_id, client_secret, token_url, username, password, audience, scope): client = BackendApplicationClient(client_id=client_id) diff --git a/env_template b/env_template new file mode 100644 index 0000000..b76f9c7 --- /dev/null +++ b/env_template @@ -0,0 +1,8 @@ +URL=https://api.dummy.com +CLIENT_ID=client_id +CLIENT_SECRET=client_secret +TOKEN_URL=oauth_token_fetch_url +USERNAME=username +PASSWORD=password +AUDIENCE=intended_audience +SCOPES=scope1,scope2 diff --git a/requirements.txt b/requirements.txt index a2003b5..d0d9acd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ oauthlib~=3.2.2 requests~=2.32.3 -requests-oauthlib~=2.0.0 \ No newline at end of file +requests-oauthlib~=2.0.0 +python-dotenv~=1.0.1 \ No newline at end of file