-
Notifications
You must be signed in to change notification settings - Fork 4
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 #5 from bepsoccer/accessApiWork
Start of Access user functions
- Loading branch information
Showing
12 changed files
with
576 additions
and
16 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,53 @@ | ||
function Invoke-VerkadaFormCall | ||
{ | ||
<# | ||
.SYNOPSIS | ||
Used to build an Invoke-RestMethod call for Verkada's AC API | ||
.DESCRIPTION | ||
.NOTES | ||
.EXAMPLE | ||
.LINK | ||
#> | ||
|
||
[CmdletBinding(PositionalBinding = $true)] | ||
Param( | ||
[Parameter(Mandatory = $true, Position = 0)] | ||
[String]$url, | ||
[Parameter(Mandatory = $true, Position = 1)] | ||
[String]$org_id, | ||
[Parameter(Mandatory = $true,Position = 3)] | ||
[Object]$form_params, | ||
[Parameter()] | ||
[String]$method = 'POST', | ||
[Parameter()] | ||
[string]$x_verkada_token = $Global:verkadaConnection.csrfToken, | ||
[Parameter()] | ||
[string]$x_verkada_auth = $Global:verkadaConnection.userToken | ||
|
||
) | ||
|
||
Begin { | ||
#if (!($Global:verkadaConnection)){Write-Warning 'Missing auth token which is required'; return} | ||
#if ($Global:verkadaConnection.authType -ne 'UnPwd'){Write-Warning 'Un/Pwd auth is required'; return} | ||
} | ||
|
||
Process { | ||
#$form = @{} | ||
#$form_params.psobject.properties | Foreach { $form[$_.Name] = $_.Value } | ||
|
||
$headers=@{ | ||
'x-verkada-token' = $x_verkada_token | ||
'X-Verkada-Auth' = $x_verkada_auth | ||
} | ||
|
||
$uri = $url | ||
|
||
$response = Invoke-RestMethod -Uri $uri -Form $form_params -Headers $headers -Method $method -ContentType 'multipart/form-data' -MaximumRetryCount 3 -TimeoutSec 30 -RetryIntervalSec 5 | ||
return $response | ||
|
||
} #end process | ||
} #end function |
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,71 @@ | ||
function Invoke-VerkadaGraphqlCall | ||
{ | ||
<# | ||
.SYNOPSIS | ||
Used to build an Invoke-RestMethod call for Verkada's Graphql enpoint | ||
.DESCRIPTION | ||
.NOTES | ||
.EXAMPLE | ||
.LINK | ||
#> | ||
|
||
[CmdletBinding(PositionalBinding = $true)] | ||
Param( | ||
[Parameter(Mandatory = $true, Position = 0)] | ||
[String]$url, | ||
[Parameter(Mandatory = $true, Position = 1, ParameterSetName = 'body')] | ||
[Object]$body, | ||
[Parameter()] | ||
[String]$method = 'GET', | ||
[Parameter()] | ||
[int]$page_size = 100, | ||
[Parameter(Mandatory = $true)] | ||
[String]$propertyName, | ||
[Parameter(Mandatory = $true, Position = 1, ParameterSetName = 'query')] | ||
[object]$query, | ||
[Parameter(Mandatory = $true, Position = 2, ParameterSetName = 'query')] | ||
[object]$qlVariables | ||
|
||
) | ||
|
||
Process { | ||
if (!($Global:verkadaConnection)){Write-Warning 'Missing auth token which is required'; return} | ||
if ($Global:verkadaConnection.authType -ne 'UnPwd'){Write-Warning 'Un/Pwd auth is required'; return} | ||
|
||
if ($query) { | ||
$body = @{ | ||
'query' = $query | ||
'variables' = $variables | ||
} | ||
} | ||
|
||
$body.variables.pagination.pageSize = $page_size | ||
$body.variables.pagination.pageToken = $null | ||
|
||
$cookies = @{ | ||
'auth' = $Global:verkadaConnection.userToken | ||
'org' = $Global:verkadaConnection.org_id | ||
'token' = $Global:verkadaConnection.csrfToken | ||
'usr' = $Global:verkadaConnection.usr = $response.userId | ||
} | ||
|
||
$session = New-WebSession $cookies $url | ||
|
||
$uri = $url | ||
$records = @() | ||
|
||
Do { | ||
$bodyJson = $body | ConvertTo-Json -depth 100 -Compress | ||
$response = Invoke-RestMethod -Uri $uri -Body $bodyJson -ContentType 'application/json' -WebSession $session -Method $method -MaximumRetryCount 3 -TimeoutSec 30 -RetryIntervalSec 5 | ||
$records += $response.data.($propertyName).($propertyName) | ||
$body.variables.pagination.pageToken = $response.data.($propertyName).nextPageToken | ||
} While ($body.variables.pagination.pageToken) | ||
|
||
return $records | ||
|
||
} #end process | ||
} #end function |
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,20 @@ | ||
function New-WebSession { | ||
param( | ||
[hashtable]$Cookies, | ||
[Uri]$For | ||
) | ||
|
||
$newSession = [Microsoft.PowerShell.Commands.WebRequestSession]::new() | ||
|
||
foreach($entry in $Cookies.GetEnumerator()){ | ||
$cookie = [System.Net.Cookie]::new($entry.Name, $entry.Value) | ||
if($For){ | ||
$newSession.Cookies.Add([uri]::new($For, '/'), $cookie) | ||
} | ||
else{ | ||
$newSession.Cookies.Add($cookie) | ||
} | ||
} | ||
|
||
return $newSession | ||
} |
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,69 @@ | ||
function Add-VerkadaAccessBadgeToUser | ||
{ | ||
<# | ||
.SYNOPSIS | ||
Adds a badger to an Access User in an organization | ||
.DESCRIPTION | ||
.NOTES | ||
.EXAMPLE | ||
.LINK | ||
#> | ||
|
||
[CmdletBinding(PositionalBinding = $true, DefaultParameterSetName = 'email')] | ||
Param( | ||
[Parameter(ValueFromPipelineByPropertyName = $true)] | ||
[ValidateNotNullOrEmpty()] | ||
[String]$org_id = $Global:verkadaConnection.org_id, | ||
[Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)] | ||
[ValidateNotNullOrEmpty()] | ||
[String]$userId, | ||
[Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)] | ||
[String]$cardType, | ||
[Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, ParameterSetName = 'cardNumber')] | ||
[String]$cardNumber, | ||
[Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, ParameterSetName = 'cardNumberHex')] | ||
[String]$cardNumberHex, | ||
[Parameter(ValueFromPipelineByPropertyName = $true)] | ||
[String]$facilityCode, | ||
[Parameter()] | ||
[ValidateNotNullOrEmpty()] | ||
[string]$x_verkada_token = $Global:verkadaConnection.csrfToken, | ||
[Parameter()] | ||
[ValidateNotNullOrEmpty()] | ||
[string]$x_verkada_auth = $Global:verkadaConnection.userToken, | ||
[Parameter()] | ||
[int]$threads=$null | ||
|
||
) | ||
|
||
Begin { | ||
#if (!($org_id)){Write-Warning 'Missing org_id which is required'; return} | ||
#if (!($Global:verkadaConnection)){Write-Warning 'Missing auth token which is required'; return} | ||
#if ($Global:verkadaConnection.authType -ne 'UnPwd'){Write-Warning 'Un/Pwd auth is required'; return} | ||
|
||
$url = "https://vcerberus.command.verkada.com/user/access_card/add" | ||
} #end begin | ||
|
||
Process { | ||
$body_params = @{ | ||
"userId" = $userId | ||
"organizationId" = $org_id | ||
"cardType" = $cardType | ||
} | ||
$body_params.cardParams = @{} | ||
if (!([string]::IsNullOrEmpty($cardNumber))){$body_params.cardParams.cardNumber = $cardNumber} | ||
if (!([string]::IsNullOrEmpty($cardNumberHex))){$body_params.cardParams.cardNumberHex = $cardNumberHex} | ||
if (!([string]::IsNullOrEmpty($facilityCode))){$body_params.cardParams.facilityCode = $facilityCode} | ||
|
||
Invoke-VerkadaRestMethod $url $org_id $body_params -x_verkada_token $x_verkada_token -x_verkada_auth $x_verkada_auth -Method 'POST' -UnPwd | ||
|
||
} #end process | ||
|
||
End { | ||
|
||
} | ||
} #end function |
Oops, something went wrong.