|
| 1 | +import os |
1 | 2 | from abc import ABC, abstractmethod
|
2 | 3 |
|
| 4 | +from feast.permissions.auth.auth_type import AuthType |
| 5 | +from feast.permissions.auth_model import ( |
| 6 | + AuthConfig, |
| 7 | + KubernetesAuthConfig, |
| 8 | + OidcClientAuthConfig, |
| 9 | +) |
| 10 | + |
3 | 11 |
|
4 | 12 | class AuthenticationClientManager(ABC):
|
5 | 13 | @abstractmethod
|
6 | 14 | def get_token(self) -> str:
|
7 | 15 | """Retrieves the token based on the authentication type configuration"""
|
8 | 16 | pass
|
| 17 | + |
| 18 | + |
| 19 | +class AuthenticationClientManagerFactory(ABC): |
| 20 | + def __init__(self, auth_config: AuthConfig): |
| 21 | + self.auth_config = auth_config |
| 22 | + |
| 23 | + def get_auth_client_manager(self) -> AuthenticationClientManager: |
| 24 | + from feast.permissions.client.intra_comm_authentication_client_manager import ( |
| 25 | + IntraCommAuthClientManager, |
| 26 | + ) |
| 27 | + from feast.permissions.client.kubernetes_auth_client_manager import ( |
| 28 | + KubernetesAuthClientManager, |
| 29 | + ) |
| 30 | + from feast.permissions.client.oidc_authentication_client_manager import ( |
| 31 | + OidcAuthClientManager, |
| 32 | + ) |
| 33 | + |
| 34 | + intra_communication_base64 = os.getenv("INTRA_COMMUNICATION_BASE64") |
| 35 | + if intra_communication_base64: |
| 36 | + return IntraCommAuthClientManager( |
| 37 | + self.auth_config, intra_communication_base64 |
| 38 | + ) |
| 39 | + |
| 40 | + if self.auth_config.type == AuthType.OIDC.value: |
| 41 | + assert isinstance(self.auth_config, OidcClientAuthConfig) |
| 42 | + return OidcAuthClientManager(self.auth_config) |
| 43 | + elif self.auth_config.type == AuthType.KUBERNETES.value: |
| 44 | + assert isinstance(self.auth_config, KubernetesAuthConfig) |
| 45 | + return KubernetesAuthClientManager(self.auth_config) |
| 46 | + else: |
| 47 | + raise RuntimeError( |
| 48 | + f"No Auth client manager implemented for the auth type:${self.auth_config.type}" |
| 49 | + ) |
0 commit comments