matlab-proxy 0.19.0__py3-none-any.whl → 0.21.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.
Potentially problematic release.
This version of matlab-proxy might be problematic. Click here for more details.
- matlab_proxy/app.py +22 -15
- matlab_proxy/gui/asset-manifest.json +6 -6
- matlab_proxy/gui/index.html +1 -1
- matlab_proxy/gui/static/css/main.6cd0caba.css +13 -0
- matlab_proxy/gui/static/css/main.6cd0caba.css.map +1 -0
- matlab_proxy/gui/static/js/main.61c661b8.js +3 -0
- matlab_proxy/gui/static/js/{main.e07799e7.js.LICENSE.txt → main.61c661b8.js.LICENSE.txt} +0 -2
- matlab_proxy/gui/static/js/main.61c661b8.js.map +1 -0
- matlab_proxy/settings.py +1 -1
- matlab_proxy/util/mwi/logger.py +22 -2
- matlab_proxy/util/windows.py +4 -1
- {matlab_proxy-0.19.0.dist-info → matlab_proxy-0.21.0.dist-info}/METADATA +16 -15
- {matlab_proxy-0.19.0.dist-info → matlab_proxy-0.21.0.dist-info}/RECORD +36 -19
- {matlab_proxy-0.19.0.dist-info → matlab_proxy-0.21.0.dist-info}/WHEEL +1 -1
- {matlab_proxy-0.19.0.dist-info → matlab_proxy-0.21.0.dist-info}/entry_points.txt +1 -0
- matlab_proxy-0.21.0.dist-info/top_level.txt +3 -0
- matlab_proxy_manager/__init__.py +6 -0
- matlab_proxy_manager/lib/__init__.py +1 -0
- matlab_proxy_manager/lib/api.py +295 -0
- matlab_proxy_manager/storage/__init__.py +1 -0
- matlab_proxy_manager/storage/file_repository.py +144 -0
- matlab_proxy_manager/storage/interface.py +62 -0
- matlab_proxy_manager/storage/server.py +144 -0
- matlab_proxy_manager/utils/__init__.py +1 -0
- matlab_proxy_manager/utils/auth.py +77 -0
- matlab_proxy_manager/utils/constants.py +5 -0
- matlab_proxy_manager/utils/environment_variables.py +46 -0
- matlab_proxy_manager/utils/helpers.py +284 -0
- matlab_proxy_manager/utils/logger.py +73 -0
- matlab_proxy_manager/web/__init__.py +1 -0
- matlab_proxy_manager/web/app.py +447 -0
- matlab_proxy_manager/web/monitor.py +45 -0
- matlab_proxy_manager/web/watcher.py +54 -0
- tests/unit/test_app.py +1 -1
- tests/unit/util/mwi/test_logger.py +38 -4
- matlab_proxy/gui/static/css/main.da9c4eb8.css +0 -13
- matlab_proxy/gui/static/css/main.da9c4eb8.css.map +0 -1
- matlab_proxy/gui/static/js/main.e07799e7.js +0 -3
- matlab_proxy/gui/static/js/main.e07799e7.js.map +0 -1
- matlab_proxy-0.19.0.dist-info/top_level.txt +0 -2
- {matlab_proxy-0.19.0.dist-info → matlab_proxy-0.21.0.dist-info}/LICENSE.md +0 -0
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# Copyright 2024 The MathWorks, Inc.
|
|
2
|
+
import glob
|
|
3
|
+
import json
|
|
4
|
+
import os
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from typing import Optional
|
|
7
|
+
|
|
8
|
+
from matlab_proxy_manager.utils import logger
|
|
9
|
+
|
|
10
|
+
from .interface import IRepository
|
|
11
|
+
|
|
12
|
+
log = logger.get()
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class FileRepository(IRepository):
|
|
16
|
+
"""
|
|
17
|
+
A repository for managing MATLAB proxy server processes using the file system.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
def __init__(self, data_dir) -> None:
|
|
21
|
+
super().__init__()
|
|
22
|
+
self.data_dir = data_dir
|
|
23
|
+
self.encoding = "utf-8"
|
|
24
|
+
|
|
25
|
+
def get_all(self):
|
|
26
|
+
"""Retrieves all server processes from the repository.
|
|
27
|
+
|
|
28
|
+
Returns:
|
|
29
|
+
A dictionary mapping file paths to server process instances.
|
|
30
|
+
"""
|
|
31
|
+
from matlab_proxy_manager.storage.server import ServerProcess
|
|
32
|
+
|
|
33
|
+
servers = {}
|
|
34
|
+
|
|
35
|
+
# Read all the files in data_dir
|
|
36
|
+
all_files = glob.glob(f"{self.data_dir}/**/*.info", recursive=True)
|
|
37
|
+
|
|
38
|
+
for file in all_files:
|
|
39
|
+
try:
|
|
40
|
+
with open(file, "r", encoding=self.encoding) as f:
|
|
41
|
+
data = f.read().strip()
|
|
42
|
+
|
|
43
|
+
# Convert the content of each file to ServerProcess
|
|
44
|
+
if data:
|
|
45
|
+
server_process = ServerProcess.instantiate_from_string(data)
|
|
46
|
+
servers[file] = server_process
|
|
47
|
+
except Exception as ex:
|
|
48
|
+
log.debug("ServerProcess instantiation failed for %s: %s", file, ex)
|
|
49
|
+
return servers
|
|
50
|
+
|
|
51
|
+
def get(self, name) -> tuple:
|
|
52
|
+
"""
|
|
53
|
+
Retrieves a server process from the repository by its filename.
|
|
54
|
+
|
|
55
|
+
Args:
|
|
56
|
+
name (str): The name of the server process file.
|
|
57
|
+
|
|
58
|
+
Returns:
|
|
59
|
+
Tuple[Optional[str], Optional[ServerProcess]]: A tuple containing the file path
|
|
60
|
+
and the server process instance.
|
|
61
|
+
"""
|
|
62
|
+
from matlab_proxy_manager.storage.server import ServerProcess
|
|
63
|
+
|
|
64
|
+
server_process = None
|
|
65
|
+
full_file_path: Optional[str] = None
|
|
66
|
+
current_files = glob.glob(f"{self.data_dir}/**/{name}.info", recursive=True)
|
|
67
|
+
if current_files:
|
|
68
|
+
full_file_path = current_files[0]
|
|
69
|
+
with open(full_file_path, "r", encoding=self.encoding) as f:
|
|
70
|
+
try:
|
|
71
|
+
data = f.read().strip()
|
|
72
|
+
if data:
|
|
73
|
+
server_process = ServerProcess.instantiate_from_string(data)
|
|
74
|
+
except Exception as ex:
|
|
75
|
+
log.debug(
|
|
76
|
+
"ServerProcess instantiation failed for %s: %s",
|
|
77
|
+
full_file_path,
|
|
78
|
+
ex,
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
return full_file_path, server_process
|
|
82
|
+
|
|
83
|
+
def add(self, server, filename: str) -> None:
|
|
84
|
+
"""
|
|
85
|
+
Adds a server process to the repository.
|
|
86
|
+
Creates a directory like <ctx>_default|<kernel_id> and then creates a file as
|
|
87
|
+
default|<kernel_id>.info in that dir
|
|
88
|
+
|
|
89
|
+
Args:
|
|
90
|
+
server (ServerProcess): The server process instance to add.
|
|
91
|
+
filename (str): The filename to associate with the server process.
|
|
92
|
+
"""
|
|
93
|
+
# Creates a child dir under the data_dir
|
|
94
|
+
server_dir = Path(f"{self.data_dir}", f"{server.id}")
|
|
95
|
+
Path.mkdir(server_dir, parents=True, exist_ok=True)
|
|
96
|
+
server_dict = {}
|
|
97
|
+
|
|
98
|
+
server_file = Path(server_dir, f"{filename}.info")
|
|
99
|
+
with open(server_file, "w", encoding=self.encoding) as f:
|
|
100
|
+
server_dict[server.id] = server.as_dict()
|
|
101
|
+
file_content = json.dumps(server_dict)
|
|
102
|
+
f.write(file_content)
|
|
103
|
+
|
|
104
|
+
def delete(self, filename: str) -> None:
|
|
105
|
+
"""
|
|
106
|
+
Deletes a server process from the repository by its filename.
|
|
107
|
+
|
|
108
|
+
Args:
|
|
109
|
+
filename (str): The filename associated with the server process to delete.
|
|
110
|
+
"""
|
|
111
|
+
# <path to proxy manager dir>/<parent_pid>_<name>/<name>.info
|
|
112
|
+
full_file_path, parent_dir = FileRepository._find_file_and_get_parent(
|
|
113
|
+
self.data_dir, filename
|
|
114
|
+
)
|
|
115
|
+
if full_file_path:
|
|
116
|
+
Path(full_file_path).unlink(missing_ok=True)
|
|
117
|
+
log.debug("Deleted file: %s", filename)
|
|
118
|
+
|
|
119
|
+
# delete the sub-directory (<parent_pid>_<id>) only if it is empty
|
|
120
|
+
if parent_dir and not len(os.listdir(parent_dir)):
|
|
121
|
+
os.rmdir(parent_dir)
|
|
122
|
+
log.debug("Deleted dir: %s", parent_dir)
|
|
123
|
+
|
|
124
|
+
@staticmethod
|
|
125
|
+
def _find_file_and_get_parent(data_dir: str, filename: str):
|
|
126
|
+
"""
|
|
127
|
+
Finds the file and its parent directory in the given data directory.
|
|
128
|
+
|
|
129
|
+
Args:
|
|
130
|
+
data_dir (str): The base directory to search within.
|
|
131
|
+
filename (str): The filename to search for.
|
|
132
|
+
|
|
133
|
+
Returns:
|
|
134
|
+
Tuple[Optional[str], Optional[str]]: A tuple containing the full file path and the parent directory.
|
|
135
|
+
"""
|
|
136
|
+
for dirpath, _, filenames in os.walk(data_dir):
|
|
137
|
+
# Check if target file is in the current directory's files
|
|
138
|
+
if filename in filenames:
|
|
139
|
+
full_path = os.path.join(dirpath, filename)
|
|
140
|
+
parent_dir = os.path.dirname(full_path)
|
|
141
|
+
return full_path, parent_dir
|
|
142
|
+
|
|
143
|
+
# Return None if the file was not found
|
|
144
|
+
return None, None
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# Copyright 2024 The MathWorks, Inc.
|
|
2
|
+
from typing import Protocol
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class IRepository(Protocol):
|
|
6
|
+
"""
|
|
7
|
+
Protocol for a repository that manages MATLAB proxy server processes.
|
|
8
|
+
This protocol defines the required methods for adding, retrieving, and deleting
|
|
9
|
+
server process instances to the storage system (files).
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
def add(self, server, filename: str):
|
|
13
|
+
"""
|
|
14
|
+
Adds a server process to the repository.
|
|
15
|
+
|
|
16
|
+
Args:
|
|
17
|
+
server (server.ServerProcess): The server process instance to add.
|
|
18
|
+
filename (str): The filename to associate with the server process.
|
|
19
|
+
|
|
20
|
+
Raises:
|
|
21
|
+
NotImplementedError
|
|
22
|
+
"""
|
|
23
|
+
raise NotImplementedError("add not implemented")
|
|
24
|
+
|
|
25
|
+
def get(self, name: str) -> tuple:
|
|
26
|
+
"""
|
|
27
|
+
Retrieves a server process from the repository by its filename.
|
|
28
|
+
|
|
29
|
+
Args:
|
|
30
|
+
filename (str): The filename associated with the server process.
|
|
31
|
+
|
|
32
|
+
Returns:
|
|
33
|
+
tuple (str, server.ServerProcess): Full file path and the retrieved server process instance.
|
|
34
|
+
|
|
35
|
+
Raises:
|
|
36
|
+
NotImplementedError
|
|
37
|
+
"""
|
|
38
|
+
raise NotImplementedError("get not implemented")
|
|
39
|
+
|
|
40
|
+
def get_all(self):
|
|
41
|
+
"""
|
|
42
|
+
Retrieves all server processes from the repository.
|
|
43
|
+
|
|
44
|
+
Returns:
|
|
45
|
+
Dict[str, server.ServerProcess]: Dict with filename as key and corresponding server process as value.
|
|
46
|
+
|
|
47
|
+
Raises:
|
|
48
|
+
NotImplementedError
|
|
49
|
+
"""
|
|
50
|
+
raise NotImplementedError("get_all not implemented")
|
|
51
|
+
|
|
52
|
+
def delete(self, filename: str) -> None:
|
|
53
|
+
"""
|
|
54
|
+
Deletes a server process from the repository by its filename.
|
|
55
|
+
|
|
56
|
+
Args:
|
|
57
|
+
filename (str): The filename associated with the server process to delete.
|
|
58
|
+
|
|
59
|
+
Raises:
|
|
60
|
+
NotImplementedError
|
|
61
|
+
"""
|
|
62
|
+
raise NotImplementedError("delete not implemented")
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# Copyright 2024 The MathWorks, Inc.
|
|
2
|
+
import json
|
|
3
|
+
from dataclasses import asdict, dataclass, field
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import Optional
|
|
6
|
+
|
|
7
|
+
from matlab_proxy_manager.utils import helpers, logger
|
|
8
|
+
|
|
9
|
+
log = logger.get()
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@dataclass
|
|
13
|
+
class ServerProcess:
|
|
14
|
+
"""
|
|
15
|
+
Represents a MATLAB server process with various attributes and methods
|
|
16
|
+
to manage its lifecycle.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
server_url: Optional[str] = None
|
|
20
|
+
mwi_base_url: Optional[str] = None
|
|
21
|
+
headers: Optional[dict] = None
|
|
22
|
+
errors: Optional[list] = None
|
|
23
|
+
pid: Optional[int] = None
|
|
24
|
+
parent_pid: Optional[int] = None
|
|
25
|
+
absolute_url: Optional[str] = field(default=None)
|
|
26
|
+
id: Optional[str] = None
|
|
27
|
+
type: Optional[str] = None
|
|
28
|
+
mpm_auth_token: Optional[str] = None
|
|
29
|
+
|
|
30
|
+
def __post_init__(self) -> None:
|
|
31
|
+
if not self.absolute_url:
|
|
32
|
+
self.absolute_url = f"{self.server_url}{self.mwi_base_url}"
|
|
33
|
+
|
|
34
|
+
def __str__(self) -> str:
|
|
35
|
+
"""
|
|
36
|
+
Returns a string representation of the ServerProcess instance.
|
|
37
|
+
"""
|
|
38
|
+
return json.dumps(asdict(self))
|
|
39
|
+
|
|
40
|
+
def as_dict(self) -> dict:
|
|
41
|
+
"""
|
|
42
|
+
Returns a dict representation of the ServerProcess instance.
|
|
43
|
+
"""
|
|
44
|
+
return asdict(self)
|
|
45
|
+
|
|
46
|
+
@staticmethod
|
|
47
|
+
def instantiate_from_string(data: str) -> "ServerProcess":
|
|
48
|
+
"""
|
|
49
|
+
Instantiates a ServerProcess object from a JSON string.
|
|
50
|
+
|
|
51
|
+
Args:
|
|
52
|
+
data (str): The JSON string representing a ServerProcess.
|
|
53
|
+
|
|
54
|
+
Returns:
|
|
55
|
+
ServerProcess: An instance of ServerProcess.
|
|
56
|
+
|
|
57
|
+
Raises:
|
|
58
|
+
ValueError: If the JSON string cannot be parsed or is missing required fields.
|
|
59
|
+
"""
|
|
60
|
+
try:
|
|
61
|
+
full_dict = json.loads(data)
|
|
62
|
+
key = list(full_dict.keys())[0]
|
|
63
|
+
server = full_dict[key]
|
|
64
|
+
server_process = ServerProcess(
|
|
65
|
+
server_url=server["server_url"],
|
|
66
|
+
mwi_base_url=server["mwi_base_url"],
|
|
67
|
+
headers=server["headers"],
|
|
68
|
+
errors=server["errors"],
|
|
69
|
+
pid=server["pid"],
|
|
70
|
+
parent_pid=server["parent_pid"],
|
|
71
|
+
absolute_url=server["absolute_url"],
|
|
72
|
+
id=server["id"],
|
|
73
|
+
type=server["type"],
|
|
74
|
+
mpm_auth_token=server["mpm_auth_token"],
|
|
75
|
+
)
|
|
76
|
+
return server_process
|
|
77
|
+
except (json.JSONDecodeError, KeyError) as ex:
|
|
78
|
+
log.debug("Failed to instantiate server from %s: %s", data, ex)
|
|
79
|
+
raise ValueError(
|
|
80
|
+
"Invalid JSON string for ServerProcess instantiation"
|
|
81
|
+
) from ex
|
|
82
|
+
|
|
83
|
+
def shutdown(self):
|
|
84
|
+
"""
|
|
85
|
+
Shuts down the MATLAB proxy server by calling the shutdown_integration endpoint.
|
|
86
|
+
"""
|
|
87
|
+
log.debug("Shutting down matlab proxy")
|
|
88
|
+
backend_server = self.absolute_url
|
|
89
|
+
url = f"{backend_server}/shutdown_integration"
|
|
90
|
+
try:
|
|
91
|
+
response = helpers.requests_retry_session(retries=1).delete(
|
|
92
|
+
url=url, headers=self.headers
|
|
93
|
+
)
|
|
94
|
+
shutdown_resp = response.json()
|
|
95
|
+
log.debug("Response from shutdown: %s", response.json())
|
|
96
|
+
return shutdown_resp
|
|
97
|
+
except Exception as e:
|
|
98
|
+
log.debug("Exception while shutting down matlab proxy: %s", e)
|
|
99
|
+
return None
|
|
100
|
+
|
|
101
|
+
def is_server_alive(self) -> bool:
|
|
102
|
+
"""
|
|
103
|
+
Checks if the server process is alive and ready.
|
|
104
|
+
|
|
105
|
+
Returns:
|
|
106
|
+
bool: True if the server process is alive and ready, False otherwise.
|
|
107
|
+
"""
|
|
108
|
+
return helpers.does_process_exist(self.pid) and helpers.is_server_ready(
|
|
109
|
+
self.absolute_url, retries=0
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
@staticmethod
|
|
113
|
+
def find_existing_server(data_dir, key: str) -> Optional["ServerProcess"]:
|
|
114
|
+
"""
|
|
115
|
+
Finds an existing server process by reading the server configuration from a file.
|
|
116
|
+
|
|
117
|
+
Args:
|
|
118
|
+
data_dir (str): The directory where server configuration files are stored.
|
|
119
|
+
key (str): The key corresponding to the specific server configuration.
|
|
120
|
+
|
|
121
|
+
Returns:
|
|
122
|
+
Optional[ServerProcess]: An instance of ServerProcess if a valid configuration is found,
|
|
123
|
+
otherwise None.
|
|
124
|
+
"""
|
|
125
|
+
key_dir = Path(data_dir, key)
|
|
126
|
+
server_process = None
|
|
127
|
+
|
|
128
|
+
# Return early if the directory is not found
|
|
129
|
+
if not key_dir.is_dir():
|
|
130
|
+
return server_process
|
|
131
|
+
|
|
132
|
+
files = list(key_dir.iterdir())
|
|
133
|
+
if not files:
|
|
134
|
+
return server_process
|
|
135
|
+
|
|
136
|
+
try:
|
|
137
|
+
with open(files[0], "r", encoding="utf-8") as file:
|
|
138
|
+
data = file.read().strip()
|
|
139
|
+
if data:
|
|
140
|
+
server_process = ServerProcess.instantiate_from_string(data)
|
|
141
|
+
except (OSError, ValueError) as ex:
|
|
142
|
+
log.debug("Exception while checking for existing server: %s", ex)
|
|
143
|
+
|
|
144
|
+
return server_process
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Copyright 2024 The MathWorks, Inc.
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# Copyright 2024 The MathWorks, Inc.
|
|
2
|
+
from hmac import compare_digest
|
|
3
|
+
|
|
4
|
+
from aiohttp import web
|
|
5
|
+
|
|
6
|
+
from matlab_proxy_manager.utils import logger
|
|
7
|
+
from matlab_proxy_manager.utils.constants import HEADER_MWI_MPM_AUTH_TOKEN
|
|
8
|
+
|
|
9
|
+
log = logger.get()
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
async def authenticate_request(request):
|
|
13
|
+
"""Authenticates incoming request by verifying whether the expected token is in the request.
|
|
14
|
+
|
|
15
|
+
The MWI-MPM-AUTH-TOKEN must be present in the request's headers.
|
|
16
|
+
|
|
17
|
+
Returns True/False based on whether the request is authenticated.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
log.debug("<======== Authenticate request: %s", request)
|
|
21
|
+
return await _is_valid_token_in_headers(request)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def authenticate_access_decorator(endpoint):
|
|
25
|
+
"""This decorator verifies that the request to an endpoint exposed by matlab-proxy-manager
|
|
26
|
+
contains the correct mpm auth token before servicing an endpoint."""
|
|
27
|
+
|
|
28
|
+
async def protect_endpoint(request):
|
|
29
|
+
"""Passes request to the endpoint after validating the token
|
|
30
|
+
|
|
31
|
+
Args:
|
|
32
|
+
request (HTTPRequest) : Web Request to endpoint
|
|
33
|
+
|
|
34
|
+
Raises:
|
|
35
|
+
web.HTTPForbidden: Thrown when validation of token fails
|
|
36
|
+
"""
|
|
37
|
+
if await authenticate_request(request):
|
|
38
|
+
# request is authentic, proceed to execute the endpoint
|
|
39
|
+
return await endpoint(request)
|
|
40
|
+
raise web.HTTPForbidden(reason="Unauthorized access!")
|
|
41
|
+
|
|
42
|
+
return protect_endpoint
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
async def _is_valid_token_in_headers(request):
|
|
46
|
+
"""Checks the request headers for mpm auth token
|
|
47
|
+
|
|
48
|
+
Args:
|
|
49
|
+
request (HTTPRequest) : Used to access app settings
|
|
50
|
+
|
|
51
|
+
Returns:
|
|
52
|
+
Boolean : True if valid token is found, else False
|
|
53
|
+
"""
|
|
54
|
+
headers = request.headers
|
|
55
|
+
if HEADER_MWI_MPM_AUTH_TOKEN in headers:
|
|
56
|
+
return await _is_valid_token(headers[HEADER_MWI_MPM_AUTH_TOKEN], request)
|
|
57
|
+
|
|
58
|
+
log.debug("Header: %s not found in request headers", HEADER_MWI_MPM_AUTH_TOKEN)
|
|
59
|
+
return False
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
async def _is_valid_token(token, request):
|
|
63
|
+
"""Checks if token contains expected value.
|
|
64
|
+
|
|
65
|
+
Args:
|
|
66
|
+
token (str): Token string to validate
|
|
67
|
+
request (HTTPRequest) : Used to access app settings
|
|
68
|
+
|
|
69
|
+
Returns:
|
|
70
|
+
_type_: True if token is valid, false otherwise.
|
|
71
|
+
"""
|
|
72
|
+
# Check if the token provided in the request matches the original token
|
|
73
|
+
# equivalent to a == b, but protects against timing attacks
|
|
74
|
+
saved_token = request.app["auth_token"]
|
|
75
|
+
is_valid = compare_digest(token, saved_token)
|
|
76
|
+
log.debug("Token validation %s ", "successful." if is_valid else "failed.")
|
|
77
|
+
return is_valid
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Copyright 2020-2024 The MathWorks, Inc.
|
|
2
|
+
"""This file lists and exposes the environment variables which are used by proxy manager."""
|
|
3
|
+
|
|
4
|
+
import os
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def _is_env_set_to_true(env_name: str) -> bool:
|
|
8
|
+
"""Helper function that returns True if the environment variable specified is set to True.
|
|
9
|
+
|
|
10
|
+
Args:
|
|
11
|
+
env_name (str): Name of the environment variable to check the state for.
|
|
12
|
+
|
|
13
|
+
Returns:
|
|
14
|
+
bool: True if the environment variable's value matches(case-insensitive) the string "True"
|
|
15
|
+
"""
|
|
16
|
+
return os.environ.get(env_name, "").lower() == "true"
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def get_env_name_logging_level():
|
|
20
|
+
"""Specifies the logging level used by app's loggers"""
|
|
21
|
+
return "MWI_MPM_LOG_LEVEL"
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def get_env_name_enable_web_logging():
|
|
25
|
+
"""Enable the logging of asyncio web traffic by setting to true"""
|
|
26
|
+
return "MWI_MPM_ENABLE_WEB_LOGGING"
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def get_env_name_mwi_mpm_auth_token():
|
|
30
|
+
"""Authentication environment variable for authenticating with proxy manager"""
|
|
31
|
+
return "MWI_MPM_AUTH_TOKEN"
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def get_env_name_mwi_mpm_port():
|
|
35
|
+
"""Used to specify the port on which to start proxy manager"""
|
|
36
|
+
return "MWI_MPM_PORT"
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def get_env_name_mwi_mpm_parent_pid():
|
|
40
|
+
"""Used to specify the parent pid for the proxy manager process"""
|
|
41
|
+
return "MWI_MPM_PARENT_PID"
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def is_web_logging_enabled():
|
|
45
|
+
"""Returns true if the web logging is required to be enabled"""
|
|
46
|
+
return _is_env_set_to_true(get_env_name_enable_web_logging())
|