TT#77256 ngcp-api-tools: Use /etc/default/ngcp-api if no user cred file exists

This unifies these tools from the ones in the ngcp-api-tools package.
We also remove the hardcoded credentials from the scripts, as a best
practice.

Change-Id: I749f008ef5c45c3cd770432fde56cca7f8624d19
changes/55/39055/4
Guillem Jover 5 years ago
parent 1fffc52f3e
commit f729ec056d

@ -4,6 +4,7 @@ set -e
importcreds () {
local CREDS=$1
local PERMS=${2:-0600}
if [ -z "${CREDS}" ]; then
echo "Error: missing mandatory file name to read" >&2
@ -20,11 +21,11 @@ importcreds () {
fi
echo "${CREDS} present, checking perms"
if stat "${CREDS}" | grep -q 'Access: (0600' 1>/dev/null ; then
if stat "${CREDS}" | grep -q "Access: (${PERMS}" 1>/dev/null ; then
echo "${CREDS} permissions ok"
. "${CREDS}"
else
echo "Error: ${CREDS} must have permissions 600" >&2
echo "Error: ${CREDS} must have permissions ${PERMS}" >&2
exit 1
fi
}

@ -1,6 +1,7 @@
#!/bin/bash
CURL="/usr/bin/curl"
CREDS="${HOME}/.ngcp-api"
SYSCREDS="/etc/default/ngcp-api"
USERCREDS="${HOME}/.ngcp-api"
TOOLS="/usr/share/ngcp-panel-tools/ngcp-api.inc"
usage () {
@ -19,9 +20,16 @@ EOF
if [ -z "${APIUSER}" ]; then
if [ -f "${TOOLS}" ]; then
source "${TOOLS}"
importcreds "${CREDS}"
else
APIUSER="administrator:administrator"
importcreds "${USERCREDS}" 0600
if [ -z "${APIUSER}" ]; then
importcreds "${SYSCREDS}" 0440
APIUSER="${AUTH_SYSTEM_LOGIN}:${AUTH_SYSTEM_PASSWORD}"
fi
fi
if [ -z "${APIUSER}" ]; then
echo "Error: no authentication credentials found" >&2
exit 1
fi
fi

@ -1,6 +1,7 @@
#!/bin/bash
CURL="/usr/bin/curl"
CREDS="${HOME}/.ngcp-api"
SYSCREDS="/etc/default/ngcp-api"
USERCREDS="${HOME}/.ngcp-api"
TOOLS="/usr/share/ngcp-panel-tools/ngcp-api.inc"
usage () {
@ -19,9 +20,16 @@ EOF
if [ -z "${APIUSER}" ]; then
if [ -f "${TOOLS}" ]; then
source "${TOOLS}"
importcreds "${CREDS}"
else
APIUSER="administrator:administrator"
importcreds "${USERCREDS}" 0600
if [ -z "${APIUSER}" ]; then
importcreds "${SYSCREDS}" 0440
APIUSER="${AUTH_SYSTEM_LOGIN}:${AUTH_SYSTEM_PASSWORD}"
fi
fi
if [ -z "${APIUSER}" ]; then
echo "Error: no authentication credentials found" >&2
exit 1
fi
fi

@ -1,6 +1,7 @@
#!/bin/bash
CURL="/usr/bin/curl"
CREDS="${HOME}/.ngcp-api"
SYSCREDS="/etc/default/ngcp-api"
USERCREDS="${HOME}/.ngcp-api"
TOOLS="/usr/share/ngcp-panel-tools/ngcp-api.inc"
usage () {
@ -21,9 +22,16 @@ EOF
if [ -z "${APIUSER}" ]; then
if [ -f "${TOOLS}" ]; then
source "${TOOLS}"
importcreds "${CREDS}"
else
APIUSER="administrator:administrator"
importcreds "${USERCREDS}" 0600
if [ -z "${APIUSER}" ]; then
importcreds "${SYSCREDS}" 0440
APIUSER="${AUTH_SYSTEM_LOGIN}:${AUTH_SYSTEM_PASSWORD}"
fi
fi
if [ -z "${APIUSER}" ]; then
echo "Error: no authentication credentials found" >&2
exit 1
fi
fi
INPUT=(-T -)

@ -1,6 +1,7 @@
#!/bin/bash
CURL="/usr/bin/curl"
CREDS="${HOME}/.ngcp-api"
SYSCREDS="/etc/default/ngcp-api"
USERCREDS="${HOME}/.ngcp-api"
TOOLS="/usr/share/ngcp-panel-tools/ngcp-api.inc"
usage () {
@ -20,9 +21,16 @@ EOF
if [ -z "${APIUSER}" ]; then
if [ -f "${TOOLS}" ]; then
source "${TOOLS}"
importcreds "${CREDS}"
else
APIUSER="administrator:administrator"
importcreds "${USERCREDS}" 0600
if [ -z "${APIUSER}" ]; then
importcreds "${SYSCREDS}" 0440
APIUSER="${AUTH_SYSTEM_LOGIN}:${AUTH_SYSTEM_PASSWORD}"
fi
fi
if [ -z "${APIUSER}" ]; then
echo "Error: no authentication credentials found" >&2
exit 1
fi
fi
INPUT=(-T -)

@ -1,6 +1,7 @@
#!/bin/bash
CURL="/usr/bin/curl"
CREDS="${HOME}/.ngcp-api"
SYSCREDS="/etc/default/ngcp-api"
USERCREDS="${HOME}/.ngcp-api"
TOOLS="/usr/share/ngcp-panel-tools/ngcp-api.inc"
usage () {
@ -20,9 +21,16 @@ EOF
if [ -z "${APIUSER}" ]; then
if [ -f "${TOOLS}" ]; then
source "${TOOLS}"
importcreds "${CREDS}"
else
APIUSER="administrator:administrator"
importcreds "${USERCREDS}" 0600
if [ -z "${APIUSER}" ]; then
importcreds "${SYSCREDS}" 0440
APIUSER="${AUTH_SYSTEM_LOGIN}:${AUTH_SYSTEM_PASSWORD}"
fi
fi
if [ -z "${APIUSER}" ]; then
echo "Error: no authentication credentials found" >&2
exit 1
fi
fi
INPUT=(-T -)

Loading…
Cancel
Save