-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clean up some http code+tests, and add auth setup documentation #40
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,8 @@ | |
import keyring | ||
import requests | ||
|
||
from canvas_sdk.utils import Http | ||
|
||
# Keyring namespace we'll use | ||
KEYRING_SERVICE = __name__ | ||
|
||
|
@@ -32,7 +34,23 @@ def get_config() -> configparser.ConfigParser: | |
"""Reads the config file and returns a ConfigParser object.""" | ||
config = configparser.ConfigParser() | ||
if not config.read(CONFIG_PATH): | ||
raise Exception(f"Please add your configuration file at '{CONFIG_PATH}'") | ||
raise Exception( | ||
f"""Please add your configuration file at '{CONFIG_PATH}' with the following format: | ||
|
||
[my-canvas-instance] | ||
client_id=myclientid | ||
client_secret=myclientsecret | ||
|
||
[my-dev-canvas-instance] | ||
client_id=devclientid | ||
client_secret=devclientsecret | ||
is_default=true | ||
|
||
[localhost] | ||
client_id=localclientid | ||
client_secret=localclientsecret | ||
""" | ||
) | ||
return config | ||
|
||
|
||
|
@@ -65,14 +83,16 @@ def get_default_host(host: str | None = None) -> str: | |
(host for host in hosts if config.getboolean(host, "is_default", fallback=False) is True), | ||
hosts[0], | ||
) | ||
if first_default_host == 'localhost': | ||
if first_default_host == "localhost": | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In ruby There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we using black and isort on this project? I always type There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It appears we are and I just haven't installed the pre-commit hooks. My bad. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I appreciate your focus on developer efficiency, btw. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sometimes laziness and efficiency are the same thing |
||
return "http://localhost:8000" | ||
|
||
return f"https://{first_default_host}.canvasmedical.com" | ||
|
||
|
||
def request_api_token(host: str, api_client_credentials: str) -> dict: | ||
"""Request an api token using the provided client_id and client_secret.""" | ||
token_response = requests.post( | ||
http = Http() | ||
token_response = http.post( | ||
f"{host}/auth/token/", | ||
headers={"Content-Type": "application/x-www-form-urlencoded"}, | ||
data=f"grant_type=client_credentials&{api_client_credentials}", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rmagier1 , you'll appreciate this.