utils

package
v0.0.0-...-260b785 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2024 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// One operation returns a single document from the database
	One string = "one"

	// All operation returns multiple documents from the database
	All string = "all"

	// Count operation returns the number of documents which match the condition
	Count string = "count"

	// Distinct operation returns distinct values
	Distinct string = "distinct"

	// Upsert creates a new document if it doesn't exist, else it updates exiting document
	Upsert string = "upsert"
)
View Source
const (

	// RealtimeInsert is for create operations
	RealtimeInsert string = "insert"

	// RealtimeUpdate is for update operations
	RealtimeUpdate string = "update"

	// RealtimeDelete is for delete operations
	RealtimeDelete string = "delete"

	// RealtimeInitial is for the initial data
	RealtimeInitial string = "initial"
)
View Source
const (
	// TypeRealtimeSubscribe is the request type for live query subscription
	TypeRealtimeSubscribe string = "realtime-subscribe"

	// TypeRealtimeUnsubscribe is the request type for live query subscription
	TypeRealtimeUnsubscribe string = "realtime-unsubscribe"

	// TypeRealtimeFeed is the response type for realtime feed
	TypeRealtimeFeed string = "realtime-feed"
)
View Source
const (
	// PortHTTP is the port used for the http server
	PortHTTP string = "4122"

	// PortHTTPConnect is the port used for the http server with consul connect
	PortHTTPConnect string = "4124"

	// PortHTTPSecure is the port used for the http server with tls
	PortHTTPSecure string = "4126"
)
View Source
const (
	// GqlConnectionKeepAlive send every 20 second to client over websocket
	GqlConnectionKeepAlive string = "ka" // Server -> Client
	// GqlConnectionInit is used by graphql over websocket protocol
	GqlConnectionInit string = "connection_init" // Client -> Server
	// GqlConnectionAck is used by graphql over websocket protocol
	GqlConnectionAck string = "connection_ack" // Server -> Client
	// GqlConnectionError is used by graphql over websocket protocol
	GqlConnectionError string = "connection_error" // Server -> Client
	// GqlConnectionTerminate is used by graphql over websocket protocol
	GqlConnectionTerminate string = "connection_terminate" // Client -> Server
	// GqlStart is used by graphql over websocket protocol
	GqlStart string = "start" // Client -> Server
	// GqlData is used by graphql over websocket protocol
	GqlData string = "data" // Server -> Client
	// GqlError is used by graphql over websocket protocol
	GqlError string = "error" // Server -> Client
	// GqlComplete is used by graphql over websocket protocol
	GqlComplete string = "complete" // Server -> Client
	// GqlStop is used by graphql over websocket protocol
	GqlStop string = "stop" // Client -> Server
)
View Source
const (
	// EventDBCreate is fired for create request
	EventDBCreate string = "DB_INSERT"

	// EventDBUpdate is fired for update request
	EventDBUpdate string = "DB_UPDATE"

	// EventDBDelete is fired for delete request
	EventDBDelete string = "DB_DELETE"

	// EventFileCreate is fired for create request
	EventFileCreate string = "FILE_CREATE"

	// EventFileDelete is fired for delete request
	EventFileDelete string = "FILE_DELETE"
)
View Source
const (
	// EventStatusIntent signifies that the event hasn't been staged yet
	EventStatusIntent string = "intent"

	// EventStatusStaged signifies that the event can be processed
	EventStatusStaged string = "staged"

	// EventStatusProcessed signifies that the event has been successfully been processed and can be deleted
	EventStatusProcessed string = "processed"

	// EventStatusFailed signifies that the event has failed and should not be processed
	EventStatusFailed string = "failed"

	// EventStatusCancelled signifies that the event has been cancelled and should not be processed
	EventStatusCancelled string = "cancel"
)
View Source
const (
	// TableEventingLogs is a variable for "event_logs"
	TableEventingLogs string = "event_logs"
	// TableInvocationLogs is a variable for "invocation_logs"
	TableInvocationLogs string = "invocation_logs"
	// SchemaInvocationLogs is a variable for invocaton schema
	SchemaInvocationLogs string = `` /* 267-byte string literal not displayed */

	// SchemaEventLogs is a variable for event schema
	SchemaEventLogs string = `` /* 342-byte string literal not displayed */

)
View Source
const AdminSecretKID = "sc-admin-kid"

AdminSecretKID describes the kid to be used for admin secrets

View Source
const BuildVersion = "0.21.5"

BuildVersion is the current version of Space Cloud

View Source
const DLQEventTriggerPrefix = "dlq_"

DLQEventTriggerPrefix used as suffix for DLQ event trigger

View Source
const DefaultCacheTTLTimeout = 60 * 5

DefaultCacheTTLTimeout used for setting default ttl expiry if not specified the value is in seconds, current value corresponds to 5 minutes

View Source
const DefaultConfigFilePath string = "config.yaml"

DefaultConfigFilePath is the default path to load / store the config file

View Source
const DefaultContextTime = 100

DefaultContextTime used for creating default context time for endpoints

View Source
const GraphQLAggregate = "aggregate"

GraphQLAggregate is used by graphql aggregate clause

View Source
const GraphQLGroupByArgument = "group"

GraphQLGroupByArgument is used by graphql group clause

View Source
const InternalUserID string = "internal-sc-user"

InternalUserID is the auth.id used for internal requests

View Source
const MaxEventTokens int = 100

MaxEventTokens describes the maximum number of event workers

View Source
const SpaceCloudServiceName string = "space-cloud"

SpaceCloudServiceName is the service name space cloud will register itself with in service discovery mechanisms

Variables

View Source
var ErrDatabaseConnection = errors.New("Could not connect to database. Make sure it is up and connection string provided to SC is correct")

ErrDatabaseConnection is thrown when SC was unable to connect to the requested database

View Source
var ErrDatabaseDisabled = errors.New("Database is disabled. Please enable it")

ErrDatabaseDisabled is thrown when an operation is requested on a disabled database

View Source
var ErrInvalidParams = errors.New("Invalid parameter provided")

ErrInvalidParams is thrown when the input parameters for an operation are invalid

View Source
var ErrUnsupportedDatabase = errors.New("Unsupported database. Make sure your database type is correct")

ErrUnsupportedDatabase is thrown when an invalid db type is provided

Functions

func AcceptableIDType

func AcceptableIDType(id interface{}) (string, bool)

AcceptableIDType converts a provied id to string

func Adjust

func Adjust(ctx context.Context, obj interface{}, state map[string]interface{}) interface{}

Adjust loads value from state if referenced

func ApplySpec

func ApplySpec(ctx context.Context, token, hostAddr string, specObj *model.SpecObject) error

ApplySpec takes a spec object and applies it

func ArrayContains

func ArrayContains(array []interface{}, value interface{}) bool

ArrayContains checks if the array contains the value provided

func CheckParse

func CheckParse(s string) (time.Time, error)

CheckParse checks if the string can be parsed or not

func CloseTheCloser

func CloseTheCloser(c io.Closer)

CloseTheCloser closes the closer

func CreateCorsObject

func CreateCorsObject() *cors.Cors

CreateCorsObject creates a cors object with the required config

func DeleteValue

func DeleteValue(ctx context.Context, key string, state map[string]interface{}) error

DeleteValue -- deletes a value in the provided state

func DownloadFileFromURL

func DownloadFileFromURL(url, dest string) error

DownloadFileFromURL downloads a file from url and stores it at a given destination

func Encrypt

func Encrypt(aesKey []byte, value string) (string, error)

Encrypt encrypts a string and base64 encodes the result

func ExtractJoinInfoForInstantInvalidate

func ExtractJoinInfoForInstantInvalidate(join []*model.JoinOption, joinKeysMapping map[string]map[string]string)

ExtractJoinInfoForInstantInvalidate extracts join info

func ExtractRequestParams

func ExtractRequestParams(r *http.Request, reqParams model.RequestParams, body interface{}) model.RequestParams

ExtractRequestParams extract request info from http request & stores it in reqParam variable

func GenerateJoinKeys

func GenerateJoinKeys(joinTable string, joinOn map[string]interface{}, databaseRow map[string]interface{}, joinKeysMapping map[string]map[string]string)

GenerateJoinKeys generates join keys

func GenerateJoinKeysForInstantInvalidate

func GenerateJoinKeysForInstantInvalidate(joinTable string, joinOn map[string]interface{}, joinKeysMapping map[string]map[string]string)

GenerateJoinKeysForInstantInvalidate generates join keys

func GetIDVariable

func GetIDVariable(dbAlias string) string

GetIDVariable gets the id variable for the provided db type

func GetTokenFromHeader

func GetTokenFromHeader(r *http.Request) string

GetTokenFromHeader returns the token from the request header

func HashString

func HashString(stringValue string) string

HashString hashes a string value and base64 encodes the result

func IsValidJoin

func IsValidJoin(on map[string]interface{}, jointTableName string) (bool, string)

IsValidJoin checks if join is valid

func JoinLeading

func JoinLeading(s1 string, s2 string, ch string) string

JoinLeading joins s1 and s2, using ch, and ensures ch occurs at the start

func JoinLeadingTrailing

func JoinLeadingTrailing(s1 string, s2 string, ch string) string

JoinLeadingTrailing joins s1 and s2, using ch, and ensures ch occurs at the start and end

func JoinTrailing

func JoinTrailing(s1 string, s2 string, ch string) string

JoinTrailing joins s1 and s2, using ch, and ensures ch occurs at the end

func LoadBool

func LoadBool(ctx context.Context, key interface{}, args map[string]interface{}) (bool, error)

LoadBool loads a key as a float. Throws error

func LoadNumber

func LoadNumber(ctx context.Context, key interface{}, args map[string]interface{}) (float64, error)

LoadNumber loads a key as a float. Throws error

func LoadStringIfExists

func LoadStringIfExists(value string, state map[string]interface{}) (string, error)

LoadStringIfExists loads a value if its present else returns the same

func LoadValue

func LoadValue(key string, state map[string]interface{}) (interface{}, error)

LoadValue loads a value from the state

func MakeHTTPRequest

func MakeHTTPRequest(ctx context.Context, request *HTTPRequest, vPtr interface{}) (int, error)

MakeHTTPRequest fires an http request and returns a response

func ParseGraphqlValue

func ParseGraphqlValue(value ast.Value, store M) (interface{}, error)

ParseGraphqlValue returns an interface that can be casted to string

func SingleLeading

func SingleLeading(s string, ch string) string

SingleLeading ensures that a string s starts with ch, but doesnt end with it

func SingleLeadingTrailing

func SingleLeadingTrailing(s string, ch string) string

SingleLeadingTrailing ensures that a string s starts and ends with single occurence of ch

func SingleTrailing

func SingleTrailing(s string, ch string) string

SingleTrailing ensures that a string s ends with ch, but doesnt start with it

func StoreValue

func StoreValue(ctx context.Context, key string, value interface{}, state map[string]interface{}) error

StoreValue -- stores a value in the provided state

func StoreValueInObject

func StoreValueInObject(key string, value interface{}, obj map[string]interface{}) error

StoreValueInObject -- stores a value in provided object

func StringExists

func StringExists(array []string, elements ...string) bool

StringExists returns true if the given string exists in the array

func Unzip

func Unzip(src string, dest string) error

Unzip unzips a source file to a given destination

func UserHomeDir

func UserHomeDir() string

UserHomeDir returns the path of home directory of user

func Validate

func Validate(dbType string, where map[string]interface{}, obj interface{}) bool

Validate checks if the provided document matches with the where clause

Types

type Array

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

Array is an atomic array

func NewArray

func NewArray(length int) *Array

NewArray creates a new array

func (*Array) Append

func (a *Array) Append(value interface{})

Append sets an item in the array at a particular index

func (*Array) GetAll

func (a *Array) GetAll() []interface{}

GetAll gets the array

func (*Array) Set

func (a *Array) Set(index int, value interface{})

Set sets an item in the array at a particular index

type Broker

type Broker string

Broker is the type of broker used by Space Cloud

const (
	// Nats is the type used for Nats
	Nats Broker = "nats"
)

type DatabaseCollections

type DatabaseCollections struct {
	TableName string `db:"table_name" json:"tableName"`
}

DatabaseCollections stores all callections of sql or postgres or mongo

type FileStoreType

type FileStoreType string

FileStoreType is the type of file store used

const (
	// Local is the type used for the local filesystem
	Local FileStoreType = "local"

	// AmazonS3 is the type used for the AmazonS3 storage
	AmazonS3 FileStoreType = "amazon-s3"

	// GCPStorage is the type used for the GCP storage
	GCPStorage FileStoreType = "gcp-storage"
)

type GetSecrets

type GetSecrets func(project, secretName, key string) (string, error)

GetSecrets gets fileStore and database secrets from runner

type HTTPRequest

type HTTPRequest struct {
	Headers        headers
	Method, URL    string
	Token, SCToken string
	Params         io.Reader
}

HTTPRequest describes the request object

type M

type M map[string]interface{}

M is a type for map

type Object

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

Object is an atomic array

func NewObject

func NewObject() *Object

NewObject creates a new atomic object

func (*Object) Get

func (obj *Object) Get(key string) (value interface{}, present bool)

Get gets the value of a key from the object

func (*Object) GetAll

func (obj *Object) GetAll() map[string]interface{}

GetAll returns the entire object

func (*Object) Set

func (obj *Object) Set(key string, value interface{})

Set sets a key in the object with a value

type OrchestratorType

type OrchestratorType string

OrchestratorType is the type of the orchestrator

const (
	// Kubernetes is the type used for a kubernetes deployement
	Kubernetes OrchestratorType = "kubernetes"
)

type RequestKind

type RequestKind string

RequestKind specifies the kind of the request

const (
	// RequestKindDirect is used when an http request is to be made directly
	RequestKindDirect RequestKind = "direct"

	// RequestKindConsulConnect is used when an http request is to be made via consul connect
	RequestKindConsulConnect RequestKind = "consul-connect"
)

type TypeMakeHTTPRequest

type TypeMakeHTTPRequest func(ctx context.Context, method, url, token, scToken string, params, vPtr interface{}) error

TypeMakeHTTPRequest makes a http request

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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