|
| 1 | +# TODO: Typer did not work in Docker container, meaning passed arguments were ignored. Switch to Click for now. Decide later if we want to switch back to Typer. |
| 2 | +# # !/usr/bin/env python3 |
| 3 | +# import typer |
| 4 | +# from typing import List |
| 5 | +# from databusclient import client |
| 6 | + |
| 7 | +# app = typer.Typer() |
| 8 | + |
| 9 | + |
| 10 | +# @app.command() |
| 11 | +# def deploy( |
| 12 | +# version_id: str = typer.Option( |
| 13 | +# ..., |
| 14 | +# help="target databus version/dataset identifier of the form " |
| 15 | +# "<https://databus.dbpedia.org/$ACCOUNT/$GROUP/$ARTIFACT/$VERSION>", |
| 16 | +# ), |
| 17 | +# title: str = typer.Option(..., help="dataset title"), |
| 18 | +# abstract: str = typer.Option(..., help="dataset abstract max 200 chars"), |
| 19 | +# description: str = typer.Option(..., help="dataset description"), |
| 20 | +# license_uri: str = typer.Option(..., help="license (see dalicc.net)"), |
| 21 | +# apikey: str = typer.Option(..., help="apikey"), |
| 22 | +# distributions: List[str] = typer.Argument( |
| 23 | +# ..., |
| 24 | +# help="distributions in the form of List[URL|CV|fileext|compression|sha256sum:contentlength] where URL is the " |
| 25 | +# "download URL and CV the " |
| 26 | +# "key=value pairs (_ separated) content variants of a distribution. filext and compression are optional " |
| 27 | +# "and if left out inferred from the path. If the sha256sum:contentlength part is left out it will be " |
| 28 | +# "calcuted by downloading the file.", |
| 29 | +# ), |
| 30 | +# ): |
| 31 | +# typer.echo(version_id) |
| 32 | +# dataid = client.create_dataset( |
| 33 | +# version_id, title, abstract, description, license_uri, distributions |
| 34 | +# ) |
| 35 | +# client.deploy(dataid=dataid, api_key=apikey) |
| 36 | + |
| 37 | + |
| 38 | +# @app.command() |
| 39 | +# def download( |
| 40 | +# databusuris: List[str] = typer.Argument(..., help="any kind of these: databus identifier, databus collection identifier, query file"), |
| 41 | +# localDir: str = typer.Option(None , help="local databus folder"), # if not given, databus folder structure is created in current working directory |
| 42 | +# databus: str = typer.Option(None, help="databus URL"), # if not given, inferred on databusuri (e.g. https://databus.dbpedia.org/sparql) |
| 43 | +# token: str = typer.Option(None, help="Path to Vault refresh token file"), |
| 44 | +# authUrl: str = typer.Option("https://auth.dbpedia.org/realms/dbpedia/protocol/openid-connect/token", help="Keycloak token endpoint URL"), |
| 45 | +# clientId: str = typer.Option("vault-token-exchange", help="Client ID for token exchange") |
| 46 | +# ): |
| 47 | +# """ |
| 48 | +# Download datasets from databus, optionally using vault access if vault options are provided. |
| 49 | +# """ |
| 50 | +# client.download(localDir=localDir, endpoint=databus, databusURIs=databusuris, vault_token_file=vaultTokenFile, auth_url=authUrl, client_id=clientId) |
| 51 | + |
1 | 52 | #!/usr/bin/env python3 |
2 | | -import typer |
| 53 | +import click |
3 | 54 | from typing import List |
4 | 55 | from databusclient import client |
5 | 56 |
|
6 | | -app = typer.Typer() |
| 57 | + |
| 58 | +@click.group() |
| 59 | +def app(): |
| 60 | + """Databus Client CLI""" |
| 61 | + pass |
7 | 62 |
|
8 | 63 |
|
9 | 64 | @app.command() |
10 | | -def deploy( |
11 | | - version_id: str = typer.Option( |
12 | | - ..., |
13 | | - help="target databus version/dataset identifier of the form " |
14 | | - "<https://databus.dbpedia.org/$ACCOUNT/$GROUP/$ARTIFACT/$VERSION>", |
15 | | - ), |
16 | | - title: str = typer.Option(..., help="dataset title"), |
17 | | - abstract: str = typer.Option(..., help="dataset abstract max 200 chars"), |
18 | | - description: str = typer.Option(..., help="dataset description"), |
19 | | - license_uri: str = typer.Option(..., help="license (see dalicc.net)"), |
20 | | - apikey: str = typer.Option(..., help="apikey"), |
21 | | - distributions: List[str] = typer.Argument( |
22 | | - ..., |
23 | | - help="distributions in the form of List[URL|CV|fileext|compression|sha256sum:contentlength] where URL is the " |
24 | | - "download URL and CV the " |
25 | | - "key=value pairs (_ separated) content variants of a distribution. filext and compression are optional " |
26 | | - "and if left out inferred from the path. If the sha256sum:contentlength part is left out it will be " |
27 | | - "calcuted by downloading the file.", |
28 | | - ), |
29 | | -): |
30 | | - typer.echo(version_id) |
31 | | - dataid = client.create_dataset( |
32 | | - version_id, title, abstract, description, license_uri, distributions |
33 | | - ) |
| 65 | +@click.option( |
| 66 | + "--version-id", |
| 67 | + required=True, |
| 68 | + help="Target databus version/dataset identifier of the form " |
| 69 | + "<https://databus.dbpedia.org/$ACCOUNT/$GROUP/$ARTIFACT/$VERSION>", |
| 70 | +) |
| 71 | +@click.option("--title", required=True, help="Dataset title") |
| 72 | +@click.option("--abstract", required=True, help="Dataset abstract max 200 chars") |
| 73 | +@click.option("--description", required=True, help="Dataset description") |
| 74 | +@click.option("--license-uri", required=True, help="License (see dalicc.net)") |
| 75 | +@click.option("--apikey", required=True, help="API key") |
| 76 | +@click.argument( |
| 77 | + "distributions", |
| 78 | + nargs=-1, |
| 79 | + required=True, |
| 80 | +) |
| 81 | +def deploy(version_id, title, abstract, description, license_uri, apikey, distributions: List[str]): |
| 82 | + """ |
| 83 | + Deploy a dataset version with the provided metadata and distributions. |
| 84 | + """ |
| 85 | + click.echo(f"Deploying dataset version: {version_id}") |
| 86 | + dataid = client.create_dataset(version_id, title, abstract, description, license_uri, distributions) |
34 | 87 | client.deploy(dataid=dataid, api_key=apikey) |
35 | 88 |
|
36 | 89 |
|
37 | 90 | @app.command() |
38 | | -def download( |
39 | | - databusuris: List[str] = typer.Argument(..., help="any kind of these: databus identifier, databus collection identifier, query file"), |
40 | | - localDir: str = typer.Option(None , help="local databus folder"), # if not given, databus folder structure is created in current working directory |
41 | | - databus: str = typer.Option(None, help="databus URL"), # if not given, inferred on databusuri (e.g. https://databus.dbpedia.org/sparql) |
42 | | - token: str = typer.Option(None, help="Path to Vault refresh token file"), |
43 | | - authUrl: str = typer.Option("https://auth.dbpedia.org/realms/dbpedia/protocol/openid-connect/token", help="Keycloak token endpoint URL"), |
44 | | - clientId: str = typer.Option("vault-token-exchange", help="Client ID for token exchange") |
45 | | -): |
| 91 | +@click.argument("databusuris", nargs=-1, required=True) |
| 92 | +@click.option("--localdir", help="Local databus folder (if not given, databus folder structure is created in current working directory)") |
| 93 | +@click.option("--databus", help="Databus URL (if not given, inferred from databusuri, e.g. https://databus.dbpedia.org/sparql)") |
| 94 | +@click.option("--token", help="Path to Vault refresh token file") |
| 95 | +@click.option("--authurl", default="https://auth.dbpedia.org/realms/dbpedia/protocol/openid-connect/token", show_default=True, help="Keycloak token endpoint URL") |
| 96 | +@click.option("--clientid", default="vault-token-exchange", show_default=True, help="Client ID for token exchange") |
| 97 | +def download(databusuris: List[str], localdir, databus, token, authurl, clientid): |
46 | 98 | """ |
47 | 99 | Download datasets from databus, optionally using vault access if vault options are provided. |
48 | 100 | """ |
49 | | - client.download(localDir=localDir, endpoint=databus, databusURIs=databusuris, vault_token_file=vaultTokenFile, auth_url=authUrl, client_id=clientId) |
| 101 | + client.download( |
| 102 | + localDir=localdir, |
| 103 | + endpoint=databus, |
| 104 | + databusURIs=databusuris, |
| 105 | + token=token, |
| 106 | + auth_url=authurl, |
| 107 | + client_id=clientid, |
| 108 | + ) |
| 109 | + |
| 110 | + |
| 111 | +if __name__ == "__main__": |
| 112 | + app() |
0 commit comments