Documentation
¶
Index ¶
- Constants
- func DefaultListOptions(page int, filter string) *linodego.ListOptions
- func NewLinodeClient(token, ua, apiURL string) (*linodego.Client, error)
- func NewLinodeClientWithTokenProvider(ua, apiURL string, tokenProvider TokenProvider) (*linodego.Client, error)
- func TokenFileCacheTTLFromEnv() time.Duration
- type LinodeClient
- type TokenFileProvider
- type TokenProvider
Constants ¶
const ( // AccessTokenEnv is the environment variable holding a static Linode API token. AccessTokenEnv = "LINODE_TOKEN" // TokenFilePathEnv is the environment variable pointing at a mounted token file. TokenFilePathEnv = "LINODE_API_TOKEN_FILE" // TokenCacheTTLEnv optionally overrides the token file cache TTL in seconds. TokenCacheTTLEnv = "LINODE_API_TOKEN_CACHE_TTL_SECONDS" // DefaultTokenFilePath is the default path for a secret-mounted API token. DefaultTokenFilePath = "/var/run/secrets/linode/api-token" // DefaultTokenFileCacheTTL is how long a file-backed token is cached. DefaultTokenFileCacheTTL = time.Minute )
const DefaultPageSize = 500
DefaultPageSize is the page size used for all Linode API list calls. 500 is the maximum page size allowed by the Linode API.
Variables ¶
This section is empty.
Functions ¶
func DefaultListOptions ¶ added in v1.1.4
func DefaultListOptions(page int, filter string) *linodego.ListOptions
DefaultListOptions builds ListOptions for a Linode API list call with the page size pinned to DefaultPageSize. Pass page 0 to fetch all pages, or a 1-based page number to fetch a single page.
func NewLinodeClient ¶
NewLinodeClient creates a Linode API client authenticated with a static token. Prefer NewLinodeClientWithTokenProvider when tokens may rotate without restart.
func NewLinodeClientWithTokenProvider ¶ added in v1.1.4
func NewLinodeClientWithTokenProvider(ua, apiURL string, tokenProvider TokenProvider) (*linodego.Client, error)
NewLinodeClientWithTokenProvider creates a Linode API client that obtains the Authorization bearer token from tokenProvider on each HTTP request.
func TokenFileCacheTTLFromEnv ¶ added in v1.1.4
TokenFileCacheTTLFromEnv returns the configured cache TTL or the default.
Types ¶
type LinodeClient ¶
type LinodeClient interface {
ListInstances(context.Context, *linodego.ListOptions) ([]linodego.Instance, error) // Needed for metadata
ListVolumes(context.Context, *linodego.ListOptions) ([]linodego.Volume, error)
ListInstanceVolumes(ctx context.Context, instanceID int, options *linodego.ListOptions) ([]linodego.Volume, error)
ListInstanceDisks(ctx context.Context, instanceID int, options *linodego.ListOptions) ([]linodego.InstanceDisk, error)
GetRegion(ctx context.Context, regionID string) (*linodego.Region, error)
GetInstance(context.Context, int) (*linodego.Instance, error)
GetVolume(context.Context, int) (*linodego.Volume, error)
CreateVolume(context.Context, linodego.VolumeCreateOptions) (*linodego.Volume, error)
CloneVolume(context.Context, int, linodego.VolumeCloneOptions) (*linodego.Volume, error)
AttachVolume(context.Context, int, *linodego.VolumeAttachOptions) (*linodego.Volume, error)
DetachVolume(context.Context, int) error
WaitForVolumeLinodeID(context.Context, int, *int) (*linodego.Volume, error)
WaitForVolumeStatus(context.Context, int, linodego.VolumeStatus) (*linodego.Volume, error)
DeleteVolume(context.Context, int) error
ResizeVolume(context.Context, int, linodego.VolumeResizeOptions) error
NewEventPoller(context.Context, any, linodego.EntityType, linodego.EventAction) (*linodego.EventPoller, error)
}
type TokenFileProvider ¶ added in v1.1.4
type TokenFileProvider struct {
// contains filtered or unexported fields
}
TokenFileProvider reads a token from a file with a short TTL cache so secret updates are picked up without restarting the process.
func NewTokenFileProvider ¶ added in v1.1.4
func NewTokenFileProvider(path string, cacheTTL time.Duration) *TokenFileProvider
NewTokenFileProvider constructs a file-backed token provider.
func (*TokenFileProvider) GetToken ¶ added in v1.1.4
func (t *TokenFileProvider) GetToken(_ context.Context) (string, error)
GetToken returns a cached token when still valid, otherwise re-reads the file.
func (*TokenFileProvider) String ¶ added in v1.1.4
func (t *TokenFileProvider) String() string
type TokenProvider ¶ added in v1.1.4
TokenProvider returns a Linode API token for the current request. Implementations may re-read a mounted secret so tokens can rotate without a restart.
func StaticTokenProvider ¶ added in v1.1.4
func StaticTokenProvider(token string) TokenProvider
StaticTokenProvider returns a TokenProvider that always yields the given token.
func TokenProviderFromFileOrEnv ¶ added in v1.1.4
func TokenProviderFromFileOrEnv(ctx context.Context, staticToken string) (TokenProvider, string, error)
TokenProviderFromFileOrEnv prefers a mounted token file (when readable), then falls back to staticToken (e.g. from --LINODE_TOKEN / envflag), then to the LINODE_TOKEN environment variable. Returns an error when no source yields a token. The second return value describes the chosen source for logging.