Documentation ¶
Index ¶
- Constants
- func IsStatusError(err error, code int) bool
- type Client
- func (c *Client) Do(ctx context.Context, req *http.Request, resBody interface{}) error
- func (c *Client) Download(ctx context.Context, u *url.URL, param *soap.Download) (io.ReadCloser, int64, error)
- func (c *Client) DownloadAttachment(ctx context.Context, req *http.Request, filename string) error
- func (c *Client) DownloadFile(ctx context.Context, file string, u *url.URL, param *soap.Download) error
- func (c *Client) Login(ctx context.Context, user *url.Userinfo) error
- func (c *Client) LoginByToken(ctx context.Context) error
- func (c *Client) Logout(ctx context.Context) error
- func (c *Client) MarshalJSON() ([]byte, error)
- func (c *Client) Path() string
- func (c *Client) Resource(path string) *Resource
- func (c *Client) Session(ctx context.Context) (*Session, error)
- func (c *Client) SessionID(id ...string) string
- func (c *Client) UnmarshalJSON(b []byte) error
- func (c *Client) Upload(ctx context.Context, f io.Reader, u *url.URL, param *soap.Upload) error
- func (c *Client) Valid() bool
- func (c *Client) WithHeader(ctx context.Context, headers http.Header) context.Context
- func (c *Client) WithSigner(ctx context.Context, s Signer) context.Context
- type LocalizableMessage
- type RawResponse
- type Resource
- func (r *Resource) Request(method string, body ...interface{}) *http.Request
- func (r *Resource) String() string
- func (r *Resource) WithAction(action string) *Resource
- func (r *Resource) WithID(id string) *Resource
- func (r *Resource) WithParam(name string, value string) *Resource
- func (r *Resource) WithPathEncodedParam(name string, value string) *Resource
- func (r *Resource) WithSubpath(subpath string) *Resource
- type Session
- type Signer
Examples ¶
Constants ¶
const (
Path = "/rest"
)
Variables ¶
This section is empty.
Functions ¶
func IsStatusError ¶
Types ¶
type Client ¶
Client extends soap.Client to support JSON encoding, while inheriting security features, debug tracing and session persistence.
func (*Client) Download ¶
func (c *Client) Download(ctx context.Context, u *url.URL, param *soap.Download) (io.ReadCloser, int64, error)
Download wraps soap.Client.Download, adding the REST authentication header
func (*Client) DownloadAttachment ¶
DownloadAttachment writes the response to given filename, defaulting to Content-Disposition filename in the response. A filename of "-" writes the response to stdout.
func (*Client) DownloadFile ¶
func (c *Client) DownloadFile(ctx context.Context, file string, u *url.URL, param *soap.Download) error
DownloadFile wraps soap.Client.DownloadFile, adding the REST authentication header
func (*Client) Login ¶
Login creates a new session via Basic Authentication with the given url.Userinfo.
func (*Client) LoginByToken ¶
Example ¶
package main import ( "context" "fmt" "net/url" _ "github.com/vmware/govmomi/lookup/simulator" "github.com/vmware/govmomi/simulator" "github.com/vmware/govmomi/sts" "github.com/vmware/govmomi/vapi/rest" "github.com/vmware/govmomi/vim25" _ "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 } rc := rest.NewClient(vc) err = rc.LoginByToken(rc.WithSigner(ctx, signer)) if err != nil { return err } session, err := rc.Session(ctx) if err != nil { return err } // Note: vcsim does not currently parse the token NameID for rest as it does for soap fmt.Println(session.User) return nil }) }
Output: TODO
func (*Client) MarshalJSON ¶
func (*Client) Session ¶
Session returns the user's current session. Nil is returned if the session is not authenticated.
func (*Client) SessionID ¶
SessionID is set by calling Login() or optionally with the given id param
func (*Client) UnmarshalJSON ¶
func (*Client) Valid ¶
Valid returns whether or not the client is valid and ready for use. This should be called after unmarshalling the client.
func (*Client) WithHeader ¶
WithHeader returns a new Context populated with the provided headers map. Calls to a VAPI REST client with this context will populate the HTTP headers map using the provided headers.
type LocalizableMessage ¶
type LocalizableMessage struct { Args []string `json:"args,omitempty"` DefaultMessage string `json:"default_message,omitempty"` ID string `json:"id,omitempty"` }
LocalizableMessage represents a localizable error
func (*LocalizableMessage) Error ¶
func (m *LocalizableMessage) Error() string
type RawResponse ¶
RawResponse may be used with the Do method as the resBody argument in order to capture the raw response data.
type Resource ¶
type Resource struct {
// contains filtered or unexported fields
}
Resource wraps url.URL with helpers
func (*Resource) Request ¶
Request returns a new http.Request for the given method. An optional body can be provided for POST and PATCH methods.
func (*Resource) WithAction ¶
WithAction sets adds action to the URL.RawQuery
func (*Resource) WithPathEncodedParam ¶
WithPathEncodedParam appends a parameter on the URL.RawQuery, For special cases where URL Path-style encoding is needed
func (*Resource) WithSubpath ¶
WithSubpath appends the provided subpath to the URL.Path