gotruenas

package module
v0.0.0-...-bb2062f Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2021 License: BSD-3-Clause, MIT Imports: 11 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bool

func Bool(v bool) *bool

Bool is a helper routine that allocates a new bool value to store v and returns a pointer to it.

func CheckResponse

func CheckResponse(r *http.Response) error

CheckResponse checks the API response for errors, and returns them if present. A response is considered an error if it has a status code outside the 200 range. API error responses are expected to have either no response body, or a JSON response body that maps to ErrorResponse. Any other response body will be silently ignored.

func DoRequest

func DoRequest(ctx context.Context, req *http.Request) (*http.Response, error)

DoRequest submits an HTTP request.

func DoRequestWithClient

func DoRequestWithClient(
	ctx context.Context,
	client *http.Client,
	req *http.Request) (*http.Response, error)

DoRequestWithClient submits an HTTP request using the specified client.

func Int

func Int(v int) *int

Int is a helper routine that allocates a new int32 value to store v and returns a pointer to it, but unlike Int32 its argument value is an int.

func StreamToString

func StreamToString(stream io.Reader) string

StreamToString converts a reader to a string

func String

func String(v string) *string

String is a helper routine that allocates a new string value to store v and returns a pointer to it.

Types

type Client

type Client struct {

	// Config for the client such as the TrueNAS hostname and credentials
	Config *Config

	// Base URL for API requests.
	BaseURL *url.URL

	// User agent for client
	UserAgent string

	// Services used for communicating with the API
	PoolDatasets PoolDatasets
	// contains filtered or unexported fields
}

Client manages communication with TrueNAS V2 API.

func NewClient

func NewClient(config *Config) (*Client, error)

NewClient returns a new TrueNAS API client, using the given http.Client to perform all requests.

Users who wish to pass their own http.Client should use this method. If you're in need of further customization, the gotruenas.New method allows more options, such as setting a custom URL or a custom user agent string.

func (*Client) Do

func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) (*http.Response, error)

Do sends an API request and returns the API response. The API response is JSON decoded and stored in the value pointed to by v, or returned as an error if an API error has occurred. If v implements the io.Writer interface, the raw response will be written to v, without attempting to decode it.

func (*Client) NewRequest

func (c *Client) NewRequest(ctx context.Context, method, urlStr string, body interface{}) (*http.Request, error)

NewRequest creates an API request. A relative URL can be provided in urlStr, which will be resolved to the BaseURL of the Client. Relative URLS should always be specified without a preceding slash. If specified, the value pointed to by body is JSON encoded and included in as the request body.

func (*Client) OnRequestCompleted

func (c *Client) OnRequestCompleted(rc RequestCompletionCallback)

OnRequestCompleted sets the TrueNAS API request completion callback

type ClientOpt

type ClientOpt func(*Client) error

ClientOpt are options for New.

func SetBaseURL

func SetBaseURL(bu string) ClientOpt

SetBaseURL is a client option for setting the base URL.

func SetRequestHeaders

func SetRequestHeaders(headers map[string]string) ClientOpt

SetRequestHeaders sets optional HTTP headers on the client that are sent on each HTTP request.

func SetUserAgent

func SetUserAgent(ua string) ClientOpt

SetUserAgent is a client option for setting the user agent.

type Config

type Config struct {
	TrueNASHost string
	BearerToken string
	SSLVerify   bool
}

Config defines the configuration needed to connect to the TrueNAS server

type ErrorResponse

type ErrorResponse struct {
	// HTTP response that caused this error
	Response *http.Response

	// Error message
	Message string `json:"message"`

	// RequestID returned from the API, useful to contact support.
	RequestID string `json:"request_id"`
}

An ErrorResponse reports the error caused by an API request

func (*ErrorResponse) Error

func (r *ErrorResponse) Error() string

type ListOptions

type ListOptions struct {
	Count  bool   `url:"count,omitempty"`
	Limit  int    `url:"limit,omitempty"`
	Offset int    `url:"offset,omitempty"`
	Sort   string `url:"count,omitempty"`
}

ListOptions specifies the optional parameters to various List methods that support pagination.

type PoolDataset

type PoolDataset struct {
	ID                    *string        `json:"id"`
	Type                  *string        `json:"type"`
	Children              *[]PoolDataset `json:"children"`
	Name                  *string        `json:"name"`
	Pool                  *string        `json:"pool"`
	Encryption            *bool          `json:"encryption"`
	EncryptionRoot        *bool          `json:"encryption_root"`
	KeyLoaded             *bool          `json:"key_loaded"`
	Mountpoint            *string        `json:"mountpoint"`
	Deduplication         *value         `json:"deduplication"`
	ACLMode               *value         `json:"aclmode"`
	ACLType               *value         `json:"acltype"`
	Xattr                 *value         `json:"xattr"`
	Atime                 *value         `json:"atime"`
	CaseSensitivity       *value         `json:"casesensitivity"`
	Exec                  *value         `json:"exec"`
	Sync                  *value         `json:"sync"`
	Compression           *value         `json:"compression"`
	CompressRatio         *value         `json:"compressratio"`
	Origin                *value         `json:"origin"`
	Quota                 *value         `json:"quota"`
	RefQuota              *value         `json:"refquota"`
	Reservation           *value         `json:"reservation"`
	RefReservation        *value         `json:"refreservation"`
	Copies                *value         `json:"copies"`
	SnapDir               *value         `json:"snapdir"`
	ReadOnly              *value         `json:"readonly"`
	RecordSize            *value         `json:"recordsize"`
	KeyFormat             *value         `json:"key_format"`
	EncryptionAlgorithm   *value         `json:"encryption_algorithm"`
	Used                  *value         `json:"used"`
	Available             *value         `json:"available"`
	SpecialSmallBlockSize *value         `json:"special_small_block_size"`
	Pbkdf2iters           *value         `json:"pbkdf2iters"`
	Locked                *bool          `json:"locked"`
}

PoolDataset defines model for a pool dataset.

type PoolDatasetCreate

type PoolDatasetCreate struct {
	Name                  *string `json:"name"`
	Type                  *string `json:"type"`
	VolSize               *int    `json:"volsize,omitempty"`
	VolBlockSize          *int    `json:"volblocksize,omitempty"`
	Sparse                *bool   `json:"sparse,omitempty"`
	ForceSize             *bool   `json:"force_size,omitempty"`
	Comments              *string `json:"comments,omitempty"`
	Sync                  *string `json:"sync,omitempty"`
	Compression           *string `json:"compression,omitempty"`
	ATime                 *string `json:"atime,omitempty"`
	Exec                  *string `json:"exec,omitempty"`
	ManagedBy             *string `json:"managedby,omitempty"`
	Quota                 *int    `json:"quota,omitempty"`
	QuotaWarning          *int    `json:"quota_warning,omitempty"`
	QuotaCritical         *int    `json:"quota_critical,omitempty"`
	RefQuota              *int    `json:"refquota,omitempty"`
	RefQuotaWarning       *int    `json:"refquota_warning,omitempty"`
	RefquotaCritical      *int    `json:"refquota_critical,omitempty"`
	Reservation           *int    `json:"reservation,omitempty"`
	RefReservation        *int    `json:"refreservation,omitempty"`
	SpecialSmallBlockSize *int    `json:"special_small_block_size,omitempty"`
	Copies                *int    `json:"copies,omitempty"`
	SnapDir               *string `json:"snapdir,omitempty"`
	Deduplication         *string `json:"deduplication,omitempty"`
	ReadOnly              *string `json:"readonly,omitempty"`
	RecordSize            *string `json:"recordsize,omitempty"`
	CaseSensitivity       *string `json:"casesensitivity,omitempty"`
	ACLMode               *string `json:"aclmode,omitempty"`
	ACLType               *string `json:"acltype,omitempty"`
	ShareType             *string `json:"share_type,omitempty"`
	Xattr                 *string `json:"xattr,omitempty"`
	Encryption            *bool   `json:"encryption,omitempty"`
	InheritEncryption     *bool   `json:"inherit_encryption,omitempty"`
	EncryptionOptions     struct {
		GenerateKey *bool   `json:"generate_key,omitempty"`
		Pbkdf2iters *int    `json:"pbkdf2iters,omitempty"`
		Algorithm   *string `json:"algorithm,omitempty"`
		Passphrase  *string `json:"passphrase,omitempty"`
		Key         *string `json:"key,omitempty"`
	} `json:"encryption_options,omitempty"`
}

PoolDatasetCreate defines model for creating a pool dataset.

type PoolDatasets

type PoolDatasets interface {
	Create(ctx context.Context, body PoolDatasetCreate) (*PoolDataset, *http.Response, error)
	Delete(ctx context.Context, id string) (*http.Response, error)
	Get(ctx context.Context, id string) (*PoolDataset, *http.Response, error)
	List(ctx context.Context, opt *ListOptions) (*[]PoolDataset, *http.Response, error)
}

PoolDatasets is an interface for interacting with Pool Datasets

type PoolDatasetsOp

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

PoolDatasetsOp handles communication with the Pool Dataset related methods of the TrueNAS REST API

func (*PoolDatasetsOp) Create

Create a new activation key

func (*PoolDatasetsOp) Delete

func (s *PoolDatasetsOp) Delete(ctx context.Context, id string) (*http.Response, error)

Delete an activation key by its ID

func (*PoolDatasetsOp) Get

Get a single pool dataset by its ID

func (*PoolDatasetsOp) List

List all activation keys or a filtered list of activation keys

type RequestCompletionCallback

type RequestCompletionCallback func(*http.Request, *http.Response)

RequestCompletionCallback defines the type of the request callback function

Jump to

Keyboard shortcuts

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