service

package
v0.25.3 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2024 License: Apache-2.0 Imports: 19 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	*edgeVPNClient.Client
	// contains filtered or unexported fields
}

Client is a wrapper of an edgeVPN client with additional metadata and syntax sugar

func NewClient

func NewClient(serviceID string, c *edgeVPNClient.Client) *Client

NewClient returns a new client with an associated service ID

func (Client) ActiveNodes

func (c Client) ActiveNodes() (active []string, err error)

ActiveNodes returns a list of active nodes

func (Client) Advertize

func (c Client) Advertize(uuid string) error

Advertize advertize the given uuid to the ledger

func (Client) AdvertizingNodes added in v0.9.3

func (c Client) AdvertizingNodes() (active []string, err error)

AdvertizingNodes returns a list of advertizing nodes

func (Client) Clean

func (c Client) Clean() error

Clean cleans up the serviceID associated data

func (Client) Get

func (c Client) Get(args ...string) (string, error)

Get returns generic data from the API e.g. get("ip", uuid)

func (Client) ListItems

func (c Client) ListItems(serviceID, suffix string) (strs []string, err error)

ListItems returns list of items associated with the serviceID and the given suffix

func (Client) Set

func (c Client) Set(thing, uuid, value string) error

Set generic data to the API e.g. set("ip", uuid, "value")

type Node

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

Node is the service Node. It have a set of defined available roles which nodes in a network can take. It takes a network token or either generates one

func NewNode

func NewNode(o ...Option) (*Node, error)

NewNode returns a new service Node The service Node can have role applied which are polled by the API. This allows to bootstrap services using the API to coordinate nodes and apply roles afterwards (e.g. start vpn with a dynamically received IP, etc. )

func (*Node) Clean

func (k *Node) Clean()

Clean stops and cleanup a node

func (*Node) Start

func (k *Node) Start(ctx context.Context) error

Start starts the node with the context

func (*Node) Stop

func (k *Node) Stop()

Stop stops a node by calling the stop roles

type Option

type Option func(k *Node) error

Option is a Node option

func WithAPIAddress

func WithAPIAddress(s string) Option

WithAPIAddress sets the EdgeVPN API address

func WithAssets

func WithAssets(assets ...string) Option

WithAssets is a list of assets to copy to a temporary state dir from the embedded FS It is used in conjunction with WithFS to ease out binary embedding

func WithClient

func WithClient(e *Client) Option

WithClient sets a service client

func WithDefaultRoles

func WithDefaultRoles(roles string) Option

WithDefaultRoles allows to set a list of comma separated roles prefixed for the node. Note, by setting this the node will refuse any assigned role

func WithFS

func WithFS(fs embed.FS) Option

WithFS accepts an embed.FS file system where to copy binaries from

func WithLogger

func WithLogger(l log.StandardLogger) Option

WithLogger defines a logger to be used across the whole execution

func WithMinNodes added in v0.19.2

func WithMinNodes(i int) Option

func WithNetworkToken

func WithNetworkToken(token string) Option

WithNetworkToken allows to set a network token. If not set, it is automatically generated

func WithPersistentRoles

func WithPersistentRoles(roles string) Option

WithPersistentRoles allows to set a list of comma separated roles that can is applied persistently

func WithRoles

func WithRoles(k ...RoleKey) Option

WithRoles defines a set of role keys

func WithStateDir

func WithStateDir(s string) Option

WithStateDir sets the node state directory. It will contain the unpacked assets (if any) and the process states generated by the roles.

func WithStopRoles

func WithStopRoles(roles string) Option

WithStopRoles allows to set a list of comma separated roles that can be applied during cleanup

func WithTokenfile

func WithTokenfile(s string) Option

WithTokenfile sets a token file. If a token file and a network token is not found it is written to such file

func WithUUID

func WithUUID(s string) Option

WithUUID sets a node UUID

type ProcessController

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

ProcessController syntax sugar around go-processmanager

func NewProcessController

func NewProcessController(statedir string) *ProcessController

NewProcessController returns a new process controller associated with the state directory

func (*ProcessController) BinaryPath

func (a *ProcessController) BinaryPath(b string) string

BinaryPath returns the binary path of the program requested as argument. The binary path is relative to the process state directory

func (*ProcessController) Process

func (a *ProcessController) Process(state, p string, opts ...process.Option) *process.Process

Process returns a process associated within binaries inside the state dir

func (*ProcessController) Run

func (a *ProcessController) Run(command string, args ...string) (string, error)

Run simply runs a command from a binary in the state directory

type Role

type Role string

Role is a service role. It is identified by a unique string which is sent over the wire and streamed to/from the clients. Roles can be applied either directly, or assigned within roles in the API

func (Role) Apply

func (rr Role) Apply(opts ...RoleOption)

Apply applies a role and takes a list of options

type RoleConfig

type RoleConfig struct {
	Client                                              *Client
	UUID, ServiceID, StateDir, APIAddress, NetworkToken string
	Logger                                              log.StandardLogger
	// contains filtered or unexported fields
}

RoleConfig is the role config structure, which holds all the objects that can be used by a Role

type RoleKey

type RoleKey struct {
	RoleHandler func(c *RoleConfig) error
	Role        Role
}

RoleKey is an association between a Role(string) and a Handler which actually fullfills the role

type RoleOption

type RoleOption func(c *RoleConfig)

RoleOption is a role option

func WithRole

func WithRole(f map[Role]func(c *RoleConfig) error) RoleOption

WithRole sets the available roles

func WithRoleAPIAddress

func WithRoleAPIAddress(s string) RoleOption

WithRoleAPIAddress sets the API Address used during the execution

func WithRoleClient

func WithRoleClient(e *Client) RoleOption

WithRoleClient sets a client for a role

func WithRoleLogger

func WithRoleLogger(l log.StandardLogger) RoleOption

WithRoleLogger sets a logger for the role action

func WithRoleServiceID

func WithRoleServiceID(s string) RoleOption

WithRoleServiceID sets a role service ID

func WithRoleStateDir

func WithRoleStateDir(s string) RoleOption

WithRoleStateDir sets the statedir for the role

func WithRoleToken

func WithRoleToken(s string) RoleOption

WithRoleToken sets the network token which can be used by the role

func WithRoleUUID

func WithRoleUUID(u string) RoleOption

WithRoleUUID sets the UUID which performs the role

Jump to

Keyboard shortcuts

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