#!/bin/sh 

# geni s6_run_query
# using aba_prover_yap

echo "=====================s6_run_query=================="

pwd=`pwd`

eloc=`which abac_prover_yap | sed 's/\/abac_prover_yap//'`
if [ "$eloc" = "" ]; then
  echo "ERROR: abac_prover_yap is not in the search path!!!"
  exit 1
fi

keyloc=$pwd

g=`creddy --keyid --cert $keyloc/G_ID.pem`
pa=`creddy --keyid --cert $keyloc/PA_ID.pem`
sa=`creddy --keyid --cert $keyloc/SA_ID.pem`

drd=`creddy --keyid --cert $keyloc/Drd_ID.pem`
frank=`creddy --keyid --cert $keyloc/Frank_ID.pem`
dan=`creddy --keyid --cert $keyloc/Dan_ID.pem`
alice=`creddy --keyid --cert $keyloc/Alice_ID.pem`

## dump all credentials 
env ABAC_CN=1 $eloc/abac_prover_yap  --keystore $keyloc --dump s6_creds_dump

# [keyid:SA].role:controlsQ("sliceA","info") <-?- [keyid:Frank]
#  runControlsQ Frank $frank good bad
runControlsQ() {
   id=$2
   role="[keyid:$sa].role:controlsQ([string:'sliceA'],[string:'info'])"
   prin="[keyid:$id]"
   echo "\n\n===$3============ SA.controlsQ('sliceA','info') <-?- $1"
   $eloc/abac_prover_yap --keystore $keyloc --role "$role" --principal "$prin"

   role="[keyid:$sa].role:controlsQ([string:'sliceA'],[string:'stop'])"
   prin="[keyid:$id]"
   echo "\n===$4============ SA.controlsQ('sliceA','stop') <-?- $1"
   $eloc/abac_prover_yap --keystore $keyloc --role "$role" --principal "$prin"
}


runControlsQ Drd $drd good good
runControlsQ Frank $frank good bad
runControlsQ Dan $dan bad bad
runControlsQ Alice $alice good good

echo "\n\n"


