diff --git a/.gitignore b/.gitignore index 37d0f1e..41c9b08 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ __blobstorage* __azurite* __queuestorage* debug.ps1 +local.settings.json diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 38d0e88..b68336d 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -7,6 +7,9 @@ "label": "CopyModuleFiles", "type": "shell", "command": "Invoke-Build -Task CopyModuleFiles -File './aipas.build.ps1'", + "osx": { + "command": "pwsh -c Invoke-Build -Task CopyModuleFiles -File './aipas.build.ps1'" + }, "problemMatcher": "$msCompile", "presentation": { "echo": false, @@ -17,6 +20,9 @@ "label": "Test", "type": "shell", "command": "Invoke-Build -Task Test -File './aipas.build.ps1'", + "osx": { + "command": "pwsh -c Invoke-Build -Task Test -File './aipas.build.ps1'" + }, "problemMatcher": "$msCompile", "presentation": { "echo": false, @@ -27,6 +33,9 @@ "label": "Startfunction", "type": "shell", "command": "Invoke-Build -Task Startfunction -File './aipas.build.ps1'", + "osx": { + "command": "pwsh -c Invoke-Build -Task Startfunction -File './aipas.build.ps1'" + }, "problemMatcher": "$msCompile", "presentation": { "echo": false, @@ -37,6 +46,9 @@ "label": "Clean", "type": "shell", "command": "Invoke-Build -Task Clean -File './aipas.build.ps1'", + "osx": { + "command": "pwsh -c Invoke-Build -Task Clean -File './aipas.build.ps1'" + }, "problemMatcher": "$msCompile", "presentation": { "echo": false, @@ -47,6 +59,9 @@ "label": "Testfunction", "type": "shell", "command": "Invoke-Build -Task TestFunction -File './aipas.build.ps1'", + "osx": { + "command": "pwsh -c Invoke-Build -Task TestFunction -File './aipas.build.ps1'" + }, "problemMatcher": "$msCompile", "presentation": { "echo": false, @@ -57,6 +72,9 @@ "label": ".", "type": "shell", "command": "Invoke-Build -Task . -File './aipas.build.ps1'", + "osx": { + "command": "pwsh -c Invoke-Build -Task . -File './aipas.build.ps1'" + }, "problemMatcher": "$msCompile", "presentation": { "echo": false, @@ -71,6 +89,9 @@ "label": "?", "type": "shell", "command": "Invoke-Build -Task ? -File './aipas.build.ps1'", + "osx": { + "command": "pwsh -c Invoke-Build -Task ? -File './aipas.build.ps1'" + }, "problemMatcher": "$msCompile", "presentation": { "echo": false, diff --git a/README.md b/README.md index 65d25f2..508ecf4 100644 --- a/README.md +++ b/README.md @@ -143,54 +143,13 @@ Azure Subscription with: ## Local development -If you want to further develop or test AIPAS you need to install the following prerequisites on your Windows development machine. - -### Install local development prerequisites - -- Git client -- Visual Studio Code -- Azure Function Core Tools (version 3.0.3160 or higher) -- PowerShell (Core) -- HTTP Testing and Debugging tool like [Httpmaster](https://www.httpmaster.net/) of [Insomnia](https://insomnia.rest/) - -If you installed [Chocolatey](https://chocolatey.org/) (a Windows Apt-Get kinda tool) you can install above software with the following commands: - -```PowerShell -# Install Git -choco install git -# Install VSCode -choco install vscode -# Install Azure Function Core Tools -choco install azure-functions-core-tools-3 -# Install PowerShell Core -choco install pwsh -# Install HttpMaster -choco install httpmaster-express -``` +AIPAS uses Azure Functions. You can develop, test and run Azure functions locally on your machine. Please see the [instructions](docs/prerequisites.md) for installing the prerequisites on Windows and MacOs. ### Clone AIPAS Repository ```PowerShell git clone https://github.com/stefanstranger/AIPAS.git ``` - -### Install PowerShell Modules - -After cloning the Git Repository you can use the bootstrap.ps1 script to install the required PowerShell modules. - -![Bootstrap screenshot](pictures/bootstrap.png) - -The following PowerShell Modules need to be installed: - -- InvokeBuild -- Pester -- PlatyPS -- Az PowerShell modules* - -\* The installation of the Az PowerShell modules are not part of the bootstrap.ps1 script. If you have not installed these PowerShell modules run Install-Module -Name Az on your development machine. - - - ### Deploy Azure Storage Table Within the Git Repository there are Azure Resource Manager Template files that can be used to deploy a new Resource Group with an Azure Storage Table. @@ -202,18 +161,13 @@ Run the following PowerShell Azure commands: Run from within your cloned repo folder #> +$subscription = '' + #region Login to Azure Add-AzAccount #endregion -#region Select Azure Subscription -$subscription = -(Get-AzSubscription | - Out-GridView ` - -Title 'Select an Azure Subscription ...' ` - -PassThru) - -Set-AzContext -SubscriptionId $subscription.subscriptionId -TenantId $subscription.TenantID +Set-AzContext -SubscriptionId $subscription.subscriptionId #endregion #region Create a new Resource Group @@ -257,20 +211,14 @@ $RoleDefinitionName = "Storage Account Contributor" $ADApplicationName = "AIPAS" $PlainPassword = "[enter password for SPN]" $StorageAccountName = "[Configure here the name of the previously deployed Storage Account]" -$SubscriptionId = "[enter subscriptionid]"" #SubscriptionId where the Vnets will be deployed. E.g. the Landing Zone Subscription. If multiple Subscriptions are used rerun for each Subscription +$SubscriptionId = "[enter subscriptionid]" #SubscriptionId where the Vnets will be deployed. E.g. the Landing Zone Subscription. If multiple Subscriptions are used rerun for each Subscription #region Login to Azure Add-AzAccount #endregion #region Select Azure Subscription -$subscription = -(Get-AzSubscription | - Out-GridView ` - -Title 'Select an Azure Subscription ...' ` - -PassThru) - -Set-AzContext -SubscriptionId $subscription.subscriptionId -TenantId $subscription.TenantID +Set-AzContext -SubscriptionId $SubscriptionId #endregion #region create SPN with Password @@ -294,14 +242,25 @@ Get-AzADServicePrincipal -ServicePrincipalName $($app.ApplicationId.Guid) -OutVa } | Convertto-json #endregion -#region create local environment variables -[Environment]::SetEnvironmentVariable("AIPASClientId", "$($app.ApplicationId)", "User") -[Environment]::SetEnvironmentVariable("AIPASClientSecret", "$PlainPassword", "User") -[Environment]::SetEnvironmentVariable("AIPASSubscriptionId", "$($subscription.subscriptionId)", "User") -[Environment]::SetEnvironmentVariable("AIPAStenantId", "$($subscription.TenantID)", "User") -[Environment]::SetEnvironmentVariable("AIPASResourceGroupName", $ResourceGroupName, "User") -[Environment]::SetEnvironmentVariable("AIPASStorageAccountName", $StorageAccountName, "User") -# Restart VSCode to have access to the environment variables +#region create local settings file +$json = @" +{ + "IsEncrypted": false, + "Values": { + "AzureWebJobsStorage": "UseDevelopmentStorage=true", + "FUNCTIONS_WORKER_RUNTIME_VERSION": "~7", + "FUNCTIONS_WORKER_RUNTIME": "powershell", + "AIPASStorageAccountName": "$StorageAccountName", + "AIPASTenantId": "$((Get-AzContext).Tenant.Id)", + "AIPASSubscriptionId": "$SubscriptionId", + "AIPASResourceGroupName": "$ResourceGroupName", + "AIPASClientId": "$($app.ApplicationId)", + "AIPASClientSecret": "$PlainPassword" + } +} +"@ +$json | Out-File -Path .vscode\local.settings.json +# Restart VSCode to load the local settings #endregion ``` diff --git a/docs/prerequisites.md b/docs/prerequisites.md new file mode 100644 index 0000000..a17db96 --- /dev/null +++ b/docs/prerequisites.md @@ -0,0 +1,60 @@ +# Installing prerequisites + +The following things are required on your system. + +- git +- VS Code +- Azure Function Core Tools (version 3.0.3160 or higher) +- PowerShell 7 +- HTTP Testing and Debugging tool like [Postman](https://www.postman.com/), [Httpmaster](https://www.httpmaster.net/) or [Insomnia](https://insomnia.rest/) + + +## Windows + +The prerequisites on Windows can be installed using [Chocolatey](https://chocolatey.org/) (a package manager for Windows). + +``` +# Install Git +choco install git +# Install VSCode +choco install vscode +# Install Azure Function Core Tools +choco install azure-functions-core-tools-3 +# Install PowerShell Core +choco install pwsh +# Install HttpMaster +choco install httpmaster-express +``` + +## MacOs +The prerequisites on MacOs can be installed using [brew](https://brew.sh/) (a package manager for Mac). + +``` +# Install Git +brew install git +# Install VSCode +brew install --cask visual-studio-code +# Install dotnet +brew tap caskroom/caskbrew cask install dotnet +# Install Azure Function Core Tools +brew install azure-functions-core-tools@3 +# Install PowerShell 7 +brew install --cask powershell +# Install Postman (alternative to httpmaster, which is only available for Windows) +brew install --cask postman +``` + +## Install PowerShell Modules + +After cloning the Git Repository you can use the bootstrap.ps1 script to install the required PowerShell modules. + +![Bootstrap screenshot](/pictures/bootstrap.png) + +The following PowerShell Modules need to be installed: + +- InvokeBuild +- Pester +- PlatyPS +- Az PowerShell modules* + +\* The installation of the Az PowerShell modules are not part of the bootstrap.ps1 script. If you have not installed these PowerShell modules run `Install-Module -Name Az`on your development machine.