api

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2021 License: Apache-2.0 Imports: 10 Imported by: 0

README

Drago API Client

This directory contains the api package which aims at providing programmatic access to Drago's HTTP API.

Documentation

...

Usage

package main

import "github.com/seashell/drago/api"

func main() {
	// Get a new client
	client, err := api.NewClient(api.DefaultConfig())
	if err != nil {
		panic(err)
	}   
	
	// Get a handle to the networks API
	networks := client.Networks()

	// Create a new network
	n := &api.Network{
		Name: "my-new-network",
		IPAddressRange: "10.1.1.0/24"
	}

	id, err := networks.Create(context.Background(), n)
	if err != nil {
		panic(err)
	}

    	...
}

To run this example, start a Drago server:

drago agent --server

Copy the code above into a file such as main.go, and run it.

After running the code, you can also view the values in the Drago UI on your local machine at http://localhost:8080/ui/

Documentation

Index

Constants

View Source
const (
	// DefaultAddress is the default Drago server address.
	DefaultAddress = "http://127.0.0.1:8080"

	// DefaultTimeout is the default request timeout.
	DefaultTimeout = 2 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ACL

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

ACL is a handle to the ACL API

func (*ACL) Bootstrap

func (a *ACL) Bootstrap() (*structs.ACLToken, error)

Boostrap :

type ACLPolicies

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

ACLPolicies is a handle to the ACL policies API

func (*ACLPolicies) Delete

func (p *ACLPolicies) Delete(name string) error

Delete :

func (*ACLPolicies) Get

func (p *ACLPolicies) Get(name string) (*structs.ACLPolicy, error)

Get :

func (*ACLPolicies) List

func (p *ACLPolicies) List() ([]*structs.ACLPolicyListStub, error)

List :

func (*ACLPolicies) Upsert

func (p *ACLPolicies) Upsert(policy *structs.ACLPolicy) (*structs.ACLPolicy, error)

Create :

type ACLTokens

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

ACLTokens is a handle to the ACL tokens API

func (*ACLTokens) Create

func (t *ACLTokens) Create(token *structs.ACLToken) (*structs.ACLToken, error)

Create :

func (*ACLTokens) Delete

func (t *ACLTokens) Delete(id string) error

Delete :

func (*ACLTokens) Get

func (t *ACLTokens) Get(id string) (*structs.ACLToken, error)

Get :

func (*ACLTokens) List

func (t *ACLTokens) List() ([]*structs.ACLTokenListStub, error)

List :

func (*ACLTokens) Self

func (t *ACLTokens) Self() (*structs.ACLToken, error)

Self :

func (*ACLTokens) Update

func (t *ACLTokens) Update(token *structs.ACLToken) (*structs.ACLToken, error)

Update :

type Agent

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

Agent is a handle to the agent API

func (*Agent) Self

func (t *Agent) Self() (*structs.Agent, error)

Self :

type Client

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

Client provides a client to the Drago API

func NewClient

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

NewClient returns a new Drago API client

func (*Client) ACL

func (c *Client) ACL() *ACL

Networks returns a handle on the networks endpoints.

func (*Client) ACLPolicies

func (c *Client) ACLPolicies() *ACLPolicies

ACLPolicies returns a handle on the ACL policies endpoints.

func (*Client) ACLTokens

func (c *Client) ACLTokens() *ACLTokens

ACLTokens returns a handle on the ACL tokens endpoints.

func (*Client) Agent

func (c *Client) Agent() *Agent

Agent returns a handle on the agent endpoints.

func (*Client) Connections

func (c *Client) Connections() *Connections

Connections returns a handle on the connections endpoints.

func (*Client) Interfaces

func (c *Client) Interfaces() *Interfaces

Interfaces returns a handle on the interfaces endpoints.

func (*Client) Networks

func (c *Client) Networks() *Networks

Networks returns a handle on the networks endpoints.

func (*Client) Nodes

func (c *Client) Nodes() *Nodes

Nodes returns a handle on the nodes endpoints.

type CodedError

type CodedError struct {
	Message string
	Code    int
}

func (CodedError) Error

func (e CodedError) Error() string

type Config

type Config struct {
	// URL of the Drago server (e.g. http://127.0.0.1:8080).
	Address string

	// Token to be used for authentication.
	Token string

	// Request timeout.
	Timeout time.Duration
}

Config contains configurations for Drago's API client.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns a default configuration for Drago's API client.

func (*Config) Merge

func (c *Config) Merge(b *Config) *Config

Merge merges two API client configurations.

func (*Config) Validate

func (c *Config) Validate() error

Validate validates the configurations contained wihin the Config struct.

type Connections

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

Connections is a handle to the connection API

func (*Connections) Create

func (n *Connections) Create(connection *structs.Connection) error

func (*Connections) Delete

func (n *Connections) Delete(id string) error

func (*Connections) Get

func (n *Connections) Get(id string) (*structs.Connection, error)

Get :

func (*Connections) List

func (n *Connections) List() ([]*structs.ConnectionListStub, error)

List :

func (*Connections) Update

func (n *Connections) Update(conn *structs.Connection) (*structs.Connection, error)

type Interfaces

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

Interfaces is a handle to the interfaces API

func (*Interfaces) Create

func (n *Interfaces) Create(nodeID, networkID string) (*structs.Interface, error)

Create :

func (*Interfaces) Delete

func (n *Interfaces) Delete(id string) error

Delete :

func (*Interfaces) Get

func (n *Interfaces) Get(id string) (*structs.Interface, error)

Get :

func (*Interfaces) List

func (n *Interfaces) List(filters map[string][]string) ([]*structs.InterfaceListStub, error)

List :

func (*Interfaces) Update

func (n *Interfaces) Update(iface *structs.Interface) (*structs.Interface, error)

Update :

type Networks

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

Networks is a handle to the nodes API

func (*Networks) Create

func (n *Networks) Create(network *structs.Network) error

Create :

func (*Networks) Delete

func (n *Networks) Delete(id string) error

Delete :

func (*Networks) Get

func (n *Networks) Get(id string) (*structs.Network, error)

Get :

func (*Networks) List

func (n *Networks) List() ([]*structs.NetworkListStub, error)

List :

type Nodes

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

Nodes is a handle to the nodes API

func (*Nodes) Get

func (t *Nodes) Get(id string) (*structs.Node, error)

Get :

func (*Nodes) List

func (t *Nodes) List(filters map[string][]string) ([]*structs.NodeListStub, error)

List :

Jump to

Keyboard shortcuts

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