diff --git a/smartgears/smartgears/templates/get-scopes.j2 b/smartgears/smartgears/templates/get-scopes.j2 index bf427956..614ac2d7 100644 --- a/smartgears/smartgears/templates/get-scopes.j2 +++ b/smartgears/smartgears/templates/get-scopes.j2 @@ -52,39 +52,35 @@ check_merge_scopes_behaviour() { USE_SAVED_STATE=0 if [ $SMARTGEARS_MERGE_SCOPES == 'True' ] ; then USE_SAVED_STATE=0 - logger "$LOG_PREFIX smartgears_merge_scopes set to True by the caller." + logger "$LOG_PREFIX check_merge_scopes_behaviour: smartgears_merge_scopes set to True by the caller." elif [ $SMARTGEARS_MERGE_SCOPES == 'False' ] ; then USE_SAVED_STATE=1 - logger "$LOG_PREFIX smartgears_merge_scopes set to False by the caller." + logger "$LOG_PREFIX check_merge_scopes_behaviour: smartgears_merge_scopes set to False by the caller." else - logger "$LOG_PREFIX smartgears_merge_scopes set to a not correct value. Assuming True" - fi -} - -check_token_presence() { - if [ $# -ge 1 ] ; then - # Ignore anything other than the first parameter - logger "$LOG_PREFIX We have an authorization token" - TOKEN=$1 + logger "$LOG_PREFIX check_merge_scopes_behaviour: smartgears_merge_scopes set to a not correct value. Assuming True." fi } check_smartgears_state_presence() { if [ ! -f $SMARTGEARS_RUNNING_STATE_FILE ] ; then USE_SAVED_STATE=1 - logger "$LOG_PREFIX No state file, it was removed or it is a first installation. We need a token to proceed successfully from now on." + logger "$LOG_PREFIX check_smartgears_state_presence: No state file, it was removed or it is a first installation. We need a token to proceed successfully from now on." + else + logger "$LOG_PREFIX check_smartgears_state_presence: There is a local state." fi } decide_how_to_proceed() { if [ -z $TOKEN ] ; then if [ ! -f $SMARTGEARS_RUNNING_STATE_FILE ] ; then - logger "$LOG_PREFIX No token no local state. Maybe a first installation. Aborting." + logger "$LOG_PREFIX decide_how_to_proceed: No token no local state. Maybe a first installation. Aborting." exit 1 - elif [ USE_SAVED_STATE -eq 1 ] ; then - logger "$LOG_PREFIX No token and we do not want to merge the local state. Doing nothing." + elif [ $USE_SAVED_STATE -eq 1 ] ; then + logger "$LOG_PREFIX decide_how_to_proceed: No token and we do not want to merge the local state. Doing nothing." exit 0 fi + else + logger "$LOG_PREFIX decide_how_to_proceed: Got a token. We are going to request tokens from the authorisation service." fi } @@ -93,19 +89,20 @@ load_the_scopes_list_from_file() { SCOPES_LIST="" if [ -f $LOCAL_ETC/scopes.list ] ; then . $LOCAL_ETC/scopes.list + logger "$LOG_PREFIX load_the_scopes_list_from_file: A token was provided." else - logger "$LOG_PREFIX There is no scopes list file, this should never happen. Aborting." + logger "$LOG_PREFIX load_the_scopes_list_from_file: There is no scopes list file, this should never happen. Aborting." exit 1 fi else # If no token was provided, we cannot use the file with the list of provided scopes - logger "$LOG_PREFIX load_the_scopes_list_from_file. No token was provided, not loading the scopes list file" + logger "$LOG_PREFIX load_the_scopes_list_from_file: No token was provided, not loading the scopes list file." fi } get_scopes_from_auth() { # We have a token and a list of scopes names. Get the scope tokens for them. - logger "$LOG_PREFIX get_scopes_from_auth. We have a token and a list of scopes names. Get the scope tokens for them." + logger "$LOG_PREFIX get_scopes_from_auth: get_scopes_from_auth. We have a token and a list of scopes names. Get the scope tokens for them." for jar in $( ls -1 /home/gcube/tomcat/lib/ ) ; do export CLASSPATH="/home/gcube/SmartGears/lib/${jar}:$CLASSPATH" done @@ -117,9 +114,9 @@ get_scopes_from_auth() { {% endif %} RETVAL=$? if [ $RETVAL -eq 0 ] ; then - logger "$LOG_PREFIX get_scopes_from_auth. We got the scope tokens." + logger "$LOG_PREFIX get_scopes_from_auth: We got the scope tokens." else - logger "$LOG_PREFIX get_scopes_from_auth. Unable to obtain the scope tokens, aborting." + logger "$LOG_PREFIX get_scopes_from_auth: Unable to obtain the scope tokens, aborting." exit 1 fi } @@ -127,7 +124,7 @@ get_scopes_from_auth() { get_scopes_from_local_state() { if [ ! -f $SMARTGEARS_RUNNING_STATE_FILE ] ; then USE_SAVED_STATE=1 - logger "$LOG_PREFIX No state file, it was removed or it is a first installation. Skip the request for the local state, do not merge the local state." + logger "$LOG_PREFIX get_scopes_from_local_state: No state file, it was removed or it is a first installation. Skip the request for the local state, do not merge the local state." return 0 fi # Get the scopes from the local state @@ -137,8 +134,9 @@ get_scopes_from_local_state() { RETVAL=$? if [ $RETVAL -ne 0 ] ; then # We were not able to get the running state from the IS. Try to get new scope tokens - logger "$LOG_PREFIX We were not able to get the running state from the IS." + logger "$LOG_PREFIX get_scopes_from_local_state: We were not able to get the running state from the IS." fi + logger "$LOG_PREFIX get_scopes_from_local_state: Got the scopes." } get_scopes() { @@ -153,31 +151,43 @@ get_scopes() { assemble_the_container_xml_file() { # Now that we have the tokens, we can assemble the container.xml file + logger "$LOG_PREFIX assemble_the_container_xml_file: Start assembling the container.xml file." chmod 640 $CONTAINER_XML_FILE if [ ! -z $TOKEN ] && [ $USE_SAVED_STATE -eq 0 ] ; then CREATE_CONTAINER_XML=$( cat $CONTAINER_XML_HEAD $SCOPES_FILE $SMARTGEARS_SAVED_STATE_PATH $CONTAINER_XML_TAIL > $CONTAINER_XML_FILE ) CREATE_CONTAINER_XML_RES=$? + logger "$LOG_PREFIX $CONTAINER_XML_FILE assemble_the_container_xml_file: Merge the scopes obtained from the authorisation service with the local state." elif [ ! -z $TOKEN ] && [ $USE_SAVED_STATE -eq 1 ] ; then CREATE_CONTAINER_XML=$( cat $CONTAINER_XML_HEAD $SCOPES_FILE $CONTAINER_XML_TAIL > $CONTAINER_XML_FILE ) CREATE_CONTAINER_XML_RES=$? + logger "$LOG_PREFIX $CONTAINER_XML_FILE assemble_the_container_xml_file: Use the scopes obtained from the authorisation service." elif [ -z $TOKEN ] && [ $USE_SAVED_STATE -eq 0 ] ; then CREATE_CONTAINER_XML=$( cat $CONTAINER_XML_HEAD $SMARTGEARS_SAVED_STATE_PATH $CONTAINER_XML_TAIL > $CONTAINER_XML_FILE ) CREATE_CONTAINER_XML_RES=$? + logger "$LOG_PREFIX $CONTAINER_XML_FILE assemble_the_container_xml_file: Use the scopes from the local state." fi if [ $CREATE_CONTAINER_XML_RES -ne 0 ] ; then - logger "$LOG_PREFIX $CONTAINER_XML_FILE cannot be updated. Error is $CREATE_CONTAINER_XML" + logger "$LOG_PREFIX assemble_the_container_xml_file: $CONTAINER_XML_FILE cannot be updated. Error is $CREATE_CONTAINER_XML" exit $CREATE_CONTAINER_XML_RES fi chmod 440 $CONTAINER_XML_FILE - logger "$LOG_PREFIX $CONTAINER_XML_FILE updated" + logger "$LOG_PREFIX $CONTAINER_XML_FILE assemble_the_container_xml_file: updated" } ############ # # Main # +# check_token_presence +if [ $# -gt 0 ] ; then + # Ignore anything other than the first parameter + logger "$LOG_PREFIX check_token_presence: We have an authorization token." + TOKEN=$1 +else + logger "$LOG_PREFIX check_token_presence: # of arguments is $#. No token." +fi + check_merge_scopes_behaviour -check_token_presence check_smartgears_state_presence decide_how_to_proceed get_scopes