client

package
v0.0.0-...-ac62dae Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2019 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ResourceContainer represents a Docker resource of type container
	ResourceContainer = ResourceType("container")

	// ResourceService represents a Docker resource of type service
	ResourceService = ResourceType("service")

	// ResourceVolume represents a Docker resource of type volume
	ResourceVolume = ResourceType("volume")

	// ResourceNetwork represents a Docker resource of type network
	ResourceNetwork = ResourceType("network")

	// ResourceSecret represents a Docker resource of type secret
	ResourceSecret = ResourceType("secret")

	// ResourceConfig represents a Docker resource of type config
	ResourceConfig = ResourceType("config")

	// ResourceStack represents a Portainer resource of type stack
	// A Portainer stack is pretty much like a Docker stack, but not the same
	ResourceStack = ResourceType("stack")
)

Variables

This section is empty.

Functions

func GetTranslatedStackType

func GetTranslatedStackType(t portainer.StackType) string

GetTranslatedStackType returns a stack's Type field (int) translated to it's human readable form (string)

Types

type AuthenticateUserOptions

type AuthenticateUserOptions struct {
	Username string
	Password string
}

AuthenticateUserOptions represents options passed to PortainerClient.AuthenticateUser()

type AuthenticateUserRequest

type AuthenticateUserRequest struct {
	Username string
	Password string
}

AuthenticateUserRequest represents the body of a request to POST /auth

type AuthenticateUserResponse

type AuthenticateUserResponse struct {
	Jwt string
}

AuthenticateUserResponse represents the body of a response for a request to POST /auth

type Config

type Config struct {
	URL           *url.URL
	User          string
	Password      string
	Token         string
	UserAgent     string
	DoNotUseToken bool
}

Config represents a Portainer client configuration

type GenericError

type GenericError struct {
	Code    int
	Err     string
	Details string
}

GenericError represents the body of a generic error returned by the Portainer API

func (GenericError) Error

func (e GenericError) Error() string

type PortainerClient

type PortainerClient interface {
	// AuthenticateUser a user to get an auth token
	AuthenticateUser(options AuthenticateUserOptions) (token string, err error)

	// Get endpoints
	EndpointList() ([]portainer.Endpoint, error)

	// Get endpoint groups
	EndpointGroupList() ([]portainer.EndpointGroup, error)

	// Get stacks, optionally filtered by swarmId and endpointId
	StackList(options StackListOptions) ([]portainer.Stack, error)

	// Create swarm stack
	StackCreateSwarm(options StackCreateSwarmOptions) (stack portainer.Stack, err error)

	// Create compose stack
	StackCreateCompose(options StackCreateComposeOptions) (stack portainer.Stack, err error)

	// Update stack
	StackUpdate(options StackUpdateOptions) error

	// Delete stack
	StackDelete(stackID portainer.StackID) error

	// Get stack file content
	StackFileInspect(stackID portainer.StackID) (content string, err error)

	// Get endpoint Docker info
	EndpointDockerInfo(endpointID portainer.EndpointID) (info map[string]interface{}, err error)

	// Get Portainer status info
	Status() (portainer.Status, error)

	// Run a function before sending a request to Portainer
	BeforeRequest(hook func(req *http.Request) (err error))

	// Run a function after receiving a response from Portainer
	AfterResponse(hook func(resp *http.Response) (err error))

	// Proxy proxies a request to /endpoint/{id}/docker and returns its result
	Proxy(endpointID portainer.EndpointID, req *http.Request) (resp *http.Response, err error)

	// ResourceControlCreate creates a resource control
	ResourceControlCreate(options ResourceControlCreateOptions) (resourceControl portainer.ResourceControl, err error)

	// ResourceControlUpdate updates a resource control
	ResourceControlUpdate(options ResourceControlUpdateOptions) (resourceControl portainer.ResourceControl, err error)

	// ResourceControlDelete deletes a resource control
	ResourceControlDelete(resourceControlID portainer.ResourceControlID) (err error)

	// UserList retrieves a list of users
	UserList() (users []portainer.User, err error)

	// GetUsername returns the user name used by the client
	GetUsername() string

	// DoJSONWithToken makes an HTTP request with a JSON body and an auth token
	DoJSONWithToken(uri, method string, headers http.Header, request interface{}, response interface{}) (err error)
}

PortainerClient represents a Portainer API client

func NewClient

func NewClient(httpClient *http.Client, config Config) PortainerClient

NewClient creates a new Portainer API client

type ResourceControlCreateOptions

type ResourceControlCreateOptions struct {
	ResourceID     string
	Type           ResourceType
	Public         bool
	Users          []portainer.UserID
	Teams          []portainer.TeamID
	SubResourceIDs []string
}

ResourceControlCreateOptions represents options passed to PortainerClient.ResourceControlCreate()

type ResourceControlCreateRequest

type ResourceControlCreateRequest struct {
	ResourceID     string
	Type           ResourceType
	Public         bool               `json:",omitempty"`
	Users          []portainer.UserID `json:",omitempty"`
	Teams          []portainer.TeamID `json:",omitempty"`
	SubResourceIDs []string           `json:",omitempty"`
}

ResourceControlCreateRequest represents the body of a request to POST /resource_controls

type ResourceControlUpdateOptions

type ResourceControlUpdateOptions struct {
	ID     portainer.ResourceControlID
	Public bool
	Users  []portainer.UserID
	Teams  []portainer.TeamID
}

ResourceControlUpdateOptions represents options passed to PortainerClient.ResourceControlUpdate()

type ResourceControlUpdateRequest

type ResourceControlUpdateRequest struct {
	Public bool               `json:",omitempty"`
	Users  []portainer.UserID `json:",omitempty"`
	Teams  []portainer.TeamID `json:",omitempty"`
}

ResourceControlUpdateRequest represents the body of a request to PUT /resource_controls/{id}

type ResourceType

type ResourceType string

ResourceType represents a type of Docker or Portainer resource

type StackCreateComposeOptions

type StackCreateComposeOptions struct {
	StackName            string
	EnvironmentVariables []portainer.Pair
	StackFileContent     string
	EndpointID           portainer.EndpointID
}

StackCreateComposeOptions represents options passed to PortainerClient.StackCreateCompose()

type StackCreateRequest

type StackCreateRequest struct {
	Name             string
	SwarmID          string
	StackFileContent string
	Env              []portainer.Pair `json:",omitempty"`
}

StackCreateRequest represents the body of a request to POST /stacks

type StackCreateSwarmOptions

type StackCreateSwarmOptions struct {
	StackName            string
	EnvironmentVariables []portainer.Pair
	StackFileContent     string
	SwarmClusterID       string
	EndpointID           portainer.EndpointID
}

StackCreateSwarmOptions represents options passed to PortainerClient.StackCreateSwarm()

type StackFileInspectResponse

type StackFileInspectResponse struct {
	StackFileContent string
}

StackFileInspectResponse represents the body of a response for a request to GET /stack/{id}/file

type StackListFilter

type StackListFilter struct {
	SwarmID    string               `json:"SwarmId,omitempty"`
	EndpointID portainer.EndpointID `json:"EndpointId,omitempty"`
}

StackListFilter represents a filter for a stack list

type StackListOptions

type StackListOptions struct {
	Filter StackListFilter
}

StackListOptions represents options passed to PortainerClient.StackList()

type StackUpdateOptions

type StackUpdateOptions struct {
	Stack                portainer.Stack
	EnvironmentVariables []portainer.Pair
	StackFileContent     string
	Prune                bool
	EndpointID           portainer.EndpointID
}

StackUpdateOptions represents options passed to PortainerClient.StackUpdate()

type StackUpdateRequest

type StackUpdateRequest struct {
	StackFileContent string
	Env              []portainer.Pair `json:",omitempty"`
	Prune            bool
}

StackUpdateRequest represents the body of a request to PUT /stacks/{id}

Jump to

Keyboard shortcuts

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