kustomer

package module
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2021 License: AGPL-3.0-or-later Imports: 15 Imported by: 0

README

Kopano Kustomer Daemon client library

GoDoc

This project implements a C shared library with a public API to talk to the API provided by a locally running Kopano Kustomer Daemon.

Also this project can be used directly from Go as an importable module.

Compiling

Make sure you have Go 1.14 or later installed. This project uses Go modules.

As this is a C library, it is furthermore assumed that there is a working C compiler toolchain in your path which includes autoconf and make.

git clone <THIS-PROJECT> libkustomer
cd libkustomer
./bootstrap.sh
./configure
make

This will produce the compiled library .so and the matching C header file in the ./.libs directory.

Use as Go module
import "stash.kopano.io/kc/libkustomer"

Documentation

Index

Constants

View Source
const StatusSuccess = ErrStatusNone

StatusSuccess is the success response as returned by this library.

Variables

View Source
var DefaultAPIPath = "/run/kopano-kustomerd/api.sock"
View Source
var DefaultUserAgent = "libkustomer/" + version.Version

DefaultUserAgent is the HTTP user agent set in to request headers for HTTP requests created by this library.

View Source
var ErrNumericToTextMap = map[ErrNumeric]string{
	ErrStatusUnknown:            "Unknown",
	ErrStatusInvalidProductName: "Invalid Product Name Value",
	ErrStatusAlreadyInitialized: "Already Initialized",
	ErrStatusNotInitialized:     "Not Initialized",
	ErrStatusTimeout:            "Timeout",

	ErrEnsureOnlineFailed:                  "Ensure failed, product claim set not online",
	ErrEnsureTrustedFailed:                 "Ensure failed, product claim set not trusted",
	ErrEnsureProductNotFound:               "Ensure failed, product entry not found",
	ErrEnsureProductNotLicensed:            "Ensure failed, product is not licensed",
	ErrEnsureProductClaimNotFound:          "Ensure failed, product claim entry not found",
	ErrEnsureProductClaimValueTypeMismatch: "Ensure failed, product claim value type mismatch",
	ErrEnsureProductClaimValueMismatch:     "Ensure failed, product claim value mismatch",
	ErrEnsureUnknownOperator:               "Ensure failed, unknown operator",
	ErrEnsureInvalidTransaction:            "Ensure failed, invalid transaction",
}

ErrNumericToTextMap maps numeric errors to readable names.

Functions

func ErrNumericText

func ErrNumericText(code ErrNumeric) string

ErrNumericText returns a text for the ErrStatus. It returns the empty string if the code is unknown.

Types

type Claims

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

Claims represent a set of active claim key value pairs.

func (*Claims) Dump

func (c *Claims) Dump() map[string]interface{}

Dump exports the associated Claims payload data.

type Config

type Config struct {
	Logger Logger

	Debug       bool
	AutoRefresh bool

	ProductUserAgent *string
}

A Config holds the configuration for this module.

type ErrNumeric

type ErrNumeric uint64

ErrNumeric is the Error type as used by kustomer.

const (
	ErrStatusNone               = 0
	ErrStatusUnknown ErrNumeric = iota + (1 << 8)
	ErrStatusInvalidProductName
	ErrStatusAlreadyInitialized
	ErrStatusNotInitialized
	ErrStatusTimeout
)

Numeric errors for status.

const (
	ErrEnsureOnlineFailed ErrNumeric = iota + (1 << 16) + 1
	ErrEnsureTrustedFailed
	ErrEnsureProductNotFound
	ErrEnsureProductNotLicensed
	ErrEnsureProductClaimNotFound
	ErrEnsureProductClaimValueTypeMismatch
	ErrEnsureProductClaimValueMismatch
	ErrEnsureUnknownOperator
	ErrEnsureInvalidTransaction
)

Numeric errors for ensure comparison.

func (ErrNumeric) Error

func (errStatus ErrNumeric) Error() string

type KopanoProductClaims

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

KopanoProductClaims represent a set of all active claims as aggregated values.

func (*KopanoProductClaims) Dump

func (kpc *KopanoProductClaims) Dump() map[string]interface{}

Dump exports the associated KopanoProductClaims data.

func (*KopanoProductClaims) EnsureBool

func (kpc *KopanoProductClaims) EnsureBool(product, claim string, value bool) error

EnsureBool returns an error if the provided product or the claim value is not found. Furthermore the claim value is compared to the provided value and if it is not a match, an error is returned as well.

func (*KopanoProductClaims) EnsureFloat64

func (kpc *KopanoProductClaims) EnsureFloat64(product, claim string, value float64) error

EnsureFloat64 returns an error if the provided product or the claim value is not found. Furthermore the claim value is compared to the provided value and if it is not a match, an error is returned as well.

func (*KopanoProductClaims) EnsureFloat64WithOperator

func (kpc *KopanoProductClaims) EnsureFloat64WithOperator(product, claim string, value float64, op OperatorType) error

EnsureFloat64WithOperator returns an error if the provided product or the claim value is not found. Furthermore the claim value is compared to the provided value using the provided comparison operator and if it is not a match, an error is returned as well.

func (*KopanoProductClaims) EnsureInt64

func (kpc *KopanoProductClaims) EnsureInt64(product, claim string, value int64) error

EnsureInt64 returns an error if the provided product or the claim value is not found. Furthermore the claim value is compared to the provided value and if it is not a match, an error is returned as well.

func (*KopanoProductClaims) EnsureInt64WithOperator

func (kpc *KopanoProductClaims) EnsureInt64WithOperator(product, claim string, value int64, op OperatorType) error

EnsureInt64WithOperator returns an error if the provided product or the claim value is not found. Furthermore the claim value is compared to the provided value using the provided comparison operator and if it is not a match, an error is returned as well.

func (*KopanoProductClaims) EnsureOK

func (kpc *KopanoProductClaims) EnsureOK(product string) (err error)

EnsureOK returns an error if the provided product is not found in the associated claims data or if that product is found but the OK flag of the active product is false.

func (*KopanoProductClaims) EnsureOnline

func (kpc *KopanoProductClaims) EnsureOnline() (err error)

EnsureOnline returns ErrEnsureOnlineFailed error if the associated claims data was validated with offline. This function returns the error even if the associated claims mustBeOnline flag was is false.

func (*KopanoProductClaims) EnsureOnlineAndTrusted

func (kpc *KopanoProductClaims) EnsureOnlineAndTrusted() (err error)

EnsureOnlineAndTrusted is the combination of EnsureOnline and EnsureOnline for convinience. Samle rules apply as described in those two functions.

func (*KopanoProductClaims) EnsureString

func (kpc *KopanoProductClaims) EnsureString(product, claim, value string) error

EnsureString returns an error if the provided product or the claim value is not found. Furthermore the claim value is compared to the provided value and if it is not a match, an error is returned as well.

func (*KopanoProductClaims) EnsureStringArrayValues added in v0.6.0

func (kpc *KopanoProductClaims) EnsureStringArrayValues(product, claim string, value ...string) error

EnsureStringArrayValues returns an error if the provided product or the claim value is not found. Furthermore if not all of the provided value prameters are present in the claim value n error is returned as well.

func (*KopanoProductClaims) EnsureTrusted

func (kpc *KopanoProductClaims) EnsureTrusted() (err error)

EnsureTrusted returns ErrEnsureTrustedFailed error if the associated claims data is not trusted. This function will return the error even if the associated claims SetAllowUntrusted was set to true.

func (*KopanoProductClaims) GetBool

func (kpc *KopanoProductClaims) GetBool(product, claim string) (bool, error)

GetBool returns the prodvided prodcut claim bool value. If the product or the claim is not found, an the returned error describes the reason why the claim value is not available.

func (*KopanoProductClaims) GetFloat64

func (kpc *KopanoProductClaims) GetFloat64(product, claim string) (float64, error)

GetFloat64 returns the prodvided product claim float value. If the product or the claim is not found, an the returned error describes the reason why the claim value is not available.

func (*KopanoProductClaims) GetInt64

func (kpc *KopanoProductClaims) GetInt64(product, claim string) (int64, error)

GetInt64 returns the prodvided product claim numeric value. If the product or the claim is not found, an the returned error describes the reason why the claim value is not available.

func (*KopanoProductClaims) GetString

func (kpc *KopanoProductClaims) GetString(product, claim string) (string, error)

GetString returns the prodvided product claim string value. If the product or the claim is not found, an the returned error describes the reason why the claim value is not available.

func (*KopanoProductClaims) GetStringArrayValues added in v0.6.0

func (kpc *KopanoProductClaims) GetStringArrayValues(product, claim string) ([]string, error)

GetStringArrayValues returns the prodvided product claim string array value. If the product or the claim is not found, an the returned error describes the reason why the claim value is not available.

func (*KopanoProductClaims) SetAllowUntrusted

func (kpc *KopanoProductClaims) SetAllowUntrusted(flag bool)

SetAllowUntrusted sets the allowUntrusted flag value of the associated claims to the provided flag value. If true, any ensure check of the associated claims will ignore the trusted state of the claims data.

func (*KopanoProductClaims) SetMustBeOnline

func (kpc *KopanoProductClaims) SetMustBeOnline(flag bool)

SetMustBeOnline sets the mustBeOnline flag value of the associated claims to the provided flag value. If true, any ensure check of the associated claims will fail if the claims data was produced without online verification.

type Kustomer

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

A Kustomer is the representation of the Kustomer interface.

func New

func New(config *Config) (*Kustomer, error)

New creates a new Kustomer instance using the provided configuration.

func (*Kustomer) BuildDate

func (k *Kustomer) BuildDate() string

BuildDate returns the build data string of this module.

func (*Kustomer) CurrentClaims

func (k *Kustomer) CurrentClaims(ctx context.Context) *Claims

CurrentClaims returns the active claim set of the associated instance. This function blocks until a value is available or until the provided context is done. The fetched claims are cached, so no subsequent requests will result when calling this function, unless the underlaying active claims have changed since the last call.

func (*Kustomer) CurrentKopanoProductClaims

func (k *Kustomer) CurrentKopanoProductClaims(ctx context.Context) *KopanoProductClaims

CurrentKopanoProductClaims returns the active Kopano product claims of the associated instance. This function blocks until a value is available or until the provided context is done. In the current implementation, a value will always be returned directly.

func (*Kustomer) Initialize

func (k *Kustomer) Initialize(ctx context.Context, productName *string) error

Initialize intializes the associated instance with a context and a product name. Initialize must be called first, before most of the other functions of the instance return ErrStatusNotInitialized if this function was not called first.

func (*Kustomer) NotifyWhenUpdated

func (k *Kustomer) NotifyWhenUpdated(ctx context.Context, eventCh chan<- bool) error

NotifyWhenUpdated registers the provided even channel to receive bool values whenever the associated isntance claims have been updated. Calling this function blocks until the provided context is Done or until the associated instance is unintialized. An error is also returned if Initialize was not called before.

func (*Kustomer) Uninitialize

func (k *Kustomer) Uninitialize() error

Uninitialize is the opposite of initialize and releases the associated resources. Returns ErrStatusNotInitialized when this function is called without a call to Initialize before.

func (*Kustomer) Version

func (k *Kustomer) Version() string

Version returns the runtime version string of this module.

func (*Kustomer) WaitUntilReady

func (k *Kustomer) WaitUntilReady(ctx context.Context) error

WaitUntilReady waits until initialization is complete, until the provided context is done or until the associated instance gets unintialized. An error is also returned if Initialize was not called before.

type Logger

type Logger interface {
	Printf(string, ...interface{})
}

A Logger defines a simple logging interface for pluggable loggers used by this module.

var DefaultLogger Logger = &nullLogger{}

DefaultLogger is the packageLogger used by this library if no other logger is explicitly specified.

type OperatorType

type OperatorType string

OperatorsType is a special type of strring which can be used as operator.

const (
	OperatorGreaterThan        OperatorType = "gt"
	OperatorGreaterThanOrEqual OperatorType = "ge"
	OperatorLesserThan         OperatorType = "lt"
	OperatorLesserThanOrEqual  OperatorType = "le"
)

Operators to use with the operator comparisons.

Directories

Path Synopsis
cmd
internal
lib

Jump to

Keyboard shortcuts

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