duros

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 28, 2021 License: MIT Imports: 29 Imported by: 2

README

duros-go

Actions PkgGoDev Go Report Card codecov License

A lightbits duros api go client library.

A usage example can be found here.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dial

Dial creates a LightOS cluster client. it is a blocking call and will only return once the connection to [at least one of the] `targets` has been actually established - subject to `ctx` limitations. if `ctx` specified timeout or duration - dialling (and only dialling!) timeout will be set accordingly. `ctx` can also be used to cancel the dialling process, as per usual.

the cluster client will make an effort to transparently reconnect to one of the `targets` in case of connection loss. if the process of finding a live and responsive target amongst `targets` and establishing the connection takes longer than the actual operation context timeout (as opposed to the `ctx` passed here) - `DeadlineExceeded` will be returned as usual, and the caller can retry the operation.

func NewJWTToken

func NewJWTToken(subject, issuer string, kid string, roles []string, expires time.Duration, keyPair *rsa.PrivateKey) (string, error)

NewJWTToken create a JWT Token to use to authenticate against a duros API endpoint

subject: 'sub' claim, who will be using this JWT, example a persons or tenants name kid: this is the "key ID", the name of the credential (pub key) as uploaded to LightOS. it is of the form "<scope>:<name>", e.g.:

  system:root - your root pub key, installed during system deployment
  tenant-foo:first-cred - pub key of tenant tenant-foo uploaded as credential named first-cred.
the JWTs are validated using the specific pub keys, so a corresponding
credential must already exist in LightOS.

roles: list of roles this token should contain, must be in the form of

foo:admin which gives this user  (subject) admin rights to the foo resource

expires: Duration after which this token will expire. keyPair: RSA public and private key which should be used to sign this token

func NewJWTTokenForCredential

func NewJWTTokenForCredential(subject, issuer string, credential *v2.Credential, roles []string, expires time.Duration, keyPair *rsa.PrivateKey) (string, error)

NewJWTTokenForCredential create a new JWTToken where subject and kid is taken from the credential

Types

type ByteCredentials added in v0.1.2

type ByteCredentials struct {
	ServerName string
	Cert       []byte
	Key        []byte
	CA         []byte
}

Credentials specify the TLS Certificate based authentication for the grpc connection without having to use certificate files. If you provide credentials, provide either these or file path credentials but not both.

type Credentials

type Credentials struct {
	ServerName string
	Certfile   string
	Keyfile    string
	CAFile     string
}

Credentials specify the TLS Certificate based authentication for the grpc connection If you provide credentials, provide either these or byte credentials but not both.

type DialConfig

type DialConfig struct {
	Endpoints       EPs
	Scheme          GRPCScheme
	Token           string
	Credentials     *Credentials
	ByteCredentials *ByteCredentials
	Log             *zap.SugaredLogger
}

DialConfig is the configuration to create a duros-api connection

type EP

type EP struct {
	Host string // either a hostname or an IP address
	Port uint16 // port number
}

EP is a duros API Endpoint

func MustParseEndpoint

func MustParseEndpoint(endpoint string) EP

MustParseEndpoint is similar to Parse(), but it panics if endpoint is invalid and can't be parsed. useful primarily for tests and global "consts" inits.

func ParseEndpoint

func ParseEndpoint(endpoint string) (EP, error)

ParseEndpoint is like parseStricter(), but it disregards spaces before and after the endpoint string.

func (EP) String

func (ep EP) String() string

type EPs

type EPs []EP

EPs is a slice of Endpoints

func MustParseCSV

func MustParseCSV(endpoints string) EPs

MustParseCSV is equal to ParseCSV but panics on error

func MustParseEndpoints

func MustParseEndpoints(endpoints []string) EPs

MustParseEndpoints is equal to ParseEndpoints but panics on error

func ParseCSV

func ParseCSV(endpoints string) (EPs, error)

ParseCSV parses a string containing comma-separated list of target endpoints, validates them syntactically, and returns a slice of EP structs. it does NOT attempt to resolve the names present in the endpoints nor does it try to connect to any of the targets. `targets` must be in a format:

<host>:<port>[,<host>:<port>...]

func ParseEndpoints

func ParseEndpoints(endpoints []string) (EPs, error)

ParseEndpoints parse a slice of strings in the form of <host>:<port> into a slice of EP.

func (EPs) Len

func (eps EPs) Len() int

for sort.Interface: Len returns the length of the EPs

func (EPs) Less

func (eps EPs) Less(i, j int) bool

Less compares two EPs entries for equality

func (EPs) String

func (eps EPs) String() string

func (EPs) Swap

func (eps EPs) Swap(i, j int)

Swap the content of the EPs

type GRPCScheme

type GRPCScheme string

GRPCScheme the scheme to talk to the duros api endpoint, can be plaintext or https

const (
	// GRPC defines a plaitext communication
	GRPC GRPCScheme = "grpc"
	// GRPCS defines https protocol for the communication
	GRPCS GRPCScheme = "grpcs"
)

type MockClient

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

func NewMock

func NewMock(c v2.DurosAPIClient) *MockClient

Directories

Path Synopsis
api
cmd
cli command

Jump to

Keyboard shortcuts

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