Skip to content

Commit

Permalink
Merge pull request #226 from pspete/issue-217
Browse files Browse the repository at this point in the history
ADD Enable-PASCPMAutoManagement
  • Loading branch information
pspete committed Dec 6, 2019
2 parents 36ee9d2 + 74f8dd4 commit dc7cfa1
Show file tree
Hide file tree
Showing 3 changed files with 156 additions and 1 deletion.
85 changes: 85 additions & 0 deletions Tests/Enable-PASCPMAutoManagement.Tests.ps1
@@ -0,0 +1,85 @@
#Get Current Directory
$Here = Split-Path -Parent $MyInvocation.MyCommand.Path

#Get Function Name
$FunctionName = (Split-Path -Leaf $MyInvocation.MyCommand.Path) -Replace ".Tests.ps1"

#Assume ModuleName from Repository Root folder
$ModuleName = Split-Path (Split-Path $Here -Parent) -Leaf

#Resolve Path to Module Directory
$ModulePath = Resolve-Path "$Here\..\$ModuleName"

#Define Path to Module Manifest
$ManifestPath = Join-Path "$ModulePath" "$ModuleName.psd1"

if ( -not (Get-Module -Name $ModuleName -All)) {

Import-Module -Name "$ManifestPath" -ArgumentList $true -Force -ErrorAction Stop

}

BeforeAll {

$Script:RequestBody = $null
$Script:BaseURI = "https://SomeURL/SomeApp"
$Script:ExternalVersion = "0.0"
$Script:WebSession = New-Object Microsoft.PowerShell.Commands.WebRequestSession

}

AfterAll {

$Script:RequestBody = $null

}

Describe $FunctionName {

InModuleScope $ModuleName {

Context "Mandatory Parameters" {

$Parameters = @{Parameter = 'AccountID' }

It "specifies parameter <Parameter> as mandatory" -TestCases $Parameters {

param($Parameter)

(Get-Command Enable-PASCPMAutoManagement).Parameters["$Parameter"].Attributes.Mandatory | Should Be $true

}

}

Context "Input" {

BeforeEach {

Mock Invoke-PASRestMethod -MockWith { }

$InputObj = [pscustomobject]@{
"AccountID" = "12_3"

}

}

It "sends request" {
$InputObj | Enable-PASCPMAutoManagement
Assert-MockCalled Invoke-PASRestMethod -Times 1 -Exactly -Scope It

}

It "throws error if version requirement not met" {
$Script:ExternalVersion = "1.2"

{ $InputObj | Enable-PASCPMAutoManagement } | Should throw
$Script:ExternalVersion = "0.0"
}

}

}

}
69 changes: 69 additions & 0 deletions psPAS/Functions/Accounts/Enable-PASCPMAutoManagement.ps1
@@ -0,0 +1,69 @@
function Enable-PASCPMAutoManagement {
<#
.SYNOPSIS
Enables an account for Automatic CPM Management.
.DESCRIPTION
Enables an account for CPm management by setting automaticManagementEnabled to $true,
and clearing any value set for manualManagementReason.
Attempting to set automaticManagementEnabled to $true without clearing manualManagementReason
at the same time results in an error.
This function requests the API to perform both operations with a single command.
.PARAMETER AccountID
The ID of the account whose activities will be retrieved.
.EXAMPLE
Enable-PASCPMAutoManagement -AccountID 543_2
Sets automaticManagementEnabled to $true & clears any value set for manualManagementReason
on account with ID 543_2
.NOTES
Applicable to and requires 10.4+
#>
[CmdletBinding()]
param(
[parameter(
Mandatory = $true,
ValueFromPipelinebyPropertyName = $true
)]
[Alias("id")]
[string]$AccountID


)

BEGIN {

$MinimumVersion = [System.Version]"10.4"

$ops = @(
@{
"path" = "/secretManagement/automaticManagementEnabled"
"op" = "replace"
"value" = $true
},
@{
"path" = "/secretManagement/manualManagementReason"
"op" = "replace"
"value" = ""
}
)

}#begin

PROCESS {

Assert-VersionRequirement -ExternalVersion $Script:ExternalVersion -RequiredVersion $MinimumVersion

Set-PASAccount -AccountID $AccountID -operations $ops

}#process

END { }#end

}
3 changes: 2 additions & 1 deletion psPAS/psPAS.psd1
Expand Up @@ -175,7 +175,8 @@
'Use-PASSession',
'Invoke-PASCPMOperation',
'Set-PASUserPassword',
'Set-PASDirectoryMappingOrder'
'Set-PASDirectoryMappingOrder',
'Enable-PASCPMAutoManagement'
)

# AliasesToExport = @( )
Expand Down

0 comments on commit dc7cfa1

Please sign in to comment.