From 000bf3f59422e009a2f6f9d70f15841bf5dcd405 Mon Sep 17 00:00:00 2001 From: Valentin Lab Date: Thu, 2 Oct 2025 05:21:57 +0200 Subject: [PATCH] new: [opensem] add ``paybox-system`` relation --- opensem/README.org | 9 +++ opensem/hooks/paybox_system-relation-joined | 62 +++++++++++++++++++++ opensem/metadata.yml | 8 +++ 3 files changed, 79 insertions(+) create mode 100755 opensem/hooks/paybox_system-relation-joined diff --git a/opensem/README.org b/opensem/README.org index af02262..efc421b 100644 --- a/opensem/README.org +++ b/opensem/README.org @@ -8,3 +8,12 @@ and ~yarn.lock~ to ensure reproducible build. We provide the resulting production ready application files in a ~tar.xz~. + +* Charm usage + +Please note that =paylib-system= relation is required and no +auto-summon exists. It won't auto-pair neither as no charm currently +provides this relation. + +So you need to explicitly express this relation to a =stub= service. + diff --git a/opensem/hooks/paybox_system-relation-joined b/opensem/hooks/paybox_system-relation-joined new file mode 100755 index 0000000..1de977d --- /dev/null +++ b/opensem/hooks/paybox_system-relation-joined @@ -0,0 +1,62 @@ +#!/bin/bash + +. lib/common + +set -e + +test=$(relation-get test 2>/dev/null) || true +site=$(relation-get site) || { + err "The 'site' option is required." + exit 1 +} +rank=$(relation-get rank) || { + err "The 'rank' option is required." + exit 1 +} +id=$(relation-get id) || { + err "The 'id' option is required." + exit 1 +} +hmac_key=$(relation-get hmac-key) || { + err "The 'hmac-key' option is required." + exit 1 +} + +[ -n "$test" ] && opensem:config-set PAYBOX_TEST "$test" +opensem:config-set PAYBOX_SITE "$site" +opensem:config-set PAYBOX_RANK "$rank" +opensem:config-set PAYBOX_ID "$id" +opensem:config-set PAYBOX_HMAC_KEY "$hmac_key" + +paybox_url="http://www1.paybox.com/wp-content/uploads/2014/03/pubkey.pem" +paybox_pubkey_path="$SERVICE_DATASTORE/var/lib/opensem/paybox/pubkey.pem" + +if ! [ -f "$paybox_pubkey_path" ]; then + mkdir -p "${paybox_pubkey_path%/*}" + if ! curl -sSL "$paybox_url" -o "$paybox_pubkey_path"; then + err "Failed to download Paybox public key from $paybox_url" + exit 1 + fi +fi + +## and create the mount point also: +paybox_mount_dir="$SERVICE_CONFIGSTORE/opt/apps/$SERVICE_NAME/storage/paybox" +if ! [ -d "$paybox_mount_dir" ]; then + mkdir -p "$paybox_mount_dir" || { + err "Could not create directory $paybox_mount_dir" + exit 1 + } +fi + + +php_fpm_service=$(service:traverse "$SERVICE_NAME":php-fpm) || { + err "Could not find php-fpm service for $SERVICE_NAME" + exit 1 +} + +config-add " +services: + $php_fpm_service: + volumes: + - $SERVICE_DATASTORE/var/lib/opensem/paybox:/opt/apps/$SERVICE_NAME/storage/paybox:ro +" diff --git a/opensem/metadata.yml b/opensem/metadata.yml index cc51332..ae111ff 100644 --- a/opensem/metadata.yml +++ b/opensem/metadata.yml @@ -74,3 +74,11 @@ uses: solves: unmanaged-logs: "in docker logs" #default-options: + paybox-system: + #constraint: required | recommended | optional + #auto: pair | summon | none ## default: pair + constraint: required + auto: pair + solves: + missing-payment: "credit card payment" + #default-options: