das-cli 1.4.3__tar.gz → 1.5.0__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.
Files changed (41) hide show
  1. {das_cli-1.4.3/das_cli.egg-info → das_cli-1.5.0}/PKG-INFO +106 -22
  2. {das_cli-1.4.3 → das_cli-1.5.0}/README.md +106 -22
  3. {das_cli-1.4.3 → das_cli-1.5.0}/das/app.py +19 -4
  4. {das_cli-1.4.3 → das_cli-1.5.0}/das/cli.py +8 -1
  5. {das_cli-1.4.3 → das_cli-1.5.0}/das/common/config.py +11 -1
  6. {das_cli-1.4.3 → das_cli-1.5.0}/das/services/service_base.py +9 -4
  7. {das_cli-1.4.3 → das_cli-1.5.0/das_cli.egg-info}/PKG-INFO +106 -22
  8. {das_cli-1.4.3 → das_cli-1.5.0}/pyproject.toml +1 -1
  9. {das_cli-1.4.3 → das_cli-1.5.0}/LICENSE +0 -0
  10. {das_cli-1.4.3 → das_cli-1.5.0}/MANIFEST.in +0 -0
  11. {das_cli-1.4.3 → das_cli-1.5.0}/das/__init__.py +0 -0
  12. {das_cli-1.4.3 → das_cli-1.5.0}/das/ai/plugins/dasai.py +0 -0
  13. {das_cli-1.4.3 → das_cli-1.5.0}/das/ai/plugins/entries/entries_plugin.py +0 -0
  14. {das_cli-1.4.3 → das_cli-1.5.0}/das/authentication/auth.py +0 -0
  15. {das_cli-1.4.3 → das_cli-1.5.0}/das/authentication/oauth.py +0 -0
  16. {das_cli-1.4.3 → das_cli-1.5.0}/das/authentication/secure_input.py +0 -0
  17. {das_cli-1.4.3 → das_cli-1.5.0}/das/common/api.py +0 -0
  18. {das_cli-1.4.3 → das_cli-1.5.0}/das/common/entry_fields_constants.py +0 -0
  19. {das_cli-1.4.3 → das_cli-1.5.0}/das/common/enums.py +0 -0
  20. {das_cli-1.4.3 → das_cli-1.5.0}/das/common/file_utils.py +0 -0
  21. {das_cli-1.4.3 → das_cli-1.5.0}/das/managers/__init__.py +0 -0
  22. {das_cli-1.4.3 → das_cli-1.5.0}/das/managers/digital_objects_manager.py +0 -0
  23. {das_cli-1.4.3 → das_cli-1.5.0}/das/managers/download_manager.py +0 -0
  24. {das_cli-1.4.3 → das_cli-1.5.0}/das/managers/entries_manager.py +0 -0
  25. {das_cli-1.4.3 → das_cli-1.5.0}/das/managers/search_manager.py +0 -0
  26. {das_cli-1.4.3 → das_cli-1.5.0}/das/services/attributes.py +0 -0
  27. {das_cli-1.4.3 → das_cli-1.5.0}/das/services/cache.py +0 -0
  28. {das_cli-1.4.3 → das_cli-1.5.0}/das/services/das_elastic_search.py +0 -0
  29. {das_cli-1.4.3 → das_cli-1.5.0}/das/services/digital_objects.py +0 -0
  30. {das_cli-1.4.3 → das_cli-1.5.0}/das/services/downloads.py +0 -0
  31. {das_cli-1.4.3 → das_cli-1.5.0}/das/services/entries.py +0 -0
  32. {das_cli-1.4.3 → das_cli-1.5.0}/das/services/entry_fields.py +0 -0
  33. {das_cli-1.4.3 → das_cli-1.5.0}/das/services/hangfire.py +0 -0
  34. {das_cli-1.4.3 → das_cli-1.5.0}/das/services/search.py +0 -0
  35. {das_cli-1.4.3 → das_cli-1.5.0}/das/services/users.py +0 -0
  36. {das_cli-1.4.3 → das_cli-1.5.0}/das_cli.egg-info/SOURCES.txt +0 -0
  37. {das_cli-1.4.3 → das_cli-1.5.0}/das_cli.egg-info/dependency_links.txt +0 -0
  38. {das_cli-1.4.3 → das_cli-1.5.0}/das_cli.egg-info/entry_points.txt +0 -0
  39. {das_cli-1.4.3 → das_cli-1.5.0}/das_cli.egg-info/requires.txt +0 -0
  40. {das_cli-1.4.3 → das_cli-1.5.0}/das_cli.egg-info/top_level.txt +0 -0
  41. {das_cli-1.4.3 → das_cli-1.5.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: das-cli
3
- Version: 1.4.3
3
+ Version: 1.5.0
4
4
  Summary: DAS api client.
5
5
  Author: Royal Netherlands Institute for Sea Research
6
6
  License-Expression: MIT
@@ -44,9 +44,12 @@ A Python library and CLI for interacting with the Data Archive System (DAS) API.
44
44
  # Install
45
45
  pip install das-cli
46
46
 
47
- # Login (prompts for credentials if omitted)
47
+ # Login with username/password (prompts for credentials if omitted)
48
48
  das login --api-url https://your-das-instance/api
49
49
 
50
+ # Or login with an API key (generated in My Settings → API Keys)
51
+ das login --api-url https://your-das-instance/api --api-key <your-api-key>
52
+
50
53
  # Search entries
51
54
  das search entries --attribute Name --query 'name(*core*)' --format table
52
55
 
@@ -88,12 +91,34 @@ The package installs a `das` executable for interacting with the DAS API.
88
91
 
89
92
  ### Authentication
90
93
 
94
+ Three authentication methods are supported:
95
+
96
+ **Basic (username/password):**
97
+
91
98
  ```bash
92
99
  das login --api-url https://your-das-instance/api --username your_username --password your_password
93
100
  ```
94
101
 
95
102
  - Omit `--username`/`--password` to be prompted securely.
96
103
 
104
+ **API key:**
105
+
106
+ ```bash
107
+ das login --api-url https://your-das-instance/api --api-key <your-api-key>
108
+ ```
109
+
110
+ - Generate an API key in the DAS web interface under **My Settings → API Keys**.
111
+ - The key is stored locally and sent as an `X-Api-Key` header on every request.
112
+ - Alternatively, set the `DAS_API_KEY` environment variable — it takes priority over any stored key.
113
+
114
+ **OAuth / Azure Entra:**
115
+
116
+ ```bash
117
+ # Configure once, then login
118
+ das oauth configure --client-id <id> --authority https://login.microsoftonline.com/<tenant-id>
119
+ das login --api-url https://your-das-instance/api --oauth
120
+ ```
121
+
97
122
  ### Search
98
123
 
99
124
  ```bash
@@ -286,8 +311,12 @@ Before using the Python API (e.g. `EntryManager`, `SearchManager`, `DownloadMana
286
311
  **Option 1 – Login via CLI first (recommended):**
287
312
 
288
313
  ```bash
314
+ # Basic auth
289
315
  das login --api-url https://your-das-instance/api --username your_username --password your_password
290
316
  # Or omit --username/--password to be prompted securely
317
+
318
+ # API key auth
319
+ das login --api-url https://your-das-instance/api --api-key <your-api-key>
291
320
  ```
292
321
 
293
322
  Then in Python:
@@ -305,10 +334,14 @@ entry = entry_manager.get(code="7b.b.4c")
305
334
  from das.app import Das
306
335
  from das.managers.entries_manager import EntryManager
307
336
 
308
- # Authenticate and store credentials
337
+ # Authenticate with username/password
309
338
  client = Das("https://your-das-instance/api")
310
339
  client.authenticate("your_username", "your_password")
311
340
 
341
+ # Or authenticate with an API key (generated in My Settings → API Keys)
342
+ client = Das("https://your-das-instance/api")
343
+ client.authenticate_with_api_key("your-api-key")
344
+
312
345
  # Now EntryManager (and other managers) can use the stored config
313
346
  entry_manager = EntryManager()
314
347
  entry = entry_manager.get(code="7b.b.4c")
@@ -1054,38 +1087,89 @@ You can use a `.env` file in the project root (or current directory) for local c
1054
1087
  cp .env.example .env
1055
1088
  ```
1056
1089
 
1057
- Example `.env` (based on `.env.example`):
1090
+ Example `.env`:
1058
1091
 
1059
1092
  ```env
1060
- # DAS API credentials (used by tests and scripts; CLI uses `das login` for interactive use)
1093
+ # ── DAS connection ─────────────────────────────────────────────────────────────
1094
+
1095
+ # DAS API base URL — used by the library and tests when no URL is stored via `das login`
1096
+ DAS_API_URL=https://api.das-dev.nioz.nl
1097
+
1098
+ # DAS API key — alternative to username/password auth (My Settings → API Keys)
1099
+ # Takes priority over any key stored via `das login --api-key`. Sent as X-Api-Key header.
1100
+ DAS_API_KEY=
1101
+
1102
+ # Enable or disable SSL certificate verification (True/False). Overrides `das config ssl-verify`.
1103
+ VERIFY_SSL=True
1104
+
1105
+ # ── Test / script credentials (basic auth) ─────────────────────────────────────
1106
+
1107
+ # Used by tests and scripts when authenticating with username/password.
1108
+ # The CLI typically uses `das login` for interactive sessions instead.
1109
+ API_URL=https://api.das-dev.nioz.nl
1061
1110
  USER_NAME=
1062
1111
  USER_PASSWORD=
1063
1112
 
1064
- # DAS API base URL (e.g. https://api.das-dev.nioz.nl or https://localhost:44301)
1065
- API_URL=
1113
+ # ── AI feature ─────────────────────────────────────────────────────────────────
1114
+
1115
+ # OpenAI API key — used by `das ai enable`. Alternative to saving it interactively.
1116
+ OPENAI_API_KEY=
1117
+
1118
+ # OpenAI model ID (e.g. gpt-4o, gpt-4o-mini). Defaults to gpt-4o-mini if not set.
1119
+ OPEN_AI_MODEL_ID=gpt-4o-mini
1120
+
1121
+ # ── Publishing (maintainers only) ──────────────────────────────────────────────
1066
1122
 
1067
- # PyPI/Twine credentials for publishing packages (deploy.ps1, etc.)
1068
1123
  TWINE_USERNAME=__token__
1069
1124
  TWINE_PASSWORD=
1125
+ ```
1126
+
1127
+ | Variable | Used by | Description |
1128
+ |----------|---------|-------------|
1129
+ | `DAS_API_URL` | Library, CLI | DAS API base URL. Takes priority over the URL stored via `das login`. Example: `https://api.das-dev.nioz.nl`. |
1130
+ | `DAS_API_KEY` | Library, CLI | DAS API key for authentication. Takes priority over any key stored via `das login --api-key`. Generate in the DAS web UI under **My Settings → API Keys**. Sent as `X-Api-Key` header on every request. |
1131
+ | `VERIFY_SSL` | Library, CLI | `True` or `False`. Overrides the value set by `das config ssl-verify`. |
1132
+ | `API_URL` | Tests | DAS API base URL used by the test suite. Equivalent to `DAS_API_URL` but only read by tests. |
1133
+ | `USER_NAME` | Tests | DAS username for test authentication. Never commit to version control. |
1134
+ | `USER_PASSWORD` | Tests | DAS password for test authentication. Never commit to version control. |
1135
+ | `OPENAI_API_KEY` | AI feature | OpenAI API key used by `das ai enable`. Alternative to saving it interactively. |
1136
+ | `OPEN_AI_MODEL_ID` | AI feature | OpenAI model ID (e.g. `gpt-4o`, `gpt-4o-mini`). Defaults to `gpt-4o-mini` if not set. |
1137
+ | `TWINE_USERNAME` | Publishing | PyPI/Twine username. Use `__token__` when publishing with an API token. |
1138
+ | `TWINE_PASSWORD` | Publishing | PyPI/Twine password or API token. Used by `deploy.ps1`. |
1070
1139
 
1071
- # Enable or disable SSL certificate verification (True/False). Overrides config when set.
1072
- VERIFY_SSL=
1140
+ **Note:** The `.env` file is gitignored. Never commit credentials.
1073
1141
 
1074
- # OpenAI model ID for the AI feature (e.g. gpt-4, gpt-4o-mini). Used by `das ai enable`.
1075
- OPEN_AI_MODEL_ID=
1142
+ #### Examples
1143
+
1144
+ **Authenticate with API key via environment (no CLI login needed):**
1145
+
1146
+ ```env
1147
+ DAS_API_URL=https://api.das-dev.nioz.nl
1148
+ DAS_API_KEY=your-api-key-here
1076
1149
  ```
1077
1150
 
1078
- | Variable | Description |
1079
- |----------|-------------|
1080
- | `USER_NAME` | DAS username. Used by tests and scripts for authentication. The CLI typically uses `das login` instead. |
1081
- | `USER_PASSWORD` | DAS password. Used by tests and scripts. Never commit this to version control. |
1082
- | `API_URL` | DAS API base URL (e.g. `https://api.das-dev.nioz.nl` or `https://localhost:44301`). Used by tests, scripts, and when no URL is stored via `das login`. |
1083
- | `TWINE_USERNAME` | PyPI/Twine username. Use `__token__` when publishing with an API token. |
1084
- | `TWINE_PASSWORD` | PyPI/Twine password or API token. Used by `deploy.ps1` when publishing packages. |
1085
- | `VERIFY_SSL` | Set to `True` or `False` to control SSL certificate verification. Overrides the value from `das config ssl-verify` when set. |
1086
- | `OPEN_AI_MODEL_ID` | OpenAI model ID (e.g. `gpt-4`, `gpt-4o-mini`). Used by the AI feature (`das ai enable`). |
1151
+ ```python
1152
+ from das.app import Das
1087
1153
 
1088
- **Note:** The `.env` file is gitignored. Do not commit credentials.
1154
+ # DAS_API_URL and DAS_API_KEY are picked up automatically from the environment
1155
+ client = Das()
1156
+ entries = client.entries.get(code="7b.b.4c")
1157
+ ```
1158
+
1159
+ **Run tests against a specific instance:**
1160
+
1161
+ ```env
1162
+ API_URL=https://api.das-dev.nioz.nl
1163
+ USER_NAME=alice
1164
+ USER_PASSWORD=secret
1165
+ ```
1166
+
1167
+ **Use the AI feature with a specific OpenAI model:**
1168
+
1169
+ ```env
1170
+ OPENAI_API_KEY=sk-...
1171
+ OPEN_AI_MODEL_ID=gpt-4o
1172
+ ```
1089
1173
 
1090
1174
  ## Downloads
1091
1175
 
@@ -21,9 +21,12 @@ A Python library and CLI for interacting with the Data Archive System (DAS) API.
21
21
  # Install
22
22
  pip install das-cli
23
23
 
24
- # Login (prompts for credentials if omitted)
24
+ # Login with username/password (prompts for credentials if omitted)
25
25
  das login --api-url https://your-das-instance/api
26
26
 
27
+ # Or login with an API key (generated in My Settings → API Keys)
28
+ das login --api-url https://your-das-instance/api --api-key <your-api-key>
29
+
27
30
  # Search entries
28
31
  das search entries --attribute Name --query 'name(*core*)' --format table
29
32
 
@@ -65,12 +68,34 @@ The package installs a `das` executable for interacting with the DAS API.
65
68
 
66
69
  ### Authentication
67
70
 
71
+ Three authentication methods are supported:
72
+
73
+ **Basic (username/password):**
74
+
68
75
  ```bash
69
76
  das login --api-url https://your-das-instance/api --username your_username --password your_password
70
77
  ```
71
78
 
72
79
  - Omit `--username`/`--password` to be prompted securely.
73
80
 
81
+ **API key:**
82
+
83
+ ```bash
84
+ das login --api-url https://your-das-instance/api --api-key <your-api-key>
85
+ ```
86
+
87
+ - Generate an API key in the DAS web interface under **My Settings → API Keys**.
88
+ - The key is stored locally and sent as an `X-Api-Key` header on every request.
89
+ - Alternatively, set the `DAS_API_KEY` environment variable — it takes priority over any stored key.
90
+
91
+ **OAuth / Azure Entra:**
92
+
93
+ ```bash
94
+ # Configure once, then login
95
+ das oauth configure --client-id <id> --authority https://login.microsoftonline.com/<tenant-id>
96
+ das login --api-url https://your-das-instance/api --oauth
97
+ ```
98
+
74
99
  ### Search
75
100
 
76
101
  ```bash
@@ -263,8 +288,12 @@ Before using the Python API (e.g. `EntryManager`, `SearchManager`, `DownloadMana
263
288
  **Option 1 – Login via CLI first (recommended):**
264
289
 
265
290
  ```bash
291
+ # Basic auth
266
292
  das login --api-url https://your-das-instance/api --username your_username --password your_password
267
293
  # Or omit --username/--password to be prompted securely
294
+
295
+ # API key auth
296
+ das login --api-url https://your-das-instance/api --api-key <your-api-key>
268
297
  ```
269
298
 
270
299
  Then in Python:
@@ -282,10 +311,14 @@ entry = entry_manager.get(code="7b.b.4c")
282
311
  from das.app import Das
283
312
  from das.managers.entries_manager import EntryManager
284
313
 
285
- # Authenticate and store credentials
314
+ # Authenticate with username/password
286
315
  client = Das("https://your-das-instance/api")
287
316
  client.authenticate("your_username", "your_password")
288
317
 
318
+ # Or authenticate with an API key (generated in My Settings → API Keys)
319
+ client = Das("https://your-das-instance/api")
320
+ client.authenticate_with_api_key("your-api-key")
321
+
289
322
  # Now EntryManager (and other managers) can use the stored config
290
323
  entry_manager = EntryManager()
291
324
  entry = entry_manager.get(code="7b.b.4c")
@@ -1031,38 +1064,89 @@ You can use a `.env` file in the project root (or current directory) for local c
1031
1064
  cp .env.example .env
1032
1065
  ```
1033
1066
 
1034
- Example `.env` (based on `.env.example`):
1067
+ Example `.env`:
1035
1068
 
1036
1069
  ```env
1037
- # DAS API credentials (used by tests and scripts; CLI uses `das login` for interactive use)
1070
+ # ── DAS connection ─────────────────────────────────────────────────────────────
1071
+
1072
+ # DAS API base URL — used by the library and tests when no URL is stored via `das login`
1073
+ DAS_API_URL=https://api.das-dev.nioz.nl
1074
+
1075
+ # DAS API key — alternative to username/password auth (My Settings → API Keys)
1076
+ # Takes priority over any key stored via `das login --api-key`. Sent as X-Api-Key header.
1077
+ DAS_API_KEY=
1078
+
1079
+ # Enable or disable SSL certificate verification (True/False). Overrides `das config ssl-verify`.
1080
+ VERIFY_SSL=True
1081
+
1082
+ # ── Test / script credentials (basic auth) ─────────────────────────────────────
1083
+
1084
+ # Used by tests and scripts when authenticating with username/password.
1085
+ # The CLI typically uses `das login` for interactive sessions instead.
1086
+ API_URL=https://api.das-dev.nioz.nl
1038
1087
  USER_NAME=
1039
1088
  USER_PASSWORD=
1040
1089
 
1041
- # DAS API base URL (e.g. https://api.das-dev.nioz.nl or https://localhost:44301)
1042
- API_URL=
1090
+ # ── AI feature ─────────────────────────────────────────────────────────────────
1091
+
1092
+ # OpenAI API key — used by `das ai enable`. Alternative to saving it interactively.
1093
+ OPENAI_API_KEY=
1094
+
1095
+ # OpenAI model ID (e.g. gpt-4o, gpt-4o-mini). Defaults to gpt-4o-mini if not set.
1096
+ OPEN_AI_MODEL_ID=gpt-4o-mini
1097
+
1098
+ # ── Publishing (maintainers only) ──────────────────────────────────────────────
1043
1099
 
1044
- # PyPI/Twine credentials for publishing packages (deploy.ps1, etc.)
1045
1100
  TWINE_USERNAME=__token__
1046
1101
  TWINE_PASSWORD=
1102
+ ```
1103
+
1104
+ | Variable | Used by | Description |
1105
+ |----------|---------|-------------|
1106
+ | `DAS_API_URL` | Library, CLI | DAS API base URL. Takes priority over the URL stored via `das login`. Example: `https://api.das-dev.nioz.nl`. |
1107
+ | `DAS_API_KEY` | Library, CLI | DAS API key for authentication. Takes priority over any key stored via `das login --api-key`. Generate in the DAS web UI under **My Settings → API Keys**. Sent as `X-Api-Key` header on every request. |
1108
+ | `VERIFY_SSL` | Library, CLI | `True` or `False`. Overrides the value set by `das config ssl-verify`. |
1109
+ | `API_URL` | Tests | DAS API base URL used by the test suite. Equivalent to `DAS_API_URL` but only read by tests. |
1110
+ | `USER_NAME` | Tests | DAS username for test authentication. Never commit to version control. |
1111
+ | `USER_PASSWORD` | Tests | DAS password for test authentication. Never commit to version control. |
1112
+ | `OPENAI_API_KEY` | AI feature | OpenAI API key used by `das ai enable`. Alternative to saving it interactively. |
1113
+ | `OPEN_AI_MODEL_ID` | AI feature | OpenAI model ID (e.g. `gpt-4o`, `gpt-4o-mini`). Defaults to `gpt-4o-mini` if not set. |
1114
+ | `TWINE_USERNAME` | Publishing | PyPI/Twine username. Use `__token__` when publishing with an API token. |
1115
+ | `TWINE_PASSWORD` | Publishing | PyPI/Twine password or API token. Used by `deploy.ps1`. |
1116
+
1117
+ **Note:** The `.env` file is gitignored. Never commit credentials.
1118
+
1119
+ #### Examples
1120
+
1121
+ **Authenticate with API key via environment (no CLI login needed):**
1122
+
1123
+ ```env
1124
+ DAS_API_URL=https://api.das-dev.nioz.nl
1125
+ DAS_API_KEY=your-api-key-here
1126
+ ```
1127
+
1128
+ ```python
1129
+ from das.app import Das
1130
+
1131
+ # DAS_API_URL and DAS_API_KEY are picked up automatically from the environment
1132
+ client = Das()
1133
+ entries = client.entries.get(code="7b.b.4c")
1134
+ ```
1047
1135
 
1048
- # Enable or disable SSL certificate verification (True/False). Overrides config when set.
1049
- VERIFY_SSL=
1136
+ **Run tests against a specific instance:**
1050
1137
 
1051
- # OpenAI model ID for the AI feature (e.g. gpt-4, gpt-4o-mini). Used by `das ai enable`.
1052
- OPEN_AI_MODEL_ID=
1138
+ ```env
1139
+ API_URL=https://api.das-dev.nioz.nl
1140
+ USER_NAME=alice
1141
+ USER_PASSWORD=secret
1053
1142
  ```
1054
1143
 
1055
- | Variable | Description |
1056
- |----------|-------------|
1057
- | `USER_NAME` | DAS username. Used by tests and scripts for authentication. The CLI typically uses `das login` instead. |
1058
- | `USER_PASSWORD` | DAS password. Used by tests and scripts. Never commit this to version control. |
1059
- | `API_URL` | DAS API base URL (e.g. `https://api.das-dev.nioz.nl` or `https://localhost:44301`). Used by tests, scripts, and when no URL is stored via `das login`. |
1060
- | `TWINE_USERNAME` | PyPI/Twine username. Use `__token__` when publishing with an API token. |
1061
- | `TWINE_PASSWORD` | PyPI/Twine password or API token. Used by `deploy.ps1` when publishing packages. |
1062
- | `VERIFY_SSL` | Set to `True` or `False` to control SSL certificate verification. Overrides the value from `das config ssl-verify` when set. |
1063
- | `OPEN_AI_MODEL_ID` | OpenAI model ID (e.g. `gpt-4`, `gpt-4o-mini`). Used by the AI feature (`das ai enable`). |
1144
+ **Use the AI feature with a specific OpenAI model:**
1064
1145
 
1065
- **Note:** The `.env` file is gitignored. Do not commit credentials.
1146
+ ```env
1147
+ OPENAI_API_KEY=sk-...
1148
+ OPEN_AI_MODEL_ID=gpt-4o
1149
+ ```
1066
1150
 
1067
1151
  ## Downloads
1068
1152
 
@@ -1185,4 +1269,4 @@ If you need to run the current module use:
1185
1269
 
1186
1270
  ```bash
1187
1271
  python -m das.cli login --api-url https://api.das-dev.nioz.nl/ --oauth
1188
- ```
1272
+ ```
@@ -6,14 +6,16 @@ from das.services.entry_fields import EntryFieldsService
6
6
  from das.services.hangfire import HangfireService
7
7
  from das.services.search import SearchService
8
8
  from das.services.das_elastic_search import DasElasticSearch
9
- from das.common.config import save_api_url
9
+ from das.common.config import save_api_url, load_api_url, save_token, set_auth_type
10
10
 
11
- # $env:PYTHONPATH="C:\Workspace\das-cli"
11
+ # $env:PYTHONPATH="C:\Workspace\das-cli"
12
12
 
13
13
  class Das:
14
- def __init__(self, base_url: str):
14
+ def __init__(self, base_url: str = None):
15
15
  if base_url is None or base_url == "":
16
- raise ValueError("You must be authenticated.")
16
+ base_url = load_api_url()
17
+ if base_url is None or base_url == "":
18
+ raise ValueError("No API URL configured. Pass base_url, set DAS_API_URL in your .env, or run 'das login'.")
17
19
  save_api_url(base_url)
18
20
  self.base_url = base_url
19
21
  self.attributes = AttributesService(base_url)
@@ -24,6 +26,19 @@ class Das:
24
26
  self.search = SearchService(base_url)
25
27
  self.elastic_search = DasElasticSearch(base_url)
26
28
 
29
+ def authenticate_with_api_key(self, api_key: str) -> None:
30
+ """
31
+ Authenticate using a DAS API key.
32
+
33
+ Generate an API key in the DAS web interface under My Settings → API Keys.
34
+ The key is stored securely and sent as an X-Api-Key header on every request.
35
+
36
+ Args:
37
+ api_key (str): The API key to authenticate with.
38
+ """
39
+ save_token(api_key)
40
+ set_auth_type("api_key")
41
+
27
42
  def authenticate(self, username: str, password: str) -> str:
28
43
  """
29
44
  Authenticate with the DAS API and return the token.
@@ -105,14 +105,21 @@ def cli(ctx):
105
105
  @click.option('--username', default=None, help='Username (basic auth)')
106
106
  @click.option('--password', default=None, hide_input=True, help='Password (basic auth)')
107
107
  @click.option('--oauth', 'use_oauth', is_flag=True, default=False, help='Use Azure Entra/OAuth authentication (opens browser)')
108
+ @click.option('--api-key', default=None, help='DAS API key (generated in My Settings → API Keys)')
108
109
  @click.option('--debug', is_flag=True, default=False, help='Print decoded token claims for troubleshooting')
109
110
  @pass_das_context
110
- def login(das_ctx, api_url, username, password, use_oauth, debug):
111
+ def login(das_ctx, api_url, username, password, use_oauth, api_key, debug):
111
112
  """Login and store authentication token"""
112
113
  # Save API URL for future use
113
114
  save_api_url(api_url)
114
115
  das_ctx.api_url = api_url
115
116
 
117
+ if api_key:
118
+ save_token(api_key)
119
+ set_auth_type("api_key")
120
+ click.secho("✓ API key saved.", fg="green")
121
+ return
122
+
116
123
  if use_oauth:
117
124
  # --- OAuth / Azure Entra PKCE flow ---
118
125
  oauth_cfg = load_oauth_config()
@@ -43,6 +43,9 @@ def save_api_url(api_url: str) -> None:
43
43
  CONFIG_FILE.write_text(json.dumps(config), encoding="utf-8")
44
44
 
45
45
  def load_api_url() -> Optional[str]:
46
+ env_url = os.getenv("DAS_API_URL")
47
+ if env_url:
48
+ return env_url
46
49
  if CONFIG_FILE.exists():
47
50
  try:
48
51
  return json.loads(CONFIG_FILE.read_text(encoding="utf-8")).get("api_url")
@@ -145,6 +148,11 @@ def save_token(token: str) -> None:
145
148
  os.chmod(p, 0o600)
146
149
 
147
150
  def load_token(auto_refresh: bool = True) -> Optional[str]:
151
+ # .env / environment variable takes highest priority
152
+ env_key = os.getenv("DAS_API_KEY")
153
+ if env_key:
154
+ return env_key
155
+
148
156
  if _keyring_available():
149
157
  import keyring
150
158
  token = keyring.get_password(SERVICE_NAME, "default")
@@ -230,7 +238,9 @@ def load_oauth_config() -> dict:
230
238
 
231
239
 
232
240
  def get_auth_type() -> str:
233
- """Return 'oauth' or 'basic' (default 'basic')."""
241
+ """Return 'api_key', 'oauth', or 'basic' (default 'basic')."""
242
+ if os.getenv("DAS_API_KEY"):
243
+ return "api_key"
234
244
  if CONFIG_FILE.exists():
235
245
  try:
236
246
  return json.loads(CONFIG_FILE.read_text(encoding="utf-8")).get("auth_type", "basic")
@@ -1,5 +1,5 @@
1
1
  from abc import ABC
2
- from das.common.config import load_token
2
+ from das.common.config import load_token, get_auth_type
3
3
 
4
4
  class ServiceBase(ABC):
5
5
 
@@ -19,7 +19,12 @@ class ServiceBase(ABC):
19
19
  if self.token is None or self.token == "":
20
20
  raise ValueError("Authorization token is required")
21
21
  if self._headers is None:
22
- self._headers = {
23
- "Authorization": f"Bearer {self.token}"
24
- }
22
+ if get_auth_type() == "api_key":
23
+ self._headers = {
24
+ "X-Api-Key": self.token
25
+ }
26
+ else:
27
+ self._headers = {
28
+ "Authorization": f"Bearer {self.token}"
29
+ }
25
30
  return self._headers
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: das-cli
3
- Version: 1.4.3
3
+ Version: 1.5.0
4
4
  Summary: DAS api client.
5
5
  Author: Royal Netherlands Institute for Sea Research
6
6
  License-Expression: MIT
@@ -44,9 +44,12 @@ A Python library and CLI for interacting with the Data Archive System (DAS) API.
44
44
  # Install
45
45
  pip install das-cli
46
46
 
47
- # Login (prompts for credentials if omitted)
47
+ # Login with username/password (prompts for credentials if omitted)
48
48
  das login --api-url https://your-das-instance/api
49
49
 
50
+ # Or login with an API key (generated in My Settings → API Keys)
51
+ das login --api-url https://your-das-instance/api --api-key <your-api-key>
52
+
50
53
  # Search entries
51
54
  das search entries --attribute Name --query 'name(*core*)' --format table
52
55
 
@@ -88,12 +91,34 @@ The package installs a `das` executable for interacting with the DAS API.
88
91
 
89
92
  ### Authentication
90
93
 
94
+ Three authentication methods are supported:
95
+
96
+ **Basic (username/password):**
97
+
91
98
  ```bash
92
99
  das login --api-url https://your-das-instance/api --username your_username --password your_password
93
100
  ```
94
101
 
95
102
  - Omit `--username`/`--password` to be prompted securely.
96
103
 
104
+ **API key:**
105
+
106
+ ```bash
107
+ das login --api-url https://your-das-instance/api --api-key <your-api-key>
108
+ ```
109
+
110
+ - Generate an API key in the DAS web interface under **My Settings → API Keys**.
111
+ - The key is stored locally and sent as an `X-Api-Key` header on every request.
112
+ - Alternatively, set the `DAS_API_KEY` environment variable — it takes priority over any stored key.
113
+
114
+ **OAuth / Azure Entra:**
115
+
116
+ ```bash
117
+ # Configure once, then login
118
+ das oauth configure --client-id <id> --authority https://login.microsoftonline.com/<tenant-id>
119
+ das login --api-url https://your-das-instance/api --oauth
120
+ ```
121
+
97
122
  ### Search
98
123
 
99
124
  ```bash
@@ -286,8 +311,12 @@ Before using the Python API (e.g. `EntryManager`, `SearchManager`, `DownloadMana
286
311
  **Option 1 – Login via CLI first (recommended):**
287
312
 
288
313
  ```bash
314
+ # Basic auth
289
315
  das login --api-url https://your-das-instance/api --username your_username --password your_password
290
316
  # Or omit --username/--password to be prompted securely
317
+
318
+ # API key auth
319
+ das login --api-url https://your-das-instance/api --api-key <your-api-key>
291
320
  ```
292
321
 
293
322
  Then in Python:
@@ -305,10 +334,14 @@ entry = entry_manager.get(code="7b.b.4c")
305
334
  from das.app import Das
306
335
  from das.managers.entries_manager import EntryManager
307
336
 
308
- # Authenticate and store credentials
337
+ # Authenticate with username/password
309
338
  client = Das("https://your-das-instance/api")
310
339
  client.authenticate("your_username", "your_password")
311
340
 
341
+ # Or authenticate with an API key (generated in My Settings → API Keys)
342
+ client = Das("https://your-das-instance/api")
343
+ client.authenticate_with_api_key("your-api-key")
344
+
312
345
  # Now EntryManager (and other managers) can use the stored config
313
346
  entry_manager = EntryManager()
314
347
  entry = entry_manager.get(code="7b.b.4c")
@@ -1054,38 +1087,89 @@ You can use a `.env` file in the project root (or current directory) for local c
1054
1087
  cp .env.example .env
1055
1088
  ```
1056
1089
 
1057
- Example `.env` (based on `.env.example`):
1090
+ Example `.env`:
1058
1091
 
1059
1092
  ```env
1060
- # DAS API credentials (used by tests and scripts; CLI uses `das login` for interactive use)
1093
+ # ── DAS connection ─────────────────────────────────────────────────────────────
1094
+
1095
+ # DAS API base URL — used by the library and tests when no URL is stored via `das login`
1096
+ DAS_API_URL=https://api.das-dev.nioz.nl
1097
+
1098
+ # DAS API key — alternative to username/password auth (My Settings → API Keys)
1099
+ # Takes priority over any key stored via `das login --api-key`. Sent as X-Api-Key header.
1100
+ DAS_API_KEY=
1101
+
1102
+ # Enable or disable SSL certificate verification (True/False). Overrides `das config ssl-verify`.
1103
+ VERIFY_SSL=True
1104
+
1105
+ # ── Test / script credentials (basic auth) ─────────────────────────────────────
1106
+
1107
+ # Used by tests and scripts when authenticating with username/password.
1108
+ # The CLI typically uses `das login` for interactive sessions instead.
1109
+ API_URL=https://api.das-dev.nioz.nl
1061
1110
  USER_NAME=
1062
1111
  USER_PASSWORD=
1063
1112
 
1064
- # DAS API base URL (e.g. https://api.das-dev.nioz.nl or https://localhost:44301)
1065
- API_URL=
1113
+ # ── AI feature ─────────────────────────────────────────────────────────────────
1114
+
1115
+ # OpenAI API key — used by `das ai enable`. Alternative to saving it interactively.
1116
+ OPENAI_API_KEY=
1117
+
1118
+ # OpenAI model ID (e.g. gpt-4o, gpt-4o-mini). Defaults to gpt-4o-mini if not set.
1119
+ OPEN_AI_MODEL_ID=gpt-4o-mini
1120
+
1121
+ # ── Publishing (maintainers only) ──────────────────────────────────────────────
1066
1122
 
1067
- # PyPI/Twine credentials for publishing packages (deploy.ps1, etc.)
1068
1123
  TWINE_USERNAME=__token__
1069
1124
  TWINE_PASSWORD=
1125
+ ```
1126
+
1127
+ | Variable | Used by | Description |
1128
+ |----------|---------|-------------|
1129
+ | `DAS_API_URL` | Library, CLI | DAS API base URL. Takes priority over the URL stored via `das login`. Example: `https://api.das-dev.nioz.nl`. |
1130
+ | `DAS_API_KEY` | Library, CLI | DAS API key for authentication. Takes priority over any key stored via `das login --api-key`. Generate in the DAS web UI under **My Settings → API Keys**. Sent as `X-Api-Key` header on every request. |
1131
+ | `VERIFY_SSL` | Library, CLI | `True` or `False`. Overrides the value set by `das config ssl-verify`. |
1132
+ | `API_URL` | Tests | DAS API base URL used by the test suite. Equivalent to `DAS_API_URL` but only read by tests. |
1133
+ | `USER_NAME` | Tests | DAS username for test authentication. Never commit to version control. |
1134
+ | `USER_PASSWORD` | Tests | DAS password for test authentication. Never commit to version control. |
1135
+ | `OPENAI_API_KEY` | AI feature | OpenAI API key used by `das ai enable`. Alternative to saving it interactively. |
1136
+ | `OPEN_AI_MODEL_ID` | AI feature | OpenAI model ID (e.g. `gpt-4o`, `gpt-4o-mini`). Defaults to `gpt-4o-mini` if not set. |
1137
+ | `TWINE_USERNAME` | Publishing | PyPI/Twine username. Use `__token__` when publishing with an API token. |
1138
+ | `TWINE_PASSWORD` | Publishing | PyPI/Twine password or API token. Used by `deploy.ps1`. |
1070
1139
 
1071
- # Enable or disable SSL certificate verification (True/False). Overrides config when set.
1072
- VERIFY_SSL=
1140
+ **Note:** The `.env` file is gitignored. Never commit credentials.
1073
1141
 
1074
- # OpenAI model ID for the AI feature (e.g. gpt-4, gpt-4o-mini). Used by `das ai enable`.
1075
- OPEN_AI_MODEL_ID=
1142
+ #### Examples
1143
+
1144
+ **Authenticate with API key via environment (no CLI login needed):**
1145
+
1146
+ ```env
1147
+ DAS_API_URL=https://api.das-dev.nioz.nl
1148
+ DAS_API_KEY=your-api-key-here
1076
1149
  ```
1077
1150
 
1078
- | Variable | Description |
1079
- |----------|-------------|
1080
- | `USER_NAME` | DAS username. Used by tests and scripts for authentication. The CLI typically uses `das login` instead. |
1081
- | `USER_PASSWORD` | DAS password. Used by tests and scripts. Never commit this to version control. |
1082
- | `API_URL` | DAS API base URL (e.g. `https://api.das-dev.nioz.nl` or `https://localhost:44301`). Used by tests, scripts, and when no URL is stored via `das login`. |
1083
- | `TWINE_USERNAME` | PyPI/Twine username. Use `__token__` when publishing with an API token. |
1084
- | `TWINE_PASSWORD` | PyPI/Twine password or API token. Used by `deploy.ps1` when publishing packages. |
1085
- | `VERIFY_SSL` | Set to `True` or `False` to control SSL certificate verification. Overrides the value from `das config ssl-verify` when set. |
1086
- | `OPEN_AI_MODEL_ID` | OpenAI model ID (e.g. `gpt-4`, `gpt-4o-mini`). Used by the AI feature (`das ai enable`). |
1151
+ ```python
1152
+ from das.app import Das
1087
1153
 
1088
- **Note:** The `.env` file is gitignored. Do not commit credentials.
1154
+ # DAS_API_URL and DAS_API_KEY are picked up automatically from the environment
1155
+ client = Das()
1156
+ entries = client.entries.get(code="7b.b.4c")
1157
+ ```
1158
+
1159
+ **Run tests against a specific instance:**
1160
+
1161
+ ```env
1162
+ API_URL=https://api.das-dev.nioz.nl
1163
+ USER_NAME=alice
1164
+ USER_PASSWORD=secret
1165
+ ```
1166
+
1167
+ **Use the AI feature with a specific OpenAI model:**
1168
+
1169
+ ```env
1170
+ OPENAI_API_KEY=sk-...
1171
+ OPEN_AI_MODEL_ID=gpt-4o
1172
+ ```
1089
1173
 
1090
1174
  ## Downloads
1091
1175
 
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "das-cli"
7
- version = "1.4.03"
7
+ version = "1.5.0"
8
8
  authors = [
9
9
  { name="Royal Netherlands Institute for Sea Research" },
10
10
  ]
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