Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### 2020-12-11 Version 0.1.2
* Fix AttributeError.

### 2020-12-09 Version 0.1.1
* Change overwrite to a method with `_async` suffix

Expand Down
2 changes: 1 addition & 1 deletion alibabacloud_credentials/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.1.1"
__version__ = "0.1.2"
18 changes: 12 additions & 6 deletions alibabacloud_credentials/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,20 @@ def get_type(self):
def get_bearer_token(self):
return self.cloud_credential.bearer_token

@attribute_error_return_none
async def get_access_key_id_async(self):
return self.cloud_credential.get_access_key_id()
if hasattr(self.cloud_credential, 'get_access_key_id'):
return self.cloud_credential.get_access_key_id()
else:
return

@attribute_error_return_none
async def get_access_key_secret_async(self):
return self.cloud_credential.get_access_key_secret()
if hasattr(self.cloud_credential, 'get_access_key_secret'):
return self.cloud_credential.get_access_key_secret()
else:
return

@attribute_error_return_none
async def get_security_token_async(self):
return self.cloud_credential.get_security_token()
if hasattr(self.cloud_credential, 'get_security_token'):
return self.cloud_credential.get_security_token()
else:
return
18 changes: 18 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import asyncio
import unittest

from alibabacloud_credentials.models import Config
Expand Down Expand Up @@ -43,3 +44,20 @@ def test_ak_client(self):

conf = Config(type='test')
self.assertIsInstance(Client.get_provider(conf), providers.DefaultCredentialsProvider)

conf = Config(
access_key_id='ak1',
access_key_secret='sk1',
type='access_key'
)
client = Client(conf)
loop = asyncio.get_event_loop()
task = asyncio.ensure_future(client.get_security_token_async())
loop.run_until_complete(task)
self.assertIsNone(task.result())
task = asyncio.ensure_future(client.get_access_key_id_async())
loop.run_until_complete(task)
self.assertEqual('ak1', task.result())
task = asyncio.ensure_future(client.get_access_key_secret_async())
loop.run_until_complete(task)
self.assertEqual('sk1', task.result())