brynq-sdk-brynq 3.0.0__tar.gz → 4.2.2.dev0__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.
- brynq_sdk_brynq-4.2.2.dev0/PKG-INFO +16 -0
- {brynq_sdk_brynq-3.0.0 → brynq_sdk_brynq-4.2.2.dev0}/brynq_sdk_brynq/brynq.py +21 -14
- {brynq_sdk_brynq-3.0.0 → brynq_sdk_brynq-4.2.2.dev0}/brynq_sdk_brynq/credentials.py +9 -7
- {brynq_sdk_brynq-3.0.0 → brynq_sdk_brynq-4.2.2.dev0}/brynq_sdk_brynq/customers.py +8 -5
- {brynq_sdk_brynq-3.0.0 → brynq_sdk_brynq-4.2.2.dev0}/brynq_sdk_brynq/interfaces.py +74 -108
- {brynq_sdk_brynq-3.0.0 → brynq_sdk_brynq-4.2.2.dev0}/brynq_sdk_brynq/mappings.py +26 -21
- {brynq_sdk_brynq-3.0.0 → brynq_sdk_brynq-4.2.2.dev0}/brynq_sdk_brynq/organization_chart.py +29 -20
- {brynq_sdk_brynq-3.0.0 → brynq_sdk_brynq-4.2.2.dev0}/brynq_sdk_brynq/roles.py +28 -19
- brynq_sdk_brynq-4.2.2.dev0/brynq_sdk_brynq/scenarios.py +1889 -0
- brynq_sdk_brynq-4.2.2.dev0/brynq_sdk_brynq/schemas/__init__.py +53 -0
- {brynq_sdk_brynq-3.0.0 → brynq_sdk_brynq-4.2.2.dev0}/brynq_sdk_brynq/schemas/credentials.py +5 -3
- {brynq_sdk_brynq-3.0.0 → brynq_sdk_brynq-4.2.2.dev0}/brynq_sdk_brynq/schemas/interfaces.py +3 -3
- brynq_sdk_brynq-4.2.2.dev0/brynq_sdk_brynq/schemas/scenarios.py +1747 -0
- {brynq_sdk_brynq-3.0.0 → brynq_sdk_brynq-4.2.2.dev0}/brynq_sdk_brynq/schemas/users.py +5 -4
- {brynq_sdk_brynq-3.0.0 → brynq_sdk_brynq-4.2.2.dev0}/brynq_sdk_brynq/source_systems.py +21 -14
- {brynq_sdk_brynq-3.0.0 → brynq_sdk_brynq-4.2.2.dev0}/brynq_sdk_brynq/users.py +43 -29
- brynq_sdk_brynq-4.2.2.dev0/brynq_sdk_brynq.egg-info/PKG-INFO +16 -0
- {brynq_sdk_brynq-3.0.0 → brynq_sdk_brynq-4.2.2.dev0}/brynq_sdk_brynq.egg-info/SOURCES.txt +3 -0
- {brynq_sdk_brynq-3.0.0 → brynq_sdk_brynq-4.2.2.dev0}/setup.py +2 -2
- brynq_sdk_brynq-3.0.0/PKG-INFO +0 -10
- brynq_sdk_brynq-3.0.0/brynq_sdk_brynq.egg-info/PKG-INFO +0 -10
- {brynq_sdk_brynq-3.0.0 → brynq_sdk_brynq-4.2.2.dev0}/brynq_sdk_brynq/__init__.py +0 -0
- {brynq_sdk_brynq-3.0.0 → brynq_sdk_brynq-4.2.2.dev0}/brynq_sdk_brynq/schemas/customers.py +0 -0
- {brynq_sdk_brynq-3.0.0 → brynq_sdk_brynq-4.2.2.dev0}/brynq_sdk_brynq/schemas/organization_chart.py +0 -0
- {brynq_sdk_brynq-3.0.0 → brynq_sdk_brynq-4.2.2.dev0}/brynq_sdk_brynq/schemas/roles.py +0 -0
- {brynq_sdk_brynq-3.0.0 → brynq_sdk_brynq-4.2.2.dev0}/brynq_sdk_brynq.egg-info/dependency_links.txt +0 -0
- {brynq_sdk_brynq-3.0.0 → brynq_sdk_brynq-4.2.2.dev0}/brynq_sdk_brynq.egg-info/not-zip-safe +0 -0
- {brynq_sdk_brynq-3.0.0 → brynq_sdk_brynq-4.2.2.dev0}/brynq_sdk_brynq.egg-info/requires.txt +0 -0
- {brynq_sdk_brynq-3.0.0 → brynq_sdk_brynq-4.2.2.dev0}/brynq_sdk_brynq.egg-info/top_level.txt +0 -0
- {brynq_sdk_brynq-3.0.0 → brynq_sdk_brynq-4.2.2.dev0}/setup.cfg +0 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: brynq_sdk_brynq
|
|
3
|
+
Version: 4.2.2.dev0
|
|
4
|
+
Summary: BrynQ SDK for the BrynQ.com platform
|
|
5
|
+
Author: BrynQ
|
|
6
|
+
Author-email: support@brynq.com
|
|
7
|
+
License: BrynQ License
|
|
8
|
+
Requires-Dist: requests<=3,>=2
|
|
9
|
+
Dynamic: author
|
|
10
|
+
Dynamic: author-email
|
|
11
|
+
Dynamic: description
|
|
12
|
+
Dynamic: license
|
|
13
|
+
Dynamic: requires-dist
|
|
14
|
+
Dynamic: summary
|
|
15
|
+
|
|
16
|
+
BrynQ SDK for the BrynQ.com platform
|
|
@@ -18,6 +18,11 @@ class BrynQ:
|
|
|
18
18
|
self.subdomain = os.getenv("BRYNQ_SUBDOMAIN", subdomain)
|
|
19
19
|
self.api_token = os.getenv("BRYNQ_API_TOKEN", api_token)
|
|
20
20
|
self.environment = os.getenv("BRYNQ_ENVIRONMENT", staging)
|
|
21
|
+
self.timeout = 3600
|
|
22
|
+
self.data_interface_id = os.getenv("DATA_INTERFACE_ID")
|
|
23
|
+
if self.data_interface_id is None:
|
|
24
|
+
raise ValueError("BRYNQ_DATA_INTERFACE_ID environment variable is not set, you should use this class via the TaskScheduler or set the variable in your code with:"
|
|
25
|
+
"os.environ['DATA_INTERFACE_ID'] = str(self.data_interface_id). This is better than setting it in your .env where you will have to change it when switching between interfaces.")
|
|
21
26
|
|
|
22
27
|
if any([self.subdomain is None, self.api_token is None]):
|
|
23
28
|
raise ValueError("Set the subdomain, api_token either in your .env file or provide the subdomain and api_token parameters")
|
|
@@ -27,19 +32,19 @@ class BrynQ:
|
|
|
27
32
|
raise ValueError(f"Environment should be in {','.join(possible_environments)}")
|
|
28
33
|
|
|
29
34
|
self.url = 'https://app.brynq-staging.com/api/v2/' if self.environment == 'dev' else 'https://app.brynq.com/api/v2/'
|
|
30
|
-
|
|
31
|
-
# Initialize session with retry strategy
|
|
32
|
-
self.
|
|
35
|
+
|
|
36
|
+
# Initialize session with retry strategy. This is called brynq_session and not session as to not conflict with other SDKs that use self.session
|
|
37
|
+
self.brynq_session = requests.Session()
|
|
33
38
|
retry_strategy = Retry(
|
|
34
39
|
total=3, # number of retries
|
|
35
40
|
backoff_factor=0.5, # wait 0.5s * (2 ** (retry - 1)) between retries
|
|
36
41
|
status_forcelist=[500, 502, 503, 504] # HTTP status codes to retry on
|
|
37
42
|
)
|
|
38
43
|
adapter = HTTPAdapter(max_retries=retry_strategy)
|
|
39
|
-
self.
|
|
40
|
-
self.
|
|
41
|
-
self.
|
|
42
|
-
|
|
44
|
+
self.brynq_session.mount("http://", adapter)
|
|
45
|
+
self.brynq_session.mount("https://", adapter)
|
|
46
|
+
self.brynq_session.headers.update(self._get_headers())
|
|
47
|
+
|
|
43
48
|
# Initialize components
|
|
44
49
|
self.users = Users(self)
|
|
45
50
|
self.organization_chart = OrganizationChart(self)
|
|
@@ -54,7 +59,7 @@ class BrynQ:
|
|
|
54
59
|
'Domain': self.subdomain
|
|
55
60
|
}
|
|
56
61
|
|
|
57
|
-
def get_mapping(self,
|
|
62
|
+
def get_mapping(self, mapping: str, return_format: Literal['input_as_key', 'columns_names_as_keys', 'nested_input_output'] = 'input_as_key') -> dict:
|
|
58
63
|
"""
|
|
59
64
|
DEPRECATED: Use brynq.mappings.get_mapping() instead
|
|
60
65
|
"""
|
|
@@ -71,7 +76,7 @@ class BrynQ:
|
|
|
71
76
|
:return: The json of the mapping
|
|
72
77
|
"""
|
|
73
78
|
# Find the mapping for the given sheet name
|
|
74
|
-
mappings = self.interfaces.mappings._get_mappings(
|
|
79
|
+
mappings = self.interfaces.mappings._get_mappings()
|
|
75
80
|
mapping_data = next((item for item in mappings if item['name'] == mapping), None)
|
|
76
81
|
if not mapping_data:
|
|
77
82
|
raise ValueError(f"Mapping named '{mapping}' not found")
|
|
@@ -103,9 +108,10 @@ class BrynQ:
|
|
|
103
108
|
else: # Default to assuming there's only one key-value pair if not concatenating
|
|
104
109
|
if output_values:
|
|
105
110
|
final_mapping[input_values[0]] = output_values[0]
|
|
111
|
+
|
|
106
112
|
return final_mapping
|
|
107
113
|
|
|
108
|
-
def get_mapping_as_dataframe(self,
|
|
114
|
+
def get_mapping_as_dataframe(self, mapping: str, prefix: bool = False) -> pd.DataFrame:
|
|
109
115
|
"""
|
|
110
116
|
DEPRECATED: Use brynq.mappings.get_mapping_as_dataframe() instead
|
|
111
117
|
"""
|
|
@@ -121,7 +127,7 @@ class BrynQ:
|
|
|
121
127
|
:return: The dataframe of the mapping
|
|
122
128
|
"""
|
|
123
129
|
# Find the mapping for the given sheet name
|
|
124
|
-
mappings = self.interfaces.mappings._get_mappings(
|
|
130
|
+
mappings = self.interfaces.mappings._get_mappings()
|
|
125
131
|
mapping_data = next((item for item in mappings if item['name'] == mapping), None)
|
|
126
132
|
if not mapping_data:
|
|
127
133
|
raise ValueError(f"Mapping named '{mapping}' not found")
|
|
@@ -148,6 +154,7 @@ class BrynQ:
|
|
|
148
154
|
df = pd.DataFrame(rows)
|
|
149
155
|
|
|
150
156
|
return df
|
|
157
|
+
|
|
151
158
|
def get_system_credential(self, system: str, label: Union[str, list], test_environment: bool = False) -> dict:
|
|
152
159
|
"""
|
|
153
160
|
DEPRECATED: Use brynq.credentials.get() instead
|
|
@@ -159,7 +166,7 @@ class BrynQ:
|
|
|
159
166
|
)
|
|
160
167
|
return self.interfaces.credentials.get_system_credential(system, label, test_environment)
|
|
161
168
|
|
|
162
|
-
def get_interface_credential(self,
|
|
169
|
+
def get_interface_credential(self, system: str, system_type: Optional[str] = None,
|
|
163
170
|
test_environment: bool = False) -> Union[dict, List[dict]]:
|
|
164
171
|
"""
|
|
165
172
|
DEPRECATED: Use brynq.credentials.get_interface_credential() instead
|
|
@@ -169,7 +176,7 @@ class BrynQ:
|
|
|
169
176
|
DeprecationWarning,
|
|
170
177
|
stacklevel=2
|
|
171
178
|
)
|
|
172
|
-
return self.interfaces.credentials.get(
|
|
179
|
+
return self.interfaces.credentials.get(self.data_interface_id, system, system_type, test_environment)
|
|
173
180
|
|
|
174
181
|
def get_user_data(self):
|
|
175
182
|
"""
|
|
@@ -279,4 +286,4 @@ class BrynQ:
|
|
|
279
286
|
def close(self):
|
|
280
287
|
"""Close the session and cleanup resources"""
|
|
281
288
|
if hasattr(self, 'session'):
|
|
282
|
-
self.
|
|
289
|
+
self.brynq_session.close()
|
|
@@ -3,7 +3,7 @@ import requests
|
|
|
3
3
|
from typing import Optional, Union, List, Dict, Any
|
|
4
4
|
import warnings
|
|
5
5
|
from .schemas.credentials import CredentialsConfig
|
|
6
|
-
from brynq_sdk_functions
|
|
6
|
+
from brynq_sdk_functions import Functions
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
class Credentials:
|
|
@@ -24,8 +24,9 @@ class Credentials:
|
|
|
24
24
|
DEPRECATED: Use brynq.interfaces.credentials.get() instead
|
|
25
25
|
"""
|
|
26
26
|
warnings.warn("This function is deprecated and will be removed in a future version.", DeprecationWarning, stacklevel=2)
|
|
27
|
-
response = self._brynq.
|
|
27
|
+
response = self._brynq.brynq_session.get(
|
|
28
28
|
url=f'{self._brynq.url}apps/{system}',
|
|
29
|
+
timeout=self._brynq.timeout
|
|
29
30
|
)
|
|
30
31
|
response.raise_for_status()
|
|
31
32
|
credentials = response.json()
|
|
@@ -46,7 +47,7 @@ class Credentials:
|
|
|
46
47
|
|
|
47
48
|
return credentials[0]
|
|
48
49
|
|
|
49
|
-
def get(self,
|
|
50
|
+
def get(self, system: str, system_type: Optional[str] = None, test_environment: bool = False) -> Union[dict, List[dict]]:
|
|
50
51
|
"""
|
|
51
52
|
This method retrieves authentication credentials from BrynQ for a specific interface and system.
|
|
52
53
|
|
|
@@ -59,7 +60,7 @@ class Credentials:
|
|
|
59
60
|
"""
|
|
60
61
|
|
|
61
62
|
# Fetch the config using a separate method
|
|
62
|
-
config = self._fetch_config(
|
|
63
|
+
config = self._fetch_config()
|
|
63
64
|
|
|
64
65
|
matching_credentials = []
|
|
65
66
|
|
|
@@ -128,7 +129,7 @@ class Credentials:
|
|
|
128
129
|
warnings.warn(warning_msg)
|
|
129
130
|
return [cred['credential'] for cred in matching_credentials]
|
|
130
131
|
|
|
131
|
-
def _fetch_config(self
|
|
132
|
+
def _fetch_config(self) -> Dict[str, Any]:
|
|
132
133
|
"""
|
|
133
134
|
Fetch configuration from BrynQ for a given interface ID.
|
|
134
135
|
|
|
@@ -142,8 +143,9 @@ class Credentials:
|
|
|
142
143
|
ValueError: If the response data is invalid.
|
|
143
144
|
requests.exceptions.RequestException: If the API request fails.
|
|
144
145
|
"""
|
|
145
|
-
response = self._brynq.
|
|
146
|
-
url=f'{self._brynq.url}interfaces/{
|
|
146
|
+
response = self._brynq.brynq_session.get(
|
|
147
|
+
url=f'{self._brynq.url}interfaces/{self._brynq.data_interface_id}/config/auth',
|
|
148
|
+
timeout=self._brynq.timeout
|
|
147
149
|
)
|
|
148
150
|
response.raise_for_status()
|
|
149
151
|
|
|
@@ -2,7 +2,7 @@ from typing import List, Dict, Any, Optional
|
|
|
2
2
|
import requests
|
|
3
3
|
from requests import Response
|
|
4
4
|
from .schemas.customers import CustomerSchema, CustomerContractDetailsSchema
|
|
5
|
-
from brynq_sdk_functions
|
|
5
|
+
from brynq_sdk_functions import Functions
|
|
6
6
|
|
|
7
7
|
class Customers:
|
|
8
8
|
"""Class for interacting with BrynQ customer endpoints"""
|
|
@@ -25,8 +25,9 @@ class Customers:
|
|
|
25
25
|
requests.exceptions.RequestException: If the API request fails
|
|
26
26
|
ValueError: If the response data doesn't match the expected schema
|
|
27
27
|
"""
|
|
28
|
-
response = self.brynq.
|
|
29
|
-
f"{self.brynq.url}customers",
|
|
28
|
+
response = self.brynq.brynq_session.get(
|
|
29
|
+
url=f"{self.brynq.url}customers",
|
|
30
|
+
timeout=self.brynq.timeout
|
|
30
31
|
)
|
|
31
32
|
response.raise_for_status()
|
|
32
33
|
|
|
@@ -47,8 +48,9 @@ class Customers:
|
|
|
47
48
|
requests.exceptions.RequestException: If the API request fails
|
|
48
49
|
ValueError: If the response data doesn't match the expected schema
|
|
49
50
|
"""
|
|
50
|
-
response = self.brynq.
|
|
51
|
+
response = self.brynq.brynq_session.get(
|
|
51
52
|
f"{self.brynq.url}customers/contract-details",
|
|
53
|
+
timeout=self.brynq.timeout
|
|
52
54
|
)
|
|
53
55
|
response.raise_for_status()
|
|
54
56
|
|
|
@@ -72,8 +74,9 @@ class Customers:
|
|
|
72
74
|
ValueError: If the response data is invalid.
|
|
73
75
|
requests.exceptions.RequestException: If the API request fails.
|
|
74
76
|
"""
|
|
75
|
-
response = self.brynq.
|
|
77
|
+
response = self.brynq.brynq_session.get(
|
|
76
78
|
f"{self.brynq.url}customers/{customer_id}/contract-details",
|
|
79
|
+
timeout=self.brynq.timeout
|
|
77
80
|
)
|
|
78
81
|
response.raise_for_status()
|
|
79
82
|
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
from typing import Dict, List, Any, Optional
|
|
2
2
|
from .credentials import Credentials
|
|
3
3
|
from .mappings import Mappings
|
|
4
|
+
from .scenarios import Scenarios
|
|
4
5
|
from .schemas.interfaces import Interface, InterfaceDetail, InterfaceConfig, Schedule, Scope, DevSettings
|
|
5
|
-
from brynq_sdk_functions
|
|
6
|
+
from brynq_sdk_functions import Functions
|
|
6
7
|
|
|
7
8
|
class Interfaces:
|
|
8
9
|
"""
|
|
@@ -11,17 +12,18 @@ class Interfaces:
|
|
|
11
12
|
def __init__(self, brynq_instance):
|
|
12
13
|
"""
|
|
13
14
|
Initialize Interfaces manager.
|
|
14
|
-
|
|
15
|
+
|
|
15
16
|
Args:
|
|
16
17
|
brynq_instance: The parent BrynQ instance
|
|
17
18
|
"""
|
|
18
19
|
self._brynq = brynq_instance
|
|
19
20
|
self.credentials = Credentials(brynq_instance)
|
|
20
21
|
self.mappings = Mappings(brynq_instance)
|
|
22
|
+
self.scenarios = Scenarios(brynq_instance)
|
|
21
23
|
|
|
22
|
-
def
|
|
24
|
+
def get_all(self) -> List[Dict[str, Any]]:
|
|
23
25
|
"""Get all interfaces this token has access to.
|
|
24
|
-
|
|
26
|
+
|
|
25
27
|
Returns:
|
|
26
28
|
List[Dict[str, Any]]: List of interfaces with their details including:
|
|
27
29
|
- id (int): Interface ID
|
|
@@ -30,16 +32,17 @@ class Interfaces:
|
|
|
30
32
|
- sourceSystems (List[int]): List of source system IDs
|
|
31
33
|
- targetSystems (List[int]): List of target system IDs
|
|
32
34
|
- taskSchedule (Dict): Task schedule details including status, timing, etc.
|
|
33
|
-
|
|
35
|
+
|
|
34
36
|
Raises:
|
|
35
37
|
ValueError: If the response data is invalid
|
|
36
38
|
requests.exceptions.RequestException: If the API request fails
|
|
37
39
|
"""
|
|
38
|
-
response = self._brynq.
|
|
39
|
-
f"{self._brynq.url}interfaces"
|
|
40
|
+
response = self._brynq.brynq_session.get(
|
|
41
|
+
f"{self._brynq.url}interfaces",
|
|
42
|
+
timeout=self._brynq.timeout
|
|
40
43
|
)
|
|
41
44
|
response.raise_for_status()
|
|
42
|
-
|
|
45
|
+
|
|
43
46
|
try:
|
|
44
47
|
interfaces_data = response.json()
|
|
45
48
|
valid_data, _ = Functions.validate_pydantic_data(interfaces_data, schema=Interface)
|
|
@@ -47,12 +50,8 @@ class Interfaces:
|
|
|
47
50
|
except ValueError as e:
|
|
48
51
|
raise ValueError(f"Invalid interface data received from API: {str(e)}")
|
|
49
52
|
|
|
50
|
-
def
|
|
53
|
+
def get(self) -> Dict[str, Any]:
|
|
51
54
|
"""Get a specific interface by its ID.
|
|
52
|
-
|
|
53
|
-
Args:
|
|
54
|
-
interface_id (int): The ID of the interface to retrieve
|
|
55
|
-
|
|
56
55
|
Returns:
|
|
57
56
|
Dict[str, Any]: Interface details including:
|
|
58
57
|
- name (str): Interface name
|
|
@@ -60,20 +59,19 @@ class Interfaces:
|
|
|
60
59
|
- apps (Dict): Application configuration with:
|
|
61
60
|
- source (str): Source application name
|
|
62
61
|
- target (str): Target application name
|
|
63
|
-
|
|
62
|
+
|
|
64
63
|
Raises:
|
|
65
64
|
ValueError: If interface_id is not a positive integer or if the response data is invalid
|
|
66
65
|
requests.exceptions.RequestException: If the API request fails
|
|
67
66
|
"""
|
|
68
67
|
# Basic validation
|
|
69
|
-
if not isinstance(interface_id, int) or interface_id <= 0:
|
|
70
|
-
raise ValueError("interface_id must be a positive integer")
|
|
71
68
|
|
|
72
|
-
response = self._brynq.
|
|
73
|
-
f"{self._brynq.url}interfaces/{
|
|
69
|
+
response = self._brynq.brynq_session.get(
|
|
70
|
+
f"{self._brynq.url}interfaces/{self._brynq.data_interface_id}",
|
|
71
|
+
timeout=self._brynq.timeout
|
|
74
72
|
)
|
|
75
73
|
response.raise_for_status()
|
|
76
|
-
|
|
74
|
+
|
|
77
75
|
try:
|
|
78
76
|
interface_data = response.json()
|
|
79
77
|
valid_data, _ = Functions.validate_pydantic_data(interface_data, schema=InterfaceDetail)
|
|
@@ -81,30 +79,29 @@ class Interfaces:
|
|
|
81
79
|
except ValueError as e:
|
|
82
80
|
raise ValueError(f"Invalid interface data received from API: {str(e)}")
|
|
83
81
|
|
|
84
|
-
def get_config(self
|
|
82
|
+
def get_config(self) -> Dict[str, Any]:
|
|
85
83
|
"""Get the base configuration of an interface.
|
|
86
|
-
|
|
84
|
+
|
|
87
85
|
Args:
|
|
88
86
|
interface_id (int): The ID of the interface
|
|
89
|
-
|
|
87
|
+
|
|
90
88
|
Returns:
|
|
91
89
|
Dict[str, Any]: Interface configuration including:
|
|
92
90
|
- mapping (List): List of mapping configurations
|
|
93
91
|
- variables (Dict): Configuration variables
|
|
94
|
-
|
|
92
|
+
|
|
95
93
|
Raises:
|
|
96
94
|
ValueError: If interface_id is not a positive integer or if the response data is invalid
|
|
97
95
|
requests.exceptions.RequestException: If the API request fails
|
|
98
96
|
"""
|
|
99
97
|
# Basic validation
|
|
100
|
-
if not isinstance(interface_id, int) or interface_id <= 0:
|
|
101
|
-
raise ValueError("interface_id must be a positive integer")
|
|
102
98
|
|
|
103
|
-
response = self._brynq.
|
|
104
|
-
f"{self._brynq.url}interfaces/{
|
|
99
|
+
response = self._brynq.brynq_session.get(
|
|
100
|
+
f"{self._brynq.url}interfaces/{self._brynq.data_interface_id}/config",
|
|
101
|
+
timeout=self._brynq.timeout
|
|
105
102
|
)
|
|
106
103
|
response.raise_for_status()
|
|
107
|
-
|
|
104
|
+
|
|
108
105
|
try:
|
|
109
106
|
config_data = response.json()
|
|
110
107
|
valid_data, _ = Functions.validate_pydantic_data(config_data, schema=InterfaceConfig)
|
|
@@ -112,50 +109,26 @@ class Interfaces:
|
|
|
112
109
|
except ValueError as e:
|
|
113
110
|
raise ValueError(f"Invalid interface configuration data: {str(e)}")
|
|
114
111
|
|
|
115
|
-
def flush_config(self
|
|
112
|
+
def flush_config(self) -> Dict[str, Any]:
|
|
116
113
|
"""
|
|
117
114
|
Flushes the interface config to revert to a fresh state.
|
|
118
|
-
|
|
119
|
-
Args:
|
|
120
|
-
interface_id: The ID of the interface
|
|
121
|
-
|
|
115
|
+
|
|
122
116
|
Returns:
|
|
123
117
|
Dict[str, Any]: Response from the flush operation
|
|
124
|
-
|
|
125
|
-
Raises:
|
|
126
|
-
requests.exceptions.RequestException: If the API request fails
|
|
127
|
-
"""
|
|
128
|
-
response = self._brynq.session.get(
|
|
129
|
-
url=f'{self._brynq.url}interfaces/{interface_id}/config/flush'
|
|
130
|
-
)
|
|
131
|
-
response.raise_for_status()
|
|
132
|
-
return response.json()
|
|
133
118
|
|
|
134
|
-
def get_dataflows(self, interface_id: int) -> Dict[str, Any]:
|
|
135
|
-
"""
|
|
136
|
-
Get the dataflows configuration of an interface.
|
|
137
|
-
|
|
138
|
-
Args:
|
|
139
|
-
interface_id: The ID of the interface
|
|
140
|
-
|
|
141
|
-
Returns:
|
|
142
|
-
Dict[str, Any]: Dataflows configuration
|
|
143
|
-
|
|
144
119
|
Raises:
|
|
145
120
|
requests.exceptions.RequestException: If the API request fails
|
|
146
121
|
"""
|
|
147
|
-
response = self._brynq.
|
|
148
|
-
url=f'{self._brynq.url}interfaces/{
|
|
122
|
+
response = self._brynq.brynq_session.get(
|
|
123
|
+
url=f'{self._brynq.url}interfaces/{self._brynq.data_interface_id}/config/flush',
|
|
124
|
+
timeout=self._brynq.timeout
|
|
149
125
|
)
|
|
150
126
|
response.raise_for_status()
|
|
151
|
-
return response
|
|
127
|
+
return response
|
|
152
128
|
|
|
153
|
-
def get_schedule(self
|
|
129
|
+
def get_schedule(self) -> Dict[str, Any]:
|
|
154
130
|
"""Get the schedule configuration of an interface.
|
|
155
|
-
|
|
156
|
-
Args:
|
|
157
|
-
interface_id (int): The ID of the interface
|
|
158
|
-
|
|
131
|
+
|
|
159
132
|
Returns:
|
|
160
133
|
Dict[str, Any]: Schedule configuration including:
|
|
161
134
|
- id (int): The schedule ID
|
|
@@ -167,20 +140,17 @@ class Interfaces:
|
|
|
167
140
|
- startAfterPrecedingTask (bool, optional): Whether to start after preceding task
|
|
168
141
|
- lastReload (str): Last reload time
|
|
169
142
|
- lastErrorMessage (str): Last error message
|
|
170
|
-
|
|
143
|
+
|
|
171
144
|
Raises:
|
|
172
145
|
ValueError: If interface_id is not a positive integer or if the response data is invalid
|
|
173
146
|
requests.exceptions.RequestException: If the API request fails
|
|
174
147
|
"""
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
response = self._brynq.session.get(
|
|
180
|
-
f"{self._brynq.url}interfaces/{interface_id}/config/schedule"
|
|
148
|
+
response = self._brynq.brynq_session.get(
|
|
149
|
+
f"{self._brynq.url}interfaces/{self._brynq.data_interface_id}/config/schedule",
|
|
150
|
+
timeout=self._brynq.timeout
|
|
181
151
|
)
|
|
182
152
|
response.raise_for_status()
|
|
183
|
-
|
|
153
|
+
|
|
184
154
|
try:
|
|
185
155
|
schedule_data = response.json()
|
|
186
156
|
valid_data, _ = Functions.validate_pydantic_data(schedule_data, schema=Schedule)
|
|
@@ -188,49 +158,25 @@ class Interfaces:
|
|
|
188
158
|
except ValueError as e:
|
|
189
159
|
raise ValueError(f"Invalid schedule configuration data: {str(e)}")
|
|
190
160
|
|
|
191
|
-
def get_template_config(self, interface_id: int) -> Dict[str, Any]:
|
|
192
|
-
"""
|
|
193
|
-
Get the template configuration of an interface.
|
|
194
|
-
|
|
195
|
-
Args:
|
|
196
|
-
interface_id: The ID of the interface
|
|
197
|
-
|
|
198
|
-
Returns:
|
|
199
|
-
Dict[str, Any]: Template configuration
|
|
200
|
-
|
|
201
|
-
Raises:
|
|
202
|
-
requests.exceptions.RequestException: If the API request fails
|
|
203
|
-
"""
|
|
204
|
-
response = self._brynq.session.get(
|
|
205
|
-
url=f'{self._brynq.url}interfaces/{interface_id}/template-config'
|
|
206
|
-
)
|
|
207
|
-
response.raise_for_status()
|
|
208
|
-
return response.json()
|
|
209
161
|
|
|
210
|
-
def get_scope(self
|
|
162
|
+
def get_scope(self) -> Dict[str, Any]:
|
|
211
163
|
"""Get live and draft scopes from interface by id.
|
|
212
|
-
|
|
213
|
-
Args:
|
|
214
|
-
interface_id (int): The ID of the interface
|
|
215
|
-
|
|
164
|
+
|
|
216
165
|
Returns:
|
|
217
166
|
Dict[str, Any]: Scope configuration including:
|
|
218
167
|
- live (Dict, optional): Live scope configuration
|
|
219
168
|
- draft (Dict, optional): Draft scope configuration
|
|
220
|
-
|
|
169
|
+
|
|
221
170
|
Raises:
|
|
222
171
|
ValueError: If interface_id is not a positive integer or if the response data is invalid
|
|
223
172
|
requests.exceptions.RequestException: If the API request fails
|
|
224
173
|
"""
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
response = self._brynq.session.get(
|
|
230
|
-
f"{self._brynq.url}interfaces/{interface_id}/scope"
|
|
174
|
+
response = self._brynq.brynq_session.get(
|
|
175
|
+
f"{self._brynq.url}interfaces/{self._brynq.data_interface_id}/scope",
|
|
176
|
+
timeout=self._brynq.timeout
|
|
231
177
|
)
|
|
232
178
|
response.raise_for_status()
|
|
233
|
-
|
|
179
|
+
|
|
234
180
|
try:
|
|
235
181
|
scope_data = response.json()
|
|
236
182
|
valid_data, _ = Functions.validate_pydantic_data(scope_data, schema=Scope)
|
|
@@ -238,12 +184,9 @@ class Interfaces:
|
|
|
238
184
|
except ValueError as e:
|
|
239
185
|
raise ValueError(f"Invalid scope data: {str(e)}")
|
|
240
186
|
|
|
241
|
-
def get_dev_settings(self
|
|
187
|
+
def get_dev_settings(self) -> List[dict[str,Any]]:
|
|
242
188
|
"""Get the dev-settings of an interface
|
|
243
189
|
|
|
244
|
-
Args:
|
|
245
|
-
interface_id: Numeric ID of the interface
|
|
246
|
-
|
|
247
190
|
Returns:
|
|
248
191
|
Dict[str, Any]: A dictionary containing the dev settings:
|
|
249
192
|
- dockerImage (str): Docker image name
|
|
@@ -256,13 +199,36 @@ class Interfaces:
|
|
|
256
199
|
requests.exceptions.HTTPError: If dev settings not found (404)
|
|
257
200
|
ValueError: If interface_id is not a positive integer
|
|
258
201
|
"""
|
|
259
|
-
if not isinstance(interface_id, int) or interface_id <= 0:
|
|
260
|
-
raise ValueError("interface_id must be a positive integer")
|
|
261
202
|
|
|
262
|
-
response = self._brynq.
|
|
263
|
-
url=f"{self._brynq.url}interfaces/{
|
|
203
|
+
response = self._brynq.brynq_session.get(
|
|
204
|
+
url=f"{self._brynq.url}interfaces/{self._brynq.data_interface_id}/config/dev-settings",
|
|
205
|
+
timeout=self._brynq.timeout
|
|
264
206
|
)
|
|
265
207
|
response.raise_for_status()
|
|
266
|
-
|
|
208
|
+
|
|
267
209
|
valid_data, _ = Functions.validate_pydantic_data(response.json(), schema=DevSettings)
|
|
268
210
|
return valid_data
|
|
211
|
+
|
|
212
|
+
def get_variables(self, variable_name: str = None):
|
|
213
|
+
"""
|
|
214
|
+
Get a value from the task_variables table corresponding with the given name. If temp value is filled, it will
|
|
215
|
+
(run_instant = 1), then the temp_value will be returned. This is to give the possibility for users in the frontend to run
|
|
216
|
+
a task once manual with other values then normal without overwriting the normal values.
|
|
217
|
+
:param variable_name: the name of the variable
|
|
218
|
+
:return: the value of the given variable.
|
|
219
|
+
"""
|
|
220
|
+
|
|
221
|
+
variables = self.get_config().get("variables")
|
|
222
|
+
|
|
223
|
+
if not variables:
|
|
224
|
+
raise Exception(f"There are no valid variables in interface '{self._brynq.data_interface_id}'")
|
|
225
|
+
|
|
226
|
+
if variable_name:
|
|
227
|
+
variable = variables.get(variable_name)
|
|
228
|
+
if not variable:
|
|
229
|
+
raise Exception(f"The variable '{variable_name}' does not exist in interface '{self._brynq.data_interface_id}'")
|
|
230
|
+
self.flush_config()
|
|
231
|
+
return variable
|
|
232
|
+
else:
|
|
233
|
+
self.flush_config()
|
|
234
|
+
return variables
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import requests
|
|
2
2
|
import pandas as pd
|
|
3
|
-
from typing import Union, Literal, Any, Tuple, List, Dict
|
|
3
|
+
from typing import Optional, Union, Literal, Any, Tuple, List, Dict
|
|
4
4
|
import warnings
|
|
5
|
-
from
|
|
6
|
-
from brynq_sdk_functions
|
|
5
|
+
from .schemas.interfaces import MappingItem
|
|
6
|
+
from brynq_sdk_functions import Functions
|
|
7
7
|
|
|
8
8
|
class MappingNotFoundError(Exception):
|
|
9
9
|
"""Raised when a requested mapping is not found"""
|
|
@@ -22,7 +22,7 @@ class Mappings:
|
|
|
22
22
|
"""
|
|
23
23
|
self._brynq = brynq_instance
|
|
24
24
|
|
|
25
|
-
def _get_mappings(self
|
|
25
|
+
def _get_mappings(self) -> List[Dict[str, Any]]:
|
|
26
26
|
"""Get all mappings for an interface.
|
|
27
27
|
|
|
28
28
|
Args:
|
|
@@ -35,12 +35,9 @@ class Mappings:
|
|
|
35
35
|
ValueError: If interface_id is not a positive integer or if the response data is invalid
|
|
36
36
|
requests.exceptions.RequestException: If the API request fails
|
|
37
37
|
"""
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
response = self._brynq.session.get(
|
|
43
|
-
f"{self._brynq.url}interfaces/{interface_id}/config/mapping"
|
|
38
|
+
response = self._brynq.brynq_session.get(
|
|
39
|
+
f"{self._brynq.url}interfaces/{self._brynq.data_interface_id}/config/mapping",
|
|
40
|
+
timeout=self._brynq.timeout
|
|
44
41
|
)
|
|
45
42
|
response.raise_for_status()
|
|
46
43
|
|
|
@@ -72,7 +69,7 @@ class Mappings:
|
|
|
72
69
|
mappings[input_key] = output_value
|
|
73
70
|
return mappings
|
|
74
71
|
|
|
75
|
-
def get(self,
|
|
72
|
+
def get(self, mapping: Optional[str] = None, as_df: bool = False, prefix: bool = False) -> dict:
|
|
76
73
|
"""Get the mapping from BrynQ.
|
|
77
74
|
|
|
78
75
|
Args:
|
|
@@ -90,13 +87,21 @@ class Mappings:
|
|
|
90
87
|
MappingNotFoundError: If mapping is not found
|
|
91
88
|
ValueError: If mapping data is invalid
|
|
92
89
|
"""
|
|
93
|
-
mappings = self._get_mappings(
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
90
|
+
mappings = self._get_mappings()
|
|
91
|
+
if mapping is None:
|
|
92
|
+
if as_df:
|
|
93
|
+
mapping_data = [{'default_value': item['default_value'], 'mappings': self._to_dataframe(item, prefix)} for item in mappings]
|
|
94
|
+
else:
|
|
95
|
+
mapping_data = [{'default_value': item['default_value'], 'mappings': self._to_dict(item)} for item in mappings]
|
|
96
|
+
|
|
97
|
+
return mapping_data
|
|
98
|
+
else:
|
|
99
|
+
mapping_data = next((item for item in mappings if item['name'] == mapping), None)
|
|
100
|
+
|
|
101
|
+
if not mapping_data:
|
|
102
|
+
raise MappingNotFoundError(f"Mapping named '{mapping}' not found")
|
|
103
|
+
|
|
104
|
+
return {
|
|
105
|
+
'default_value': mapping_data['default_value'],
|
|
106
|
+
'mappings': self._to_dataframe(mapping_data, prefix) if as_df else self._to_dict(mapping_data)
|
|
107
|
+
}
|