capabilities

package
v0.15.2 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2022 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DBTypeMySQL    = "mysql"
	DBTypePostgres = "pgx"
)
View Source
const (
	RequestFieldTypeMeta   = int32(0)
	RequestFieldTypeBody   = int32(1)
	RequestFieldTypeHeader = int32(2)
	RequestFieldTypeParams = int32(3)
	RequestFieldTypeState  = int32(4)
	RequestFieldTypeQuery  = int32(5)
)

Variables

View Source
var (
	ErrDatabaseTypeInvalid = errors.New("database type invalid")
	ErrQueryNotFound       = errors.New("query not found")
	ErrQueryNotPrepared    = errors.New("query not prepared")
	ErrQueryTypeMismatch   = errors.New("query type incorrect")
	ErrQueryTypeInvalid    = errors.New("query type invalid")
	ErrQueryVarsMismatch   = errors.New("number of variables incorrect")
)
View Source
var (
	ErrHttpDisallowed    = errors.New("requests to insecure HTTP endpoints is disallowed")
	ErrIPsDisallowed     = errors.New("requests to IP addresses are disallowed")
	ErrPrivateDisallowed = errors.New("requests to private IP address ranges are disallowed")
	ErrDomainDisallowed  = errors.New("requests to this domain are disallowed")
	ErrPortDisallowed    = errors.New("requests to this port are disallowed")
)
View Source
var (
	ErrReqNotSet        = errors.New("req is not set")
	ErrInvalidFieldType = errors.New("invalid field type")
	ErrKeyNotFound      = errors.New("key not found")
)
View Source
var ErrCacheKeyNotFound = errors.New("key not found")

ErrCacheKeyNotFound is returned when a non-existent cache key is requested

View Source
var ErrCapabilityNotAvailable = errors.New("capability not available")
View Source
var ErrCapabilityNotEnabled = errors.New("capability is not enabled")

Functions

func AugmentedValFromEnv

func AugmentedValFromEnv(original string) string

Types

type AuthCapability

type AuthCapability interface {
	HeaderForDomain(string) *AuthHeader
}

AuthCapability is a provider for various kinds of auth

func DefaultAuthProvider

func DefaultAuthProvider(config AuthConfig) AuthCapability

DefaultAuthProvider creates the default static auth provider

type AuthConfig

type AuthConfig struct {
	Enabled bool `json:"enabled" yaml:"enabled"`

	// Headers is a map between domains and auth header that should be added to requests to those domains
	Headers map[string]AuthHeader `json:"headers" yaml:"headers"`
}

AuthConfig is a config for the default auth provider

type AuthHeader

type AuthHeader struct {
	HeaderType string `json:"headerType" yaml:"headerType"`
	Value      string `json:"value" yaml:"value"`
}

AuthHeader is an HTTP header designed to authenticate requests

type CacheCapability

type CacheCapability interface {
	Set(key string, val []byte, ttl int) error
	Get(key string) ([]byte, error)
	Delete(key string) error
}

CacheCapability gives Runnables access to a key/value cache

func SetupCache

func SetupCache(config CacheConfig) CacheCapability

type CacheConfig

type CacheConfig struct {
	Enabled     bool         `json:"enabled" yaml:"enabled"`
	Rules       CacheRules   `json:"rules" yaml:"rules"`
	RedisConfig *RedisConfig `json:"redis,omitempty" yaml:"redis,omitempty"`
}

CacheConfig is configuration for the cache capability

type CacheRules

type CacheRules struct {
	AllowSet    bool `json:"allowSet" yaml:"allowSet"`
	AllowGet    bool `json:"allowGet" yaml:"allowGet"`
	AllowDelete bool `json:"allowDelete" yaml:"allowDelete"`
}

type Capabilities

type Capabilities struct {
	Auth          AuthCapability
	LoggerSource  LoggerCapability
	HTTPClient    HTTPCapability
	GraphQLClient GraphQLCapability
	Cache         CacheCapability
	FileSource    FileCapability
	Database      DatabaseCapability

	// RequestHandler and doFunc are special because they are more
	// sensitive; they could cause memory leaks or expose internal state,
	// so they cannot be swapped out for a different implementation.
	RequestConfig *RequestHandlerConfig
	// contains filtered or unexported fields
}

Capabilities define the capabilities available to a Runnable

func New

func New(logger *vlog.Logger) *Capabilities

New returns the default capabilities with the provided Logger

func NewWithConfig

func NewWithConfig(config CapabilityConfig) (*Capabilities, error)

func (Capabilities) Config

func (c Capabilities) Config() CapabilityConfig

Config returns the configuration that was used to create the Capabilities the config cannot be changed, but it can be used to determine what was previously set so that the orginal config (like enabled settings) can be respected

type CapabilityConfig

type CapabilityConfig struct {
	Logger  *LoggerConfig         `json:"logger,omitempty" yaml:"logger,omitempty"`
	HTTP    *HTTPConfig           `json:"http,omitempty" yaml:"http,omitempty"`
	GraphQL *GraphQLConfig        `json:"graphql,omitempty" yaml:"graphql,omitempty"`
	Auth    *AuthConfig           `json:"auth,omitempty" yaml:"auth,omitempty"`
	Cache   *CacheConfig          `json:"cache,omitempty" yaml:"cache,omitempty"`
	File    *FileConfig           `json:"file,omitempty" yaml:"file,omitempty"`
	DB      *DatabaseConfig       `json:"db" yaml:"db"`
	Request *RequestHandlerConfig `json:"requestHandler,omitempty" yaml:"requestHandler,omitempty"`
}

CapabilityConfig is configuration for a Runnable's capabilities NOTE: if any of the individual configs are nil, it will cause a crash, but we need to be able to determine if they're set or not, hence the pointers we are going to leave capabilities undocumented until we come up with a more elegant solution

func DefaultCapabilityConfig

func DefaultCapabilityConfig() CapabilityConfig

DefaultCapabilityConfig returns the default all-enabled config (with a default logger)

func DefaultConfigWithDB

func DefaultConfigWithDB(logger *vlog.Logger, dbType, dbConnString string, queries []Query) CapabilityConfig

DefaultConfigWithDB returns a capability config with a custom logger and database configured

func DefaultConfigWithLogger

func DefaultConfigWithLogger(logger *vlog.Logger) CapabilityConfig

DefaultConfigWithLogger returns a capability config with a custom logger

func NewConfig

func NewConfig(logger *vlog.Logger, dbType, dbConnString string, queries []Query) CapabilityConfig

type DatabaseCapability

type DatabaseCapability interface {
	ExecQuery(queryType int32, name string, vars []interface{}) ([]byte, error)
	Prepare(q *Query) error
}

func NewSqlDatabase

func NewSqlDatabase(config *DatabaseConfig) (DatabaseCapability, error)

NewSqlDatabase creates a new SQL database

type DatabaseConfig

type DatabaseConfig struct {
	Enabled          bool    `json:"enabled" yaml:"enabled"`
	DBType           string  `json:"dbType" yaml:"dbType"`
	ConnectionString string  `json:"connectionString" yaml:"connectionString"`
	Queries          []Query `json:"queries" yaml:"queries"`
}

type FileCapability

type FileCapability interface {
	GetStatic(filename string) ([]byte, error)
}

FileCapability gives runnables access to various kinds of files

func DefaultFileSource

func DefaultFileSource(config FileConfig) FileCapability

type FileConfig

type FileConfig struct {
	Enabled bool `json:"enabled" yaml:"enabled"`

	FileFunc StaticFileFunc `json:"-" yaml:"-"`
}

FileConfig is configuration for the File capability

type GraphQLCapability

type GraphQLCapability interface {
	Do(auth AuthCapability, endpoint, query string) (*GraphQLResponse, error)
}

GraphQLCapability is a GraphQL capability for Reactr Modules

func DefaultGraphQLClient

func DefaultGraphQLClient(config GraphQLConfig) GraphQLCapability

DefaultGraphQLClient creates a GraphQLClient object

type GraphQLConfig

type GraphQLConfig struct {
	Enabled bool      `json:"enabled" yaml:"enabled"`
	Rules   HTTPRules `json:"rules" yaml:"rules"`
}

GraphQLConfig is configuration for the GraphQL capability

type GraphQLError

type GraphQLError struct {
	Message string `json:"message"`
	Path    string `json:"path"`
}

GraphQLError is a GraphQL error

type GraphQLRequest

type GraphQLRequest struct {
	Query         string            `json:"query"`
	Variables     map[string]string `json:"variables,omitempty"`
	OperationName string            `json:"operationName,omitempty"`
}

GraphQLRequest is a request to a GraphQL endpoint

type GraphQLResponse

type GraphQLResponse struct {
	Data   map[string]interface{} `json:"data"`
	Errors []GraphQLError         `json:"errors,omitempty"`
}

GraphQLResponse is a GraphQL response

type HTTPCapability

type HTTPCapability interface {
	Do(auth AuthCapability, method, urlString string, body []byte, headers http.Header) (*http.Response, error)
}

HTTPCapability gives Runnables the ability to make HTTP requests

func DefaultHTTPClient

func DefaultHTTPClient(config HTTPConfig) HTTPCapability

DefaultHTTPClient creates an HTTP client with no restrictions

type HTTPConfig

type HTTPConfig struct {
	Enabled bool      `json:"enabled" yaml:"enabled"`
	Rules   HTTPRules `json:"rules" yaml:"rules"`
}

HTTPConfig is configuration for the HTTP capability

type HTTPRules

type HTTPRules struct {
	AllowedDomains []string `json:"allowedDomains" yaml:"allowedDomains"`
	BlockedDomains []string `json:"blockedDomains" yaml:"blockedDomains"`
	AllowedPorts   []int    `json:"allowedPorts" yaml:"allowedPorts"`
	BlockedPorts   []int    `json:"blockedPorts" yaml:"blockedPorts"`
	AllowIPs       bool     `json:"allowIPs" yaml:"allowIPs"`
	AllowPrivate   bool     `json:"allowPrivate" yaml:"allowPrivate"`
	AllowHTTP      bool     `json:"allowHTTP" yaml:"allowHTTP"`
}

HTTPRules is a set of rules that governs use of the HTTP capability

type LoggerCapability

type LoggerCapability interface {
	Log(level int32, msg string, scope interface{})
}

LoggerCapability provides a logger to Runnables

func DefaultLoggerSource

func DefaultLoggerSource(config LoggerConfig) LoggerCapability

DefaultLoggerSource returns a LoggerSource that provides vlog.Default

type LoggerConfig

type LoggerConfig struct {
	Enabled bool         `json:"enabled" yaml:"enabled"`
	Logger  *vlog.Logger `json:"-" yaml:"-"`
}

LoggerConfig is configuration for the logger capability

type Query

type Query struct {
	Type     QueryType `json:"type" yaml:"type"`
	Name     string    `json:"name" yaml:"name"`
	VarCount int       `json:"varCount" yaml:"varCount"`
	Query    string    `json:"query" yaml:"query"`
	// contains filtered or unexported fields
}

type QueryType

type QueryType int32
const (
	QueryTypeInsert QueryType = QueryType(0)
	QueryTypeSelect QueryType = QueryType(1)
	QueryTypeUpdate QueryType = QueryType(2)
	QueryTypeDelete QueryType = QueryType(3)
)

type RedisCache

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

func (*RedisCache) Delete

func (r *RedisCache) Delete(key string) error

Delete deletes a key

func (*RedisCache) Get

func (r *RedisCache) Get(key string) ([]byte, error)

Get gets a value from the cache

func (*RedisCache) Set

func (r *RedisCache) Set(key string, val []byte, ttl int) error

Set sets a value in the cache

type RedisConfig

type RedisConfig struct {
	ServerAddress string `json:"serverAddress" yaml:"serverAddress"`
	Username      string `json:"username" yaml:"username"`
	Password      string `json:"password" yaml:"password"`
}

type RequestHandlerCapability

type RequestHandlerCapability interface {
	GetField(fieldType int32, key string) ([]byte, error)
	SetField(fieldType int32, key string, val string) error
	SetResponseHeader(key, val string) error
}

RequestHandlerCapability allows runnables to handle HTTP requests

func NewRequestHandler

NewRequestHandler provides a handler for the given request

type RequestHandlerConfig

type RequestHandlerConfig struct {
	Enabled       bool `json:"enabled" yaml:"enabled"`
	AllowGetField bool `json:"allowGetField" yaml:"allowGetField"`
	AllowSetField bool `json:"allowSetField" yaml:"allowSetField"`
}

RequestHandlerConfig is configuration for the request capability

type SqlDatabase

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

SqlDatabase is an SQL implementation of DatabaseCapability

func (*SqlDatabase) ExecQuery

func (s *SqlDatabase) ExecQuery(queryType int32, name string, vars []interface{}) ([]byte, error)

func (*SqlDatabase) Prepare

func (s *SqlDatabase) Prepare(q *Query) error

type StaticFileFunc

type StaticFileFunc func(string) ([]byte, error)

StaticFileFunc is a function that returns the contents of a requested file

Jump to

Keyboard shortcuts

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