diff options
author | Jose Bollo <jose.bollo@iot.bzh> | 2020-01-03 18:36:02 +0100 |
---|---|---|
committer | Jose Bollo <jose.bollo@iot.bzh> | 2020-03-09 10:43:49 +0100 |
commit | 275f7f5b9d2b148ae61da39c87f81c75974ab31f (patch) | |
tree | b4ab41c7357c1a47a441e16395a87183beab22cd /scripts | |
parent | 9a0d792982ae637dd32e6939724441fe1b5fb47d (diff) |
Allow to set the user in queriessandbox/jobol/uids
Instead of enforcing administrator to log as
user, allow him to explicitely tell the uid of
the application to launch or browse.
This change also includes a refactor of how
parameters are scanned.
Bug-AGL: SPEC-3085
Change-Id: Id2c4e6ccfc0a59f3ec694ec45afc1f35496273e6
Signed-off-by: Jose Bollo <jose.bollo@iot.bzh>
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/afm-util.in | 44 |
1 files changed, 29 insertions, 15 deletions
diff --git a/scripts/afm-util.in b/scripts/afm-util.in index 2cc714b..4594685 100755 --- a/scripts/afm-util.in +++ b/scripts/afm-util.in @@ -1,10 +1,29 @@ #!/bin/bash send() { - afb-client-demo -H -d unix:@afm_platform_rundir@/apis/ws/afm-main "$1" "$2" | - awk '$1=="ON-REPLY" && $3!="success"{$1="ERROR:";$2="";print > "/dev/stderr";exit 1;}NR>1' + local verb="$1" + afb-client-demo -H -d unix:@afm_platform_rundir@/apis/ws/afm-main "$verb" "$2" | + awk '$1=="ON-REPLY" && $3!="success"{$1="ERROR:";$2="";print > "/dev/stderr";exit 1;}NR>1' } +all=false +force=false +uid="$UID" +help=false + +set -- $(getopt -l all,force,help,uid: -s afhu: -n afm-util -- "$@") +while : +do + case "$1" in + -a|--all) all=true; shift;; + -f|--force) force=true; shift;; + -h|--help) help=true; shift;; + -u|--uid) uid="$2"; shift 2;; + --) shift; break;; + *) help=true; break;; + esac +done + getall() { case "$1" in -a|--all) echo -n '{"all":true}';; @@ -15,14 +34,14 @@ getall() { case "$1" in list|runnables) - send runnables $(getall $2) + send runnables "{\"all\":$all,\"uid\":$uid}" ;; add|install) f=$(realpath $2) r=true if [[ "$(basename $0)" = "afm-install" ]]; then r=false; fi - send install '{"wgt":"'"$f"'","force":true,"reload":'"$r"'}' + send install "{\"wgt\":\"$f\",\"force\":$force,\"reload\":$r}" ;; remove|uninstall) @@ -32,36 +51,31 @@ case "$1" in info|detail) i=$2 - send detail "\"$i\"" + send detail "{\"id\":$i,\"uid\":$uid}" ;; ps|runners) - send runners $(getall $2) + send runners "{\"all\":$all,\"uid\":$uid}" ;; run|start) i=$2 - send start "\"$i\"" - ;; - - run-remote|start-remote) - i=$2 - send start '{"id":"'"$i"'","mode":"remote"}' + send start "{\"id\":$i,\"uid\":$uid}" ;; once) i=$2 - send once "\"$i\"" + send once "{\"id\":$i,\"uid\":$uid}" ;; terminate|kill) i=$2 - send terminate "$i" + send terminate "{\"runid\":$i,\"uid\":$uid}" ;; state|status) i=$2 - send state "$i" + send state "{\"runid\":$i,\"uid\":$uid}" ;; -h|--help|help) |