Skip to content

add suport for proxy authorization headers #3

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions lightdash/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ class Client:
instance_url (str): The URL of your Lightdash instance
access_token (str): The access token for authentication
project_uuid (str): The UUID of the project to interact with
proxy_authorization (str): An optional value for the proxy authorization header
"""
def __init__(self, instance_url: str, access_token: str, project_uuid: str):
def __init__(self, instance_url: str, access_token: str, project_uuid: str, proxy_authorization: Optional[str] = None):
self.instance_url = instance_url.rstrip('/')
self.access_token = access_token
self.project_uuid = project_uuid
self.proxy_authorization = proxy_authorization
self.models = Models(self)

def _log_request(
Expand Down Expand Up @@ -85,12 +87,16 @@ def _make_request(
"""
url = urljoin(self.instance_url, path)
self._log_request(method, url, params, json)

with httpx.Client(
headers={

headers = {
"Authorization": f"ApiKey {self.access_token}",
"Accept": "application/json",
},
}
if self.proxy_authorization is not None:
headers["Proxy-Authorization"] = self.proxy_authorization

with httpx.Client(
headers=headers,
timeout=30.0
) as client:
response = client.request(
Expand Down Expand Up @@ -158,4 +164,4 @@ def list_models(self) -> List[Model]:
LightdashError: If the API returns an error response
httpx.HTTPError: If there's a network or HTTP protocol error
"""
return self.models.list()
return self.models.list()