Skip to content

Commit

Permalink
WIP: Added -A and REACTOR_TOKENS support
Browse files Browse the repository at this point in the history
  • Loading branch information
mwvaughn committed Aug 7, 2019
1 parent 893bbac commit 91d635c
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 7 deletions.
9 changes: 7 additions & 2 deletions abaco-create.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Options:
-f force actor update
-s create a stateless actor (default)
-S create a stateful actor
-A disable creation of Tapis tokens
-u use actor uid
-v verbose output
-V very verbose output
Expand All @@ -41,11 +42,12 @@ privileged="false"
stateless="true"
force="false"
use_uid="false"
request_token="true"
tok=
env_json=
declare -a env_args

while getopts ":hn:e:E:pfsSuvz:V" o; do
while getopts ":hn:e:E:pfsSuvz:AV" o; do
case "${o}" in
z) # custom token
tok=${OPTARG}
Expand All @@ -71,6 +73,9 @@ while getopts ":hn:e:E:pfsSuvz:V" o; do
S) # stateful!
stateless="false"
;;
A) # do not request tokens
request_token="false"
;;
u) # use uid
use_uid="true"
;;
Expand Down Expand Up @@ -118,7 +123,7 @@ args_default_env=$(build_json_from_array "${env_args[@]}")
default_env=$(echo "$file_default_env $args_default_env" | jq -s add)

# curl command
data="{\"image\":\"${image}\", \"name\":\"${name}\", \"privileged\":${privileged}, \"stateless\":${stateless}, \"force\":${force}, \"useContainerUid\":${use_uid}, \"defaultEnvironment\":${default_env}}"
data="{\"image\":\"${image}\", \"name\":\"${name}\", \"privileged\":${privileged}, \"stateless\":${stateless}, \"force\":${force}, \"useContainerUid\":${use_uid}, \"defaultEnvironment\":${default_env}, \"token\":${request_token}}"
curlCommand="curl -X POST -sk -H \"Authorization: Bearer $TOKEN\" -H \"Content-Type: application/json\" --data '$data' '$BASE_URL/actors/v2'"

function filter() {
Expand Down
27 changes: 25 additions & 2 deletions abaco-deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ Options:
-t override file REACTOR_IMAGE_VERSION
-s override REACTOR_STATEFUL to deploy the actor as stateless
-S override REACTOR_STATEFUL to deploy the actor as stateful
-A override REACTOR_TOKENS to deploy actor without Tapis tokens
-p don't pull source image when building
-k bypass Docker cache when building
-K skip pushing to the container registry
-R dry run - only build image
-U update preexisting actor (provided or from .ACTOR_ID)
-D display only (do not cache actor ID on the host)
-R dry run - build container image and stop
"

function usage() {
Expand Down Expand Up @@ -71,10 +72,12 @@ displayonly=0
stateful=0
varstateful=
optstateful=
opt_no_token=0
no_tokens=0
verbose=0

current_actor=
while getopts ":hz:F:B:RpkUkKsvSDO:c:t:" o; do
while getopts ":hz:F:B:RpkUkKsvSDAO:c:t:" o; do
case "${o}" in
z) # API token
tok=${OPTARG}
Expand Down Expand Up @@ -115,6 +118,9 @@ while getopts ":hz:F:B:RpkUkKsvSDO:c:t:" o; do
S) # stateful
optstateful=1
;;
A) # disable tokens
opt_no_token=1
;;
D) # display only
displayonly=1
;;
Expand Down Expand Up @@ -207,6 +213,7 @@ REACTOR_DESCRIPTION=
REACTOR_STATEFUL=
REACTOR_PRIVILEGED=
REACTOR_USE_UID=
REACTOR_TOKENS=

# Docker image
DOCKER_HUB_ORG=
Expand Down Expand Up @@ -243,6 +250,17 @@ if [ -z "${REACTOR_NAME}" ]; then
echo "${REACTOR_NAME}"
fi

# Whether to automatically request API tokens
if [ "${REACTOR_TOKENS}" == "1" ]; then
# Read default from config file
# Do not disable in abaco create/update
no_tokens=0
fi
# If CLI option was passed, disable in abaco create/update
if ((opt_no_token)); then
no_tokens=1
fi

# Read STATEFUL from config
if [ "${REACTOR_STATEFUL}" == "1" ]; then
stateful=1
Expand Down Expand Up @@ -330,6 +348,11 @@ if [ "${REACTOR_USE_UID}" == "1" ]; then
ABACO_CREATE_OPTS="$ABACO_CREATE_OPTS -u"
fi

# Pass -A to create if token issuance is to be disabled
if ((no_tokens)); then
ABACO_CREATE_OPTS="$ABACO_CREATE_OPTS -A"
fi

# If updating, do not include name or stateless
if [ -z "$current_actor" ]; then
ABACO_CREATE_OPTS="$ABACO_CREATE_OPTS -n ${REACTOR_NAME}"
Expand Down
1 change: 1 addition & 0 deletions abaco-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ cat <<EOF >"${basepath}/${name}/reactor.rc"
# Reactor mandatory settings
REACTOR_NAME=${name}
REACTOR_DESCRIPTION="${description}"
REACTOR_TOKENS=1
REACTOR_PRIVILEGED=
REACTOR_USE_UID=
REACTOR_STATEFUL=
Expand Down
11 changes: 8 additions & 3 deletions abaco-update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ Options:
-e set environment variables (key=value)
-E read environment variables from json file
-p add privileged status
-f force update
-A disable creation of Tapis tokens
-u use actor uid
-f force update
-v verbose output
-V very verbose output
"
Expand All @@ -37,11 +38,12 @@ privileged="false"
stateless="true"
force="false"
use_uid="false"
request_token="true"
tok=

# the s and S opts are here to swallow them when passed - we do not allow
# toggling between stateless and stateful via an update operation
while getopts ":he:E:pfsSuvz:V" o; do
while getopts ":he:E:pfsSAuvz:V" o; do
case "${o}" in
z) # custom token
tok=${OPTARG}
Expand All @@ -64,6 +66,9 @@ while getopts ":he:E:pfsSuvz:V" o; do
S) # stateful!
stateless="false"
;;
A) # do not request tokens
request_token="false"
;;
u) # use uid
use_uid=true
;;
Expand Down Expand Up @@ -113,7 +118,7 @@ stateless=$(${DIR}/abaco ls -v ${actorid} | jq -r .result.stateless)

# curl command
# \"stateless\":\"${stateless}\",
data="{\"stateless\":\"${stateless}\", \"image\":\"${image}\", \"privileged\":${privileged}, \"force\":${force}, \"useContainerUid\":${use_uid}, \"defaultEnvironment\":${default_env}}"
data="{\"stateless\":\"${stateless}\", \"image\":\"${image}\", \"privileged\":${privileged}, \"force\":${force}, \"useContainerUid\":${use_uid}, \"defaultEnvironment\":${default_env}, \"token\":${request_token}}"
curlCommand="curl -X PUT -sk -H \"Authorization: Bearer $TOKEN\" -H \"Content-Type: application/json\" --data '$data' '$BASE_URL/actors/v2/${actorid}'"

function filter() {
Expand Down

0 comments on commit 91d635c

Please sign in to comment.