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.
|
||||
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 {
|
||||
<#
|
||||
.NOTES
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
RootModule = 'VMware.vSphere.SsoAdmin.psm1'
|
||||
|
||||
# Version number of this module.
|
||||
ModuleVersion = '1.2.3'
|
||||
ModuleVersion = '1.3.0'
|
||||
|
||||
# ID used to uniquely identify this module
|
||||
GUID = 'b3e25326-e809-4d68-a252-ca5fcaf1eb8b'
|
||||
@@ -34,7 +34,14 @@ RequiredModules = @(
|
||||
)
|
||||
|
||||
# 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
|
||||
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());
|
||||
|
||||
// Act
|
||||
var actual = ssoAdminClient.GetPersonUsersInGroup("", new Group {
|
||||
var actual = ssoAdminClient.GetPersonUsersInGroup("", new Group(ssoAdminClient) {
|
||||
Name = "Administrators",
|
||||
Domain = "vsphere.local"
|
||||
}).ToArray();
|
||||
|
||||
@@ -9,13 +9,26 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace VMware.vSphere.SsoAdminClient.DataTypes
|
||||
{
|
||||
public class Group
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Domain { get; set; }
|
||||
public class Group
|
||||
{
|
||||
SsoAdminClient _client;
|
||||
public Group(SsoAdminClient client)
|
||||
{
|
||||
_client = client;
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
return $"{Name}@{Domain}";
|
||||
}
|
||||
}
|
||||
public string Name { get; set; }
|
||||
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 `
|
||||
-Password $Password `
|
||||
-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"
|
||||
Import-Module $modulePath
|
||||
|
||||
Describe "Get-SsoGroup Tests" {
|
||||
BeforeEach {
|
||||
Connect-SsoAdminServer `
|
||||
-Server $VcAddress `
|
||||
-User $User `
|
||||
-Password $Password `
|
||||
-SkipCertificateCheck
|
||||
}
|
||||
Describe "SsoGroup Tests" {
|
||||
BeforeEach {
|
||||
Connect-SsoAdminServer `
|
||||
-Server $VcAddress `
|
||||
-User $User `
|
||||
-Password $Password `
|
||||
-SkipCertificateCheck
|
||||
|
||||
AfterEach {
|
||||
$connectionsToCleanup = $global:DefaultSsoAdminServers.ToArray()
|
||||
foreach ($connection in $connectionsToCleanup) {
|
||||
Disconnect-SsoAdminServer -Server $connection
|
||||
}
|
||||
}
|
||||
$script:testGroupsToDelete = @()
|
||||
}
|
||||
|
||||
Context "Get-SsoGroup" {
|
||||
It 'Gets groups without filters' {
|
||||
# Act
|
||||
$actual = Get-SsoGroup
|
||||
AfterEach {
|
||||
|
||||
# Assert
|
||||
$actual | Should -Not -Be $null
|
||||
$actual.Count | Should -BeGreaterThan 0
|
||||
$actual[0].Name | Should -Not -Be $null
|
||||
$actual[0].Domain | Should -Be 'localos'
|
||||
}
|
||||
foreach ($group in $script:testGroupsToDelete) {
|
||||
Remove-SsoGroup -Group $group
|
||||
}
|
||||
|
||||
It 'Gets groups for default domain' {
|
||||
# Arrange
|
||||
$newUserName = "NewUser1"
|
||||
$password = '$tr0NG_TestPa$$w0rd'
|
||||
$connectionsToCleanup = $global:DefaultSsoAdminServers.ToArray()
|
||||
foreach ($connection in $connectionsToCleanup) {
|
||||
Disconnect-SsoAdminServer -Server $connection
|
||||
}
|
||||
}
|
||||
|
||||
## Create Person User to determine default domain name
|
||||
## Person Users are created in the default domain
|
||||
$newPersonUser = New-SsoPersonUser `
|
||||
-UserName $newUserName `
|
||||
-Password $password
|
||||
Context "Get-SsoGroup" {
|
||||
It 'Gets groups without filters' {
|
||||
# Act
|
||||
$actual = Get-SsoGroup
|
||||
|
||||
# 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 'localos'
|
||||
}
|
||||
|
||||
# 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
|
||||
It 'Gets groups for default domain' {
|
||||
# Arrange
|
||||
$newUserName = "NewUser1"
|
||||
$password = '$tr0NG_TestPa$$w0rd'
|
||||
|
||||
# Cleanup
|
||||
Remove-SsoPersonUser -User $newPersonUser
|
||||
}
|
||||
}
|
||||
## Create Person User to determine default domain name
|
||||
## 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