ibm-cloud-sdk-core 3.20.5__tar.gz → 3.21.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ibm_cloud_sdk_core-3.21.0/PKG-INFO +159 -0
- ibm_cloud_sdk_core-3.21.0/README.md +114 -0
- ibm_cloud_sdk_core-3.21.0/ibm_cloud_sdk_core/authenticators/__init__.py +44 -0
- ibm_cloud_sdk_core-3.21.0/ibm_cloud_sdk_core/authenticators/authenticator.py +58 -0
- ibm_cloud_sdk_core-3.21.0/ibm_cloud_sdk_core/authenticators/basic_authenticator.py +89 -0
- ibm_cloud_sdk_core-3.21.0/ibm_cloud_sdk_core/authenticators/bearer_token_authenticator.py +85 -0
- ibm_cloud_sdk_core-3.21.0/ibm_cloud_sdk_core/authenticators/container_authenticator.py +150 -0
- ibm_cloud_sdk_core-3.21.0/ibm_cloud_sdk_core/authenticators/cp4d_authenticator.py +168 -0
- ibm_cloud_sdk_core-3.21.0/ibm_cloud_sdk_core/authenticators/iam_authenticator.py +110 -0
- ibm_cloud_sdk_core-3.21.0/ibm_cloud_sdk_core/authenticators/iam_request_based_authenticator.py +118 -0
- ibm_cloud_sdk_core-3.21.0/ibm_cloud_sdk_core/authenticators/mcsp_authenticator.py +134 -0
- ibm_cloud_sdk_core-3.21.0/ibm_cloud_sdk_core/authenticators/no_auth_authenticator.py +31 -0
- ibm_cloud_sdk_core-3.21.0/ibm_cloud_sdk_core/authenticators/vpc_instance_authenticator.py +125 -0
- {ibm_cloud_sdk_core-3.20.5 → ibm_cloud_sdk_core-3.21.0}/ibm_cloud_sdk_core/base_service.py +27 -9
- {ibm_cloud_sdk_core-3.20.5 → ibm_cloud_sdk_core-3.21.0}/ibm_cloud_sdk_core/get_authenticator.py +7 -1
- ibm_cloud_sdk_core-3.21.0/ibm_cloud_sdk_core/logger.py +85 -0
- ibm_cloud_sdk_core-3.21.0/ibm_cloud_sdk_core/token_managers/__init__.py +15 -0
- ibm_cloud_sdk_core-3.21.0/ibm_cloud_sdk_core/token_managers/container_token_manager.py +200 -0
- ibm_cloud_sdk_core-3.21.0/ibm_cloud_sdk_core/token_managers/cp4d_token_manager.py +129 -0
- ibm_cloud_sdk_core-3.21.0/ibm_cloud_sdk_core/token_managers/iam_request_based_token_manager.py +198 -0
- ibm_cloud_sdk_core-3.21.0/ibm_cloud_sdk_core/token_managers/iam_token_manager.py +93 -0
- ibm_cloud_sdk_core-3.21.0/ibm_cloud_sdk_core/token_managers/jwt_token_manager.py +91 -0
- ibm_cloud_sdk_core-3.21.0/ibm_cloud_sdk_core/token_managers/mcsp_token_manager.py +108 -0
- ibm_cloud_sdk_core-3.21.0/ibm_cloud_sdk_core/token_managers/token_manager.py +216 -0
- ibm_cloud_sdk_core-3.21.0/ibm_cloud_sdk_core/token_managers/vpc_instance_token_manager.py +174 -0
- {ibm_cloud_sdk_core-3.20.5 → ibm_cloud_sdk_core-3.21.0}/ibm_cloud_sdk_core/utils.py +6 -2
- ibm_cloud_sdk_core-3.21.0/ibm_cloud_sdk_core/version.py +1 -0
- ibm_cloud_sdk_core-3.21.0/ibm_cloud_sdk_core.egg-info/PKG-INFO +159 -0
- ibm_cloud_sdk_core-3.21.0/ibm_cloud_sdk_core.egg-info/SOURCES.txt +61 -0
- {ibm_cloud_sdk_core-3.20.5 → ibm_cloud_sdk_core-3.21.0}/pyproject.toml +2 -2
- {ibm_cloud_sdk_core-3.20.5 → ibm_cloud_sdk_core-3.21.0}/test/test_api_exception.py +4 -0
- {ibm_cloud_sdk_core-3.20.5 → ibm_cloud_sdk_core-3.21.0}/test/test_base_service.py +9 -0
- {ibm_cloud_sdk_core-3.20.5 → ibm_cloud_sdk_core-3.21.0}/test/test_basic_authenticator.py +4 -0
- {ibm_cloud_sdk_core-3.20.5 → ibm_cloud_sdk_core-3.21.0}/test/test_bearer_authenticator.py +4 -0
- {ibm_cloud_sdk_core-3.20.5 → ibm_cloud_sdk_core-3.21.0}/test/test_container_token_manager.py +4 -0
- {ibm_cloud_sdk_core-3.20.5 → ibm_cloud_sdk_core-3.21.0}/test/test_cp4d_authenticator.py +4 -0
- {ibm_cloud_sdk_core-3.20.5 → ibm_cloud_sdk_core-3.21.0}/test/test_cp4d_token_manager.py +4 -0
- {ibm_cloud_sdk_core-3.20.5 → ibm_cloud_sdk_core-3.21.0}/test/test_http_adapter.py +9 -41
- {ibm_cloud_sdk_core-3.20.5 → ibm_cloud_sdk_core-3.21.0}/test/test_iam_authenticator.py +4 -0
- {ibm_cloud_sdk_core-3.20.5 → ibm_cloud_sdk_core-3.21.0}/test/test_iam_token_manager.py +4 -0
- {ibm_cloud_sdk_core-3.20.5 → ibm_cloud_sdk_core-3.21.0}/test/test_jwt_token_manager.py +4 -0
- ibm_cloud_sdk_core-3.21.0/test/test_logger.py +94 -0
- {ibm_cloud_sdk_core-3.20.5 → ibm_cloud_sdk_core-3.21.0}/test/test_mcsp_authenticator.py +4 -0
- {ibm_cloud_sdk_core-3.20.5 → ibm_cloud_sdk_core-3.21.0}/test/test_mcsp_token_manager.py +4 -0
- {ibm_cloud_sdk_core-3.20.5 → ibm_cloud_sdk_core-3.21.0}/test/test_utils.py +5 -1
- {ibm_cloud_sdk_core-3.20.5 → ibm_cloud_sdk_core-3.21.0}/test/test_vpc_instance_authenticator.py +4 -0
- {ibm_cloud_sdk_core-3.20.5 → ibm_cloud_sdk_core-3.21.0}/test/test_vpc_instance_token_manager.py +9 -58
- ibm_cloud_sdk_core-3.20.5/PKG-INFO +0 -124
- ibm_cloud_sdk_core-3.20.5/README.md +0 -79
- ibm_cloud_sdk_core-3.20.5/ibm_cloud_sdk_core/version.py +0 -1
- ibm_cloud_sdk_core-3.20.5/ibm_cloud_sdk_core.egg-info/PKG-INFO +0 -124
- ibm_cloud_sdk_core-3.20.5/ibm_cloud_sdk_core.egg-info/SOURCES.txt +0 -39
- {ibm_cloud_sdk_core-3.20.5 → ibm_cloud_sdk_core-3.21.0}/LICENSE +0 -0
- {ibm_cloud_sdk_core-3.20.5 → ibm_cloud_sdk_core-3.21.0}/MANIFEST.in +0 -0
- {ibm_cloud_sdk_core-3.20.5 → ibm_cloud_sdk_core-3.21.0}/ibm_cloud_sdk_core/__init__.py +0 -0
- {ibm_cloud_sdk_core-3.20.5 → ibm_cloud_sdk_core-3.21.0}/ibm_cloud_sdk_core/api_exception.py +0 -0
- {ibm_cloud_sdk_core-3.20.5 → ibm_cloud_sdk_core-3.21.0}/ibm_cloud_sdk_core/detailed_response.py +0 -0
- {ibm_cloud_sdk_core-3.20.5 → ibm_cloud_sdk_core-3.21.0}/ibm_cloud_sdk_core/http_adapter.py +0 -0
- {ibm_cloud_sdk_core-3.20.5 → ibm_cloud_sdk_core-3.21.0}/ibm_cloud_sdk_core/private_helpers.py +0 -0
- {ibm_cloud_sdk_core-3.20.5 → ibm_cloud_sdk_core-3.21.0}/ibm_cloud_sdk_core.egg-info/dependency_links.txt +0 -0
- {ibm_cloud_sdk_core-3.20.5 → ibm_cloud_sdk_core-3.21.0}/ibm_cloud_sdk_core.egg-info/requires.txt +0 -0
- {ibm_cloud_sdk_core-3.20.5 → ibm_cloud_sdk_core-3.21.0}/ibm_cloud_sdk_core.egg-info/top_level.txt +0 -0
- {ibm_cloud_sdk_core-3.20.5 → ibm_cloud_sdk_core-3.21.0}/setup.cfg +0 -0
- {ibm_cloud_sdk_core-3.20.5 → ibm_cloud_sdk_core-3.21.0}/test/test_authenticator.py +0 -0
- {ibm_cloud_sdk_core-3.20.5 → ibm_cloud_sdk_core-3.21.0}/test/test_container_authenticator.py +0 -0
- {ibm_cloud_sdk_core-3.20.5 → ibm_cloud_sdk_core-3.21.0}/test/test_detailed_response.py +0 -0
- {ibm_cloud_sdk_core-3.20.5 → ibm_cloud_sdk_core-3.21.0}/test/test_no_auth_authenticator.py +0 -0
- {ibm_cloud_sdk_core-3.20.5 → ibm_cloud_sdk_core-3.21.0}/test/test_token_manager.py +0 -0
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: ibm-cloud-sdk-core
|
|
3
|
+
Version: 3.21.0
|
|
4
|
+
Summary: Core library used by SDKs for IBM Cloud Services
|
|
5
|
+
Author-email: IBM <devxsdk@us.ibm.com>
|
|
6
|
+
Project-URL: Repository, https://github.com/IBM/python-sdk-core
|
|
7
|
+
Project-URL: Documentation, https://github.com/IBM/python-sdk-core/blob/main/README.md
|
|
8
|
+
Project-URL: Issues, https://github.com/IBM/python-sdk-core/issues
|
|
9
|
+
Project-URL: Changelog, https://github.com/IBM/python-sdk-core/blob/main/CHANGELOG.md
|
|
10
|
+
Project-URL: Contributing, https://github.com/IBM/python-sdk-core/blob/main/CONTRIBUTING.md
|
|
11
|
+
Project-URL: License, https://github.com/IBM/python-sdk-core/blob/main/LICENSE
|
|
12
|
+
Keywords: ibm,cloud,ibm cloud services
|
|
13
|
+
Classifier: Programming Language :: Python
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
21
|
+
Classifier: Environment :: Console
|
|
22
|
+
Classifier: Intended Audience :: Developers
|
|
23
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
24
|
+
Classifier: Operating System :: OS Independent
|
|
25
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
26
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
27
|
+
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
|
|
28
|
+
Requires-Python: >=3.8
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
License-File: LICENSE
|
|
31
|
+
Requires-Dist: requests<3.0.0,>=2.31.0
|
|
32
|
+
Requires-Dist: urllib3<3.0.0,>=2.1.0
|
|
33
|
+
Requires-Dist: python_dateutil<3.0.0,>=2.8.2
|
|
34
|
+
Requires-Dist: PyJWT<3.0.0,>=2.8.0
|
|
35
|
+
Provides-Extra: dev
|
|
36
|
+
Requires-Dist: coverage<8.0.0,>=7.3.2; extra == "dev"
|
|
37
|
+
Requires-Dist: pylint<4.0.0,>=3.0.0; extra == "dev"
|
|
38
|
+
Requires-Dist: pytest<8.0.0,>=7.4.2; extra == "dev"
|
|
39
|
+
Requires-Dist: pytest-cov<5.0.0,>=4.1.0; extra == "dev"
|
|
40
|
+
Requires-Dist: responses<1.0.0,>=0.23.3; extra == "dev"
|
|
41
|
+
Requires-Dist: black<25.0.0,>=24.0.0; extra == "dev"
|
|
42
|
+
Provides-Extra: publish
|
|
43
|
+
Requires-Dist: build; extra == "publish"
|
|
44
|
+
Requires-Dist: twine; extra == "publish"
|
|
45
|
+
|
|
46
|
+
[](https://app.travis-ci.com/IBM/python-sdk-core)
|
|
47
|
+
[](https://pypi.org/project/ibm-cloud-sdk-core/)
|
|
48
|
+
[](https://pypi.python.org/pypi/ibm-cloud-sdk-core)
|
|
49
|
+
[](https://cla-assistant.io/ibm/python-sdk-core)
|
|
50
|
+
[](https://github.com/semantic-release/semantic-release)
|
|
51
|
+
|
|
52
|
+
# IBM Python SDK Core Version 3.21.0
|
|
53
|
+
This project contains core functionality required by Python code generated by the IBM Cloud OpenAPI SDK Generator
|
|
54
|
+
(openapi-sdkgen).
|
|
55
|
+
|
|
56
|
+
# Python Version
|
|
57
|
+
The current minimum Python version supported is 3.8.
|
|
58
|
+
|
|
59
|
+
## Installation
|
|
60
|
+
|
|
61
|
+
To install, use `pip`:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
python -m pip install --upgrade ibm-cloud-sdk-core
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Authentication
|
|
68
|
+
The python-sdk-core project supports the following types of authentication:
|
|
69
|
+
- Basic Authentication
|
|
70
|
+
- Bearer Token Authentication
|
|
71
|
+
- Identity and Access Management (IAM) Authentication
|
|
72
|
+
- Container Authentication
|
|
73
|
+
- VPC Instance Authentication
|
|
74
|
+
- Cloud Pak for Data Authentication
|
|
75
|
+
- No Authentication (for testing)
|
|
76
|
+
|
|
77
|
+
For more information about the various authentication types and how to use them with your services, click [here](Authentication.md).
|
|
78
|
+
|
|
79
|
+
## Issues
|
|
80
|
+
|
|
81
|
+
If you encounter an issue with this project, you are welcome to submit a [bug report](https://github.com/IBM/python-sdk-core/issues).
|
|
82
|
+
Before opening a new issue, please search for similar issues. It's possible that someone has already reported it.
|
|
83
|
+
|
|
84
|
+
## Logging
|
|
85
|
+
|
|
86
|
+
This library uses Python's built-in `logging` module to perform logging of error,
|
|
87
|
+
warning, informational and debug messages.
|
|
88
|
+
The components within the SDK Core library use a single logger named `ibm-cloud-sdk-core`.
|
|
89
|
+
|
|
90
|
+
For complete information on the logging facility, please see: [Logging facility for Python](https://docs.python.org/3/library/logging.html).
|
|
91
|
+
|
|
92
|
+
### Enable logging
|
|
93
|
+
|
|
94
|
+
There are various ways to configure and enable the logging facility.
|
|
95
|
+
|
|
96
|
+
The code example below demonstrates a simple way to enable debug logging by invoking
|
|
97
|
+
the `logging.basicConfig()` function.
|
|
98
|
+
|
|
99
|
+
Note that, as a convenience, if you set the logging level to `DEBUG`, then HTTP request/response message logging
|
|
100
|
+
is also enabled.
|
|
101
|
+
|
|
102
|
+
The following code example shows how debug logging can be enabled:
|
|
103
|
+
```python
|
|
104
|
+
import logging
|
|
105
|
+
|
|
106
|
+
# Create a basic logging configuration that:
|
|
107
|
+
# 1. Defines a handler to display messages on the console.
|
|
108
|
+
# 2. Sets the root logger's logging level to DEBUG.
|
|
109
|
+
# 3. Sets the 'format' string used to display messages.
|
|
110
|
+
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s [%(name)s:%(levelname)s] %(message)s', force=True)
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
When running your application, you should see output like this if debug logging is enabled:
|
|
114
|
+
```
|
|
115
|
+
2024-09-16 15:44:45,174 [ibm-cloud-sdk-core:DEBUG] Get authenticator from environment, key=global_search
|
|
116
|
+
2024-09-16 15:44:45,175 [ibm-cloud-sdk-core:DEBUG] Set service URL: https://api.global-search-tagging.cloud.ibm.com
|
|
117
|
+
2024-09-16 15:44:45,175 [ibm-cloud-sdk-core:DEBUG] Set User-Agent: ibm-python-sdk-core-3.21.0 os.name=Linux os.version=6.10.9-100.fc39.x86_64 python.version=3.12.5
|
|
118
|
+
2024-09-16 15:44:45,181 [ibm-cloud-sdk-core:DEBUG] Configuring BaseService instance with service name: global_search
|
|
119
|
+
2024-09-16 15:44:45,181 [ibm-cloud-sdk-core:DEBUG] Performing synchronous token fetch
|
|
120
|
+
2024-09-16 15:44:45,182 [ibm-cloud-sdk-core:DEBUG] Invoking IAM get_token operation: https://iam.cloud.ibm.com/identity/token
|
|
121
|
+
2024-09-16 15:44:45,182 [urllib3.connectionpool:DEBUG] Starting new HTTPS connection (1): iam.cloud.ibm.com:443
|
|
122
|
+
send: b'POST /identity/token HTTP/1.1\r\nHost: iam.cloud.ibm.com\r\nUser-Agent: ibm-python-sdk-core/iam-authenticator-3.21.0 os.name=Linux os.version=6.10.9-100.fc39.x86_64 python.version=3.12.5\r\nAccept-Encoding: gzip, deflate\r\nAccept: application/json\r\nConnection: keep-alive\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: 135\r\n\r\n'
|
|
123
|
+
send: b'grant_type=urn%3Aibm%3Aparams%3Aoauth%3Agrant-type%3Aapikey&apikey=[redacted]&response_type=cloud_iam'
|
|
124
|
+
reply: 'HTTP/1.1 200 OK\r\n'
|
|
125
|
+
header: Content-Type: application/json
|
|
126
|
+
header: Content-Language: en-US
|
|
127
|
+
header: Content-Encoding: gzip
|
|
128
|
+
header: Date: Mon, 16 Sep 2024 20:44:45 GMT
|
|
129
|
+
header: Content-Length: 983
|
|
130
|
+
header: Connection: keep-alive
|
|
131
|
+
2024-09-16 15:44:45,670 [urllib3.connectionpool:DEBUG] https://iam.cloud.ibm.com:443 "POST /identity/token HTTP/11" 200 983
|
|
132
|
+
2024-09-16 15:44:45,672 [ibm-cloud-sdk-core:DEBUG] Returned from IAM get_token operation
|
|
133
|
+
2024-09-16 15:44:45,673 [ibm-cloud-sdk-core:DEBUG] Authenticated outbound request (type=iam)
|
|
134
|
+
2024-09-16 15:44:45,673 [ibm-cloud-sdk-core:DEBUG] Prepared request [POST https://api.global-search-tagging.cloud.ibm.com/v3/resources/search]
|
|
135
|
+
2024-09-16 15:44:45,673 [ibm-cloud-sdk-core:DEBUG] Sending HTTP request message
|
|
136
|
+
2024-09-16 15:44:45,674 [urllib3.connectionpool:DEBUG] Starting new HTTPS connection (1): api.global-search-tagging.cloud.ibm.com:443
|
|
137
|
+
send: b'POST /v3/resources/search?limit=1 HTTP/1.1\r\nHost: api.global-search-tagging.cloud.ibm.com\r\nUser-Agent: platform-services-python-sdk/0.57.0 (lang=python; os.name=Linux; os.version=6.10.9-100.fc39.x86_64; python.version=3.12.5)\r\nAccept-Encoding: gzip, deflate\r\nAccept: application/json\r\nConnection: keep-alive\r\ncontent-type: application/json\r\nAuthorization: [redacted]\r\nContent-Length: 39\r\n\r\n'
|
|
138
|
+
send: b'{"query": "GST-sdk-*", "fields": ["*"]}'
|
|
139
|
+
reply: 'HTTP/1.1 200 OK\r\n'
|
|
140
|
+
header: Content-Type: application/json
|
|
141
|
+
header: Content-Length: 22
|
|
142
|
+
header: Date: Mon, 16 Sep 2024 20:44:46 GMT
|
|
143
|
+
header: Connection: keep-alive
|
|
144
|
+
2024-09-16 15:44:46,079 [urllib3.connectionpool:DEBUG] https://api.global-search-tagging.cloud.ibm.com:443 "POST /v3/resources/search?limit=1 HTTP/11" 200 22
|
|
145
|
+
2024-09-16 15:44:46,080 [ibm-cloud-sdk-core:DEBUG] Received HTTP response message, status code 200
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## Open source @ IBM
|
|
149
|
+
|
|
150
|
+
Find more open source projects on the [IBM Github Page](http://github.com/IBM)
|
|
151
|
+
|
|
152
|
+
## License
|
|
153
|
+
|
|
154
|
+
This library is licensed under Apache 2.0. Full license text is
|
|
155
|
+
available in [LICENSE](LICENSE).
|
|
156
|
+
|
|
157
|
+
## Contributing
|
|
158
|
+
|
|
159
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
[](https://app.travis-ci.com/IBM/python-sdk-core)
|
|
2
|
+
[](https://pypi.org/project/ibm-cloud-sdk-core/)
|
|
3
|
+
[](https://pypi.python.org/pypi/ibm-cloud-sdk-core)
|
|
4
|
+
[](https://cla-assistant.io/ibm/python-sdk-core)
|
|
5
|
+
[](https://github.com/semantic-release/semantic-release)
|
|
6
|
+
|
|
7
|
+
# IBM Python SDK Core Version 3.21.0
|
|
8
|
+
This project contains core functionality required by Python code generated by the IBM Cloud OpenAPI SDK Generator
|
|
9
|
+
(openapi-sdkgen).
|
|
10
|
+
|
|
11
|
+
# Python Version
|
|
12
|
+
The current minimum Python version supported is 3.8.
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
To install, use `pip`:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
python -m pip install --upgrade ibm-cloud-sdk-core
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Authentication
|
|
23
|
+
The python-sdk-core project supports the following types of authentication:
|
|
24
|
+
- Basic Authentication
|
|
25
|
+
- Bearer Token Authentication
|
|
26
|
+
- Identity and Access Management (IAM) Authentication
|
|
27
|
+
- Container Authentication
|
|
28
|
+
- VPC Instance Authentication
|
|
29
|
+
- Cloud Pak for Data Authentication
|
|
30
|
+
- No Authentication (for testing)
|
|
31
|
+
|
|
32
|
+
For more information about the various authentication types and how to use them with your services, click [here](Authentication.md).
|
|
33
|
+
|
|
34
|
+
## Issues
|
|
35
|
+
|
|
36
|
+
If you encounter an issue with this project, you are welcome to submit a [bug report](https://github.com/IBM/python-sdk-core/issues).
|
|
37
|
+
Before opening a new issue, please search for similar issues. It's possible that someone has already reported it.
|
|
38
|
+
|
|
39
|
+
## Logging
|
|
40
|
+
|
|
41
|
+
This library uses Python's built-in `logging` module to perform logging of error,
|
|
42
|
+
warning, informational and debug messages.
|
|
43
|
+
The components within the SDK Core library use a single logger named `ibm-cloud-sdk-core`.
|
|
44
|
+
|
|
45
|
+
For complete information on the logging facility, please see: [Logging facility for Python](https://docs.python.org/3/library/logging.html).
|
|
46
|
+
|
|
47
|
+
### Enable logging
|
|
48
|
+
|
|
49
|
+
There are various ways to configure and enable the logging facility.
|
|
50
|
+
|
|
51
|
+
The code example below demonstrates a simple way to enable debug logging by invoking
|
|
52
|
+
the `logging.basicConfig()` function.
|
|
53
|
+
|
|
54
|
+
Note that, as a convenience, if you set the logging level to `DEBUG`, then HTTP request/response message logging
|
|
55
|
+
is also enabled.
|
|
56
|
+
|
|
57
|
+
The following code example shows how debug logging can be enabled:
|
|
58
|
+
```python
|
|
59
|
+
import logging
|
|
60
|
+
|
|
61
|
+
# Create a basic logging configuration that:
|
|
62
|
+
# 1. Defines a handler to display messages on the console.
|
|
63
|
+
# 2. Sets the root logger's logging level to DEBUG.
|
|
64
|
+
# 3. Sets the 'format' string used to display messages.
|
|
65
|
+
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s [%(name)s:%(levelname)s] %(message)s', force=True)
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
When running your application, you should see output like this if debug logging is enabled:
|
|
69
|
+
```
|
|
70
|
+
2024-09-16 15:44:45,174 [ibm-cloud-sdk-core:DEBUG] Get authenticator from environment, key=global_search
|
|
71
|
+
2024-09-16 15:44:45,175 [ibm-cloud-sdk-core:DEBUG] Set service URL: https://api.global-search-tagging.cloud.ibm.com
|
|
72
|
+
2024-09-16 15:44:45,175 [ibm-cloud-sdk-core:DEBUG] Set User-Agent: ibm-python-sdk-core-3.21.0 os.name=Linux os.version=6.10.9-100.fc39.x86_64 python.version=3.12.5
|
|
73
|
+
2024-09-16 15:44:45,181 [ibm-cloud-sdk-core:DEBUG] Configuring BaseService instance with service name: global_search
|
|
74
|
+
2024-09-16 15:44:45,181 [ibm-cloud-sdk-core:DEBUG] Performing synchronous token fetch
|
|
75
|
+
2024-09-16 15:44:45,182 [ibm-cloud-sdk-core:DEBUG] Invoking IAM get_token operation: https://iam.cloud.ibm.com/identity/token
|
|
76
|
+
2024-09-16 15:44:45,182 [urllib3.connectionpool:DEBUG] Starting new HTTPS connection (1): iam.cloud.ibm.com:443
|
|
77
|
+
send: b'POST /identity/token HTTP/1.1\r\nHost: iam.cloud.ibm.com\r\nUser-Agent: ibm-python-sdk-core/iam-authenticator-3.21.0 os.name=Linux os.version=6.10.9-100.fc39.x86_64 python.version=3.12.5\r\nAccept-Encoding: gzip, deflate\r\nAccept: application/json\r\nConnection: keep-alive\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: 135\r\n\r\n'
|
|
78
|
+
send: b'grant_type=urn%3Aibm%3Aparams%3Aoauth%3Agrant-type%3Aapikey&apikey=[redacted]&response_type=cloud_iam'
|
|
79
|
+
reply: 'HTTP/1.1 200 OK\r\n'
|
|
80
|
+
header: Content-Type: application/json
|
|
81
|
+
header: Content-Language: en-US
|
|
82
|
+
header: Content-Encoding: gzip
|
|
83
|
+
header: Date: Mon, 16 Sep 2024 20:44:45 GMT
|
|
84
|
+
header: Content-Length: 983
|
|
85
|
+
header: Connection: keep-alive
|
|
86
|
+
2024-09-16 15:44:45,670 [urllib3.connectionpool:DEBUG] https://iam.cloud.ibm.com:443 "POST /identity/token HTTP/11" 200 983
|
|
87
|
+
2024-09-16 15:44:45,672 [ibm-cloud-sdk-core:DEBUG] Returned from IAM get_token operation
|
|
88
|
+
2024-09-16 15:44:45,673 [ibm-cloud-sdk-core:DEBUG] Authenticated outbound request (type=iam)
|
|
89
|
+
2024-09-16 15:44:45,673 [ibm-cloud-sdk-core:DEBUG] Prepared request [POST https://api.global-search-tagging.cloud.ibm.com/v3/resources/search]
|
|
90
|
+
2024-09-16 15:44:45,673 [ibm-cloud-sdk-core:DEBUG] Sending HTTP request message
|
|
91
|
+
2024-09-16 15:44:45,674 [urllib3.connectionpool:DEBUG] Starting new HTTPS connection (1): api.global-search-tagging.cloud.ibm.com:443
|
|
92
|
+
send: b'POST /v3/resources/search?limit=1 HTTP/1.1\r\nHost: api.global-search-tagging.cloud.ibm.com\r\nUser-Agent: platform-services-python-sdk/0.57.0 (lang=python; os.name=Linux; os.version=6.10.9-100.fc39.x86_64; python.version=3.12.5)\r\nAccept-Encoding: gzip, deflate\r\nAccept: application/json\r\nConnection: keep-alive\r\ncontent-type: application/json\r\nAuthorization: [redacted]\r\nContent-Length: 39\r\n\r\n'
|
|
93
|
+
send: b'{"query": "GST-sdk-*", "fields": ["*"]}'
|
|
94
|
+
reply: 'HTTP/1.1 200 OK\r\n'
|
|
95
|
+
header: Content-Type: application/json
|
|
96
|
+
header: Content-Length: 22
|
|
97
|
+
header: Date: Mon, 16 Sep 2024 20:44:46 GMT
|
|
98
|
+
header: Connection: keep-alive
|
|
99
|
+
2024-09-16 15:44:46,079 [urllib3.connectionpool:DEBUG] https://api.global-search-tagging.cloud.ibm.com:443 "POST /v3/resources/search?limit=1 HTTP/11" 200 22
|
|
100
|
+
2024-09-16 15:44:46,080 [ibm-cloud-sdk-core:DEBUG] Received HTTP response message, status code 200
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Open source @ IBM
|
|
104
|
+
|
|
105
|
+
Find more open source projects on the [IBM Github Page](http://github.com/IBM)
|
|
106
|
+
|
|
107
|
+
## License
|
|
108
|
+
|
|
109
|
+
This library is licensed under Apache 2.0. Full license text is
|
|
110
|
+
available in [LICENSE](LICENSE).
|
|
111
|
+
|
|
112
|
+
## Contributing
|
|
113
|
+
|
|
114
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
|
|
3
|
+
# Copyright 2019 IBM All Rights Reserved.
|
|
4
|
+
#
|
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
# See the License for the specific language governing permissions and
|
|
15
|
+
# limitations under the License.
|
|
16
|
+
"""The ibm_cloud_sdk_core project supports the following types of authentication:
|
|
17
|
+
|
|
18
|
+
Basic Authentication
|
|
19
|
+
Bearer Token
|
|
20
|
+
Identity and Access Management (IAM)
|
|
21
|
+
Cloud Pak for Data
|
|
22
|
+
No Authentication
|
|
23
|
+
|
|
24
|
+
The authentication types that are appropriate for a particular service may vary from service to service.
|
|
25
|
+
Each authentication type is implemented as an Authenticator for consumption by a service.
|
|
26
|
+
|
|
27
|
+
classes:
|
|
28
|
+
Authenticator: Abstract Base Class. Implement this interface to provide custom authentication schemes to services.
|
|
29
|
+
BasicAuthenticator: Authenticator for passing supplied basic authentication information to service endpoint.
|
|
30
|
+
BearerTokenAuthenticator: Authenticator for passing supplied bearer token to service endpoint.
|
|
31
|
+
CloudPakForDataAuthenticator: Authenticator for passing CP4D authentication information to service endpoint.
|
|
32
|
+
IAMAuthenticator: Authenticator for passing IAM authentication information to service endpoint.
|
|
33
|
+
NoAuthAuthenticator: Performs no authentication. Useful for testing purposes.
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
from .authenticator import Authenticator
|
|
37
|
+
from .basic_authenticator import BasicAuthenticator
|
|
38
|
+
from .bearer_token_authenticator import BearerTokenAuthenticator
|
|
39
|
+
from .container_authenticator import ContainerAuthenticator
|
|
40
|
+
from .cp4d_authenticator import CloudPakForDataAuthenticator
|
|
41
|
+
from .iam_authenticator import IAMAuthenticator
|
|
42
|
+
from .vpc_instance_authenticator import VPCInstanceAuthenticator
|
|
43
|
+
from .no_auth_authenticator import NoAuthAuthenticator
|
|
44
|
+
from .mcsp_authenticator import MCSPAuthenticator
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
|
|
3
|
+
# Copyright 2019, 2023 IBM All Rights Reserved.
|
|
4
|
+
#
|
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
# See the License for the specific language governing permissions and
|
|
15
|
+
# limitations under the License.
|
|
16
|
+
|
|
17
|
+
from abc import ABC, abstractmethod
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class Authenticator(ABC):
|
|
21
|
+
"""This interface defines the common methods and constants associated with an Authenticator implementation."""
|
|
22
|
+
|
|
23
|
+
# Constants representing the various authenticator types.
|
|
24
|
+
AUTHTYPE_BASIC = 'basic'
|
|
25
|
+
AUTHTYPE_BEARERTOKEN = 'bearerToken'
|
|
26
|
+
AUTHTYPE_IAM = 'iam'
|
|
27
|
+
AUTHTYPE_CONTAINER = 'container'
|
|
28
|
+
AUTHTYPE_CP4D = 'cp4d'
|
|
29
|
+
AUTHTYPE_VPC = 'vpc'
|
|
30
|
+
AUTHTYPE_NOAUTH = 'noAuth'
|
|
31
|
+
AUTHTYPE_MCSP = 'mcsp'
|
|
32
|
+
AUTHTYPE_UNKNOWN = 'unknown'
|
|
33
|
+
|
|
34
|
+
@abstractmethod
|
|
35
|
+
def authenticate(self, req: dict) -> None:
|
|
36
|
+
"""Perform the necessary authentication steps for the specified request.
|
|
37
|
+
|
|
38
|
+
Attributes:
|
|
39
|
+
req (dict): Will be modified to contain the appropriate authentication information.
|
|
40
|
+
|
|
41
|
+
To be implemented by subclasses.
|
|
42
|
+
"""
|
|
43
|
+
pass
|
|
44
|
+
|
|
45
|
+
@abstractmethod
|
|
46
|
+
def validate(self) -> None:
|
|
47
|
+
"""Validates the current set of configuration information in the Authenticator.
|
|
48
|
+
|
|
49
|
+
Raises:
|
|
50
|
+
ValueError: The configuration information is not valid for service operations.
|
|
51
|
+
|
|
52
|
+
To be implemented by subclasses.
|
|
53
|
+
"""
|
|
54
|
+
pass
|
|
55
|
+
|
|
56
|
+
def authentication_type(self) -> str:
|
|
57
|
+
"""Returns the authenticator's type. This method should be overridden by each authenticator implementation."""
|
|
58
|
+
return self.AUTHTYPE_UNKNOWN
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
|
|
3
|
+
# Copyright 2019, 2024 IBM All Rights Reserved.
|
|
4
|
+
#
|
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
# See the License for the specific language governing permissions and
|
|
15
|
+
# limitations under the License.
|
|
16
|
+
|
|
17
|
+
import base64
|
|
18
|
+
|
|
19
|
+
from requests import Request
|
|
20
|
+
|
|
21
|
+
from ibm_cloud_sdk_core.logger import get_logger
|
|
22
|
+
from .authenticator import Authenticator
|
|
23
|
+
from ..utils import has_bad_first_or_last_char
|
|
24
|
+
|
|
25
|
+
logger = get_logger()
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class BasicAuthenticator(Authenticator):
|
|
29
|
+
"""The BasicAuthenticator is used to add basic authentication information to requests.
|
|
30
|
+
|
|
31
|
+
Basic Authorization will be sent as an Authorization header in the form:
|
|
32
|
+
|
|
33
|
+
Authorization: Basic <encoded username and password>
|
|
34
|
+
|
|
35
|
+
Args:
|
|
36
|
+
username: User-supplied username for basic auth.
|
|
37
|
+
password: User-supplied password for basic auth.
|
|
38
|
+
|
|
39
|
+
Raises:
|
|
40
|
+
ValueError: The username or password is not specified or contains invalid characters.
|
|
41
|
+
"""
|
|
42
|
+
|
|
43
|
+
def __init__(self, username: str, password: str) -> None:
|
|
44
|
+
self.username = username
|
|
45
|
+
self.password = password
|
|
46
|
+
self.validate()
|
|
47
|
+
self.authorization_header = self.__construct_basic_auth_header()
|
|
48
|
+
logger.debug('Created new BasicAuthenticator instance!')
|
|
49
|
+
|
|
50
|
+
def authentication_type(self) -> str:
|
|
51
|
+
"""Returns this authenticator's type ('basic')."""
|
|
52
|
+
return Authenticator.AUTHTYPE_BASIC
|
|
53
|
+
|
|
54
|
+
def validate(self) -> None:
|
|
55
|
+
"""Validate username and password.
|
|
56
|
+
|
|
57
|
+
Ensure the username and password are valid for service operations.
|
|
58
|
+
|
|
59
|
+
Raises:
|
|
60
|
+
ValueError: The username and/or password is not valid for service operations.
|
|
61
|
+
"""
|
|
62
|
+
if self.username is None or self.password is None:
|
|
63
|
+
raise ValueError('The username and password shouldn\'t be None.')
|
|
64
|
+
|
|
65
|
+
if has_bad_first_or_last_char(self.username) or has_bad_first_or_last_char(self.password):
|
|
66
|
+
raise ValueError(
|
|
67
|
+
'The username and password shouldn\'t start or end with curly brackets or quotes. '
|
|
68
|
+
'Please remove any surrounding {, }, or \" characters.'
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
def __construct_basic_auth_header(self) -> str:
|
|
72
|
+
authstring = "{0}:{1}".format(self.username, self.password)
|
|
73
|
+
base64_authorization = base64.b64encode(authstring.encode('utf-8')).decode('utf-8')
|
|
74
|
+
return 'Basic {0}'.format(base64_authorization)
|
|
75
|
+
|
|
76
|
+
def authenticate(self, req: Request) -> None:
|
|
77
|
+
"""Add basic authentication information to a request.
|
|
78
|
+
|
|
79
|
+
Basic Authorization will be added to the request's headers in the form:
|
|
80
|
+
|
|
81
|
+
Authorization: Basic <encoded username and password>
|
|
82
|
+
|
|
83
|
+
Args:
|
|
84
|
+
req: The request to add basic auth information to. Must contain a key to a dictionary
|
|
85
|
+
called headers.
|
|
86
|
+
"""
|
|
87
|
+
headers = req.get('headers')
|
|
88
|
+
headers['Authorization'] = self.authorization_header
|
|
89
|
+
logger.debug('Authenticated outbound request (type=%s)', self.authentication_type())
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
|
|
3
|
+
# Copyright 2019, 2024 IBM All Rights Reserved.
|
|
4
|
+
#
|
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
# See the License for the specific language governing permissions and
|
|
15
|
+
# limitations under the License.
|
|
16
|
+
|
|
17
|
+
from requests import Request
|
|
18
|
+
|
|
19
|
+
from ibm_cloud_sdk_core.logger import get_logger
|
|
20
|
+
from .authenticator import Authenticator
|
|
21
|
+
|
|
22
|
+
logger = get_logger()
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class BearerTokenAuthenticator(Authenticator):
|
|
26
|
+
"""The BearerTokenAuthenticator will add a user-supplied bearer token
|
|
27
|
+
to requests.
|
|
28
|
+
|
|
29
|
+
The bearer token will be sent as an Authorization header in the form:
|
|
30
|
+
|
|
31
|
+
Authorization: Bearer <bearer-token>
|
|
32
|
+
|
|
33
|
+
Args:
|
|
34
|
+
bearer_token: The user supplied bearer token.
|
|
35
|
+
|
|
36
|
+
Raises:
|
|
37
|
+
ValueError: Bearer token is none.
|
|
38
|
+
"""
|
|
39
|
+
|
|
40
|
+
def __init__(self, bearer_token: str) -> None:
|
|
41
|
+
self.bearer_token = bearer_token
|
|
42
|
+
self.validate()
|
|
43
|
+
logger.debug('Created BearerTokenAuthenticator instance!')
|
|
44
|
+
|
|
45
|
+
def authentication_type(self) -> str:
|
|
46
|
+
"""Returns this authenticator's type ('bearertoken')."""
|
|
47
|
+
return Authenticator.AUTHTYPE_BEARERTOKEN
|
|
48
|
+
|
|
49
|
+
def validate(self) -> None:
|
|
50
|
+
"""Validate the bearer token.
|
|
51
|
+
|
|
52
|
+
Ensures the bearer token is valid for service operations.
|
|
53
|
+
|
|
54
|
+
Raises:
|
|
55
|
+
ValueError: The bearer token is not valid for service operations.
|
|
56
|
+
"""
|
|
57
|
+
if self.bearer_token is None:
|
|
58
|
+
raise ValueError('The bearer token shouldn\'t be None.')
|
|
59
|
+
|
|
60
|
+
def authenticate(self, req: Request) -> None:
|
|
61
|
+
"""Adds bearer authentication information to the request.
|
|
62
|
+
|
|
63
|
+
The bearer token will be added to the request's headers in the form:
|
|
64
|
+
|
|
65
|
+
Authorization: Bearer <bearer-token>
|
|
66
|
+
|
|
67
|
+
Args:
|
|
68
|
+
req: The request to add bearer authentication information to. Must contain a key to a dictionary
|
|
69
|
+
called headers.
|
|
70
|
+
"""
|
|
71
|
+
headers = req.get('headers')
|
|
72
|
+
headers['Authorization'] = 'Bearer {0}'.format(self.bearer_token)
|
|
73
|
+
logger.debug('Authenticated outbound request (type=%s)', self.authentication_type())
|
|
74
|
+
|
|
75
|
+
def set_bearer_token(self, bearer_token: str) -> None:
|
|
76
|
+
"""Set a new bearer token to be sent in subsequent service operations.
|
|
77
|
+
|
|
78
|
+
Args:
|
|
79
|
+
bearer_token: The bearer token that will be sent in service requests.
|
|
80
|
+
|
|
81
|
+
Raises:
|
|
82
|
+
ValueError: The bearer token is not valid for service operations.
|
|
83
|
+
"""
|
|
84
|
+
self.bearer_token = bearer_token
|
|
85
|
+
self.validate()
|