From 3f90532d05fb3c0192060be6a49b23d833f29e03 Mon Sep 17 00:00:00 2001 From: mjanez <96422458+mjanez@users.noreply.github.com> Date: Wed, 19 Apr 2023 15:37:42 +0200 Subject: [PATCH] Fix xloader token creation Removes unnecessary tokens previously created each time the script is executed. --- README.md | 4 +++- ckan/docker-entrypoint.d/01_setup_xloader.sh | 21 +++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f08e7e3..7d5a825 100644 --- a/README.md +++ b/README.md @@ -190,7 +190,9 @@ Use this if you are a maintainer and will not be making code changes to CKAN or > Please note that when accessing CKAN directly (via a browser) ie: not going through Apache/NGINX you will need to make sure you have "ckan" set up to be an alias to localhost in the local hosts file. Either that or you will need to change the `.env` entry for `CKAN_SITE_URL` >**Warning**:
- > Using the default values on the `.env` file will get you a working CKAN instance. There is a sysadmin user created by default with the values defined in `CKAN_SYSADMIN_NAME` and `CKAN_SYSADMIN_PASSWORD`(`ckan_admin` and `test1234` by default). **This should be obviously changed before running this setup as a public CKAN instance.** + > Using the default values on the `.env` file will get you a working CKAN instance. There is a sysadmin user created by default with the values defined in `CKAN_SYSADMIN_NAME` and `CKAN_SYSADMIN_PASSWORD` (`ckan_admin` and `test1234` by default). All ennvars with `API_TOKEN` are automatically regenerated when CKAN is loaded, no editing is required. + > + >**This should be obviously changed before running this setup as a public CKAN instance.** 3. Build the images: ```bash diff --git a/ckan/docker-entrypoint.d/01_setup_xloader.sh b/ckan/docker-entrypoint.d/01_setup_xloader.sh index 8aa2569..4f5e3e5 100644 --- a/ckan/docker-entrypoint.d/01_setup_xloader.sh +++ b/ckan/docker-entrypoint.d/01_setup_xloader.sh @@ -1,14 +1,29 @@ #!/bin/bash +# Set the name of the token to revoke +TOKEN_NAME="xloader" + +# Get the list of tokens and extract the IDs for tokens with the specified name +TOKEN_IDS=$(ckan -c $CKAN_INI user token list ckan_admin | grep "$TOKEN_NAME" | awk -F'[][]' '{print $2}' | tr -d '[]') + +# Revoke each previous token of xloader +for TOKEN_ID in $TOKEN_IDS +do + ckan -c $CKAN_INI user token revoke $TOKEN_ID + if [ $? -eq 0 ]; then + echo "API Token $TOKEN_ID has been revoked" + fi +done + # Add ckanext.xloader.api_token to the CKAN config file echo "Loading ckanext-xloader settings in the CKAN config file" ckan config-tool $CKAN_INI \ - "ckanext.xloader.api_token = xxx" \ - "ckanext.xloader.jobs_db.uri = $CKANEXT__XLOADER__JOBS__DB_URI" + "ckanext.xloader.api_token=xxx" \ + "ckanext.xloader.jobs_db.uri=$CKANEXT__XLOADER__JOBS__DB_URI" # Create ckanext-xloader API_TOKEN echo "Set up ckanext.xloader.api_token in the CKAN config file" -ckan config-tool $CKAN_INI "ckanext.xloader.api_token = $(ckan -c $CKAN_INI user token add ckan_admin xloader | tail -n 1 | tr -d '\t')" +ckan config-tool $CKAN_INI "ckanext.xloader.api_token=$(ckan -c $CKAN_INI user token add ckan_admin xloader | tail -n 1 | tr -d '\t')" #TODO: Setup worker background #echo "Set up CKAN jobs worker"