Skip to content

Commit 94b3289

Browse files
authored
Merge pull request KelvinTegelaar#1050 from JohnDuprey/dev
Bugfixes
2 parents 0d0f943 + 161736a commit 94b3289

3 files changed

Lines changed: 48 additions & 25 deletions

File tree

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Extensions/Invoke-ExecExtensionsConfig.ps1

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,22 @@ Function Invoke-ExecExtensionsConfig {
1717
#Connect-AzAccount -UseDeviceAuthentication
1818
# Write to the Azure Functions log stream.
1919
Write-Information 'PowerShell HTTP trigger function processed a request.'
20+
$Body = [PSCustomObject]$Request.Body
2021
$results = try {
21-
if ($Request.Body.CIPPAPI.Enabled) {
22+
if ($Body.CIPPAPI.Enabled) {
2223
try {
23-
$APIConfig = New-CIPPAPIConfig -ExecutingUser $Request.Headers.'x-ms-client-principal' -resetpassword $Request.Body.CIPPAPI.ResetPassword
24+
$APIConfig = New-CIPPAPIConfig -ExecutingUser $Request.Headers.'x-ms-client-principal' -resetpassword $Body.CIPPAPI.ResetPassword
2425
$AddedText = $APIConfig.Results
2526
} catch {
2627
$AddedText = ' Could not enable CIPP-API. Check the CIPP documentation for API requirements.'
27-
$Request.Body = $Request.Body | Select-Object * -ExcludeProperty CIPPAPI
28+
$Body = $Body | Select-Object * -ExcludeProperty CIPPAPI
2829
}
2930
}
3031

3132
# Check if NinjaOne URL is set correctly and the instance has at least version 5.6
32-
if ($Request.Body.NinjaOne) {
33+
if ($Body.NinjaOne) {
3334
try {
34-
[version]$Version = (Invoke-WebRequest -Method GET -Uri "https://$(($Request.Body.NinjaOne.Instance -replace '/ws','') -replace 'https://','')/app-version.txt" -ea stop).content
35+
[version]$Version = (Invoke-WebRequest -Method GET -Uri "https://$(($Body.NinjaOne.Instance -replace '/ws','') -replace 'https://','')/app-version.txt" -ea stop).content
3536
} catch {
3637
throw "Failed to connect to NinjaOne check your Instance is set correctly eg 'app.ninjarmmm.com'"
3738
}
@@ -41,39 +42,39 @@ Function Invoke-ExecExtensionsConfig {
4142
}
4243

4344
$Table = Get-CIPPTable -TableName Extensionsconfig
44-
foreach ($APIKey in ([pscustomobject]$Request.Body).psobject.properties.name) {
45+
foreach ($APIKey in $Body.PSObject.Properties.Name) {
4546
Write-Information "Working on $apikey"
46-
if ($Request.Body.$APIKey.APIKey -eq 'SentToKeyVault' -or $Request.Body.$APIKey.APIKey -eq '') {
47+
if ($Body.$APIKey.APIKey -eq 'SentToKeyVault' -or $Body.$APIKey.APIKey -eq '') {
4748
Write-Information 'Not sending to keyvault. Key previously set or left blank.'
4849
} else {
4950
Write-Information 'writing API Key to keyvault, and clearing.'
5051
Write-Information "$ENV:WEBSITE_DEPLOYMENT_ID"
51-
if ($Request.Body.$APIKey.APIKey) {
52+
if ($Body.$APIKey.APIKey) {
5253
if ($env:AzureWebJobsStorage -eq 'UseDevelopmentStorage=true') {
5354
$DevSecretsTable = Get-CIPPTable -tablename 'DevSecrets'
5455
$Secret = [PSCustomObject]@{
5556
'PartitionKey' = $APIKey
5657
'RowKey' = $APIKey
57-
'APIKey' = $Request.Body.$APIKey.APIKey
58+
'APIKey' = $Body.$APIKey.APIKey
5859
}
5960
Add-CIPPAzDataTableEntity @DevSecretsTable -Entity $Secret -Force
6061
} else {
61-
$null = Set-AzKeyVaultSecret -VaultName $ENV:WEBSITE_DEPLOYMENT_ID -Name $APIKey -SecretValue (ConvertTo-SecureString -AsPlainText -Force -String $Request.Body.$APIKey.APIKey)
62+
$null = Set-AzKeyVaultSecret -VaultName $ENV:WEBSITE_DEPLOYMENT_ID -Name $APIKey -SecretValue (ConvertTo-SecureString -AsPlainText -Force -String $Body.$APIKey.APIKey)
6263
}
6364
}
64-
if ($Request.Body.$APIKey.PSObject.Properties -notcontains 'APIKey') {
65-
$Request.Body.$APIKey | Add-Member -MemberType NoteProperty -Name APIKey -Value 'SentToKeyVault'
65+
if ($Body.$APIKey.PSObject.Properties.Name -notcontains 'APIKey') {
66+
$Body.$APIKey | Add-Member -MemberType NoteProperty -Name APIKey -Value 'SentToKeyVault'
6667
} else {
67-
$Request.Body.$APIKey.APIKey = 'SentToKeyVault'
68+
$Body.$APIKey.APIKey = 'SentToKeyVault'
6869
}
6970
}
70-
$Request.Body.$APIKey = $Request.Body.$APIKey | Select-Object * -ExcludeProperty ResetPassword
71+
$Body.$APIKey = $Body.$APIKey | Select-Object * -ExcludeProperty ResetPassword
7172
}
72-
$body = $Request.Body | Select-Object * -ExcludeProperty APIKey, Enabled | ConvertTo-Json -Depth 10 -Compress
73+
$Body = $Body | Select-Object * -ExcludeProperty APIKey, Enabled | ConvertTo-Json -Depth 10 -Compress
7374
$Config = @{
7475
'PartitionKey' = 'CippExtensions'
7576
'RowKey' = 'Config'
76-
'config' = [string]$body
77+
'config' = [string]$Body
7778
}
7879

7980
Add-CIPPAzDataTableEntity @Table -Entity $Config -Force | Out-Null

Modules/CippExtensions/Public/PwPush/New-PwPushLink.ps1

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,21 @@ function New-PwPushLink {
1313
if ($Configuration.ExpireAfterDays) { $PushParams.ExpireAfterDays = $Configuration.ExpireAfterDays }
1414
if ($Configuration.ExpireAfterViews) { $PushParams.ExpireAfterViews = $Configuration.ExpireAfterViews }
1515
if ($Configuration.DeletableByViewer) { $PushParams.DeletableByViewer = $Configuration.DeletableByViewer }
16-
$Link = New-Push @PushParams | Select-Object Link, LinkRetrievalStep
17-
if ($Configuration.RetrievalStep) {
18-
$Link.Link = $Link.LinkRetrievalStep
16+
try {
17+
$Link = New-Push @PushParams | Select-Object Link, LinkRetrievalStep
18+
if ($Configuration.RetrievalStep) {
19+
$Link.Link = $Link.LinkRetrievalStep
20+
}
21+
$Link | Select-Object -ExpandProperty Link
22+
} catch {
23+
$LogData = [PSCustomObject]@{
24+
'Response' = $Link
25+
'Exception' = Get-CippException -Exception $_
26+
}
27+
Write-LogMessage -API PwPush -Message "Failed to create a new PwPush link: $($_.Exception.Message)" -Sev 'Error' -LogData $LogData
28+
throw 'Failed to create a new PwPush link, check the log book for more details'
1929
}
20-
$Link | Select-Object -ExpandProperty Link
2130
} else {
2231
return $false
2332
}
24-
}
33+
}
Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,36 @@
11
function Set-PwPushConfig {
2+
<#
3+
.SYNOPSIS
4+
Sets PwPush configuration
5+
6+
.DESCRIPTION
7+
Sets PwPush configuration from CIPP Extension config
8+
9+
.PARAMETER Configuration
10+
Configuration object
11+
#>
12+
[CmdletBinding(SupportsShouldProcess = $true)]
213
param(
314
$Configuration
415
)
516
$InitParams = @{}
617
if ($Configuration.BaseUrl) {
718
$InitParams.BaseUrl = $Configuration.BaseUrl
819
}
9-
if ($Configuration.EmailAddress) {
20+
if (![string]::IsNullOrEmpty($Configuration.EmailAddress)) {
1021
if ($env:AzureWebJobsStorage -eq 'UseDevelopmentStorage=true') {
1122
$DevSecretsTable = Get-CIPPTable -tablename 'DevSecrets'
1223
$ApiKey = (Get-CIPPAzDataTableEntity @DevSecretsTable -Filter "PartitionKey eq 'PWPush' and RowKey eq 'PWPush'").APIKey
1324
} else {
1425
$null = Connect-AzAccount -Identity
1526
$ApiKey = Get-AzKeyVaultSecret -VaultName $ENV:WEBSITE_DEPLOYMENT_ID -Name 'PWPush' -AsPlainText
1627
}
17-
if ($ApiKey) {
28+
if (![string]::IsNullOrEmpty($ApiKey)) {
1829
$InitParams.APIKey = $ApiKey
1930
$InitParams.EmailAddress = $Configuration.EmailAddress
2031
}
2132
}
22-
Initialize-PassPushPosh @InitParams
23-
}
33+
if ($PSCmdlet.ShouldProcess('Initialize-PassPushPosh')) {
34+
Initialize-PassPushPosh @InitParams
35+
}
36+
}

0 commit comments

Comments
 (0)