Documentation ¶
Index ¶
- Constants
- Variables
- func AugmentedValFromEnv(original string) string
- type AuthCapability
- type AuthConfig
- type AuthHeader
- type CacheCapability
- type CacheConfig
- type CacheRules
- type Capabilities
- type CapabilityConfig
- func DefaultCapabilityConfig() CapabilityConfig
- func DefaultConfigWithDB(logger *vlog.Logger, dbType, dbConnString string, queries []Query) CapabilityConfig
- func DefaultConfigWithLogger(logger *vlog.Logger) CapabilityConfig
- func NewConfig(logger *vlog.Logger, dbType, dbConnString string, queries []Query) CapabilityConfig
- type DatabaseCapability
- type DatabaseConfig
- type FileCapability
- type FileConfig
- type GraphQLCapability
- type GraphQLConfig
- type GraphQLError
- type GraphQLRequest
- type GraphQLResponse
- type HTTPCapability
- type HTTPConfig
- type HTTPRules
- type LoggerCapability
- type LoggerConfig
- type Query
- type QueryType
- type RedisCache
- type RedisConfig
- type RequestHandlerCapability
- type RequestHandlerConfig
- type SqlDatabase
- type StaticFileFunc
Constants ¶
const ( DBTypeMySQL = "mysql" DBTypePostgres = "pgx" )
Variables ¶
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") )
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") )
var ( ErrReqNotSet = errors.New("req is not set") ErrInvalidFieldType = errors.New("invalid field type") ErrKeyNotFound = errors.New("key not found") )
var ErrCacheKeyNotFound = errors.New("key not found")
ErrCacheKeyNotFound is returned when a non-existent cache key is requested
var ErrCapabilityNotAvailable = errors.New("capability not available")
var ErrCapabilityNotEnabled = errors.New("capability is not enabled")
Functions ¶
func AugmentedValFromEnv ¶
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 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
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 FileCapability ¶
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 ¶
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 ¶
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 RedisCache ¶
type RedisCache struct {
// contains filtered or unexported fields
}
type RedisConfig ¶
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 ¶
func NewRequestHandler(config RequestHandlerConfig, req *request.CoordinatedRequest) RequestHandlerCapability
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 ¶
StaticFileFunc is a function that returns the contents of a requested file