Adds module code structure, build script, test script, and API bindings
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"ProviderId": "Microsoft.VisualStudio.ConnectedService.Wcf",
|
||||
"Version": "15.0.20628.921",
|
||||
"ExtendedData": {
|
||||
"Uri": "https://10.23.80.205/lookupservice/wsdl/lookup.wsdl",
|
||||
"Namespace": "LookupServiceReference",
|
||||
"SelectedAccessLevelForGeneratedClass": "Public",
|
||||
"GenerateMessageContract": false,
|
||||
"ReuseTypesinReferencedAssemblies": true,
|
||||
"ReuseTypesinAllReferencedAssemblies": true,
|
||||
"CollectionTypeReference": {
|
||||
"Item1": "System.Array",
|
||||
"Item2": "System.Runtime.dll"
|
||||
},
|
||||
"DictionaryCollectionTypeReference": {
|
||||
"Item1": "System.Collections.Generic.Dictionary`2",
|
||||
"Item2": "System.Collections.dll"
|
||||
},
|
||||
"CheckedReferencedAssemblies": [],
|
||||
"InstanceId": null,
|
||||
"Name": "LookupServiceReference",
|
||||
"Metadata": {}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,129 @@
|
||||
// **************************************************************************
|
||||
// Copyright 2019 VMware, Inc. All rights reserved. -- VMware Confidential.
|
||||
// **************************************************************************
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IdentityModel.Selectors;
|
||||
using System.Linq;
|
||||
using System.Security;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.ServiceModel;
|
||||
using System.ServiceModel.Channels;
|
||||
using System.ServiceModel.Security;
|
||||
using System.Text;
|
||||
using LookupServiceReference;
|
||||
|
||||
namespace VMware.vSphere.LsClient
|
||||
{
|
||||
public class LookupServiceClient {
|
||||
private const int WEB_OPERATION_TIMEOUT_SECONDS = 30;
|
||||
private LsPortTypeClient _lsClient;
|
||||
|
||||
private static readonly ManagedObjectReference RootMoRef = new ManagedObjectReference
|
||||
{
|
||||
type = "LookupServiceInstance",
|
||||
Value = "ServiceInstance"
|
||||
};
|
||||
|
||||
public LookupServiceClient(string hostname, X509CertificateValidator serverCertificateValidator) {
|
||||
var lsUri = $"https://{hostname}/lookupservice/sdk";
|
||||
|
||||
_lsClient = new LsPortTypeClient(GetBinding(), new EndpointAddress(new Uri(lsUri)));
|
||||
|
||||
var serverAuthentication = GetServerAuthentication(serverCertificateValidator);
|
||||
|
||||
if (serverAuthentication != null)
|
||||
{
|
||||
_lsClient
|
||||
.ChannelFactory
|
||||
.Credentials
|
||||
.ServiceCertificate
|
||||
.SslCertificateAuthentication = serverAuthentication;
|
||||
}
|
||||
}
|
||||
|
||||
#region Private Helpers
|
||||
private X509ServiceCertificateAuthentication GetServerAuthentication(X509CertificateValidator serverCertificateValidator)
|
||||
{
|
||||
if (serverCertificateValidator != null) {
|
||||
return new X509ServiceCertificateAuthentication {
|
||||
CertificateValidationMode = X509CertificateValidationMode.Custom,
|
||||
CustomCertificateValidator = serverCertificateValidator
|
||||
};
|
||||
}
|
||||
|
||||
// Default .NET behavior for TLS certificate validation
|
||||
return null;
|
||||
}
|
||||
|
||||
private static MessageEncodingBindingElement GetWcfEncoding()
|
||||
{
|
||||
return new TextMessageEncodingBindingElement(MessageVersion.Soap11, Encoding.UTF8);
|
||||
}
|
||||
|
||||
private static HttpsTransportBindingElement GetWcfTransport(bool useSystemProxy)
|
||||
{
|
||||
HttpsTransportBindingElement transport = new HttpsTransportBindingElement
|
||||
{
|
||||
RequireClientCertificate = false
|
||||
};
|
||||
|
||||
transport.UseDefaultWebProxy = useSystemProxy;
|
||||
transport.MaxBufferSize = 2147483647;
|
||||
transport.MaxReceivedMessageSize = 2147483647;
|
||||
|
||||
return transport;
|
||||
}
|
||||
|
||||
private static Binding GetBinding() {
|
||||
var binding = new CustomBinding(GetWcfEncoding(), GetWcfTransport(true));
|
||||
|
||||
var timeout = TimeSpan.FromSeconds(WEB_OPERATION_TIMEOUT_SECONDS);
|
||||
binding.CloseTimeout = timeout;
|
||||
binding.OpenTimeout = timeout;
|
||||
binding.ReceiveTimeout = timeout;
|
||||
binding.SendTimeout = timeout;
|
||||
|
||||
return binding;
|
||||
}
|
||||
#endregion
|
||||
|
||||
public Uri GetSsoAdminEndpointUri() {
|
||||
var product = "com.vmware.cis";
|
||||
var endpointType = "com.vmware.cis.cs.identity.admin";
|
||||
var type = "sso:admin";
|
||||
return FindServiceEndpoint(product, type, endpointType);
|
||||
}
|
||||
|
||||
private Uri FindServiceEndpoint(string product, string type, string endpointType) {
|
||||
Uri result = null;
|
||||
|
||||
var svcContent = _lsClient.RetrieveServiceContentAsync(RootMoRef).Result;
|
||||
var filterCriteria = new LookupServiceRegistrationFilter() {
|
||||
searchAllSsoDomains = true,
|
||||
serviceType = new LookupServiceRegistrationServiceType {
|
||||
product = product,
|
||||
type = type
|
||||
}
|
||||
};
|
||||
|
||||
var lsRegInfo = _lsClient.
|
||||
ListAsync(svcContent.serviceRegistration, filterCriteria)
|
||||
.Result?
|
||||
.returnval?
|
||||
.FirstOrDefault();
|
||||
if (lsRegInfo != null) {
|
||||
var registrationEndpooint = lsRegInfo.
|
||||
serviceEndpoints?.
|
||||
Where(a => a.endpointType.type == endpointType)?.
|
||||
FirstOrDefault<LookupServiceRegistrationEndpoint>();
|
||||
if (registrationEndpooint != null) {
|
||||
result = new Uri(registrationEndpooint.url);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<RootNamespace>VMware.vSphere.LsClient</RootNamespace>
|
||||
<AssemblyName>VMware.vSphere.LsClient</AssemblyName>
|
||||
<Description>vSphere Lookup Service API client.</Description>
|
||||
<TargetFrameworks>net45;netcoreapp2.0</TargetFrameworks>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup Condition="'$(TargetFramework)' == 'net45'">
|
||||
<Reference Include="System.IdentityModel" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="System.ServiceModel.Primitives" Version="4.4.0" />
|
||||
<PackageReference Include="System.ServiceModel.Duplex" Version="4.4.0" />
|
||||
<PackageReference Include="System.ServiceModel.Http" Version="4.4.0" />
|
||||
<PackageReference Include="System.ServiceModel.NetTcp" Version="4.4.0" />
|
||||
<PackageReference Include="System.ServiceModel.Security" Version="4.4.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<WCFMetadata Include="Connected Services" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user