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.
Merge pull request #34 from KelvinTegelaar/master
[pull] master from KelvinTegelaar:master
- Loading branch information
Showing
69 changed files
with
2,870 additions
and
403 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
function Clear-CippDurables { | ||
[CmdletBinding(SupportsShouldProcess = $true)] | ||
Param() | ||
# Collect info | ||
$StorageContext = New-AzStorageContext -ConnectionString $env:AzureWebJobsStorage | ||
$FunctionName = $env:WEBSITE_SITE_NAME | ||
|
||
# Get orchestrators | ||
$InstancesTable = Get-CippTable -TableName ('{0}Instances' -f $FunctionName) | ||
$HistoryTable = Get-CippTable -TableName ('{0}History' -f $FunctionName) | ||
$Yesterday = (Get-Date).AddDays(-1).ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ssZ') | ||
$Filter = "CreatedTime ge datetime'$Yesterday' or RuntimeStatus eq 'Pending' or RuntimeStatus eq 'Running'" | ||
$Instances = Get-CippAzDataTableEntity @InstancesTable -Filter $Filter | ||
|
||
$Queues = Get-AzStorageQueue -Context $StorageContext -Name ('{0}*' -f $FunctionName) | Select-Object -Property Name, ApproximateMessageCount, QueueClient | ||
|
||
$RunningQueues = $Queues | Where-Object { $_.ApproximateMessageCount -gt 0 } | ||
foreach ($Queue in $RunningQueues) { | ||
Write-Information "- Removing queue: $($Queue.Name), message count: $($Queue.ApproximateMessageCount)" | ||
if ($PSCmdlet.ShouldProcess($Queue.Name, 'Clear Queue')) { | ||
$Queue.QueueClient.ClearMessagesAsync() | ||
} | ||
} | ||
|
||
$QueueTable = Get-CippTable -TableName 'CippQueue' | ||
$CippQueue = Invoke-ListCippQueue | ||
$QueueEntities = foreach ($Queue in $CippQueue) { | ||
if ($Queue.Status -eq 'Running') { | ||
$Queue.TotalTasks = $Queue.CompletedTasks | ||
$Queue | Select-Object -Property PartitionKey, RowKey, TotalTasks | ||
} | ||
} | ||
if (($QueueEntities | Measure-Object).Count -gt 0) { | ||
if ($PSCmdlet.ShouldProcess('Queues', 'Mark Failed')) { | ||
Update-AzDataTableEntity @QueueTable -Entity $QueueEntities | ||
} | ||
} | ||
|
||
$CippQueueTasks = Get-CippTable -TableName 'CippQueueTasks' | ||
$RunningTasks = Get-CIPPAzDataTableEntity @CippQueueTasks -Filter "Status eq 'Running'" -Property RowKey, PartitionKey, Status | ||
if (($RunningTasks | Measure-Object).Count -gt 0) { | ||
if ($PSCmdlet.ShouldProcess('Tasks', 'Mark Failed')) { | ||
$UpdatedTasks = foreach ($Task in $RunningTasks) { | ||
$Task.Status = 'Failed' | ||
$Task | ||
} | ||
Update-AzDataTableEntity @CippQueueTasks -Entity $UpdatedTasks | ||
} | ||
} | ||
|
||
Remove-AzDataTable @InstancesTable | ||
Remove-AzDataTable @HistoryTable | ||
$BlobContainer = '{0}-largemessages' -f $Function.Name | ||
if (Get-AzStorageContainer -Name $BlobContainer -Context $StorageContext -ErrorAction SilentlyContinue) { | ||
Write-Information "- Removing blob container: $BlobContainer" | ||
if ($PSCmdlet.ShouldProcess($BlobContainer, 'Remove Blob Container')) { | ||
Remove-AzStorageContainer -Name $BlobContainer -Context $StorageContext -Confirm:$false -Force | ||
} | ||
} | ||
$null = Get-CippTable -TableName ('{0}History' -f $FunctionName) | ||
Write-Information 'Durable Orchestrators and Queues have been cleared' | ||
} |
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
21 changes: 21 additions & 0 deletions
21
Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Core/Invoke-ExecListBackup.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,21 @@ | ||
using namespace System.Net | ||
|
||
Function Invoke-ExecListBackup { | ||
<# | ||
.FUNCTIONALITY | ||
Entrypoint | ||
.ROLE | ||
CIPP.Backup.Read | ||
#> | ||
[CmdletBinding()] | ||
param($Request, $TriggerMetadata) | ||
|
||
$Result = Get-CIPPBackup -type $Request.body.Type -TenantFilter $Request.body.TenantFilter | ||
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API 'Alerts' -message $request.body.text -Sev $request.body.Severity | ||
# Associate values to output bindings by calling 'Push-OutputBinding'. | ||
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{ | ||
StatusCode = [HttpStatusCode]::OK | ||
Body = @($Result) | ||
}) | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
...les/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Core/Invoke-ExecSetCIPPAutoBackup.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,43 @@ | ||
using namespace System.Net | ||
|
||
Function Invoke-ExecSetCIPPAutoBackup { | ||
<# | ||
.FUNCTIONALITY | ||
Entrypoint | ||
.ROLE | ||
CIPP.Backup.Read | ||
#> | ||
[CmdletBinding()] | ||
param($Request, $TriggerMetadata) | ||
$unixtime = [int64](([datetime]::UtcNow) - (Get-Date '1/1/1970')).TotalSeconds | ||
if ($Request.query.Enabled -eq 'True') { | ||
$Table = Get-CIPPTable -TableName 'ScheduledTasks' | ||
$AutomatedCIPPBackupTask = Get-AzDataTableEntity @table -Filter "Name eq 'Automated CIPP Backup'" | ||
$task = @{ | ||
RowKey = $AutomatedCIPPBackupTask.RowKey | ||
PartitionKey = 'ScheduledTask' | ||
} | ||
Remove-AzDataTableEntity @Table -Entity $task | Out-Null | ||
|
||
$TaskBody = @{ | ||
TenantFilter = 'AllTenants' | ||
Name = 'Automated CIPP Backup' | ||
Command = @{ | ||
value = 'New-CIPPBackup' | ||
label = 'New-CIPPBackup' | ||
} | ||
Parameters = @{ backupType = 'CIPP' } | ||
ScheduledTime = $unixtime | ||
Recurrence = '1d' | ||
} | ||
Add-CIPPScheduledTask -Task $TaskBody -hidden $false | ||
$Result = @{ 'Results' = 'Scheduled Task Successfully created' } | ||
} | ||
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API 'Alerts' -message $request.body.text -Sev $request.body.Severity | ||
# Associate values to output bindings by calling 'Push-OutputBinding'. | ||
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{ | ||
StatusCode = [HttpStatusCode]::OK | ||
Body = $Result | ||
}) | ||
|
||
} |
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
Oops, something went wrong.