Skip to content

Commit

Permalink
Merge pull request #123 from okfn/allow_expire_api_token_plugin
Browse files Browse the repository at this point in the history
Allow required params for token creation
  • Loading branch information
avdata99 authored Jul 6, 2023
2 parents a236853 + 49c4185 commit 3eb5a72
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
9 changes: 9 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ CKAN_REDIS_URL=redis://redis:6379/1
CKAN_DATAPUSHER_URL=http://datapusher:8800
CKAN__DATAPUSHER__CALLBACK_URL_BASE=http://ckan:5000

# If the "expire_api_token" plugin is enabled we need to define
# "expires_in" and "unit" parameters
DATAPUSHER_TOKEN_EXPIRES_IN=
DATAPUSHER_TOKEN_EXPIRES_UNIT=
# example for 1 year
# DATAPUSHER_TOKEN_EXPIRES_IN=365
# unit=1:Second;unit=2:Minute;unit=3:Hour;unit=4:Day
# DATAPUSHER_TOKEN_EXPIRES_UNIT=4

TEST_CKAN_SOLR_URL=http://solr:8983/solr/ckan
TEST_CKAN_REDIS_URL=redis://redis:6379/1

Expand Down
4 changes: 4 additions & 0 deletions ckan-base/2.10/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ ENV CKAN__PLUGINS image_view text_view recline_view datastore datapusher envvars
# UWSGI options
ENV UWSGI_HARAKIRI=50

# optional. If the "expire_api_token" is enabled you will need this.
ENV DATAPUSHER_TOKEN_EXPIRES_IN=
ENV DATAPUSHER_TOKEN_EXPIRES_UNIT=

WORKDIR ${APP_DIR}

# Install necessary packages to run CKAN
Expand Down
15 changes: 14 additions & 1 deletion ckan-base/2.10/setup/start_ckan.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,21 @@ fi
sudo -u ckan -EH python3 prerun.py

# Set a proper value for ckan.datapusher.api_token now that that an admin user exists

# If the expire_api_token plugin is enabled you will need to define
# "expires_in" and "unit" parameters. If required, add
# DATAPUSHER_TOKEN_EXPIRES_IN and DATAPUSHER_TOKEN_EXPIRES_UNIT as env
# variables.
if [[ -n "$DATAPUSHER_TOKEN_EXPIRES_IN" ]]
then
TOKEN_EXTRAS="expires_in=$DATAPUSHER_TOKEN_EXPIRES_IN unit=$DATAPUSHER_TOKEN_EXPIRES_UNIT"
else
TOKEN_EXTRAS=""
fi

expires_in=30 unit=4
echo "Set up ckan.datapusher.api_token"
ckan config-tool $CKAN_INI "ckan.datapusher.api_token=$(ckan -c $CKAN_INI user token add ckan_admin datapusher | tail -n 1 | tr -d '\t')"
ckan config-tool $CKAN_INI "ckan.datapusher.api_token=$(ckan -c $CKAN_INI user token add ckan_admin datapusher $TOKEN_EXTRAS | tail -n 1 | tr -d '\t')"

# Run any startup scripts provided by images extending this one
if [[ -d "/docker-entrypoint.d" ]]
Expand Down

0 comments on commit 3eb5a72

Please sign in to comment.