das-cli 1.7.4__tar.gz → 1.7.8__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.
- {das_cli-1.7.4/das_cli.egg-info → das_cli-1.7.8}/PKG-INFO +16 -4
- {das_cli-1.7.4 → das_cli-1.7.8}/README.md +15 -3
- {das_cli-1.7.4 → das_cli-1.7.8}/das/cli.py +20 -5
- {das_cli-1.7.4 → das_cli-1.7.8}/das/common/api.py +21 -5
- {das_cli-1.7.4 → das_cli-1.7.8}/das/common/config.py +43 -17
- {das_cli-1.7.4 → das_cli-1.7.8}/das/managers/entries_manager.py +64 -13
- {das_cli-1.7.4 → das_cli-1.7.8}/das/services/attributes.py +9 -1
- {das_cli-1.7.4 → das_cli-1.7.8}/das/services/entry_fields.py +17 -0
- {das_cli-1.7.4 → das_cli-1.7.8/das_cli.egg-info}/PKG-INFO +16 -4
- {das_cli-1.7.4 → das_cli-1.7.8}/pyproject.toml +1 -1
- {das_cli-1.7.4 → das_cli-1.7.8}/LICENSE +0 -0
- {das_cli-1.7.4 → das_cli-1.7.8}/MANIFEST.in +0 -0
- {das_cli-1.7.4 → das_cli-1.7.8}/das/__init__.py +0 -0
- {das_cli-1.7.4 → das_cli-1.7.8}/das/ai/plugins/dasai.py +0 -0
- {das_cli-1.7.4 → das_cli-1.7.8}/das/ai/plugins/entries/entries_plugin.py +0 -0
- {das_cli-1.7.4 → das_cli-1.7.8}/das/app.py +0 -0
- {das_cli-1.7.4 → das_cli-1.7.8}/das/authentication/auth.py +0 -0
- {das_cli-1.7.4 → das_cli-1.7.8}/das/authentication/oauth.py +0 -0
- {das_cli-1.7.4 → das_cli-1.7.8}/das/authentication/secure_input.py +0 -0
- {das_cli-1.7.4 → das_cli-1.7.8}/das/common/entry_fields_constants.py +0 -0
- {das_cli-1.7.4 → das_cli-1.7.8}/das/common/enums.py +0 -0
- {das_cli-1.7.4 → das_cli-1.7.8}/das/common/errors.py +0 -0
- {das_cli-1.7.4 → das_cli-1.7.8}/das/common/exceptions.py +0 -0
- {das_cli-1.7.4 → das_cli-1.7.8}/das/common/file_utils.py +0 -0
- {das_cli-1.7.4 → das_cli-1.7.8}/das/managers/__init__.py +0 -0
- {das_cli-1.7.4 → das_cli-1.7.8}/das/managers/digital_objects_manager.py +0 -0
- {das_cli-1.7.4 → das_cli-1.7.8}/das/managers/download_manager.py +0 -0
- {das_cli-1.7.4 → das_cli-1.7.8}/das/managers/search_manager.py +0 -0
- {das_cli-1.7.4 → das_cli-1.7.8}/das/services/cache.py +0 -0
- {das_cli-1.7.4 → das_cli-1.7.8}/das/services/das_elastic_search.py +0 -0
- {das_cli-1.7.4 → das_cli-1.7.8}/das/services/digital_objects.py +0 -0
- {das_cli-1.7.4 → das_cli-1.7.8}/das/services/downloads.py +0 -0
- {das_cli-1.7.4 → das_cli-1.7.8}/das/services/entries.py +0 -0
- {das_cli-1.7.4 → das_cli-1.7.8}/das/services/hangfire.py +0 -0
- {das_cli-1.7.4 → das_cli-1.7.8}/das/services/search.py +0 -0
- {das_cli-1.7.4 → das_cli-1.7.8}/das/services/service_base.py +0 -0
- {das_cli-1.7.4 → das_cli-1.7.8}/das/services/session.py +0 -0
- {das_cli-1.7.4 → das_cli-1.7.8}/das/services/users.py +0 -0
- {das_cli-1.7.4 → das_cli-1.7.8}/das_cli.egg-info/SOURCES.txt +0 -0
- {das_cli-1.7.4 → das_cli-1.7.8}/das_cli.egg-info/dependency_links.txt +0 -0
- {das_cli-1.7.4 → das_cli-1.7.8}/das_cli.egg-info/entry_points.txt +0 -0
- {das_cli-1.7.4 → das_cli-1.7.8}/das_cli.egg-info/requires.txt +0 -0
- {das_cli-1.7.4 → das_cli-1.7.8}/das_cli.egg-info/top_level.txt +0 -0
- {das_cli-1.7.4 → das_cli-1.7.8}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: das-cli
|
|
3
|
-
Version: 1.7.
|
|
3
|
+
Version: 1.7.8
|
|
4
4
|
Summary: DAS api client.
|
|
5
5
|
Author: Royal Netherlands Institute for Sea Research
|
|
6
6
|
License-Expression: MIT
|
|
@@ -233,8 +233,17 @@ das entry update --id e1987f3e-7db7-11f0-a7e8-0edcca226f3d --data "{ 'Comment':
|
|
|
233
233
|
|
|
234
234
|
# Bulk from file (each item should include Id/Code)
|
|
235
235
|
das entry update c:\data\entries-to-update.json
|
|
236
|
+
|
|
237
|
+
# Recalculate the auto-generated name after changing a field it is built from
|
|
238
|
+
das entry update --code 4.b.rdg --data "{ 'Cast No.': '02' }" --regenerate-name
|
|
239
|
+
das entry update c:\data\events.xlsx --regenerate-name
|
|
236
240
|
```
|
|
237
241
|
|
|
242
|
+
An auto-generated name (an Event is `<station>_<cast><device acronym>`) is **kept as stored** on
|
|
243
|
+
update, even when the update changes the cast number or the device. Pass `--regenerate-name` to have
|
|
244
|
+
the server rebuild it from the updated values. The flag applies to every entry of a bulk update,
|
|
245
|
+
overrides a `Name` given in the data, and is ignored for attributes whose name has no formula.
|
|
246
|
+
|
|
238
247
|
#### Logs and ownership
|
|
239
248
|
```bash
|
|
240
249
|
# Audit logs
|
|
@@ -447,7 +456,7 @@ Import: `from das.managers.entries_manager import EntryManager`
|
|
|
447
456
|
| `get(code=..., id=...)` | `dict` — entry with display field names |
|
|
448
457
|
| `get_entry(entry_id)` | `dict` — same as `get(id=...)` |
|
|
449
458
|
| `create(attribute, entry=..., entries=...)` | `list[dict]` — per-item status with `id`, `code`, `status` |
|
|
450
|
-
| `update(id=..., code=..., entry=..., entries
|
|
459
|
+
| `update(id=..., code=..., entry=..., entries=..., regenerate_name=False)` | `list[dict]` — per-item status |
|
|
451
460
|
| `delete(id=..., code=...)` | `bool` |
|
|
452
461
|
| `create_from_file(attribute, file_path)` | `None` |
|
|
453
462
|
| `chown(user_name, entry_code_list)` | API response |
|
|
@@ -543,6 +552,9 @@ entries.update(entries=[
|
|
|
543
552
|
{"Code": "ENT001", "Comment": "Updated 1"},
|
|
544
553
|
{"Code": "ENT002", "Comment": "Updated 2"},
|
|
545
554
|
])
|
|
555
|
+
|
|
556
|
+
# Rebuild the auto-generated name from the updated values (kept as stored by default)
|
|
557
|
+
entries.update(code="4.b.rdg", entry={"Cast No.": "02"}, regenerate_name=True)
|
|
546
558
|
```
|
|
547
559
|
|
|
548
560
|
#### `delete` — delete one entry
|
|
@@ -922,7 +934,7 @@ You can configure values through CLI commands and/or `.env`.
|
|
|
922
934
|
|
|
923
935
|
```env
|
|
924
936
|
# Connection
|
|
925
|
-
DAS_API_URL=https://
|
|
937
|
+
DAS_API_URL=https://your-das-instance/api
|
|
926
938
|
DAS_API_KEY=
|
|
927
939
|
VERIFY_SSL=True
|
|
928
940
|
|
|
@@ -931,7 +943,7 @@ DAS_LOG_LEVEL=WARN
|
|
|
931
943
|
DAS_LOG_FILE=
|
|
932
944
|
|
|
933
945
|
# Test credentials (for integration tests)
|
|
934
|
-
API_URL=https://
|
|
946
|
+
API_URL=https://your-das-instance/api
|
|
935
947
|
USER_NAME=
|
|
936
948
|
USER_PASSWORD=
|
|
937
949
|
|
|
@@ -210,8 +210,17 @@ das entry update --id e1987f3e-7db7-11f0-a7e8-0edcca226f3d --data "{ 'Comment':
|
|
|
210
210
|
|
|
211
211
|
# Bulk from file (each item should include Id/Code)
|
|
212
212
|
das entry update c:\data\entries-to-update.json
|
|
213
|
+
|
|
214
|
+
# Recalculate the auto-generated name after changing a field it is built from
|
|
215
|
+
das entry update --code 4.b.rdg --data "{ 'Cast No.': '02' }" --regenerate-name
|
|
216
|
+
das entry update c:\data\events.xlsx --regenerate-name
|
|
213
217
|
```
|
|
214
218
|
|
|
219
|
+
An auto-generated name (an Event is `<station>_<cast><device acronym>`) is **kept as stored** on
|
|
220
|
+
update, even when the update changes the cast number or the device. Pass `--regenerate-name` to have
|
|
221
|
+
the server rebuild it from the updated values. The flag applies to every entry of a bulk update,
|
|
222
|
+
overrides a `Name` given in the data, and is ignored for attributes whose name has no formula.
|
|
223
|
+
|
|
215
224
|
#### Logs and ownership
|
|
216
225
|
```bash
|
|
217
226
|
# Audit logs
|
|
@@ -424,7 +433,7 @@ Import: `from das.managers.entries_manager import EntryManager`
|
|
|
424
433
|
| `get(code=..., id=...)` | `dict` — entry with display field names |
|
|
425
434
|
| `get_entry(entry_id)` | `dict` — same as `get(id=...)` |
|
|
426
435
|
| `create(attribute, entry=..., entries=...)` | `list[dict]` — per-item status with `id`, `code`, `status` |
|
|
427
|
-
| `update(id=..., code=..., entry=..., entries
|
|
436
|
+
| `update(id=..., code=..., entry=..., entries=..., regenerate_name=False)` | `list[dict]` — per-item status |
|
|
428
437
|
| `delete(id=..., code=...)` | `bool` |
|
|
429
438
|
| `create_from_file(attribute, file_path)` | `None` |
|
|
430
439
|
| `chown(user_name, entry_code_list)` | API response |
|
|
@@ -520,6 +529,9 @@ entries.update(entries=[
|
|
|
520
529
|
{"Code": "ENT001", "Comment": "Updated 1"},
|
|
521
530
|
{"Code": "ENT002", "Comment": "Updated 2"},
|
|
522
531
|
])
|
|
532
|
+
|
|
533
|
+
# Rebuild the auto-generated name from the updated values (kept as stored by default)
|
|
534
|
+
entries.update(code="4.b.rdg", entry={"Cast No.": "02"}, regenerate_name=True)
|
|
523
535
|
```
|
|
524
536
|
|
|
525
537
|
#### `delete` — delete one entry
|
|
@@ -899,7 +911,7 @@ You can configure values through CLI commands and/or `.env`.
|
|
|
899
911
|
|
|
900
912
|
```env
|
|
901
913
|
# Connection
|
|
902
|
-
DAS_API_URL=https://
|
|
914
|
+
DAS_API_URL=https://your-das-instance/api
|
|
903
915
|
DAS_API_KEY=
|
|
904
916
|
VERIFY_SSL=True
|
|
905
917
|
|
|
@@ -908,7 +920,7 @@ DAS_LOG_LEVEL=WARN
|
|
|
908
920
|
DAS_LOG_FILE=
|
|
909
921
|
|
|
910
922
|
# Test credentials (for integration tests)
|
|
911
|
-
API_URL=https://
|
|
923
|
+
API_URL=https://your-das-instance/api
|
|
912
924
|
USER_NAME=
|
|
913
925
|
USER_PASSWORD=
|
|
914
926
|
|
|
@@ -687,14 +687,21 @@ def entry():
|
|
|
687
687
|
@click.option('--code', default=None, help='Entry code to update (only used with --data for single entry)')
|
|
688
688
|
@click.argument('file_path', required=False)
|
|
689
689
|
@click.option('--data', help='Data string in format { "key1": "value1", "key2": "value2", ... } or a list of such objects')
|
|
690
|
+
@click.option('--regenerate-name', is_flag=True, default=False,
|
|
691
|
+
help='Rebuild the auto-generated name from the updated values instead of keeping the stored one. '
|
|
692
|
+
'Applies to every entry of a bulk update; ignored for attributes whose name has no formula.')
|
|
690
693
|
@pass_das_context
|
|
691
|
-
def update_entry(das_ctx, id, code, file_path, data):
|
|
694
|
+
def update_entry(das_ctx, id, code, file_path, data, regenerate_name):
|
|
692
695
|
"""Update entries from file or data string by ID or code.
|
|
693
|
-
|
|
696
|
+
|
|
694
697
|
For single updates, provide either --id or --code (or Id/Code in the data).
|
|
695
698
|
For bulk updates, each entry must contain a Code or Id field.
|
|
696
699
|
Files can contain multiple entries (rows in CSV/XLS or list of objects in JSON).
|
|
697
|
-
|
|
700
|
+
|
|
701
|
+
An auto-generated name (e.g. an Event's station_cast+device) is kept as it
|
|
702
|
+
is unless --regenerate-name is given, even when the update changes one of
|
|
703
|
+
the fields it is built from.
|
|
704
|
+
|
|
698
705
|
Examples:
|
|
699
706
|
|
|
700
707
|
\b
|
|
@@ -716,6 +723,14 @@ def update_entry(das_ctx, id, code, file_path, data):
|
|
|
716
723
|
\b
|
|
717
724
|
# Update multiple entries from data string
|
|
718
725
|
das entry update --data "[{ 'Code': 'ENT001', ... }, { 'Code': 'ENT002', ... }]"
|
|
726
|
+
|
|
727
|
+
\b
|
|
728
|
+
# Change the cast number and have the name recalculated
|
|
729
|
+
das entry update --code 4.b.rdg --data "{ 'Cast No.': '02' }" --regenerate-name
|
|
730
|
+
|
|
731
|
+
\b
|
|
732
|
+
# Recalculate the names of every entry in a file
|
|
733
|
+
das entry update c:\\data\\events.xlsx --regenerate-name
|
|
719
734
|
"""
|
|
720
735
|
try:
|
|
721
736
|
# Ensure client and entry_manager are initialized
|
|
@@ -770,7 +785,7 @@ def update_entry(das_ctx, id, code, file_path, data):
|
|
|
770
785
|
|
|
771
786
|
# Update the entries
|
|
772
787
|
if is_bulk_update:
|
|
773
|
-
results = das_ctx.entry_manager.update(entries=entry_data)
|
|
788
|
+
results = das_ctx.entry_manager.update(entries=entry_data, regenerate_name=regenerate_name)
|
|
774
789
|
|
|
775
790
|
# Display results
|
|
776
791
|
success_count = sum(1 for result in results if result.get('status') == 'success')
|
|
@@ -790,7 +805,7 @@ def update_entry(das_ctx, id, code, file_path, data):
|
|
|
790
805
|
click.echo(f" {ident}: {result.get('error', 'Unknown error')}")
|
|
791
806
|
else:
|
|
792
807
|
# Single entry update
|
|
793
|
-
results = das_ctx.entry_manager.update(id=id, code=code, entry=entry_data)
|
|
808
|
+
results = das_ctx.entry_manager.update(id=id, code=code, entry=entry_data, regenerate_name=regenerate_name)
|
|
794
809
|
|
|
795
810
|
if results and results[0].get('status') == 'success':
|
|
796
811
|
identifier = id or code
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import json
|
|
2
2
|
import logging
|
|
3
|
+
import threading
|
|
3
4
|
import requests
|
|
4
5
|
from das.common.config import load_verify_ssl
|
|
5
6
|
from das.common.errors import describe_request_exception
|
|
@@ -10,6 +11,21 @@ logger = logging.getLogger("das")
|
|
|
10
11
|
# hanging indefinitely on an unreachable host.
|
|
11
12
|
DEFAULT_TIMEOUT = (10, 60)
|
|
12
13
|
|
|
14
|
+
# One ``requests.Session`` per thread. A session keeps the TCP/TLS connection
|
|
15
|
+
# to the API alive between calls (HTTP keep-alive); without it every request
|
|
16
|
+
# pays a fresh DNS lookup, TCP connect and TLS handshake, which dominates the
|
|
17
|
+
# cost of the many small calls an entry import makes. ``requests.Session`` is
|
|
18
|
+
# not guaranteed thread-safe, hence thread-local.
|
|
19
|
+
_local = threading.local()
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def _get_session() -> requests.Session:
|
|
23
|
+
session = getattr(_local, "session", None)
|
|
24
|
+
if session is None:
|
|
25
|
+
session = requests.Session()
|
|
26
|
+
_local.session = session
|
|
27
|
+
return session
|
|
28
|
+
|
|
13
29
|
|
|
14
30
|
def _process_response(response, action: str):
|
|
15
31
|
"""Turn a ``requests.Response`` into a parsed dict or a structured error dict.
|
|
@@ -85,7 +101,7 @@ def get_data(url, headers=None, params=None):
|
|
|
85
101
|
"""
|
|
86
102
|
logger.debug("GET %s", url)
|
|
87
103
|
try:
|
|
88
|
-
response =
|
|
104
|
+
response = _get_session().get(
|
|
89
105
|
url, headers=headers, params=params,
|
|
90
106
|
verify=load_verify_ssl(), timeout=DEFAULT_TIMEOUT,
|
|
91
107
|
)
|
|
@@ -104,7 +120,7 @@ def get_binary_response(url, headers=None, params=None, stream=True):
|
|
|
104
120
|
"""
|
|
105
121
|
logger.debug("GET (binary) %s", url)
|
|
106
122
|
try:
|
|
107
|
-
response =
|
|
123
|
+
response = _get_session().get(
|
|
108
124
|
url,
|
|
109
125
|
headers=headers,
|
|
110
126
|
params=params,
|
|
@@ -133,7 +149,7 @@ def post_data(url, headers=None, data=None):
|
|
|
133
149
|
"""
|
|
134
150
|
logger.debug("POST %s", url)
|
|
135
151
|
try:
|
|
136
|
-
response =
|
|
152
|
+
response = _get_session().post(
|
|
137
153
|
url, headers=headers, json=data,
|
|
138
154
|
verify=load_verify_ssl(), timeout=DEFAULT_TIMEOUT,
|
|
139
155
|
)
|
|
@@ -157,7 +173,7 @@ def put_data(url, headers=None, data=None):
|
|
|
157
173
|
"""
|
|
158
174
|
logger.debug("PUT %s", url)
|
|
159
175
|
try:
|
|
160
|
-
response =
|
|
176
|
+
response = _get_session().put(
|
|
161
177
|
url, headers=headers, json=data,
|
|
162
178
|
verify=load_verify_ssl(), timeout=DEFAULT_TIMEOUT,
|
|
163
179
|
)
|
|
@@ -181,7 +197,7 @@ def delete_data(url, headers=None, data=None):
|
|
|
181
197
|
"""
|
|
182
198
|
logger.debug("DELETE %s", url)
|
|
183
199
|
try:
|
|
184
|
-
response =
|
|
200
|
+
response = _get_session().delete(
|
|
185
201
|
url, headers=headers, json=data,
|
|
186
202
|
verify=load_verify_ssl(), timeout=DEFAULT_TIMEOUT,
|
|
187
203
|
)
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import copy
|
|
1
2
|
import json
|
|
2
3
|
import os
|
|
3
4
|
import time
|
|
@@ -48,6 +49,7 @@ logging.basicConfig(
|
|
|
48
49
|
SERVICE_NAME = "Data-Archive-System"
|
|
49
50
|
DEFAULT_BASE_URL = "https://localhost:44301" # ← change to your API
|
|
50
51
|
VERIFY_SSL = True # Default is True for secure connections
|
|
52
|
+
_ssl_warning_shown = False
|
|
51
53
|
TOKEN_FIELD = "accessToken"
|
|
52
54
|
# Environment variable (usually set in .env) holding a DAS API key. It takes
|
|
53
55
|
# precedence over any credential saved by 'das login'.
|
|
@@ -64,6 +66,22 @@ def _config_dir() -> Path:
|
|
|
64
66
|
|
|
65
67
|
CONFIG_FILE = _config_dir() / "config.json"
|
|
66
68
|
|
|
69
|
+
# Parsed config.json, keyed on the file's path and stat signature. Settings
|
|
70
|
+
# such as verify_ssl and auth_type are consulted on every API request, so
|
|
71
|
+
# re-reading and re-parsing the file each time is wasted work. Any write
|
|
72
|
+
# changes the mtime/size, which invalidates the cache.
|
|
73
|
+
_config_cache = {"key": None, "data": None}
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def _read_config() -> dict:
|
|
77
|
+
"""Return a fresh copy of the parsed config file (raises like json.loads)."""
|
|
78
|
+
stat = CONFIG_FILE.stat()
|
|
79
|
+
key = (str(CONFIG_FILE), stat.st_mtime_ns, stat.st_size)
|
|
80
|
+
if _config_cache["key"] != key:
|
|
81
|
+
data = json.loads(CONFIG_FILE.read_text(encoding="utf-8"))
|
|
82
|
+
_config_cache["key"], _config_cache["data"] = key, data
|
|
83
|
+
return copy.deepcopy(_config_cache["data"])
|
|
84
|
+
|
|
67
85
|
def normalize_api_url(api_url: Optional[str]) -> Optional[str]:
|
|
68
86
|
"""Strip whitespace and trailing slashes. Services append "/api/...", and a
|
|
69
87
|
"//api/..." URL makes the backend answer HTTP 200 with a non-JSON body."""
|
|
@@ -75,7 +93,7 @@ def save_api_url(api_url: str) -> None:
|
|
|
75
93
|
config = {}
|
|
76
94
|
if CONFIG_FILE.exists():
|
|
77
95
|
try:
|
|
78
|
-
config =
|
|
96
|
+
config = _read_config()
|
|
79
97
|
except Exception:
|
|
80
98
|
config = {}
|
|
81
99
|
config["api_url"] = normalize_api_url(api_url)
|
|
@@ -87,7 +105,7 @@ def load_api_url() -> Optional[str]:
|
|
|
87
105
|
return env_url
|
|
88
106
|
if CONFIG_FILE.exists():
|
|
89
107
|
try:
|
|
90
|
-
return normalize_api_url(
|
|
108
|
+
return normalize_api_url(_read_config().get("api_url"))
|
|
91
109
|
except Exception:
|
|
92
110
|
return None
|
|
93
111
|
return None
|
|
@@ -103,7 +121,7 @@ def save_verify_ssl(verify: bool) -> None:
|
|
|
103
121
|
config = {}
|
|
104
122
|
if CONFIG_FILE.exists():
|
|
105
123
|
try:
|
|
106
|
-
config =
|
|
124
|
+
config = _read_config()
|
|
107
125
|
except Exception:
|
|
108
126
|
config = {}
|
|
109
127
|
config["verify_ssl"] = verify
|
|
@@ -112,6 +130,14 @@ def save_verify_ssl(verify: bool) -> None:
|
|
|
112
130
|
VERIFY_SSL = verify
|
|
113
131
|
CONFIG_FILE.write_text(json.dumps(config), encoding="utf-8")
|
|
114
132
|
|
|
133
|
+
def _warn_ssl_disabled() -> None:
|
|
134
|
+
"""Tell the user once per process (not once per request) that SSL is off."""
|
|
135
|
+
global _ssl_warning_shown
|
|
136
|
+
if not _ssl_warning_shown:
|
|
137
|
+
_ssl_warning_shown = True
|
|
138
|
+
print("SSL certificate verification is disabled")
|
|
139
|
+
|
|
140
|
+
|
|
115
141
|
def load_verify_ssl() -> bool:
|
|
116
142
|
"""
|
|
117
143
|
Load the VERIFY_SSL setting from the config file.
|
|
@@ -122,27 +148,27 @@ def load_verify_ssl() -> bool:
|
|
|
122
148
|
global VERIFY_SSL
|
|
123
149
|
if CONFIG_FILE.exists():
|
|
124
150
|
try:
|
|
125
|
-
config =
|
|
151
|
+
config = _read_config()
|
|
126
152
|
|
|
127
153
|
verify = config.get("verify_ssl")
|
|
128
154
|
verify_explicit = config.get("verify_ssl_explicit", False)
|
|
129
155
|
if verify is not None and verify_explicit:
|
|
130
156
|
VERIFY_SSL = verify
|
|
131
157
|
if not VERIFY_SSL:
|
|
132
|
-
|
|
158
|
+
_warn_ssl_disabled()
|
|
133
159
|
return verify
|
|
134
160
|
|
|
135
161
|
env_verify_ssl = os.getenv("VERIFY_SSL")
|
|
136
162
|
if env_verify_ssl is not None:
|
|
137
163
|
VERIFY_SSL = env_verify_ssl.strip().lower() == "true"
|
|
138
164
|
if not VERIFY_SSL:
|
|
139
|
-
|
|
165
|
+
_warn_ssl_disabled()
|
|
140
166
|
return VERIFY_SSL
|
|
141
167
|
|
|
142
168
|
if verify is not None:
|
|
143
169
|
VERIFY_SSL = verify
|
|
144
170
|
if not VERIFY_SSL:
|
|
145
|
-
|
|
171
|
+
_warn_ssl_disabled()
|
|
146
172
|
return verify
|
|
147
173
|
|
|
148
174
|
raise ValueError("SSL certificate verification is not set")
|
|
@@ -160,7 +186,7 @@ def save_log_level(level) -> None:
|
|
|
160
186
|
config = {}
|
|
161
187
|
if CONFIG_FILE.exists():
|
|
162
188
|
try:
|
|
163
|
-
config =
|
|
189
|
+
config = _read_config()
|
|
164
190
|
except Exception:
|
|
165
191
|
config = {}
|
|
166
192
|
config["log_level"] = level.name
|
|
@@ -204,7 +230,7 @@ def load_log_level() -> LogLevel:
|
|
|
204
230
|
pass
|
|
205
231
|
if CONFIG_FILE.exists():
|
|
206
232
|
try:
|
|
207
|
-
stored =
|
|
233
|
+
stored = _read_config().get("log_level")
|
|
208
234
|
if stored:
|
|
209
235
|
return parse_log_level(stored)
|
|
210
236
|
except Exception:
|
|
@@ -221,7 +247,7 @@ def save_log_file(path) -> None:
|
|
|
221
247
|
config = {}
|
|
222
248
|
if CONFIG_FILE.exists():
|
|
223
249
|
try:
|
|
224
|
-
config =
|
|
250
|
+
config = _read_config()
|
|
225
251
|
except Exception:
|
|
226
252
|
config = {}
|
|
227
253
|
if path:
|
|
@@ -238,7 +264,7 @@ def load_log_file() -> Optional[str]:
|
|
|
238
264
|
return env_path
|
|
239
265
|
if CONFIG_FILE.exists():
|
|
240
266
|
try:
|
|
241
|
-
return
|
|
267
|
+
return _read_config().get("log_file")
|
|
242
268
|
except Exception:
|
|
243
269
|
return None
|
|
244
270
|
return None
|
|
@@ -504,7 +530,7 @@ def save_oauth_config(client_id: str, authority: str, scope: str) -> None:
|
|
|
504
530
|
config = {}
|
|
505
531
|
if CONFIG_FILE.exists():
|
|
506
532
|
try:
|
|
507
|
-
config =
|
|
533
|
+
config = _read_config()
|
|
508
534
|
except Exception:
|
|
509
535
|
config = {}
|
|
510
536
|
config.setdefault("oauth", {})
|
|
@@ -518,7 +544,7 @@ def load_oauth_config() -> dict:
|
|
|
518
544
|
"""Return the stored OAuth config dict (may be empty if not configured)."""
|
|
519
545
|
if CONFIG_FILE.exists():
|
|
520
546
|
try:
|
|
521
|
-
return
|
|
547
|
+
return _read_config().get("oauth", {})
|
|
522
548
|
except Exception:
|
|
523
549
|
pass
|
|
524
550
|
return {}
|
|
@@ -530,7 +556,7 @@ def get_auth_type() -> str:
|
|
|
530
556
|
return "api_key"
|
|
531
557
|
if CONFIG_FILE.exists():
|
|
532
558
|
try:
|
|
533
|
-
return
|
|
559
|
+
return _read_config().get("auth_type", "basic")
|
|
534
560
|
except Exception:
|
|
535
561
|
pass
|
|
536
562
|
return "basic"
|
|
@@ -541,7 +567,7 @@ def set_auth_type(auth_type: str) -> None:
|
|
|
541
567
|
config = {}
|
|
542
568
|
if CONFIG_FILE.exists():
|
|
543
569
|
try:
|
|
544
|
-
config =
|
|
570
|
+
config = _read_config()
|
|
545
571
|
except Exception:
|
|
546
572
|
config = {}
|
|
547
573
|
config["auth_type"] = auth_type
|
|
@@ -553,7 +579,7 @@ def save_token_expiry(expires_at: float) -> None:
|
|
|
553
579
|
config = {}
|
|
554
580
|
if CONFIG_FILE.exists():
|
|
555
581
|
try:
|
|
556
|
-
config =
|
|
582
|
+
config = _read_config()
|
|
557
583
|
except Exception:
|
|
558
584
|
config = {}
|
|
559
585
|
config.setdefault("oauth", {})
|
|
@@ -565,7 +591,7 @@ def load_token_expiry() -> Optional[float]:
|
|
|
565
591
|
"""Return the stored token expiry timestamp, or None."""
|
|
566
592
|
if CONFIG_FILE.exists():
|
|
567
593
|
try:
|
|
568
|
-
cfg =
|
|
594
|
+
cfg = _read_config()
|
|
569
595
|
return cfg.get("oauth", {}).get("token_expires_at")
|
|
570
596
|
except Exception:
|
|
571
597
|
pass
|
|
@@ -49,6 +49,26 @@ def _safe_lower(value) -> str:
|
|
|
49
49
|
return str(value).lower()
|
|
50
50
|
|
|
51
51
|
|
|
52
|
+
def _is_generated_field(field: dict) -> bool:
|
|
53
|
+
"""Return True when the field's value is built by the server from a formula.
|
|
54
|
+
|
|
55
|
+
Such a field (typically ``Name``) declares ``generatedFrom`` in its custom
|
|
56
|
+
data, e.g. ``{"generatedFrom": ["x24", "castnumber|_{0:00}", {"x28": "acronym"}]}``.
|
|
57
|
+
"""
|
|
58
|
+
custom_data = field.get("customData") or field.get("customdata")
|
|
59
|
+
|
|
60
|
+
if _is_empty(custom_data):
|
|
61
|
+
return False
|
|
62
|
+
|
|
63
|
+
if isinstance(custom_data, str):
|
|
64
|
+
try:
|
|
65
|
+
custom_data = json.loads(custom_data)
|
|
66
|
+
except ValueError: # includes json.JSONDecodeError
|
|
67
|
+
return False
|
|
68
|
+
|
|
69
|
+
return isinstance(custom_data, dict) and custom_data.get("generatedFrom") is not None
|
|
70
|
+
|
|
71
|
+
|
|
52
72
|
# The single key digital objects are published under, whatever the attribute
|
|
53
73
|
# calls its digital-object field (Persons calls it "Files").
|
|
54
74
|
DIGITAL_OBJECTS_KEY = "Digital Object(s)"
|
|
@@ -111,6 +131,11 @@ class EntryManager:
|
|
|
111
131
|
self.attribute_service = AttributesService(base_url)
|
|
112
132
|
self.user_service = UsersService(base_url)
|
|
113
133
|
self.das_elastic_search = DasElasticSearch(base_url)
|
|
134
|
+
# Resolved select/lookup values: (attribute_id, query, max) -> JSON
|
|
135
|
+
# string. Bulk imports reference the same Cruise/Device/etc. on every
|
|
136
|
+
# row; resolve each one once per manager. Only hits are cached, so a
|
|
137
|
+
# value that does not exist yet is looked up again next time.
|
|
138
|
+
self._select_value_cache = {}
|
|
114
139
|
|
|
115
140
|
def delete(self, id: str = None, code: str = None) -> bool:
|
|
116
141
|
"""Delete an entry by its id or code."""
|
|
@@ -313,19 +338,24 @@ class EntryManager:
|
|
|
313
338
|
|
|
314
339
|
return self.entry_service.create(attribute_id=attribute_id, entry=new_entry)
|
|
315
340
|
|
|
316
|
-
def update(self, id: str = None, code: str = None, entry: dict = None, entries: list = None) -> list:
|
|
341
|
+
def update(self, id: str = None, code: str = None, entry: dict = None, entries: list = None, regenerate_name: bool = False) -> list:
|
|
317
342
|
"""
|
|
318
343
|
Update one or more existing entries.
|
|
319
|
-
|
|
344
|
+
|
|
320
345
|
If 'code' and 'entry' are provided, updates a single entry.
|
|
321
346
|
If 'entries' is provided, updates multiple entries based on the code in each entry.
|
|
322
|
-
|
|
347
|
+
|
|
323
348
|
Args:
|
|
324
349
|
id (str, optional): The entry ID for single entry update
|
|
325
350
|
code (str, optional): The entry code for single entry update
|
|
326
351
|
entry (dict, optional): The entry data for single entry update
|
|
327
352
|
entries (list, optional): List of entry data for multiple updates
|
|
328
|
-
|
|
353
|
+
regenerate_name (bool, optional): Have the server rebuild the
|
|
354
|
+
auto-generated name (and any other field with a
|
|
355
|
+
``generatedFrom`` formula) from the updated values. Off by
|
|
356
|
+
default: the stored name is kept. It overrides a name given in
|
|
357
|
+
the data and does nothing for attributes without a formula.
|
|
358
|
+
|
|
329
359
|
Returns:
|
|
330
360
|
list: List of updated entry IDs
|
|
331
361
|
|
|
@@ -354,22 +384,27 @@ class EntryManager:
|
|
|
354
384
|
entry_data['id'] = id
|
|
355
385
|
|
|
356
386
|
try:
|
|
357
|
-
result = self._update_single_entry(
|
|
387
|
+
result = self._update_single_entry(
|
|
388
|
+
id=entry_id or id,
|
|
389
|
+
code=entry_code or code,
|
|
390
|
+
entry=entry_data,
|
|
391
|
+
regenerate_name=regenerate_name,
|
|
392
|
+
)
|
|
358
393
|
results.append({"code": entry_code, "id": result, "status": "success"})
|
|
359
394
|
except Exception as e:
|
|
360
395
|
results.append({"code": entry_code, "error": str(e), "status": "error"})
|
|
361
|
-
|
|
396
|
+
|
|
362
397
|
return results
|
|
363
|
-
|
|
398
|
+
|
|
364
399
|
elif (code or id) and entry:
|
|
365
400
|
# Single entry update
|
|
366
|
-
result = self._update_single_entry(id=id, code=code, entry=entry)
|
|
401
|
+
result = self._update_single_entry(id=id, code=code, entry=entry, regenerate_name=regenerate_name)
|
|
367
402
|
return [{"code": code, "id": result, "status": "success"}]
|
|
368
|
-
|
|
403
|
+
|
|
369
404
|
else:
|
|
370
405
|
raise ValueError("Either 'id', 'code' and 'entry' or 'entries' must be provided")
|
|
371
|
-
|
|
372
|
-
def _update_single_entry(self, id: str = None, code: str = None, entry: dict = None) -> str:
|
|
406
|
+
|
|
407
|
+
def _update_single_entry(self, id: str = None, code: str = None, entry: dict = None, regenerate_name: bool = False) -> str:
|
|
373
408
|
"""Internal method to update a single entry."""
|
|
374
409
|
if not id and not code:
|
|
375
410
|
raise ValueError("Entry ID or code is required")
|
|
@@ -421,7 +456,17 @@ class EntryManager:
|
|
|
421
456
|
elif column_name in entry:
|
|
422
457
|
updated_entry[column_name] = self.__get_value(field, entry[column_name])
|
|
423
458
|
|
|
424
|
-
|
|
459
|
+
if regenerate_name:
|
|
460
|
+
# The server only rebuilds an auto-generated value when it arrives
|
|
461
|
+
# empty; otherwise the stored one is kept, even when the fields it
|
|
462
|
+
# is built from have changed. Fields without a formula are left
|
|
463
|
+
# alone, so the flag cannot blank a name that is typed by hand.
|
|
464
|
+
for field in fields:
|
|
465
|
+
column_name = _safe_lower(field.get("column"))
|
|
466
|
+
if column_name and _is_generated_field(field):
|
|
467
|
+
updated_entry[column_name] = None
|
|
468
|
+
|
|
469
|
+
return self.entry_service.update(attribute_id=attribute_id, entry=updated_entry)
|
|
425
470
|
|
|
426
471
|
|
|
427
472
|
def __set_group_box_field_value(self, current_entry: dict, field, entry: dict) -> dict:
|
|
@@ -608,6 +653,10 @@ class EntryManager:
|
|
|
608
653
|
"skipCount": 0
|
|
609
654
|
}
|
|
610
655
|
|
|
656
|
+
cache_key = (attribute_id, search_params["queryString"], expected_max_result_count)
|
|
657
|
+
if cache_key in self._select_value_cache:
|
|
658
|
+
return self._select_value_cache[cache_key]
|
|
659
|
+
|
|
611
660
|
search_response = self.search_service.search_entries(**search_params)
|
|
612
661
|
|
|
613
662
|
if search_response.get('totalCount', 0) == 0:
|
|
@@ -624,7 +673,9 @@ class EntryManager:
|
|
|
624
673
|
result['attributeid'] = attribute_id
|
|
625
674
|
result = {k: v for k, v in result.items() if v is not None}
|
|
626
675
|
result_list.append(result)
|
|
627
|
-
|
|
676
|
+
value = json.dumps(result_list)
|
|
677
|
+
self._select_value_cache[cache_key] = value
|
|
678
|
+
return value
|
|
628
679
|
else:
|
|
629
680
|
return source
|
|
630
681
|
|
|
@@ -7,6 +7,9 @@ class AttributesService(ServiceBase):
|
|
|
7
7
|
|
|
8
8
|
def __init__(self, base_url):
|
|
9
9
|
self.base_url = f"{base_url}/api/services/app/Attribute"
|
|
10
|
+
# name -> id. Attribute ids never change, and importers resolve the
|
|
11
|
+
# same attribute name for every row they create.
|
|
12
|
+
self._id_cache = {}
|
|
10
13
|
|
|
11
14
|
def get_attribute(self, id: int = None, name: str = None, alias: str = None, table_name: str = None):
|
|
12
15
|
if (id is None and name is None and alias is None and table_name is None):
|
|
@@ -45,11 +48,16 @@ class AttributesService(ServiceBase):
|
|
|
45
48
|
if (name is None):
|
|
46
49
|
raise ValueError("Name parameter must be provided")
|
|
47
50
|
|
|
51
|
+
if name in self._id_cache:
|
|
52
|
+
return self._id_cache[name]
|
|
53
|
+
|
|
48
54
|
url = f"{self.base_url}/GetAll?name={name}"
|
|
49
55
|
|
|
50
56
|
response = get_data(url, headers=self.set_auth_headers())
|
|
51
57
|
|
|
52
58
|
if response.get('success') == True:
|
|
53
|
-
|
|
59
|
+
attribute_id = response.get('result').get('items')[0].get('id')
|
|
60
|
+
self._id_cache[name] = attribute_id
|
|
61
|
+
return attribute_id
|
|
54
62
|
else:
|
|
55
63
|
raise ValueError(extract_api_error(response))
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import copy
|
|
2
|
+
|
|
1
3
|
from das.common.api import get_data
|
|
2
4
|
from das.common.errors import extract_api_error
|
|
3
5
|
from das.services.service_base import ServiceBase
|
|
@@ -6,16 +8,31 @@ from das.services.service_base import ServiceBase
|
|
|
6
8
|
class EntryFieldsService(ServiceBase):
|
|
7
9
|
def __init__(self, base_url):
|
|
8
10
|
self.base_url = f"{base_url}/api/services/app/EntryField"
|
|
11
|
+
# (attribute_id, display_type) -> successful response. Field
|
|
12
|
+
# definitions are schema, not data: every get/create/update of an
|
|
13
|
+
# entry needs them, and they are identical for every entry of the
|
|
14
|
+
# attribute. Lives as long as this service instance; call
|
|
15
|
+
# clear_cache() if the schema changes while it is in use.
|
|
16
|
+
self._cache = {}
|
|
17
|
+
|
|
18
|
+
def clear_cache(self):
|
|
19
|
+
self._cache.clear()
|
|
9
20
|
|
|
10
21
|
def get_entry_fields(self, attribute_id: int, display_type: int = 2):
|
|
11
22
|
if (attribute_id is None):
|
|
12
23
|
raise ValueError("Attribute ID parameter must be provided")
|
|
13
24
|
|
|
25
|
+
key = (str(attribute_id), display_type)
|
|
26
|
+
if key in self._cache:
|
|
27
|
+
# Callers may modify the result; hand out a copy.
|
|
28
|
+
return copy.deepcopy(self._cache[key])
|
|
29
|
+
|
|
14
30
|
url = f"{self.base_url}/GetAll?AttributeId={attribute_id}&DisplayType={display_type}"
|
|
15
31
|
|
|
16
32
|
response = get_data(url, headers=self.set_auth_headers())
|
|
17
33
|
|
|
18
34
|
if response.get('success') == True:
|
|
35
|
+
self._cache[key] = copy.deepcopy(response)
|
|
19
36
|
return response
|
|
20
37
|
else:
|
|
21
38
|
raise ValueError(extract_api_error(response, "Unknown error in entry fields request"))
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: das-cli
|
|
3
|
-
Version: 1.7.
|
|
3
|
+
Version: 1.7.8
|
|
4
4
|
Summary: DAS api client.
|
|
5
5
|
Author: Royal Netherlands Institute for Sea Research
|
|
6
6
|
License-Expression: MIT
|
|
@@ -233,8 +233,17 @@ das entry update --id e1987f3e-7db7-11f0-a7e8-0edcca226f3d --data "{ 'Comment':
|
|
|
233
233
|
|
|
234
234
|
# Bulk from file (each item should include Id/Code)
|
|
235
235
|
das entry update c:\data\entries-to-update.json
|
|
236
|
+
|
|
237
|
+
# Recalculate the auto-generated name after changing a field it is built from
|
|
238
|
+
das entry update --code 4.b.rdg --data "{ 'Cast No.': '02' }" --regenerate-name
|
|
239
|
+
das entry update c:\data\events.xlsx --regenerate-name
|
|
236
240
|
```
|
|
237
241
|
|
|
242
|
+
An auto-generated name (an Event is `<station>_<cast><device acronym>`) is **kept as stored** on
|
|
243
|
+
update, even when the update changes the cast number or the device. Pass `--regenerate-name` to have
|
|
244
|
+
the server rebuild it from the updated values. The flag applies to every entry of a bulk update,
|
|
245
|
+
overrides a `Name` given in the data, and is ignored for attributes whose name has no formula.
|
|
246
|
+
|
|
238
247
|
#### Logs and ownership
|
|
239
248
|
```bash
|
|
240
249
|
# Audit logs
|
|
@@ -447,7 +456,7 @@ Import: `from das.managers.entries_manager import EntryManager`
|
|
|
447
456
|
| `get(code=..., id=...)` | `dict` — entry with display field names |
|
|
448
457
|
| `get_entry(entry_id)` | `dict` — same as `get(id=...)` |
|
|
449
458
|
| `create(attribute, entry=..., entries=...)` | `list[dict]` — per-item status with `id`, `code`, `status` |
|
|
450
|
-
| `update(id=..., code=..., entry=..., entries
|
|
459
|
+
| `update(id=..., code=..., entry=..., entries=..., regenerate_name=False)` | `list[dict]` — per-item status |
|
|
451
460
|
| `delete(id=..., code=...)` | `bool` |
|
|
452
461
|
| `create_from_file(attribute, file_path)` | `None` |
|
|
453
462
|
| `chown(user_name, entry_code_list)` | API response |
|
|
@@ -543,6 +552,9 @@ entries.update(entries=[
|
|
|
543
552
|
{"Code": "ENT001", "Comment": "Updated 1"},
|
|
544
553
|
{"Code": "ENT002", "Comment": "Updated 2"},
|
|
545
554
|
])
|
|
555
|
+
|
|
556
|
+
# Rebuild the auto-generated name from the updated values (kept as stored by default)
|
|
557
|
+
entries.update(code="4.b.rdg", entry={"Cast No.": "02"}, regenerate_name=True)
|
|
546
558
|
```
|
|
547
559
|
|
|
548
560
|
#### `delete` — delete one entry
|
|
@@ -922,7 +934,7 @@ You can configure values through CLI commands and/or `.env`.
|
|
|
922
934
|
|
|
923
935
|
```env
|
|
924
936
|
# Connection
|
|
925
|
-
DAS_API_URL=https://
|
|
937
|
+
DAS_API_URL=https://your-das-instance/api
|
|
926
938
|
DAS_API_KEY=
|
|
927
939
|
VERIFY_SSL=True
|
|
928
940
|
|
|
@@ -931,7 +943,7 @@ DAS_LOG_LEVEL=WARN
|
|
|
931
943
|
DAS_LOG_FILE=
|
|
932
944
|
|
|
933
945
|
# Test credentials (for integration tests)
|
|
934
|
-
API_URL=https://
|
|
946
|
+
API_URL=https://your-das-instance/api
|
|
935
947
|
USER_NAME=
|
|
936
948
|
USER_PASSWORD=
|
|
937
949
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|