Removal of older test profiles
[nonrtric.git] / test / common / a1pms_api_functions.sh
index f539717..ccc424e 100644 (file)
@@ -89,6 +89,7 @@ __A1PMS_store_docker_logs() {
 # args: -
 __A1PMS_initial_setup() {
        use_a1pms_rest_http
+       export A1PMS_SIDECAR_JWT_FILE=""
 }
 
 # Set app short-name, app name and namespace for logging runtime statistics of kubernets pods or docker containers
@@ -196,9 +197,6 @@ __export_a1pms_vars() {
                export A1PMS_CONFIG_CONFIGMAP_NAME=$A1PMS_APP_NAME"-config"
                export A1PMS_DATA_CONFIGMAP_NAME=$A1PMS_APP_NAME"-data"
                export A1PMS_PKG_NAME
-               export CONSUL_HOST
-               export CONSUL_INTERNAL_PORT
-               export CONFIG_BINDING_SERVICE
                export A1PMS_CONFIG_KEY
                export DOCKER_SIM_NWNAME
                export A1PMS_HOST_MNT_DIR
@@ -306,6 +304,10 @@ start_a1pms() {
                        # Create app
                        input_yaml=$SIM_GROUP"/"$A1PMS_COMPOSE_DIR"/"app.yaml
                        output_yaml=$PWD/tmp/a1pmsapp.yaml
+                       if [ -z "$A1PMS_SIDECAR_JWT_FILE" ]; then
+                               cat $input_yaml | sed  '/#A1PMS_JWT_START/,/#A1PMS_JWT_STOP/d' > $PWD/tmp/a1pmsapp_tmp.yaml
+                               input_yaml=$PWD/tmp/a1pmsapp_tmp.yaml
+                       fi
                        __kube_create_instance app $A1PMS_APP_NAME $input_yaml $output_yaml
 
                fi
@@ -346,6 +348,7 @@ start_a1pms() {
                        fi
                else
                        echo " No files in mounted dir or dir does not exists"
+                       mkdir db
                fi
                cd $curdir
 
@@ -456,7 +459,7 @@ start_stopped_a1pms() {
 # Function to perpare the consul configuration according to the current simulator configuration
 # args: SDNC|NOSDNC <output-file>
 # (Function for test scripts)
-prepare_consul_config() {
+prepare_a1pms_config() {
        echo -e $BOLD"Prepare Consul config"$EBOLD
 
        echo " Writing consul config for "$A1PMS_APP_NAME" to file: "$2
@@ -473,7 +476,7 @@ prepare_consul_config() {
                echo -e " Config$BOLD excluding SDNC$EBOLD configuration"
        else
                ((RES_CONF_FAIL++))
-       __print_err "need two args,  SDNC|NOSDNC <output-file>" $@
+       __print_err "need three args,  SDNC|NOSDNC <output-file> HEADER|NOHEADER" $@
                exit 1
        fi
 
@@ -542,7 +545,7 @@ prepare_consul_config() {
                        ric_id=${ric%.*.*} #extract pod id from full hosthame
                        ric_id=$(echo "$ric_id" | tr '-' '_')
                else
-                       if [ $DOCKER_COMPOSE_VERION == "V1" ]; then
+                       if [ $DOCKER_COMPOSE_VERSION == "V1" ]; then
                                ric_id=$ric
                        else
                                ric_id=$(echo "$ric" | tr '-' '_')  #ric id still needs underscore as it is different from the container name
@@ -565,9 +568,7 @@ prepare_consul_config() {
        config_json=$config_json"\n           ]"
        config_json=$config_json"\n}"
 
-       if [ $RUNMODE == "KUBE" ]; then
-               config_json="{\"config\":"$config_json"}"
-       fi
+       config_json="{\"config\":"$config_json"}"
 
        printf "$config_json">$2
 
@@ -2290,9 +2291,9 @@ a1pms_api_put_configuration() {
                return 1
        fi
        inputJson=$(< $2)
-       if [ $RUNMODE == "DOCKER" ]; then  #In kube the file already has a header
-               inputJson="{\"config\":"$inputJson"}"
-       fi
+       if [ $RUNMODE == "DOCKER" ]; then  #In kube the file already has a header
+       #       inputJson="{\"config\":"$inputJson"}"
+       fi
        file="./tmp/.config.json"
        echo $inputJson > $file
        query="/v2/configuration"
@@ -2343,7 +2344,9 @@ a1pms_api_get_configuration() {
                body=${res:0:${#res}-3}
 
                targetJson=$(< $2)
-               targetJson="{\"config\":"$targetJson"}"
+               # if [ $RUNMODE == "DOCKER" ]; then  #In kube the file already has a header
+               #       inputJson="{\"config\":"$inputJson"}"
+               # fi
                echo "TARGET JSON: $targetJson" >> $HTTPLOG
                res=$(python3 ../common/compare_json.py "$targetJson" "$body")
 
@@ -2380,4 +2383,17 @@ a1pms_kube_pvc_reset() {
 
        __log_test_pass
        return 0
+}
+
+# args: <realm> <client-name> <client-secret>
+a1pms_configure_sec() {
+       export A1PMS_CREDS_GRANT_TYPE="client_credentials"
+       export A1PMS_CREDS_CLIENT_SECRET=$3
+       export A1PMS_CREDS_CLIENT_ID=$2
+       export A1PMS_AUTH_SERVICE_URL=$KEYCLOAK_SERVICE_PATH$KEYCLOAK_TOKEN_URL_PREFIX/$1/protocol/openid-connect/token
+       export A1PMS_SIDECAR_MOUNT="/token-cache"
+       export A1PMS_SIDECAR_JWT_FILE=$A1PMS_SIDECAR_MOUNT"/jwt.txt"
+
+       export AUTHSIDECAR_APP_NAME
+       export AUTHSIDECAR_DISPLAY_NAME
 }
\ No newline at end of file