|
1 | | -# Parameters required for this script |
2 | | -token = "" |
3 | | -doi = "" # DOI in format "doi:10.34810/dataXXX" |
4 | | -lang = "" #language of the Readme file |
5 | | -base_url = "https://dataverse.csuc.cat/" |
6 | 1 |
|
7 | 2 | import os |
8 | 3 | import subprocess |
9 | 4 | import sys |
10 | 5 | import re |
11 | 6 |
|
| 7 | +def read_secret(path): |
| 8 | + try: |
| 9 | + with open(path, "r") as f: |
| 10 | + return f.read().strip() |
| 11 | + except Exception as e: |
| 12 | + raise RuntimeError(f"Failed to read secret from {path}: {e}") |
| 13 | + |
| 14 | + |
| 15 | +# Load token from Docker secret |
| 16 | +token = read_secret("/run/secrets/DATAVERSE_TOKEN") # Do not allow hardcoded credentials... |
| 17 | + |
| 18 | +doi = os.environ.get("DOI") |
| 19 | +lang = os.environ.get("LANG", "english") |
| 20 | +base_url = os.environ.get("BASE_URL", "https://dataverse.csuc.cat/") |
| 21 | +output_path = os.environ.get("OUTPUT_PATH") |
| 22 | + |
| 23 | +# Example usage |
| 24 | +print("✅ Token, DOI, LANG, BASE_URL and OUTPUT_PATH loaded successfully") |
| 25 | +print(f"TOKEN (first 5 chars): {token[:5]}...") |
| 26 | +print(f"DOI: {doi}") |
| 27 | +print(f"LANG: {lang}") |
| 28 | +print(f"BASE_URL: {base_url}") |
| 29 | +print(f"OUTPUT_PATH: {output_path}") |
| 30 | + |
| 31 | + |
12 | 32 | # Function to install required packages |
13 | 33 | def install_packages(): |
14 | 34 | """ |
@@ -275,8 +295,12 @@ def createreadme(base_url, token, doi, language, |
275 | 295 | # Retrieve dataset metadata |
276 | 296 | dataset = api.get_dataset(doi) |
277 | 297 |
|
278 | | - # Extract path from DOI |
279 | | - path = doi.replace("doi:10.34810/", "") |
| 298 | + # Extract path from DOI if not provided |
| 299 | + if output_path is None: |
| 300 | + path = doi.replace("doi:10.34810/", "") |
| 301 | + else: |
| 302 | + path = output_path |
| 303 | + |
280 | 304 |
|
281 | 305 | try: |
282 | 306 | # Create directory if it does not exist |
|
0 commit comments