Skip to content

Commit

Permalink
Merge pull request #29 from KelvinTegelaar/dev
Browse files Browse the repository at this point in the history
[pull] dev from KelvinTegelaar:dev
  • Loading branch information
smood922 authored May 6, 2024
2 parents 35e493a + da0e1c4 commit abaec39
Show file tree
Hide file tree
Showing 541 changed files with 7,968 additions and 4,238 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/dev_cippckdtz.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Docs for the Azure Web Apps Deploy action: https://github.com/azure/functions-action
# More GitHub Actions for Azure: https://github.com/Azure/actions

name: Build and deploy Powershell project to Azure Function App - cippckdtz

on:
push:
branches:
- dev
workflow_dispatch:

env:
AZURE_FUNCTIONAPP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root

jobs:
deploy:
runs-on: windows-latest

steps:
- name: 'Checkout GitHub Action'
uses: actions/checkout@v4

- name: 'Run Azure Functions Action'
uses: Azure/functions-action@v1
id: fa
with:
app-name: 'cippckdtz'
slot-name: 'Production'
package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_2101C7175BFB47E58240ABD1E72E81C2 }}
30 changes: 30 additions & 0 deletions .github/workflows/dev_cippeln4y.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Docs for the Azure Web Apps Deploy action: https://github.com/azure/functions-action
# More GitHub Actions for Azure: https://github.com/Azure/actions

name: Build and deploy Powershell project to Azure Function App - cippeln4y

on:
push:
branches:
- dev
workflow_dispatch:

env:
AZURE_FUNCTIONAPP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root

jobs:
deploy:
runs-on: windows-latest

steps:
- name: 'Checkout GitHub Action'
uses: actions/checkout@v4

- name: 'Run Azure Functions Action'
uses: Azure/functions-action@v1
id: fa
with:
app-name: 'cippeln4y'
slot-name: 'Production'
package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_B82C66E0F3BD4BDD9FFFB32FA83A68C9 }}
13 changes: 6 additions & 7 deletions Activity_AddOrUpdateTableRows/run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ $TableName = ($TableParams.Context['TableName'])
$Table = Get-CippTable -tablename $TableName

foreach ($param in $TableParams.Entity) {
try {
#Sending each item indivually, if it fails, log an error.
Add-CIPPAzDataTableEntity @Table -Entity $param -Force
}
catch {
Write-LogMessage -API 'Activity_AddOrUpdateTableRows' -message "Unable to write to '$($TableParams.TableName)' Using RowKey $($param.RowKey) table: $($_.Exception.Message)" -sev error
}
try {
#Sending each item indivually, if it fails, log an error.
Add-CIPPAzDataTableEntity @Table -Entity $param -Force
} catch {
Write-LogMessage -API 'Activity_AddOrUpdateTableRows' -message "Unable to write to '$($TableParams.TableName)' Using RowKey $($param.RowKey)" -LogData (Get-CippException -Exception $_) -sev error
}
}
2 changes: 1 addition & 1 deletion Applications_Orchestrator/run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ try {
$Outputs = Wait-ActivityFunction -Task $ParallelTasks
Write-Host $Outputs
}
catch {
catch {
Write-Host "Applications_Orchestrator exception: $($_.Exception.Message)"
}
finally {
Expand Down
24 changes: 12 additions & 12 deletions Applications_Upload/run.ps1
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
param($name)
$Table = Get-CippTable -tablename 'apps'
$Filter = "PartitionKey eq 'apps' and RowKey eq '$name'"
$Filter = "PartitionKey eq 'apps' and RowKey eq '$name'"
Set-Location (Get-Item $PSScriptRoot).Parent.FullName
$ChocoApp = (Get-CIPPAzDataTableEntity @Table -filter $Filter).JSON | ConvertFrom-Json
$intuneBody = $ChocoApp.IntuneBody
$tenants = if ($chocoapp.Tenant -eq 'AllTenants') {
$tenants = if ($chocoapp.Tenant -eq 'AllTenants') {
(Get-tenants).defaultDomainName
} else {
$chocoapp.Tenant
}
}
if ($chocoApp.type -eq 'MSPApp') {
[xml]$Intunexml = Get-Content "AddMSPApp\$($ChocoApp.MSPAppName).app.xml"
$intunewinFilesize = (Get-Item "AddMSPApp\$($ChocoApp.MSPAppName).intunewin")
Expand All @@ -25,7 +25,7 @@ $ContentBody = ConvertTo-Json @{
name = $intunexml.ApplicationInfo.FileName
size = [int64]$intunexml.ApplicationInfo.UnencryptedContentSize
sizeEncrypted = [int64]($intunewinFilesize).length
}
}
$ClearRow = Get-CIPPAzDataTableEntity @Table -Filter $Filter
$RemoveCacheFile = if ($chocoapp.Tenant -ne 'AllTenants') {
Remove-AzDataTableEntity @Table -Entity $clearRow
Expand Down Expand Up @@ -54,11 +54,11 @@ foreach ($tenant in $tenants) {
Try {

$ApplicationList = (New-graphGetRequest -Uri $baseuri -tenantid $Tenant) | Where-Object { $_.DisplayName -eq $ChocoApp.ApplicationName }
if ($ApplicationList.displayname.count -ge 1) {
if ($ApplicationList.displayname.count -ge 1) {
Write-LogMessage -api 'AppUpload' -tenant $($Tenant) -message "$($ChocoApp.ApplicationName) exists. Skipping this application" -Sev 'Info'
continue
}
if ($chocoApp.type -eq 'WinGet') {
if ($chocoApp.type -eq 'WinGet') {
Write-Host 'Winget!'
Write-Host ($intuneBody | ConvertTo-Json -Compress)
$NewApp = New-GraphPostRequest -Uri $baseuri -Body ($intuneBody | ConvertTo-Json -Compress) -Type POST -tenantid $tenant
Expand All @@ -79,8 +79,8 @@ foreach ($tenant in $tenants) {
$AzFileUri = New-graphGetRequest -Uri "$($BaseURI)/$($NewApp.id)/microsoft.graph.win32lobapp/contentVersions/1/files/$($ContentReq.id)" -tenantid $tenant
if ($AZfileuri.uploadState -like '*fail*') { break }
Start-Sleep -Milliseconds 300
} while ($AzFileUri.AzureStorageUri -eq $null)
} while ($AzFileUri.AzureStorageUri -eq $null)

$chunkSizeInBytes = 4mb
[byte[]]$bytes = [System.IO.File]::ReadAllBytes($($intunewinFilesize.fullname))
$chunks = [Math]::Ceiling($bytes.Length / $chunkSizeInBytes)
Expand All @@ -89,15 +89,15 @@ foreach ($tenant in $tenants) {
$Upload = Invoke-RestMethod -Uri "$($AzFileUri.azureStorageUri)&comp=block&blockid=$id" -Method Put -Headers @{'x-ms-blob-type' = 'BlockBlob' } -InFile $inFile -ContentType 'application/octet-stream'
$ConfirmUpload = Invoke-RestMethod -Uri "$($AzFileUri.azureStorageUri)&comp=blocklist" -Method Put -Body "<?xml version=`"1.0`" encoding=`"utf-8`"?><BlockList><Latest>$id</Latest></BlockList>"
$CommitReq = New-graphPostRequest -Uri "$($BaseURI)/$($NewApp.id)/microsoft.graph.win32lobapp/contentVersions/1/files/$($ContentReq.id)/commit" -Body $EncBody -Type POST -tenantid $tenant

do {
$CommitStateReq = New-graphGetRequest -Uri "$($BaseURI)/$($NewApp.id)/microsoft.graph.win32lobapp/contentVersions/1/files/$($ContentReq.id)" -tenantid $tenant
if ($CommitStateReq.uploadState -like '*fail*') {
Write-LogMessage -api 'AppUpload' -tenant $($Tenant) -message "$($ChocoApp.ApplicationName) Commit failed. Please check if app uploaded succesful" -Sev 'Warning'
break
break
}
Start-Sleep -Milliseconds 300
} while ($CommitStateReq.uploadState -eq 'commitFilePending')
} while ($CommitStateReq.uploadState -eq 'commitFilePending')
$CommitFinalizeReq = New-graphPostRequest -Uri "$($BaseURI)/$($NewApp.id)" -tenantid $tenant -Body '{"@odata.type":"#microsoft.graph.win32lobapp","committedContentVersion":"1"}' -type PATCH
Write-LogMessage -api 'AppUpload' -tenant $($Tenant) -message "Added Application $($chocoApp.ApplicationName)" -Sev 'Info'
if ($AssignTo -ne 'On') {
Expand All @@ -108,7 +108,7 @@ foreach ($tenant in $tenants) {
Write-LogMessage -api 'AppUpload' -tenant $($Tenant) -message 'Successfully added Application' -Sev 'Info'
} catch {
"Failed to add Application for $($Tenant): $($_.Exception.Message)"
Write-LogMessage -api 'AppUpload' -tenant $($Tenant) -message "Failed adding Application $($ChocoApp.ApplicationName). Error: $($_.Exception.Message)" -Sev 'Error'
Write-LogMessage -api 'AppUpload' -tenant $($Tenant) -message "Failed adding Application $($ChocoApp.ApplicationName). Error: $($_.Exception.Message)" -LogData (Get-CippException -Exception $_) -Sev 'Error'
continue
}

Expand Down
9 changes: 0 additions & 9 deletions BestPracticeAnalyser_All/function.json

This file was deleted.

9 changes: 0 additions & 9 deletions BestPracticeAnalyser_GetQueue/function.json

This file was deleted.

10 changes: 0 additions & 10 deletions BestPracticeAnalyser_GetQueue/run.ps1

This file was deleted.

9 changes: 0 additions & 9 deletions BestPracticeAnalyser_Orchestration/function.json

This file was deleted.

21 changes: 0 additions & 21 deletions BestPracticeAnalyser_Orchestration/run.ps1

This file was deleted.

46 changes: 33 additions & 13 deletions BestPracticeAnalyser_OrchestrationStarter/run.ps1
Original file line number Diff line number Diff line change
@@ -1,23 +1,43 @@
using namespace System.Net

param($Request, $TriggerMetadata)
if ($CurrentlyRunning) {
$Results = [pscustomobject]@{'Results' = 'Already running. Please wait for the current instance to finish' }
Write-LogMessage -API 'BestPracticeAnalyser' -message 'Attempted to start analysis but an instance was already running.' -sev Info

if ($Request.Query.TenantFilter) {
$TenantList = @($Request.Query.TenantFilter)
$Name = "Best Practice Analyser ($($Request.Query.TenantFilter))"
} else {
$InputObject = @{
TenantFilter = $Request.Query.TenantFilter
$TenantList = Get-Tenants
$Name = 'Best Practice Analyser (All Tenants)'
}
$CippRoot = (Get-Item $PSScriptRoot).Parent.FullName
$TemplatesLoc = Get-ChildItem "$CippRoot\Config\*.BPATemplate.json"
$Templates = $TemplatesLoc | ForEach-Object {
$Template = $(Get-Content $_) | ConvertFrom-Json
$Template.Name
}

$BPAReports = foreach ($Tenant in $TenantList) {
foreach ($Template in $Templates) {
[PSCustomObject]@{
FunctionName = 'BPACollectData'
Tenant = $Tenant.defaultDomainName
Template = $Template
QueueName = '{0} - {1}' -f $Template, $Tenant.defaultDomainName
}
}
$InstanceId = Start-NewOrchestration -FunctionName 'BestPracticeAnalyser_Orchestration' -InputObject $InputObject
Write-Host "Started orchestration with ID = '$InstanceId'"
$Orchestrator = New-OrchestrationCheckStatusResponse -Request $Request -InstanceId $InstanceId
Write-LogMessage -API 'BestPracticeAnalyser' -message 'Started retrieving best practice information' -sev Info
$Results = [pscustomobject]@{'Results' = 'Started running analysis' }
}
Write-Host ($Orchestrator | ConvertTo-Json)

$Queue = New-CippQueueEntry -Name $Name -TotalTasks ($BPAReports | Measure-Object).Count
$BPAReports = $BPAReports | Select-Object *, @{Name = 'QueueId'; Expression = { $Queue.RowKey } }
$InputObject = [PSCustomObject]@{
Batch = @($BPAReports)
OrchestratorName = 'BPAOrchestrator'
SkipLog = $true
DurableMode = 'Sequence'
}
Start-NewOrchestration -FunctionName 'CIPPOrchestrator' -InputObject ($InputObject | ConvertTo-Json -Compress -Depth 5)

$Results = [pscustomobject]@{'Results' = 'BPA started' }
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = [HttpStatusCode]::OK
Body = $results
Body = $Results
})
45 changes: 29 additions & 16 deletions BestPracticeAnalyser_OrchestrationStarterTimer/run.ps1
Original file line number Diff line number Diff line change
@@ -1,23 +1,36 @@
param($Timer)

if ($env:DEV_SKIP_BPA_TIMER) {
if ($env:DEV_SKIP_BPA_TIMER) {
Write-Host 'Skipping BPA timer'
exit 0
exit 0
}

try {
$CurrentlyRunning = Get-Item 'Cache_BestPracticeAnalyser\CurrentlyRunning.txt' -ErrorAction SilentlyContinue | Where-Object -Property LastWriteTime -GT (Get-Date).AddHours(-24)
if ($CurrentlyRunning) {
$Results = [pscustomobject]@{'Results' = 'Already running. Please wait for the current instance to finish' }
Write-LogMessage -API 'BestPracticeAnalyser' -message 'Attempted to start analysis but an instance was already running.' -sev Info
}
else {
$InstanceId = Start-NewOrchestration -FunctionName 'BestPracticeAnalyser_Orchestration'
Write-Host "Started orchestration with ID = '$InstanceId'"
$Orchestrator = New-OrchestrationCheckStatusResponse -Request $Timer -InstanceId $InstanceId
Write-LogMessage -API 'BestPracticeAnalyser' -message 'Started retrieving best practice information' -sev Info
$Results = [pscustomobject]@{'Results' = 'Started running analysis' }
$TenantList = Get-Tenants

$CippRoot = (Get-Item $PSScriptRoot).Parent.FullName
$TemplatesLoc = Get-ChildItem "$CippRoot\Config\*.BPATemplate.json"
$Templates = $TemplatesLoc | ForEach-Object {
$Template = $(Get-Content $_) | ConvertFrom-Json
$Template.Name
}

$BPAReports = foreach ($Tenant in $TenantList) {
foreach ($Template in $Templates) {
[PSCustomObject]@{
FunctionName = 'BPACollectData'
Tenant = $Tenant.defaultDomainName
Template = $Template
QueueName = '{0} - {1}' -f $Template, $Tenant.defaultDomainName
}
}
Write-Host ($Orchestrator | ConvertTo-Json)
}
catch { Write-Host "BestPracticeAnalyser_OrchestratorStarterTimer Exception $($_.Exception.Message)" }

$Queue = New-CippQueueEntry -Name 'Best Practice Analyser' -TotalTasks ($BPAReports | Measure-Object).Count
$BPAReports = $BPAReports | Select-Object *, @{Name = 'QueueId'; Expression = { $Queue.RowKey } }
$InputObject = [PSCustomObject]@{
Batch = @($BPAReports)
OrchestratorName = 'BPAOrchestrator'
SkipLog = $true
DurableMode = 'Sequence'
}
Start-NewOrchestration -FunctionName 'CIPPOrchestrator' -InputObject ($InputObject | ConvertTo-Json -Compress -Depth 5)
16 changes: 16 additions & 0 deletions CIPPActivityFunction/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"scriptFile": "../Modules/CippEntryPoints/CippEntryPoints.psm1",
"entryPoint": "Receive-CippActivityTrigger",
"bindings": [
{
"name": "Item",
"type": "activityTrigger",
"direction": "in"
},
{
"name": "starter",
"type": "durableClient",
"direction": "in"
}
]
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{
"scriptFile": "../Modules/CippEntryPoints/CippEntryPoints.psm1",
"entryPoint": "Receive-CippOrchestrationTrigger",
"bindings": [
{
"name": "Context",
"type": "orchestrationTrigger",
"direction": "in"
}
]
}
}
8 changes: 4 additions & 4 deletions Cache_SAMSetup/SAMManifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@
{ "id": "b27a61ec-b99c-4d6a-b126-c4375d08ae30", "type": "Scope" },
{ "id": "84bccea3-f856-4a8a-967b-dbe0a3d53a64", "type": "Scope" },
{ "id": "280b3b69-0437-44b1-bc20-3b2fca1ee3e9", "type": "Scope" },
{
"id": "885f682f-a990-4bad-a642-36736a74b0c7",
"type": "Scope"
}
{ "id": "885f682f-a990-4bad-a642-36736a74b0c7", "type": "Scope" },
{ "id": "913b9306-0ce1-42b8-9137-6a7df690a760", "type": "Role" },
{ "id": "cb8f45a0-5c2e-4ea1-b803-84b870a7d7ec", "type": "Scope" },
{ "id": "4c06a06a-098a-4063-868e-5dfee3827264", "type": "Scope" }
]
},
{
Expand Down
Loading

0 comments on commit abaec39

Please sign in to comment.