Skip to content

Commit d4749b0

Browse files
add role checks for Storage Blob Data Contributor and Key Vault Administrator in scripts and eliminated unnecessary output
1 parent 97ca74e commit d4749b0

File tree

3 files changed

+33
-12
lines changed

3 files changed

+33
-12
lines changed

azure.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ hooks:
4040
run: |
4141
echo "Web app URL: "
4242
echo $WEB_APP_URL
43-
# echo "Run the following command in the terminal to copy data files to storage account: "
44-
# echo $copykbfiles
45-
# echo "Run the following command in the terminal to run the scripts: "
46-
# echo $createindex
4743
echo ""
4844
echo "If you want to use the Sample Data, run the following command in the terminal to process it:"
4945
echo "bash ./infra/scripts/process_sample_data.sh $STORAGE_ACCOUNT_NAME $STORAGE_CONTAINER_NAME $KEY_VAULT_NAME"

infra/scripts/copy_kb_files.sh

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,23 @@ signed_user_id=$(az ad signed-in-user show --query id -o tsv)
5050
echo "Getting storage account resource id"
5151
storage_account_resource_id=$(az storage account show --name $storageAccount --query id --output tsv)
5252

53-
# add Storage Blob Data Contributor role to the user
54-
az role assignment create --assignee $signed_user_id --role "Storage Blob Data Contributor" --scope /$storage_account_resource_id
53+
#check if user has the Storage Blob Data Contributor role, add it if not
54+
echo "Checking if user has the Storage Blob Data Contributor role"
55+
role_assignment=$(MSYS_NO_PATHCONV=1 az role assignment list --assignee $signed_user_id --role "Storage Blob Data Contributor" --scope $storage_account_resource_id --query "[].roleDefinitionId" -o tsv)
56+
if [ -z "$role_assignment" ]; then
57+
echo "User does not have the Storage Blob Data Contributor role. Assigning the role."
58+
MSYS_NO_PATHCONV=1 az role assignment create --assignee $signed_user_id --role "Storage Blob Data Contributor" --scope $storage_account_resource_id --output none
59+
if [ $? -eq 0 ]; then
60+
echo "Role assignment completed successfully."
61+
else
62+
echo "Error: Role assignment failed."
63+
exit 1
64+
fi
65+
else
66+
echo "User already has the Storage Blob Data Contributor role."
67+
fi
5568

5669
# Using az storage blob upload-batch to upload files with managed identity authentication, as the az storage fs directory upload command is not working with managed identity authentication.
57-
echo "Uploading files to Azure Storage..."
58-
az storage blob upload-batch --account-name "$storageAccount" --destination "$fileSystem"/"$extractedFolder1" --source infra/data/"$extractedFolder1" --auth-mode login --pattern '*' --overwrite
70+
echo "Uploading files to Azure Storage"
71+
az storage blob upload-batch --account-name "$storageAccount" --destination "$fileSystem"/"$extractedFolder1" --source infra/data/"$extractedFolder1" --auth-mode login --pattern '*' --overwrite --output none
5972
# az storage blob upload-batch --account-name "$storageAccount" --destination data/"$extractedFolder2" --source /mnt/azscripts/azscriptinput/"$extractedFolder2" --auth-mode login --pattern '*' --overwrite

infra/scripts/run_create_index_scripts.sh

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,21 @@ signed_user_id=$(az ad signed-in-user show --query id -o tsv)
2121
echo "Getting key vault resource id"
2222
key_vault_resource_id=$(az keyvault show --name $keyvaultName --query id --output tsv)
2323

24-
# Assign the Key Vault Administrator role to the user
25-
echo "Assigning the Key Vault Administrator role to the user."
26-
az role assignment create --assignee $signed_user_id --role "Key Vault Administrator" --scope /$key_vault_resource_id
24+
# Check if the user has the Key Vault Administrator role
25+
echo "Checking if user has the Key Vault Administrator role"
26+
role_assignment=$(MSYS_NO_PATHCONV=1 az role assignment list --assignee $signed_user_id --role "Key Vault Administrator" --scope $key_vault_resource_id --query "[].roleDefinitionId" -o tsv)
27+
if [ -z "$role_assignment" ]; then
28+
echo "User does not have the Key Vault Administrator role. Assigning the role."
29+
MSYS_NO_PATHCONV=1 az role assignment create --assignee $signed_user_id --role "Key Vault Administrator" --scope $key_vault_resource_id --output none
30+
if [ $? -eq 0 ]; then
31+
echo "Key Vault Administrator role assigned successfully."
32+
else
33+
echo "Failed to assign Key Vault Administrator role."
34+
exit 1
35+
fi
36+
else
37+
echo "User already has the Key Vault Administrator role."
38+
fi
2739

2840
# RUN apt-get update
2941
# RUN apt-get install python3 python3-dev g++ unixodbc-dev unixodbc libpq-dev
@@ -58,7 +70,7 @@ source infra/scripts/scriptenv/bin/activate
5870

5971
# Install the requirements
6072
echo "Installing requirements"
61-
pip install -r infra/scripts/index_scripts/requirements.txt
73+
pip install --quiet -r infra/scripts/index_scripts/requirements.txt
6274
echo "Requirements installed"
6375

6476
# Run the scripts

0 commit comments

Comments
 (0)