-
Notifications
You must be signed in to change notification settings - Fork 7
Add function to create and manage Guests #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,196 @@ | ||
| # | ||
| # Copyright 2018, Alexis La Goutte <alexis.lagoutte at gmail dot com> | ||
| # Copyright 2018, Cédric Moreau <moreaucedric0 at gmail dot com> | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
|
|
||
| function Get-ArubaCPGuest { | ||
|
|
||
| <# | ||
| .SYNOPSIS | ||
| Get Guest account on Aruba ClearPass | ||
|
|
||
| .DESCRIPTION | ||
alagoutte marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Get Guest account on Aruba ClearPass | ||
|
|
||
| .EXAMPLE | ||
| Get-ArubaCPGuest | ||
| Get all the guest accounts on Clearpass. | ||
| #> | ||
|
|
||
| Begin { | ||
| } | ||
|
|
||
| Process { | ||
|
|
||
| $run = Invoke-ArubaCPRestMethod -method "get" -uri "api/guest" | ||
|
|
||
| $guest = $run._embedded | ||
|
|
||
| $guest.items | ||
|
|
||
| } | ||
|
|
||
| End { | ||
| } | ||
| } | ||
|
|
||
| function Add-ArubaCPGuest { | ||
|
|
||
| <# | ||
| .SYNOPSIS | ||
| Add Guest account on Aruba ClearPass | ||
|
|
||
| .DESCRIPTION | ||
| Add Guest account on Aruba ClearPass | ||
| .EXAMPLE | ||
|
|
||
| Add-ArubaCPGuest -username -company -mail -role -enable | ||
| Add the guest account with parameters. | ||
| .EXAMPLE | ||
|
|
||
| Add-ArubaCPGuest -username matthew -company "Interstellar & Co" -mail [email protected] -role guest -enable True | ||
| Add the guest account matthew with company Interstellar & Co, e-mail [email protected] and role guest and enable it on Clearpass. | ||
| #> | ||
|
|
||
| Param( | ||
| [Parameter(Mandatory = $true)] | ||
| [String]$username, | ||
| [Parameter(Mandatory = $true)] | ||
| [String]$company, | ||
| [Parameter(Mandatory = $true)] | ||
| [String]$mail, | ||
| [Parameter(Mandatory = $true)] | ||
| [int]$role, | ||
| [Parameter(Mandatory = $false)] | ||
| [ValidateSet ("True", "False")] | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use switch type ? :)
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No yet fixed |
||
| [string]$enable | ||
| ) | ||
|
|
||
| Begin { | ||
| } | ||
|
|
||
| Process { | ||
|
|
||
| $guest = new-Object -TypeName PSObject | ||
|
|
||
| $guest | add-member -name "username" -membertype NoteProperty -Value $username | ||
|
|
||
| $guest | add-member -name "visitor_company" -membertype NoteProperty -Value $company | ||
|
|
||
| $guest | add-member -name "email" -membertype NoteProperty -Value $mail | ||
|
|
||
| if ( $PsBoundParameters.ContainsKey('role')) | ||
| { | ||
| $guest | add-member -name "role_id" -membertype NoteProperty -Value $role | ||
| } | ||
|
|
||
| if ( $PsBoundParameters.ContainsKey('enable')) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use switch type it will be more easy |
||
| { | ||
| switch( $enable ) { | ||
| True { | ||
| $enable = $true | ||
| } | ||
| False { | ||
| $enable = $false | ||
| } | ||
| } | ||
| $guest | add-member -name "enabled" -membertype NoteProperty -Value $enable | ||
| } | ||
|
|
||
| $run = Invoke-ArubaCPRestMethod -method "post" -body $guest -uri "api/guest" | ||
|
|
||
| $run | ||
|
|
||
| } | ||
|
|
||
| End { | ||
| } | ||
| } | ||
|
|
||
| function Set-ArubaCPGuest { | ||
|
|
||
| <# | ||
| .SYNOPSIS | ||
| Set information about a guest account. | ||
|
|
||
| .DESCRIPTION | ||
| Set information about a guest account based on his username on Aruba ClearPass. | ||
|
|
||
| .EXAMPLE | ||
| Set-ArubaCPGuest -username test [-company] [-mail] [-role (contractor/employee/guest) ] [-enable (true/false)] [-expire (hour/day/week/month/year)] | ||
| Set the information of the guest user. | ||
|
|
||
| .EXAMPLE | ||
| Set-ArubaCPGuest -username matthew -company "Company" -mail [email protected] -role guest -enable true -expire hour | ||
| Set the guest account matthew enable, with his company, his email, the role guest and with an expire time of an hour. | ||
| #> | ||
|
|
||
| Param( | ||
| [Parameter(Mandatory = $true)] | ||
| [String]$username, | ||
| [Parameter(Mandatory = $false)] | ||
| [String]$company, | ||
| [Parameter(Mandatory = $false)] | ||
| [String]$mail, | ||
| [Parameter(Mandatory = $false)] | ||
| [int]$role, | ||
| [Parameter(Mandatory = $false)] | ||
| [ValidateSet ("true", "false")] | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use switch.. |
||
| [string]$enable, | ||
| [Parameter(Mandatory = $false)] | ||
| [int]$expire | ||
| ) | ||
|
|
||
| Begin { | ||
| } | ||
|
|
||
| Process { | ||
|
|
||
| $guest = new-Object -TypeName PSObject | ||
|
|
||
| $guest | add-member -name "username" -membertype NoteProperty -Value $username | ||
|
|
||
| if ( $PsBoundParameters.ContainsKey('company')) | ||
| { | ||
| $guest | add-member -name "visitor_company" -membertype NoteProperty -Value $company | ||
| } | ||
|
|
||
| if ( $PsBoundParameters.ContainsKey('mail')) | ||
| { | ||
| $guest | add-member -name "email" -membertype NoteProperty -Value $mail | ||
| } | ||
|
|
||
| if ( $PsBoundParameters.ContainsKey('role')) | ||
| { | ||
| $guest | add-member -name "role_id" -membertype NoteProperty -Value $role | ||
| } | ||
|
|
||
| if ( $PsBoundParameters.ContainsKey('enable')) | ||
| { | ||
| switch( $enable ) { | ||
| true { | ||
| $enable = $true | ||
| } | ||
| false { | ||
| $enable = $false | ||
| } | ||
| } | ||
| $guest | add-member -name "enabled" -membertype NoteProperty -Value $enable | ||
| } | ||
|
|
||
| if ( $PsBoundParameters.ContainsKey('expire')) | ||
| { | ||
| $guest | add-member -name "expire_time" -membertype NoteProperty -Value $expire | ||
| } | ||
|
|
||
| $run = Invoke-ArubaCPRestMethod -method "patch" -body $guest -uri "api/username/${username}" | ||
|
|
||
| $run | ||
|
|
||
| } | ||
|
|
||
| End { | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.