Skip to content

Commit

Permalink
fix: move logging to credential providers
Browse files Browse the repository at this point in the history
  • Loading branch information
NikitaYurasov committed Sep 10, 2024
1 parent 333fd0a commit c471c88
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
2 changes: 1 addition & 1 deletion dbxio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
from dbxio.utils import * # noqa: F403
from dbxio.volume import * # noqa: F403

__version__ = '0.4.4' # single source of truth
__version__ = '0.4.5' # single source of truth
22 changes: 10 additions & 12 deletions dbxio/core/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,6 @@ class DbxIOClient:

session_configuration: Optional[Dict[str, Any]] = None

def __attrs_post_init__(self):
"""
This method is used only for logging
"""
logger.info(
'Client is created with the following settings: %s; cluster settings: http-path: %s, server-hostname: %s',
self.settings,
self._cluster_credentials.http_path,
self._cluster_credentials.server_hostname,
)
logger.info('Auth provider: %s', self.credential_provider.__class__.__name__)

def clear_cache(self):
self.credential_provider.clear_cache()

Expand All @@ -72,6 +60,15 @@ def from_cluster_settings(
"""
Create a client from the cluster settings. Use this method if you want to use PAT for authentication.
"""
logger.info(
'Creating a client from the cluster settings (http-path: %s, server-hostname: %s, '
'cluster-type: %s, az-cred-provider: %s, settings: %s)',
http_path,
server_hostname,
cluster_type,
az_cred_provider,
settings,
)
provider = DefaultCredentialProvider(
cluster_type=cluster_type,
az_cred_provider=az_cred_provider,
Expand All @@ -91,6 +88,7 @@ def from_auth_provider(
Create a client from the auth provider.
Use this method if you want to generate a short-lived token based on the available authentication method.
"""
logger.info('Creating a client from the auth provider: %s', auth_provider.__class__.__name__)
return cls(credential_provider=auth_provider, settings=settings or Settings(), **kwargs)

@property
Expand Down
14 changes: 14 additions & 0 deletions dbxio/core/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ def __init__(
), 'semi_configured_credentials must be provided if not lazy'
self.ensure_set_auth_provider()

logger.info(
'DefaultCredentialProvider is created with the following settings: %s', self.semi_configured_credentials
)

def clear_cache(self):
if self._successful_provider is not None:
self._successful_provider.clear_cache()
Expand Down Expand Up @@ -226,6 +230,16 @@ class BareAuthProvider(BaseAuthProvider):

semi_configured_credentials: None = attrs.field(default=None, init=False)

def __attrs_post_init__(self):
"""
This method is used only for logging
"""
logger.info(
'BareAuthProvider is created with the following settings ( http_path: %s, server_hostname: %s )',
self.http_path,
self.server_hostname,
)

def clear_cache(self):
pass

Expand Down

0 comments on commit c471c88

Please sign in to comment.