Skip to content

Commit efff5f5

Browse files
Add PowerShell setup instructions and enhance sample data processing scripts
- Added PowerShell installation instructions for Windows users in README.md. - Updated process_sample_data.sh to include Cosmos DB account and resource group as parameters. - Created add_cosmosdb_access.sh to manage Cosmos DB role assignments. - Enhanced run_create_index_scripts.sh with Azure authentication checks. - Updated main.bicep to output Cosmos DB account and resource group names.
1 parent ae6e81c commit efff5f5

File tree

7 files changed

+131
-7
lines changed

7 files changed

+131
-7
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ If you're not using one of the above options for opening the project, then you'l
138138
* [Python 3.9+](https://www.python.org/downloads/)
139139
* [Docker Desktop](https://www.docker.com/products/docker-desktop/)
140140
* [Git](https://git-scm.com/downloads)
141+
* [Powershell](https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell-on-windows?view=powershell-7.5) (Required for Windows users only. Follow the steps [here](./docs/PowershellSetup.md) to add it to the Windows PATH.)
141142

142143
2. Download the project code:
143144

@@ -194,7 +195,7 @@ To change the azd parameters from the default values, follow the steps [here](./
194195
195196
5. Once the deployment has completed successfully and you would like to use the sample data, run the bash command printed in the terminal. The bash command will look like the following:
196197
```shell
197-
./infra/scripts/process_sample_data.sh <Storage-Account-name> <Storgae-Account-container-name> <Key-Vault-name>
198+
bash ./infra/scripts/process_sample_data.sh <Storage-Account-name> <Storgae-Account-container-name> <Key-Vault-name> <CosmosDB-Account-name> <Resource-Group-name>
198199
```
199200
200201
6. Open the [Azure Portal](https://portal.azure.com/), go to the deployed resource group, find the App Service and get the app URL from `Default domain`.

azure.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ hooks:
3232
Write-Host "Web app URL: "
3333
Write-Host "$env:WEB_APP_URL" -ForegroundColor Cyan
3434
Write-Host "`nIf you want to use the Sample Data, run the following command in the Bash terminal to process it:"
35-
Write-Host "bash ./infra/scripts/process_sample_data.sh $env:STORAGE_ACCOUNT_NAME $env:STORAGE_CONTAINER_NAME $env:KEY_VAULT_NAME" -ForegroundColor Cyan
35+
Write-Host "bash ./infra/scripts/process_sample_data.sh $env:STORAGE_ACCOUNT_NAME $env:STORAGE_CONTAINER_NAME $env:KEY_VAULT_NAME $env:COSMOSDB_ACCOUNT_NAME $env:RESOURCE_GROUP_NAME" -ForegroundColor Cyan
3636
shell: pwsh
3737
continueOnError: false
3838
interactive: true
@@ -42,7 +42,7 @@ hooks:
4242
echo $WEB_APP_URL
4343
echo ""
4444
echo "If you want to use the Sample Data, run the following command in the terminal to process it:"
45-
echo "bash ./infra/scripts/process_sample_data.sh $STORAGE_ACCOUNT_NAME $STORAGE_CONTAINER_NAME $KEY_VAULT_NAME"
45+
echo "bash ./infra/scripts/process_sample_data.sh $STORAGE_ACCOUNT_NAME $STORAGE_CONTAINER_NAME $KEY_VAULT_NAME $COSMOSDB_ACCOUNT_NAME $RESOURCE_GROUP_NAME"
4646
shell: sh
4747
continueOnError: false
4848
interactive: true

docs/PowershellSetup.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Add PowerShell 7 to PATH in Windows
2+
3+
This guide will help you add **PowerShell 7** (PowerShell Core) to your system’s PATH variable on Windows, so you can easily run it from any Command Prompt or Run dialog.
4+
5+
## Prerequisites
6+
7+
- You should have **PowerShell 7** installed on your machine. If you haven’t installed it yet, you can download it following the guide here: [Installing PowerShell on Windows | Microsoft Learn](https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell-on-windows?view=powershell-7.5).
8+
- **Administrative privileges are not required** unless you're modifying system-wide environment variables. You can modify your **user-specific PATH** without admin rights.
9+
10+
## Steps to Add PowerShell 7 to PATH
11+
12+
### 1. Open **System Properties**
13+
- Press `Win + X` and choose **System**.
14+
- Click on **Advanced system settings** on the left sidebar. This will open the **System Properties** window.
15+
- In the **System Properties** window, click on the **Environment Variables** button at the bottom.
16+
17+
### 2. Edit User Environment Variables
18+
- In the **Environment Variables** window, under **User variables**, find the `Path` variable.
19+
- Select the `Path` variable and click **Edit**. (If the `Path` variable doesn’t exist, click **New** and name it `Path`.)
20+
21+
### 3. Check if PowerShell 7 Path is Already in PATH
22+
- Before adding the path, make sure the following path is not already present in the list:
23+
```
24+
C:\Program Files\PowerShell\7\
25+
```
26+
- If the path is already there, you don't need to add it again.
27+
### 4. Add PowerShell 7 Path
28+
- If the path is not already in the list, click **New** in the **Edit Environment Variable** window.
29+
- Add the following path to the list:
30+
```
31+
C:\Program Files\PowerShell\7\
32+
```
33+
> **Note:** If you installed PowerShell 7 in a custom location, replace the above path with the correct one.
34+
### 5. Save Changes
35+
- After adding the path, click **OK** to close the **Edit Environment Variable** window.
36+
- Click **OK** again to close the **Environment Variables** window.
37+
- Finally, click **OK** to exit the **System Properties** window.
38+
### 6. Verify PowerShell 7 in PATH
39+
- Open **Command Prompt** or **Run** (press `Win + R`).
40+
- Type `pwsh` and press Enter.
41+
- If PowerShell 7 opens, you've successfully added it to your PATH!
42+
---
43+
## Troubleshooting
44+
- **PowerShell 7 not opening:** Ensure the path to PowerShell 7 is entered correctly. If you're using a custom installation folder, check that the correct path is added to the `Path` variable.
45+
- **Changes not taking effect:** Try restarting your computer or logging out and logging back in for the changes to apply.

infra/main.bicep

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,8 @@ module cosmosDBModule 'deploy_cosmos_db.bicep' = {
430430
output STORAGE_ACCOUNT_NAME string = storageAccount.outputs.storageName
431431
output STORAGE_CONTAINER_NAME string = storageAccount.outputs.storageContainer
432432
output KEY_VAULT_NAME string = kvault.outputs.keyvaultName
433+
output COSMOSDB_ACCOUNT_NAME string = cosmosDBModule.outputs.cosmosAccountName
434+
output RESOURCE_GROUP_NAME string = resourceGroup().name
433435

434436

435437
// //========== Deployment script to upload sample data ========== //
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/bin/bash
2+
3+
# Variables
4+
resource_group="$1"
5+
account_name="$2"
6+
7+
# Authenticate with Azure
8+
if az account show &> /dev/null; then
9+
echo "Already authenticated with Azure."
10+
else
11+
if [ -n "$managedIdentityClientId" ]; then
12+
# Use managed identity if running in Azure
13+
echo "Authenticating with Managed Identity..."
14+
az login --identity --client-id ${managedIdentityClientId}
15+
else
16+
# Use Azure CLI login if running locally
17+
echo "Authenticating with Azure CLI..."
18+
az login
19+
fi
20+
echo "Not authenticated with Azure. Attempting to authenticate..."
21+
fi
22+
23+
echo "Getting signed in user id"
24+
signed_user_id=$(az ad signed-in-user show --query id -o tsv)
25+
26+
# Check if the user has the Cosmos DB Built-in Data Contributor role
27+
echo "Checking if user has the Cosmos DB Built-in Data Contributor role"
28+
roleExists=$(az cosmosdb sql role assignment list \
29+
--resource-group $resource_group \
30+
--account-name $account_name \
31+
--query "[?roleDefinitionId.ends_with(@, '00000000-0000-0000-0000-000000000002') && principalId == '$signed_user_id']" -o tsv)
32+
33+
# Check if the role exists
34+
if [ -n "$roleExists" ]; then
35+
echo "User already has the Cosmos DB Built-in Data Contributer role."
36+
else
37+
echo "User does not have the Cosmos DB Built-in Data Contributer role. Assigning the role."
38+
MSYS_NO_PATHCONV=1 az cosmosdb sql role assignment create \
39+
--resource-group $resource_group \
40+
--account-name $account_name \
41+
--role-definition-id 00000000-0000-0000-0000-000000000002 \
42+
--principal-id $signed_user_id \
43+
--scope "/" \
44+
--output none
45+
if [ $? -eq 0 ]; then
46+
echo "Cosmos DB Built-in Data Contributer role assigned successfully."
47+
else
48+
echo "Failed to assign Cosmos DB Built-in Data Contributer role."
49+
fi
50+
fi

infra/scripts/process_sample_data.sh

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,25 @@
44
storageAccount="$1"
55
fileSystem="$2"
66
keyvaultName="$3"
7-
managedIdentityClientId="$4"
7+
cosmosDbAccountName="$4"
8+
resourceGroupName="$5"
9+
managedIdentityClientId="$6"
810

911
# Check if all required arguments are provided
10-
if [ -z "$storageAccount" ] || [ -z "$fileSystem" ] || [ -z "$keyvaultName" ]; then
11-
echo "Usage: $0 <storageAccount> <fileSystem> <keyvaultName> [managedIdentityClientId]"
12+
if [ -z "$storageAccount" ] || [ -z "$fileSystem" ] || [ -z "$keyvaultName" ] || [ -z "$cosmosDbAccountName" ] || [ -z "$resourceGroupName" ]; then
13+
echo "Usage: $0 <storageAccount> <fileSystem> <keyvaultName> <cosmosDbAccountName> <resourceGroupName> [managedIdentityClientId]"
1214
exit 1
1315
fi
1416

17+
# Call add_cosmosdb_access.sh
18+
echo "Running add_cosmosdb_access.sh"
19+
bash infra/scripts/add_cosmosdb_access.sh "$resourceGroupName" "$cosmosDbAccountName" "$managedIdentityClientId"
20+
if [ $? -ne 0 ]; then
21+
echo "Error: add_cosmosdb_access.sh failed."
22+
exit 1
23+
fi
24+
echo "add_cosmosdb_access.sh completed successfully."
25+
1526
# Call copy_kb_files.sh
1627
echo "Running copy_kb_files.sh"
1728
bash infra/scripts/copy_kb_files.sh "$storageAccount" "$fileSystem" "$managedIdentityClientId"

infra/scripts/run_create_index_scripts.sh

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/bin/bash
2-
echo "started the script"
32

43
# Variables
54
# baseUrl="$1"
@@ -10,6 +9,22 @@ managedIdentityClientId="$2"
109

1110
echo "Script Started"
1211

12+
# Authenticate with Azure
13+
if az account show &> /dev/null; then
14+
echo "Already authenticated with Azure."
15+
else
16+
if [ -n "$managedIdentityClientId" ]; then
17+
# Use managed identity if running in Azure
18+
echo "Authenticating with Managed Identity..."
19+
az login --identity --client-id ${managedIdentityClientId}
20+
else
21+
# Use Azure CLI login if running locally
22+
echo "Authenticating with Azure CLI..."
23+
az login
24+
fi
25+
echo "Not authenticated with Azure. Attempting to authenticate..."
26+
fi
27+
1328
echo "Getting signed in user id"
1429
signed_user_id=$(az ad signed-in-user show --query id -o tsv)
1530

0 commit comments

Comments
 (0)