<commit_before>#!/bin/bash
#TODO this should be ported to python

securityGroupIds=$1
subnetIds=$2
iamRoleARN=$3
stackprefix=$4
jazz_admin=$5
jazz_accountid=$6
region=$7

# Add the stackname to int serverless-config-packs
sed -i "s/{inst_stack_prefix}/$stackprefix/g" ./jazz-core/builds/serverless-config-pack/serverless-java.yml
sed -i "s/{inst_stack_prefix}/$stackprefix/g" ./jazz-core/builds/serverless-config-pack/serverless-nodejs.yml
sed -i "s/{inst_stack_prefix}/$stackprefix/g" ./jazz-core/builds/serverless-config-pack/serverless-python.yml

#-------------------------------------------

function inArray() {
   local n=$#
   local value=${!n}
   for ((i=1;i < $#;i++)) {
       if [ "${!i}" == "${value}" ]; then
       echo "found" #Need one line after then and before return
       return 1
       fi
   }
   return 0
}

function pushToCatalog {
  tablename=$1
  element=$2
  service_type=$3
  deployment_targets=$4
  provider_runtime=$5

  timestamp=$(date --utc +%FT%T)
  uuid=$(uuidgen -t)

  echo -n > "./jazz-core/core/$element/deployment-env.yml"
  echo "service_id: $uuid" >> "./jazz-core/core/$element/deployment-env.yml"

  if [[ $element =~ ^jazz ]] ; then
    service_name="${element:5}"
  else
    service_name=$element
  fi

  aws dynamodb put-item --table-name "$tablename" --item "{
      \"SERVICE_ID\":{\"S\":\"$uuid\"},
      \"SERVICE_CREATED_BY\":{\"S\":\"$jazz_admin\"},
      \"SERVICE_DOMAIN\":{\"S\":\"jazz\"},
      \"SERVICE_NAME\":{\"S\":\"$service_name\"},
      \"SERVICE_RUNTIME\":{\"S\":\"$provider_runtime\"},
      \"SERVICE_STATUS\":{\"S\":\"active\"},
      \"TIMESTAMP\":{\"S\":\"$timestamp\"},
      \"SERVICE_TYPE\":{\"S\":\"$service_type\"},
      \"SERVICE_DEPLOYMENT_TARGETS\": {\"M\": $deployment_targets},
      \"SERVICE_DEPLOYMENT_ACCOUNTS\": {\"L\": {\"M\": {
                  \"accountId\":{\"S\":\"$jazz_accountid\"},
                  \"primary\":{\"B\":\"true\"},
                  \"provider\":{\"S\":\"aws\"},
                  \"region\":{\"S\":\"$region\"}
          }
        }
      },
      \"SERVICE_METADATA\":{\"M\":{<commit_msg>fix script make it an list of maps.<commit_after>#!/bin/bash
#TODO this should be ported to python

securityGroupIds=$1
subnetIds=$2
iamRoleARN=$3
stackprefix=$4
jazz_admin=$5
jazz_accountid=$6
region=$7

# Add the stackname to int serverless-config-packs
sed -i "s/{inst_stack_prefix}/$stackprefix/g" ./jazz-core/builds/serverless-config-pack/serverless-java.yml
sed -i "s/{inst_stack_prefix}/$stackprefix/g" ./jazz-core/builds/serverless-config-pack/serverless-nodejs.yml
sed -i "s/{inst_stack_prefix}/$stackprefix/g" ./jazz-core/builds/serverless-config-pack/serverless-python.yml

#-------------------------------------------

function inArray() {
   local n=$#
   local value=${!n}
   for ((i=1;i < $#;i++)) {
       if [ "${!i}" == "${value}" ]; then
       echo "found" #Need one line after then and before return
       return 1
       fi
   }
   return 0
}

function pushToCatalog {
  tablename=$1
  element=$2
  service_type=$3
  deployment_targets=$4
  provider_runtime=$5

  timestamp=$(date --utc +%FT%T)
  uuid=$(uuidgen -t)

  echo -n > "./jazz-core/core/$element/deployment-env.yml"
  echo "service_id: $uuid" >> "./jazz-core/core/$element/deployment-env.yml"

  if [[ $element =~ ^jazz ]] ; then
    service_name="${element:5}"
  else
    service_name=$element
  fi

  aws dynamodb put-item --table-name "$tablename" --item "{
      \"SERVICE_ID\":{\"S\":\"$uuid\"},
      \"SERVICE_CREATED_BY\":{\"S\":\"$jazz_admin\"},
      \"SERVICE_DOMAIN\":{\"S\":\"jazz\"},
      \"SERVICE_NAME\":{\"S\":\"$service_name\"},
      \"SERVICE_RUNTIME\":{\"S\":\"$provider_runtime\"},
      \"SERVICE_STATUS\":{\"S\":\"active\"},
      \"TIMESTAMP\":{\"S\":\"$timestamp\"},
      \"SERVICE_TYPE\":{\"S\":\"$service_type\"},
      \"SERVICE_DEPLOYMENT_TARGETS\": {\"M\": $deployment_targets},
      \"SERVICE_DEPLOYMENT_ACCOUNTS\": {
        \"L\": [{
            \"M\": {
                \"accountId\": {
                    \"S\": \"$jazz_accountid\"
                },
                \"primary\": {
                    \"B\": \"true\"
                },
                \"provider\": {
                    \"S\": \"aws\"
                },
                \"region\": {
                    \"S\": \"$region\"
                }
            }
        }]
      },
      \"SERVICE_METADATA\":{\"M\":{
{'fraction_non_alphanumeric': 0.2341053587647593, 'fraction_numerical': 0.007266121707538601, 'mean_word_length': 2.2605477424130274, 'pattern_counts': {'":': 62, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7049963', 'n_tokens_mistral': 1559, 'n_tokens_neox': 1523, 'n_words': 240}