peer

package
v0.0.18 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ChangedActionCreated = "CREATED"
	ChangedActionUpdated = "UPDATED"
	ChangedActionDeleted = "DELETED"
)

Variables

View Source
var (
	ErrIdRequired                  = errors.New("id is required")
	ErrServerIdRequired            = errors.New("server id is required")
	ErrNameRequired                = errors.New("name is required")
	ErrOneOptionRequired           = errors.New("one option is required")
	ErrOnlyOneOptionAllowed        = errors.New("only one option is allowed")
	ErrServerNotFound              = errors.New("server not found")
	ErrPeerNotFound                = errors.New("peer not found")
	ErrPeerIdAlreadyExists         = errors.New("peer id already exists")
	ErrPeerNameAlreadyInUse        = errors.New("peer name already in use")
	ErrPublicKeyRequired           = errors.New("public key is required")
	ErrPublicKeyAlreadyExists      = errors.New("public key already exists")
	ErrCreatePeerOptionsRequired   = errors.New("create peer options are required")
	ErrUpdatePeerOptionsRequired   = errors.New("update peer options are required")
	ErrUpdatePeerFieldMaskRequired = errors.New("update peer field mask are required")
)

Functions

This section is empty.

Types

type ChangedEvent

type ChangedEvent struct {
	Action string `json:"action"`
	Peer   *Peer  `json:"peer"`
}

type CreateOptions

type CreateOptions struct {
	Name                string
	Description         string
	PublicKey           string
	Endpoint            string
	AllowedIPs          []string
	PresharedKey        string
	PersistentKeepalive int
	Hooks               []*Hook
}

type FindOneOptions

type FindOneOptions struct {
	IdOption                *IdOption
	ServerIdPublicKeyOption *ServerIdPublicKeyOption
}

func (*FindOneOptions) Validate

func (options *FindOneOptions) Validate() error

type FindOptions

type FindOptions struct {
	Ids          []string
	ServerId     *string
	CreateUserId *string
	UpdateUserId *string
	Query        string
}

type Hook

type Hook struct {
	Command     string
	RunOnCreate bool
	RunOnUpdate bool
	RunOnDelete bool
}

type HookAction

type HookAction string
var (
	HookActionCreate HookAction = "CREATE"
	HookActionUpdate HookAction = "UPDATE"
	HookActionDelete HookAction = "DELETE"
)

type IdOption

type IdOption struct {
	Id string
}

func (*IdOption) Validate

func (option *IdOption) Validate() error

type Peer

type Peer struct {
	Id                  string
	ServerId            string
	Name                string
	Description         string
	PublicKey           string
	Endpoint            string
	AllowedIPs          []string
	PresharedKey        string
	PersistentKeepalive int
	Hooks               []*Hook
	CreateUserId        string
	UpdateUserId        string
	DeleteUserId        string
	CreatedAt           time.Time
	UpdatedAt           time.Time
	DeletedAt           *time.Time
}

type Repository

type Repository interface {
	FindOne(ctx context.Context, options *FindOneOptions) (*Peer, error)
	FindAll(ctx context.Context, options *FindOptions) ([]*Peer, error)
	Create(ctx context.Context, peer *Peer) (*Peer, error)
	Update(ctx context.Context, peer *Peer, fieldMask *UpdateFieldMask) (*Peer, error)
	Delete(ctx context.Context, peerId string, deleteUserId string) (*Peer, error)
}

type ServerIdPublicKeyOption

type ServerIdPublicKeyOption struct {
	ServerId  string
	PublicKey string
}

func (*ServerIdPublicKeyOption) Validate

func (option *ServerIdPublicKeyOption) Validate() error

type Service

type Service interface {
	FindPeer(ctx context.Context, options *FindOneOptions) (*Peer, error)
	FindPeers(ctx context.Context, options *FindOptions) ([]*Peer, error)
	CreatePeer(ctx context.Context, serverId string, options *CreateOptions, userId string) (*Peer, error)
	UpdatePeer(ctx context.Context, peerId string, options *UpdateOptions, fieldMask *UpdateFieldMask, userId string) (*Peer, error)
	DeletePeer(ctx context.Context, peerId string, userId string) (*Peer, error)
	Subscribe(ctx context.Context) (<-chan *ChangedEvent, error)
	HasSubscribers() bool
}

func NewService

func NewService(
	peerRepository Repository,
	transactionScoper dbx.TransactionScoper,
	serverService server.Service,
	subscription subscription.Subscription,
) Service

type UpdateFieldMask

type UpdateFieldMask struct {
	Name                bool
	Description         bool
	PublicKey           bool
	Endpoint            bool
	AllowedIPs          bool
	PresharedKey        bool
	PersistentKeepalive bool
	Hooks               bool
	CreateUserId        bool
	UpdateUserId        bool
}

type UpdateOptions

type UpdateOptions struct {
	Name                string
	Description         string
	Enabled             bool
	PublicKey           string
	Endpoint            string
	AllowedIPs          []string
	PresharedKey        string
	PersistentKeepalive int
	Hooks               []*Hook
	CreateUserId        string
	UpdateUserId        string
}

Jump to

Keyboard shortcuts

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