client

package
v2.31.2 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2025 License: MIT Imports: 21 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientOption

type ClientOption func(*clientOptions)

ClientOption defines a functional option for configuring the Portainer client

func WithBasePath

func WithBasePath(basePath string) ClientOption

WithBasePath sets the base path for the Portainer client

func WithScheme

func WithScheme(scheme string) ClientOption

WithScheme sets the scheme (http/https) for the Portainer client

func WithSkipTLSVerify

func WithSkipTLSVerify(skip bool) ClientOption

WithSkipTLSVerify enables or disables TLS verification

type PortainerClient

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

PortainerClient provides a simplified interface to the Portainer API client that uses API token authentication for all operations

func NewPortainerClient

func NewPortainerClient(host, apiKey string, opts ...ClientOption) *PortainerClient

NewPortainerClient creates a new Portainer client with required parameters and optional configuration Host and apiKey are required, while other settings can be customized through options

func (*PortainerClient) AddEnvironmentToEndpointGroup

func (c *PortainerClient) AddEnvironmentToEndpointGroup(groupId int64, environmentId int64) error

AddEnvironmentToEndpointGroup adds an environment to an endpoint group

func (*PortainerClient) CreateEdgeDockerEndpoint

func (c *PortainerClient) CreateEdgeDockerEndpoint(name string) (int64, error)

CreateEdgeDockerEndpoint creates a new edge docker endpoint

Parameters:

  • name: The name of the endpoint

Returns the ID of the created endpoint and an error if the creation fails

func (*PortainerClient) CreateEdgeGroup

func (c *PortainerClient) CreateEdgeGroup(name string, environmentIds []int64) (int64, error)

CreateEdgeGroup creates a new edge group

func (*PortainerClient) CreateEdgeStack

func (c *PortainerClient) CreateEdgeStack(name string, file string, environmentGroupIds []int64) (int64, error)

CreateEdgeStack creates a new edge stack

func (*PortainerClient) CreateEndpointGroup

func (c *PortainerClient) CreateEndpointGroup(name string, associatedEndpoints []int64) (int64, error)

CreateEndpointGroup creates a new endpoint group

func (*PortainerClient) CreateLocalDockerEndpoint

func (c *PortainerClient) CreateLocalDockerEndpoint(name string) (int64, error)

CreateLocalDockerEndpoint creates a new local Docker endpoint

Parameters:

  • name: The name of the endpoint

Returns the ID of the created endpoint and an error if the creation fails

func (*PortainerClient) CreateTag

func (c *PortainerClient) CreateTag(name string) (int64, error)

CreateTag creates a new tag

func (*PortainerClient) CreateTeam

func (c *PortainerClient) CreateTeam(name string) (int64, error)

CreateTeam creates a new team.

Parameters:

  • name: The name of the team

func (*PortainerClient) CreateTeamMembership

func (c *PortainerClient) CreateTeamMembership(teamId int, userId int) error

CreateTeamMembership creates a team membership.

Parameters:

  • teamId: The ID of the team to create the membership for
  • userId: The ID of the user to add to the team

func (*PortainerClient) CreateUser

func (c *PortainerClient) CreateUser(username, password string, role int64) (int64, error)

CreateUser creates a new user.

func (*PortainerClient) DeleteTeamMembership

func (c *PortainerClient) DeleteTeamMembership(id int) error

DeleteTeamMembership deletes a team membership.

Parameters:

  • id: The ID of the team membership to delete

func (*PortainerClient) GetEdgeGroup

GetEdgeGroup returns the first edge group that matches the specified ID Note that this operation do not leverage the edge_groups.EdgeGroupInspect operation because it returns a different object.

func (*PortainerClient) GetEdgeGroupByName

func (c *PortainerClient) GetEdgeGroupByName(name string) (*models.EdgegroupsDecoratedEdgeGroup, error)

GetEdgeGroupByName returns the first edge group that matches the specified name

func (*PortainerClient) GetEdgeStack

func (c *PortainerClient) GetEdgeStack(id int64) (*models.PortainereeEdgeStack, error)

GetEdgeStack returns an edge stack by ID

func (*PortainerClient) GetEdgeStackByName

func (c *PortainerClient) GetEdgeStackByName(name string) (*models.PortainereeEdgeStack, error)

GetEdgeStackByName returns the first edge stack that matches the specified name

func (*PortainerClient) GetEdgeStackFile

func (c *PortainerClient) GetEdgeStackFile(id int64) (string, error)

GetEdgeStackFile gets the file for an edge stack

func (*PortainerClient) GetEndpoint

func (c *PortainerClient) GetEndpoint(id int64) (*models.PortainereeEndpoint, error)

GetEndpoint gets a specific endpoint by ID

func (*PortainerClient) GetEndpointGroup

func (c *PortainerClient) GetEndpointGroup(id int64) (*models.PortainerEndpointGroup, error)

GetEndpointGroup returns an endpoint group by ID

func (*PortainerClient) GetEndpointGroupByName

func (c *PortainerClient) GetEndpointGroupByName(name string) (*models.PortainerEndpointGroup, error)

GetEndpointGroupByName returns the first endpoint group that matches the specified name

func (*PortainerClient) GetSettings

func (c *PortainerClient) GetSettings() (*models.PortainereeSettings, error)

GetSettings retrieves the Portainer settings

func (*PortainerClient) GetSystemStatus

GetSystemStatus returns the system status

func (*PortainerClient) GetTagByName

func (c *PortainerClient) GetTagByName(name string) (*models.PortainerTag, error)

GetTagByName returns the first tag that matches the specified name

func (*PortainerClient) GetTeam

func (c *PortainerClient) GetTeam(id int64) (*models.PortainerTeam, error)

GetTeam returns a team by ID

func (*PortainerClient) GetTeamByName

func (c *PortainerClient) GetTeamByName(name string) (*models.PortainerTeam, error)

GetTeamByName returns the first team that matches the specified name

func (*PortainerClient) GetUser

func (c *PortainerClient) GetUser(id int) (*models.PortainereeUser, error)

GetUser returns a user by ID

func (*PortainerClient) GetVersion

func (c *PortainerClient) GetVersion() (string, error)

GetVersion returns the version of the Portainer API

func (*PortainerClient) ListEdgeGroups

func (c *PortainerClient) ListEdgeGroups() ([]*models.EdgegroupsDecoratedEdgeGroup, error)

ListEdgeGroups lists all edge groups

func (*PortainerClient) ListEdgeStacks

func (c *PortainerClient) ListEdgeStacks() ([]*models.PortainereeEdgeStack, error)

ListEdgeStacks lists all edge stacks

func (*PortainerClient) ListEndpointGroups

func (c *PortainerClient) ListEndpointGroups() ([]*models.PortainerEndpointGroup, error)

ListEndpointGroups lists all endpoint groups

func (*PortainerClient) ListEndpoints

func (c *PortainerClient) ListEndpoints() ([]*models.PortainereeEndpoint, error)

ListEndpoints lists all endpoints

func (*PortainerClient) ListLicenses added in v2.30.0

func (c *PortainerClient) ListLicenses() ([]*models.LiblicensePortainerLicense, error)

ListLicenses lists all licenses

func (*PortainerClient) ListTags

func (c *PortainerClient) ListTags() ([]*models.PortainerTag, error)

ListTags lists all tags

func (*PortainerClient) ListTeamMemberships

func (c *PortainerClient) ListTeamMemberships() ([]*models.PortainerTeamMembership, error)

ListTeamMemberships lists all team memberships

func (*PortainerClient) ListTeams

func (c *PortainerClient) ListTeams() ([]*models.PortainerTeam, error)

ListTeams lists all teams

func (*PortainerClient) ListUsers

func (c *PortainerClient) ListUsers() ([]*models.PortainereeUser, error)

ListUsers lists all users

func (*PortainerClient) ProxyDockerRequest

func (c *PortainerClient) ProxyDockerRequest(environmentId int, opts ProxyRequestOptions) (*http.Response, error)

ProxyDockerRequest proxies a request to the Docker API via the Portainer API using the provided options.

Parameters:

  • environmentId: The ID of the target Docker environment in Portainer
  • opts: Options defining the proxied request (method, path, query params, headers, body)

Returns:

  • *http.Response: The response from the Docker API
  • error: Any error that occurred during the request

func (*PortainerClient) ProxyKubernetesRequest

func (c *PortainerClient) ProxyKubernetesRequest(environmentId int, opts ProxyRequestOptions) (*http.Response, error)

ProxyKubernetesRequest proxies a request to the Kubernetes API via the Portainer API using the provided options.

Parameters:

  • environmentId: The ID of the target Kubernetes environment in Portainer
  • opts: Options defining the proxied request (method, path, query params, headers, body)

Returns:

  • *http.Response: The response from the Kubernetes API
  • error: Any error that occurred during the request

func (*PortainerClient) RemoveEnvironmentFromEndpointGroup

func (c *PortainerClient) RemoveEnvironmentFromEndpointGroup(groupId int64, environmentId int64) error

RemoveEnvironmentFromEndpointGroup removes an environment from an endpoint group

func (*PortainerClient) UpdateEdgeGroup

func (c *PortainerClient) UpdateEdgeGroup(id int64, name *string, environmentIds *[]int64, tagIds *[]int64) error

UpdateEdgeGroup updates an existing edge group.

Parameters:

  • id: The ID of the edge group to update
  • name: Optional. If provided, updates the name of the edge group. Use nil to keep existing name
  • environmentIds: Optional. If provided, updates the environments associated with the group. Use nil to keep existing environments
  • tagIds: Optional. If provided, updates the tags associated with the group. Use nil to keep existing tags

Returns an error if the update fails.

func (*PortainerClient) UpdateEdgeStack

func (c *PortainerClient) UpdateEdgeStack(id int64, file string, environmentGroupIds []int64) error

UpdateEdgeStack updates an existing edge stack

func (*PortainerClient) UpdateEndpoint

func (c *PortainerClient) UpdateEndpoint(id int64, tagIds *[]int64, userAccesses *map[int64]string, teamAccesses *map[int64]string) error

UpdateEndpoint updates an existing endpoint in Portainer. An endpoint represents a Docker environment that Portainer can manage.

Parameters:

  • id: The ID of the endpoint to update
  • tagIds: Optional. If provided (including empty slice), updates the endpoint's tags. Use nil to keep existing tags. Slice of tag IDs to associate with the endpoint.
  • userAccesses: Optional. If provided (including empty map), updates user access policies. Use nil to keep existing policies. Map of user ID to role name.
  • teamAccesses: Optional. If provided (including empty map), updates team access policies. Use nil to keep existing policies. Map of team ID to role name.

Valid roles for access policies are:

  • environment_administrator
  • helpdesk_user
  • standard_user
  • readonly_user
  • operator_user

Invalid roles are ignored. Returns an error if the update fails.

func (*PortainerClient) UpdateEndpointGroup

func (c *PortainerClient) UpdateEndpointGroup(id int64, name *string, userAccesses *map[int64]string, teamAccesses *map[int64]string) error

UpdateEndpointGroup updates an existing endpoint group.

Parameters:

  • id: The ID of the endpoint group to update
  • name: Optional. If provided, updates the group name. Use nil to keep existing name
  • userAccesses: Optional. If provided (including empty map), updates user access policies. Use nil to keep existing policies. Map of user ID to role name.
  • teamAccesses: Optional. If provided (including empty map), updates team access policies. Use nil to keep existing policies. Map of team ID to role name.

Valid roles for access policies are:

  • environment_administrator
  • helpdesk_user
  • standard_user
  • readonly_user
  • operator_user

Invalid roles are ignored. Returns an error if the update fails.

func (*PortainerClient) UpdateSettings

func (c *PortainerClient) UpdateSettings(enableEdgeComputeFeatures bool, edgePortainerURL, tunnelServerAddress string) error

UpdateSettings updates the Portainer settings

func (*PortainerClient) UpdateTeamName

func (c *PortainerClient) UpdateTeamName(id int, name string) error

UpdateTeamName updates the name of a team.

Parameters:

  • id: The ID of the team to update
  • name: The new name for the team

func (*PortainerClient) UpdateUserRole

func (c *PortainerClient) UpdateUserRole(id int, role int64) error

UpdateUserRole updates the role of a user.

type ProxyClient

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

ProxyClient provides a wrapper around the http.Client that is used to proxy requests via the Portainer API

type ProxyRequestOptions

type ProxyRequestOptions struct {
	// Method is the HTTP method to use (GET, POST, PUT, DELETE, etc.)
	Method string
	// APIPath is the API endpoint path to proxy to (e.g., "/containers/json" or "/api/v1/namespaces/default/pods"). Must include the leading slash.
	APIPath string
	// QueryParams is a map of query parameters to include in the request URL (can be nil)
	QueryParams map[string]string
	// Headers is a map of headers to include in the request (can be nil)
	Headers map[string]string
	// Body is the request body to send (can be nil for requests that don't have a body)
	Body io.Reader
}

ProxyRequestOptions bundles the parameters for an API (Docker, Kubernetes, etc.) proxy request.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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