From f529ea5ea9fb39ed26e0105566e5c7f103db1085 Mon Sep 17 00:00:00 2001 From: John Duprey Date: Tue, 11 Feb 2025 21:09:32 -0500 Subject: [PATCH 1/3] upload template tweaks --- .../Tools/GitHub/Invoke-ExecCommunityRepo.ps1 | 24 ++++++++++++++++++- .../GitHub/Invoke-ListCommunityRepos.ps1 | 2 ++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tools/GitHub/Invoke-ExecCommunityRepo.ps1 b/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tools/GitHub/Invoke-ExecCommunityRepo.ps1 index 573cb275f16f..845dc1e6906c 100644 --- a/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tools/GitHub/Invoke-ExecCommunityRepo.ps1 +++ b/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tools/GitHub/Invoke-ExecCommunityRepo.ps1 @@ -88,12 +88,13 @@ function Invoke-ExecCommunityRepo { $GUID = $Request.Body.GUID $TemplateTable = Get-CIPPTable -TableName templates $TemplateEntity = Get-CIPPAzDataTableEntity @TemplateTable -Filter "RowKey eq '$($GUID)'" + $Branch = $RepoEntity.UploadBranch ?? $RepoEntity.DefaultBranch if ($TemplateEntity) { $Template = $TemplateEntity.JSON | ConvertFrom-Json $DisplayName = $Template.Displayname ?? $Template.templateName ?? $Template.name $Basename = $DisplayName -replace '\s', '_' -replace '[^\w\d_]', '' $Path = '{0}/{1}.json' -f $TemplateEntity.PartitionKey, $Basename - $Results = Push-GitHubContent -FullName $Request.Body.FullName -Path $Path -Content ($TemplateEntity | ConvertTo-Json -Compress) -Message $Request.Body.Message + $Results = Push-GitHubContent -FullName $Request.Body.FullName -Path $Path -Content ($TemplateEntity | ConvertTo-Json -Compress) -Message $Request.Body.Message -Branch $Branch $Results = @{ resultText = "Template '$($DisplayName)' uploaded" @@ -106,6 +107,27 @@ function Invoke-ExecCommunityRepo { } } } + 'SetBranch' { + if (!$RepoEntity) { + $Results = @{ + resultText = "Repository $($Id) not found" + state = 'error' + } + } else { + $Branch = $Request.Body.Branch + if (!$RepoEntity.UploadBranch) { + $RepoEntity | Add-Member -NotePropertyName 'UploadBranch' -NotePropertyValue $Branch + } else { + $RepoEntity.UploadBranch = $Branch + } + $null = Add-CIPPAzDataTableEntity @Table -Entity $RepoEntity -Force + + $Results = @{ + resultText = "Branch set to $Branch" + state = 'success' + } + } + } 'ImportTemplate' { $Path = $Request.Body.Path $FullName = $Request.Body.FullName diff --git a/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tools/GitHub/Invoke-ListCommunityRepos.ps1 b/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tools/GitHub/Invoke-ListCommunityRepos.ps1 index 0b8d54094286..b1e33a877336 100644 --- a/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tools/GitHub/Invoke-ListCommunityRepos.ps1 +++ b/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tools/GitHub/Invoke-ListCommunityRepos.ps1 @@ -41,6 +41,7 @@ function Invoke-ListCommunityRepos { Visibility = $Repo.Visibility WriteAccess = $Repo.WriteAccess DefaultBranch = $Repo.DefaultBranch + UploadBranch = $Repo.DefaultBranch Permissions = [string]($Repo.RepoPermissions | ConvertTo-Json) } Add-CIPPAzDataTableEntity @Table -Entity $Entity @@ -63,6 +64,7 @@ function Invoke-ListCommunityRepos { Visibility = $_.Visibility WriteAccess = $_.WriteAccess DefaultBranch = $_.DefaultBranch + UploadBranch = $_.UploadBranch ?? $_.DefaultBranch RepoPermissions = $_.Permissions | ConvertFrom-Json } } From 1aba62e6854914406a377513fc003908f5126f66 Mon Sep 17 00:00:00 2001 From: John Duprey Date: Wed, 12 Feb 2025 00:10:38 -0500 Subject: [PATCH 2/3] Update Invoke-ListGraphExplorerPresets.ps1 --- .../Public/Entrypoints/Invoke-ListGraphExplorerPresets.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/CIPPCore/Public/Entrypoints/Invoke-ListGraphExplorerPresets.ps1 b/Modules/CIPPCore/Public/Entrypoints/Invoke-ListGraphExplorerPresets.ps1 index d899116de6b1..86153e7e1fc9 100644 --- a/Modules/CIPPCore/Public/Entrypoints/Invoke-ListGraphExplorerPresets.ps1 +++ b/Modules/CIPPCore/Public/Entrypoints/Invoke-ListGraphExplorerPresets.ps1 @@ -12,7 +12,7 @@ Function Invoke-ListGraphExplorerPresets { $APIName = $Request.Params.CIPPEndpoint Write-LogMessage -headers $Request.Headers -API $APINAME -message 'Accessed this API' -Sev 'Debug' - $Username = ([System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($Request.Headers)) | ConvertFrom-Json).userDetails + $Username = $Request.Headers['x-ms-client-principal-name'] try { $Table = Get-CIPPTable -TableName 'GraphPresets' From bc714f4deec41239d96816c4cb253faeb9139dba Mon Sep 17 00:00:00 2001 From: John Duprey Date: Wed, 12 Feb 2025 00:50:18 -0500 Subject: [PATCH 3/3] fix community repo table lookup --- .../Tools/GitHub/Invoke-ExecCommunityRepo.ps1 | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tools/GitHub/Invoke-ExecCommunityRepo.ps1 b/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tools/GitHub/Invoke-ExecCommunityRepo.ps1 index 845dc1e6906c..169f700987de 100644 --- a/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tools/GitHub/Invoke-ExecCommunityRepo.ps1 +++ b/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tools/GitHub/Invoke-ExecCommunityRepo.ps1 @@ -14,9 +14,29 @@ function Invoke-ExecCommunityRepo { $Action = $Request.Body.Action $Id = $Request.Body.Id + if ($Request.Body.Id) { + $Filter = "PartitionKey eq 'CommunityRepos' and RowKey eq '$($Id)'" + } elseif ($Request.Body.FullName) { + $Filter = "PartitionKey eq 'CommunityRepos' and FullName eq '$($Request.Body.FullName)'" + } else { + $Results = @( + @{ + resultText = 'Id or FullName required' + state = 'error' + } + ) + $Body = @{ + Results = $Results + } + + Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{ + StatusCode = [HttpStatusCode]::OK + Body = $Body + }) + return + } $Table = Get-CIPPTable -TableName CommunityRepos - $Filter = "PartitionKey eq 'CommunityRepos' and RowKey eq '$($Id)'" $RepoEntity = Get-CIPPAzDataTableEntity @Table -Filter $Filter switch ($Action) { @@ -92,6 +112,14 @@ function Invoke-ExecCommunityRepo { if ($TemplateEntity) { $Template = $TemplateEntity.JSON | ConvertFrom-Json $DisplayName = $Template.Displayname ?? $Template.templateName ?? $Template.name + if ($Template.tenantFilter) { + $Template.tenantFilter = @(@{ label = 'Template Tenant'; value = 'Template Tenant' }) + } + if ($Template.excludedTenants) { + $Template.excludedTenants = @() + } + $TemplateEntity.JSON = $Template | ConvertTo-Json -Compress -Depth 100 + $Basename = $DisplayName -replace '\s', '_' -replace '[^\w\d_]', '' $Path = '{0}/{1}.json' -f $TemplateEntity.PartitionKey, $Basename $Results = Push-GitHubContent -FullName $Request.Body.FullName -Path $Path -Content ($TemplateEntity | ConvertTo-Json -Compress) -Message $Request.Body.Message -Branch $Branch