Skip to content

Commit a82676d

Browse files
committed
port manual credential option to ExecCombinedSetup
1 parent 48741f3 commit a82676d

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Setup/Invoke-ExecCombinedSetup.ps1

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
using namespace System.Net
22

3-
Function Invoke-ExecCombinedSetup {
3+
function Invoke-ExecCombinedSetup {
44
<#
55
.FUNCTIONALITY
66
Entrypoint,AnyTenant
77
.ROLE
88
CIPP.AppSettings.ReadWrite
99
#>
10+
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')]
1011
[CmdletBinding()]
1112
param($Request, $TriggerMetadata)
1213
#Make arraylist of Results
1314
$Results = [System.Collections.ArrayList]::new()
1415
try {
16+
# Set up Azure context if needed for Key Vault access
17+
if ($env:AzureWebJobsStorage -ne 'UseDevelopmentStorage=true' -and $env:MSI_SECRET) {
18+
Disable-AzContextAutosave -Scope Process | Out-Null
19+
$null = Connect-AzAccount -Identity
20+
$SubscriptionId = $env:WEBSITE_OWNER_NAME -split '\+' | Select-Object -First 1
21+
$null = Set-AzContext -SubscriptionId $SubscriptionId
22+
}
1523
if ($request.body.selectedBaselines -and $request.body.baselineOption -eq 'downloadBaselines') {
1624
#do a single download of the selected baselines.
1725
foreach ($template in $request.body.selectedBaselines) {
@@ -56,6 +64,47 @@ Function Invoke-ExecCombinedSetup {
5664
$notificationResults = Set-CIPPNotificationConfig @notificationConfig
5765
$Results.add($notificationResults)
5866
}
67+
if ($Request.Body.selectedOption -eq 'Manual') {
68+
$KV = $env:WEBSITE_DEPLOYMENT_ID
69+
70+
if ($env:AzureWebJobsStorage -eq 'UseDevelopmentStorage=true') {
71+
$DevSecretsTable = Get-CIPPTable -tablename 'DevSecrets'
72+
$Secret = Get-CIPPAzDataTableEntity @DevSecretsTable -Filter "PartitionKey eq 'Secret' and RowKey eq 'Secret'"
73+
if (!$Secret) {
74+
$Secret = [PSCustomObject]@{
75+
'PartitionKey' = 'Secret'
76+
'RowKey' = 'Secret'
77+
'TenantId' = ''
78+
'RefreshToken' = ''
79+
'ApplicationId' = ''
80+
'ApplicationSecret' = ''
81+
}
82+
Add-CIPPAzDataTableEntity @DevSecretsTable -Entity $Secret -Force
83+
}
84+
85+
if ($Request.Body.tenantId) { $Secret.TenantId = $Request.Body.tenantid }
86+
if ($Request.Body.applicationId) { $Secret.ApplicationId = $Request.Body.applicationId }
87+
if ($Request.Body.ApplicationSecret) { $Secret.ApplicationSecret = $Request.Body.ApplicationSecret }
88+
Add-CIPPAzDataTableEntity @DevSecretsTable -Entity $Secret -Force
89+
$Results.add('Manual credentials have been set in the DevSecrets table.')
90+
} else {
91+
if ($Request.Body.tenantId) {
92+
Set-AzKeyVaultSecret -VaultName $kv -Name 'tenantid' -SecretValue (ConvertTo-SecureString -String $Request.Body.tenantId -AsPlainText -Force)
93+
$Results.add('Set tenant ID in Key Vault.')
94+
}
95+
if ($Request.Body.applicationId) {
96+
Set-AzKeyVaultSecret -VaultName $kv -Name 'applicationid' -SecretValue (ConvertTo-SecureString -String $Request.Body.applicationId -AsPlainText -Force)
97+
$Results.add('Set application ID in Key Vault.')
98+
}
99+
if ($Request.Body.applicationSecret) {
100+
Set-AzKeyVaultSecret -VaultName $kv -Name 'applicationsecret' -SecretValue (ConvertTo-SecureString -String $Request.Body.applicationSecret -AsPlainText -Force)
101+
$Results.add('Set application secret in Key Vault.')
102+
}
103+
}
104+
105+
$Results.add('Manual credentials setup has been completed.')
106+
}
107+
59108
$Results.add('Setup is now complete. You may navigate away from this page and start using CIPP.')
60109
#one more force of reauth so env vars update.
61110
$auth = Get-CIPPAuthentication

0 commit comments

Comments
 (0)