Skip to content

Commit

Permalink
Merge pull request #6 from bepsoccer/dev
Browse files Browse the repository at this point in the history
0.0.5
  • Loading branch information
bepsoccer authored Feb 23, 2023
2 parents dd1bcd0 + a4b34da commit e2eb167
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Private/Invoke-VerkadaFormCall.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function Invoke-VerkadaFormCall

$uri = $url

$response = Invoke-RestMethod -Uri $uri -Form $form_params -Headers $headers -Method $method -ContentType 'multipart/form-data' -MaximumRetryCount 3 -TimeoutSec 30 -RetryIntervalSec 5
$response = Invoke-RestMethod -Uri $uri -Form $form_params -Headers $headers -Method $method -ContentType 'multipart/form-data' -MaximumRetryCount 3 -TimeoutSec 120 -RetryIntervalSec 5
return $response

} #end process
Expand Down
2 changes: 1 addition & 1 deletion Private/Invoke-VerkadaGraphqlCall.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function Invoke-VerkadaGraphqlCall

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
$response = Invoke-RestMethod -Uri $uri -Body $bodyJson -ContentType 'application/json' -WebSession $session -Method $method -MaximumRetryCount 3 -TimeoutSec 120 -RetryIntervalSec 5
$records += $response.data.($propertyName).($propertyName)
$body.variables.pagination.pageToken = $response.data.($propertyName).nextPageToken
} While ($body.variables.pagination.pageToken)
Expand Down
4 changes: 2 additions & 2 deletions Private/Invoke-VerkadaRestMethod.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function Invoke-VerkadaRestMethod
$uri = $uri.Uri.OriginalString
$records = @()
Do {
$response = Invoke-RestMethod -Uri $uri -Body $body -Headers $headers -ContentType 'application/json' -MaximumRetryCount 3 -TimeoutSec 30 -RetryIntervalSec 5
$response = Invoke-RestMethod -Uri $uri -Body $body -Headers $headers -ContentType 'application/json' -MaximumRetryCount 3 -TimeoutSec 120 -RetryIntervalSec 5
$records += $response.($propertyName)
$body.page_token = $response.next_page_token
} While ($body.page_token)
Expand All @@ -97,7 +97,7 @@ function Invoke-VerkadaRestMethod
$uri = $uri.Uri.OriginalString
}

$response = Invoke-RestMethod -Uri $uri -Body $body -Headers $headers -Method $method -ContentType 'application/json' -MaximumRetryCount 3 -TimeoutSec 30 -RetryIntervalSec 5
$response = Invoke-RestMethod -Uri $uri -Body $body -Headers $headers -Method $method -ContentType 'application/json' -MaximumRetryCount 3 -TimeoutSec 120 -RetryIntervalSec 5
return $response
}

Expand Down
19 changes: 18 additions & 1 deletion Public/Add-VerkadaAccessUser.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ function Add-VerkadaAccessUser
[String]$cardNumberHex,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[String]$facilityCode,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[String[]]$groupId,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[String[]]$groupName,
[Parameter()]
[Switch]$includeBadge,
[Parameter()]
Expand Down Expand Up @@ -78,7 +82,7 @@ function Add-VerkadaAccessUser

if ($threads){
do {
$job = (Get-Job -State Running | measure).Count
$job = (Get-Job -State Running | Measure-Object).Count
} until ($job -le $threads)

Start-Job -Name $email -InitializationScript {Import-Module verkadaModule.psm1} -ScriptBlock {
Expand All @@ -102,6 +106,12 @@ function Add-VerkadaAccessUser
$res.accessCards = $output2.accessCards
}

if ($using:groupId){
$response | Add-VerkadaAccessUserToGroup -groupId $using:groupId -org_id $using:org_id -x_verkada_token $using:x_verkada_token -x_verkada_auth $using:x_verkada_auth | Out-Null
} elseif ($using:groupName) {
<# Action when this condition is true #>
}

$response = $res | ConvertTo-Json -Depth 100 | ConvertFrom-Json
$response
} | Out-Null
Expand All @@ -126,6 +136,13 @@ function Add-VerkadaAccessUser
$output2 = invoke-expression $eval
$res.accessCards = $output2.accessCards
}

if ($groupId){
$response | Add-VerkadaAccessUserToGroup -groupId $groupId
} elseif ($groupName) {
<# Action when this condition is true #>
}

$response = $res | ConvertTo-Json -Depth 100 | ConvertFrom-Json
$response

Expand Down
61 changes: 61 additions & 0 deletions Public/Add-VerkadaAccessUserToGroup.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
function Add-VerkadaAccessUserToGroup
{
<#
.SYNOPSIS
Adds an Access User to an Access Group 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, ParameterSetName = 'groupId')]
[String[]]$groupId,
[Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, ParameterSetName = 'groupName')]
[String[]]$groupName,
[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_groups/bulk_add_users"
} #end begin

Process {
$body_params = @{
"userIds" = $userId
"organizationId" = $org_id
"groupIds" = $groupId
}

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
9 changes: 5 additions & 4 deletions verkadaModule.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'verkadaModule.psm1'

# Version number of this module.
ModuleVersion = '0.0.4'
ModuleVersion = '0.0.5'

# Supported PSEditions
CompatiblePSEditions = 'Desktop', 'Core'
Expand Down Expand Up @@ -70,9 +70,10 @@ PowerShellVersion = '6.1'

# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
FunctionsToExport = 'Add-VerkadaAccessBadgeToUser', 'Add-VerkadaAccessUser',
'Connect-Verkada', 'Disconnect-Verkada', 'Get-VerkadaAccessUser',
'Get-VerkadaCameras', 'Get-VerkadaCloudBackupSettings',
'Read-VerkadaCommandUsers', 'Set-VerkadaCloudBackupSettings'
'Add-VerkadaAccessUserToGroup', 'Connect-Verkada',
'Disconnect-Verkada', 'Get-VerkadaAccessUser', 'Get-VerkadaCameras',
'Get-VerkadaCloudBackupSettings', 'Read-VerkadaCommandUsers',
'Set-VerkadaCloudBackupSettings'

# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
CmdletsToExport = @()
Expand Down

0 comments on commit e2eb167

Please sign in to comment.