Skip to content
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

🔨 add HTTPBasicAuth for supporting MLFlow authentication #193

Open
wants to merge 1 commit into
base: master
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
10 changes: 7 additions & 3 deletions mlflow_export_import/client/http_client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from abc import abstractmethod, ABCMeta
import os
import json
from requests.auth import HTTPBasicAuth
import requests
import click
from mlflow_export_import.common import MlflowExportImportException
Expand Down Expand Up @@ -96,11 +97,14 @@ def __init__(self, api_name, host=None, token=None):
self.host = host
self.api_uri = os.path.join(host, api_name)
self.token = token
user = os.environ.get("MLFLOW_TRACKING_USERNAME")
password = os.environ.get("MLFLOW_TRACKING_PASSWORD")
self.auth = HTTPBasicAuth(user, password) if user and password else None


def _get(self, resource, params=None):
uri = self._mk_uri(resource)
rsp = requests.get(uri, headers=self._mk_headers(), data=params, timeout=_TIMEOUT)
rsp = requests.get(uri, headers=self._mk_headers(), data=params, auth=self.auth, timeout=_TIMEOUT)
return self._check_response(rsp, params)


Expand Down Expand Up @@ -151,7 +155,7 @@ def patch(self, resource, data=None):

def _delete(self, resource):
uri = self._mk_uri(resource)
rsp = requests.delete(uri, headers=self._mk_headers(), timeout=_TIMEOUT)
rsp = requests.delete(uri, headers=self._mk_headers(), auth=self.auth, timeout=_TIMEOUT)
return self._check_response(rsp)

def delete(self, resource):
Expand All @@ -163,7 +167,7 @@ def delete(self, resource):

def _mutator(self, method, resource, data=None):
uri = self._mk_uri(resource)
rsp = method(uri, headers=self._mk_headers(), data=data, timeout=_TIMEOUT)
rsp = method(uri, headers=self._mk_headers(), data=data, auth=self.auth, timeout=_TIMEOUT)
return self._check_response(rsp)


Expand Down