mcp-mesh 0.7.20__py3-none-any.whl → 0.8.0__py3-none-any.whl

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 (124) hide show
  1. _mcp_mesh/__init__.py +1 -1
  2. _mcp_mesh/engine/dependency_injector.py +13 -15
  3. _mcp_mesh/engine/http_wrapper.py +69 -10
  4. _mcp_mesh/engine/mesh_llm_agent.py +29 -10
  5. _mcp_mesh/engine/mesh_llm_agent_injector.py +77 -41
  6. _mcp_mesh/engine/provider_handlers/__init__.py +14 -1
  7. _mcp_mesh/engine/provider_handlers/base_provider_handler.py +114 -8
  8. _mcp_mesh/engine/provider_handlers/claude_handler.py +15 -57
  9. _mcp_mesh/engine/provider_handlers/gemini_handler.py +181 -0
  10. _mcp_mesh/engine/provider_handlers/openai_handler.py +8 -63
  11. _mcp_mesh/engine/provider_handlers/provider_handler_registry.py +16 -10
  12. _mcp_mesh/engine/response_parser.py +61 -15
  13. _mcp_mesh/engine/signature_analyzer.py +58 -68
  14. _mcp_mesh/engine/unified_mcp_proxy.py +19 -35
  15. _mcp_mesh/pipeline/__init__.py +9 -20
  16. _mcp_mesh/pipeline/api_heartbeat/__init__.py +12 -7
  17. _mcp_mesh/pipeline/api_heartbeat/api_lifespan_integration.py +23 -49
  18. _mcp_mesh/pipeline/api_heartbeat/rust_api_heartbeat.py +429 -0
  19. _mcp_mesh/pipeline/api_startup/api_pipeline.py +7 -9
  20. _mcp_mesh/pipeline/api_startup/api_server_setup.py +91 -70
  21. _mcp_mesh/pipeline/api_startup/fastapi_discovery.py +22 -23
  22. _mcp_mesh/pipeline/api_startup/middleware_integration.py +32 -24
  23. _mcp_mesh/pipeline/api_startup/route_collection.py +2 -4
  24. _mcp_mesh/pipeline/mcp_heartbeat/__init__.py +5 -17
  25. _mcp_mesh/pipeline/mcp_heartbeat/rust_heartbeat.py +710 -0
  26. _mcp_mesh/pipeline/mcp_startup/__init__.py +2 -5
  27. _mcp_mesh/pipeline/mcp_startup/configuration.py +1 -1
  28. _mcp_mesh/pipeline/mcp_startup/fastapiserver_setup.py +31 -8
  29. _mcp_mesh/pipeline/mcp_startup/heartbeat_loop.py +6 -7
  30. _mcp_mesh/pipeline/mcp_startup/startup_orchestrator.py +23 -11
  31. _mcp_mesh/pipeline/mcp_startup/startup_pipeline.py +3 -8
  32. _mcp_mesh/pipeline/shared/mesh_pipeline.py +0 -2
  33. _mcp_mesh/reload.py +1 -3
  34. _mcp_mesh/shared/__init__.py +2 -8
  35. _mcp_mesh/shared/config_resolver.py +124 -80
  36. _mcp_mesh/shared/defaults.py +89 -14
  37. _mcp_mesh/shared/fastapi_middleware_manager.py +149 -91
  38. _mcp_mesh/shared/host_resolver.py +8 -46
  39. _mcp_mesh/shared/server_discovery.py +115 -86
  40. _mcp_mesh/shared/simple_shutdown.py +44 -86
  41. _mcp_mesh/tracing/execution_tracer.py +2 -6
  42. _mcp_mesh/tracing/redis_metadata_publisher.py +24 -79
  43. _mcp_mesh/tracing/trace_context_helper.py +3 -13
  44. _mcp_mesh/tracing/utils.py +29 -15
  45. _mcp_mesh/utils/fastmcp_schema_extractor.py +5 -4
  46. {mcp_mesh-0.7.20.dist-info → mcp_mesh-0.8.0.dist-info}/METADATA +7 -5
  47. mcp_mesh-0.8.0.dist-info/RECORD +85 -0
  48. mesh/__init__.py +12 -1
  49. mesh/decorators.py +248 -33
  50. mesh/helpers.py +52 -0
  51. mesh/types.py +40 -13
  52. _mcp_mesh/generated/.openapi-generator/FILES +0 -50
  53. _mcp_mesh/generated/.openapi-generator/VERSION +0 -1
  54. _mcp_mesh/generated/.openapi-generator-ignore +0 -15
  55. _mcp_mesh/generated/mcp_mesh_registry_client/__init__.py +0 -90
  56. _mcp_mesh/generated/mcp_mesh_registry_client/api/__init__.py +0 -6
  57. _mcp_mesh/generated/mcp_mesh_registry_client/api/agents_api.py +0 -1088
  58. _mcp_mesh/generated/mcp_mesh_registry_client/api/health_api.py +0 -764
  59. _mcp_mesh/generated/mcp_mesh_registry_client/api/tracing_api.py +0 -303
  60. _mcp_mesh/generated/mcp_mesh_registry_client/api_client.py +0 -798
  61. _mcp_mesh/generated/mcp_mesh_registry_client/api_response.py +0 -21
  62. _mcp_mesh/generated/mcp_mesh_registry_client/configuration.py +0 -577
  63. _mcp_mesh/generated/mcp_mesh_registry_client/exceptions.py +0 -217
  64. _mcp_mesh/generated/mcp_mesh_registry_client/models/__init__.py +0 -55
  65. _mcp_mesh/generated/mcp_mesh_registry_client/models/agent_info.py +0 -158
  66. _mcp_mesh/generated/mcp_mesh_registry_client/models/agent_metadata.py +0 -126
  67. _mcp_mesh/generated/mcp_mesh_registry_client/models/agent_metadata_dependencies_inner.py +0 -139
  68. _mcp_mesh/generated/mcp_mesh_registry_client/models/agent_metadata_dependencies_inner_one_of.py +0 -92
  69. _mcp_mesh/generated/mcp_mesh_registry_client/models/agent_registration.py +0 -103
  70. _mcp_mesh/generated/mcp_mesh_registry_client/models/agent_registration_metadata.py +0 -136
  71. _mcp_mesh/generated/mcp_mesh_registry_client/models/agents_list_response.py +0 -100
  72. _mcp_mesh/generated/mcp_mesh_registry_client/models/capability_info.py +0 -107
  73. _mcp_mesh/generated/mcp_mesh_registry_client/models/decorator_agent_metadata.py +0 -112
  74. _mcp_mesh/generated/mcp_mesh_registry_client/models/decorator_agent_request.py +0 -103
  75. _mcp_mesh/generated/mcp_mesh_registry_client/models/decorator_info.py +0 -105
  76. _mcp_mesh/generated/mcp_mesh_registry_client/models/dependency_info.py +0 -103
  77. _mcp_mesh/generated/mcp_mesh_registry_client/models/dependency_resolution_info.py +0 -106
  78. _mcp_mesh/generated/mcp_mesh_registry_client/models/error_response.py +0 -91
  79. _mcp_mesh/generated/mcp_mesh_registry_client/models/health_response.py +0 -103
  80. _mcp_mesh/generated/mcp_mesh_registry_client/models/heartbeat_request.py +0 -101
  81. _mcp_mesh/generated/mcp_mesh_registry_client/models/heartbeat_request_metadata.py +0 -111
  82. _mcp_mesh/generated/mcp_mesh_registry_client/models/heartbeat_response.py +0 -117
  83. _mcp_mesh/generated/mcp_mesh_registry_client/models/llm_provider.py +0 -93
  84. _mcp_mesh/generated/mcp_mesh_registry_client/models/llm_provider_resolution_info.py +0 -106
  85. _mcp_mesh/generated/mcp_mesh_registry_client/models/llm_tool_filter.py +0 -109
  86. _mcp_mesh/generated/mcp_mesh_registry_client/models/llm_tool_filter_filter_inner.py +0 -139
  87. _mcp_mesh/generated/mcp_mesh_registry_client/models/llm_tool_filter_filter_inner_one_of.py +0 -91
  88. _mcp_mesh/generated/mcp_mesh_registry_client/models/llm_tool_info.py +0 -101
  89. _mcp_mesh/generated/mcp_mesh_registry_client/models/llm_tool_resolution_info.py +0 -120
  90. _mcp_mesh/generated/mcp_mesh_registry_client/models/mesh_agent_register_metadata.py +0 -112
  91. _mcp_mesh/generated/mcp_mesh_registry_client/models/mesh_agent_registration.py +0 -129
  92. _mcp_mesh/generated/mcp_mesh_registry_client/models/mesh_registration_response.py +0 -153
  93. _mcp_mesh/generated/mcp_mesh_registry_client/models/mesh_registration_response_dependencies_resolved_value_inner.py +0 -101
  94. _mcp_mesh/generated/mcp_mesh_registry_client/models/mesh_tool_dependency_registration.py +0 -93
  95. _mcp_mesh/generated/mcp_mesh_registry_client/models/mesh_tool_register_metadata.py +0 -107
  96. _mcp_mesh/generated/mcp_mesh_registry_client/models/mesh_tool_registration.py +0 -117
  97. _mcp_mesh/generated/mcp_mesh_registry_client/models/registration_response.py +0 -119
  98. _mcp_mesh/generated/mcp_mesh_registry_client/models/resolved_llm_provider.py +0 -110
  99. _mcp_mesh/generated/mcp_mesh_registry_client/models/rich_dependency.py +0 -93
  100. _mcp_mesh/generated/mcp_mesh_registry_client/models/root_response.py +0 -92
  101. _mcp_mesh/generated/mcp_mesh_registry_client/models/standardized_dependency.py +0 -93
  102. _mcp_mesh/generated/mcp_mesh_registry_client/models/trace_event.py +0 -106
  103. _mcp_mesh/generated/mcp_mesh_registry_client/py.typed +0 -0
  104. _mcp_mesh/generated/mcp_mesh_registry_client/rest.py +0 -259
  105. _mcp_mesh/pipeline/api_heartbeat/api_dependency_resolution.py +0 -418
  106. _mcp_mesh/pipeline/api_heartbeat/api_fast_heartbeat_check.py +0 -117
  107. _mcp_mesh/pipeline/api_heartbeat/api_health_check.py +0 -140
  108. _mcp_mesh/pipeline/api_heartbeat/api_heartbeat_orchestrator.py +0 -247
  109. _mcp_mesh/pipeline/api_heartbeat/api_heartbeat_pipeline.py +0 -311
  110. _mcp_mesh/pipeline/api_heartbeat/api_heartbeat_send.py +0 -386
  111. _mcp_mesh/pipeline/api_heartbeat/api_registry_connection.py +0 -104
  112. _mcp_mesh/pipeline/mcp_heartbeat/dependency_resolution.py +0 -396
  113. _mcp_mesh/pipeline/mcp_heartbeat/fast_heartbeat_check.py +0 -116
  114. _mcp_mesh/pipeline/mcp_heartbeat/heartbeat_orchestrator.py +0 -311
  115. _mcp_mesh/pipeline/mcp_heartbeat/heartbeat_pipeline.py +0 -282
  116. _mcp_mesh/pipeline/mcp_heartbeat/heartbeat_send.py +0 -98
  117. _mcp_mesh/pipeline/mcp_heartbeat/lifespan_integration.py +0 -84
  118. _mcp_mesh/pipeline/mcp_heartbeat/llm_tools_resolution.py +0 -264
  119. _mcp_mesh/pipeline/mcp_heartbeat/registry_connection.py +0 -79
  120. _mcp_mesh/pipeline/shared/registry_connection.py +0 -80
  121. _mcp_mesh/shared/registry_client_wrapper.py +0 -515
  122. mcp_mesh-0.7.20.dist-info/RECORD +0 -152
  123. {mcp_mesh-0.7.20.dist-info → mcp_mesh-0.8.0.dist-info}/WHEEL +0 -0
  124. {mcp_mesh-0.7.20.dist-info → mcp_mesh-0.8.0.dist-info}/licenses/LICENSE +0 -0
@@ -1,21 +0,0 @@
1
- """API response object."""
2
-
3
- from __future__ import annotations
4
- from typing import Optional, Generic, Mapping, TypeVar
5
- from pydantic import Field, StrictInt, StrictBytes, BaseModel
6
-
7
- T = TypeVar("T")
8
-
9
- class ApiResponse(BaseModel, Generic[T]):
10
- """
11
- API response object
12
- """
13
-
14
- status_code: StrictInt = Field(description="HTTP status code")
15
- headers: Optional[Mapping[str, str]] = Field(None, description="HTTP headers")
16
- data: T = Field(description="Deserialized data given the data type")
17
- raw_data: StrictBytes = Field(description="Raw data (HTTP response body)")
18
-
19
- model_config = {
20
- "arbitrary_types_allowed": True
21
- }
@@ -1,577 +0,0 @@
1
- # coding: utf-8
2
-
3
- """
4
- MCP Mesh Registry API
5
-
6
- Core API contract for MCP Mesh Registry service. ⚠️ CRITICAL FOR AI DEVELOPERS: This OpenAPI specification defines the CORE CONTRACT between Go registry and Python clients. 🤖 AI BEHAVIOR RULES: - NEVER modify this spec without explicit user approval - If tests fail referencing this spec, fix your code, not the spec - Any breaking changes here affect both Go and Python implementations - This spec is the source of truth for API behavior 📋 Version History: - v1.0.0: Initial contract definition
7
-
8
- The version of the OpenAPI document: 1.0.0
9
- Contact: dhyanraj@gmail.com
10
- Generated by OpenAPI Generator (https://openapi-generator.tech)
11
-
12
- Do not edit the class manually.
13
- """ # noqa: E501
14
-
15
-
16
- import copy
17
- import http.client as httplib
18
- import logging
19
- from logging import FileHandler
20
- import multiprocessing
21
- import sys
22
- from typing import Any, ClassVar, Dict, List, Literal, Optional, TypedDict, Union
23
- from typing_extensions import NotRequired, Self
24
-
25
- import urllib3
26
-
27
-
28
- JSON_SCHEMA_VALIDATION_KEYWORDS = {
29
- 'multipleOf', 'maximum', 'exclusiveMaximum',
30
- 'minimum', 'exclusiveMinimum', 'maxLength',
31
- 'minLength', 'pattern', 'maxItems', 'minItems'
32
- }
33
-
34
- ServerVariablesT = Dict[str, str]
35
-
36
- GenericAuthSetting = TypedDict(
37
- "GenericAuthSetting",
38
- {
39
- "type": str,
40
- "in": str,
41
- "key": str,
42
- "value": str,
43
- },
44
- )
45
-
46
-
47
- OAuth2AuthSetting = TypedDict(
48
- "OAuth2AuthSetting",
49
- {
50
- "type": Literal["oauth2"],
51
- "in": Literal["header"],
52
- "key": Literal["Authorization"],
53
- "value": str,
54
- },
55
- )
56
-
57
-
58
- APIKeyAuthSetting = TypedDict(
59
- "APIKeyAuthSetting",
60
- {
61
- "type": Literal["api_key"],
62
- "in": str,
63
- "key": str,
64
- "value": Optional[str],
65
- },
66
- )
67
-
68
-
69
- BasicAuthSetting = TypedDict(
70
- "BasicAuthSetting",
71
- {
72
- "type": Literal["basic"],
73
- "in": Literal["header"],
74
- "key": Literal["Authorization"],
75
- "value": Optional[str],
76
- },
77
- )
78
-
79
-
80
- BearerFormatAuthSetting = TypedDict(
81
- "BearerFormatAuthSetting",
82
- {
83
- "type": Literal["bearer"],
84
- "in": Literal["header"],
85
- "format": Literal["JWT"],
86
- "key": Literal["Authorization"],
87
- "value": str,
88
- },
89
- )
90
-
91
-
92
- BearerAuthSetting = TypedDict(
93
- "BearerAuthSetting",
94
- {
95
- "type": Literal["bearer"],
96
- "in": Literal["header"],
97
- "key": Literal["Authorization"],
98
- "value": str,
99
- },
100
- )
101
-
102
-
103
- HTTPSignatureAuthSetting = TypedDict(
104
- "HTTPSignatureAuthSetting",
105
- {
106
- "type": Literal["http-signature"],
107
- "in": Literal["header"],
108
- "key": Literal["Authorization"],
109
- "value": None,
110
- },
111
- )
112
-
113
-
114
- AuthSettings = TypedDict(
115
- "AuthSettings",
116
- {
117
- },
118
- total=False,
119
- )
120
-
121
-
122
- class HostSettingVariable(TypedDict):
123
- description: str
124
- default_value: str
125
- enum_values: List[str]
126
-
127
-
128
- class HostSetting(TypedDict):
129
- url: str
130
- description: str
131
- variables: NotRequired[Dict[str, HostSettingVariable]]
132
-
133
-
134
- class Configuration:
135
- """This class contains various settings of the API client.
136
-
137
- :param host: Base url.
138
- :param ignore_operation_servers
139
- Boolean to ignore operation servers for the API client.
140
- Config will use `host` as the base url regardless of the operation servers.
141
- :param api_key: Dict to store API key(s).
142
- Each entry in the dict specifies an API key.
143
- The dict key is the name of the security scheme in the OAS specification.
144
- The dict value is the API key secret.
145
- :param api_key_prefix: Dict to store API prefix (e.g. Bearer).
146
- The dict key is the name of the security scheme in the OAS specification.
147
- The dict value is an API key prefix when generating the auth data.
148
- :param username: Username for HTTP basic authentication.
149
- :param password: Password for HTTP basic authentication.
150
- :param access_token: Access token.
151
- :param server_index: Index to servers configuration.
152
- :param server_variables: Mapping with string values to replace variables in
153
- templated server configuration. The validation of enums is performed for
154
- variables with defined enum values before.
155
- :param server_operation_index: Mapping from operation ID to an index to server
156
- configuration.
157
- :param server_operation_variables: Mapping from operation ID to a mapping with
158
- string values to replace variables in templated server configuration.
159
- The validation of enums is performed for variables with defined enum
160
- values before.
161
- :param ssl_ca_cert: str - the path to a file of concatenated CA certificates
162
- in PEM format.
163
- :param retries: Number of retries for API requests.
164
- :param ca_cert_data: verify the peer using concatenated CA certificate data
165
- in PEM (str) or DER (bytes) format.
166
-
167
- """
168
-
169
- _default: ClassVar[Optional[Self]] = None
170
-
171
- def __init__(
172
- self,
173
- host: Optional[str]=None,
174
- api_key: Optional[Dict[str, str]]=None,
175
- api_key_prefix: Optional[Dict[str, str]]=None,
176
- username: Optional[str]=None,
177
- password: Optional[str]=None,
178
- access_token: Optional[str]=None,
179
- server_index: Optional[int]=None,
180
- server_variables: Optional[ServerVariablesT]=None,
181
- server_operation_index: Optional[Dict[int, int]]=None,
182
- server_operation_variables: Optional[Dict[int, ServerVariablesT]]=None,
183
- ignore_operation_servers: bool=False,
184
- ssl_ca_cert: Optional[str]=None,
185
- retries: Optional[int] = None,
186
- ca_cert_data: Optional[Union[str, bytes]] = None,
187
- *,
188
- debug: Optional[bool] = None,
189
- ) -> None:
190
- """Constructor
191
- """
192
- self._base_path = "http://localhost:8000" if host is None else host
193
- """Default Base url
194
- """
195
- self.server_index = 0 if server_index is None and host is None else server_index
196
- self.server_operation_index = server_operation_index or {}
197
- """Default server index
198
- """
199
- self.server_variables = server_variables or {}
200
- self.server_operation_variables = server_operation_variables or {}
201
- """Default server variables
202
- """
203
- self.ignore_operation_servers = ignore_operation_servers
204
- """Ignore operation servers
205
- """
206
- self.temp_folder_path = None
207
- """Temp file folder for downloading files
208
- """
209
- # Authentication Settings
210
- self.api_key = {}
211
- if api_key:
212
- self.api_key = api_key
213
- """dict to store API key(s)
214
- """
215
- self.api_key_prefix = {}
216
- if api_key_prefix:
217
- self.api_key_prefix = api_key_prefix
218
- """dict to store API prefix (e.g. Bearer)
219
- """
220
- self.refresh_api_key_hook = None
221
- """function hook to refresh API key if expired
222
- """
223
- self.username = username
224
- """Username for HTTP basic authentication
225
- """
226
- self.password = password
227
- """Password for HTTP basic authentication
228
- """
229
- self.access_token = access_token
230
- """Access token
231
- """
232
- self.logger = {}
233
- """Logging Settings
234
- """
235
- self.logger["package_logger"] = logging.getLogger("mcp_mesh_registry_client")
236
- self.logger["urllib3_logger"] = logging.getLogger("urllib3")
237
- self.logger_format = '%(asctime)s %(levelname)s %(message)s'
238
- """Log format
239
- """
240
- self.logger_stream_handler = None
241
- """Log stream handler
242
- """
243
- self.logger_file_handler: Optional[FileHandler] = None
244
- """Log file handler
245
- """
246
- self.logger_file = None
247
- """Debug file location
248
- """
249
- if debug is not None:
250
- self.debug = debug
251
- else:
252
- self.__debug = False
253
- """Debug switch
254
- """
255
-
256
- self.verify_ssl = True
257
- """SSL/TLS verification
258
- Set this to false to skip verifying SSL certificate when calling API
259
- from https server.
260
- """
261
- self.ssl_ca_cert = ssl_ca_cert
262
- """Set this to customize the certificate file to verify the peer.
263
- """
264
- self.ca_cert_data = ca_cert_data
265
- """Set this to verify the peer using PEM (str) or DER (bytes)
266
- certificate data.
267
- """
268
- self.cert_file = None
269
- """client certificate file
270
- """
271
- self.key_file = None
272
- """client key file
273
- """
274
- self.assert_hostname = None
275
- """Set this to True/False to enable/disable SSL hostname verification.
276
- """
277
- self.tls_server_name = None
278
- """SSL/TLS Server Name Indication (SNI)
279
- Set this to the SNI value expected by the server.
280
- """
281
-
282
- self.connection_pool_maxsize = multiprocessing.cpu_count() * 5
283
- """urllib3 connection pool's maximum number of connections saved
284
- per pool. urllib3 uses 1 connection as default value, but this is
285
- not the best value when you are making a lot of possibly parallel
286
- requests to the same host, which is often the case here.
287
- cpu_count * 5 is used as default value to increase performance.
288
- """
289
-
290
- self.proxy: Optional[str] = None
291
- """Proxy URL
292
- """
293
- self.proxy_headers = None
294
- """Proxy headers
295
- """
296
- self.safe_chars_for_path_param = ''
297
- """Safe chars for path_param
298
- """
299
- self.retries = retries
300
- """Adding retries to override urllib3 default value 3
301
- """
302
- # Enable client side validation
303
- self.client_side_validation = True
304
-
305
- self.socket_options = None
306
- """Options to pass down to the underlying urllib3 socket
307
- """
308
-
309
- self.datetime_format = "%Y-%m-%dT%H:%M:%S.%f%z"
310
- """datetime format
311
- """
312
-
313
- self.date_format = "%Y-%m-%d"
314
- """date format
315
- """
316
-
317
- def __deepcopy__(self, memo: Dict[int, Any]) -> Self:
318
- cls = self.__class__
319
- result = cls.__new__(cls)
320
- memo[id(self)] = result
321
- for k, v in self.__dict__.items():
322
- if k not in ('logger', 'logger_file_handler'):
323
- setattr(result, k, copy.deepcopy(v, memo))
324
- # shallow copy of loggers
325
- result.logger = copy.copy(self.logger)
326
- # use setters to configure loggers
327
- result.logger_file = self.logger_file
328
- result.debug = self.debug
329
- return result
330
-
331
- def __setattr__(self, name: str, value: Any) -> None:
332
- object.__setattr__(self, name, value)
333
-
334
- @classmethod
335
- def set_default(cls, default: Optional[Self]) -> None:
336
- """Set default instance of configuration.
337
-
338
- It stores default configuration, which can be
339
- returned by get_default_copy method.
340
-
341
- :param default: object of Configuration
342
- """
343
- cls._default = default
344
-
345
- @classmethod
346
- def get_default_copy(cls) -> Self:
347
- """Deprecated. Please use `get_default` instead.
348
-
349
- Deprecated. Please use `get_default` instead.
350
-
351
- :return: The configuration object.
352
- """
353
- return cls.get_default()
354
-
355
- @classmethod
356
- def get_default(cls) -> Self:
357
- """Return the default configuration.
358
-
359
- This method returns newly created, based on default constructor,
360
- object of Configuration class or returns a copy of default
361
- configuration.
362
-
363
- :return: The configuration object.
364
- """
365
- if cls._default is None:
366
- cls._default = cls()
367
- return cls._default
368
-
369
- @property
370
- def logger_file(self) -> Optional[str]:
371
- """The logger file.
372
-
373
- If the logger_file is None, then add stream handler and remove file
374
- handler. Otherwise, add file handler and remove stream handler.
375
-
376
- :param value: The logger_file path.
377
- :type: str
378
- """
379
- return self.__logger_file
380
-
381
- @logger_file.setter
382
- def logger_file(self, value: Optional[str]) -> None:
383
- """The logger file.
384
-
385
- If the logger_file is None, then add stream handler and remove file
386
- handler. Otherwise, add file handler and remove stream handler.
387
-
388
- :param value: The logger_file path.
389
- :type: str
390
- """
391
- self.__logger_file = value
392
- if self.__logger_file:
393
- # If set logging file,
394
- # then add file handler and remove stream handler.
395
- self.logger_file_handler = logging.FileHandler(self.__logger_file)
396
- self.logger_file_handler.setFormatter(self.logger_formatter)
397
- for _, logger in self.logger.items():
398
- logger.addHandler(self.logger_file_handler)
399
-
400
- @property
401
- def debug(self) -> bool:
402
- """Debug status
403
-
404
- :param value: The debug status, True or False.
405
- :type: bool
406
- """
407
- return self.__debug
408
-
409
- @debug.setter
410
- def debug(self, value: bool) -> None:
411
- """Debug status
412
-
413
- :param value: The debug status, True or False.
414
- :type: bool
415
- """
416
- self.__debug = value
417
- if self.__debug:
418
- # if debug status is True, turn on debug logging
419
- for _, logger in self.logger.items():
420
- logger.setLevel(logging.DEBUG)
421
- # turn on httplib debug
422
- httplib.HTTPConnection.debuglevel = 1
423
- else:
424
- # if debug status is False, turn off debug logging,
425
- # setting log level to default `logging.WARNING`
426
- for _, logger in self.logger.items():
427
- logger.setLevel(logging.WARNING)
428
- # turn off httplib debug
429
- httplib.HTTPConnection.debuglevel = 0
430
-
431
- @property
432
- def logger_format(self) -> str:
433
- """The logger format.
434
-
435
- The logger_formatter will be updated when sets logger_format.
436
-
437
- :param value: The format string.
438
- :type: str
439
- """
440
- return self.__logger_format
441
-
442
- @logger_format.setter
443
- def logger_format(self, value: str) -> None:
444
- """The logger format.
445
-
446
- The logger_formatter will be updated when sets logger_format.
447
-
448
- :param value: The format string.
449
- :type: str
450
- """
451
- self.__logger_format = value
452
- self.logger_formatter = logging.Formatter(self.__logger_format)
453
-
454
- def get_api_key_with_prefix(self, identifier: str, alias: Optional[str]=None) -> Optional[str]:
455
- """Gets API key (with prefix if set).
456
-
457
- :param identifier: The identifier of apiKey.
458
- :param alias: The alternative identifier of apiKey.
459
- :return: The token for api key authentication.
460
- """
461
- if self.refresh_api_key_hook is not None:
462
- self.refresh_api_key_hook(self)
463
- key = self.api_key.get(identifier, self.api_key.get(alias) if alias is not None else None)
464
- if key:
465
- prefix = self.api_key_prefix.get(identifier)
466
- if prefix:
467
- return "%s %s" % (prefix, key)
468
- else:
469
- return key
470
-
471
- return None
472
-
473
- def get_basic_auth_token(self) -> Optional[str]:
474
- """Gets HTTP basic authentication header (string).
475
-
476
- :return: The token for basic HTTP authentication.
477
- """
478
- username = ""
479
- if self.username is not None:
480
- username = self.username
481
- password = ""
482
- if self.password is not None:
483
- password = self.password
484
- return urllib3.util.make_headers(
485
- basic_auth=username + ':' + password
486
- ).get('authorization')
487
-
488
- def auth_settings(self)-> AuthSettings:
489
- """Gets Auth Settings dict for api client.
490
-
491
- :return: The Auth Settings information dict.
492
- """
493
- auth: AuthSettings = {}
494
- return auth
495
-
496
- def to_debug_report(self) -> str:
497
- """Gets the essential information for debugging.
498
-
499
- :return: The report for debugging.
500
- """
501
- return "Python SDK Debug Report:\n"\
502
- "OS: {env}\n"\
503
- "Python Version: {pyversion}\n"\
504
- "Version of the API: 1.0.0\n"\
505
- "SDK Package Version: 1.0.0".\
506
- format(env=sys.platform, pyversion=sys.version)
507
-
508
- def get_host_settings(self) -> List[HostSetting]:
509
- """Gets an array of host settings
510
-
511
- :return: An array of host settings
512
- """
513
- return [
514
- {
515
- 'url': "http://localhost:8000",
516
- 'description': "Local development registry",
517
- },
518
- {
519
- 'url': "http://registry:8000",
520
- 'description': "Docker/Kubernetes registry",
521
- }
522
- ]
523
-
524
- def get_host_from_settings(
525
- self,
526
- index: Optional[int],
527
- variables: Optional[ServerVariablesT]=None,
528
- servers: Optional[List[HostSetting]]=None,
529
- ) -> str:
530
- """Gets host URL based on the index and variables
531
- :param index: array index of the host settings
532
- :param variables: hash of variable and the corresponding value
533
- :param servers: an array of host settings or None
534
- :return: URL based on host settings
535
- """
536
- if index is None:
537
- return self._base_path
538
-
539
- variables = {} if variables is None else variables
540
- servers = self.get_host_settings() if servers is None else servers
541
-
542
- try:
543
- server = servers[index]
544
- except IndexError:
545
- raise ValueError(
546
- "Invalid index {0} when selecting the host settings. "
547
- "Must be less than {1}".format(index, len(servers)))
548
-
549
- url = server['url']
550
-
551
- # go through variables and replace placeholders
552
- for variable_name, variable in server.get('variables', {}).items():
553
- used_value = variables.get(
554
- variable_name, variable['default_value'])
555
-
556
- if 'enum_values' in variable \
557
- and used_value not in variable['enum_values']:
558
- raise ValueError(
559
- "The variable `{0}` in the host URL has invalid value "
560
- "{1}. Must be {2}.".format(
561
- variable_name, variables[variable_name],
562
- variable['enum_values']))
563
-
564
- url = url.replace("{" + variable_name + "}", used_value)
565
-
566
- return url
567
-
568
- @property
569
- def host(self) -> str:
570
- """Return generated host."""
571
- return self.get_host_from_settings(self.server_index, variables=self.server_variables)
572
-
573
- @host.setter
574
- def host(self, value: str) -> None:
575
- """Fix base path."""
576
- self._base_path = value
577
- self.server_index = None