Skip to content

Commit

Permalink
Get rid of get_token in data engine and in streaming
Browse files Browse the repository at this point in the history
  • Loading branch information
kbolashev committed Aug 21, 2023
1 parent 32f4381 commit 60daab1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
11 changes: 9 additions & 2 deletions dagshub/auth/token_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,22 @@ def auth_flow(self, request: Request) -> Generator[Request, Response, None]:
def token_text(self) -> str:
return self._token.token_text

def __call__(self, request):
"""
Forward the call to the token
"""
# TODO: NEED TO COME UP WITH A WAY TO RENEGOTIATE HERE SOMEHOW
# PROBABLY NEED TO CHECK FOR requests' REQUEST HERE
self._token(request)


class TokenDeserializationError(Exception):
...


class DagshubTokenABC(metaclass=ABCMeta):
token_type = "NONE"
# Decides which token is giving out first to the user
priority = 10000
priority = 10000 # Decides which token is given out first to the user

def __call__(self, request: Request) -> Request:
request.headers["Authorization"] = f"Bearer {self.token_text}"
Expand Down
3 changes: 1 addition & 2 deletions dagshub/data_engine/client/data_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import dagshub.auth
import dagshub.common.config
from dagshub.auth.token_auth import HTTPBearerAuth
from dagshub.common import config
from dagshub.common.analytics import send_analytics_event
from dagshub.common.rich_util import get_rich_progress
Expand Down Expand Up @@ -39,7 +38,7 @@ def __init__(self, repo: str):

def _init_client(self):
url = f"{self.host}/api/v1/repos/{self.repo}/data-engine/graphql"
auth = HTTPBearerAuth(config.token or dagshub.auth.get_token(host=self.host))
auth = dagshub.auth.get_authenticator(host=self.host)
transport = RequestsHTTPTransport(url=url, auth=auth)
client = gql.Client(transport=transport)
return client
Expand Down
5 changes: 1 addition & 4 deletions dagshub/streaming/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,17 +234,14 @@ def get_remote_branch_head(self, branch):
@property
def auth(self):
import dagshub.auth
from dagshub.auth.token_auth import HTTPBearerAuth

if self.username is not None and self.password is not None:
return self.username, self.password

try:
token = self.token or dagshub.auth.get_token()
return dagshub.auth.get_authenticator()
except dagshub.auth.OauthNonInteractiveShellException:
logger.debug("Failed to perform OAuth in a non interactive shell")
if token is not None:
return HTTPBearerAuth(token)

# Try to fetch credentials from the git credential file
proc = subprocess.run(['git', 'credential', 'fill'],
Expand Down

0 comments on commit 60daab1

Please sign in to comment.