go.mod: update github.com/vmware/govmomi to v0.48.0
Needs manual change of import paths.
This commit is contained in:
parent
3a6bea380e
commit
bec893e37c
170 changed files with 7474 additions and 1604 deletions
16
vendor/github.com/vmware/govmomi/session/cache/session.go
generated
vendored
16
vendor/github.com/vmware/govmomi/session/cache/session.go
generated
vendored
|
|
@ -1,11 +1,11 @@
|
|||
/*
|
||||
Copyright (c) 2020 VMware, Inc. All Rights Reserved.
|
||||
Copyright (c) 2020-2024 VMware, Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
|
|
@ -18,7 +18,7 @@ package cache
|
|||
|
||||
import (
|
||||
"context"
|
||||
"crypto/sha1"
|
||||
"crypto/sha256"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
|
|
@ -26,6 +26,7 @@ import (
|
|||
"os/user"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/vmware/govmomi/fault"
|
||||
"github.com/vmware/govmomi/session"
|
||||
"github.com/vmware/govmomi/vapi/rest"
|
||||
"github.com/vmware/govmomi/vim25"
|
||||
|
|
@ -104,7 +105,7 @@ func (s *Session) key(path string) string {
|
|||
// Key session file off of full URI and insecure setting.
|
||||
// Hash key to get a predictable, canonical format.
|
||||
key := fmt.Sprintf("%s#insecure=%t", p.String(), s.Insecure)
|
||||
return fmt.Sprintf("%040x", sha1.Sum([]byte(key)))
|
||||
return fmt.Sprintf("%064x", sha256.Sum256([]byte(key)))
|
||||
}
|
||||
|
||||
func (s *Session) file(p string) string {
|
||||
|
|
@ -227,12 +228,9 @@ func soapSessionValid(ctx context.Context, client *vim25.Client) (bool, error) {
|
|||
m := session.NewManager(client)
|
||||
u, err := m.UserSession(ctx)
|
||||
if err != nil {
|
||||
if soap.IsSoapFault(err) {
|
||||
fault := soap.ToSoapFault(err).VimFault()
|
||||
if fault.Is(err, &types.ManagedObjectNotFound{}) {
|
||||
// If the PropertyCollector is not found, the saved session for this URL is not valid
|
||||
if _, ok := fault.(types.ManagedObjectNotFound); ok {
|
||||
return false, nil
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
|
||||
return false, err
|
||||
|
|
|
|||
50
vendor/github.com/vmware/govmomi/session/manager.go
generated
vendored
50
vendor/github.com/vmware/govmomi/session/manager.go
generated
vendored
|
|
@ -1,11 +1,11 @@
|
|||
/*
|
||||
Copyright (c) 2015 VMware, Inc. All Rights Reserved.
|
||||
Copyright (c) 2015-2024 VMware, Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
|
|
@ -21,7 +21,9 @@ import (
|
|||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/vmware/govmomi/fault"
|
||||
"github.com/vmware/govmomi/property"
|
||||
"github.com/vmware/govmomi/vim25"
|
||||
"github.com/vmware/govmomi/vim25/methods"
|
||||
|
|
@ -59,6 +61,7 @@ func Secret(value string) (string, error) {
|
|||
type Manager struct {
|
||||
client *vim25.Client
|
||||
userSession *types.UserSession
|
||||
mu sync.Mutex
|
||||
}
|
||||
|
||||
func NewManager(client *vim25.Client) *Manager {
|
||||
|
|
@ -69,7 +72,7 @@ func NewManager(client *vim25.Client) *Manager {
|
|||
return &m
|
||||
}
|
||||
|
||||
func (sm Manager) Reference() types.ManagedObjectReference {
|
||||
func (sm *Manager) Reference() types.ManagedObjectReference {
|
||||
return *sm.client.ServiceContent.SessionManager
|
||||
}
|
||||
|
||||
|
|
@ -83,6 +86,21 @@ func (sm *Manager) SetLocale(ctx context.Context, locale string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
func (sm *Manager) setUserSession(val *types.UserSession) {
|
||||
sm.mu.Lock()
|
||||
sm.userSession = val
|
||||
sm.mu.Unlock()
|
||||
}
|
||||
|
||||
func (sm *Manager) getUserSession() (types.UserSession, bool) {
|
||||
sm.mu.Lock()
|
||||
defer sm.mu.Unlock()
|
||||
if sm.userSession == nil {
|
||||
return types.UserSession{}, false
|
||||
}
|
||||
return *sm.userSession, true
|
||||
}
|
||||
|
||||
func (sm *Manager) Login(ctx context.Context, u *url.Userinfo) error {
|
||||
req := types.Login{
|
||||
This: sm.Reference(),
|
||||
|
|
@ -101,7 +119,7 @@ func (sm *Manager) Login(ctx context.Context, u *url.Userinfo) error {
|
|||
return err
|
||||
}
|
||||
|
||||
sm.userSession = &login.Returnval
|
||||
sm.setUserSession(&login.Returnval)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -139,7 +157,7 @@ func (sm *Manager) LoginExtensionByCertificate(ctx context.Context, key string)
|
|||
// Copy the session cookie
|
||||
sm.client.Jar.SetCookies(u, c.Jar.Cookies(c.URL()))
|
||||
|
||||
sm.userSession = &login.Returnval
|
||||
sm.setUserSession(&login.Returnval)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -154,7 +172,7 @@ func (sm *Manager) LoginByToken(ctx context.Context) error {
|
|||
return err
|
||||
}
|
||||
|
||||
sm.userSession = &login.Returnval
|
||||
sm.setUserSession(&login.Returnval)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -168,7 +186,7 @@ func (sm *Manager) Logout(ctx context.Context) error {
|
|||
return err
|
||||
}
|
||||
|
||||
sm.userSession = nil
|
||||
sm.setUserSession(nil)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -181,11 +199,8 @@ func (sm *Manager) UserSession(ctx context.Context) (*types.UserSession, error)
|
|||
err := pc.RetrieveOne(ctx, sm.Reference(), []string{"currentSession"}, &mgr)
|
||||
if err != nil {
|
||||
// It's OK if we can't retrieve properties because we're not authenticated
|
||||
if f, ok := err.(types.HasFault); ok {
|
||||
switch f.Fault().(type) {
|
||||
case *types.NotAuthenticated:
|
||||
return nil, nil
|
||||
}
|
||||
if fault.Is(err, &types.NotAuthenticated{}) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return nil, err
|
||||
|
|
@ -207,14 +222,15 @@ func (sm *Manager) TerminateSession(ctx context.Context, sessionId []string) err
|
|||
// SessionIsActive checks whether the session that was created at login is
|
||||
// still valid. This function only works against vCenter.
|
||||
func (sm *Manager) SessionIsActive(ctx context.Context) (bool, error) {
|
||||
if sm.userSession == nil {
|
||||
userSession, ok := sm.getUserSession()
|
||||
if !ok {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
req := types.SessionIsActive{
|
||||
This: sm.Reference(),
|
||||
SessionID: sm.userSession.Key,
|
||||
UserName: sm.userSession.UserName,
|
||||
SessionID: userSession.Key,
|
||||
UserName: userSession.UserName,
|
||||
}
|
||||
|
||||
active, err := methods.SessionIsActive(ctx, sm.client, &req)
|
||||
|
|
@ -277,7 +293,7 @@ func (sm *Manager) CloneSession(ctx context.Context, ticket string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
sm.userSession = &res.Returnval
|
||||
sm.setUserSession(&res.Returnval)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -304,6 +320,6 @@ func (sm *Manager) ImpersonateUser(ctx context.Context, name string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
sm.userSession = &res.Returnval
|
||||
sm.setUserSession(&res.Returnval)
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue