diff options
author | 2021-02-08 16:19:30 +0000 | |
---|---|---|
committer | 2021-02-08 16:19:30 +0000 | |
commit | f706e2f0f401c26a507f38b13c6f6bac7f6594bb (patch) | |
tree | 379bf9d05f1bd2b2d6564cb2f620443db04b895b /consul-loader-container/consul_store.sh | |
parent | d6f51329c094b7264a9aebdbb76496b40966ce6b (diff) | |
parent | b65d4c1fc374af0f4b3bb5ea55641efd88f65ab3 (diff) |
Merge "Add yaml load and key delete to consul-loader-container"4.2.0-cm-container1.1.0-consul-loader-container
Diffstat (limited to 'consul-loader-container/consul_store.sh')
-rwxr-xr-x | consul-loader-container/consul_store.sh | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/consul-loader-container/consul_store.sh b/consul-loader-container/consul_store.sh index 4e64fc3..e60dbc4 100755 --- a/consul-loader-container/consul_store.sh +++ b/consul-loader-container/consul_store.sh @@ -1,6 +1,7 @@ #!/bin/bash # ================================================================================ # Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. +# Copyright (c) 2021 J. F. Lucas. All rights reserved. # ================================================================================ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -25,6 +26,11 @@ # Command line options # --service name|address|port : Register a service with name 'name', address 'address', and port 'port'. # --key keyname|filepath: Register a key-value pair with key 'keyname' and the contents of a file at 'filepath' as its value +# --key-yaml keyname|filepath: Register a key-value pair with name 'keyname', converting the YAML content of the file at 'filepath' +# to JSON, and storing the JSON result as the value. This is used for Helm deployment of DCAE microservices, where the initial +# application configuration is stored in a Helm values.yaml file in YAML form. --key-yaml converts the YAML configuration into +# JSON, which is the format that microservices expect. +# -- delete-key # A command can include multiple instances of each option. CONSUL_ADDR=${CONSUL_PROTO:-http}://${CONSUL_HOST:-consul}:${CONSUL_PORT:-8500} @@ -48,6 +54,12 @@ function put_key { curl -v -X PUT --data-binary @$2 -H 'Content-Type: application/json' ${KV_URL}/$1 } +# Delete a key from the Consul KV store +# $1: Key to be deleted +function delete_key { + curl -v -X DELETE ${KV_URL}/$1 +} + set -x # Check Consul readiness @@ -86,6 +98,16 @@ do put_key ${kv[@]} shift 2; ;; + "--key-yaml") + # See above for explanation of (${2//|/ }) + kv=(${2//|/ }) + cat ${kv[1]} | /opt/app/yaml2json.py | put_key ${kv[0]} - + shift 2; + ;; + "--delete-key") + delete_key $2 + shift 2; + ;; *) echo "ignoring $1" shift |