rcap

package
v0.15.1 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 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 ErrCapabilityNotEnabled = errors.New("capability is not enabled")

Functions

func AugmentedValFromEnv added in v0.13.0

func AugmentedValFromEnv(original string) string

Types

type AuthCapability added in v0.11.1

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 added in v0.11.1

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 added in v0.11.1

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 added in v0.12.0

func SetupCache(config CacheConfig) CacheCapability

type CacheConfig added in v0.11.1

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 added in v0.12.0

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

type CapabilityConfig added in v0.11.1

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"`
	RequestHandler *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 added in v0.11.1

func DefaultCapabilityConfig() CapabilityConfig

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

func DefaultConfigWithDB added in v0.13.0

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 added in v0.11.1

func DefaultConfigWithLogger(logger *vlog.Logger) CapabilityConfig

DefaultConfigWithLogger returns a capability config with a custom logger

func NewConfig added in v0.13.0

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

type DatabaseCapability added in v0.13.0

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

func NewSqlDatabase added in v0.13.0

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

NewSqlDatabase creates a new SQL database

type DatabaseConfig added in v0.13.0

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 added in v0.11.1

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 added in v0.11.1

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

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

FileConfig is configuration for the File capability

type GraphQLCapability added in v0.11.1

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 added in v0.11.1

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 added in v0.11.1

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 added in v0.11.1

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

HTTPConfig is configuration for the HTTP capability

type HTTPRules added in v0.12.0

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 added in v0.11.1

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 added in v0.11.1

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

LoggerConfig is configuration for the logger capability

type Query added in v0.13.0

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 added in v0.13.0

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

type RedisCache added in v0.12.0

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

func (*RedisCache) Delete added in v0.12.0

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

Delete deletes a key

func (*RedisCache) Get added in v0.12.0

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

Get gets a value from the cache

func (*RedisCache) Set added in v0.12.0

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

Set sets a value in the cache

type RedisConfig added in v0.12.0

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

type RequestHandlerCapability added in v0.11.1

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 added in v0.11.1

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 added in v0.13.0

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

SqlDatabase is an SQL implementation of DatabaseCapability

func (*SqlDatabase) ExecQuery added in v0.13.0

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

func (*SqlDatabase) Prepare added in v0.13.0

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