Skip to content

Commit

Permalink
feat: add AuthTarget to AuthData (#459)
Browse files Browse the repository at this point in the history
  • Loading branch information
ovsds authored May 28, 2024
1 parent 5543f94 commit 24a595d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
13 changes: 9 additions & 4 deletions lib/dl_api_commons/dl_api_commons/base_models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import abc
import enum
from typing import (
Any,
Optional,
Expand Down Expand Up @@ -37,13 +38,17 @@ def get_reporting_extra(self) -> dict[str, str | None]:
)


class AuthTarget(str, enum.Enum):
UNITED_STORAGE = "united_storage"


class AuthData(metaclass=abc.ABCMeta):
@abc.abstractmethod
def get_headers(self) -> dict[DLHeaders, str]:
def get_headers(self, target: Optional[AuthTarget] = None) -> dict[DLHeaders, str]:
raise NotImplementedError()

@abc.abstractmethod
def get_cookies(self) -> dict[DLCookies, str]:
def get_cookies(self, target: Optional[AuthTarget] = None) -> dict[DLCookies, str]:
raise NotImplementedError()


Expand Down Expand Up @@ -169,8 +174,8 @@ def get_tenant_id(self) -> str:

@attr.s()
class NoAuthData(AuthData):
def get_headers(self) -> dict[DLHeaders, str]:
def get_headers(self, target: Optional[AuthTarget] = None) -> dict[DLHeaders, str]:
return {}

def get_cookies(self) -> dict[DLCookies, str]:
def get_cookies(self, target: Optional[AuthTarget] = None) -> dict[DLCookies, str]:
return {}
9 changes: 5 additions & 4 deletions lib/dl_core/dl_core/united_storage_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

from dl_api_commons.base_models import (
AuthData,
AuthTarget,
TenantCommon,
TenantDef,
)
Expand Down Expand Up @@ -104,12 +105,12 @@ def get_outbound_headers(self, include_tenancy: bool = True) -> dict[DLHeaders,

return {
**(self.tenant.get_outbound_tenancy_headers() if include_tenancy else {}),
**self.auth_data.get_headers(),
**self.auth_data.get_headers(AuthTarget.UNITED_STORAGE),
**{name: val for name, val in flags.items() if val is not None},
}

def get_outbound_cookies(self) -> dict[DLCookies, str]:
return self.auth_data.get_cookies()
return self.auth_data.get_cookies(AuthTarget.UNITED_STORAGE)


@attr.s(frozen=True)
Expand Down Expand Up @@ -176,11 +177,11 @@ def get_tenant(self) -> TenantDef:
def get_outbound_headers(self, include_tenancy: bool = True) -> dict[DLHeaders, str]:
return {
**(self.tenant.get_outbound_tenancy_headers() if include_tenancy else {}),
**self.auth_data.get_headers(),
**self.auth_data.get_headers(AuthTarget.UNITED_STORAGE),
}

def get_outbound_cookies(self) -> dict[DLCookies, str]:
return self.auth_data.get_cookies()
return self.auth_data.get_cookies(AuthTarget.UNITED_STORAGE)


# noinspection PyCallByClass
Expand Down

0 comments on commit 24a595d

Please sign in to comment.