Skip to content

Commit

Permalink
Merge pull request #61 from KelvinTegelaar/dev
Browse files Browse the repository at this point in the history
[pull] dev from KelvinTegelaar:dev
  • Loading branch information
pull[bot] authored Feb 7, 2025
2 parents 5adf4b3 + 56fde8a commit 40fae4b
Show file tree
Hide file tree
Showing 18 changed files with 1,367 additions and 1,199 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ Function Invoke-ExecExtensionMapping {
'Sherweb' {
$Body = Get-SherwebMapping -CIPPMapping $Table
}
'HaloPSAFields' {
$TicketTypes = Get-HaloTicketType
$Body = @{'TicketTypes' = $TicketTypes }
}
'PWPushFields' {
$Accounts = Get-PwPushAccount
$Body = @{
'Accounts' = $Accounts
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Function Invoke-ExecExtensionTest {
$Payload = 'This is a test from CIPP'
$PasswordLink = New-PwPushLink -Payload $Payload
if ($PasswordLink) {
$Results = [pscustomobject]@{'Results' = 'Successfully generated PWPush'; 'Link' = $PasswordLink }
$Results = [pscustomobject]@{Results = @(@{'resultText' = 'Successfully generated PWPush, hit the Copy to Clipboard button to retrieve the test.'; 'copyField' = $PasswordLink; 'state' = 'success' }) }
} else {
$Results = [pscustomobject]@{'Results' = 'PWPush is not enabled' }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ function Invoke-ExecApiClient {
'Enabled' = $Request.Body.Enabled ?? $false
}
$Results = @{
text = "API Client created '$($Client.AppName)'"
copyField = $APIConfig.ApplicationSecret
severity = 'success'
resultText = "API Client created with the name '$($Client.AppName)'. Use the Copy to Clipboard button to retrieve the secret."
copyField = $APIConfig.ApplicationSecret
state = 'success'
}
}

Expand Down Expand Up @@ -117,22 +117,22 @@ function Invoke-ExecApiClient {
$Client = Get-CIPPAzDataTableEntity @Table -Filter "RowKey eq '$($Request.Body.ClientId)'"
if (!$Client) {
$Results = @{
text = 'API client not found'
severity = 'error'
resultText = 'API client not found'
severity = 'error'
}
} else {
$ApiConfig = New-CIPPAPIConfig -ResetSecret -AppId $Request.Body.ClientId

if ($ApiConfig.ApplicationSecret) {
$Results = @{
text = "API secret reset for $($Client.AppName)"
copyField = $ApiConfig.ApplicationSecret
severity = 'success'
resultText = "API secret reset for $($Client.AppName). Use the Copy to Clipboard button to retrieve the new secret."
copyField = $ApiConfig.ApplicationSecret
state = 'success'
}
} else {
$Results = @{
text = "Failed to reset secret for $($Client.AppName)"
severity = 'error'
resultText = "Failed to reset secret for $($Client.AppName)"
state = 'error'
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,21 @@ Function Invoke-ListExtensionsConfig {
$Table = Get-CIPPTable -TableName Extensionsconfig
try {
$Body = (Get-CIPPAzDataTableEntity @Table).config | ConvertFrom-Json -Depth 10 -ErrorAction Stop
if ($Body.HaloPSA.TicketType -and !$Body.HaloPSA.TicketType.value) {
# translate ticket type to autocomplete format
Write-Information "Ticket Type: $($Body.HaloPSA.TicketType)"
$Types = Get-HaloTicketType
$Type = $Types | Where-Object { $_.id -eq $Body.HaloPSA.TicketType }
#Write-Information ($Type | ConvertTo-Json)
if ($Type) {
$Body.HaloPSA.TicketType = @{
label = $Type.name
value = $Type.id
}
}
}
} catch {
Write-Information (Get-CippException -Exception $_ | ConvertTo-Json)
$Body = @{}
}
# Associate values to output bindings by calling 'Push-OutputBinding'.
Expand Down
327 changes: 170 additions & 157 deletions Modules/CIPPCore/Public/New-CIPPTemplateRun.ps1

Large diffs are not rendered by default.

23 changes: 23 additions & 0 deletions Modules/CippExtensions/Private/GitHub/Get-GitHubFileContents.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
function Get-GitHubFileContents {
[CmdletBinding()]
param (
[Parameter(ValueFromPipelineByPropertyName = $true)]
$Url
)

process {
$Table = Get-CIPPTable -TableName Extensionsconfig
$Configuration = ((Get-CIPPAzDataTableEntity @Table).config | ConvertFrom-Json).GitHub
[uri]$Uri = $Url
$Path = $Uri.PathAndQuery.TrimStart('/')
$File = Invoke-GitHubApiRequest -Configuration $Configuration -Path "$Path" -Method GET

return [PSCustomObject]@{
name = $File.name
path = $File.path
content = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($File.content))
sha = $File.sha
size = $File.size
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ function Invoke-GitHubApiRequest {
}

$FullUri = "https://api.github.com/$Path"
Write-Verbose "[$Method] $FullUri"
return Invoke-RestMethod -Method $Method -Uri $FullUri -Headers $Headers -Body $Body
} else {
throw 'GitHub API is not enabled'
Expand Down
38 changes: 38 additions & 0 deletions Modules/CippExtensions/Private/GitHub/Search-GitHubRepository.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
function Search-GitHubRepository {
[CmdletBinding()]
Param (
[string[]]$Repository,
[string]$Path,
[string]$SearchTerm,
[string]$Language,
[string]$Type = 'code'
)
$Table = Get-CIPPTable -TableName Extensionsconfig
$Configuration = ((Get-CIPPAzDataTableEntity @Table).config | ConvertFrom-Json).GitHub

$QueryParts = [System.Collections.Generic.List[string]]::new()
if ($Repository) {
$RepoParts = [System.Collections.Generic.List[string]]::new()
foreach ($Repo in $Repository) {
$RepoParts.Add("repo:$Repo")
}
if (($RepoParts | Measure-Object).Count -gt 1) {
$QueryParts.Add('(' + ($RepoParts -join ' OR ') + ')')
} else {
$QueryParts.Add($RepoParts[0])
}
}
if ($Path) {
$QueryParts.Add("path:$Path")
}
if ($SearchTerm) {
$QueryParts.Add("`"$SearchTerm`"")
}
if ($Language) {
$QueryParts.Add("language:$Language")
}

$Query = $QueryParts -join ' '
Write-Information "Query: $Query"
Invoke-GitHubApiRequest -Configuration $Configuration -Path "search/$($Type)?q=$($Query)" -Method GET
}
28 changes: 28 additions & 0 deletions Modules/CippExtensions/Public/Halo/Get-HaloTicketType.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
function Get-HaloTicketType {
<#
.SYNOPSIS
Get Halo Ticket Type
.DESCRIPTION
Get Halo Ticket Type
.EXAMPLE
Get-HaloTicketType
#>
[CmdletBinding()]
param ()
$Table = Get-CIPPTable -TableName Extensionsconfig
try {
$Configuration = ((Get-CIPPAzDataTableEntity @Table).config | ConvertFrom-Json -ea stop).HaloPSA
$Token = Get-HaloToken -configuration $Configuration

Invoke-RestMethod -Uri "$($Configuration.ResourceURL)/TicketType?showall=true&showinactive=true&access_control_level=2&include_defaults=true&domain=reqs" -ContentType 'application/json' -Method GET -Headers @{Authorization = "Bearer $($Token.access_token)" }
} catch {
$Message = if ($_.ErrorDetails.Message) {
Get-NormalizedError -Message $_.ErrorDetails.Message
} else {
$_.Exception.message
}
@(@{name = "Could not get HaloPSA Ticket Types, error: $Message"; id = '' })
}
}

1 change: 0 additions & 1 deletion Modules/CippExtensions/Public/Halo/Get-HaloToken.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ function Get-HaloToken {
client_secret = $Secret
scope = 'all'
}
Write-Host ($body | ConvertTo-Json)
if ($Configuration.Tenant -ne 'None') { $Tenant = "?tenant=$($Configuration.Tenant)" }
$token = Invoke-RestMethod -Uri "$($Configuration.AuthURL)/token$Tenant" -Method Post -Body $body -ContentType 'application/x-www-form-urlencoded'
return $token
Expand Down
22 changes: 12 additions & 10 deletions Modules/CippExtensions/Public/Halo/New-HaloPSATicket.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function New-HaloPSATicket {
[CmdletBinding()]
[CmdletBinding(SupportsShouldProcess)]
param (
$title,
$description,
Expand Down Expand Up @@ -29,25 +29,27 @@ function New-HaloPSATicket {
}

if ($Configuration.TicketType) {
$object | Add-Member -MemberType NoteProperty -Name 'tickettype_id' -Value $Configuration.TicketType -Force
$TicketType = $Configuration.TicketType.value ?? $Configuration.TicketType
$object | Add-Member -MemberType NoteProperty -Name 'tickettype_id' -Value $TicketType -Force
}
#use the token to create a new ticket in HaloPSA
$body = ConvertTo-Json -Compress -Depth 10 -InputObject @($Object)


Write-Host 'Sending ticket to HaloPSA'
Write-Host $body
Write-Information 'Sending ticket to HaloPSA'
Write-Information $body
try {
$Ticket = Invoke-RestMethod -Uri "$($Configuration.ResourceURL)/Tickets" -ContentType 'application/json; charset=utf-8' -Method Post -Body $body -Headers @{Authorization = "Bearer $($token.access_token)" }
if ($PSCmdlet.ShouldProcess('Send ticket to HaloPSA', 'Create ticket')) {
$Ticket = Invoke-RestMethod -Uri "$($Configuration.ResourceURL)/Tickets" -ContentType 'application/json; charset=utf-8' -Method Post -Body $body -Headers @{Authorization = "Bearer $($token.access_token)" }
Write-Information "Ticket created in HaloPSA: $($Ticket.id)"
}
} catch {
$Message = if ($_.ErrorDetails.Message) {
Get-NormalizedError -Message $_.ErrorDetails.Message
} else {
$_.Exception.message
}
Write-LogMessage -message "Failed to send ticket to HaloPSA: $Message" -API 'HaloPSATicket' -sev Error
Write-Host "Failed to send ticket to HaloPSA: $Message"
Write-Host "Body we tried to ship: $body"
Write-LogMessage -message "Failed to send ticket to HaloPSA: $Message" -API 'HaloPSATicket' -sev Error -LogData (Get-CippException -Exception $_)
Write-Information "Failed to send ticket to HaloPSA: $Message"
Write-Information "Body we tried to ship: $body"
}

}
13 changes: 13 additions & 0 deletions Modules/CippExtensions/Public/PwPush/Get-PwPushAccount.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function Get-PwPushAccount {
$Table = Get-CIPPTable -TableName Extensionsconfig
$Configuration = ((Get-CIPPAzDataTableEntity @Table).config | ConvertFrom-Json).PWPush
if ($Configuration.Enabled -eq $true -and $Configuration.PWPushPro -eq $true) {
Set-PwPushConfig -Configuration $Configuration
Get-PushAccount
} else {
return @(@{
name = 'PWPush Pro is not enabled or configured. Make sure to save the configuration first.';
id = ''
})
}
}
1 change: 1 addition & 0 deletions Modules/CippExtensions/Public/PwPush/New-PwPushLink.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ function New-PwPushLink {
if ($Configuration.ExpireAfterDays) { $PushParams.ExpireAfterDays = $Configuration.ExpireAfterDays }
if ($Configuration.ExpireAfterViews) { $PushParams.ExpireAfterViews = $Configuration.ExpireAfterViews }
if ($Configuration.DeletableByViewer) { $PushParams.DeletableByViewer = $Configuration.DeletableByViewer }
if ($Configuration.AccountId) { $PushParams.AccountId = $Configuration.AccountId.value }
try {
if ($PSCmdlet.ShouldProcess('Create a new PwPush link')) {
$Link = New-Push @PushParams
Expand Down
13 changes: 12 additions & 1 deletion Modules/CippExtensions/Public/PwPush/Set-PwPushConfig.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,26 @@ function Set-PwPushConfig {
if ($Configuration.BaseUrl) {
$InitParams.BaseUrl = $Configuration.BaseUrl
}
if (![string]::IsNullOrEmpty($Configuration.EmailAddress)) {
if (![string]::IsNullOrEmpty($Configuration.EmailAddress) -or $Configuration.PWPushPro -eq $true) {
$ApiKey = Get-ExtensionAPIKey -Extension 'PWPush'

if (![string]::IsNullOrEmpty($ApiKey)) {
$InitParams.APIKey = $ApiKey
}
if (![string]::IsNullOrEmpty($Configuration.EmailAddress)) {
$InitParams.EmailAddress = $Configuration.EmailAddress
}
if ($Configuration.PWPushPro -eq $true) {
$InitParams.AccountType = 'Pro'
$InitParams.Remove('BaseUrl')
}
}
Write-Information ($InitParams | ConvertTo-Json)

$Module = Get-Module PassPushPosh -ListAvailable
Write-Host $Module.Version
if ($PSCmdlet.ShouldProcess('Initialize-PassPushPosh')) {
Initialize-PassPushPosh @InitParams
}
}

Loading

0 comments on commit 40fae4b

Please sign in to comment.