Documentation ¶
Index ¶
- Constants
- Variables
- type APIError
- type APIErrorReason
- type Client
- func (c *Client) GenerateToken(ctx context.Context, opts ...TokenOption) (string, error)
- func (c *Client) GetInstance(ctx context.Context) (*InstanceData, error)
- func (c *Client) GetNetwork(ctx context.Context) (*NetworkData, error)
- func (c *Client) GetSSHKeys(ctx context.Context) (*SSHKeysData, error)
- func (c *Client) GetUserData(ctx context.Context) (string, error)
- func (c *Client) NewInstanceWatcher(opts ...WatcherOption) *InstanceWatcher
- func (c *Client) NewNetworkWatcher(opts ...WatcherOption) *NetworkWatcher
- func (c *Client) R(ctx context.Context) *resty.Request
- func (c *Client) RefreshToken(ctx context.Context, opts ...TokenOption) (*Client, error)
- func (c *Client) SetBaseURL(baseURL string) *Client
- func (c *Client) SetVersion(version string) *Client
- func (c *Client) UseToken(token string) *Client
- type ClientOption
- func ClientWithBaseURL(baseURL string) ClientOption
- func ClientWithDebug() ClientOption
- func ClientWithHTTPClient(client *http.Client) ClientOption
- func ClientWithLogger(logger Logger) ClientOption
- func ClientWithManagedToken(opts ...TokenOption) ClientOption
- func ClientWithToken(token string) ClientOption
- func ClientWithUAPrefix(uaPrefix string) ClientOption
- func ClientWithVersion(version string) ClientOption
- func ClientWithoutManagedToken() ClientOption
- type Error
- type IPv4Data
- type IPv6Data
- type InstanceBackupsData
- type InstanceData
- type InstanceImageData
- type InstanceSpecsData
- type InstanceWatcher
- type InterfaceData
- type Logger
- type NetworkData
- type NetworkWatcher
- type SSHKeysData
- type TokenOption
- type WatcherOption
Constants ¶
const ( APIHost = "169.254.169.254" APIProto = "http" APIVersion = "v1" )
const DefaultWatcherInterval = 5 * time.Minute
Variables ¶
var ( Version = "dev" // DefaultUserAgent is the default User-Agent sent in HTTP request headers DefaultUserAgent string )
Functions ¶
This section is empty.
Types ¶
type APIError ¶
type APIError struct {
Errors []APIErrorReason `json:"errors"`
}
APIError is the error-set returned by the Linode API when presented with an invalid request
type APIErrorReason ¶
APIErrorReason is an individual invalid request message returned by the Linode API
func (APIErrorReason) Error ¶
func (r APIErrorReason) Error() string
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents an instance of a Linode Metadata Service client.
func NewClient ¶
func NewClient(ctx context.Context, opts ...ClientOption) (*Client, error)
NewClient creates a new Metadata API client configured with the given options.
func (*Client) GenerateToken ¶
GenerateToken generates a token to access the Metadata API.
func (*Client) GetInstance ¶
func (c *Client) GetInstance(ctx context.Context) (*InstanceData, error)
GetInstance gets various information about the current instance.
func (*Client) GetNetwork ¶
func (c *Client) GetNetwork(ctx context.Context) (*NetworkData, error)
GetNetwork gets networking information about the current Linode instance.
func (*Client) GetSSHKeys ¶
func (c *Client) GetSSHKeys(ctx context.Context) (*SSHKeysData, error)
GetSSHKeys gets all SSH keys for the current instance.
func (*Client) GetUserData ¶
GetUserData returns the user data for the current instance. NOTE: The result of this endpoint is automatically decoded from base64 and un-gzipped if needed.
func (*Client) NewInstanceWatcher ¶
func (c *Client) NewInstanceWatcher(opts ...WatcherOption) *InstanceWatcher
NewInstanceWatcher creates a new InstanceWatcher for monitoring changes to the current Linode instance.
func (*Client) NewNetworkWatcher ¶
func (c *Client) NewNetworkWatcher(opts ...WatcherOption) *NetworkWatcher
NewNetworkWatcher creates a new NetworkWatcher for monitoring changes to the current Linode instance.
func (*Client) RefreshToken ¶
RefreshToken generates and applies a new token for this client.
func (*Client) SetBaseURL ¶
SetBaseURL configures the target URL for metadata API this client accesses.
func (*Client) SetVersion ¶
SetVersion configures the target metadata API version for this client.
type ClientOption ¶
type ClientOption func(options *clientCreateConfig)
ClientOption is an option that can be used during client creation.
func ClientWithBaseURL ¶
func ClientWithBaseURL(baseURL string) ClientOption
ClientWithBaseURL configures the target host of the Metadata API this client points to. Default: "169.254.169.254"
func ClientWithDebug ¶
func ClientWithDebug() ClientOption
ClientWithDebug enables debug mode for the metadata client. If this option is specified, all metadata service API requests and responses will be written to the client logger (default: stderr).
To override the client logger, refer to ClientWithLogger.
func ClientWithHTTPClient ¶
func ClientWithHTTPClient(client *http.Client) ClientOption
ClientWithHTTPClient configures the underlying HTTP client to communicate with the Metadata API.
func ClientWithLogger ¶
func ClientWithLogger(logger Logger) ClientOption
ClientWithLogger specifies the logger that should be used when outputting debug logs. The logger argument should implement the Logger interface. Default: stderr
func ClientWithManagedToken ¶
func ClientWithManagedToken(opts ...TokenOption) ClientOption
ClientWithManagedToken configures the metadata client to automatically generate and refresh the API token for the Metadata client.
func ClientWithToken ¶
func ClientWithToken(token string) ClientOption
ClientWithToken configures the starting token for the metadata client. If this option is specified and managed tokens are enabled for a client, the client will not generate an initial Metadata API token.
func ClientWithUAPrefix ¶
func ClientWithUAPrefix(uaPrefix string) ClientOption
ClientWithUAPrefix configures the prefix for user agents on API requests made by this client.
func ClientWithVersion ¶
func ClientWithVersion(version string) ClientOption
ClientWithVersion configures the Metadata API version this client should target. Default: "v1"
func ClientWithoutManagedToken ¶
func ClientWithoutManagedToken() ClientOption
ClientWithoutManagedToken configures the metadata client to disable automatic token management.
type InstanceBackupsData ¶
InstanceBackupsData contains information about the current Linode instance's backups enrollment.
type InstanceData ¶
type InstanceData struct { ID int `json:"id"` Label string `json:"label"` Region string `json:"region"` Type string `json:"type"` HostUUID string `json:"host_uuid"` Tags []string `json:"tags"` Specs InstanceSpecsData `json:"specs"` Backups InstanceBackupsData `json:"backups"` Image InstanceImageData `json:"image"` }
InstanceData contains various metadata about the current Linode instance.
type InstanceImageData ¶
InstanceImageData contains information about the Disk Image used during instance provisioning
type InstanceSpecsData ¶
type InstanceSpecsData struct { VCPUs int `json:"vcpus"` Memory int `json:"memory"` GPUs int `json:"gpus"` Transfer int `json:"transfer"` Disk int `json:"disk"` }
InstanceSpecsData contains various information about the specifications of the current Linode instance.
type InstanceWatcher ¶
type InstanceWatcher struct { Updates chan *InstanceData Errors chan error // contains filtered or unexported fields }
InstanceWatcher watches for any changes that are reflected in the Client.GetInstance(...) function result.
func (*InstanceWatcher) Close ¶
func (watcher *InstanceWatcher) Close()
Close closes the watcher and all related channels. If applicable, close will also cancel the poller for this watcher.
func (*InstanceWatcher) Start ¶
func (watcher *InstanceWatcher) Start(ctx context.Context)
Start starts the watcher. NOTE: Start should only be called once per-watcher.
type InterfaceData ¶
type NetworkData ¶
type NetworkData struct { Interfaces []InterfaceData `json:"interfaces"` IPv4 IPv4Data `json:"ipv4"` IPv6 IPv6Data `json:"ipv6"` }
type NetworkWatcher ¶
type NetworkWatcher struct { Updates chan *NetworkData Errors chan error // contains filtered or unexported fields }
NetworkWatcher watches for any changes that are reflected in the Client.GetNetwork(...) function result.
func (*NetworkWatcher) Close ¶
func (watcher *NetworkWatcher) Close()
Close closes the watcher and all related channels. If applicable, close will also cancel the poller for this watcher.
func (*NetworkWatcher) Start ¶
func (watcher *NetworkWatcher) Start(ctx context.Context)
Start starts the watcher. NOTE: Start should only be called once per-watcher.
type SSHKeysData ¶
SSHKeysData contains information about SSH keys relevant to the current Linode instance.
type TokenOption ¶
type TokenOption func(opts *tokenCreateOpts)
func TokenWithExpiry ¶
func TokenWithExpiry(seconds int) TokenOption
TokenWithExpiry configures the expiry in seconds for a token. Default: 3600
type WatcherOption ¶
type WatcherOption func(options *watcherConfig)
WatcherOption represents an option that can be used to configure a watcher.
func WatcherWithInterval ¶
func WatcherWithInterval(duration time.Duration) WatcherOption
WatcherWithInterval configures the interval at which a watcher should poll for changes. Default: 5 minutes