intersight

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2023 License: MIT Imports: 13 Imported by: 3

Documentation

Overview

Package intersight provides a simple to use client for the Intersight API. It handles signature authentication and supports both v2 and v3 keys.

Simple example to get NTP policies

func Example() {
	client, _ := intersight.NewClient()

	result, _ := client.Get("/api/v1/ntp/Policies")

	fmt.Printf("Result: \n%v", result)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client handles communication with the Intersight API. It holds credentials (API keys) and handles authentication for a single Intersight account.

func NewClient

func NewClient(configs ...Config) (*Client, error)

NewClient creates a new Client object. If called with no parameters, it will default to the Intersight SaaS instance and attempt to find the Key ID and Key File from the IS_KEYID and IS_KEYFILE environment variables. Alternatively, it can be passed a Config object to explicitly set the key details and other options.

func (*Client) Call

func (c *Client) Call(method, path string, body []byte) (any, error)

Call will send a request to the Intersight API. The response will be JSON decoded automatically. Get will return an error if the HTTP request fails, if the API response code is not 2xx or if JSON decoding fails.

func (*Client) Delete

func (c *Client) Delete(path string) (any, error)

Delete will send a DELETE request to the Intersight API. The response will be JSON decoded automatically. Delete will return an error if the HTTP request fails or if the API response code is not 2xx.

func (*Client) Get

func (c *Client) Get(path string) (any, error)

Get will send a GET request to the Intersight API. The response will be JSON decoded automatically. Get will return an error if the HTTP request fails, if the API response code is not 2xx or if JSON decoding fails.

func (*Client) Patch

func (c *Client) Patch(path string, body []byte) (any, error)

Patch will send a POST request to the Intersight API. The response will be JSON decoded automatically. Patch will return an error if the HTTP request fails, if the API response code is not 2xx or if JSON decoding fails.

func (*Client) Post

func (c *Client) Post(path string, body []byte) (any, error)

Post will send a POST request to the Intersight API. The response will be JSON decoded automatically. Post will return an error if the HTTP request fails, if the API response code is not 2xx or if JSON decoding fails.

type Config

type Config struct {
	// KeyID is the Intersight API Key ID
	// If unset, the value of IS_KEYID environment variable will be used.
	KeyID string

	// KeyFile is the path to a file containing the Intersight API Key.
	// This cannot be set at the same time as KeyData.
	// If unset, the value of IS_KEYFILE environment variable will be used.
	KeyFile string

	// KeyData is the Intersight API key. This cannot be set at the same time as KeyFile.
	KeyData string

	// Host is the Intersight instance host name. Default "intersight.com"
	Host string

	// Logger is a logger object to send log messages to
	Logger Logger

	// BaseTransport is a http.RoundTripper for this client to use. If unset http.DefaultTransport will be used.
	BaseTransport http.RoundTripper
}

Config holds configuration options for creating a new Client. Each field that is empty will be replaced with a default value when calling NewClient

type Logger

type Logger interface {
	Printf(format string, v ...any)
}

Logger is an interface that can receive log messages.

Jump to

Keyboard shortcuts

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