-
-
Notifications
You must be signed in to change notification settings - Fork 5
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 #27 from johnduprey/dev
Initial Policy v2 API support
- Loading branch information
Showing
3 changed files
with
121 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
function Get-Sha512HexDigest { | ||
Param($String) | ||
|
||
if ([string]::IsNullOrEmpty($String)) { $String = '' } | ||
$StringBuilder = New-Object System.Text.StringBuilder | ||
[System.Security.Cryptography.HashAlgorithm]::Create('SHA512').ComputeHash([System.Text.Encoding]::UTF8.GetBytes($String)) | ForEach-Object { | ||
[Void]$StringBuilder.Append($_.ToString('x2')) | ||
} | ||
$StringBuilder.ToString() | ||
} |
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,55 @@ | ||
function Get-DuoPolicies { | ||
<# | ||
.SYNOPSIS | ||
Retrieve Policies | ||
.DESCRIPTION | ||
Retrieve a complete set of all policies. Includes all policy section data for each policy. Requires "Grant read resource" API permission. | ||
.PARAMETER PolicyKey | ||
The key for the Policy | ||
.EXAMPLE | ||
Get-DuoPolicies | ||
.LINK | ||
https://duo.com/docs/adminapi#retrieve-policies | ||
.LINK | ||
https://duo.com/docs/adminapi#retrieve-policy-by-id | ||
#> | ||
[CmdletBinding()] | ||
Param( | ||
[Parameter(ValueFromPipelineByPropertyName = $true)] | ||
[Alias('policy_key')] | ||
[string]$PolicyKey | ||
) | ||
|
||
process { | ||
if ($PolicyKey) { | ||
$Path = '/admin/v2/policies/{0}' -f $PolicyKey | ||
} else { | ||
$Path = '/admin/v2/policies' | ||
} | ||
|
||
$DuoRequest = @{ | ||
Method = 'GET' | ||
Path = $Path | ||
SignatureVersion = 5 | ||
} | ||
|
||
if ($EndpointKey) { | ||
$Request = Invoke-DuoRequest @DuoRequest | ||
if ($Request.stat -ne 'OK') { | ||
$Request | ||
} else { | ||
$Request.response | ||
} | ||
} else { | ||
Invoke-DuoPaginatedRequest -DuoRequest $DuoRequest | ||
} | ||
} | ||
} | ||
|
||
Set-Alias -Name Get-DuoEndpoint -Value Get-DuoEndpoints |