Skip to content
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

Add enforcement (Policy and Profile) #82

Merged
merged 4 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
236 changes: 236 additions & 0 deletions PowerArubaCP/Public/Enforcement.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,236 @@
#
# Copyright 2020, Alexis La Goutte <alexis.lagoutte at gmail dot com>
#
# SPDX-License-Identifier: Apache-2.0
#


function Get-ArubaCPEnforcementPolicy {

<#
.SYNOPSIS
Get Enforcement Policy on CPPM

.DESCRIPTION
Get Enforcement Policy (Id, name, description, (enforcement_)type, rules ...)

.EXAMPLE
Get-ArubaCPEnforcementPolicy

Get ALL Enforcement Policies on the Clearpass

.EXAMPLE
Get-ArubaCPEnforcementPolicy -id 23

Get info about Enforcement Policy id 23 on the ClearPass

.EXAMPLE
Get-ArubaCPEnforcementPolicy Aruba -filter_type contains

Get info about Enforcement Policy where bae contains Aruba

.EXAMPLE
Get-ArubaCPEnforcementPolicy -filter_attribute description -filter_type equal -filter_value MAC

Get info about Enforcement Policies where description equal MAC

#>

[CmdLetBinding(DefaultParameterSetName = "Default")]

Param(
[Parameter (Mandatory = $false)]
[switch]$details,
[Parameter (Mandatory = $false)]
[Parameter (ParameterSetName = "id")]
[int]$id,
[Parameter (Mandatory = $false, Position = 1)]
[Parameter (ParameterSetName = "name")]
[string]$name,
[Parameter (Mandatory = $false)]
[Parameter (ParameterSetName = "filter")]
[string]$filter_attribute,
[Parameter (Mandatory = $false)]
[Parameter (ParameterSetName = "id")]
[Parameter (ParameterSetName = "name")]
[Parameter (ParameterSetName = "filter")]
[ValidateSet('equal', 'contains')]
[string]$filter_type,
[Parameter (Mandatory = $false)]
[Parameter (ParameterSetName = "filter")]
[psobject]$filter_value,
[Parameter (Mandatory = $false)]
[int]$limit,
[Parameter (Mandatory = $False)]
[ValidateNotNullOrEmpty()]
[PSObject]$connection = $DefaultArubaCPConnection
)

Begin {
}

Process {

if ($connection.version -lt [version]"6.11.0") {
throw "Need ClearPass >= 6.11.0 for use this cmdlet"
}

$invokeParams = @{ }

if ( $PsBoundParameters.ContainsKey('limit') ) {
$invokeParams.add( 'limit', $limit )
}

switch ( $PSCmdlet.ParameterSetName ) {
"id" {
$filter_value = $id
$filter_attribute = "id"
}
"name" {
$filter_value = $name
$filter_attribute = "name"
}
default { }
}

if ( $PsBoundParameters.ContainsKey('filter_type') ) {
switch ( $filter_type ) {
"equal" {
$filter_value = @{ "`$eq" = $filter_value }
}
"contains" {
$filter_value = @{ "`$contains" = $filter_value }
}
default { }
}
}

if ($filter_value -and $filter_attribute) {
$filter = @{ $filter_attribute = $filter_value }
$invokeParams.add( 'filter', $filter )
}

$uri = "api/enforcement-policy"

$epl = Invoke-ArubaCPRestMethod -method "GET" -uri $uri @invokeParams -connection $connection
$epl._embedded.items
}

End {
}
}

function Get-ArubaCPEnforcementProfile {

<#
.SYNOPSIS
Get Enforcement Profile on CPPM

.DESCRIPTION
Get Enforcement Profile (Id, name, description, type, attributes ...)

.EXAMPLE
Get-ArubaCPEnforcementProfile

Get ALL Enforcement Profiles on the Clearpass

.EXAMPLE
Get-ArubaCPEnforcementProfile -id 23

Get info about Enforcement Profile id 23 on the ClearPass

.EXAMPLE
Get-ArubaCPEnforcementProfile Aruba -filter_type contains

Get info about Enforcement Profile where bae contains Aruba

.EXAMPLE
Get-ArubaCPEnforcementProfile -filter_attribute description -filter_type equal -filter_value MAC

Get info about Enforcement Profiles where description equal MAC

#>

[CmdLetBinding(DefaultParameterSetName = "Default")]

Param(
[Parameter (Mandatory = $false)]
[switch]$details,
[Parameter (Mandatory = $false)]
[Parameter (ParameterSetName = "id")]
[int]$id,
[Parameter (Mandatory = $false, Position = 1)]
[Parameter (ParameterSetName = "name")]
[string]$name,
[Parameter (Mandatory = $false)]
[Parameter (ParameterSetName = "filter")]
[string]$filter_attribute,
[Parameter (Mandatory = $false)]
[Parameter (ParameterSetName = "id")]
[Parameter (ParameterSetName = "name")]
[Parameter (ParameterSetName = "filter")]
[ValidateSet('equal', 'contains')]
[string]$filter_type,
[Parameter (Mandatory = $false)]
[Parameter (ParameterSetName = "filter")]
[psobject]$filter_value,
[Parameter (Mandatory = $false)]
[int]$limit,
[Parameter (Mandatory = $False)]
[ValidateNotNullOrEmpty()]
[PSObject]$connection = $DefaultArubaCPConnection
)

Begin {
}

Process {

if ($connection.version -lt [version]"6.11.0") {
throw "Need ClearPass >= 6.11.0 for use this cmdlet"
}

$invokeParams = @{ }

if ( $PsBoundParameters.ContainsKey('limit') ) {
$invokeParams.add( 'limit', $limit )
}

switch ( $PSCmdlet.ParameterSetName ) {
"id" {
$filter_value = $id
$filter_attribute = "id"
}
"name" {
$filter_value = $name
$filter_attribute = "name"
}
default { }
}

if ( $PsBoundParameters.ContainsKey('filter_type') ) {
switch ( $filter_type ) {
"equal" {
$filter_value = @{ "`$eq" = $filter_value }
}
"contains" {
$filter_value = @{ "`$contains" = $filter_value }
}
default { }
}
}

if ($filter_value -and $filter_attribute) {
$filter = @{ $filter_attribute = $filter_value }
$invokeParams.add( 'filter', $filter )
}

$uri = "api/enforcement-profile"

$epf = Invoke-ArubaCPRestMethod -method "GET" -uri $uri @invokeParams -connection $connection
$epf._embedded.items
}

End {
}
}
1 change: 1 addition & 0 deletions Tests/common.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ $script:VersionBefore680 = $DefaultArubaCPConnection.Version -lt [version]"6.8.0
$script:VersionBefore686 = $DefaultArubaCPConnection.Version -lt [version]"6.8.6"
$script:VersionBefore690 = $DefaultArubaCPConnection.Version -lt [version]"6.9.0"
$script:VersionBefore6100 = $DefaultArubaCPConnection.Version -lt [version]"6.10.0"
$script:VersionBefore6110 = $DefaultArubaCPConnection.Version -lt [version]"6.11.0"

$script:server_uuid = (Get-ArubaCPServerConfiguration).server_uuid[0]

Expand Down
6 changes: 6 additions & 0 deletions Tests/integration/Connection.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ Describe "Connect to a ClearPass (using multi connection)" {
It "Use Multi connection for call Get Service Certificate" {
{ Get-ArubaCPServiceCertificate -connection $cppm } | Should -Not -Throw
}
It "Use Multi connection for call Get Enforcement Policy" -Skip:$VersionBefore6110 {
{ Get-ArubaCPEnforcementPolicy -connection $cppm } | Should -Not -Throw
}
It "Use Multi connection for call Get Enforcement Profile" -Skip:$VersionBefore6110 {
{ Get-ArubaCPEnforcementProfile -connection $cppm } | Should -Not -Throw
}
}

It "Disconnect to a ClearPass (Multi connection)" {
Expand Down