METADATA 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. Metadata-Version: 2.1
  2. Name: alibabacloud-credentials-py2
  3. Version: 0.0.3
  4. Summary: The alibabacloud credentials module of alibabaCloud Python2 SDK.
  5. Home-page: https://github.com/aliyun/credentials-python2
  6. Author: Alibaba Cloud
  7. Author-email: alibaba-cloud-sdk-dev-team@list.alibaba-inc.com
  8. License: Apache License 2.0
  9. Keywords: alibabacloud,sdk,tea
  10. Platform: any
  11. Classifier: Development Status :: 5 - Production/Stable
  12. Classifier: Intended Audience :: Developers
  13. Classifier: License :: OSI Approved :: Apache Software License
  14. Classifier: Programming Language :: Python :: 2
  15. Classifier: Programming Language :: Python :: 2.7
  16. Classifier: Topic :: Software Development
  17. Description-Content-Type: text/markdown
  18. Requires-Dist: alibabacloud-tea-py2
  19. English | [简体中文](README-CN.md)
  20. ![](https://aliyunsdk-pages.alicdn.com/icons/AlibabaCloud.svg)
  21. # Alibaba Cloud Credentials for Python2
  22. ## Installation
  23. - **Install with pip**
  24. Python SDK uses a common package management tool named `pip`. If pip is not installed, see the [pip user guide](https://pip.pypa.io/en/stable/installing/ "pip User Guide") to install pip.
  25. ```bash
  26. # Install the alibabacloud_credentials_py2
  27. pip install alibabacloud_credentials_py2
  28. ```
  29. ## Usage
  30. Before you begin, you need to sign up for an Alibaba Cloud account and retrieve your [Credentials](https://usercenter.console.aliyun.com/#/manage/ak).
  31. ### Credential Type
  32. #### access_key
  33. Setup access_key credential through [User Information Management][ak], it have full authority over the account, please keep it safe. Sometimes for security reasons, you cannot hand over a primary account AccessKey with full access to the developer of a project. You may create a sub-account [RAM Sub-account][ram] , grant its [authorization][permissions],and use the AccessKey of RAM Sub-account.
  34. ```python
  35. from alibabacloud_credentials.client import Client
  36. from alibabacloud_credentials.models import Config
  37. config = Config(
  38. type='access_key', # credential type
  39. access_key_id='accessKeyId', # AccessKeyId
  40. access_key_secret='accessKeySecret', # AccessKeySecret
  41. )
  42. cred = Client(config)
  43. access_key_id = cred.get_access_key_id()
  44. access_key_secret = cred.get_access_key_secret()
  45. cred_type = cred.get_type()
  46. ```
  47. #### sts
  48. Create a temporary security credential by applying Temporary Security Credentials (TSC) through the Security Token Service (STS).
  49. ```python
  50. from alibabacloud_credentials.client import Client
  51. from alibabacloud_credentials.models import Config
  52. config = Config(
  53. type='sts', # credential type
  54. access_key_id='accessKeyId', # AccessKeyId
  55. access_key_secret='accessKeySecret', # AccessKeySecret
  56. security_token='securityToken' # STS Token
  57. )
  58. cred = Client(config)
  59. access_key_id = cred.get_access_key_id()
  60. access_key_secret = cred.get_access_key_secret()
  61. security_token = cred.get_security_token()
  62. cred_type = cred.get_type()
  63. ```
  64. #### ram_role_arn
  65. By specifying [RAM Role][RAM Role], the credential will be able to automatically request maintenance of STS Token. If you want to limit the permissions([How to make a policy][policy]) of STS Token, you can assign value for `Policy`.
  66. ```python
  67. from alibabacloud_credentials.client import Client
  68. from alibabacloud_credentials.models import Config
  69. config = Config(
  70. type='ram_role_arn', # credential type
  71. access_key_id='accessKeyId', # AccessKeyId
  72. access_key_secret='accessKeySecret', # AccessKeySecret
  73. security_token='securityToken', # STS Token
  74. role_arn='roleArn', # Format: acs:ram::USER_ID:role/ROLE_NAME
  75. role_session_name='roleSessionName', # Role Session Name
  76. policy='policy', # Not required, limit the permissions of STS Token
  77. role_session_expiration=3600 # Not required, limit the Valid time of STS Token
  78. )
  79. cred = Client(config)
  80. access_key_id = cred.get_access_key_id()
  81. access_key_secret = cred.get_access_key_secret()
  82. security_token = cred.get_security_token()
  83. cred_type = cred.get_type()
  84. ```
  85. #### ecs_ram_role
  86. By specifying the role name, the credential will be able to automatically request maintenance of STS Token.
  87. ```python
  88. from alibabacloud_credentials.client import Client
  89. from alibabacloud_credentials.models import Config
  90. config = Config(
  91. type='ecs_ram_role', # credential type
  92. role_name='roleName' # `roleName` is optional. It will be retrieved automatically if not set. It is highly recommended to set it up to reduce requests.
  93. )
  94. cred = Client(config)
  95. access_key_id = cred.get_access_key_id()
  96. access_key_secret = cred.get_access_key_secret()
  97. security_token = cred.get_security_token()
  98. cred_type = cred.get_type()
  99. ```
  100. #### rsa_key_pair
  101. By specifying the public key ID and the private key file, the credential will be able to automatically request maintenance of the AccessKey before sending the request. Only Japan station is supported.
  102. ```python
  103. from alibabacloud_credentials.client import Client
  104. from alibabacloud_credentials.models import Config
  105. config = Config(
  106. type='rsa_key_pair', # credential type
  107. private_key_file='privateKeyFile', # The file path to store the PrivateKey
  108. public_key_id='publicKeyId' # PublicKeyId of your account
  109. )
  110. cred = Client(config)
  111. access_key_id = cred.get_access_key_id()
  112. access_key_secret = cred.get_access_key_secret()
  113. security_token = cred.get_security_token()
  114. cred_type = cred.get_type()
  115. ```
  116. #### bearer
  117. If credential is required by the Cloud Call Centre (CCC), please apply for Bearer Token maintenance by yourself.
  118. ```python
  119. from alibabacloud_credentials.client import Client
  120. from alibabacloud_credentials.models import Config
  121. config = Config(
  122. type='bearer', # credential type
  123. bearer_token='bearerToken', # BearerToken
  124. )
  125. cred = Client(config)
  126. access_key_id = cred.get_access_key_id()
  127. access_key_secret = cred.get_access_key_secret()
  128. security_token = cred.get_security_token()
  129. cred_type = cred.get_type()
  130. ```
  131. ### Use the default credential provider chain
  132. ```python
  133. from alibabacloud_credentials.client import Client as CredClient
  134. from alibabacloud_ocr20191230.client import Client as OcrClient
  135. from alibabacloud_ocr20191230.models import GetAsyncJobResultRequest
  136. from alibabacloud_tea_rpc.models import Config
  137. from alibabacloud_tea_util.models import RuntimeOptions
  138. cred = CredClient()
  139. config = Config(credential=cred)
  140. client = OcrClient(config)
  141. request = GetAsyncJobResultRequest(
  142. job_id='<job_id>'
  143. )
  144. runtime_options = RuntimeOptions()
  145. response = client.get_async_job_result(request, runtime_options)
  146. ```
  147. The default credential provider chain looks for available credentials, with following order:
  148. 1.Environment Credentials
  149. Look for environment credentials in environment variable. If the `ALIBABA_CLOUD_ACCESS_KEY_ID` and `ALIBABA_CLOUD_ACCESS_KEY_SECRET` environment variables are defined and are not empty, the program will use them to create default credentials.
  150. 2.Credentials File
  151. If there is `~/.alibabacloud/credentials default file (Windows shows C:\Users\USER_NAME\.alibabacloud\credentials)`, the program automatically creates credentials with the specified type and name. The default file is not necessarily exist, but a parse error will throw an exception. The name of configuration item is lowercase.This configuration file can be shared between different projects and between different tools. Because it is outside of the project and will not be accidentally committed to the version control. The path to the default file can be modified by defining the `ALIBABA_CLOUD_CREDENTIALS_FILE` environment variable. If not configured, use the default configuration `default`. You can also set the environment variables `ALIBABA_CLOUD_PROFILE` to use the configuration.
  152. ```ini
  153. [default] # default setting
  154. enable = true # Enable,Enabled by default if this option is not present
  155. type = access_key # Certification type: access_key
  156. access_key_id = foo # Key
  157. access_key_secret = bar # Secret
  158. [client1] # configuration that is named as `client1`
  159. type = ecs_ram_role # Certification type: ecs_ram_role
  160. role_name = EcsRamRoleTest # Role Name
  161. [client2] # configuration that is named as `client2`
  162. enable = false # Disable
  163. type = ram_role_arn # Certification type: ram_role_arn
  164. region_id = cn-test
  165. policy = test # optional Specify permissions
  166. access_key_id = foo
  167. access_key_secret = bar
  168. role_arn = role_arn
  169. role_session_name = session_name # optional
  170. [client3] # configuration that is named as `client3`
  171. type = rsa_key_pair # Certification type: rsa_key_pair
  172. public_key_id = publicKeyId # Public Key ID
  173. private_key_file = /your/pk.pem # Private Key file
  174. ```
  175. 3.Instance RAM Role
  176. If the environment variable `ALIBABA_CLOUD_ECS_METADATA` is defined and not empty, the program will take the value of the environment variable as the role name and request <http://100.100.100.200/latest/meta-data/ram/security-credentials/> to get the temporary Security credentials.
  177. ## Issues
  178. [Opening an Issue](https://github.com/aliyun/credentials-python2/issues/new), Issues not conforming to the guidelines may be closed immediately.
  179. ## Changelog
  180. Detailed changes for each release are documented in the [release notes](./ChangeLog.md).
  181. ## References
  182. * [Latest Release](https://github.com/aliyun/credentials-python2)
  183. ## License
  184. [Apache-2.0](http://www.apache.org/licenses/LICENSE-2.0)
  185. Copyright (c) 2009-present, Alibaba Cloud All rights reserved.