@@ -101,44 +101,29 @@ def __deepcopy__(self, memo):
101101
102102
103103class AwsCredentialsProviderBase (NativeResource ):
104- """
105- Base class for providers that source the AwsCredentials needed to sign an authenticated AWS request.
106-
107- NOTE: Custom subclasses of AwsCredentialsProviderBase are not yet supported.
108- """
109- __slots__ = ()
110-
111- def __init__ (self , binding = None ):
112- super ().__init__ ()
113-
114- if binding is None :
115- # TODO: create binding type that lets native code call into python subclass
116- raise NotImplementedError ("Custom subclasses of AwsCredentialsProviderBase are not yet supported" )
117-
118- self ._binding = binding
119-
120- def get_credentials (self ):
121- """
122- Asynchronously fetch AwsCredentials.
123-
124- Returns:
125- concurrent.futures.Future: A Future which will contain
126- :class:`AwsCredentials` (or an exception) when the operation completes.
127- The operation may complete on a different thread.
128- """
129- raise NotImplementedError ()
104+ # Pointless base class, kept for backwards compatibility.
105+ # AwsCredentialsProvider is (and always will be) the only subclass.
106+ #
107+ # Originally created with the thought that, when we supported
108+ # custom python providers, they would inherit from this class.
109+ # We ended up supporting custom python providers via
110+ # AwsCredentialsProvider.new_delegate() instead.
111+ pass
130112
131113
132114class AwsCredentialsProvider (AwsCredentialsProviderBase ):
133115 """
134116 Credentials providers source the AwsCredentials needed to sign an authenticated AWS request.
135117
136- Base class: AwsCredentialsProviderBase
137-
138118 This class provides `new()` functions for several built-in provider types.
119+ To define a custom provider, use the `new_delegate()` function.
139120 """
140121 __slots__ = ()
141122
123+ def __init__ (self , binding ):
124+ super ().__init__ ()
125+ self ._binding = binding
126+
142127 @classmethod
143128 def new_default_chain (cls , client_bootstrap ):
144129 """
@@ -289,7 +274,35 @@ def new_chain(cls, providers):
289274 binding = _awscrt .credentials_provider_new_chain (providers )
290275 return cls (binding )
291276
277+ @classmethod
278+ def new_delegate (cls , get_credentials ):
279+ """
280+ Creates a provider that sources credentials from a custom
281+ synchronous callback.
282+
283+ Args:
284+ get_credentials: Callable which takes no arguments and returns
285+ :class:`AwsCredentials`.
286+
287+ Returns:
288+ AwsCredentialsProvider:
289+ """
290+ # TODO: support async delegates
291+
292+ assert callable (get_credentials )
293+
294+ binding = _awscrt .credentials_provider_new_delegate (get_credentials )
295+ return cls (binding )
296+
292297 def get_credentials (self ):
298+ """
299+ Asynchronously fetch AwsCredentials.
300+
301+ Returns:
302+ concurrent.futures.Future: A Future which will contain
303+ :class:`AwsCredentials` (or an exception) when the operation completes.
304+ The operation may complete on a different thread.
305+ """
293306 future = Future ()
294307
295308 def _on_complete (error_code , binding ):
@@ -306,7 +319,7 @@ def _on_complete(error_code, binding):
306319 try :
307320 _awscrt .credentials_provider_get_credentials (self ._binding , _on_complete )
308321 except Exception as e :
309- future .set_result (e )
322+ future .set_exception (e )
310323
311324 return future
312325
@@ -383,7 +396,7 @@ class AwsSigningConfig(NativeResource):
383396 signature_type (AwsSignatureType): Which sort of signature should be
384397 computed from the signable.
385398
386- credentials_provider (AwsCredentialsProviderBase ): Credentials provider
399+ credentials_provider (AwsCredentialsProvider ): Credentials provider
387400 to fetch signing credentials with.
388401
389402 region (str): The region to sign against.
@@ -470,7 +483,7 @@ def __init__(self,
470483
471484 assert isinstance (algorithm , AwsSigningAlgorithm )
472485 assert isinstance (signature_type , AwsSignatureType )
473- assert isinstance (credentials_provider , AwsCredentialsProviderBase )
486+ assert isinstance (credentials_provider , AwsCredentialsProvider )
474487 assert isinstance (region , str )
475488 assert isinstance (service , str )
476489 assert callable (should_sign_header ) or should_sign_header is None
@@ -533,7 +546,7 @@ def signature_type(self):
533546
534547 @property
535548 def credentials_provider (self ):
536- """AwsCredentialsProviderBase : Credentials provider to fetch signing credentials with"""
549+ """AwsCredentialsProvider : Credentials provider to fetch signing credentials with"""
537550 return _awscrt .signing_config_get_credentials_provider (self ._binding )
538551
539552 @property
0 commit comments