ibm-cloud-sdk-core 3.19.2__tar.gz → 3.20.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.
Files changed (70) hide show
  1. {ibm-cloud-sdk-core-3.19.2/ibm_cloud_sdk_core.egg-info → ibm-cloud-sdk-core-3.20.0}/PKG-INFO +2 -2
  2. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0}/README.md +1 -1
  3. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0}/ibm_cloud_sdk_core/api_exception.py +1 -1
  4. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0}/ibm_cloud_sdk_core/base_service.py +3 -14
  5. ibm-cloud-sdk-core-3.20.0/ibm_cloud_sdk_core/private_helpers.py +34 -0
  6. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0}/ibm_cloud_sdk_core/token_managers/container_token_manager.py +3 -1
  7. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0}/ibm_cloud_sdk_core/token_managers/cp4d_token_manager.py +12 -2
  8. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0}/ibm_cloud_sdk_core/token_managers/iam_request_based_token_manager.py +9 -3
  9. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0}/ibm_cloud_sdk_core/token_managers/iam_token_manager.py +4 -1
  10. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0}/ibm_cloud_sdk_core/token_managers/mcsp_token_manager.py +12 -2
  11. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0}/ibm_cloud_sdk_core/token_managers/token_manager.py +9 -1
  12. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0}/ibm_cloud_sdk_core/token_managers/vpc_instance_token_manager.py +4 -0
  13. ibm-cloud-sdk-core-3.20.0/ibm_cloud_sdk_core/version.py +1 -0
  14. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0/ibm_cloud_sdk_core.egg-info}/PKG-INFO +2 -2
  15. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0}/ibm_cloud_sdk_core.egg-info/SOURCES.txt +1 -0
  16. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0}/setup.py +1 -1
  17. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0}/test/test_base_service.py +18 -2
  18. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0}/test/test_container_token_manager.py +3 -0
  19. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0}/test/test_cp4d_token_manager.py +17 -0
  20. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0}/test/test_iam_token_manager.py +2 -1
  21. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0}/test/test_mcsp_token_manager.py +17 -0
  22. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0}/test/test_vpc_instance_token_manager.py +2 -0
  23. ibm-cloud-sdk-core-3.19.2/ibm_cloud_sdk_core/version.py +0 -1
  24. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0}/LICENSE +0 -0
  25. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0}/MANIFEST.in +0 -0
  26. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0}/ibm_cloud_sdk_core/__init__.py +0 -0
  27. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0}/ibm_cloud_sdk_core/authenticators/__init__.py +0 -0
  28. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0}/ibm_cloud_sdk_core/authenticators/authenticator.py +0 -0
  29. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0}/ibm_cloud_sdk_core/authenticators/basic_authenticator.py +0 -0
  30. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0}/ibm_cloud_sdk_core/authenticators/bearer_token_authenticator.py +0 -0
  31. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0}/ibm_cloud_sdk_core/authenticators/container_authenticator.py +0 -0
  32. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0}/ibm_cloud_sdk_core/authenticators/cp4d_authenticator.py +0 -0
  33. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0}/ibm_cloud_sdk_core/authenticators/iam_authenticator.py +0 -0
  34. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0}/ibm_cloud_sdk_core/authenticators/iam_request_based_authenticator.py +0 -0
  35. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0}/ibm_cloud_sdk_core/authenticators/mcsp_authenticator.py +0 -0
  36. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0}/ibm_cloud_sdk_core/authenticators/no_auth_authenticator.py +0 -0
  37. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0}/ibm_cloud_sdk_core/authenticators/vpc_instance_authenticator.py +0 -0
  38. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0}/ibm_cloud_sdk_core/detailed_response.py +0 -0
  39. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0}/ibm_cloud_sdk_core/get_authenticator.py +0 -0
  40. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0}/ibm_cloud_sdk_core/token_managers/__init__.py +0 -0
  41. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0}/ibm_cloud_sdk_core/token_managers/jwt_token_manager.py +0 -0
  42. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0}/ibm_cloud_sdk_core/utils.py +0 -0
  43. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0}/ibm_cloud_sdk_core.egg-info/dependency_links.txt +0 -0
  44. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0}/ibm_cloud_sdk_core.egg-info/requires.txt +0 -0
  45. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0}/ibm_cloud_sdk_core.egg-info/top_level.txt +0 -0
  46. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0}/ibm_cloud_sdk_core.egg-info/zip-safe +0 -0
  47. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0}/pyproject.toml +0 -0
  48. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0}/requirements-dev.txt +0 -0
  49. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0}/requirements.txt +0 -0
  50. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0}/setup.cfg +0 -0
  51. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0}/test/__init__.py +0 -0
  52. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0}/test/test_api_exception.py +0 -0
  53. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0}/test/test_authenticator.py +0 -0
  54. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0}/test/test_basic_authenticator.py +0 -0
  55. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0}/test/test_bearer_authenticator.py +0 -0
  56. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0}/test/test_container_authenticator.py +0 -0
  57. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0}/test/test_cp4d_authenticator.py +0 -0
  58. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0}/test/test_detailed_response.py +0 -0
  59. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0}/test/test_iam_authenticator.py +0 -0
  60. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0}/test/test_jwt_token_manager.py +0 -0
  61. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0}/test/test_mcsp_authenticator.py +0 -0
  62. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0}/test/test_no_auth_authenticator.py +0 -0
  63. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0}/test/test_token_manager.py +0 -0
  64. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0}/test/test_utils.py +0 -0
  65. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0}/test/test_vpc_instance_authenticator.py +0 -0
  66. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0}/test_integration/__init__.py +0 -0
  67. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0}/test_integration/test_cp4d_authenticator_integration.py +0 -0
  68. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0}/test_integration/test_iam_authenticator_integration.py +0 -0
  69. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0}/test_integration/test_mcsp_authenticator_integration.py +0 -0
  70. {ibm-cloud-sdk-core-3.19.2 → ibm-cloud-sdk-core-3.20.0}/test_integration/test_ssl_verification.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ibm-cloud-sdk-core
3
- Version: 3.19.2
3
+ Version: 3.20.0
4
4
  Summary: Core library used by SDKs for IBM Cloud Services
5
5
  Home-page: https://github.com/IBM/python-sdk-core
6
6
  Author: IBM
@@ -29,7 +29,7 @@ License-File: LICENSE
29
29
  [![CLA assistant](https://cla-assistant.io/readme/badge/ibm/python-sdk-core)](https://cla-assistant.io/ibm/python-sdk-core)
30
30
  [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
31
31
 
32
- # IBM Python SDK Core Version 3.19.2
32
+ # IBM Python SDK Core Version 3.20.0
33
33
  This project contains core functionality required by Python code generated by the IBM Cloud OpenAPI SDK Generator
34
34
  (openapi-sdkgen).
35
35
 
@@ -4,7 +4,7 @@
4
4
  [![CLA assistant](https://cla-assistant.io/readme/badge/ibm/python-sdk-core)](https://cla-assistant.io/ibm/python-sdk-core)
5
5
  [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
6
6
 
7
- # IBM Python SDK Core Version 3.19.2
7
+ # IBM Python SDK Core Version 3.20.0
8
8
  This project contains core functionality required by Python code generated by the IBM Cloud OpenAPI SDK Generator
9
9
  (openapi-sdkgen).
10
10
 
@@ -54,7 +54,7 @@ class ApiException(Exception):
54
54
  """The old `code` property with a deprecation warning."""
55
55
 
56
56
  warnings.warn(
57
- 'Using the `code` attribute on the `ApiException` is deprecated and'
57
+ 'Using the `code` attribute on the `ApiException` is deprecated and '
58
58
  'will be removed in the future. Use `status_code` instead.',
59
59
  DeprecationWarning,
60
60
  )
@@ -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,7 +18,6 @@ import gzip
18
18
  import io
19
19
  import json as json_import
20
20
  import logging
21
- import platform
22
21
  from http.cookiejar import CookieJar
23
22
  from os.path import basename
24
23
  from typing import Dict, List, Optional, Tuple, Union
@@ -42,7 +41,7 @@ from .utils import (
42
41
  SSLHTTPAdapter,
43
42
  GzipStream,
44
43
  )
45
- from .version import __version__
44
+ from .private_helpers import _build_user_agent
46
45
 
47
46
  # Uncomment this to enable http debugging
48
47
  # import http.client as http_client
@@ -82,7 +81,6 @@ class BaseService:
82
81
  ValueError: If Authenticator is not provided or invalid type.
83
82
  """
84
83
 
85
- SDK_NAME = 'ibm-python-sdk-core'
86
84
  ERROR_MSG_DISABLE_SSL = (
87
85
  'The connection failed because the SSL certificate is not valid. To use a self-signed '
88
86
  'certificate, disable verification of the server\'s SSL certificate by invoking the '
@@ -106,7 +104,7 @@ class BaseService:
106
104
  self.disable_ssl_verification = disable_ssl_verification
107
105
  self.default_headers = None
108
106
  self.enable_gzip_compression = enable_gzip_compression
109
- self._set_user_agent_header(self._build_user_agent())
107
+ self._set_user_agent_header(_build_user_agent())
110
108
  self.retry_config = None
111
109
  self.http_adapter = SSLHTTPAdapter(_disable_ssl_verification=self.disable_ssl_verification)
112
110
  if not self.authenticator:
@@ -151,15 +149,6 @@ class BaseService:
151
149
  self.http_client.mount('http://', self.http_adapter)
152
150
  self.http_client.mount('https://', self.http_adapter)
153
151
 
154
- @staticmethod
155
- def _get_system_info() -> str:
156
- return '{0} {1} {2}'.format(
157
- platform.system(), platform.release(), platform.python_version() # OS # OS version # Python version
158
- )
159
-
160
- def _build_user_agent(self) -> str:
161
- return '{0}-{1} {2}'.format(self.SDK_NAME, __version__, self._get_system_info())
162
-
163
152
  def configure_service(self, service_name: str) -> None:
164
153
  """Look for external configuration of a service. Set service properties.
165
154
 
@@ -0,0 +1,34 @@
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
+ # from ibm_cloud_sdk_core.authenticators import Authenticator
17
+
18
+ import platform
19
+ from .version import __version__
20
+
21
+ SDK_NAME = 'ibm-python-sdk-core'
22
+
23
+
24
+ def _get_system_info() -> str:
25
+ return 'os.name={0} os.version={1} python.version={2}'.format(
26
+ platform.system(), platform.release(), platform.python_version()
27
+ )
28
+
29
+
30
+ def _build_user_agent(component: str = None) -> str:
31
+ sub_component = ""
32
+ if component is not None:
33
+ sub_component = '/{0}'.format(component)
34
+ return '{0}{1}-{2} {3}'.format(SDK_NAME, sub_component, __version__, _get_system_info())
@@ -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,6 +18,7 @@ import logging
18
18
  from typing import Dict, Optional
19
19
 
20
20
  from .iam_request_based_token_manager import IAMRequestBasedTokenManager
21
+ from ..private_helpers import _build_user_agent
21
22
 
22
23
 
23
24
  logger = logging.getLogger(__name__)
@@ -111,6 +112,7 @@ class ContainerTokenManager(IAMRequestBasedTokenManager):
111
112
  self.iam_profile_id = iam_profile_id
112
113
 
113
114
  self.request_payload['grant_type'] = 'urn:ibm:params:oauth:grant-type:cr-token'
115
+ self._set_user_agent(_build_user_agent('container-authenticator'))
114
116
 
115
117
  def retrieve_cr_token(self) -> str:
116
118
  """Retrieves the CR token for the current compute resource by reading it from the local file system.
@@ -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.
@@ -17,6 +17,7 @@
17
17
  import json
18
18
  from typing import Dict, Optional
19
19
 
20
+ from ..private_helpers import _build_user_agent
20
21
  from .jwt_token_manager import JWTTokenManager
21
22
 
22
23
 
@@ -76,12 +77,21 @@ class CP4DTokenManager(JWTTokenManager):
76
77
  self.headers['Content-Type'] = 'application/json'
77
78
  self.proxies = proxies
78
79
  super().__init__(url, disable_ssl_verification=disable_ssl_verification, token_name=self.TOKEN_NAME)
80
+ self._set_user_agent(_build_user_agent('cp4d-authenticator'))
79
81
 
80
82
  def request_token(self) -> dict:
81
83
  """Makes a request for a token."""
84
+ required_headers = {
85
+ 'User-Agent': self.user_agent,
86
+ }
87
+ request_headers = {}
88
+ if self.headers is not None and isinstance(self.headers, dict):
89
+ request_headers.update(self.headers)
90
+ request_headers.update(required_headers)
91
+
82
92
  response = self._request(
83
93
  method='POST',
84
- headers=self.headers,
94
+ headers=request_headers,
85
95
  url=self.url,
86
96
  data=json.dumps({"username": self.username, "password": self.password, "api_key": self.apikey}),
87
97
  proxies=self.proxies,
@@ -98,9 +98,15 @@ class IAMRequestBasedTokenManager(JWTTokenManager):
98
98
  Returns:
99
99
  A dictionary containing the bearer token to be subsequently used service requests.
100
100
  """
101
- headers = {'Content-type': 'application/x-www-form-urlencoded', 'Accept': 'application/json'}
101
+ required_headers = {
102
+ 'Content-Type': 'application/x-www-form-urlencoded',
103
+ 'Accept': 'application/json',
104
+ 'User-Agent': self._get_user_agent(),
105
+ }
106
+ request_headers = {}
102
107
  if self.headers is not None and isinstance(self.headers, dict):
103
- headers.update(self.headers)
108
+ request_headers.update(self.headers)
109
+ request_headers.update(required_headers)
104
110
 
105
111
  data = dict(self.request_payload)
106
112
 
@@ -115,7 +121,7 @@ class IAMRequestBasedTokenManager(JWTTokenManager):
115
121
  response = self._request(
116
122
  method='POST',
117
123
  url=(self.url + self.OPERATION_PATH) if self.url else self.url,
118
- headers=headers,
124
+ headers=request_headers,
119
125
  data=data,
120
126
  auth_tuple=auth_tuple,
121
127
  proxies=self.proxies,
@@ -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.
@@ -17,6 +17,7 @@
17
17
  from typing import Dict, Optional
18
18
 
19
19
  from .iam_request_based_token_manager import IAMRequestBasedTokenManager
20
+ from ..private_helpers import _build_user_agent
20
21
 
21
22
 
22
23
  class IAMTokenManager(IAMRequestBasedTokenManager):
@@ -88,3 +89,5 @@ class IAMTokenManager(IAMRequestBasedTokenManager):
88
89
  self.request_payload['grant_type'] = 'urn:ibm:params:oauth:grant-type:apikey'
89
90
  self.request_payload['apikey'] = self.apikey
90
91
  self.request_payload['response_type'] = 'cloud_iam'
92
+
93
+ self._set_user_agent(_build_user_agent('iam-authenticator'))
@@ -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.
@@ -17,6 +17,7 @@
17
17
  import json
18
18
  from typing import Dict, Optional
19
19
 
20
+ from ..private_helpers import _build_user_agent
20
21
  from .jwt_token_manager import JWTTokenManager
21
22
 
22
23
 
@@ -55,12 +56,21 @@ class MCSPTokenManager(JWTTokenManager):
55
56
  self.headers['Accept'] = 'application/json'
56
57
  self.proxies = proxies
57
58
  super().__init__(url, disable_ssl_verification=disable_ssl_verification, token_name=self.TOKEN_NAME)
59
+ self._set_user_agent(_build_user_agent('mcsp-authenticator'))
58
60
 
59
61
  def request_token(self) -> dict:
60
62
  """Makes a request for a token."""
63
+ required_headers = {
64
+ 'User-Agent': self.user_agent,
65
+ }
66
+ request_headers = {}
67
+ if self.headers is not None and isinstance(self.headers, dict):
68
+ request_headers.update(self.headers)
69
+ request_headers.update(required_headers)
70
+
61
71
  response = self._request(
62
72
  method='POST',
63
- headers=self.headers,
73
+ headers=request_headers,
64
74
  url=self.url + self.OPERATION_PATH,
65
75
  data=json.dumps({"apikey": self.apikey}),
66
76
  proxies=self.proxies,
@@ -1,6 +1,6 @@
1
1
  # coding: utf-8
2
2
 
3
- # Copyright 2020 IBM All Rights Reserved.
3
+ # Copyright 2020, 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.
@@ -49,6 +49,7 @@ class TokenManager(ABC):
49
49
  lock (Lock): Lock variable to serialize access to refresh/request times
50
50
  http_config (dict): A dictionary containing values that control the timeout, proxies, and etc of HTTP requests.
51
51
  access_token (str): The latest stored access token
52
+ user_agent (str): The User-Agent header value to be included in each outbound token request
52
53
  """
53
54
 
54
55
  def __init__(self, url: str, *, disable_ssl_verification: bool = False):
@@ -60,6 +61,7 @@ class TokenManager(ABC):
60
61
  self.lock = Lock()
61
62
  self.http_config = {}
62
63
  self.access_token = None
64
+ self.user_agent = None
63
65
 
64
66
  def get_token(self) -> str:
65
67
  """Get a token to be used for authentication.
@@ -95,6 +97,12 @@ class TokenManager(ABC):
95
97
  else:
96
98
  raise TypeError('status must be a bool')
97
99
 
100
+ def _set_user_agent(self, user_agent: str = None) -> None:
101
+ self.user_agent = user_agent
102
+
103
+ def _get_user_agent(self) -> str:
104
+ return self.user_agent
105
+
98
106
  def paced_request_token(self) -> None:
99
107
  """
100
108
  Paces requests to request_token.
@@ -18,6 +18,7 @@ import json
18
18
  import logging
19
19
  from typing import Optional
20
20
 
21
+ from ..private_helpers import _build_user_agent
21
22
  from .jwt_token_manager import JWTTokenManager
22
23
 
23
24
 
@@ -64,6 +65,7 @@ class VPCInstanceTokenManager(JWTTokenManager):
64
65
  url = self.DEFAULT_IMS_ENDPOINT
65
66
 
66
67
  super().__init__(url, token_name=self.TOKEN_NAME)
68
+ self._set_user_agent(_build_user_agent('vpc-instance-authenticator'))
67
69
 
68
70
  self.iam_profile_crn = iam_profile_crn
69
71
  self.iam_profile_id = iam_profile_id
@@ -92,6 +94,7 @@ class VPCInstanceTokenManager(JWTTokenManager):
92
94
  'Content-Type': 'application/json',
93
95
  'Accept': 'application/json',
94
96
  'Authorization': 'Bearer ' + instance_identity_token,
97
+ 'User-Agent': self._get_user_agent(),
95
98
  }
96
99
 
97
100
  logger.debug('Invoking VPC \'create_iam_token\' operation: %s', url)
@@ -138,6 +141,7 @@ class VPCInstanceTokenManager(JWTTokenManager):
138
141
  'Content-type': 'application/json',
139
142
  'Accept': 'application/json',
140
143
  'Metadata-Flavor': 'ibm',
144
+ 'User-Agent': self._get_user_agent(),
141
145
  }
142
146
 
143
147
  request_body = {'expires_in': 300}
@@ -0,0 +1 @@
1
+ __version__ = '3.20.0'
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ibm-cloud-sdk-core
3
- Version: 3.19.2
3
+ Version: 3.20.0
4
4
  Summary: Core library used by SDKs for IBM Cloud Services
5
5
  Home-page: https://github.com/IBM/python-sdk-core
6
6
  Author: IBM
@@ -29,7 +29,7 @@ License-File: LICENSE
29
29
  [![CLA assistant](https://cla-assistant.io/readme/badge/ibm/python-sdk-core)](https://cla-assistant.io/ibm/python-sdk-core)
30
30
  [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
31
31
 
32
- # IBM Python SDK Core Version 3.19.2
32
+ # IBM Python SDK Core Version 3.20.0
33
33
  This project contains core functionality required by Python code generated by the IBM Cloud OpenAPI SDK Generator
34
34
  (openapi-sdkgen).
35
35
 
@@ -10,6 +10,7 @@ ibm_cloud_sdk_core/api_exception.py
10
10
  ibm_cloud_sdk_core/base_service.py
11
11
  ibm_cloud_sdk_core/detailed_response.py
12
12
  ibm_cloud_sdk_core/get_authenticator.py
13
+ ibm_cloud_sdk_core/private_helpers.py
13
14
  ibm_cloud_sdk_core/utils.py
14
15
  ibm_cloud_sdk_core/version.py
15
16
  ibm_cloud_sdk_core.egg-info/PKG-INFO
@@ -19,7 +19,7 @@ import pkg_resources
19
19
  from setuptools import setup, find_packages
20
20
  from setuptools.command.test import test as TestCommand
21
21
 
22
- __version__ = '3.19.2'
22
+ __version__ = '3.20.0'
23
23
 
24
24
  if sys.argv[-1] == 'publish':
25
25
  # test server
@@ -1,5 +1,21 @@
1
- # coding=utf-8
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
+
2
17
  # pylint: disable=missing-docstring,protected-access,too-few-public-methods,too-many-lines
18
+
3
19
  import gzip
4
20
  import json
5
21
  import os
@@ -802,7 +818,7 @@ def test_user_agent_header():
802
818
  service = AnyServiceV1('2018-11-20', authenticator=NoAuthAuthenticator())
803
819
  user_agent_header = service.user_agent_header
804
820
  assert user_agent_header is not None
805
- assert user_agent_header['User-Agent'] is not None
821
+ assert user_agent_header['User-Agent'].startswith('ibm-python-sdk-core-')
806
822
 
807
823
  responses.add(responses.GET, 'https://gateway.watsonplatform.net/test/api', status=200, body='some text')
808
824
  prepped = service.prepare_request('GET', url='', headers={'user-agent': 'my_user_agent'})
@@ -111,6 +111,9 @@ def test_request_token_auth_default():
111
111
  assert len(responses.calls) == 1
112
112
  assert responses.calls[0].request.url == iam_url
113
113
  assert responses.calls[0].request.headers.get('Authorization') is None
114
+ assert (
115
+ responses.calls[0].request.headers.get('User-Agent').startswith('ibm-python-sdk-core/container-authenticator')
116
+ )
114
117
  assert json.loads(responses.calls[0].response.text)['access_token'] == TEST_ACCESS_TOKEN_1
115
118
 
116
119
 
@@ -1,3 +1,19 @@
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
+
1
17
  # pylint: disable=missing-docstring
2
18
  import json
3
19
  import time
@@ -38,6 +54,7 @@ def test_request_token():
38
54
 
39
55
  assert len(responses.calls) == 1
40
56
  assert responses.calls[0].request.url == url + '/v1/authorize'
57
+ assert responses.calls[0].request.headers.get('User-Agent').startswith('ibm-python-sdk-core/cp4d-authenticator')
41
58
  assert token == access_token
42
59
 
43
60
  token_manager = CP4DTokenManager("username", "password", url + '/v1/authorize')
@@ -1,6 +1,6 @@
1
1
  # coding: utf-8
2
2
 
3
- # Copyright 2021, 2024 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.
@@ -72,6 +72,7 @@ def test_request_token_auth_default():
72
72
  assert len(responses.calls) == 1
73
73
  assert responses.calls[0].request.url == iam_url
74
74
  assert responses.calls[0].request.headers.get('Authorization') is None
75
+ assert responses.calls[0].request.headers.get('User-Agent').startswith('ibm-python-sdk-core/iam-authenticator')
75
76
  assert responses.calls[0].response.text == response
76
77
 
77
78
 
@@ -1,3 +1,19 @@
1
+ # coding: utf-8
2
+
3
+ # Copyright 2023, 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
+
1
17
  # pylint: disable=missing-docstring
2
18
  import json
3
19
  import time
@@ -45,6 +61,7 @@ def test_request_token():
45
61
 
46
62
  assert len(responses.calls) == 1
47
63
  assert responses.calls[0].request.url == MOCK_URL + OPERATION_PATH
64
+ assert responses.calls[0].request.headers.get('User-Agent').startswith('ibm-python-sdk-core/mcsp-authenticator')
48
65
  assert token == access_token
49
66
 
50
67
 
@@ -85,6 +85,7 @@ def test_retrieve_instance_identity_token(caplog):
85
85
  assert responses.calls[0].request.headers['Content-Type'] == 'application/json'
86
86
  assert responses.calls[0].request.headers['Accept'] == 'application/json'
87
87
  assert responses.calls[0].request.headers['Metadata-Flavor'] == 'ibm'
88
+ assert responses.calls[0].request.headers['User-Agent'].startswith('ibm-python-sdk-core/vpc-instance-authenticator')
88
89
  assert responses.calls[0].request.params['version'] == '2022-03-01'
89
90
  assert responses.calls[0].request.body == '{"expires_in": 300}'
90
91
  assert ii_token == TEST_TOKEN
@@ -151,6 +152,7 @@ def test_request_token_with_crn(caplog):
151
152
  assert responses.calls[0].request.headers['Content-Type'] == 'application/json'
152
153
  assert responses.calls[0].request.headers['Accept'] == 'application/json'
153
154
  assert responses.calls[0].request.headers['Authorization'] == 'Bearer ' + TEST_TOKEN
155
+ assert responses.calls[0].request.headers['User-Agent'].startswith('ibm-python-sdk-core/vpc-instance-authenticator')
154
156
  assert responses.calls[0].request.body == '{"trusted_profile": {"crn": "crn:iam-profile:123"}}'
155
157
  assert responses.calls[0].request.params['version'] == '2022-03-01'
156
158
  # Check the logs.
@@ -1 +0,0 @@
1
- __version__ = '3.19.2'