ibm-cloud-sdk-core 3.20.6__tar.gz → 3.22.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.22.0/PKG-INFO +160 -0
- ibm_cloud_sdk_core-3.22.0/README.md +115 -0
- {ibm_cloud_sdk_core-3.20.6 → ibm_cloud_sdk_core-3.22.0}/ibm_cloud_sdk_core/__init__.py +2 -0
- {ibm_cloud_sdk_core-3.20.6 → ibm_cloud_sdk_core-3.22.0}/ibm_cloud_sdk_core/authenticators/__init__.py +1 -0
- {ibm_cloud_sdk_core-3.20.6 → ibm_cloud_sdk_core-3.22.0}/ibm_cloud_sdk_core/authenticators/authenticator.py +1 -0
- {ibm_cloud_sdk_core-3.20.6 → ibm_cloud_sdk_core-3.22.0}/ibm_cloud_sdk_core/authenticators/basic_authenticator.py +7 -1
- {ibm_cloud_sdk_core-3.20.6 → ibm_cloud_sdk_core-3.22.0}/ibm_cloud_sdk_core/authenticators/bearer_token_authenticator.py +6 -1
- {ibm_cloud_sdk_core-3.20.6 → ibm_cloud_sdk_core-3.22.0}/ibm_cloud_sdk_core/authenticators/container_authenticator.py +1 -0
- {ibm_cloud_sdk_core-3.20.6 → ibm_cloud_sdk_core-3.22.0}/ibm_cloud_sdk_core/authenticators/cp4d_authenticator.py +5 -2
- ibm_cloud_sdk_core-3.22.0/ibm_cloud_sdk_core/authenticators/iam_assume_authenticator.py +146 -0
- {ibm_cloud_sdk_core-3.20.6 → ibm_cloud_sdk_core-3.22.0}/ibm_cloud_sdk_core/authenticators/iam_request_based_authenticator.py +5 -1
- {ibm_cloud_sdk_core-3.20.6 → ibm_cloud_sdk_core-3.22.0}/ibm_cloud_sdk_core/authenticators/mcsp_authenticator.py +5 -1
- {ibm_cloud_sdk_core-3.20.6 → ibm_cloud_sdk_core-3.22.0}/ibm_cloud_sdk_core/authenticators/vpc_instance_authenticator.py +5 -1
- {ibm_cloud_sdk_core-3.20.6 → ibm_cloud_sdk_core-3.22.0}/ibm_cloud_sdk_core/base_service.py +28 -10
- {ibm_cloud_sdk_core-3.20.6 → ibm_cloud_sdk_core-3.22.0}/ibm_cloud_sdk_core/get_authenticator.py +22 -1
- ibm_cloud_sdk_core-3.22.0/ibm_cloud_sdk_core/logger.py +85 -0
- {ibm_cloud_sdk_core-3.20.6 → ibm_cloud_sdk_core-3.22.0}/ibm_cloud_sdk_core/token_managers/container_token_manager.py +3 -3
- {ibm_cloud_sdk_core-3.20.6 → ibm_cloud_sdk_core-3.22.0}/ibm_cloud_sdk_core/token_managers/cp4d_token_manager.py +5 -0
- ibm_cloud_sdk_core-3.22.0/ibm_cloud_sdk_core/token_managers/iam_assume_token_manager.py +150 -0
- {ibm_cloud_sdk_core-3.20.6 → ibm_cloud_sdk_core-3.22.0}/ibm_cloud_sdk_core/token_managers/iam_request_based_token_manager.py +8 -1
- {ibm_cloud_sdk_core-3.20.6 → ibm_cloud_sdk_core-3.22.0}/ibm_cloud_sdk_core/token_managers/mcsp_token_manager.py +7 -1
- {ibm_cloud_sdk_core-3.20.6 → ibm_cloud_sdk_core-3.22.0}/ibm_cloud_sdk_core/token_managers/token_manager.py +7 -0
- {ibm_cloud_sdk_core-3.20.6 → ibm_cloud_sdk_core-3.22.0}/ibm_cloud_sdk_core/token_managers/vpc_instance_token_manager.py +4 -5
- {ibm_cloud_sdk_core-3.20.6 → ibm_cloud_sdk_core-3.22.0}/ibm_cloud_sdk_core/utils.py +6 -2
- ibm_cloud_sdk_core-3.22.0/ibm_cloud_sdk_core/version.py +1 -0
- ibm_cloud_sdk_core-3.22.0/ibm_cloud_sdk_core.egg-info/PKG-INFO +160 -0
- {ibm_cloud_sdk_core-3.20.6 → ibm_cloud_sdk_core-3.22.0}/ibm_cloud_sdk_core.egg-info/SOURCES.txt +6 -0
- {ibm_cloud_sdk_core-3.20.6 → ibm_cloud_sdk_core-3.22.0}/pyproject.toml +1 -1
- {ibm_cloud_sdk_core-3.20.6 → ibm_cloud_sdk_core-3.22.0}/test/test_api_exception.py +4 -0
- {ibm_cloud_sdk_core-3.20.6 → ibm_cloud_sdk_core-3.22.0}/test/test_authenticator.py +2 -0
- {ibm_cloud_sdk_core-3.20.6 → ibm_cloud_sdk_core-3.22.0}/test/test_base_service.py +9 -0
- {ibm_cloud_sdk_core-3.20.6 → ibm_cloud_sdk_core-3.22.0}/test/test_basic_authenticator.py +4 -0
- {ibm_cloud_sdk_core-3.20.6 → ibm_cloud_sdk_core-3.22.0}/test/test_bearer_authenticator.py +4 -0
- {ibm_cloud_sdk_core-3.20.6 → ibm_cloud_sdk_core-3.22.0}/test/test_container_authenticator.py +1 -1
- {ibm_cloud_sdk_core-3.20.6 → ibm_cloud_sdk_core-3.22.0}/test/test_container_token_manager.py +30 -0
- {ibm_cloud_sdk_core-3.20.6 → ibm_cloud_sdk_core-3.22.0}/test/test_cp4d_authenticator.py +4 -0
- {ibm_cloud_sdk_core-3.20.6 → ibm_cloud_sdk_core-3.22.0}/test/test_cp4d_token_manager.py +4 -0
- {ibm_cloud_sdk_core-3.20.6 → ibm_cloud_sdk_core-3.22.0}/test/test_http_adapter.py +9 -41
- ibm_cloud_sdk_core-3.22.0/test/test_iam_assume_authenticator.py +190 -0
- ibm_cloud_sdk_core-3.22.0/test/test_iam_assume_token_manager.py +241 -0
- {ibm_cloud_sdk_core-3.20.6 → ibm_cloud_sdk_core-3.22.0}/test/test_iam_authenticator.py +4 -0
- {ibm_cloud_sdk_core-3.20.6 → ibm_cloud_sdk_core-3.22.0}/test/test_iam_token_manager.py +4 -0
- {ibm_cloud_sdk_core-3.20.6 → ibm_cloud_sdk_core-3.22.0}/test/test_jwt_token_manager.py +4 -0
- ibm_cloud_sdk_core-3.22.0/test/test_logger.py +94 -0
- {ibm_cloud_sdk_core-3.20.6 → ibm_cloud_sdk_core-3.22.0}/test/test_mcsp_authenticator.py +4 -0
- {ibm_cloud_sdk_core-3.20.6 → ibm_cloud_sdk_core-3.22.0}/test/test_mcsp_token_manager.py +4 -0
- {ibm_cloud_sdk_core-3.20.6 → ibm_cloud_sdk_core-3.22.0}/test/test_utils.py +37 -2
- {ibm_cloud_sdk_core-3.20.6 → ibm_cloud_sdk_core-3.22.0}/test/test_vpc_instance_authenticator.py +4 -0
- {ibm_cloud_sdk_core-3.20.6 → ibm_cloud_sdk_core-3.22.0}/test/test_vpc_instance_token_manager.py +9 -58
- ibm_cloud_sdk_core-3.20.6/PKG-INFO +0 -124
- ibm_cloud_sdk_core-3.20.6/README.md +0 -79
- ibm_cloud_sdk_core-3.20.6/ibm_cloud_sdk_core/version.py +0 -1
- ibm_cloud_sdk_core-3.20.6/ibm_cloud_sdk_core.egg-info/PKG-INFO +0 -124
- {ibm_cloud_sdk_core-3.20.6 → ibm_cloud_sdk_core-3.22.0}/LICENSE +0 -0
- {ibm_cloud_sdk_core-3.20.6 → ibm_cloud_sdk_core-3.22.0}/MANIFEST.in +0 -0
- {ibm_cloud_sdk_core-3.20.6 → ibm_cloud_sdk_core-3.22.0}/ibm_cloud_sdk_core/api_exception.py +0 -0
- {ibm_cloud_sdk_core-3.20.6 → ibm_cloud_sdk_core-3.22.0}/ibm_cloud_sdk_core/authenticators/iam_authenticator.py +0 -0
- {ibm_cloud_sdk_core-3.20.6 → ibm_cloud_sdk_core-3.22.0}/ibm_cloud_sdk_core/authenticators/no_auth_authenticator.py +0 -0
- {ibm_cloud_sdk_core-3.20.6 → ibm_cloud_sdk_core-3.22.0}/ibm_cloud_sdk_core/detailed_response.py +0 -0
- {ibm_cloud_sdk_core-3.20.6 → ibm_cloud_sdk_core-3.22.0}/ibm_cloud_sdk_core/http_adapter.py +0 -0
- {ibm_cloud_sdk_core-3.20.6 → ibm_cloud_sdk_core-3.22.0}/ibm_cloud_sdk_core/private_helpers.py +0 -0
- {ibm_cloud_sdk_core-3.20.6 → ibm_cloud_sdk_core-3.22.0}/ibm_cloud_sdk_core/token_managers/__init__.py +0 -0
- {ibm_cloud_sdk_core-3.20.6 → ibm_cloud_sdk_core-3.22.0}/ibm_cloud_sdk_core/token_managers/iam_token_manager.py +0 -0
- {ibm_cloud_sdk_core-3.20.6 → ibm_cloud_sdk_core-3.22.0}/ibm_cloud_sdk_core/token_managers/jwt_token_manager.py +0 -0
- {ibm_cloud_sdk_core-3.20.6 → ibm_cloud_sdk_core-3.22.0}/ibm_cloud_sdk_core.egg-info/dependency_links.txt +0 -0
- {ibm_cloud_sdk_core-3.20.6 → ibm_cloud_sdk_core-3.22.0}/ibm_cloud_sdk_core.egg-info/requires.txt +0 -0
- {ibm_cloud_sdk_core-3.20.6 → ibm_cloud_sdk_core-3.22.0}/ibm_cloud_sdk_core.egg-info/top_level.txt +0 -0
- {ibm_cloud_sdk_core-3.20.6 → ibm_cloud_sdk_core-3.22.0}/setup.cfg +0 -0
- {ibm_cloud_sdk_core-3.20.6 → ibm_cloud_sdk_core-3.22.0}/test/test_detailed_response.py +0 -0
- {ibm_cloud_sdk_core-3.20.6 → ibm_cloud_sdk_core-3.22.0}/test/test_no_auth_authenticator.py +0 -0
- {ibm_cloud_sdk_core-3.20.6 → ibm_cloud_sdk_core-3.22.0}/test/test_token_manager.py +0 -0
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: ibm-cloud-sdk-core
|
|
3
|
+
Version: 3.22.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.22.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 (grant type: apikey)
|
|
72
|
+
- Identity and Access Management (IAM) Authentication (grant type: assume)
|
|
73
|
+
- Container Authentication
|
|
74
|
+
- VPC Instance Authentication
|
|
75
|
+
- Cloud Pak for Data Authentication
|
|
76
|
+
- No Authentication (for testing)
|
|
77
|
+
|
|
78
|
+
For more information about the various authentication types and how to use them with your services, click [here](Authentication.md).
|
|
79
|
+
|
|
80
|
+
## Issues
|
|
81
|
+
|
|
82
|
+
If you encounter an issue with this project, you are welcome to submit a [bug report](https://github.com/IBM/python-sdk-core/issues).
|
|
83
|
+
Before opening a new issue, please search for similar issues. It's possible that someone has already reported it.
|
|
84
|
+
|
|
85
|
+
## Logging
|
|
86
|
+
|
|
87
|
+
This library uses Python's built-in `logging` module to perform logging of error,
|
|
88
|
+
warning, informational and debug messages.
|
|
89
|
+
The components within the SDK Core library use a single logger named `ibm-cloud-sdk-core`.
|
|
90
|
+
|
|
91
|
+
For complete information on the logging facility, please see: [Logging facility for Python](https://docs.python.org/3/library/logging.html).
|
|
92
|
+
|
|
93
|
+
### Enable logging
|
|
94
|
+
|
|
95
|
+
There are various ways to configure and enable the logging facility.
|
|
96
|
+
|
|
97
|
+
The code example below demonstrates a simple way to enable debug logging by invoking
|
|
98
|
+
the `logging.basicConfig()` function.
|
|
99
|
+
|
|
100
|
+
Note that, as a convenience, if you set the logging level to `DEBUG`, then HTTP request/response message logging
|
|
101
|
+
is also enabled.
|
|
102
|
+
|
|
103
|
+
The following code example shows how debug logging can be enabled:
|
|
104
|
+
```python
|
|
105
|
+
import logging
|
|
106
|
+
|
|
107
|
+
# Create a basic logging configuration that:
|
|
108
|
+
# 1. Defines a handler to display messages on the console.
|
|
109
|
+
# 2. Sets the root logger's logging level to DEBUG.
|
|
110
|
+
# 3. Sets the 'format' string used to display messages.
|
|
111
|
+
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s [%(name)s:%(levelname)s] %(message)s', force=True)
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
When running your application, you should see output like this if debug logging is enabled:
|
|
115
|
+
```
|
|
116
|
+
2024-09-16 15:44:45,174 [ibm-cloud-sdk-core:DEBUG] Get authenticator from environment, key=global_search
|
|
117
|
+
2024-09-16 15:44:45,175 [ibm-cloud-sdk-core:DEBUG] Set service URL: https://api.global-search-tagging.cloud.ibm.com
|
|
118
|
+
2024-09-16 15:44:45,175 [ibm-cloud-sdk-core:DEBUG] Set User-Agent: ibm-python-sdk-core-3.22.0 os.name=Linux os.version=6.10.9-100.fc39.x86_64 python.version=3.12.5
|
|
119
|
+
2024-09-16 15:44:45,181 [ibm-cloud-sdk-core:DEBUG] Configuring BaseService instance with service name: global_search
|
|
120
|
+
2024-09-16 15:44:45,181 [ibm-cloud-sdk-core:DEBUG] Performing synchronous token fetch
|
|
121
|
+
2024-09-16 15:44:45,182 [ibm-cloud-sdk-core:DEBUG] Invoking IAM get_token operation: https://iam.cloud.ibm.com/identity/token
|
|
122
|
+
2024-09-16 15:44:45,182 [urllib3.connectionpool:DEBUG] Starting new HTTPS connection (1): iam.cloud.ibm.com:443
|
|
123
|
+
send: b'POST /identity/token HTTP/1.1\r\nHost: iam.cloud.ibm.com\r\nUser-Agent: ibm-python-sdk-core/iam-authenticator-3.22.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'
|
|
124
|
+
send: b'grant_type=urn%3Aibm%3Aparams%3Aoauth%3Agrant-type%3Aapikey&apikey=[redacted]&response_type=cloud_iam'
|
|
125
|
+
reply: 'HTTP/1.1 200 OK\r\n'
|
|
126
|
+
header: Content-Type: application/json
|
|
127
|
+
header: Content-Language: en-US
|
|
128
|
+
header: Content-Encoding: gzip
|
|
129
|
+
header: Date: Mon, 16 Sep 2024 20:44:45 GMT
|
|
130
|
+
header: Content-Length: 983
|
|
131
|
+
header: Connection: keep-alive
|
|
132
|
+
2024-09-16 15:44:45,670 [urllib3.connectionpool:DEBUG] https://iam.cloud.ibm.com:443 "POST /identity/token HTTP/11" 200 983
|
|
133
|
+
2024-09-16 15:44:45,672 [ibm-cloud-sdk-core:DEBUG] Returned from IAM get_token operation
|
|
134
|
+
2024-09-16 15:44:45,673 [ibm-cloud-sdk-core:DEBUG] Authenticated outbound request (type=iam)
|
|
135
|
+
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]
|
|
136
|
+
2024-09-16 15:44:45,673 [ibm-cloud-sdk-core:DEBUG] Sending HTTP request message
|
|
137
|
+
2024-09-16 15:44:45,674 [urllib3.connectionpool:DEBUG] Starting new HTTPS connection (1): api.global-search-tagging.cloud.ibm.com:443
|
|
138
|
+
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'
|
|
139
|
+
send: b'{"query": "GST-sdk-*", "fields": ["*"]}'
|
|
140
|
+
reply: 'HTTP/1.1 200 OK\r\n'
|
|
141
|
+
header: Content-Type: application/json
|
|
142
|
+
header: Content-Length: 22
|
|
143
|
+
header: Date: Mon, 16 Sep 2024 20:44:46 GMT
|
|
144
|
+
header: Connection: keep-alive
|
|
145
|
+
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
|
|
146
|
+
2024-09-16 15:44:46,080 [ibm-cloud-sdk-core:DEBUG] Received HTTP response message, status code 200
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## Open source @ IBM
|
|
150
|
+
|
|
151
|
+
Find more open source projects on the [IBM Github Page](http://github.com/IBM)
|
|
152
|
+
|
|
153
|
+
## License
|
|
154
|
+
|
|
155
|
+
This library is licensed under Apache 2.0. Full license text is
|
|
156
|
+
available in [LICENSE](LICENSE).
|
|
157
|
+
|
|
158
|
+
## Contributing
|
|
159
|
+
|
|
160
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
@@ -0,0 +1,115 @@
|
|
|
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.22.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 (grant type: apikey)
|
|
27
|
+
- Identity and Access Management (IAM) Authentication (grant type: assume)
|
|
28
|
+
- Container Authentication
|
|
29
|
+
- VPC Instance Authentication
|
|
30
|
+
- Cloud Pak for Data Authentication
|
|
31
|
+
- No Authentication (for testing)
|
|
32
|
+
|
|
33
|
+
For more information about the various authentication types and how to use them with your services, click [here](Authentication.md).
|
|
34
|
+
|
|
35
|
+
## Issues
|
|
36
|
+
|
|
37
|
+
If you encounter an issue with this project, you are welcome to submit a [bug report](https://github.com/IBM/python-sdk-core/issues).
|
|
38
|
+
Before opening a new issue, please search for similar issues. It's possible that someone has already reported it.
|
|
39
|
+
|
|
40
|
+
## Logging
|
|
41
|
+
|
|
42
|
+
This library uses Python's built-in `logging` module to perform logging of error,
|
|
43
|
+
warning, informational and debug messages.
|
|
44
|
+
The components within the SDK Core library use a single logger named `ibm-cloud-sdk-core`.
|
|
45
|
+
|
|
46
|
+
For complete information on the logging facility, please see: [Logging facility for Python](https://docs.python.org/3/library/logging.html).
|
|
47
|
+
|
|
48
|
+
### Enable logging
|
|
49
|
+
|
|
50
|
+
There are various ways to configure and enable the logging facility.
|
|
51
|
+
|
|
52
|
+
The code example below demonstrates a simple way to enable debug logging by invoking
|
|
53
|
+
the `logging.basicConfig()` function.
|
|
54
|
+
|
|
55
|
+
Note that, as a convenience, if you set the logging level to `DEBUG`, then HTTP request/response message logging
|
|
56
|
+
is also enabled.
|
|
57
|
+
|
|
58
|
+
The following code example shows how debug logging can be enabled:
|
|
59
|
+
```python
|
|
60
|
+
import logging
|
|
61
|
+
|
|
62
|
+
# Create a basic logging configuration that:
|
|
63
|
+
# 1. Defines a handler to display messages on the console.
|
|
64
|
+
# 2. Sets the root logger's logging level to DEBUG.
|
|
65
|
+
# 3. Sets the 'format' string used to display messages.
|
|
66
|
+
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s [%(name)s:%(levelname)s] %(message)s', force=True)
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
When running your application, you should see output like this if debug logging is enabled:
|
|
70
|
+
```
|
|
71
|
+
2024-09-16 15:44:45,174 [ibm-cloud-sdk-core:DEBUG] Get authenticator from environment, key=global_search
|
|
72
|
+
2024-09-16 15:44:45,175 [ibm-cloud-sdk-core:DEBUG] Set service URL: https://api.global-search-tagging.cloud.ibm.com
|
|
73
|
+
2024-09-16 15:44:45,175 [ibm-cloud-sdk-core:DEBUG] Set User-Agent: ibm-python-sdk-core-3.22.0 os.name=Linux os.version=6.10.9-100.fc39.x86_64 python.version=3.12.5
|
|
74
|
+
2024-09-16 15:44:45,181 [ibm-cloud-sdk-core:DEBUG] Configuring BaseService instance with service name: global_search
|
|
75
|
+
2024-09-16 15:44:45,181 [ibm-cloud-sdk-core:DEBUG] Performing synchronous token fetch
|
|
76
|
+
2024-09-16 15:44:45,182 [ibm-cloud-sdk-core:DEBUG] Invoking IAM get_token operation: https://iam.cloud.ibm.com/identity/token
|
|
77
|
+
2024-09-16 15:44:45,182 [urllib3.connectionpool:DEBUG] Starting new HTTPS connection (1): iam.cloud.ibm.com:443
|
|
78
|
+
send: b'POST /identity/token HTTP/1.1\r\nHost: iam.cloud.ibm.com\r\nUser-Agent: ibm-python-sdk-core/iam-authenticator-3.22.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'
|
|
79
|
+
send: b'grant_type=urn%3Aibm%3Aparams%3Aoauth%3Agrant-type%3Aapikey&apikey=[redacted]&response_type=cloud_iam'
|
|
80
|
+
reply: 'HTTP/1.1 200 OK\r\n'
|
|
81
|
+
header: Content-Type: application/json
|
|
82
|
+
header: Content-Language: en-US
|
|
83
|
+
header: Content-Encoding: gzip
|
|
84
|
+
header: Date: Mon, 16 Sep 2024 20:44:45 GMT
|
|
85
|
+
header: Content-Length: 983
|
|
86
|
+
header: Connection: keep-alive
|
|
87
|
+
2024-09-16 15:44:45,670 [urllib3.connectionpool:DEBUG] https://iam.cloud.ibm.com:443 "POST /identity/token HTTP/11" 200 983
|
|
88
|
+
2024-09-16 15:44:45,672 [ibm-cloud-sdk-core:DEBUG] Returned from IAM get_token operation
|
|
89
|
+
2024-09-16 15:44:45,673 [ibm-cloud-sdk-core:DEBUG] Authenticated outbound request (type=iam)
|
|
90
|
+
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]
|
|
91
|
+
2024-09-16 15:44:45,673 [ibm-cloud-sdk-core:DEBUG] Sending HTTP request message
|
|
92
|
+
2024-09-16 15:44:45,674 [urllib3.connectionpool:DEBUG] Starting new HTTPS connection (1): api.global-search-tagging.cloud.ibm.com:443
|
|
93
|
+
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'
|
|
94
|
+
send: b'{"query": "GST-sdk-*", "fields": ["*"]}'
|
|
95
|
+
reply: 'HTTP/1.1 200 OK\r\n'
|
|
96
|
+
header: Content-Type: application/json
|
|
97
|
+
header: Content-Length: 22
|
|
98
|
+
header: Date: Mon, 16 Sep 2024 20:44:46 GMT
|
|
99
|
+
header: Connection: keep-alive
|
|
100
|
+
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
|
|
101
|
+
2024-09-16 15:44:46,080 [ibm-cloud-sdk-core:DEBUG] Received HTTP response message, status code 200
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Open source @ IBM
|
|
105
|
+
|
|
106
|
+
Find more open source projects on the [IBM Github Page](http://github.com/IBM)
|
|
107
|
+
|
|
108
|
+
## License
|
|
109
|
+
|
|
110
|
+
This library is licensed under Apache 2.0. Full license text is
|
|
111
|
+
available in [LICENSE](LICENSE).
|
|
112
|
+
|
|
113
|
+
## Contributing
|
|
114
|
+
|
|
115
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
@@ -18,6 +18,7 @@ classes:
|
|
|
18
18
|
BaseService: Abstract class for common functionality between each service.
|
|
19
19
|
DetailedResponse: The object returned from successful service operations.
|
|
20
20
|
IAMTokenManager: Requests and refreshes IAM tokens using an apikey, and optionally a client_id and client_secret.
|
|
21
|
+
IAMAssumeTokenManager: Requests and refreshes IAM tokens using an apikey and a trusted profile.
|
|
21
22
|
JWTTokenManager: Abstract class for common functionality between each JWT token manager.
|
|
22
23
|
CP4DTokenManager: Requests and refreshes CP4D tokens given a username and password.
|
|
23
24
|
ApiException: Custom exception class for errors returned from service operations.
|
|
@@ -39,6 +40,7 @@ functions:
|
|
|
39
40
|
from .base_service import BaseService
|
|
40
41
|
from .detailed_response import DetailedResponse
|
|
41
42
|
from .token_managers.iam_token_manager import IAMTokenManager
|
|
43
|
+
from .token_managers.iam_assume_token_manager import IAMAssumeTokenManager
|
|
42
44
|
from .token_managers.jwt_token_manager import JWTTokenManager
|
|
43
45
|
from .token_managers.cp4d_token_manager import CP4DTokenManager
|
|
44
46
|
from .token_managers.container_token_manager import ContainerTokenManager
|
|
@@ -39,6 +39,7 @@ from .bearer_token_authenticator import BearerTokenAuthenticator
|
|
|
39
39
|
from .container_authenticator import ContainerAuthenticator
|
|
40
40
|
from .cp4d_authenticator import CloudPakForDataAuthenticator
|
|
41
41
|
from .iam_authenticator import IAMAuthenticator
|
|
42
|
+
from .iam_assume_authenticator import IAMAssumeAuthenticator
|
|
42
43
|
from .vpc_instance_authenticator import VPCInstanceAuthenticator
|
|
43
44
|
from .no_auth_authenticator import NoAuthAuthenticator
|
|
44
45
|
from .mcsp_authenticator import MCSPAuthenticator
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# coding: utf-8
|
|
2
2
|
|
|
3
|
-
# Copyright 2019 IBM All Rights Reserved.
|
|
3
|
+
# Copyright 2019, 2024 IBM All Rights Reserved.
|
|
4
4
|
#
|
|
5
5
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
6
|
# you may not use this file except in compliance with the License.
|
|
@@ -15,11 +15,15 @@
|
|
|
15
15
|
# limitations under the License.
|
|
16
16
|
|
|
17
17
|
import base64
|
|
18
|
+
|
|
18
19
|
from requests import Request
|
|
19
20
|
|
|
21
|
+
from ibm_cloud_sdk_core.logger import get_logger
|
|
20
22
|
from .authenticator import Authenticator
|
|
21
23
|
from ..utils import has_bad_first_or_last_char
|
|
22
24
|
|
|
25
|
+
logger = get_logger()
|
|
26
|
+
|
|
23
27
|
|
|
24
28
|
class BasicAuthenticator(Authenticator):
|
|
25
29
|
"""The BasicAuthenticator is used to add basic authentication information to requests.
|
|
@@ -41,6 +45,7 @@ class BasicAuthenticator(Authenticator):
|
|
|
41
45
|
self.password = password
|
|
42
46
|
self.validate()
|
|
43
47
|
self.authorization_header = self.__construct_basic_auth_header()
|
|
48
|
+
logger.debug('Created new BasicAuthenticator instance!')
|
|
44
49
|
|
|
45
50
|
def authentication_type(self) -> str:
|
|
46
51
|
"""Returns this authenticator's type ('basic')."""
|
|
@@ -81,3 +86,4 @@ class BasicAuthenticator(Authenticator):
|
|
|
81
86
|
"""
|
|
82
87
|
headers = req.get('headers')
|
|
83
88
|
headers['Authorization'] = self.authorization_header
|
|
89
|
+
logger.debug('Authenticated outbound request (type=%s)', self.authentication_type())
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# coding: utf-8
|
|
2
2
|
|
|
3
|
-
# Copyright 2019 IBM All Rights Reserved.
|
|
3
|
+
# Copyright 2019, 2024 IBM All Rights Reserved.
|
|
4
4
|
#
|
|
5
5
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
6
|
# you may not use this file except in compliance with the License.
|
|
@@ -16,8 +16,11 @@
|
|
|
16
16
|
|
|
17
17
|
from requests import Request
|
|
18
18
|
|
|
19
|
+
from ibm_cloud_sdk_core.logger import get_logger
|
|
19
20
|
from .authenticator import Authenticator
|
|
20
21
|
|
|
22
|
+
logger = get_logger()
|
|
23
|
+
|
|
21
24
|
|
|
22
25
|
class BearerTokenAuthenticator(Authenticator):
|
|
23
26
|
"""The BearerTokenAuthenticator will add a user-supplied bearer token
|
|
@@ -37,6 +40,7 @@ class BearerTokenAuthenticator(Authenticator):
|
|
|
37
40
|
def __init__(self, bearer_token: str) -> None:
|
|
38
41
|
self.bearer_token = bearer_token
|
|
39
42
|
self.validate()
|
|
43
|
+
logger.debug('Created BearerTokenAuthenticator instance!')
|
|
40
44
|
|
|
41
45
|
def authentication_type(self) -> str:
|
|
42
46
|
"""Returns this authenticator's type ('bearertoken')."""
|
|
@@ -66,6 +70,7 @@ class BearerTokenAuthenticator(Authenticator):
|
|
|
66
70
|
"""
|
|
67
71
|
headers = req.get('headers')
|
|
68
72
|
headers['Authorization'] = 'Bearer {0}'.format(self.bearer_token)
|
|
73
|
+
logger.debug('Authenticated outbound request (type=%s)', self.authentication_type())
|
|
69
74
|
|
|
70
75
|
def set_bearer_token(self, bearer_token: str) -> None:
|
|
71
76
|
"""Set a new bearer token to be sent in subsequent service operations.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# coding: utf-8
|
|
2
2
|
|
|
3
|
-
# Copyright 2019 IBM All Rights Reserved.
|
|
3
|
+
# Copyright 2019, 2024 IBM All Rights Reserved.
|
|
4
4
|
#
|
|
5
5
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
6
|
# you may not use this file except in compliance with the License.
|
|
@@ -15,13 +15,15 @@
|
|
|
15
15
|
# limitations under the License.
|
|
16
16
|
|
|
17
17
|
from typing import Dict, Optional
|
|
18
|
-
|
|
19
18
|
from requests import Request
|
|
20
19
|
|
|
20
|
+
from ibm_cloud_sdk_core.logger import get_logger
|
|
21
21
|
from .authenticator import Authenticator
|
|
22
22
|
from ..token_managers.cp4d_token_manager import CP4DTokenManager
|
|
23
23
|
from ..utils import has_bad_first_or_last_char
|
|
24
24
|
|
|
25
|
+
logger = get_logger()
|
|
26
|
+
|
|
25
27
|
|
|
26
28
|
class CloudPakForDataAuthenticator(Authenticator):
|
|
27
29
|
"""The CloudPakForDataAuthenticator utilizes a username and password pair to
|
|
@@ -133,6 +135,7 @@ class CloudPakForDataAuthenticator(Authenticator):
|
|
|
133
135
|
headers = req.get('headers')
|
|
134
136
|
bearer_token = self.token_manager.get_token()
|
|
135
137
|
headers['Authorization'] = 'Bearer {0}'.format(bearer_token)
|
|
138
|
+
logger.debug('Authenticated outbound request (type=%s)', self.authentication_type())
|
|
136
139
|
|
|
137
140
|
def set_disable_ssl_verification(self, status: bool = False) -> None:
|
|
138
141
|
"""Set the flag that indicates whether verification of the server's SSL certificate should be
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
|
|
3
|
+
# Copyright 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 typing import Any, Dict, Optional
|
|
18
|
+
|
|
19
|
+
from ibm_cloud_sdk_core.authenticators.iam_authenticator import IAMAuthenticator
|
|
20
|
+
from ibm_cloud_sdk_core.token_managers.iam_assume_token_manager import IAMAssumeTokenManager
|
|
21
|
+
|
|
22
|
+
from .authenticator import Authenticator
|
|
23
|
+
from .iam_request_based_authenticator import IAMRequestBasedAuthenticator
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class IAMAssumeAuthenticator(IAMRequestBasedAuthenticator):
|
|
27
|
+
"""IAMAssumeAuthenticator obtains an IAM access token using the IAM "get-token" operation's
|
|
28
|
+
"assume" grant type. The authenticator obtains an initial IAM access token from a
|
|
29
|
+
user-supplied apikey, then exchanges this initial IAM access token for another IAM access token
|
|
30
|
+
that has "assumed the identity" of the specified trusted profile.
|
|
31
|
+
|
|
32
|
+
The bearer token will be sent as an Authorization header in the form:
|
|
33
|
+
|
|
34
|
+
Authorization: Bearer <bearer-token>
|
|
35
|
+
|
|
36
|
+
Args:
|
|
37
|
+
apikey: The IAM api key.
|
|
38
|
+
|
|
39
|
+
Keyword Args:
|
|
40
|
+
iam_profile_id: the ID of the trusted profile
|
|
41
|
+
iam_profile_crn: the CRN of the trusted profile
|
|
42
|
+
iam_profile_name: the name of the trusted profile (must be used together with `iam_account_id`)
|
|
43
|
+
iam_account_id: the ID of the trusted profile (must be used together with `iam_profile_name`)
|
|
44
|
+
url: The URL representing the IAM token service endpoint. If not specified, a suitable default value is used.
|
|
45
|
+
client_id: The client_id and client_secret fields are used to form
|
|
46
|
+
a "basic" authorization header for IAM token requests. Defaults to None.
|
|
47
|
+
client_secret: The client_id and client_secret fields are used to form
|
|
48
|
+
a "basic" authorization header for IAM token requests. Defaults to None.
|
|
49
|
+
disable_ssl_verification: A flag that indicates whether verification of
|
|
50
|
+
the server's SSL certificate should be disabled or not. Defaults to False.
|
|
51
|
+
headers: Default headers to be sent with every IAM token request. Defaults to None.
|
|
52
|
+
proxies: Dictionary for mapping request protocol to proxy URL. Defaults to None.
|
|
53
|
+
proxies.http (optional): The proxy endpoint to use for HTTP requests.
|
|
54
|
+
proxies.https (optional): The proxy endpoint to use for HTTPS requests.
|
|
55
|
+
scope: The "scope" to use when fetching the bearer token from the IAM token server.
|
|
56
|
+
This can be used to obtain an access token with a specific scope.
|
|
57
|
+
|
|
58
|
+
Attributes:
|
|
59
|
+
token_manager (IAMTokenManager): Retrieves and manages IAM tokens from the endpoint specified by the url.
|
|
60
|
+
|
|
61
|
+
Raises:
|
|
62
|
+
TypeError: The `disable_ssl_verification` is not a bool.
|
|
63
|
+
ValueError: The `apikey`, `client_id`, and/or `client_secret` are not valid for IAM token requests or the
|
|
64
|
+
following keyword arguments are incorrectly specified:
|
|
65
|
+
`iam_profile_id`, `iam_profile_crn`, `iam_profile_name`, `iam_account_id`.
|
|
66
|
+
"""
|
|
67
|
+
|
|
68
|
+
def __init__(
|
|
69
|
+
self,
|
|
70
|
+
apikey: str,
|
|
71
|
+
*,
|
|
72
|
+
iam_profile_id: Optional[str] = None,
|
|
73
|
+
iam_profile_crn: Optional[str] = None,
|
|
74
|
+
iam_profile_name: Optional[str] = None,
|
|
75
|
+
iam_account_id: Optional[str] = None,
|
|
76
|
+
url: Optional[str] = None,
|
|
77
|
+
client_id: Optional[str] = None,
|
|
78
|
+
client_secret: Optional[str] = None,
|
|
79
|
+
disable_ssl_verification: bool = False,
|
|
80
|
+
headers: Optional[Dict[str, str]] = None,
|
|
81
|
+
proxies: Optional[Dict[str, str]] = None,
|
|
82
|
+
scope: Optional[str] = None,
|
|
83
|
+
) -> None:
|
|
84
|
+
# Check the type of `disable_ssl_verification`. Must be a bool.
|
|
85
|
+
if not isinstance(disable_ssl_verification, bool):
|
|
86
|
+
raise TypeError('disable_ssl_verification must be a bool')
|
|
87
|
+
|
|
88
|
+
self.token_manager = IAMAssumeTokenManager(
|
|
89
|
+
apikey,
|
|
90
|
+
iam_profile_id=iam_profile_id,
|
|
91
|
+
iam_profile_crn=iam_profile_crn,
|
|
92
|
+
iam_profile_name=iam_profile_name,
|
|
93
|
+
iam_account_id=iam_account_id,
|
|
94
|
+
url=url,
|
|
95
|
+
client_id=client_id,
|
|
96
|
+
client_secret=client_secret,
|
|
97
|
+
disable_ssl_verification=disable_ssl_verification,
|
|
98
|
+
headers=headers,
|
|
99
|
+
proxies=proxies,
|
|
100
|
+
scope=scope,
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
self.validate()
|
|
104
|
+
|
|
105
|
+
# Disable all setter methods, inherited from the parent class.
|
|
106
|
+
def __getattribute__(self, name: str) -> Any:
|
|
107
|
+
if name.startswith("set_"):
|
|
108
|
+
raise AttributeError(f"'{self.__class__.__name__}' has no attribute '{name}'")
|
|
109
|
+
|
|
110
|
+
return super().__getattribute__(name)
|
|
111
|
+
|
|
112
|
+
def authentication_type(self) -> str:
|
|
113
|
+
"""Returns this authenticator's type ('iamAssume')."""
|
|
114
|
+
return Authenticator.AUTHTYPE_IAM_ASSUME
|
|
115
|
+
|
|
116
|
+
def validate(self) -> None:
|
|
117
|
+
"""Validates the provided IAM related arguments.
|
|
118
|
+
|
|
119
|
+
Ensure the following:
|
|
120
|
+
- `apikey` of the IAMTokenManager is not `None`, and has no bad characters
|
|
121
|
+
- both `client_id` and `client_secret` are set if either of them are defined
|
|
122
|
+
- the correct number and type of IAM profile and IAM account options are specified
|
|
123
|
+
|
|
124
|
+
Raises:
|
|
125
|
+
ValueError: The apikey, client_id, and/or client_secret are not valid for IAM token requests.
|
|
126
|
+
"""
|
|
127
|
+
# Create a temporary IAM authenticator that we can use to validate our delegate.
|
|
128
|
+
tmp_authenticator = IAMAuthenticator("")
|
|
129
|
+
tmp_authenticator.token_manager = self.token_manager.iam_delegate
|
|
130
|
+
tmp_authenticator.validate()
|
|
131
|
+
del tmp_authenticator
|
|
132
|
+
|
|
133
|
+
# Only one of the following arguments must be specified.
|
|
134
|
+
mutually_exclusive_attributes = [
|
|
135
|
+
self.token_manager.iam_profile_id,
|
|
136
|
+
self.token_manager.iam_profile_crn,
|
|
137
|
+
self.token_manager.iam_profile_name,
|
|
138
|
+
]
|
|
139
|
+
if list(map(bool, mutually_exclusive_attributes)).count(True) != 1:
|
|
140
|
+
raise ValueError(
|
|
141
|
+
'Exactly one of `iam_profile_id`, `iam_profile_crn`, or `iam_profile_name` must be specified.'
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
# `iam_account_id` must be specified iff `iam_profile_name` is used.
|
|
145
|
+
if self.token_manager.iam_profile_name and not self.token_manager.iam_account_id:
|
|
146
|
+
raise ValueError('`iam_profile_name` and `iam_account_id` must be provided together, or not at all.')
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# coding: utf-8
|
|
2
2
|
|
|
3
|
-
# Copyright 2019 IBM All Rights Reserved.
|
|
3
|
+
# Copyright 2019, 2024 IBM All Rights Reserved.
|
|
4
4
|
#
|
|
5
5
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
6
|
# you may not use this file except in compliance with the License.
|
|
@@ -18,8 +18,11 @@ from typing import Dict
|
|
|
18
18
|
|
|
19
19
|
from requests import Request
|
|
20
20
|
|
|
21
|
+
from ibm_cloud_sdk_core.logger import get_logger
|
|
21
22
|
from .authenticator import Authenticator
|
|
22
23
|
|
|
24
|
+
logger = get_logger()
|
|
25
|
+
|
|
23
26
|
|
|
24
27
|
class IAMRequestBasedAuthenticator(Authenticator):
|
|
25
28
|
"""The IAMRequestBasedAuthenticator class contains code that is common to all authenticators
|
|
@@ -60,6 +63,7 @@ class IAMRequestBasedAuthenticator(Authenticator):
|
|
|
60
63
|
headers = req.get('headers')
|
|
61
64
|
bearer_token = self.token_manager.get_token()
|
|
62
65
|
headers['Authorization'] = 'Bearer {0}'.format(bearer_token)
|
|
66
|
+
logger.debug('Authenticated outbound request (type=%s)', self.authentication_type())
|
|
63
67
|
|
|
64
68
|
def set_client_id_and_secret(self, client_id: str, client_secret: str) -> None:
|
|
65
69
|
"""Set the client_id and client_secret pair the token manager will use for IAM token requests.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# coding: utf-8
|
|
2
2
|
|
|
3
|
-
# Copyright 2023 IBM All Rights Reserved.
|
|
3
|
+
# Copyright 2023, 2024 IBM All Rights Reserved.
|
|
4
4
|
#
|
|
5
5
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
6
|
# you may not use this file except in compliance with the License.
|
|
@@ -18,9 +18,12 @@ from typing import Dict, Optional
|
|
|
18
18
|
|
|
19
19
|
from requests import Request
|
|
20
20
|
|
|
21
|
+
from ibm_cloud_sdk_core.logger import get_logger
|
|
21
22
|
from .authenticator import Authenticator
|
|
22
23
|
from ..token_managers.mcsp_token_manager import MCSPTokenManager
|
|
23
24
|
|
|
25
|
+
logger = get_logger()
|
|
26
|
+
|
|
24
27
|
|
|
25
28
|
class MCSPAuthenticator(Authenticator):
|
|
26
29
|
"""The MCSPAuthenticator uses an apikey to obtain an access token from the MCSP token server.
|
|
@@ -98,6 +101,7 @@ class MCSPAuthenticator(Authenticator):
|
|
|
98
101
|
headers = req.get('headers')
|
|
99
102
|
bearer_token = self.token_manager.get_token()
|
|
100
103
|
headers['Authorization'] = 'Bearer {0}'.format(bearer_token)
|
|
104
|
+
logger.debug('Authenticated outbound request (type=%s)', self.authentication_type())
|
|
101
105
|
|
|
102
106
|
def set_disable_ssl_verification(self, status: bool = False) -> None:
|
|
103
107
|
"""Set the flag that indicates whether verification of the server's SSL certificate should be
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# coding: utf-8
|
|
2
2
|
|
|
3
|
-
# Copyright 2021 IBM All Rights Reserved.
|
|
3
|
+
# Copyright 2021, 2024 IBM All Rights Reserved.
|
|
4
4
|
#
|
|
5
5
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
6
|
# you may not use this file except in compliance with the License.
|
|
@@ -18,9 +18,12 @@ from typing import Optional
|
|
|
18
18
|
|
|
19
19
|
from requests import Request
|
|
20
20
|
|
|
21
|
+
from ibm_cloud_sdk_core.logger import get_logger
|
|
21
22
|
from ..token_managers.vpc_instance_token_manager import VPCInstanceTokenManager
|
|
22
23
|
from .authenticator import Authenticator
|
|
23
24
|
|
|
25
|
+
logger = get_logger()
|
|
26
|
+
|
|
24
27
|
|
|
25
28
|
class VPCInstanceAuthenticator(Authenticator):
|
|
26
29
|
"""VPCInstanceAuthenticator implements an authentication scheme in which it
|
|
@@ -89,6 +92,7 @@ class VPCInstanceAuthenticator(Authenticator):
|
|
|
89
92
|
headers = req.get('headers')
|
|
90
93
|
bearer_token = self.token_manager.get_token()
|
|
91
94
|
headers['Authorization'] = 'Bearer {0}'.format(bearer_token)
|
|
95
|
+
logger.debug('Authenticated outbound request (type=%s)', self.authentication_type())
|
|
92
96
|
|
|
93
97
|
def set_iam_profile_crn(self, iam_profile_crn: str) -> None:
|
|
94
98
|
"""Sets CRN of the IAM profile.
|