Skip to content

Commit 8f902a8

Browse files
authored
Merge branch 'dev' into fix-issue-4005
2 parents 408e4f6 + fd0495b commit 8f902a8

File tree

7 files changed

+92
-18
lines changed

7 files changed

+92
-18
lines changed

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tenant/Standards/Invoke-RemoveStandardTemplate.ps1

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using namespace System.Net
22

3-
Function Invoke-RemoveStandardTemplate {
3+
function Invoke-RemoveStandardTemplate {
44
<#
55
.FUNCTIONALITY
66
Entrypoint,AnyTenant
@@ -32,12 +32,9 @@ Function Invoke-RemoveStandardTemplate {
3232
$StatusCode = [HttpStatusCode]::InternalServerError
3333
}
3434

35-
3635
# Associate values to output bindings by calling 'Push-OutputBinding'.
3736
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
3837
StatusCode = $StatusCode
3938
Body = @{'Results' = $Result }
4039
})
41-
42-
4340
}

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tenant/Tools/Invoke-ExecGraphExplorerPreset.ps1

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using namespace System.Net
22

3-
Function Invoke-ExecGraphExplorerPreset {
3+
function Invoke-ExecGraphExplorerPreset {
44
<#
55
.FUNCTIONALITY
66
Entrypoint
@@ -22,7 +22,7 @@ Function Invoke-ExecGraphExplorerPreset {
2222

2323
switch ($Action) {
2424
'Copy' {
25-
$Id = $Request.Body.preset.id ? $Request.Body.preset.id: (New-Guid).Guid
25+
$Id = $Request.Body.preset.id ? $Request.Body.preset.id : (New-Guid).Guid
2626
}
2727
'Save' {
2828
$Id = $Request.Body.preset.id
@@ -42,6 +42,32 @@ Function Invoke-ExecGraphExplorerPreset {
4242
$params.'$select' = ($params.'$select').value -join ','
4343
}
4444

45+
if (!$Request.Body.preset.name) {
46+
$Message = 'Error: Preset name is required'
47+
$StatusCode = [HttpStatusCode]::BadRequest
48+
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
49+
StatusCode = $StatusCode
50+
Body = @{
51+
Results = $Message
52+
Success = $false
53+
}
54+
})
55+
return
56+
}
57+
58+
if (!$Request.Body.preset.endpoint) {
59+
$Message = 'Error: Preset endpoint is required'
60+
$StatusCode = [HttpStatusCode]::BadRequest
61+
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
62+
StatusCode = $StatusCode
63+
Body = @{
64+
Results = $Message
65+
Success = $false
66+
}
67+
})
68+
return
69+
}
70+
4571
$Preset = [PSCustomObject]@{
4672
PartitionKey = 'Preset'
4773
RowKey = [string]$Id

Modules/CIPPCore/Public/Entrypoints/Invoke-ListGraphExplorerPresets.ps1

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using namespace System.Net
22

3-
Function Invoke-ListGraphExplorerPresets {
3+
function Invoke-ListGraphExplorerPresets {
44
<#
55
.FUNCTIONALITY
66
Entrypoint,AnyTenant
@@ -19,14 +19,14 @@ Function Invoke-ListGraphExplorerPresets {
1919

2020
try {
2121
$Table = Get-CIPPTable -TableName 'GraphPresets'
22-
$Presets = Get-CIPPAzDataTableEntity @Table -Filter "Owner eq '$Username' or IsShared eq true" | Sort-Object -Property name
22+
$Presets = Get-CIPPAzDataTableEntity @Table | Where-Object { $Username -eq $_.Owner -or $_.IsShared -eq $true } | Sort-Object -Property name
2323
$Results = foreach ($Preset in $Presets) {
2424
[PSCustomObject]@{
2525
id = $Preset.Id
2626
name = $Preset.name
2727
IsShared = $Preset.IsShared
2828
IsMyPreset = $Preset.Owner -eq $Username
29-
params = ConvertFrom-Json -InputObject $Preset.Params
29+
params = (ConvertFrom-Json -InputObject $Preset.Params)
3030
}
3131
}
3232

@@ -35,6 +35,8 @@ Function Invoke-ListGraphExplorerPresets {
3535
$Results = $Results | Where-Object { ($_.params.endpoint -replace '^/', '') -eq $Endpoint }
3636
}
3737
} catch {
38+
Write-Warning "Could not list presets. $($_.Exception.Message)"
39+
Write-Information $_.InvocationInfo.PositionMessage
3840
$Results = @()
3941
}
4042
# Associate values to output bindings by calling 'Push-OutputBinding'.

Modules/CIPPCore/Public/Get-CIPPAuthentication.ps1

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,22 @@ function Get-CIPPAuthentication {
1919
}
2020
}
2121
} else {
22+
Write-Information 'Connecting to Azure'
2223
Connect-AzAccount -Identity
2324
$SubscriptionId = $env:WEBSITE_OWNER_NAME -split '\+' | Select-Object -First 1
24-
$null = Set-AzContext -SubscriptionId $SubscriptionId
25+
try {
26+
$Context = Get-AzContext
27+
if ($Context.Subscription) {
28+
#Write-Information "Current context: $($Context | ConvertTo-Json)"
29+
if ($Context.Subscription.Id -ne $SubscriptionId) {
30+
Write-Information "Setting context to subscription $SubscriptionId"
31+
$null = Set-AzContext -SubscriptionId $SubscriptionId
32+
}
33+
}
34+
} catch {
35+
Write-Information "ERROR: Could not set context to subscription $SubscriptionId."
36+
}
37+
2538
$keyvaultname = ($env:WEBSITE_DEPLOYMENT_ID -split '-')[0]
2639
$Variables | ForEach-Object {
2740
Set-Item -Path env:$_ -Value (Get-AzKeyVaultSecret -VaultName $keyvaultname -Name $_ -AsPlainText -ErrorAction Stop) -Force

Modules/CIPPCore/Public/GraphHelper/Get-Tenants.ps1

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ function Get-Tenants {
7575
if (($BuildRequired -or $TriggerRefresh.IsPresent) -and $PartnerTenantState.state -ne 'owntenant') {
7676
# Get TenantProperties table
7777
$PropertiesTable = Get-CippTable -TableName 'TenantProperties'
78-
$Aliases = Get-CIPPAzDataTableEntity @PropertiesTable -Filter "RowKey eq 'Alias'"
7978

8079
#get the full list of tenants
8180
$GDAPRelationships = New-GraphGetRequest -uri "https://graph.microsoft.com/beta/tenantRelationships/delegatedAdminRelationships?`$filter=status eq 'active' and not startsWith(displayName,'MLT_')$RelationshipFilter&`$select=customer,autoExtendDuration,endDateTime&`$top=300" -NoAuthCheck:$true
@@ -95,7 +94,11 @@ function Get-Tenants {
9594
# Write-Host "Processing $($_.Name), $($_.displayName) to add to tenant list."
9695
$ExistingTenantInfo = Get-CIPPAzDataTableEntity @TenantsTable -Filter "PartitionKey eq 'Tenants' and RowKey eq '$($_.Name)'"
9796

98-
$Alias = ($Aliases | Where-Object { $_.PartitionKey -eq $_.Name }).Value
97+
$Alias = (Get-AzDataTableEntity @PropertiesTable -Filter "PartitionKey eq '$($_.Name)' and RowKey eq 'Alias'").Value
98+
99+
if ($Alias) {
100+
Write-Host "Alias found for $($_.Name) - $Alias."
101+
}
99102

100103
if ($TriggerRefresh.IsPresent -and $ExistingTenantInfo.customerId) {
101104
# Reset error count
@@ -104,8 +107,29 @@ function Get-Tenants {
104107
Add-CIPPAzDataTableEntity @TenantsTable -Entity $ExistingTenantInfo -Force | Out-Null
105108
}
106109

107-
if ($ExistingTenantInfo -and $ExistingTenantInfo.RequiresRefresh -eq $false -and $ExistingTenantInfo.displayName -eq $LatestRelationship.displayName) {
110+
if ($ExistingTenantInfo -and $ExistingTenantInfo.RequiresRefresh -eq $false -and ($ExistingTenantInfo.displayName -eq $LatestRelationship.displayName -or $ExistingTenantInfo.displayName -eq $Alias)) {
108111
Write-Host 'Existing tenant found. We already have it cached, skipping.'
112+
113+
$DisplayNameUpdated = $false
114+
if (![string]::IsNullOrEmpty($Alias)) {
115+
if ($Alias -ne $ExistingTenantInfo.displayName) {
116+
Write-Host "Alias found for $($_.Name)."
117+
$ExistingTenantInfo.displayName = $Alias
118+
$DisplayNameUpdated = $true
119+
}
120+
} else {
121+
if ($LatestRelationship.displayName -ne $ExistingTenantInfo.displayName) {
122+
Write-Host 'Display name changed from relationship, updating.'
123+
$ExistingTenantInfo.displayName = $LatestRelationship.displayName
124+
$DisplayNameUpdated = $true
125+
}
126+
}
127+
128+
if ($DisplayNameUpdated) {
129+
$ExistingTenantInfo.displayName = $LatestRelationship.displayName
130+
Add-CIPPAzDataTableEntity @TenantsTable -Entity $ExistingTenantInfo -Force | Out-Null
131+
}
132+
109133
$ExistingTenantInfo
110134
return
111135
}
@@ -136,9 +160,9 @@ function Get-Tenants {
136160
}
137161
Write-Host 'finished getting domain'
138162

139-
if ($Aliases.PartitionKey -contains $_.Name -and ![string]::IsNullOrEmpty($Alias)) {
140-
$Alias = $Aliases | Where-Object { $_.PartitionKey -eq $_.Name }
141-
$displayName = $Alias.Value
163+
if (![string]::IsNullOrEmpty($Alias)) {
164+
Write-Information "Setting display name to $Alias."
165+
$displayName = $Alias
142166
} else {
143167
$displayName = $LatestRelationship.displayName
144168
}

Modules/CippExtensions/Public/Extension Functions/Get-ExtensionAPIKey.ps1

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,13 @@ function Get-ExtensionAPIKey {
2323
$keyvaultname = ($env:WEBSITE_DEPLOYMENT_ID -split '-')[0]
2424
$null = Connect-AzAccount -Identity
2525
$SubscriptionId = $env:WEBSITE_OWNER_NAME -split '\+' | Select-Object -First 1
26-
$null = Set-AzContext -SubscriptionId $SubscriptionId
26+
$Context = Get-AzContext
27+
if ($Context.Subscription) {
28+
if ($Context.Subscription.Id -ne $SubscriptionId) {
29+
Write-Information "Setting context to subscription $SubscriptionId"
30+
$null = Set-AzContext -SubscriptionId $SubscriptionId
31+
}
32+
}
2733
$APIKey = (Get-AzKeyVaultSecret -VaultName $keyvaultname -Name $Extension -AsPlainText)
2834
}
2935
Set-Item -Path "env:$Var" -Value $APIKey -Force -ErrorAction SilentlyContinue

Modules/CippExtensions/Public/Extension Functions/Set-ExtensionAPIKey.ps1

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@ function Set-ExtensionAPIKey {
2626
$keyvaultname = ($env:WEBSITE_DEPLOYMENT_ID -split '-')[0]
2727
$null = Connect-AzAccount -Identity
2828
$SubscriptionId = $env:WEBSITE_OWNER_NAME -split '\+' | Select-Object -First 1
29-
$null = Set-AzContext -SubscriptionId $SubscriptionId
29+
$Context = Get-AzContext
30+
if ($Context.Subscription) {
31+
if ($Context.Subscription.Id -ne $SubscriptionId) {
32+
Write-Information "Setting context to subscription $SubscriptionId"
33+
$null = Set-AzContext -SubscriptionId $SubscriptionId
34+
}
35+
}
3036
$null = Set-AzKeyVaultSecret -VaultName $keyvaultname -Name $Extension -SecretValue (ConvertTo-SecureString -AsPlainText -Force -String $APIKey)
3137
}
3238
Set-Item -Path "env:$Var" -Value $APIKey -Force -ErrorAction SilentlyContinue

0 commit comments

Comments
 (0)