aas-http-client 0.3.4__tar.gz → 0.3.6__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.

Potentially problematic release.


This version of aas-http-client might be problematic. Click here for more details.

Files changed (21) hide show
  1. {aas_http_client-0.3.4 → aas_http_client-0.3.6}/PKG-INFO +1 -1
  2. {aas_http_client-0.3.4 → aas_http_client-0.3.6}/aas_http_client/client.py +5 -0
  3. {aas_http_client-0.3.4 → aas_http_client-0.3.6}/aas_http_client/demo/demo_process.py +2 -2
  4. {aas_http_client-0.3.4 → aas_http_client-0.3.6}/aas_http_client/wrapper/sdk_wrapper.py +3 -0
  5. {aas_http_client-0.3.4 → aas_http_client-0.3.6}/aas_http_client.egg-info/PKG-INFO +1 -1
  6. {aas_http_client-0.3.4 → aas_http_client-0.3.6}/aas_http_client.egg-info/SOURCES.txt +0 -1
  7. {aas_http_client-0.3.4 → aas_http_client-0.3.6}/pyproject.toml +1 -1
  8. {aas_http_client-0.3.4 → aas_http_client-0.3.6}/tests/test_client.py +3 -3
  9. {aas_http_client-0.3.4 → aas_http_client-0.3.6}/tests/test_wrapper.py +3 -3
  10. aas_http_client-0.3.4/aas_http_client/demo/logging_handler.py +0 -177
  11. {aas_http_client-0.3.4 → aas_http_client-0.3.6}/LICENSE +0 -0
  12. {aas_http_client-0.3.4 → aas_http_client-0.3.6}/README.md +0 -0
  13. {aas_http_client-0.3.4 → aas_http_client-0.3.6}/aas_http_client/__init__.py +0 -0
  14. {aas_http_client-0.3.4 → aas_http_client-0.3.6}/aas_http_client/core/encoder.py +0 -0
  15. {aas_http_client-0.3.4 → aas_http_client-0.3.6}/aas_http_client/core/version_check.py +0 -0
  16. {aas_http_client-0.3.4 → aas_http_client-0.3.6}/aas_http_client/utilities/__init__.py +0 -0
  17. {aas_http_client-0.3.4 → aas_http_client-0.3.6}/aas_http_client/utilities/model_builder.py +0 -0
  18. {aas_http_client-0.3.4 → aas_http_client-0.3.6}/aas_http_client.egg-info/dependency_links.txt +0 -0
  19. {aas_http_client-0.3.4 → aas_http_client-0.3.6}/aas_http_client.egg-info/requires.txt +0 -0
  20. {aas_http_client-0.3.4 → aas_http_client-0.3.6}/aas_http_client.egg-info/top_level.txt +0 -0
  21. {aas_http_client-0.3.4 → aas_http_client-0.3.6}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aas-http-client
3
- Version: 0.3.4
3
+ Version: 0.3.6
4
4
  Summary: Generic python HTTP client for communication with various types of AAS servers
5
5
  Author-email: Daniel Klein <daniel.klein@em.ag>
6
6
  License: # :em engineering methods AG Software License
@@ -80,6 +80,7 @@ class AasHttpClient(BaseModel):
80
80
  time_out: int = 200
81
81
  connection_time_out: int = 100
82
82
  ssl_verify: bool = True
83
+ trust_env: bool = True
83
84
  _session: Session = PrivateAttr(default=None)
84
85
 
85
86
  def initialize(self, password: str):
@@ -93,6 +94,7 @@ class AasHttpClient(BaseModel):
93
94
  self._session = requests.Session()
94
95
  self._session.auth = HTTPBasicAuth(self.username, password)
95
96
  self._session.verify = self.ssl_verify
97
+ self._session.trust_env = self.trust_env
96
98
 
97
99
  if self.https_proxy:
98
100
  self._session.proxies.update({"https": self.https_proxy})
@@ -600,6 +602,7 @@ def create_client_by_url(
600
602
  time_out: int = 200,
601
603
  connection_time_out: int = 60,
602
604
  ssl_verify: str = True, # noqa: FBT002
605
+ trust_env: bool = True, # noqa: FBT001, FBT002
603
606
  ) -> AasHttpClient | None:
604
607
  """Create a HTTP client for a AAS server connection from the given parameters.
605
608
 
@@ -611,6 +614,7 @@ def create_client_by_url(
611
614
  :param time_out: Timeout for the API calls, defaults to 200
612
615
  :param connection_time_out: Timeout for the connection to the API, defaults to 60
613
616
  :param ssl_verify: Whether to verify SSL certificates, defaults to True
617
+ :param trust_env: Whether to trust environment variables for proxy settings, defaults to True
614
618
  :return: An instance of Http client initialized with the provided parameters.
615
619
  """
616
620
  logger.info(f"Create AAS server http client from URL '{base_url}'")
@@ -622,6 +626,7 @@ def create_client_by_url(
622
626
  config_dict["time_out"] = time_out
623
627
  config_dict["connection_time_out"] = connection_time_out
624
628
  config_dict["ssl_verify"] = ssl_verify
629
+ config_dict["trust_env"] = trust_env
625
630
  return create_client_by_dict(config_dict, password)
626
631
 
627
632
 
@@ -31,8 +31,8 @@ def start() -> None:
31
31
  # add submodel to AAS
32
32
  model_builder.add_submodel_to_aas(aas, submodel)
33
33
 
34
- wrapper = _create_sdk_wrapper(Path("./aas_http_client/demo/python_server_config.json"))
35
- # dotnet_sdk_wrapper = _create_sdk_wrapper(Path("./aas_http_client/demo/dotnet_server_config.json"))
34
+ wrapper = _create_sdk_wrapper(Path("./aas_http_client/demo/python_server_config.yml"))
35
+ # dotnet_sdk_wrapper = _create_sdk_wrapper(Path("./aas_http_client/demo/dotnet_server_config.yml"))
36
36
 
37
37
  for existing_shell in wrapper.get_all_asset_administration_shells():
38
38
  logger.warning(f"Delete shell '{existing_shell.id}'")
@@ -335,6 +335,7 @@ def create_wrapper_by_url(
335
335
  time_out: int = 200,
336
336
  connection_time_out: int = 60,
337
337
  ssl_verify: str = True, # noqa: FBT002
338
+ trust_env: bool = True, # noqa: FBT001, FBT002
338
339
  ) -> SdkWrapper | None:
339
340
  """Create a wrapper for a AAS server connection from the given parameters.
340
341
 
@@ -346,6 +347,7 @@ def create_wrapper_by_url(
346
347
  :param time_out: timeout for the API calls, defaults to 200
347
348
  :param connection_time_out: timeout for the connection to the API, defaults to 60
348
349
  :param ssl_verify: whether to verify SSL certificates, defaults to True
350
+ :param trust_env: Whether to trust environment variables for proxy settings, defaults to True
349
351
  :return: An instance of SdkWrapper initialized with the provided parameters.
350
352
  """
351
353
  logger.info(f"Create AAS server wrapper from URL '{base_url}'")
@@ -357,6 +359,7 @@ def create_wrapper_by_url(
357
359
  config_dict["time_out"] = time_out
358
360
  config_dict["connection_time_out"] = connection_time_out
359
361
  config_dict["ssl_verify"] = ssl_verify
362
+ config_dict["trust_env"] = trust_env
360
363
  return create_wrapper_by_dict(config_dict, password)
361
364
 
362
365
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aas-http-client
3
- Version: 0.3.4
3
+ Version: 0.3.6
4
4
  Summary: Generic python HTTP client for communication with various types of AAS servers
5
5
  Author-email: Daniel Klein <daniel.klein@em.ag>
6
6
  License: # :em engineering methods AG Software License
@@ -11,7 +11,6 @@ aas_http_client.egg-info/top_level.txt
11
11
  aas_http_client/core/encoder.py
12
12
  aas_http_client/core/version_check.py
13
13
  aas_http_client/demo/demo_process.py
14
- aas_http_client/demo/logging_handler.py
15
14
  aas_http_client/utilities/__init__.py
16
15
  aas_http_client/utilities/model_builder.py
17
16
  aas_http_client/wrapper/sdk_wrapper.py
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "aas-http-client"
7
- version = "0.3.4"
7
+ version = "0.3.6"
8
8
  description = "Generic python HTTP client for communication with various types of AAS servers"
9
9
  readme = "README.md"
10
10
  license = { file = "LICENSE" }
@@ -11,9 +11,9 @@ JAVA_SERVER_PORTS = [8075]
11
11
  PYTHON_SERVER_PORTS = [8080, 80]
12
12
 
13
13
  CONFIG_FILES = [
14
- "./tests/server_configs/test_dotnet_server_config.json",
15
- "./tests/server_configs/test_java_server_config.json",
16
- "./tests/server_configs/test_python_server_config.json"
14
+ "./tests/server_configs/test_dotnet_server_config.yml",
15
+ "./tests/server_configs/test_java_server_config.yml",
16
+ "./tests/server_configs/test_python_server_config.yml"
17
17
  ]
18
18
 
19
19
  # CONFIG_FILES = [
@@ -11,9 +11,9 @@ PYTHON_SERVER_PORTS = [8080, 80]
11
11
  DOTNET_SERVER_PORTS = [5043]
12
12
 
13
13
  CONFIG_FILES = [
14
- "./tests/server_configs/test_dotnet_server_config.json",
15
- "./tests/server_configs/test_java_server_config.json",
16
- "./tests/server_configs/test_python_server_config.json"
14
+ "./tests/server_configs/test_dotnet_server_config.yml",
15
+ "./tests/server_configs/test_java_server_config.yml",
16
+ "./tests/server_configs/test_python_server_config.yml"
17
17
  ]
18
18
 
19
19
  # CONFIG_FILES = [
@@ -1,177 +0,0 @@
1
- """
2
- Logging handler.
3
-
4
- This module contains all methods and functions to handle the logging.
5
- """
6
-
7
- import json
8
- import logging
9
- import queue
10
- import sys
11
- import uuid
12
- from datetime import UTC, datetime
13
- from logging.handlers import QueueHandler
14
- from pathlib import Path
15
- from typing import ClassVar
16
-
17
- from pythonjsonlogger import jsonlogger
18
-
19
- LOG_FOLDER: str = "./_log"
20
- LOG_FILE_SUFFIX: str = "_log.json"
21
-
22
-
23
- class ColorCodes:
24
- """Define the color codes for the console output."""
25
-
26
- grey = "\x1b[38;21m"
27
- green = "\x1b[1;32m"
28
- yellow = "\x1b[33;21m"
29
- red = "\x1b[31;21m"
30
- bold_red = "\x1b[31;1m"
31
- blue = "\x1b[1;34m"
32
- light_blue = "\x1b[1;36m"
33
- purple = "\x1b[1;35m"
34
- reset = "\x1b[0m"
35
-
36
-
37
- class CustomConsoleFormatter(logging.Formatter):
38
- """Custom console formatter for logging with colored level.
39
-
40
- :param logging: formatter
41
- """
42
-
43
- FORMATS: ClassVar[dict] = {
44
- logging.DEBUG: ColorCodes.blue + "%(levelname)s" + ColorCodes.reset + ": %(message)s (%(filename)s:%(lineno)d)",
45
- logging.INFO: ColorCodes.green + "%(levelname)s" + ColorCodes.reset + ": %(message)s",
46
- logging.WARNING: ColorCodes.yellow + "%(levelname)s" + ColorCodes.reset + ": %(message)s",
47
- logging.ERROR: ColorCodes.red + "%(levelname)s" + ColorCodes.reset + ": %(message)s (%(filename)s:%(lineno)d)",
48
- logging.CRITICAL: ColorCodes.bold_red + "%(levelname)s: %(message)s (%(filename)s:%(lineno)d)" + ColorCodes.reset,
49
- }
50
-
51
- def format(self, record) -> str:
52
- """Format the log record.
53
-
54
- :param record: record to format
55
- :return: formatted record
56
- """
57
- log_fmt = self.FORMATS.get(record.levelno)
58
- formatter = logging.Formatter(log_fmt)
59
- return formatter.format(record)
60
-
61
-
62
- def _handle_file_rotation(log_file_path: Path, max_file_count: int = 5) -> None:
63
- log_folder: Path = log_file_path.resolve()
64
-
65
- if max_file_count < 1:
66
- return
67
-
68
- if not log_folder.exists():
69
- return
70
-
71
- existing_log_files: list[Path] = [file for file in log_folder.iterdir() if file.name.endswith(LOG_FILE_SUFFIX)]
72
-
73
- if len(existing_log_files) < max_file_count:
74
- return
75
-
76
- existing_log_files.sort(key=lambda x: x.stat().st_ctime)
77
-
78
- files_to_delete: int = len(existing_log_files) - (max_file_count - 1)
79
-
80
- for file in existing_log_files[:files_to_delete]:
81
- file.unlink()
82
-
83
- return
84
-
85
-
86
- def initialize_logging(console_level=logging.INFO) -> Path:
87
- """Initialize the standard logging.
88
-
89
- :param debug_mode_status: Status of the debug mode
90
- :param log_file_name: Name of the (path and extension)
91
- """
92
- log_path = Path(LOG_FOLDER).resolve()
93
- log_path.mkdir(parents=True, exist_ok=True)
94
-
95
- log_file_path = log_path / "api.log"
96
-
97
- log_file_format = "%(asctime)s %(levelname)s: %(message)s (%(filename)s:%(lineno)d)"
98
- logging.basicConfig(
99
- filename=log_file_path,
100
- level=logging.DEBUG,
101
- format=log_file_format,
102
- filemode="w",
103
- )
104
-
105
- # set console logging
106
- console_handler = logging.StreamHandler()
107
- console_handler.setLevel(console_level)
108
- console_handler.setFormatter(CustomConsoleFormatter())
109
- logging.getLogger("").addHandler(console_handler)
110
-
111
- # set queue logging
112
- log_queue: queue.Queue = queue.Queue(-1) # Use default max size
113
- queue_handler = QueueHandler(log_queue)
114
- logging.getLogger("").addHandler(queue_handler)
115
-
116
- logger = logging.getLogger(__name__)
117
- script_path = Path(sys.argv[0])
118
- python_version = sys.version.replace("\n", "")
119
-
120
- print("")
121
- logger.info(f"Run script '{script_path.name.replace('.py', '')}'")
122
- logger.info(f"Script executed by Python v{python_version}")
123
- logger.info("Logging initialized")
124
-
125
- return log_file_path.resolve()
126
-
127
-
128
- def read_log_file_as_list(log_file_path: Path) -> list[dict]:
129
- """Read the log file as a list of dictionaries (Json conform).
130
-
131
- :param log_file_path: Path to the log file
132
- :return: list of dictionaries (Json conform)
133
- """
134
- with Path.open(log_file_path, "r", encoding="utf-8") as f:
135
- return [json.loads(line) for line in f if line.strip()]
136
-
137
-
138
- def set_log_file(
139
- max_log_files: int = 10,
140
- ) -> Path:
141
- """Set the log file.
142
-
143
- :param max_log_files: max number of log files in folder, defaults to 5
144
- :return: log file path
145
- """
146
- logger = logging.getLogger() # Get the root logger
147
-
148
- # Remove all existing file handlers
149
- for handler in logger.handlers[:]:
150
- if isinstance(handler, logging.FileHandler):
151
- logger.removeHandler(handler)
152
- handler.close()
153
-
154
- now = datetime.now(tz=UTC)
155
- time_string = now.strftime("%Y-%m-%d_%H-%M-%S")
156
-
157
- # handle log file and folder
158
- log_path: Path = Path(LOG_FOLDER).resolve()
159
- log_path = Path(LOG_FOLDER, "runtime").resolve()
160
-
161
- log_path.mkdir(parents=True, exist_ok=True)
162
- log_file_name = f"{uuid.uuid4().hex}{LOG_FILE_SUFFIX}"
163
- log_file_path = log_path / f"{time_string}_{log_file_name}"
164
-
165
- _handle_file_rotation(log_path, max_log_files)
166
-
167
- # Add a new file handler with the new log file path
168
- json_formatter = jsonlogger.JsonFormatter("%(asctime)s %(levelname)s %(name)s %(message)s %(filename)s %(lineno)d")
169
- json_file_handler = logging.FileHandler(log_file_path, mode="w")
170
- json_file_handler.setFormatter(json_formatter)
171
- json_file_handler.setLevel(logging.DEBUG)
172
- logger.addHandler(json_file_handler)
173
-
174
- logging.info(f"Maximum log file number is: {max_log_files}") # noqa: LOG015
175
- logging.info(f"Write log file to: '{log_file_path}'") # noqa: LOG015
176
-
177
- return log_file_path.resolve()
File without changes