Categorygithub.com/linode/go-metadata
modulepackage
0.2.0
Repository: https://github.com/linode/go-metadata.git
Documentation: pkg.go.dev

# README

Linode Metadata Service Client for Go

Release GoDoc

This package allows Go projects to easily interact with the Linode Metadata Service.

Getting Started

Prerequisites

Installation

go get github.com/linode/go-metadata

Basic Example

The following sample shows a simple Go project that initializes a new metadata client and retrieves various information about the current Linode.

package main

import (
	"context"
	"fmt"
	"log"

	metadata "github.com/linode/go-metadata"
)

func main() {
	// Create a new client
	client, err := metadata.NewClient(context.Background())
	if err != nil {
		log.Fatal(err)
	}

	// Retrieve metadata about the current instance from the metadata API
	instanceInfo, err := client.GetInstance(context.Background())
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println("Instance Label:", instanceInfo.Label)
}

Without Token Management

By default, metadata API tokens are automatically generated and refreshed without any user intervention. If you would like to manage API tokens yourself, this functionality can be disabled:

package main

import (
	"context"
	"fmt"
	"log"
	"os"

	metadata "github.com/linode/go-metadata"
)

func main() {
	// Get a token from the environment
	token := os.Getenv("LINODE_METADATA_TOKEN")

	// Create a new client
	client, err := metadata.NewClient(
		context.Background(), 
		metadata.ClientWithoutManagedToken(), 
		metadata.ClientWithToken(token),
	)
	if err != nil {
		log.Fatal(err)
	}

	// Retrieve metadata about the current instance from the metadata API
	instanceInfo, err := client.GetInstance(context.Background())
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println("Instance Label:", instanceInfo.Label)
}

For more examples, visit the examples directory.

Documentation

See godoc for a complete documentation reference.

Testing

Before running tests on this project, please ensure you have a Linode Personal Access Token exported under the LINODE_TOKEN environment variable.

End-to-End Testing Using Ansible

This project contains an Ansible playbook to automatically deploy the necessary infrastructure and run end-to-end tests on it.

To install the dependencies for this playbook, ensure you have Python 3 installed and run the following:

make test-deps

After all dependencies have been installed, you can run the end-to-end test suite by running the following:

make e2e

If your local SSH public key is stored in a location other than ~/.ssh/id_rsa.pub, you may need to override the TEST_PUBKEY argument:

make TEST_PUBKEY=/path/to/my/pubkey e2e

NOTE: To speed up subsequent test runs, the infrastructure provisioned for testing will persist after the test run is complete. This infrastructure is safe to manually remove.

Manual End-to-End Testing

End-to-end tests can also be manually run using the make e2e-local target. This test suite is expected to run from within a Linode instance and will likely fail in other environments.

Contribution Guidelines

Want to improve metadata-go? Please start here.

License

This software is Copyright Akamai Technologies, Inc. and is released under the Apache 2.0 license.

# Packages

No description provided by the author

# Functions

ClientWithBaseURL configures the target host of the Metadata API this client points to.
ClientWithDebug enables debug mode for the metadata client.
ClientWithHTTPClient configures the underlying HTTP client to communicate with the Metadata API.
ClientWithLogger specifies the logger that should be used when outputting debug logs.
ClientWithManagedToken configures the metadata client to automatically generate and refresh the API token for the Metadata client.
ClientWithoutManagedToken configures the metadata client to disable automatic token management.
ClientWithToken configures the starting token for the metadata client.
ClientWithUAPrefix configures the prefix for user agents on API requests made by this client.
ClientWithVersion configures the Metadata API version this client should target.
NewClient creates a new Metadata API client configured with the given options.
TokenWithExpiry configures the expiry in seconds for a token.
WatcherWithInterval configures the interval at which a watcher should poll for changes.

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Variables

DefaultUserAgent is the default User-Agent sent in HTTP request headers.
No description provided by the author

# Structs

APIError is the error-set returned by the Linode API when presented with an invalid request.
APIErrorReason is an individual invalid request message returned by the Linode API.
Client represents an instance of a Linode Metadata Service client.
Error wraps the LinodeGo error with the relevant http.Response.
InstanceBackupsData contains information about the current Linode instance's backups enrollment.
InstanceData contains various metadata about the current Linode instance.
InstanceSpecsData contains various information about the specifications of the current Linode instance.
InstanceWatcher watches for any changes that are reflected in the Client.GetInstance(...) function result.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
NetworkWatcher watches for any changes that are reflected in the Client.GetNetwork(...) function result.
SSHKeysData contains information about SSH keys relevant to the current Linode instance.

# Type aliases

ClientOption is an option that can be used during client creation.
No description provided by the author
No description provided by the author
WatcherOption represents an option that can be used to configure a watcher.