Skip to content

Commit 9d6de50

Browse files
committed
fix: coderabbit
1 parent d86d06b commit 9d6de50

File tree

5 files changed

+24
-24
lines changed

5 files changed

+24
-24
lines changed

README.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ Commands to download the [DBpedia Knowledge Graphs](#dbpedia-knowledge-graphs) g
6767

6868
To download BUSL 1.1 licensed datasets, you need to register and get an access token.
6969

70-
1. If you do not have a DBpedia Account yet (Forum/Databus), please register at https://account.dbpedia.org
71-
2. Log in at https://account.dbpedia.org and create your token.
70+
1. If you do not have a DBpedia Account yet (Forum/Databus), please register at [https://account.dbpedia.org](https://account.dbpedia.org)
71+
2. Log in at [https://account.dbpedia.org](https://account.dbpedia.org) and create your token.
7272
3. Save the token to a file, e.g. `vault-token.dat`.
7373

7474
### DBpedia Knowledge Graphs
@@ -182,7 +182,7 @@ Options:
182182
--databus TEXT Databus URL (if not given, inferred from databusuri,
183183
e.g. https://databus.dbpedia.org/sparql)
184184
--vault-token TEXT Path to Vault refresh token file
185-
--databus-key TEXT Databus API key to donwload from protected databus
185+
--databus-key TEXT Databus API key to download from protected databus
186186
--authurl TEXT Keycloak token endpoint URL [default:
187187
https://auth.dbpedia.org/realms/dbpedia/protocol/openid-
188188
connect/token]
@@ -191,7 +191,7 @@ Options:
191191
--help Show this message and exit.
192192
```
193193
194-
### Examples of using the download command
194+
#### Examples of using the download command
195195
196196
**Download File**: download of a single file
197197
```bash
@@ -397,7 +397,7 @@ docker run --rm -v $(pwd):/data dbpedia/databus-python-client deploy \
397397
./data_folder
398398
```
399399
400-
<a id="module-delete"></a>
400+
<a id="cli-delete"></a>
401401
### Delete
402402
403403
With the delete command you can delete collections, groups, artifacts, and versions from the Databus. Deleting files is not supported via API.
@@ -437,11 +437,9 @@ To authenticate the delete request, you need to provide an API key with `--datab
437437
438438
If you want to perform a dry run without actual deletion, use the `--dry-run` option. This will show you what would be deleted without making any changes.
439439
440-
As securety measure, the delete command will prompt you for confirmation before proceeding with the deletion. If you want to skip this prompt, you can use the `--force` option.
440+
As security measure, the delete command will prompt you for confirmation before proceeding with the deletion. If you want to skip this prompt, you can use the `--force` option.
441441
442-
**Example of using the delete command**
443-
444-
### Examples of using the download command
442+
#### Examples of using the delete command
445443
446444
**Delete Version**: delete a specific version
447445
```bash

databusclient/api/delete.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def _delete_resource(databusURI: str, databus_key: str, dry_run: bool = False, f
6565
print(f"[DRY RUN] Would delete: {databusURI}")
6666
return
6767

68-
response = requests.delete(databusURI, headers=headers)
68+
response = requests.delete(databusURI, headers=headers, timeout=30)
6969

7070
if response.status_code in (200, 204):
7171
print(f"Successfully deleted: {databusURI}")
@@ -112,11 +112,10 @@ def _delete_artifact(databusURI: str, databus_key: str, dry_run: bool = False, f
112112
raise ValueError("No versions found in artifact JSON-LD")
113113

114114
# Delete all versions
115-
_delete_list(version_uris, databus_key, dry_run=dry_run)
115+
_delete_list(version_uris, databus_key, dry_run=dry_run, force=force)
116116

117117
# Finally, delete the artifact itself
118-
_delete_resource(databusURI, databus_key, dry_run=dry_run)
119-
118+
_delete_resource(databusURI, databus_key, dry_run=dry_run, force=force)
120119

121120
def _delete_group(databusURI: str, databus_key: str, dry_run: bool = False, force: bool = False):
122121
"""
@@ -167,7 +166,7 @@ def delete(databusURIs: List[str], databus_key: str, dry_run: bool, force: bool)
167166
"""
168167

169168
for databusURI in databusURIs:
170-
host, account, group, artifact, version, file = get_databus_id_parts_from_uri(databusURI)
169+
_host, _account, group, artifact, version, file = get_databus_id_parts_from_uri(databusURI)
171170

172171
if group == "collections" and artifact is not None:
173172
print(f"Deleting collection: {databusURI}")
@@ -185,4 +184,4 @@ def delete(databusURIs: List[str], databus_key: str, dry_run: bool, force: bool)
185184
print(f"Deleting group and all its artifacts and versions: {databusURI}")
186185
_delete_group(databusURI, databus_key, dry_run=dry_run, force=force)
187186
else:
188-
print(f"Deleting ${databusURI} is not supported.")
187+
print(f"Deleting {databusURI} is not supported.")

databusclient/api/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def get_databus_id_parts_from_uri(uri: str) -> Tuple[Optional[str], Optional[str
1717
parts += [None] * (6 - len(parts)) # pad with None if less than 6 parts
1818
return tuple(parts[:6]) # return only the first 6 parts
1919

20-
def get_json_ld_from_databus(uri: str, databus_key: str = None) -> str:
20+
def get_json_ld_from_databus(uri: str, databus_key: str | None = None) -> str:
2121
"""
2222
Retrieve JSON-LD representation of a databus resource.
2323
@@ -31,7 +31,7 @@ def get_json_ld_from_databus(uri: str, databus_key: str = None) -> str:
3131
headers = {"Accept": "application/ld+json"}
3232
if databus_key is not None:
3333
headers["X-API-KEY"] = databus_key
34-
response = requests.get(uri, headers=headers)
34+
response = requests.get(uri, headers=headers, timeout=30)
3535
response.raise_for_status()
3636

3737
return response.text

databusclient/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def deploy(version_id, title, abstract, description, license_url, apikey,
9696
@click.option("--localdir", help="Local databus folder (if not given, databus folder structure is created in current working directory)")
9797
@click.option("--databus", help="Databus URL (if not given, inferred from databusuri, e.g. https://databus.dbpedia.org/sparql)")
9898
@click.option("--vault-token", help="Path to Vault refresh token file")
99-
@click.option("--databus-key", help="Databus API key to donwload from protected databus")
99+
@click.option("--databus-key", help="Databus API key to download from protected databus")
100100
@click.option("--authurl", default="https://auth.dbpedia.org/realms/dbpedia/protocol/openid-connect/token", show_default=True, help="Keycloak token endpoint URL")
101101
@click.option("--clientid", default="vault-token-exchange", show_default=True, help="Client ID for token exchange")
102102
def download(databusuris: List[str], localdir, databus, vault_token, databus_key, authurl, clientid):

databusclient/client.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -568,8 +568,7 @@ def __download_file__(url, filename, vault_token_file=None, databus_key=None, au
568568

569569
# TODO: could be a problem of github raw / openflaas
570570
if total_size_in_bytes != 0 and progress_bar.n != total_size_in_bytes:
571-
# raise IOError("Downloaded size does not match Content-Length header")
572-
print(f"Warning: Downloaded size does not match Content-Length header:\nExpected {total_size_in_bytes}, got {progress_bar.n}")
571+
raise IOError("Downloaded size does not match Content-Length header")
573572

574573

575574
def __get_vault_access__(download_url: str,
@@ -622,13 +621,14 @@ def __get_vault_access__(download_url: str,
622621
return vault_token
623622

624623

625-
def __query_sparql__(endpoint_url, query) -> dict:
624+
def __query_sparql__(endpoint_url, query, databus_key=None) -> dict:
626625
"""
627626
Query a SPARQL endpoint and return results in JSON format.
628627
629628
Parameters:
630629
- endpoint_url: the URL of the SPARQL endpoint
631630
- query: the SPARQL query string
631+
- databus_key: Optional API key for authentication
632632
633633
Returns:
634634
- Dictionary containing the query results
@@ -637,12 +637,14 @@ def __query_sparql__(endpoint_url, query) -> dict:
637637
sparql.method = 'POST'
638638
sparql.setQuery(query)
639639
sparql.setReturnFormat(JSON)
640+
if databus_key is not None:
641+
sparql.setCustomHttpHeaders({"X-API-KEY": databus_key})
640642
results = sparql.query().convert()
641643
return results
642644

643645

644-
def __handle_databus_file_query__(endpoint_url, query) -> List[str]:
645-
result_dict = __query_sparql__(endpoint_url, query)
646+
def __handle_databus_file_query__(endpoint_url, query, databus_key=None) -> List[str]:
647+
result_dict = __query_sparql__(endpoint_url, query, databus_key=databus_key)
646648
for binding in result_dict['results']['bindings']:
647649
if len(binding.keys()) > 1:
648650
print("Error multiple bindings in query response")
@@ -760,6 +762,7 @@ def download(
760762
endpoint: the databus endpoint URL
761763
databusURIs: identifiers to access databus registered datasets
762764
token: Path to Vault refresh token file
765+
databus_key: Databus API key for protected downloads
763766
auth_url: Keycloak token endpoint URL
764767
client_id: Client ID for token exchange
765768
"""
@@ -823,5 +826,5 @@ def download(
823826
print("QUERY {}", databusURI.replace("\n", " "))
824827
if endpoint is None: # endpoint is required for queries (--databus)
825828
raise ValueError("No endpoint given for query")
826-
res = __handle_databus_file_query__(endpoint, databusURI)
829+
res = __handle_databus_file_query__(endpoint, databusURI, databus_key=databus_key)
827830
__download_list__(res, localDir, vault_token_file=token, databus_key=databus_key, auth_url=auth_url, client_id=client_id)

0 commit comments

Comments
 (0)