Implement Get-Group advanced function
This commit is contained in:
@@ -79,5 +79,19 @@ namespace VMware.vSphere.SsoAdminClient.Tests
|
||||
Assert.AreEqual("root", actual[0].Name);
|
||||
Assert.AreEqual("localos", actual[0].Domain);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetRootLocalOsGroups() {
|
||||
// Arrange
|
||||
var ssoAdminClient = new SsoAdminClient(_vc, _user, _password, new AcceptAllX509CertificateValidator());
|
||||
|
||||
// Act
|
||||
var actual = ssoAdminClient.GetGroups("", "localos").ToArray();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(actual);
|
||||
Assert.Greater(actual.Length, 1);
|
||||
Assert.AreEqual("localos", actual[0].Domain);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
// **************************************************************************
|
||||
// Copyright (c) VMware, Inc. All rights reserved. -- VMware Confidential.
|
||||
// **************************************************************************
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VMware.vSphere.SsoAdminClient.DataTypes
|
||||
{
|
||||
public class Group
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Domain { get; set; }
|
||||
|
||||
public override string ToString() {
|
||||
return $"{Name}@{Domain}";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -234,6 +234,34 @@ namespace VMware.vSphere.SsoAdminClient
|
||||
principal.Name));
|
||||
}
|
||||
|
||||
public IEnumerable<DataTypes.Group> GetGroups(string searchString, string domain) {
|
||||
// Create Authorization Invocation Context
|
||||
var authorizedInvocationContext =
|
||||
CreateAuthorizedInvocationContext();
|
||||
|
||||
// Invoke SSO Admin FindGroupsAsync operation
|
||||
var ssoAdminGroups = authorizedInvocationContext.
|
||||
InvokeOperation(() =>
|
||||
_ssoAdminBindingClient.FindGroupsAsync(
|
||||
new ManagedObjectReference {
|
||||
type = "SsoAdminPrincipalDiscoveryService",
|
||||
Value = "principalDiscoveryService"
|
||||
},
|
||||
new SsoAdminPrincipalDiscoveryServiceSearchCriteria {
|
||||
searchString = searchString,
|
||||
domain = domain
|
||||
},
|
||||
int.MaxValue)).Result.returnval;
|
||||
|
||||
if (ssoAdminGroups != null) {
|
||||
foreach (var group in ssoAdminGroups) {
|
||||
yield return new DataTypes.Group {
|
||||
Name = group.id.name,
|
||||
Domain = group.id.domain
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user