client

package
v0.0.0-...-e608a4f Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2025 License: Zlib Imports: 41 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildHTTPClient

func BuildHTTPClient(timeout float64, options *agent.Options) *edgeHTTPClient

Types

type APIClient

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

APIClient is used to execute HTTP requests against the agent API

func NewAPIClient

func NewAPIClient() *APIClient

NewAPIClient returns a pointer to a new APIClient instance

func (*APIClient) GetEdgeKey

func (client *APIClient) GetEdgeKey(serverAddr string) (string, error)

GetEdgeKey executes a KeyInspect operation against the specified server

func (*APIClient) SetEdgeKey

func (client *APIClient) SetEdgeKey(serverAddr, key string) error

SetEdgeKey executes a KeyCreate operation against the specified server

type AsyncCommand

type AsyncCommand struct {
	ID         int                  `json:"id"`
	Type       string               `json:"type"`
	EndpointID portainer.EndpointID `json:"endpointID"`
	Timestamp  time.Time            `json:"timestamp"`
	Operation  string               `json:"op"`
	Path       string               `json:"path"`
	Value      any                  `json:"value"`
}

type AsyncRequest

type AsyncRequest struct {
	CommandTimestamp *time.Time           `json:"commandTimestamp,omitempty"`
	Snapshot         *snapshot            `json:"snapshot,omitempty"`
	EndpointId       portainer.EndpointID `json:"endpointId,omitempty"`
	MetaFields       *MetaFields          `json:"metaFields,omitempty"`
}

type AsyncResponse

type AsyncResponse struct {
	PingInterval     time.Duration `json:"pingInterval"`
	SnapshotInterval time.Duration `json:"snapshotInterval"`
	CommandInterval  time.Duration `json:"commandInterval"`

	EndpointID       portainer.EndpointID `json:"endpointID"`
	Commands         []AsyncCommand       `json:"commands"`
	NeedFullSnapshot bool                 `json:"needFullSnapshot"`
}

type ContainerCommandData

type ContainerCommandData struct {
	ContainerName          string
	ContainerStartOptions  container.StartOptions
	ContainerRemoveOptions container.RemoveOptions
	ContainerOperation     string
}

type DockerSnapshotter

type DockerSnapshotter func(edgeKey string) (*portainer.DockerSnapshot, error)

type EdgeConfig

type EdgeConfig struct {
	ID         EdgeConfigID
	Name       string
	BaseDir    string
	DirEntries []filesystem.DirEntry
	Prev       *EdgeConfig
	Invalid    bool
}

type EdgeConfigID

type EdgeConfigID int

type EdgeConfigStateType

type EdgeConfigStateType int
const (
	EdgeConfigIdleState EdgeConfigStateType = iota
	EdgeConfigFailureState
	EdgeConfigSavingState
	EdgeConfigDeletingState
	EdgeConfigUpdatingState
)

func (EdgeConfigStateType) String

func (e EdgeConfigStateType) String() string

type EdgeJobData

type EdgeJobData struct {
	ID                portainer.EdgeJobID
	CollectLogs       bool
	LogsStatus        portainer.EdgeJobLogsStatus
	CronExpression    string
	ScriptFileContent string
	Version           int
}

type EdgeStackLog

type EdgeStackLog struct {
	EdgeStackID portainer.EdgeStackID `json:"edgeStackID,omitempty"`
	Logs        []EndpointLog         `json:"logs,omitempty"`
	Append      bool                  `json:"append,omitempty"`
}

type EndpointLog

type EndpointLog struct {
	DockerContainerID string `json:"dockerContainerID,omitempty"`
	StdOut            string `json:"stdOut,omitempty"`
	StdErr            string `json:"stdErr,omitempty"`
}

type HelmChartStatusPayload

type HelmChartStatusPayload struct {
	Statuses []portainer.PolicyChartStatus `json:"chartStatuses"`
}

type ImageCommandData

type ImageCommandData struct {
	ImageName          string
	ImageRemoveOptions image.RemoveOptions
	ImageOperation     string
}

type LiveLogCollector

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

func StartNewLiveLogCollector

func StartNewLiveLogCollector(containerName, since, until, tail string) (*LiveLogCollector, error)

func (*LiveLogCollector) Collect

func (c *LiveLogCollector) Collect() ([]byte, []byte, bool)

type LogCommandData

type LogCommandData struct {
	EdgeStackID   portainer.EdgeStackID
	EdgeStackName string
	ContainerID   string
	Tail          int
	Since         string
	Until         string
}

type MetaFields

type MetaFields struct {
	EdgeGroupsIDs      []int `json:"edgeGroupsIds"`
	TagsIDs            []int `json:"tagsIds"`
	EnvironmentGroupID int   `json:"environmentGroupId"`
}

type NonOkResponseError

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

func (*NonOkResponseError) Error

func (e *NonOkResponseError) Error() string

type NormalStackCommandData

type NormalStackCommandData struct {
	Name             string
	StackFileContent string
	StackOperation   string
	RemoveVolumes    bool
}

type Option

type Option func(*options)

func WithDockerSnapshotter

func WithDockerSnapshotter(snapshotter DockerSnapshotter) Option

func WithVersion

func WithVersion(version string) Option

type PollStatusResponse

type PollStatusResponse struct {
	Status               string                               `json:"status"`
	Port                 int                                  `json:"port"`
	Schedules            []agent.Schedule                     `json:"schedules"`
	CheckinInterval      float64                              `json:"checkin"`
	Credentials          string                               `json:"credentials"`
	Stacks               []StackStatus                        `json:"stacks"`
	EdgeConfigurations   map[EdgeConfigID]EdgeConfigStateType `json:"edge_configurations"`
	PolicyChartSummaries []portainer.PolicyChartSummary       `json:"policy_chart_summaries"`

	// Async mode only
	EndpointID       int            `json:"endpointID"`
	PingInterval     time.Duration  `json:"pingInterval"`
	SnapshotInterval time.Duration  `json:"snapshotInterval"`
	CommandInterval  time.Duration  `json:"commandInterval"`
	AsyncCommands    []AsyncCommand `json:"commands"`
}

type PortainerAsyncClient

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

PortainerAsyncClient is used to execute HTTP requests using only the /api/entrypoint/async api endpoint

func NewPortainerAsyncClient

func NewPortainerAsyncClient(
	serverAddress string,
	setEIDFn setEndpointIDFn,
	getEIDFn getEndpointIDFn,
	edgeID string,
	edgeKey string,
	containerPlatform agent.ContainerPlatform,
	metaFields agent.EdgeMetaFields,
	httpClient *edgeHTTPClient,
	opts ...Option,
) *PortainerAsyncClient

NewPortainerAsyncClient returns a pointer to a new PortainerAsyncClient instance

func (*PortainerAsyncClient) DeleteEdgeStackStatus

func (client *PortainerAsyncClient) DeleteEdgeStackStatus(edgeStackID int) error

func (*PortainerAsyncClient) EnqueueLogCollectionForStack

func (client *PortainerAsyncClient) EnqueueLogCollectionForStack(logCmd LogCommandData)

func (*PortainerAsyncClient) GetCharts

GetCharts retrieves the chart contents for the specified charts from the Portainer server

func (*PortainerAsyncClient) GetEdgeConfig

func (client *PortainerAsyncClient) GetEdgeConfig(id EdgeConfigID) (*EdgeConfig, error)

func (*PortainerAsyncClient) GetEdgeStackConfig

func (client *PortainerAsyncClient) GetEdgeStackConfig(edgeStackID int, version *int) (*edge.StackPayload, error)

GetEdgeStackConfig retrieves the configuration associated to an Edge stack

func (*PortainerAsyncClient) GetEnvironmentID

func (client *PortainerAsyncClient) GetEnvironmentID() (portainer.EndpointID, error)

func (*PortainerAsyncClient) GetEnvironmentStatus

func (client *PortainerAsyncClient) GetEnvironmentStatus(flags ...string) (*PollStatusResponse, error)

func (*PortainerAsyncClient) SetEdgeConfigState

func (client *PortainerAsyncClient) SetEdgeConfigState(id EdgeConfigID, state EdgeConfigStateType) error

func (*PortainerAsyncClient) SetEdgeJobStatus

func (client *PortainerAsyncClient) SetEdgeJobStatus(edgeJobStatus agent.EdgeJobStatus) error

SetEdgeJobStatus sends the jobID log to the Portainer server

func (*PortainerAsyncClient) SetEdgeStackStatus

func (client *PortainerAsyncClient) SetEdgeStackStatus(edgeStackID, version int, edgeStackStatus portainer.EdgeStackStatusType, rollbackTo *int, err string) error

SetEdgeStackStatus updates the status of an Edge stack on the Portainer server

func (*PortainerAsyncClient) SetLastCommandTimestamp

func (client *PortainerAsyncClient) SetLastCommandTimestamp(timestamp time.Time)

func (*PortainerAsyncClient) SetPendingCommand

func (client *PortainerAsyncClient) SetPendingCommand(id portainer.EdgeStackID, version int, timestamp time.Time)

SetPendingCommand stores the latest command timestamp for a given stack ID

func (*PortainerAsyncClient) SetTimeout

func (client *PortainerAsyncClient) SetTimeout(t time.Duration)

func (*PortainerAsyncClient) UpdatePolicyChartStatuses

func (client *PortainerAsyncClient) UpdatePolicyChartStatuses(statuses []portainer.PolicyChartStatus) error

type PortainerClient

type PortainerClient interface {
	GetEnvironmentID() (portainer.EndpointID, error)
	GetEnvironmentStatus(flags ...string) (*PollStatusResponse, error)
	GetEdgeStackConfig(edgeStackID int, version *int) (*edge.StackPayload, error)
	SetEdgeStackStatus(edgeStackID, version int, edgeStackStatus portainer.EdgeStackStatusType, rollbackTo *int, errMessage string) error
	SetEdgeJobStatus(edgeJobStatus agent.EdgeJobStatus) error
	GetEdgeConfig(id EdgeConfigID) (*EdgeConfig, error)
	SetEdgeConfigState(id EdgeConfigID, state EdgeConfigStateType) error
	SetTimeout(t time.Duration)
	SetLastCommandTimestamp(timestamp time.Time)
	EnqueueLogCollectionForStack(logCmd LogCommandData)
	GetCharts(chartNames []string) ([]portainer.PolicyChartBundle, portainer.RestoreSettingsBundle, error)
	UpdatePolicyChartStatuses(statuses []portainer.PolicyChartStatus) error
}

func NewPortainerClient

func NewPortainerClient(serverAddress string, setEIDFn setEndpointIDFn, getEIDFn getEndpointIDFn, edgeID string, edgeKey string, edgeAsyncMode bool, agentPlatform agent.ContainerPlatform, metaFields agent.EdgeMetaFields, httpClient *edgeHTTPClient) PortainerClient

NewPortainerClient returns a pointer to a new PortainerClient instance

type PortainerEdgeClient

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

PortainerEdgeClient is used to execute HTTP requests against the Portainer API

func NewPortainerEdgeClient

func NewPortainerEdgeClient(
	serverAddress string,
	setEIDFn setEndpointIDFn,
	getEIDFn getEndpointIDFn,
	edgeID string,
	agentPlatform agent.ContainerPlatform,
	metaFields agent.EdgeMetaFields,
	httpClient *edgeHTTPClient,
	opts ...Option,
) *PortainerEdgeClient

NewPortainerEdgeClient returns a pointer to a new PortainerEdgeClient instance

func (*PortainerEdgeClient) EnqueueLogCollectionForStack

func (client *PortainerEdgeClient) EnqueueLogCollectionForStack(logCmd LogCommandData)

func (*PortainerEdgeClient) GetCharts

GetCharts retrieves the chart contents for the specified charts from the Portainer server

func (*PortainerEdgeClient) GetEdgeConfig

func (client *PortainerEdgeClient) GetEdgeConfig(id EdgeConfigID) (*EdgeConfig, error)

func (*PortainerEdgeClient) GetEdgeStackConfig

func (client *PortainerEdgeClient) GetEdgeStackConfig(edgeStackID int, version *int) (*edge.StackPayload, error)

GetEdgeStackConfig retrieves the configuration associated to an Edge stack

func (*PortainerEdgeClient) GetEnvironmentID

func (client *PortainerEdgeClient) GetEnvironmentID() (portainer.EndpointID, error)

func (*PortainerEdgeClient) GetEnvironmentStatus

func (client *PortainerEdgeClient) GetEnvironmentStatus(flags ...string) (*PollStatusResponse, error)

func (*PortainerEdgeClient) ProcessAsyncCommands

func (client *PortainerEdgeClient) ProcessAsyncCommands() error

func (*PortainerEdgeClient) SetEdgeConfigState

func (client *PortainerEdgeClient) SetEdgeConfigState(id EdgeConfigID, state EdgeConfigStateType) error

func (*PortainerEdgeClient) SetEdgeJobStatus

func (client *PortainerEdgeClient) SetEdgeJobStatus(edgeJobStatus agent.EdgeJobStatus) error

SetEdgeJobStatus sends the jobID log to the Portainer server

func (*PortainerEdgeClient) SetEdgeStackStatus

func (client *PortainerEdgeClient) SetEdgeStackStatus(
	edgeStackID, version int,
	edgeStackStatus portainer.EdgeStackStatusType,
	rollbackTo *int,
	error string,
) error

SetEdgeStackStatus updates the status of an Edge stack on the Portainer server

func (*PortainerEdgeClient) SetLastCommandTimestamp

func (client *PortainerEdgeClient) SetLastCommandTimestamp(timestamp time.Time)

func (*PortainerEdgeClient) SetTimeout

func (client *PortainerEdgeClient) SetTimeout(t time.Duration)

func (*PortainerEdgeClient) UpdatePolicyChartStatuses

func (client *PortainerEdgeClient) UpdatePolicyChartStatuses(statuses []portainer.PolicyChartStatus) error

type StackStatus

type StackStatus struct {
	ID               int
	Version          int
	Name             string // used in async mode
	CommandOperation string // used in async mode
	// ForceRedeploy is used to indicate that the stack should be redeployed
	// even if the version is the same this value is set by the server
	ForceRedeploy bool
	// RepullImage is used to indicate that the image should be re-pulled
	// during the next deployment of the stack
	RePullImage bool
}

type VolumeCommandData

type VolumeCommandData struct {
	VolumeName      string
	ForceRemove     bool
	VolumeOperation string
}

Jump to

Keyboard shortcuts

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