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

integration

package module
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: ISC Imports: 18 Imported by: 0

README

Integration SDK

Go Reference

Here you'll find the SDKs for all Plakar integrations.

Core concepts:

  • every Plakar integration is a standalone binary;
  • communications happens via GRPC;
  • Plakar acts as a client, and the integration as a Server;
  • integrations can be written in any language in theory, in practice only the Go binding are officially provided.

The layout is as follows:

  • the root contains just the integrations interfaces and ancillary types

  • proto/ contains the protobuf definition and the generated Go code. If you intend to write integrations in other language, you can start generating the server component for your target language using these.

  • server/ contains the machinery for an integration to talk with plakar. All integrations should import this package and use either the Entrypoint*() or Run*On() functions family.

  • client/ contains the machinery to talk with an integration, i.e. the plakar side. Development-aid tools also will use this.

  • cmd/ contains some helpers to run integrations for development purposes.

  • example/ contains an example inventory.

Documentation

Index

Constants

View Source
const (
	ResourceClassUndefined     ResourceClass = ""
	ResourceClassUnknown       ResourceClass = "unknown"
	ResourceClassAnalytics     ResourceClass = "analytics"
	ResourceClassBlockStorage  ResourceClass = "block-storage"
	ResourceClassCompute       ResourceClass = "compute"
	ResourceClassDatabase      ResourceClass = "database"
	ResourceClassFileStorage   ResourceClass = "file-storage"
	ResourceClassHypervisor    ResourceClass = "hypervisor"
	ResourceClassIdentity      ResourceClass = "identity"
	ResourceClassMessaging     ResourceClass = "messaging"
	ResourceClassNetwork       ResourceClass = "network"
	ResourceClassObjectStorage ResourceClass = "object-storage"
	ResourceClassObservability ResourceClass = "observability"
	ResourceClassRegistry      ResourceClass = "registry"
	ResourceClassSecurity      ResourceClass = "security"
	ResourceClassService       ResourceClass = "service"

	ResourceSubClassUndefined     ResourceSubClass = ""
	ResourceSubClassUnknown       ResourceSubClass = "unknown"
	ResourceSubClassAzBlob        ResourceSubClass = "azblob"
	ResourceSubClassFTP           ResourceSubClass = "ftp"
	ResourceSubClassGCS           ResourceSubClass = "gcs"
	ResourceSubClassIMAP          ResourceSubClass = "imap"
	ResourceSubClassMongoDB       ResourceSubClass = "mongodb"
	ResourceSubClassMySQL         ResourceSubClass = "mysql"
	ResourceSubClassPVC           ResourceSubClass = "pvc"
	ResourceSubClassPostgreSQL    ResourceSubClass = "postgresql"
	ResourceSubClassProxmox       ResourceSubClass = "proxmox"
	ResourceSubClassRedis         ResourceSubClass = "redis"
	ResourceSubClassS3            ResourceSubClass = "s3"
	ResourceSubClassSecretManager ResourceSubClass = "secret-manager"
	ResourceSubClassSFTP          ResourceSubClass = "sftp"
	ResourceSubClassVMware        ResourceSubClass = "vmware"

	ConnectorTypeImporter       ConnectorType = "importer"
	ConnectorTypeExporter       ConnectorType = "exporter"
	ConnectorTypeStorage        ConnectorType = "storage"
	ConnectorTypeSecretProvider ConnectorType = "secret_provider"
	ConnectorTypeInventory      ConnectorType = "inventory"
)

Variables

View Source
var (
	ErrInvalidEndpoint     = errors.New("invalid endpoint")
	ErrConnectorMismatch   = errors.New("cannot update connector type")
	ErrUnknownEndpointType = errors.New("unknown endpoint type")
	ErrDisabledSync        = errors.New("disabled sync")
)

Functions

func GetClassTree

func GetClassTree() map[ResourceClass][]ResourceSubClass

func ParseFileInfoSortKeys added in v1.1.2

func ParseFileInfoSortKeys(sortKeysStr string) ([]string, error)

func SortFileInfos added in v1.1.2

func SortFileInfos(infos []FileInfo, sortKeys []string) error

func WithFlag added in v1.1.2

func WithFlag(ctx context.Context, flag StorageFlag) context.Context

Types

type Attribute added in v1.1.2

type Attribute uint8
const (
	AttributeExtended Attribute = 0
	AttributeADS      Attribute = 1
	AttributeCustom   Attribute = 2
)

type ConnectorType

type ConnectorType string

func (ConnectorType) IsValid

func (c ConnectorType) IsValid() bool

type Country

type Country string

Country is where a resource physically sits, as an ISO 3166-1 alpha-2 code. It is an observation, not a rule: whether data is allowed to be there is the control plane's question, not the integration's.

Empty means we cannot tell -- correct for an SFTP host or a local filesystem. It never means "same as the inventory": nothing is inferred from anything else.

func CountryOf

func CountryOf(code string) Country

CountryOf normalizes a code, returning "" for anything that is not one. Use it on the way out so an unmapped region becomes "unknown" rather than a bad code.

The shape is checked rather than the code looked up in a list of countries: that list changes, and an integration somewhere we have not heard of should not wait for an SDK release.

type EndpointType

type EndpointType string
const (
	EndpointUndefined  EndpointType = ""
	EndpointHost       EndpointType = "host"
	EndpointInet4      EndpointType = "inet4"
	EndpointInet6      EndpointType = "inet6"
	EndpointUUID       EndpointType = "uuid"
	EndpointNetwork    EndpointType = "network"
	EndpointIdentifier EndpointType = "identifier"
)

func EndpointTypeFromString

func EndpointTypeFromString(t string) (EndpointType, error)

type Exporter added in v1.1.2

type Exporter interface {
	Origin() string
	Type() string
	Root() string
	Flags() location.Flags
	Ping(context.Context) error
	Export(context.Context, <-chan *Record, chan<- *Result) error
	Close(context.Context) error
}

type ExporterFn added in v1.1.2

type ExporterFn func(context.Context, *Options, string, map[string]string) (Exporter, error)

type FileInfo added in v1.1.2

type FileInfo struct {
	Lname      string      `json:"name" msgpack:"name"`
	Lsize      int64       `json:"size" msgpack:"size"`
	Lmode      fs.FileMode `json:"mode" msgpack:"mode"`
	LmodTime   time.Time   `json:"mod_time" msgpack:"mod_time"`
	Ldev       uint64      `json:"dev" msgpack:"dev"`
	Lino       uint64      `json:"ino" msgpack:"ino"`
	Luid       uint64      `json:"uid" msgpack:"uid"`
	Lgid       uint64      `json:"gid" msgpack:"gid"`
	Lnlink     uint16      `json:"nlink" msgpack:"nlink"`
	Lusername  string      `json:"username" msgpack:"username"`   // local addition
	Lgroupname string      `json:"groupname" msgpack:"groupname"` // local addition

	// Just in case we need something special to handle special
	// OSes.
	Flags uint32 `json:"flags" msgpack:"flags"`
}

Danger: If you add any fields here, be sure to adapt the Equal and EqualIgnoreSize methods.

func FileInfoFromStat added in v1.1.2

func FileInfoFromStat(stat fs.FileInfo) FileInfo

func NewFileInfo added in v1.1.2

func NewFileInfo(name string, size int64, mode os.FileMode, modTime time.Time, dev uint64, ino uint64, uid uint64, gid uint64, nlink uint16) FileInfo

func (FileInfo) Dev added in v1.1.2

func (f FileInfo) Dev() uint64

func (*FileInfo) Equal added in v1.1.2

func (fileinfo *FileInfo) Equal(fi *FileInfo) bool

func (*FileInfo) EqualIgnoreSize added in v1.1.2

func (fileinfo *FileInfo) EqualIgnoreSize(fi *FileInfo) bool

func (FileInfo) Gid added in v1.1.2

func (f FileInfo) Gid() uint64

func (FileInfo) Groupname added in v1.1.2

func (f FileInfo) Groupname() string

func (*FileInfo) HumanSize added in v1.1.2

func (fileinfo *FileInfo) HumanSize() string

func (FileInfo) Ino added in v1.1.2

func (f FileInfo) Ino() uint64

func (FileInfo) IsDir added in v1.1.2

func (f FileInfo) IsDir() bool

func (FileInfo) ModTime added in v1.1.2

func (f FileInfo) ModTime() time.Time

func (FileInfo) Mode added in v1.1.2

func (f FileInfo) Mode() os.FileMode

func (FileInfo) Name added in v1.1.2

func (f FileInfo) Name() string
func (f FileInfo) Nlink() uint16

func (FileInfo) Size added in v1.1.2

func (f FileInfo) Size() int64

func (FileInfo) Sys added in v1.1.2

func (f FileInfo) Sys() any

func (*FileInfo) ToBytes added in v1.1.2

func (fileinfo *FileInfo) ToBytes() ([]byte, error)

func (*FileInfo) Type added in v1.1.2

func (fileinfo *FileInfo) Type() string

func (FileInfo) Uid added in v1.1.2

func (f FileInfo) Uid() uint64

func (FileInfo) Username added in v1.1.2

func (f FileInfo) Username() string

type HostEndpoint

type HostEndpoint struct {
	Type       EndpointType
	Endpoint   string
	Attributes map[string]string
}

type Importer added in v1.1.2

type Importer interface {
	Origin() string
	Type() string
	Root() string
	Flags() location.Flags
	Ping(context.Context) error
	Import(context.Context, chan<- *Record, <-chan *Result) error
	Close(context.Context) error
}

type ImporterFn added in v1.1.2

type ImporterFn func(context.Context, *Options, string, map[string]string) (Importer, error)

type Inventory

type Inventory interface {
	List(context.Context, chan<- *InventoryEntry) error
	Close(context.Context) error
}

type InventoryEntry

type InventoryEntry struct {
	Class    ResourceClass    // interpreted
	SubClass ResourceSubClass // interpreted
	Tags     []string         // <value>, <key>=<value>

	// The rest is provider data
	URN       string //
	Name      string //
	Region    string // eu-west-3, paris/dc-1, ...
	Service   string // s3, ec2, instance, dedicated-server, ...
	Resource  string // s3:bucket, ec2:volume, ...
	Details   []byte // Additional backend-specific content
	Endpoints []HostEndpoint

	// Fill via CountryOf. Report it on every entry you can.
	Country Country
}

type LazyReader added in v1.1.2

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

func NewLazyReader added in v1.1.2

func NewLazyReader(open func() (io.ReadCloser, error)) *LazyReader

func (*LazyReader) Close added in v1.1.2

func (lr *LazyReader) Close() error

func (*LazyReader) Read added in v1.1.2

func (lr *LazyReader) Read(p []byte) (int, error)

type MAC added in v1.1.2

type MAC [32]byte
var (
	NilMac MAC
)

func RandomMAC added in v1.1.2

func RandomMAC() MAC

func (MAC) FormatHex added in v1.1.2

func (m MAC) FormatHex() string

func (MAC) MarshalJSON added in v1.1.2

func (m MAC) MarshalJSON() ([]byte, error)

func (*MAC) ParseHex added in v1.1.2

func (m *MAC) ParseHex(s string) error

func (*MAC) UnmarshalJSON added in v1.1.2

func (m *MAC) UnmarshalJSON(data []byte) error

type Mode added in v1.1.2

type Mode uint32
const (
	ModeWrite Mode = 1 << 1
	ModeRead  Mode = 1 << 2
)

type Options added in v1.1.2

type Options struct {
	Hostname        string
	OperatingSystem string
	Architecture    string
	CWD             string
	MaxConcurrency  int
	Excludes        []string
	NoXattr         bool

	Stdin  io.Reader `msgpack:"-"`
	Stdout io.Writer `msgpack:"-"`
	Stderr io.Writer `msgpack:"-"`
}

type Range added in v1.1.2

type Range struct {
	Offset uint64
	Length uint32
}

type Record added in v1.1.2

type Record struct {
	// kloset doesn't make use of this field at all, it's just
	// echoed back in the record.
	ID string

	Reader io.ReadCloser

	Pathname string
	Err      error

	IsXattr   bool
	XattrName string
	XattrType Attribute

	Target             string
	FileInfo           FileInfo
	ExtendedAttributes []string
	FileAttributes     uint32
}

requests

func NewError added in v1.1.2

func NewError(pathname string, err error) *Record

func NewRecord added in v1.1.2

func NewRecord(pathname, target string, fileinfo FileInfo, xattr []string, read func() (io.ReadCloser, error)) *Record

func NewXattr added in v1.1.2

func NewXattr(pathname, xattr string, kind Attribute, read func() (io.ReadCloser, error)) *Record

func (*Record) Close added in v1.1.2

func (s *Record) Close() error

func (*Record) Error added in v1.1.2

func (s *Record) Error(err error) *Result

func (*Record) Ok added in v1.1.2

func (s *Record) Ok() *Result

type ResourceClass

type ResourceClass string

func (ResourceClass) IsValid

func (c ResourceClass) IsValid() bool

type ResourceSubClass

type ResourceSubClass string

func (ResourceSubClass) IsSubClassOf

func (c ResourceSubClass) IsSubClassOf(parent ResourceClass) bool

func (ResourceSubClass) IsValid

func (c ResourceSubClass) IsValid() bool

type Result added in v1.1.2

type Result struct {
	Record Record
	Err    error
}

result

type SecretProvider

type SecretProvider interface {
	Ping(ctx context.Context) error
	Resolve(ctx context.Context, handle string) (secret string, err error)
	Close(ctx context.Context) error
}

type StorageFlag added in v1.1.2

type StorageFlag uint32
const (
	StorageHot StorageFlag = 1 << iota
)

func Flag added in v1.1.2

func Flag(ctx context.Context) StorageFlag

type StorageResource added in v1.1.2

type StorageResource uint32
const (
	StorageResourceUndefined   StorageResource = 0
	StorageResourcePackfile    StorageResource = 1
	StorageResourceState       StorageResource = 2
	StorageResourceLock        StorageResource = 3
	StorageResourceECCPackfile StorageResource = 4
	StorageResourceECCState    StorageResource = 5
)

func (StorageResource) String added in v1.1.2

func (s StorageResource) String() string

type Store added in v1.1.2

type Store interface {
	Create(context.Context, []byte) error
	Open(context.Context) ([]byte, error)
	Ping(context.Context) error

	Origin() string
	Type() string
	Root() string
	Flags() location.Flags

	Mode(context.Context) (Mode, error)
	Size(context.Context) (int64, error) // this can be costly, call with caution
	List(context.Context, StorageResource) ([]MAC, error)
	Put(context.Context, StorageResource, MAC, io.Reader) (int64, error)
	Get(context.Context, StorageResource, MAC, *Range) (io.ReadCloser, error)
	Delete(context.Context, StorageResource, MAC) error

	Close(ctx context.Context) error
}

type StoreFn added in v1.1.2

type StoreFn func(context.Context, string, map[string]string) (Store, error)

Directories

Path Synopsis
cmd
inventory-run command
secret-run command
cmd/rot13 command
Package stdioconn provides a net.Conn over a pair of files, such as the standard input and output of a process or the pipes to a child.
Package stdioconn provides a net.Conn over a pair of files, such as the standard input and output of a process or the pipes to a child.

Jump to

Keyboard shortcuts

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