Added JWT handling to a1pms
[nonrtric.git] / test / common / ics_api_functions.sh
index a18bf72..0c067ca 100644 (file)
@@ -89,6 +89,7 @@ __ICS_store_docker_logs() {
 # args: -
 __ICS_initial_setup() {
        use_ics_rest_http
+       export ICS_SIDECAR_JWT_FILE=""
 }
 
 # Set app short-name, app name and namespace for logging runtime statistics of kubernets pods or docker containers
@@ -278,6 +279,10 @@ start_ics() {
                        # Create app
                        input_yaml=$SIM_GROUP"/"$ICS_COMPOSE_DIR"/"app.yaml
                        output_yaml=$PWD/tmp/ics_app.yaml
+                       if [ -z "$ICS_SIDECAR_JWT_FILE" ]; then
+                               cat $input_yaml | sed  '/#ICS_JWT_START/,/#ICS_JWT_STOP/d' > $PWD/tmp/ics_app_tmp.yaml
+                               input_yaml=$PWD/tmp/ics_app_tmp.yaml
+                       fi
                        __kube_create_instance app $ICS_APP_NAME $input_yaml $output_yaml
                fi
 
@@ -321,6 +326,7 @@ start_ics() {
                        fi
                else
                        echo " No files in mounted dir or dir does not exists"
+                       mkdir db
                fi
 
                cd $curdir
@@ -396,13 +402,13 @@ start_stopped_ics() {
                fi
 
                # Tie the ICS to the same worker node it was initially started on
-               # A PVC of type hostPath is mounted to PMS, for persistent storage, so the PMS must always be on the node which mounted the volume
+               # A PVC of type hostPath is mounted to A1PMS, for persistent storage, so the A1PMS must always be on the node which mounted the volume
                if [ -z "$__ICS_WORKER_NODE" ]; then
                        echo -e $RED" No initial worker node found for pod "$RED
                        ((RES_CONF_FAIL++))
                        return 1
                else
-                       echo -e $BOLD" Setting nodeSelector kubernetes.io/hostname=$__ICS_WORKER_NODE to deployment for $ICS_APP_NAME. Pod will always run on this worker node: $__PA_WORKER_NODE"$BOLD
+                       echo -e $BOLD" Setting nodeSelector kubernetes.io/hostname=$__ICS_WORKER_NODE to deployment for $ICS_APP_NAME. Pod will always run on this worker node: $__ICS_WORKER_NODE"$BOLD
                        echo -e $BOLD" The mounted volume is mounted as hostPath and only available on that worker node."$BOLD
                        tmp=$(kubectl $KUBECONF patch deployment $ICS_APP_NAME -n $KUBE_NONRTRIC_NAMESPACE --patch '{"spec": {"template": {"spec": {"nodeSelector": {"kubernetes.io/hostname": "'$__ICS_WORKER_NODE'"}}}}}')
                        if [ $? -ne 0 ]; then
@@ -448,7 +454,7 @@ set_ics_debug() {
 # (Function for test scripts)
 set_ics_trace() {
        echo -e $BOLD"Setting ics trace logging"$EBOLD
-       curlString="$ICS_SERVICE_PATH/actuator/loggers/org.oransc.information -X POST  -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
+       curlString="$ICS_SERVICE_PATH$ICS_ACTUATOR -X POST  -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
        result=$(__do_curl "$curlString")
        if [ $? -ne 0 ]; then
                __print_err "Could not set trace mode" $@
@@ -2461,4 +2467,17 @@ ics_kube_pvc_reset() {
 
        __log_test_pass
        return 0
+}
+
+# args: <realm> <client-name> <client-secret>
+ics_configure_sec() {
+       export ICS_CREDS_GRANT_TYPE="client_credentials"
+       export ICS_CREDS_CLIENT_SECRET=$3
+       export ICS_CREDS_CLIENT_ID=$2
+       export ICS_AUTH_SERVICE_URL=$KEYCLOAK_SERVICE_PATH$KEYCLOAK_TOKEN_URL_PREFIX/$1/protocol/openid-connect/token
+       export ICS_SIDECAR_MOUNT="/token-cache"
+       export ICS_SIDECAR_JWT_FILE=$ICS_SIDECAR_MOUNT"/jwt.txt"
+
+       export AUTHSIDECAR_APP_NAME
+       export AUTHSIDECAR_DISPLAY_NAME
 }
\ No newline at end of file