From 275f7f5b9d2b148ae61da39c87f81c75974ab31f Mon Sep 17 00:00:00 2001 From: Jose Bollo Date: Fri, 3 Jan 2020 18:36:02 +0100 Subject: Allow to set the user in queries 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 --- scripts/afm-util.in | 44 +++++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 15 deletions(-) (limited to 'scripts') 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) -- cgit 1.2.3-korg