rest

package
v0.0.0-...-fd46d7f Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2023 License: MPL-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoDataObjectInResponse = errors.New("the server did not include a data object in the response")

ErrNoDataObjectInResponse is returned when the server does not include a data object in the response.

Functions

This section is empty.

Types

type AuthenticationResponseBody

type AuthenticationResponseBody struct {
	Data *AuthenticationResponseData `json:"data,omitempty"`
}

AuthenticationResponseBody contains the body from an authentication response.

type AuthenticationResponseCapabilities

type AuthenticationResponseCapabilities struct {
	Access     *types.CustomPrivileges `json:"access,omitempty"`
	Datacenter *types.CustomPrivileges `json:"dc,omitempty"`
	Nodes      *types.CustomPrivileges `json:"nodes,omitempty"`
	Storage    *types.CustomPrivileges `json:"storage,omitempty"`
	VMs        *types.CustomPrivileges `json:"vms,omitempty"`
}

AuthenticationResponseCapabilities contains the supported capabilities for a session.

type AuthenticationResponseData

type AuthenticationResponseData struct {
	ClusterName         *string                             `json:"clustername,omitempty"`
	CSRFPreventionToken *string                             `json:"CSRFPreventionToken,omitempty"`
	Capabilities        *AuthenticationResponseCapabilities `json:"cap,omitempty"`
	Ticket              *string                             `json:"ticket,omitempty"`
	Username            string                              `json:"username"`
}

AuthenticationResponseData contains the data from an authentication response.

type Authenticator

type Authenticator interface {
	// IsRoot returns true if the authenticator is configured to use the root
	IsRoot() bool

	// IsRootTicket returns true if the authenticator is configured to use the root directly using a login ticket.
	// (root using token is weaker, cannot change VM arch)
	IsRootTicket() bool

	// AuthenticateRequest adds authentication data to a new request.
	AuthenticateRequest(ctx context.Context, req *http.Request) error
}

Authenticator is an interface for adding authentication data to a request. The authenticator is also aware of the authentication context, e.g. if it is configured to use the root user.

func NewTicketAuthenticator

func NewTicketAuthenticator(conn *Connection, creds *Credentials) (Authenticator, error)

NewTicketAuthenticator returns a new ticket authenticator.

func NewTokenAuthenticator

func NewTokenAuthenticator(token string) (Authenticator, error)

NewTokenAuthenticator creates a new authenticator that uses a PVE API Token for authentication.

type Client

type Client interface {
	// DoRequest performs a request against the Proxmox API.
	DoRequest(
		ctx context.Context,
		method, path string,
		requestBody, responseBody interface{},
	) error

	// ExpandPath expands a path relative to the client's base path.
	// For example, if the client is configured for a VM and the
	// path is "firewall/options", the returned path will be
	// "/nodes/<node>/qemu/<vmid>/firewall/options".
	ExpandPath(path string) string

	// IsRoot returns true if the client is configured with the root user.
	IsRoot() bool

	// IsRootTicket returns true if the authenticator is configured to use the root directly using a login ticket.
	// (root using token is weaker, cannot change VM arch)
	IsRootTicket() bool
}

Client is an interface for performing requests against the Proxmox API.

func NewClient

func NewClient(creds *Credentials, conn *Connection) (Client, error)

NewClient creates and initializes a VirtualEnvironmentClient instance.

type Connection

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

Connection represents a connection to the Proxmox Virtual Environment API.

func NewConnection

func NewConnection(endpoint string, insecure bool) (*Connection, error)

NewConnection creates and initializes a Connection instance.

type Credentials

type Credentials struct {
	Username string
	Password string
	OTP      *string
	APIToken *string
}

Credentials is a struct that holds the credentials for the Proxmox Virtual Environment API.

func NewCredentials

func NewCredentials(username, password, otp, apiToken string) (*Credentials, error)

NewCredentials creates a new Credentials struct.

type ErrorResponseBody

type ErrorResponseBody struct {
	Data   *string            `json:"data"`
	Errors *map[string]string `json:"errors"`
}

ErrorResponseBody contains the body of an error response.

type FileUploadRequest

type FileUploadRequest struct {
	ContentType string
	FileName    string
	File        *os.File
}

FileUploadRequest is a request for uploading a file.

type MultiPartData

type MultiPartData struct {
	Boundary string
	Reader   io.Reader
	Size     *int64
}

MultiPartData enables multipart uploads in DoRequest.

Jump to

Keyboard shortcuts

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