diff --git a/confluent_osdeploy/common/profile/scripts/functions b/confluent_osdeploy/common/profile/scripts/functions index 4b17d3ad..92069e6b 100644 --- a/confluent_osdeploy/common/profile/scripts/functions +++ b/confluent_osdeploy/common/profile/scripts/functions @@ -29,6 +29,39 @@ function confluentpython() { fi } +# Print a node attribute, e.g. 'confluent_attrib custom.foo'. Returns 1 if unset. +function confluent_attrib() { + if [ -z "$1" ]; then + echo "Usage: confluent_attrib " >&2 + return 2 + fi + local apiclient=/opt/confluent/bin/apiclient + if [ -f /etc/confluent/apiclient ]; then + apiclient=/etc/confluent/apiclient + fi + # program on stdin, data on fd 3: confluentpython splits its args + confluentpython - "$1" 3< <(confluentpython $apiclient /confluent-api/self/myattribs -j) <<'EOF' +import json +import os +import sys +try: + attribs = json.load(os.fdopen(3)) +except ValueError: + sys.stderr.write('Unable to retrieve node attributes\n') + sys.exit(2) +value = attribs.get(sys.argv[1], None) +if value is None or value == '': + sys.exit(1) +if isinstance(value, list): + value = u','.join(value) +if not isinstance(value, str): + value = u'{0}'.format(value) +if sys.version_info[0] < 3: + value = value.encode('utf8') +sys.stdout.write(value + '\n') +EOF +} + function set_confluent_vars() { if [ -z "$nodename" ]; then nodename=$(grep ^NODENAME: /etc/confluent/confluent.info | awk '{print $2}') diff --git a/confluent_osdeploy/genesis/profiles/default/scripts/functions b/confluent_osdeploy/genesis/profiles/default/scripts/functions index 97c3d54d..5c118165 100644 --- a/confluent_osdeploy/genesis/profiles/default/scripts/functions +++ b/confluent_osdeploy/genesis/profiles/default/scripts/functions @@ -12,6 +12,39 @@ function confluentpython() { fi } +# Print a node attribute, e.g. 'confluent_attrib custom.foo'. Returns 1 if unset. +function confluent_attrib() { + if [ -z "$1" ]; then + echo "Usage: confluent_attrib " >&2 + return 2 + fi + local apiclient=/opt/confluent/bin/apiclient + if [ -f /etc/confluent/apiclient ]; then + apiclient=/etc/confluent/apiclient + fi + # program on stdin, data on fd 3: confluentpython splits its args + confluentpython - "$1" 3< <(confluentpython $apiclient /confluent-api/self/myattribs -j) <<'EOF' +import json +import os +import sys +try: + attribs = json.load(os.fdopen(3)) +except ValueError: + sys.stderr.write('Unable to retrieve node attributes\n') + sys.exit(2) +value = attribs.get(sys.argv[1], None) +if value is None or value == '': + sys.exit(1) +if isinstance(value, list): + value = u','.join(value) +if not isinstance(value, str): + value = u'{0}'.format(value) +if sys.version_info[0] < 3: + value = value.encode('utf8') +sys.stdout.write(value + '\n') +EOF +} + function set_confluent_vars() { if [ -z "$nodename" ]; then nodename=$(grep ^NODENAME: /etc/confluent/confluent.info | awk '{print $2}') diff --git a/confluent_server/confluent/selfservice.py b/confluent_server/confluent/selfservice.py index 350107da..7b678b31 100644 --- a/confluent_server/confluent/selfservice.py +++ b/confluent_server/confluent/selfservice.py @@ -275,7 +275,13 @@ async def handle_request(req, make_response, mimetype): cfd = cfg.get_node_attributes(nodename, '*', decrypt=True).get(nodename, {}) rsp = {} for k in cfd: - if k.startswith('secret') or k.startswith('crypt') or 'value' not in cfd[k] or not cfd[k]['value']: + if k.startswith('secret') or k.startswith('crypt'): + continue + if isinstance(cfd[k], list): + if cfd[k]: + rsp[k] = cfd[k] + continue + if 'value' not in cfd[k] or not cfd[k]['value']: continue rsp[k] = cfd[k]['value'] if isinstance(rsp[k], bytes):