Skip to content

Commit

Permalink
feat: add ability to set properties
Browse files Browse the repository at this point in the history
  • Loading branch information
Jose Diaz-Gonzalez committed Jan 28, 2023
1 parent c0c18ba commit bff8244
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
4 changes: 2 additions & 2 deletions help-functions
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ fn-help-content() {
declare desc="return help content"
cat <<help_content
letsencrypt:active <app>, Verify if letsencrypt is active for an app
letsencrypt:auto-renew, Auto-renew all apps secured by letsencrypt if renewal is necessary
letsencrypt:auto-renew <app>, Auto-renew app if renewal is necessary
letsencrypt:auto-renew [<app>], Auto-renew app if renewal is necessary
letsencrypt:cleanup <app>, Remove stale certificate directories for app
letsencrypt:cron-job [--add --remove], Add or remove a cron job that periodically calls auto-renew.
letsencrypt:disable <app>, Disable letsencrypt for an app
letsencrypt:enable <app>, Enable or renew letsencrypt for an app
letsencrypt:help, Display letsencrypt help
letsencrypt:list, List letsencrypt-secured apps with certificate expiry times
letsencrypt:revoke <app>, Revoke letsencrypt certificate for app
letsencrypt:set <app> <property> (<value>), Set or clear a letsencrypt property for an app
help_content
}
14 changes: 14 additions & 0 deletions post-delete
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash
source "$PLUGIN_CORE_AVAILABLE_PATH/common/property-functions"
set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x

trigger-letsencrypt-post-delete() {
declare desc="destroys the letsencrypt properties for a given app"
declare trigger="post-delete"
declare APP="$1"

fn-plugin-property-destroy "letsencrypt" "$APP"
}

trigger-letsencrypt-post-delete "$@"
37 changes: 37 additions & 0 deletions subcommands/set
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env bash
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
source "$PLUGIN_CORE_AVAILABLE_PATH/common/property-functions"
set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x

cmd-letsencrypt-set() {
declare desc="set or clear a letsencrypt property for an app"
declare cmd="letsencrypt:set"
[[ "$1" == "$cmd" ]] && shift 1
declare APP="$1" KEY="$2" VALUE="$3"
local VALID_KEYS=("email" "graceperiod" "server" "lego-args")
[[ "$APP" == "--global" ]] || verify_app_name "$APP"

[[ -z "$KEY" ]] && dokku_log_fail "No key specified"

if ! fn-in-array "$KEY" "${VALID_KEYS[@]}"; then
dokku_log_fail "Invalid key specified, valid keys include: email, graceperiod, server, lego-args"
fi

if [[ -n "$VALUE" ]]; then
dokku_log_info2_quiet "Setting ${KEY} to ${VALUE}"
fn-plugin-property-write "letsencrypt" "$APP" "$KEY" "$VALUE"
else
dokku_log_info2_quiet "Unsetting ${KEY}"
if [[ "$KEY" == "rev-env-var" ]]; then
fn-plugin-property-write "letsencrypt" "$APP" "$KEY" "$VALUE"
else
fn-plugin-property-delete "letsencrypt" "$APP" "$KEY"
if [[ "$KEY" == "enabled" ]]; then
fn-plugin-property-destroy "letsencrypt" "$APP"
fi
fi
fi
}

cmd-letsencrypt-set "$@"

0 comments on commit bff8244

Please sign in to comment.