forked from KelvinTegelaar/CIPP-API
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update a variety of logging output. Add IronScales mapping interface.…
… Increase Autotask filtering to customers only
- Loading branch information
Troy Harshberger
committed
Feb 23, 2024
1 parent
7fdf3f8
commit a642e61
Showing
10 changed files
with
110 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
Modules/CippExtensions/IronScales/Get-IronScalesMapping.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
function Get-IronScalesMapping { | ||
[CmdletBinding()] | ||
param ( | ||
$CIPPMapping | ||
) | ||
#Get available mappings | ||
$Mappings = [pscustomobject]@{} | ||
|
||
$Filter = "PartitionKey eq 'Mapping'" | ||
Get-CIPPAzDataTableEntity @CIPPMapping -Filter $Filter | ForEach-Object { | ||
if($null -ne $_.IronScalesName -and "" -ne $_.IronScalesName){ | ||
$Mappings | Add-Member -NotePropertyName $_.RowKey -NotePropertyValue @{ label = "$($_.IronScalesName)"; value = "$($_.IronScalesId)" } | ||
} | ||
} | ||
|
||
$Table = Get-CIPPTable -TableName Extensionsconfig | ||
try { | ||
$Configuration = ((Get-CIPPAzDataTableEntity @Table).config | ConvertFrom-Json -ea stop).IronScales | ||
|
||
$JWT = Get-IronScalesToken -configuration $configuration | ||
$reqargs = @{ Uri = "$($Configuration.apiHost+"/company/list/")"; Headers = @{ Authorization = "Bearer $($JWT)"; }} | ||
$resp = Invoke-RestMethod @reqargs | ||
$RawCompanies = $resp.companies | ||
} catch { | ||
$Message = if ($_.ErrorDetails.Message) { | ||
Get-NormalizedError -Message $_.ErrorDetails.Message | ||
} else { | ||
$_.Exception.message | ||
} | ||
|
||
Write-LogMessage -Message "Could not get IronScales Companies error: $Message " -Level Error -tenant 'CIPP' -API 'IronScalesMapping' | ||
$RawCompanies = @(@{name = "Could not get IronScales Companies, error: $Message" }) | ||
} | ||
|
||
$IronScalesCompanies = $RawCompanies | Sort-Object -Property name | ForEach-Object { | ||
[PSCustomObject]@{ | ||
name = $_.name | ||
value = "$($_.id)" | ||
} | ||
} | ||
|
||
$Tenants = Get-Tenants | ||
|
||
$MappingObj = [PSCustomObject]@{ | ||
Tenants = @($Tenants) | ||
IronScalesCompanies = @($IronScalesCompanies) | ||
Mappings = $Mappings | ||
} | ||
|
||
return $MappingObj | ||
} |
37 changes: 37 additions & 0 deletions
37
Modules/CippExtensions/IronScales/Set-IronScalesMapping.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
function Set-IronScalesMapping { | ||
[CmdletBinding()] | ||
param ( | ||
$CIPPMapping, | ||
$APIName, | ||
$Request | ||
) | ||
|
||
foreach ($Mapping in ([pscustomobject]$Request.body.mappings).psobject.properties) { | ||
$Filter = "PartitionKey eq 'Mapping' and RowKey eq '$($mapping.name)'" | ||
$res = Get-CIPPAzDataTableEntity @CIPPMapping -Filter $Filter | ||
if($null -ne $res){ | ||
Write-LogMessage -API $APINAME -user $request.headers.'x-ms-client-principal' -message "Updated mapping for $($mapping.name)." -Sev 'Info' | ||
Update-AzDataTableEntity @CIPPMapping -Entity @{ | ||
PartitionKey = $res.PartitionKey | ||
RowKey = $res.RowKey | ||
'IronScalesName' = "$($Mapping.value.label)" | ||
'IronScalesId' = "$($Mapping.value.value)" | ||
} | ||
} | ||
else { | ||
Write-LogMessage -API $APINAME -user $request.headers.'x-ms-client-principal' -message "Added mapping for $($mapping.name)." -Sev 'Info' | ||
|
||
$AddObject = @{ | ||
PartitionKey = 'Mapping' | ||
RowKey = "$($mapping.name)" | ||
'IronScalesId' = "$($mapping.value.value)" | ||
'IronScalesName' = "$($mapping.value.label)" | ||
} | ||
|
||
Add-CIPPAzDataTableEntity @CIPPMapping -Entity $AddObject -Force | ||
} | ||
} | ||
$Result = [pscustomobject]@{'Results' = "Successfully edited mapping table." } | ||
|
||
Return $Result | ||
} |