[pve-devel] [PATCH 3/3] Implement functions setup and teardown. We use these functions for adding and removing a txt record through the dnsapi.

Wolfgang Link w.link at proxmox.com
Tue Nov 5 13:44:29 CET 2019


---
 src/proxmox-acme/proxmox-acme | 78 +++++++++++++++++++++++++++++++++++
 1 file changed, 78 insertions(+)

diff --git a/src/proxmox-acme/proxmox-acme b/src/proxmox-acme/proxmox-acme
index 662c39a..6da9436 100644
--- a/src/proxmox-acme/proxmox-acme
+++ b/src/proxmox-acme/proxmox-acme
@@ -1,5 +1,12 @@
 #!/usr/bin/env sh
 
+VER=0.9
+
+PROJECT_NAME="ProxmoxACME"
+
+USER_AGENT="$PROJECT_NAME/$VER"
+
+DNS_PLUGIN_PATH="/var/lib/proxmox-acme/dnsapi"
 HTTP_HEADER="$(mktemp)"
 
 _base64() {
@@ -568,3 +575,74 @@ _source_plugin_config() {
   return
 }
 
+# Proxmox implementation
+_load_plugin_config() {
+
+  tmp_str="${plugin_conf_sting//[^,]}"
+  index="$(_math ${#tmp_str} + 1)"
+
+  while [ "$index" -gt "0" ]
+  do
+      field=$(_getfield $plugin_conf_sting "$index" ",")
+      key=$(_getfield $field 1 "=")
+      value=$(_getfield $field 2 "=")
+      eval "$key"="$value"
+
+      index="$(_math "$index" - 1)"
+  done
+
+}
+
+setup() {
+  dns_plugin="dns_$1"
+  dns_plugin_path="${DNS_PLUGIN_PATH}/${dns_plugin}.sh"
+  fqdn="_acme-challenge.$2"
+  txtvalue=$3
+  plugin_conf_sting=$4
+
+  _load_plugin_config
+
+  if ! . "$dns_plugin_path"; then
+    _err "Load file $dns_plugin error."
+    return 1
+  fi
+
+  addcommand="${dns_plugin}_add"
+  if ! _exists "$addcommand"; then
+    _err "It seems that your api file is not correct, it must have a function named: $addcommand"
+    return 1
+  fi
+
+  if ! $addcommand "$fqdn" "$txtvalue"; then
+    _err "Error add txt for domain:$fulldomain"
+    return 1
+  fi
+}
+
+teardown() {
+  dns_plugin="dns_$1"
+  dns_plugin_path="${DNS_PLUGIN_PATH}/${dns_plugin}.sh"
+  fqdn="_acme-challenge.$2"
+  txtvalue=$3
+  plugin_conf_sting=$4
+
+  _load_plugin_config
+
+  if ! . "$dns_plugin_path"; then
+    _err "Load file $dns_plugin error."
+    return 1
+  fi
+
+  rmcommand="${dns_plugin}_rm"
+  if ! _exists "$rmcommand"; then
+    _err "It seems that your api file is not correct, it must have a function named: $rmcommand"
+    return 1
+  fi
+
+  if ! $rmcommand "$fqdn" "$txtvalue"; then
+    _err "Error add txt for domain:$fulldomain"
+    return 1
+  fi
+}
+
+"$@"
-- 
2.20.1





More information about the pve-devel mailing list