Skip to content

Commit

Permalink
Issue mlflow#192: Added support for MLFlow authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
Derek Tapley committed Oct 28, 2024
1 parent a572e94 commit e5cacc4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
11 changes: 8 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 Expand Up @@ -265,6 +269,7 @@ def __init__(self, host=None, token=None):
type=str,
required=False
)

def main(api, resource, method, params, data, output_file):
print("Options:")
for k,v in locals().items():
Expand Down
3 changes: 2 additions & 1 deletion mlflow_export_import/client/mlflow_auth_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from mlflow_export_import.client import databricks_cli_utils
from mlflow_export_import.common import MlflowExportImportException
from mlflow_export_import.common import utils
import os

_logger = utils.getLogger(__name__)

Expand All @@ -23,7 +24,7 @@ def get_mlflow_host_token():
if not uri.startswith("http"):
_raise_exception(uri)
else:
return (uri, None)
return (uri, os.environ.get("MLFLOW_TRACKING_TOKEN"))
else:
_raise_exception(uri)

Expand Down

0 comments on commit e5cacc4

Please sign in to comment.