session

package
v0.56.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 14 Imported by: 211 modules, 363 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var Locale = os.Getenv("GOVMOMI_LOCALE")

Locale defaults to "en_US" and can be overridden via this var or the GOVMOMI_LOCALE env var. A value of "_" uses the server locale setting.

Functions

func KeepAlive

func KeepAlive(roundTripper soap.RoundTripper, idleTime time.Duration) soap.RoundTripper

KeepAlive is a backward compatible wrapper around KeepAliveHandler.

func KeepAliveHandler added in v0.3.0

func KeepAliveHandler(roundTripper soap.RoundTripper, idleTime time.Duration, handler func(soap.RoundTripper) error) soap.RoundTripper

KeepAliveHandler is a backward compatible wrapper around keepalive.NewHandlerSOAP.

func Secret added in v0.21.0

func Secret(value string) (string, error)

Secret returns the contents if a file path value is given, otherwise returns value itself.

Types

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

func NewManager

func NewManager(client *vim25.Client) *Manager

func (*Manager) AcquireCloneTicket added in v0.16.0

func (sm *Manager) AcquireCloneTicket(ctx context.Context) (string, error)

func (*Manager) AcquireGenericServiceTicket added in v0.3.0

func (*Manager) AcquireLocalTicket added in v0.8.0

func (sm *Manager) AcquireLocalTicket(ctx context.Context, userName string) (*types.SessionManagerLocalTicket, error)

func (*Manager) CloneSession added in v0.16.0

func (sm *Manager) CloneSession(ctx context.Context, ticket string) error

func (*Manager) ImpersonateUser added in v0.40.0

func (sm *Manager) ImpersonateUser(ctx context.Context, name string) error

func (*Manager) Login

func (sm *Manager) Login(ctx context.Context, u *url.Userinfo) error

func (*Manager) LoginByToken added in v0.18.0

func (sm *Manager) LoginByToken(ctx context.Context) error
Example
package main

import (
	"context"
	"fmt"
	"net/url"

	_ "github.com/vmware/govmomi/lookup/simulator"
	"github.com/vmware/govmomi/session"
	"github.com/vmware/govmomi/simulator"
	"github.com/vmware/govmomi/sts"
	"github.com/vmware/govmomi/vim25"
	"github.com/vmware/govmomi/vim25/soap"

	_ "github.com/vmware/govmomi/sts/simulator"
)

func main() {
	simulator.Run(func(ctx context.Context, vc *vim25.Client) error {
		c, err := sts.NewClient(ctx, vc)
		if err != nil {
			return err
		}

		// Issue a bearer token
		req := sts.TokenRequest{
			Userinfo: url.UserPassword("Administrator@VSPHERE.LOCAL", "password"),
		}

		signer, err := c.Issue(ctx, req)
		if err != nil {
			return err
		}

		// Create a new un-authenticated client and LoginByToken
		vc2, err := vim25.NewClient(ctx, soap.NewClient(vc.URL(), true))
		if err != nil {
			return err
		}

		m := session.NewManager(vc2)
		header := soap.Header{Security: signer}

		err = m.LoginByToken(vc2.WithHeader(ctx, header))
		if err != nil {
			return err
		}

		session, err := m.UserSession(ctx)
		if err != nil {
			return err
		}

		fmt.Println(session.UserName)

		return nil
	})
}
Output:
Administrator@VSPHERE.LOCAL

func (*Manager) LoginExtensionByCertificate added in v0.3.0

func (sm *Manager) LoginExtensionByCertificate(ctx context.Context, key string) error

LoginExtensionByCertificate uses the vCenter SDK tunnel to login using a client certificate. The client certificate can be set using the soap.Client.SetCertificate method.

func (*Manager) Logout

func (sm *Manager) Logout(ctx context.Context) error

func (*Manager) Reference

func (sm *Manager) Reference() types.ManagedObjectReference

func (*Manager) SessionIsActive

func (sm *Manager) SessionIsActive(ctx context.Context) (bool, error)

SessionIsActive checks whether the session that was created at login is still valid. This function only works against vCenter.

func (*Manager) SetLocale added in v0.10.0

func (sm *Manager) SetLocale(ctx context.Context, locale string) error

func (*Manager) TerminateSession added in v0.3.0

func (sm *Manager) TerminateSession(ctx context.Context, sessionId []string) error

func (*Manager) UpdateServiceMessage added in v0.24.1

func (sm *Manager) UpdateServiceMessage(ctx context.Context, message string) error

func (*Manager) UserSession

func (sm *Manager) UserSession(ctx context.Context) (*types.UserSession, error)

UserSession retrieves and returns the SessionManager's CurrentSession field. Nil is returned if the session is not authenticated.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL