Implement New and Remove SsoGroup cmdlets.
Signed-off-by: Dimitar Milov <dmilov@vmware.com>
This commit is contained in:
@@ -2,6 +2,152 @@
|
|||||||
Copyright 2020-2021 VMware, Inc.
|
Copyright 2020-2021 VMware, Inc.
|
||||||
SPDX-License-Identifier: BSD-2-Clause
|
SPDX-License-Identifier: BSD-2-Clause
|
||||||
#>
|
#>
|
||||||
|
|
||||||
|
function New-SsoGroup {
|
||||||
|
<#
|
||||||
|
.NOTES
|
||||||
|
===========================================================================
|
||||||
|
Created on: 5/25/2021
|
||||||
|
Created by: Dimitar Milov
|
||||||
|
Twitter: @dimitar_milov
|
||||||
|
Github: https://github.com/dmilov
|
||||||
|
===========================================================================
|
||||||
|
|
||||||
|
.SYNOPSIS
|
||||||
|
Creates Local Sso Group
|
||||||
|
|
||||||
|
.DESCRIPTION
|
||||||
|
Creates Local Sso Group
|
||||||
|
|
||||||
|
.PARAMETER Name
|
||||||
|
Specifies the name of the group.
|
||||||
|
|
||||||
|
.PARAMETER Description
|
||||||
|
Specifies optionaldescription of the group.
|
||||||
|
|
||||||
|
.PARAMETER Server
|
||||||
|
Specifies the vSphere Sso Admin Server on which you want to run the cmdlet.
|
||||||
|
If not specified the servers available in $global:DefaultSsoAdminServers variable will be used.
|
||||||
|
|
||||||
|
.EXAMPLE
|
||||||
|
New-SsoGroup -Name 'myGroup' -Description 'My Group Description'
|
||||||
|
|
||||||
|
Creates local groupwith user 'myGroup' and description 'My Group Description'
|
||||||
|
|
||||||
|
#>
|
||||||
|
|
||||||
|
[CmdletBinding()]
|
||||||
|
param(
|
||||||
|
[Parameter(
|
||||||
|
Mandatory = $true,
|
||||||
|
ValueFromPipeline = $false,
|
||||||
|
ValueFromPipelineByPropertyName = $false,
|
||||||
|
HelpMessage = 'Specifies the name of the group')]
|
||||||
|
[string]
|
||||||
|
$Name,
|
||||||
|
|
||||||
|
[Parameter(
|
||||||
|
Mandatory = $false,
|
||||||
|
ValueFromPipeline = $false,
|
||||||
|
ValueFromPipelineByPropertyName = $false,
|
||||||
|
HelpMessage = 'Specifies the description of the group')]
|
||||||
|
[string]
|
||||||
|
$Description,
|
||||||
|
|
||||||
|
[Parameter(
|
||||||
|
Mandatory = $false,
|
||||||
|
ValueFromPipeline = $false,
|
||||||
|
ValueFromPipelineByPropertyName = $false,
|
||||||
|
HelpMessage = 'Connected SsoAdminServer object')]
|
||||||
|
[ValidateNotNull()]
|
||||||
|
[VMware.vSphere.SsoAdminClient.DataTypes.SsoAdminServer]
|
||||||
|
$Server)
|
||||||
|
|
||||||
|
Process {
|
||||||
|
$serversToProcess = $global:DefaultSsoAdminServers.ToArray()
|
||||||
|
if ($Server -ne $null) {
|
||||||
|
$serversToProcess = $Server
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($connection in $serversToProcess) {
|
||||||
|
if (-not $connection.IsConnected) {
|
||||||
|
Write-Error "Server $connection is disconnected"
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
# Output is the result of 'CreateLocalGroup'
|
||||||
|
try {
|
||||||
|
$connection.Client.CreateLocalGroup(
|
||||||
|
$Name,
|
||||||
|
$Description
|
||||||
|
)
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Error (FormatError $_.Exception)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Set-SsoGroup {
|
||||||
|
}
|
||||||
|
|
||||||
|
function Remove-SsoGroup {
|
||||||
|
<#
|
||||||
|
.NOTES
|
||||||
|
===========================================================================
|
||||||
|
Created on: 5/25/2021
|
||||||
|
Created by: Dimitar Milov
|
||||||
|
Twitter: @dimitar_milov
|
||||||
|
Github: https://github.com/dmilov
|
||||||
|
===========================================================================
|
||||||
|
.DESCRIPTION
|
||||||
|
This function removes existing local group.
|
||||||
|
|
||||||
|
.PARAMETER Group
|
||||||
|
Specifies the Group instance to remove.
|
||||||
|
|
||||||
|
.EXAMPLE
|
||||||
|
$ssoAdminConnection = Connect-SsoAdminServer -Server my.vc.server -User ssoAdmin@vsphere.local -Password 'ssoAdminStrongPa$$w0rd'
|
||||||
|
$myNewGroup = New-SsoGroup -Server $ssoAdminConnection -Name 'myGroup'
|
||||||
|
Remove-SsoGroup -Group $myNewGroup
|
||||||
|
|
||||||
|
Remove plocal group with name 'myGroup'
|
||||||
|
#>
|
||||||
|
[CmdletBinding(ConfirmImpact = 'High')]
|
||||||
|
param(
|
||||||
|
[Parameter(
|
||||||
|
Mandatory = $true,
|
||||||
|
ValueFromPipeline = $true,
|
||||||
|
ValueFromPipelineByPropertyName = $false,
|
||||||
|
HelpMessage = 'Group instance you want to remove from specified servers')]
|
||||||
|
[VMware.vSphere.SsoAdminClient.DataTypes.Group]
|
||||||
|
$Group)
|
||||||
|
|
||||||
|
Process {
|
||||||
|
try {
|
||||||
|
foreach ($g in $Group) {
|
||||||
|
$ssoAdminClient = $g.GetClient()
|
||||||
|
if ((-not $ssoAdminClient)) {
|
||||||
|
Write-Error "Object '$g' is from disconnected server"
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
$ssoAdminClient.RemoveLocalGroup($g)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Error (FormatError $_.Exception)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Add-PrincipalToSsoGroup {
|
||||||
|
}
|
||||||
|
|
||||||
|
function Remove-PrincipalFromSsoGroup {
|
||||||
|
}
|
||||||
|
|
||||||
function Get-SsoGroup {
|
function Get-SsoGroup {
|
||||||
<#
|
<#
|
||||||
.NOTES
|
.NOTES
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
RootModule = 'VMware.vSphere.SsoAdmin.psm1'
|
RootModule = 'VMware.vSphere.SsoAdmin.psm1'
|
||||||
|
|
||||||
# Version number of this module.
|
# Version number of this module.
|
||||||
ModuleVersion = '1.2.3'
|
ModuleVersion = '1.3.0'
|
||||||
|
|
||||||
# ID used to uniquely identify this module
|
# ID used to uniquely identify this module
|
||||||
GUID = 'b3e25326-e809-4d68-a252-ca5fcaf1eb8b'
|
GUID = 'b3e25326-e809-4d68-a252-ca5fcaf1eb8b'
|
||||||
@@ -34,7 +34,14 @@ RequiredModules = @(
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Functions to export from this module
|
# Functions to export from this module
|
||||||
FunctionsToExport = @('Connect-SsoAdminServer', 'Disconnect-SsoAdminServer', 'New-SsoPersonUser', 'Get-SsoPersonUser', 'Set-SsoPersonUser', 'Remove-SsoPersonUser', 'Get-SsoGroup', 'Get-SsoPasswordPolicy', 'Set-SsoPasswordPolicy', 'Get-SsoLockoutPolicy', 'Set-SsoLockoutPolicy', 'Get-SsoTokenLifetime', 'Set-SsoTokenLifetime', 'Get-IdentitySource', 'Remove-IdentitySource', 'Add-ActiveDirectoryIdentitySource', 'Add-LDAPIdentitySource', 'Set-LDAPIdentitySource', 'Set-SsoSelfPersonUserPassword')
|
FunctionsToExport = @(
|
||||||
|
'Connect-SsoAdminServer', 'Disconnect-SsoAdminServer',
|
||||||
|
'New-SsoPersonUser', 'Get-SsoPersonUser', 'Set-SsoPersonUser', 'Remove-SsoPersonUser', 'Set-SsoSelfPersonUserPassword'
|
||||||
|
'New-SsoGroup', 'Get-SsoGroup', 'Set-SsoGroup', 'Remove-SsoGroup', 'Add-PrincipalToSsoGroup', 'Remove-PrincipalFromSsoGroup'
|
||||||
|
'Get-SsoPasswordPolicy', 'Set-SsoPasswordPolicy',
|
||||||
|
'Get-SsoLockoutPolicy', 'Set-SsoLockoutPolicy',
|
||||||
|
'Get-SsoTokenLifetime', 'Set-SsoTokenLifetime',
|
||||||
|
'Get-IdentitySource', 'Remove-IdentitySource', 'Add-ActiveDirectoryIdentitySource', 'Add-LDAPIdentitySource', 'Set-LDAPIdentitySource')
|
||||||
|
|
||||||
# Cmdlets to export from this module
|
# Cmdlets to export from this module
|
||||||
CmdletsToExport = @()
|
CmdletsToExport = @()
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -103,7 +103,7 @@ namespace VMware.vSphere.SsoAdminClient.Tests
|
|||||||
var ssoAdminClient = new SsoAdminClient(_vc, _user, _password, new AcceptAllX509CertificateValidator());
|
var ssoAdminClient = new SsoAdminClient(_vc, _user, _password, new AcceptAllX509CertificateValidator());
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var actual = ssoAdminClient.GetPersonUsersInGroup("", new Group {
|
var actual = ssoAdminClient.GetPersonUsersInGroup("", new Group(ssoAdminClient) {
|
||||||
Name = "Administrators",
|
Name = "Administrators",
|
||||||
Domain = "vsphere.local"
|
Domain = "vsphere.local"
|
||||||
}).ToArray();
|
}).ToArray();
|
||||||
|
|||||||
@@ -9,13 +9,26 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace VMware.vSphere.SsoAdminClient.DataTypes
|
namespace VMware.vSphere.SsoAdminClient.DataTypes
|
||||||
{
|
{
|
||||||
public class Group
|
public class Group
|
||||||
{
|
{
|
||||||
public string Name { get; set; }
|
SsoAdminClient _client;
|
||||||
public string Domain { get; set; }
|
public Group(SsoAdminClient client)
|
||||||
|
{
|
||||||
|
_client = client;
|
||||||
|
}
|
||||||
|
|
||||||
public override string ToString() {
|
public string Name { get; set; }
|
||||||
return $"{Name}@{Domain}";
|
public string Domain { get; set; }
|
||||||
}
|
public string Description { get; set; }
|
||||||
}
|
|
||||||
|
public SsoAdminClient GetClient()
|
||||||
|
{
|
||||||
|
return _client;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return $"{Name}@{Domain}";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -65,7 +65,7 @@ Describe "Connect-SsoAdminServer and Disconnect-SsoAdminServer Tests" {
|
|||||||
-User $User `
|
-User $User `
|
||||||
-Password $Password `
|
-Password $Password `
|
||||||
-ErrorAction Stop } | `
|
-ErrorAction Stop } | `
|
||||||
Should -Throw "The SSL connection could not be established, see inner exception."
|
Should -Throw "*The SSL connection could not be established, see inner exception.*"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,57 +20,111 @@ param(
|
|||||||
$modulePath = Join-Path (Split-Path $PSScriptRoot | Split-Path) "VMware.vSphere.SsoAdmin.psd1"
|
$modulePath = Join-Path (Split-Path $PSScriptRoot | Split-Path) "VMware.vSphere.SsoAdmin.psd1"
|
||||||
Import-Module $modulePath
|
Import-Module $modulePath
|
||||||
|
|
||||||
Describe "Get-SsoGroup Tests" {
|
Describe "SsoGroup Tests" {
|
||||||
BeforeEach {
|
BeforeEach {
|
||||||
Connect-SsoAdminServer `
|
Connect-SsoAdminServer `
|
||||||
-Server $VcAddress `
|
-Server $VcAddress `
|
||||||
-User $User `
|
-User $User `
|
||||||
-Password $Password `
|
-Password $Password `
|
||||||
-SkipCertificateCheck
|
-SkipCertificateCheck
|
||||||
}
|
|
||||||
|
|
||||||
AfterEach {
|
$script:testGroupsToDelete = @()
|
||||||
$connectionsToCleanup = $global:DefaultSsoAdminServers.ToArray()
|
}
|
||||||
foreach ($connection in $connectionsToCleanup) {
|
|
||||||
Disconnect-SsoAdminServer -Server $connection
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Context "Get-SsoGroup" {
|
AfterEach {
|
||||||
It 'Gets groups without filters' {
|
|
||||||
# Act
|
|
||||||
$actual = Get-SsoGroup
|
|
||||||
|
|
||||||
# Assert
|
foreach ($group in $script:testGroupsToDelete) {
|
||||||
$actual | Should -Not -Be $null
|
Remove-SsoGroup -Group $group
|
||||||
$actual.Count | Should -BeGreaterThan 0
|
}
|
||||||
$actual[0].Name | Should -Not -Be $null
|
|
||||||
$actual[0].Domain | Should -Be 'localos'
|
|
||||||
}
|
|
||||||
|
|
||||||
It 'Gets groups for default domain' {
|
$connectionsToCleanup = $global:DefaultSsoAdminServers.ToArray()
|
||||||
# Arrange
|
foreach ($connection in $connectionsToCleanup) {
|
||||||
$newUserName = "NewUser1"
|
Disconnect-SsoAdminServer -Server $connection
|
||||||
$password = '$tr0NG_TestPa$$w0rd'
|
}
|
||||||
|
}
|
||||||
|
|
||||||
## Create Person User to determine default domain name
|
Context "Get-SsoGroup" {
|
||||||
## Person Users are created in the default domain
|
It 'Gets groups without filters' {
|
||||||
$newPersonUser = New-SsoPersonUser `
|
# Act
|
||||||
-UserName $newUserName `
|
$actual = Get-SsoGroup
|
||||||
-Password $password
|
|
||||||
|
|
||||||
# Act
|
# Assert
|
||||||
$actual = Get-SsoGroup `
|
$actual | Should -Not -Be $null
|
||||||
-Domain $newPersonUser.Domain
|
$actual.Count | Should -BeGreaterThan 0
|
||||||
|
$actual[0].Name | Should -Not -Be $null
|
||||||
|
$actual[0].Domain | Should -Be 'localos'
|
||||||
|
}
|
||||||
|
|
||||||
# Assert
|
It 'Gets groups for default domain' {
|
||||||
$actual | Should -Not -Be $null
|
# Arrange
|
||||||
$actual.Count | Should -BeGreaterThan 0
|
$newUserName = "NewUser1"
|
||||||
$actual[0].Name | Should -Not -Be $null
|
$password = '$tr0NG_TestPa$$w0rd'
|
||||||
$actual[0].Domain | Should -Be $newPersonUser.Domain
|
|
||||||
|
|
||||||
# Cleanup
|
## Create Person User to determine default domain name
|
||||||
Remove-SsoPersonUser -User $newPersonUser
|
## Person Users are created in the default domain
|
||||||
}
|
$newPersonUser = New-SsoPersonUser `
|
||||||
}
|
-UserName $newUserName `
|
||||||
|
-Password $password
|
||||||
|
|
||||||
|
# Act
|
||||||
|
$actual = Get-SsoGroup `
|
||||||
|
-Domain $newPersonUser.Domain
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
$actual | Should -Not -Be $null
|
||||||
|
$actual.Count | Should -BeGreaterThan 0
|
||||||
|
$actual[0].Name | Should -Not -Be $null
|
||||||
|
$actual[0].Domain | Should -Be $newPersonUser.Domain
|
||||||
|
|
||||||
|
# Cleanup
|
||||||
|
Remove-SsoPersonUser -User $newPersonUser
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Context "New-SsoGroup" {
|
||||||
|
It 'Should create SsoGroup specifying only the name of the group' {
|
||||||
|
# Arrange
|
||||||
|
$expectedName = 'TestGroup1'
|
||||||
|
|
||||||
|
# Act
|
||||||
|
$actual = New-SsoGroup -Name $expectedName
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
$actual | Should -Not -Be $null
|
||||||
|
$script:testGroupsToDelete += $actual
|
||||||
|
$actual.Name | Should -Be $expectedName
|
||||||
|
$actual.Domain | Should -Be 'vsphere.local'
|
||||||
|
$actual.Description | Should -Be ([string]::Empty)
|
||||||
|
}
|
||||||
|
|
||||||
|
It 'Should create SsoGroup specifying name and description' {
|
||||||
|
# Arrange
|
||||||
|
$expectedName = 'TestGroup2'
|
||||||
|
$expectedDescription = 'Test Description 2'
|
||||||
|
|
||||||
|
# Act
|
||||||
|
$actual = New-SsoGroup -Name $expectedName -Description $expectedDescription
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
$actual | Should -Not -Be $
|
||||||
|
$script:testGroupsToDelete += $actual
|
||||||
|
$actual.Name | Should -Be $expectedName
|
||||||
|
$actual.Domain | Should -Be 'vsphere.local'
|
||||||
|
$actual.Description | Should -Be $expectedDescription
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Context "Remove-SsoGroup" {
|
||||||
|
It 'Should remove SsoGroup' {
|
||||||
|
# Arrange
|
||||||
|
$groupName = 'TestGroup3'
|
||||||
|
$groupToRemove = New-SsoGroup -Name $groupName
|
||||||
|
|
||||||
|
# Act
|
||||||
|
$groupToRemove | Remove-SsoGroup
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
Get-SsoGroup -Name $groupName -Domain 'vsphere.local' | Should -Be $null
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user