seed_data.sh 2.29 KB
Newer Older
1
2
3
#!/bin/bash

# This logs the Azure CLI in using the configured service principal.
4
az login --service-principal -u $ARM_CLIENT_ID -p $ARM_CLIENT_SECRET --tenant $ARM_TENANT_ID
5
6
7
8
9

# The Legal_COO.json file needs to be loaded into the Data Partition Storage Account,
# in the container  legal-service-azure-configuration.
ENV_VAULT=$(az keyvault list --resource-group $RESOURCE_GROUP_NAME --query [].name -otsv)

10
IFS=',' read -r -a partitions <<< ${PARTITIONS}
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65

for index in "${!partitions[@]}"
do
    echo "Ingesting file for partition: $index. ${partitions[index]}"
    
    STORAGE_ACCOUNT_NAME=$(az keyvault secret show --id https://${ENV_VAULT}.vault.azure.net/secrets/${partitions[index]}-storage --query value -otsv)
    STORAGE_ACCOUNT_KEY=$(az keyvault secret show --id https://${ENV_VAULT}.vault.azure.net/secrets/${partitions[index]}-storage-key --query value -otsv)
    FILE_NAME=Legal_COO.json

    if [ -z "$STORAGE_ACCOUNT_NAME" -a "$STORAGE_ACCOUNT_NAME"==" " ]; then
        exit 1
    fi
    if [ -z "$STORAGE_ACCOUNT_KEY" -a "$STORAGE_ACCOUNT_KEY"==" " ]; then
        exit 1
    fi

    az storage blob upload \
        --account-name $STORAGE_ACCOUNT_NAME \
        --account-key $STORAGE_ACCOUNT_KEY \
        --file ./test_data/Legal_COO.json \
        --container-name legal-service-azure-configuration \
        --name $FILE_NAME

    BLOB_LIST=$(az storage blob list \
        --account-name $STORAGE_ACCOUNT_NAME \
        --account-key $STORAGE_ACCOUNT_KEY \
        --container-name legal-service-azure-configuration \
        --query "[].{name:name}" -otsv)

    if [[ ! " ${BLOB_LIST[@]} " =~ " ${FILE_NAME} " ]]; then
        
        sleep 1m

        az storage blob upload \
        --account-name $STORAGE_ACCOUNT_NAME \
        --account-key $STORAGE_ACCOUNT_KEY \
        --file ./test_data/Legal_COO.json \
        --container-name legal-service-azure-configuration \
        --name $FILE_NAME

        BLOB_LIST=$(az storage blob list \
        --account-name $STORAGE_ACCOUNT_NAME \
        --account-key $STORAGE_ACCOUNT_KEY \
        --container-name legal-service-azure-configuration \
        --query "[].{name:name}" -otsv)

        if [[ ! " ${BLOB_LIST[@]} " =~ " ${FILE_NAME} " ]]; then
            exit 1
        fi
    fi

    echo "File ingested for partition: $index. ${partitions[index]}"
    
done