#!/bin/sh

export SGA_NAME="chuva"
export SGA_BASE_URL="http://localhost:12345"

case "$1" in

job)
   curl -v -H "Content-Type: application/json" -X POST -d '{
      "cmd_string": "bash -c \"echo user token: \\$CSBASE_USER_TOKEN \" && sleep 10 && echo bye",
      "cmd_id": "job_123",
      "parameters": {
         "csbase_command_path": "/tmp",
         "csbase_command_root_path":"/tmp",
         "csbase_command_output_path":"/tmp",
         "csbase_command_sandbox_paths.1":"/tmp/job_123",
         "csbase_command_user_token":"USER_TOKEN",
      }
   }' -H "Authorization: Bearer <token>" $SGA_BASE_URL'/v1/sga/'$SGA_NAME'/job'
   ;;

status)
   num=$2
   if [ -z "$num" ]
   then
      num=123
   fi
   curl -H "Authorization: Bearer <token>" -v $SGA_BASE_URL'/v1/sga/'$SGA_NAME'/job/'$num'/status'
   ;;
   
path)
   curl -H "Authorization: Bearer <token>" -v $SGA_BASE_URL'/v1/sga/'$SGA_NAME'/path?name='$2
   ;;
   
esac

echo
