github.com/vmware/govmomi@v0.37.1/lookup/simulator/registration_info.go (about)

     1  /*
     2  Copyright (c) 2018-2023 VMware, Inc. All Rights Reserved.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8  http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package simulator
    18  
    19  import (
    20  	"github.com/google/uuid"
    21  
    22  	"github.com/vmware/govmomi/lookup"
    23  	"github.com/vmware/govmomi/lookup/types"
    24  	"github.com/vmware/govmomi/simulator"
    25  	"github.com/vmware/govmomi/vim25"
    26  )
    27  
    28  var (
    29  	siteID = "vcsim"
    30  )
    31  
    32  // registrationInfo returns a ServiceRegistration populated with vcsim's OptionManager settings.
    33  // The complete list can be captured using: govc sso.service.ls -dump
    34  func registrationInfo() []types.LookupServiceRegistrationInfo {
    35  	vc := simulator.Map.Get(vim25.ServiceInstance).(*simulator.ServiceInstance)
    36  	setting := simulator.Map.OptionManager().Setting
    37  	sm := simulator.Map.SessionManager()
    38  	opts := make(map[string]string, len(setting))
    39  
    40  	for _, o := range setting {
    41  		opt := o.GetOptionValue()
    42  		if val, ok := opt.Value.(string); ok {
    43  			opts[opt.Key] = val
    44  		}
    45  	}
    46  
    47  	trust := []string{""}
    48  	if sm.TLSCert != nil {
    49  		trust[0] = sm.TLSCert()
    50  	}
    51  	sdk := opts["vcsim.server.url"] + vim25.Path
    52  	admin := opts["config.vpxd.sso.default.admin"]
    53  	owner := opts["config.vpxd.sso.solutionUser.name"]
    54  	instance := opts["VirtualCenter.InstanceName"]
    55  
    56  	// Real PSC has 30+ services by default, we just provide a few that are useful for vmomi interaction..
    57  	info := []types.LookupServiceRegistrationInfo{
    58  		{
    59  			LookupServiceRegistrationCommonServiceInfo: types.LookupServiceRegistrationCommonServiceInfo{
    60  				LookupServiceRegistrationMutableServiceInfo: types.LookupServiceRegistrationMutableServiceInfo{
    61  					ServiceVersion: lookup.Version,
    62  					ServiceEndpoints: []types.LookupServiceRegistrationEndpoint{
    63  						{
    64  							Url: opts["config.vpxd.sso.sts.uri"],
    65  							EndpointType: types.LookupServiceRegistrationEndpointType{
    66  								Protocol: "wsTrust",
    67  								Type:     "com.vmware.cis.cs.identity.sso",
    68  							},
    69  							SslTrust: trust,
    70  						},
    71  					},
    72  				},
    73  				OwnerId: admin,
    74  				ServiceType: types.LookupServiceRegistrationServiceType{
    75  					Product: "com.vmware.cis",
    76  					Type:    "cs.identity",
    77  				},
    78  			},
    79  			ServiceId: siteID + ":" + uuid.New().String(),
    80  			SiteId:    siteID,
    81  		},
    82  		{
    83  			LookupServiceRegistrationCommonServiceInfo: types.LookupServiceRegistrationCommonServiceInfo{
    84  				LookupServiceRegistrationMutableServiceInfo: types.LookupServiceRegistrationMutableServiceInfo{
    85  					ServiceVersion: lookup.Version,
    86  					ServiceEndpoints: []types.LookupServiceRegistrationEndpoint{
    87  						{
    88  							Url: opts["config.vpxd.sso.admin.uri"],
    89  							EndpointType: types.LookupServiceRegistrationEndpointType{
    90  								Protocol: "vmomi",
    91  								Type:     "com.vmware.cis.cs.identity.admin",
    92  							},
    93  							SslTrust: trust,
    94  						},
    95  					},
    96  				},
    97  				OwnerId: admin,
    98  				ServiceType: types.LookupServiceRegistrationServiceType{
    99  					Product: "com.vmware.cis",
   100  					Type:    "cs.identity",
   101  				},
   102  			},
   103  			ServiceId: siteID + ":" + uuid.New().String(),
   104  			SiteId:    siteID,
   105  		},
   106  		{
   107  			LookupServiceRegistrationCommonServiceInfo: types.LookupServiceRegistrationCommonServiceInfo{
   108  				LookupServiceRegistrationMutableServiceInfo: types.LookupServiceRegistrationMutableServiceInfo{
   109  					ServiceVersion: vim25.Version,
   110  					ServiceEndpoints: []types.LookupServiceRegistrationEndpoint{
   111  						{
   112  							Url: sdk,
   113  							EndpointType: types.LookupServiceRegistrationEndpointType{
   114  								Protocol: "vmomi",
   115  								Type:     "com.vmware.vim",
   116  							},
   117  							SslTrust: trust,
   118  							EndpointAttributes: []types.LookupServiceRegistrationAttribute{
   119  								{
   120  									Key:   "cis.common.ep.localurl",
   121  									Value: sdk,
   122  								},
   123  							},
   124  						},
   125  					},
   126  					ServiceAttributes: []types.LookupServiceRegistrationAttribute{
   127  						{
   128  							Key:   "com.vmware.cis.cm.GroupInternalId",
   129  							Value: "com.vmware.vim.vcenter",
   130  						},
   131  						{
   132  							Key:   "com.vmware.vim.vcenter.instanceName",
   133  							Value: instance,
   134  						},
   135  						{
   136  							Key:   "com.vmware.cis.cm.ControlScript",
   137  							Value: "service-control-default-vmon",
   138  						},
   139  						{
   140  							Key:   "com.vmware.cis.cm.HostId",
   141  							Value: uuid.New().String(),
   142  						},
   143  					},
   144  					ServiceNameResourceKey:        "AboutInfo.vpx.name",
   145  					ServiceDescriptionResourceKey: "AboutInfo.vpx.name",
   146  				},
   147  				OwnerId: owner,
   148  				ServiceType: types.LookupServiceRegistrationServiceType{
   149  					Product: "com.vmware.cis",
   150  					Type:    "vcenterserver",
   151  				},
   152  				NodeId: uuid.New().String(),
   153  			},
   154  			ServiceId: vc.Content.About.InstanceUuid,
   155  			SiteId:    siteID,
   156  		},
   157  	}
   158  
   159  	sts := info[0]
   160  	sts.ServiceType.Type = "sso:sts" // obsolete service type, but still used by PowerCLI
   161  
   162  	return append(info, sts)
   163  }