Skip to content

Commit

Permalink
Merge pull request #30 from johnduprey/dev
Browse files Browse the repository at this point in the history
Dev to Main
  • Loading branch information
JohnDuprey committed Jan 8, 2024
2 parents 4dd9c38 + 3299b28 commit 989c788
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
test.ps1
Output
Output
Tests
4 changes: 4 additions & 0 deletions DuoSecurity/Private/REST Handler/Invoke-DuoRequest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ function Invoke-DuoRequest {
$Body = $Request
Write-Verbose $Request
}
if ($Method -eq 'PUT') {
$Headers.'Content-Type' = 'application/json'
Write-Verbose $Body
}

if ($NoAuth) {
$Headers = @{}
Expand Down
7 changes: 6 additions & 1 deletion DuoSecurity/Public/Accounts API/New-DuoAccount.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ function New-DuoAccount {
}

if ($PSCmdlet.ShouldProcess($Name)) {
Invoke-DuoRequest @DuoRequest
$Response = Invoke-DuoRequest @DuoRequest
if ($Response.stat -eq 'OK') {
$Response.response
} else {
$Response
}
}
}
3 changes: 2 additions & 1 deletion DuoSecurity/Public/Accounts API/Select-DuoAccount.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ function Select-DuoAccount {
#>
[CmdletBinding()]
Param(
[Parameter(Mandatory = $true, ParameterSetName = 'AccountId')]
[Parameter(ValueFromPipelineByPropertyName = $true, Mandatory = $true, ParameterSetName = 'AccountId')]
[Alias('account_id')]
[string]$AccountId,

[Parameter(Mandatory = $true, ParameterSetName = 'AccountName')]
Expand Down
2 changes: 1 addition & 1 deletion DuoSecurity/Public/Accounts API/Set-DuoAccountEdition.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function Set-DuoAccountEdition {
Select-DuoAccount -AccountId $AccountId -Quiet

$DuoRequest = @{
Method = 'GET'
Method = 'POST'
Path = '/admin/v1/billing/edition'
Params = @{ edition = $Edition }
}
Expand Down
4 changes: 2 additions & 2 deletions DuoSecurity/Public/Admin API/Policies/Get-DuoPolicies.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function Get-DuoPolicies {
SignatureVersion = 5
}

if ($EndpointKey) {
if ($PolicyKey) {
$Request = Invoke-DuoRequest @DuoRequest
if ($Request.stat -ne 'OK') {
$Request
Expand All @@ -52,4 +52,4 @@ function Get-DuoPolicies {
}
}

Set-Alias -Name Get-DuoEndpoint -Value Get-DuoEndpoints
Set-Alias -Name Get-DuoPolicy -Value Get-DuoPolicies
67 changes: 67 additions & 0 deletions DuoSecurity/Public/Admin API/Policies/Update-DuoPolicies.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
function Update-DuoPolicies {
<#
.SYNOPSIS
Update policy
.DESCRIPTION
Update policy section data for all policies or a set of specified policy_key values. Requires "Grant write resource" API permission.
.PARAMETER policies_to_update
The list of policies to update.
Key/Value
edit_all_policies
Is true if the changes should be applied to all policies (default). Otherwise false.
edit_list
An array of policy keys to apply the changes to. Ignored if edit_all_policies is true.
.PARAMETER policy_changes
The list of changes to apply to the policies specified in policies_to_update.
Key/Value
sections
The list of policy sections to be updated, with associated keys/values for each section. See Policy Section Data for all sections and their keys/values.
sections_to_delete
An array of section names to remove from the specified policies. Note that sections cannot be removed from the global policy.
.EXAMPLE
Update-DuoPolicies -policy_changes @{sections = @{authentication_methods = @{blocked_auth_list = @('webauthn-roaming', 'webauthn-platform')}};sections_to_delete = @()}
.LINK
https://duo.com/docs/adminapi#update-policies
.NOTES
General notes
#>
[CmdletBinding(SupportsShouldProcess)]
Param(
[Parameter()]
[hashtable]$policies_to_update = @{edit_all_policies = $true },

[Parameter(mandatory = $true)]
[hashtable]$policy_changes
)

$Params = @{}
if ($policies_to_update) { $Params.policies_to_update = $policies_to_update }
if ($policy_changes) { $Params.policy_changes = $policy_changes }

$DuoRequest = @{
Method = 'PUT'
Path = '/admin/v2/policies/update'
SignatureVersion = 5
Body = $Params | ConvertTo-Json -Depth 10 -Compress
}
if ($PSCmdlet.ShouldProcess($policies_to_update)) {
$Request = Invoke-DuoRequest @DuoRequest
if ($Request.stat -ne 'OK') {
$Request
} else {
$Request.response
}
}
}

Set-Alias -Name Update-DuoPolicy -Value Update-DuoPolicies

0 comments on commit 989c788

Please sign in to comment.