build(deps): bump the go-deps group with 6 updates

Bumps the go-deps group with 6 updates:

| Package | From | To |
| --- | --- | --- |
| [github.com/aws/aws-sdk-go](https://github.com/aws/aws-sdk-go) | `1.45.10` | `1.45.16` |
| [github.com/gophercloud/gophercloud](https://github.com/gophercloud/gophercloud) | `1.6.0` | `1.7.0` |
| [github.com/openshift-online/ocm-sdk-go](https://github.com/openshift-online/ocm-sdk-go) | `0.1.364` | `0.1.371` |
| [github.com/osbuild/images](https://github.com/osbuild/images) | `0.5.1-0.20230915095808-dd48a38be218` | `0.7.0` |
| [github.com/vmware/govmomi](https://github.com/vmware/govmomi) | `0.30.7` | `0.31.0` |
| [google.golang.org/api](https://github.com/googleapis/google-api-go-client) | `0.142.0` | `0.143.0` |


Updates `github.com/aws/aws-sdk-go` from 1.45.10 to 1.45.16
- [Release notes](https://github.com/aws/aws-sdk-go/releases)
- [Commits](https://github.com/aws/aws-sdk-go/compare/v1.45.10...v1.45.16)

Updates `github.com/gophercloud/gophercloud` from 1.6.0 to 1.7.0
- [Release notes](https://github.com/gophercloud/gophercloud/releases)
- [Changelog](https://github.com/gophercloud/gophercloud/blob/v1.7.0/CHANGELOG.md)
- [Commits](https://github.com/gophercloud/gophercloud/compare/v1.6.0...v1.7.0)

Updates `github.com/openshift-online/ocm-sdk-go` from 0.1.364 to 0.1.371
- [Release notes](https://github.com/openshift-online/ocm-sdk-go/releases)
- [Changelog](https://github.com/openshift-online/ocm-sdk-go/blob/main/CHANGES.md)
- [Commits](https://github.com/openshift-online/ocm-sdk-go/compare/v0.1.364...v0.1.371)

Updates `github.com/osbuild/images` from 0.5.1-0.20230915095808-dd48a38be218 to 0.7.0
- [Release notes](https://github.com/osbuild/images/releases)
- [Commits](https://github.com/osbuild/images/commits/v0.7.0)

Updates `github.com/vmware/govmomi` from 0.30.7 to 0.31.0
- [Release notes](https://github.com/vmware/govmomi/releases)
- [Changelog](https://github.com/vmware/govmomi/blob/main/CHANGELOG.md)
- [Commits](https://github.com/vmware/govmomi/compare/v0.30.7...v0.31.0)

Updates `google.golang.org/api` from 0.142.0 to 0.143.0
- [Release notes](https://github.com/googleapis/google-api-go-client/releases)
- [Changelog](https://github.com/googleapis/google-api-go-client/blob/main/CHANGES.md)
- [Commits](https://github.com/googleapis/google-api-go-client/compare/v0.142.0...v0.143.0)

---
updated-dependencies:
- dependency-name: github.com/aws/aws-sdk-go
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: go-deps
- dependency-name: github.com/gophercloud/gophercloud
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: go-deps
- dependency-name: github.com/openshift-online/ocm-sdk-go
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: go-deps
- dependency-name: github.com/osbuild/images
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: go-deps
- dependency-name: github.com/vmware/govmomi
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: go-deps
- dependency-name: google.golang.org/api
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: go-deps
...

Signed-off-by: dependabot[bot] <support@github.com>
This commit is contained in:
dependabot[bot] 2023-09-26 04:16:38 +00:00 committed by Sanne Raymaekers
parent 9d7159dab3
commit 41aacd8817
88 changed files with 65996 additions and 13187 deletions

View file

@ -1,11 +1,11 @@
/*
Copyright (c) 2014-2018 VMware, Inc. All Rights Reserved.
Copyright (c) 2014-2023 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,
@ -40,7 +40,6 @@ import (
"runtime"
"strings"
"sync"
"time"
"github.com/vmware/govmomi/internal/version"
"github.com/vmware/govmomi/vim25/progress"
@ -87,6 +86,8 @@ type Client struct {
cookie string
insecureCookies bool
useJSON bool
}
var schemeMatch = regexp.MustCompile(`^\w+://`)
@ -113,6 +114,7 @@ func ParseURL(s string) (*url.URL, error) {
s = "https://" + s
}
s := strings.TrimSuffix(s, "/")
u, err = url.Parse(s)
if err != nil {
return nil, err
@ -132,30 +134,22 @@ func ParseURL(s string) (*url.URL, error) {
}
func NewClient(u *url.URL, insecure bool) *Client {
c := Client{
u: u,
k: insecure,
d: newDebug(),
var t *http.Transport
Types: types.TypeFunc(),
}
// Initialize http.RoundTripper on client, so we can customize it below
if t, ok := http.DefaultTransport.(*http.Transport); ok {
c.t = &http.Transport{
Proxy: t.Proxy,
DialContext: t.DialContext,
MaxIdleConns: t.MaxIdleConns,
IdleConnTimeout: t.IdleConnTimeout,
TLSHandshakeTimeout: t.TLSHandshakeTimeout,
ExpectContinueTimeout: t.ExpectContinueTimeout,
}
if d, ok := http.DefaultTransport.(*http.Transport); ok {
t = d.Clone()
} else {
c.t = new(http.Transport)
t = new(http.Transport)
}
c.hosts = make(map[string]string)
c.t.TLSClientConfig = &tls.Config{InsecureSkipVerify: c.k}
if insecure {
if t.TLSClientConfig == nil {
t.TLSClientConfig = new(tls.Config)
}
t.TLSClientConfig.InsecureSkipVerify = insecure
}
c := newClientWithTransport(u, insecure, t)
// Always set DialTLS and DialTLSContext, even if InsecureSkipVerify=true,
// because of how certificate verification has been delegated to the host's
@ -163,7 +157,22 @@ func NewClient(u *url.URL, insecure bool) *Client {
//
// * https://tip.golang.org/doc/go1.18 (search for "Certificate.Verify")
// * https://github.com/square/certigo/issues/264
c.t.DialTLSContext = c.dialTLSContext
t.DialTLSContext = c.dialTLSContext
return c
}
func newClientWithTransport(u *url.URL, insecure bool, t *http.Transport) *Client {
c := Client{
u: u,
k: insecure,
d: newDebug(),
t: t,
Types: types.TypeFunc(),
}
c.hosts = make(map[string]string)
c.Client.Transport = c.t
c.Client.Jar, _ = cookiejar.New(nil)
@ -185,6 +194,10 @@ func (c *Client) DefaultTransport() *http.Transport {
// NewServiceClient creates a NewClient with the given URL.Path and namespace.
func (c *Client) NewServiceClient(path string, namespace string) *Client {
return c.newServiceClientWithTransport(path, namespace, c.t)
}
func (c *Client) newServiceClientWithTransport(path string, namespace string, t *http.Transport) *Client {
vc := c.URL()
u, err := url.Parse(path)
if err != nil {
@ -195,12 +208,8 @@ func (c *Client) NewServiceClient(path string, namespace string) *Client {
u.Host = vc.Host
}
client := NewClient(u, c.k)
client := newClientWithTransport(u, c.k, t)
client.Namespace = "urn:" + namespace
client.DefaultTransport().TLSClientConfig = c.DefaultTransport().TLSClientConfig
if cert := c.Certificate(); cert != nil {
client.SetCertificate(*cert)
}
// Copy the trusted thumbprints
c.hostsMu.Lock()
@ -239,6 +248,14 @@ func (c *Client) NewServiceClient(path string, namespace string) *Client {
return client
}
// UseJSON changes the protocol between SOAP and JSON. Starting with vCenter
// 8.0.1 JSON over HTTP can be used. Note this method has no locking and clients
// should be careful to not interfere with concurrent use of the client
// instance.
func (c *Client) UseJSON(useJSON bool) {
c.useJSON = useJSON
}
// SetRootCAs defines the set of PEM-encoded file locations of root certificate
// authorities the client uses when verifying server certificates instead of the
// TLS defaults which uses the host's root CA set. Multiple PEM file locations
@ -415,6 +432,7 @@ func splitHostPort(host string) (string, string) {
const sdkTunnel = "sdkTunnel:8089"
// Certificate returns the current TLS certificate.
func (c *Client) Certificate() *tls.Certificate {
certs := c.t.TLSClientConfig.Certificates
if len(certs) == 0 {
@ -423,6 +441,7 @@ func (c *Client) Certificate() *tls.Certificate {
return &certs[0]
}
// SetCertificate st a certificate for TLS use.
func (c *Client) SetCertificate(cert tls.Certificate) {
t := c.Client.Transport.(*http.Transport)
@ -434,7 +453,8 @@ func (c *Client) SetCertificate(cert tls.Certificate) {
// to the SDK tunnel virtual host. Use of the SDK tunnel is required by LoginExtensionByCertificate()
// and optional for other methods.
func (c *Client) Tunnel() *Client {
tunnel := c.NewServiceClient(c.u.Path, c.Namespace)
tunnel := c.newServiceClientWithTransport(c.u.Path, c.Namespace, c.DefaultTransport().Clone())
t := tunnel.Client.Transport.(*http.Transport)
// Proxy to vCenter host on port 80
host := tunnel.u.Hostname()
@ -460,6 +480,7 @@ func (c *Client) Tunnel() *Client {
return tunnel
}
// URL returns the URL to which the client is configured
func (c *Client) URL() *url.URL {
urlCopy := *c.u
return &urlCopy
@ -470,19 +491,23 @@ type marshaledClient struct {
URL *url.URL
Insecure bool
Version string
UseJSON bool
}
// MarshalJSON writes the Client configuration to JSON.
func (c *Client) MarshalJSON() ([]byte, error) {
m := marshaledClient{
Cookies: c.Jar.Cookies(c.u),
URL: c.u,
Insecure: c.k,
Version: c.Version,
UseJSON: c.useJSON,
}
return json.Marshal(m)
}
// UnmarshalJSON rads Client configuration from JSON.
func (c *Client) UnmarshalJSON(b []byte) error {
var m marshaledClient
@ -494,12 +519,11 @@ func (c *Client) UnmarshalJSON(b []byte) error {
*c = *NewClient(m.URL, m.Insecure)
c.Version = m.Version
c.Jar.SetCookies(m.URL, m.Cookies)
c.useJSON = m.UseJSON
return nil
}
type kindContext struct{}
func (c *Client) setInsecureCookies(res *http.Response) {
cookies := res.Cookies()
if len(cookies) != 0 {
@ -510,6 +534,9 @@ func (c *Client) setInsecureCookies(res *http.Response) {
}
}
// Do is equivalent to http.Client.Do and takes care of API specifics including
// logging, user-agent header, handling cookies, measuring responsiveness of the
// API
func (c *Client) Do(ctx context.Context, req *http.Request, f func(*http.Response) error) error {
if ctx == nil {
ctx = context.Background()
@ -532,20 +559,7 @@ func (c *Client) Do(ctx context.Context, req *http.Request, f func(*http.Respons
ext = d.debugRequest(req)
}
tstart := time.Now()
res, err := c.Client.Do(req.WithContext(ctx))
tstop := time.Now()
if d.enabled() {
var name string
if kind, ok := ctx.Value(kindContext{}).(HasFault); ok {
name = fmt.Sprintf("%T", kind)
} else {
name = fmt.Sprintf("%s %s", req.Method, req.URL)
}
d.logf("%6dms (%s)", tstop.Sub(tstart)/time.Millisecond, name)
}
if err != nil {
return err
}
@ -603,7 +617,15 @@ func newStatusError(res *http.Response) error {
}
}
// RoundTrip executes an API request to VMOMI server.
func (c *Client) RoundTrip(ctx context.Context, reqBody, resBody HasFault) error {
if !c.useJSON {
return c.soapRoundTrip(ctx, reqBody, resBody)
}
return c.jsonRoundTrip(ctx, reqBody, resBody)
}
func (c *Client) soapRoundTrip(ctx context.Context, reqBody, resBody HasFault) error {
var err error
var b []byte
@ -651,7 +673,7 @@ func (c *Client) RoundTrip(ctx context.Context, reqBody, resBody HasFault) error
}
req.Header.Set(`SOAPAction`, action)
return c.Do(context.WithValue(ctx, kindContext{}, resBody), req, func(res *http.Response) error {
return c.Do(ctx, req, func(res *http.Response) error {
switch res.StatusCode {
case http.StatusOK:
// OK

View file

@ -22,7 +22,6 @@ import (
"net/http"
"net/http/httputil"
"sync/atomic"
"time"
"github.com/vmware/govmomi/vim25/debug"
)
@ -37,17 +36,9 @@ var (
// debugRoundTrip contains state and logic needed to debug a single round trip.
type debugRoundTrip struct {
cn uint64 // Client number
rn uint64 // Request number
log io.WriteCloser // Request log
cs []io.Closer // Files that need closing when done
}
func (d *debugRoundTrip) logf(format string, a ...interface{}) {
now := time.Now().Format("2006-01-02T15-04-05.000000000")
fmt.Fprintf(d.log, "%s - %04d: ", now, d.rn)
fmt.Fprintf(d.log, format, a...)
fmt.Fprintf(d.log, "\n")
cn uint64 // Client number
rn uint64 // Request number
cs []io.Closer // Files that need closing when done
}
func (d *debugRoundTrip) enabled() bool {
@ -120,9 +111,8 @@ var cn uint64 // Client counter
// debugContainer wraps the debugging state for a single client.
type debugContainer struct {
cn uint64 // Client number
rn uint64 // Request counter
log io.WriteCloser // Request log
cn uint64 // Client number
rn uint64 // Request counter
}
func newDebug() *debugContainer {
@ -134,8 +124,6 @@ func newDebug() *debugContainer {
if !debug.Enabled() {
return nil
}
d.log = debug.NewFile(fmt.Sprintf("%d-client.log", d.cn))
return &d
}
@ -145,9 +133,8 @@ func (d *debugContainer) newRoundTrip() *debugRoundTrip {
}
drt := debugRoundTrip{
cn: d.cn,
rn: atomic.AddUint64(&d.rn, 1),
log: d.log,
cn: d.cn,
rn: atomic.AddUint64(&d.rn, 1),
}
return &drt

View file

@ -0,0 +1,262 @@
/*
Copyright (c) 2023-2023 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
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package soap
import (
"bytes"
"context"
"errors"
"fmt"
"io"
"mime"
"net/http"
"reflect"
"strings"
"github.com/vmware/govmomi/vim25/xml"
"github.com/vmware/govmomi/vim25/types"
)
const (
sessionHeader = "vmware-api-session-id"
)
var (
// errInvalidResponse is used during unmarshaling when the response content
// does not match expectations e.g. unexpected HTTP status code or MIME
// type.
errInvalidResponse error = errors.New("Invalid response")
// errInputError is used as root error when the request is malformed.
errInputError error = errors.New("Invalid input error")
)
// Handles round trip using json HTTP
func (c *Client) jsonRoundTrip(ctx context.Context, req, res HasFault) error {
this, method, params, err := unpackSOAPRequest(req)
if err != nil {
return fmt.Errorf("Cannot unpack the request. %w", err)
}
return c.invoke(ctx, this, method, params, res)
}
// Invoke calls a managed object method
func (c *Client) invoke(ctx context.Context, this types.ManagedObjectReference, method string, params interface{}, res HasFault) error {
buffer := bytes.Buffer{}
if params != nil {
marshaller := types.NewJSONEncoder(&buffer)
err := marshaller.Encode(params)
if err != nil {
return fmt.Errorf("Encoding request to JSON failed. %w", err)
}
}
uri := c.getPathForName(this, method)
req, err := http.NewRequest(http.MethodPost, uri, &buffer)
if err != nil {
return err
}
if len(c.cookie) != 0 {
req.Header.Add(sessionHeader, c.cookie)
}
result, err := getSOAPResultPtr(res)
if err != nil {
return fmt.Errorf("Cannot get pointer to the result structure. %w", err)
}
return c.Do(ctx, req, c.responseUnmarshaler(&result))
}
// responseUnmarshaler create unmarshaler function for VMOMI JSON request. The
// unmarshaler checks for errors and tries to load the response body in the
// result structure. It is assumed that result is pointer to a data structure or
// interface{}.
func (c *Client) responseUnmarshaler(result interface{}) func(resp *http.Response) error {
return func(resp *http.Response) error {
if resp.StatusCode == http.StatusNoContent ||
(!isError(resp.StatusCode) && resp.ContentLength == 0) {
return nil
}
if e := checkJSONContentType(resp); e != nil {
return e
}
if resp.StatusCode == 500 {
bodyBytes, e := io.ReadAll(resp.Body)
if e != nil {
return e
}
var serverErr interface{}
dec := types.NewJSONDecoder(bytes.NewReader(bodyBytes))
e = dec.Decode(&serverErr)
if e != nil {
return e
}
var faultStringStruct struct {
FaultString string `json:"faultstring,omitempty"`
}
dec = types.NewJSONDecoder(bytes.NewReader(bodyBytes))
e = dec.Decode(&faultStringStruct)
if e != nil {
return e
}
f := &Fault{
XMLName: xml.Name{
Space: c.Namespace,
Local: reflect.TypeOf(serverErr).Name() + "Fault",
},
String: faultStringStruct.FaultString,
Code: "ServerFaultCode",
}
f.Detail.Fault = serverErr
return WrapSoapFault(f)
}
if isError(resp.StatusCode) {
return fmt.Errorf("Unexpected HTTP error code: %v. %w", resp.StatusCode, errInvalidResponse)
}
dec := types.NewJSONDecoder(resp.Body)
e := dec.Decode(result)
if e != nil {
return e
}
c.checkForSessionHeader(resp)
return nil
}
}
func isError(statusCode int) bool {
return statusCode < http.StatusOK || statusCode >= http.StatusMultipleChoices
}
// checkForSessionHeader checks if we have new session id.
// This is a hack that intercepts the session id header and then repeats it.
// It is very similar to cookie store but only for the special vCenter
// session header.
func (c *Client) checkForSessionHeader(resp *http.Response) {
sessionKey := resp.Header.Get(sessionHeader)
if len(sessionKey) > 0 {
c.cookie = sessionKey
}
}
// Checks if the payload of an HTTP response has the JSON MIME type.
func checkJSONContentType(resp *http.Response) error {
contentType := resp.Header.Get("content-type")
mediaType, _, err := mime.ParseMediaType(contentType)
if err != nil {
return fmt.Errorf("error parsing content-type: %v, error %w", contentType, err)
}
if mediaType != "application/json" {
return fmt.Errorf("content-type is not application/json: %v. %w", contentType, errInvalidResponse)
}
return nil
}
func (c *Client) getPathForName(this types.ManagedObjectReference, name string) string {
const urnPrefix = "urn:"
ns := c.Namespace
if strings.HasPrefix(ns, urnPrefix) {
ns = ns[len(urnPrefix):]
}
return fmt.Sprintf("%v/%v/%v/%v/%v/%v", c.u, ns, c.Version, this.Type, this.Value, name)
}
// unpackSOAPRequest converts SOAP request into this value, method nam and
// parameters using reflection. The input is a one of the *Body structures
// defined in methods.go. It is expected to have "Req" field that is a non-null
// pointer to a struct. The struct simple type name is the method name. The
// struct "This" member is the this MoRef value.
func unpackSOAPRequest(req HasFault) (this types.ManagedObjectReference, method string, params interface{}, err error) {
reqBodyPtr := reflect.ValueOf(req)
if reqBodyPtr.Kind() != reflect.Ptr {
err = fmt.Errorf("Expected pointer to request body as input. %w", errInputError)
return
}
reqBody := reqBodyPtr.Elem()
if reqBody.Kind() != reflect.Struct {
err = fmt.Errorf("Expected Request body to be structure. %w", errInputError)
return
}
methodRequestPtr := reqBody.FieldByName("Req")
if methodRequestPtr.Kind() != reflect.Ptr {
err = fmt.Errorf("Expected method request body field to be pointer to struct. %w", errInputError)
return
}
methodRequest := methodRequestPtr.Elem()
if methodRequest.Kind() != reflect.Struct {
err = fmt.Errorf("Expected method request body to be structure. %w", errInputError)
return
}
thisValue := methodRequest.FieldByName("This")
if thisValue.Kind() != reflect.Struct {
err = fmt.Errorf("Expected This field in the method request body to be structure. %w", errInputError)
return
}
var ok bool
if this, ok = thisValue.Interface().(types.ManagedObjectReference); !ok {
err = fmt.Errorf("Expected This field to be MoRef. %w", errInputError)
return
}
method = methodRequest.Type().Name()
params = methodRequestPtr.Interface()
return
}
// getSOAPResultPtr extract a pointer to the result data structure using go
// reflection from a SOAP data structure used for marshalling.
func getSOAPResultPtr(result HasFault) (res interface{}, err error) {
resBodyPtr := reflect.ValueOf(result)
if resBodyPtr.Kind() != reflect.Ptr {
err = fmt.Errorf("Expected pointer to result body as input. %w", errInputError)
return
}
resBody := resBodyPtr.Elem()
if resBody.Kind() != reflect.Struct {
err = fmt.Errorf("Expected result body to be structure. %w", errInputError)
return
}
methodResponsePtr := resBody.FieldByName("Res")
if methodResponsePtr.Kind() != reflect.Ptr {
err = fmt.Errorf("Expected method response body field to be pointer to struct. %w", errInputError)
return
}
if methodResponsePtr.IsNil() {
methodResponsePtr.Set(reflect.New(methodResponsePtr.Type().Elem()))
}
methodResponse := methodResponsePtr.Elem()
if methodResponse.Kind() != reflect.Struct {
err = fmt.Errorf("Expected method response body to be structure. %w", errInputError)
return
}
returnval := methodResponse.FieldByName("Returnval")
if !returnval.IsValid() {
// void method and we return nil, nil
return
}
res = returnval.Addr().Interface()
return
}