Help us shape the future of Go! Take the 2026 Go Developer Survey

portainer

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package portainer is the Portainer API backend. TLS trust is exactly one of a CA file or a pinned certificate fingerprint (decided at config load); there is no insecure mode. Git-backed stacks are never updated directly — Proposals go through Git.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Adapter

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

Adapter is the Portainer backend.

func New

func New(options Options) (*Adapter, error)

New builds an Adapter, reading and validating the API key file.

func (*Adapter) CurrentUsername

func (a *Adapter) CurrentUsername() (string, error)

CurrentUsername returns the username the API key authenticates as.

func (*Adapter) ImageStatus

func (a *Adapter) ImageStatus(stackID int) (string, error)

ImageStatus returns the stack's image status, lowercased.

func (*Adapter) ListStacks

func (a *Adapter) ListStacks() ([]Stack, error)

ListStacks lists all stacks, marking Git-backed ones.

func (*Adapter) ServiceImageDigests

func (a *Adapter) ServiceImageDigests(stack Stack) (map[string]string, error)

ServiceImageDigests maps each running service of the stack's compose project to its image digest. Only running containers of the stack's own project are ever queried — never the whole host.

func (*Adapter) StackFile

func (a *Adapter) StackFile(stackID int) (string, error)

StackFile returns the live compose file content of a stack.

func (*Adapter) UpdateStack

func (a *Adapter) UpdateStack(stack Stack, compose string, env []EnvVar, repull bool) error

UpdateStack redeploys a stack with new compose content. Git-backed stacks are refused before any HTTP traffic — they deploy through Git.

type Backend

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

Backend adapts the Portainer API to the orchestrator port.

func NewBackend

func NewBackend(adapter *Adapter, expectedUsername string) *Backend

NewBackend wraps an Adapter as a backend port. The expected username is the identity every run is checked against before it touches anything.

func (*Backend) Deploy

func (b *Backend) Deploy(state backend.StackState, compose string, repull bool) error

Deploy redeploys the stack with new Compose content, keeping its environment exactly as Portainer holds it.

func (*Backend) Observe

func (b *Backend) Observe(stack config.StackPolicy) (backend.StackState, error)

Observe reads one stack: its Compose document, its services, and either the digests running or Portainer's own image-status verdict.

func (*Backend) Preflight

func (b *Backend) Preflight() error

Preflight refuses to run at all under the wrong Portainer identity. This is not a per-stack problem: a key that authenticates as someone else can see and change things the reviewed policy never described.

func (*Backend) RunningDigests

func (b *Backend) RunningDigests(state backend.StackState) (map[string]string, error)

RunningDigests re-reads the digests the stack's compose project runs.

func (*Backend) ServicesRunning

func (b *Backend) ServicesRunning(backend.StackState) (bool, string, error)

ServicesRunning is always satisfied for Portainer: the API exposes no per-service liveness beyond the digest discovery an apply already does, so the functional health checks are the whole verification here.

func (*Backend) WithContext added in v1.2.0

func (b *Backend) WithContext(ctx context.Context) backend.Port

WithContext returns a backend bound to the caller lifetime.

type EnvVar

type EnvVar struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

EnvVar is one stack environment variable, in Portainer's wire shape.

type HTTPError

type HTTPError struct {
	Status int
	Detail string
}

HTTPError is a non-2xx Portainer API response.

func (*HTTPError) Error

func (e *HTTPError) Error() string

type Options

type Options struct {
	BaseURL           string
	APIKeyFile        string
	CAFile            string
	FingerprintSHA256 string
	Timeout           time.Duration
	UpdateTimeout     time.Duration
}

Options configures an Adapter.

type Stack

type Stack struct {
	ID         int
	EndpointID int
	Name       string
	Status     int
	Env        []EnvVar
	GitBacked  bool
}

Stack is one Portainer stack as listed by the API.

Jump to

Keyboard shortcuts

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