core

package
v0.6.4 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2023 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EnvironmentVariableDirective   = "environment_variables"
	ORM_ENV_VAR_NAME_SUFFIX        = "_PERSIST_ORM_CONNECTION"
	REDIS_PORT_ENV_VAR_NAME_SUFFIX = "_PERSIST_REDIS_PORT"
	REDIS_HOST_ENV_VAR_NAME_SUFFIX = "_PERSIST_REDIS_HOST"
	KLOTHO_PROXY_ENV_VAR_NAME      = "KLOTHO_PROXY_RESOURCE_NAME"
)
View Source
const (
	VerbAny     = Verb("ANY")
	VerbGet     = Verb("GET")
	VerbPost    = Verb("POST")
	VerbPut     = Verb("PUT")
	VerbDelete  = Verb("DELETE")
	VerbPatch   = Verb("PATCH")
	VerbOptions = Verb("OPTIONS")
	VerbHead    = Verb("HEAD")
)
View Source
const (
	ProviderGCP   = "gcp"
	ProviderAWS   = "aws"
	ProviderAzure = "azure"
)
View Source
const ConfigKind = "config"
View Source
const InternalKind = "internal"
View Source
const KlothoPayloadName = "InternalKlothoPayloads"
View Source
const PubSubKind = "pubsub"

Variables

View Source
var (
	ExecutableTypeNodeJS = ExecutableType("NodeJS")
	ExecutableTypePython = ExecutableType("Python")
	ExecutableTypeGolang = ExecutableType("Golang")
	ExecutableTypeCSharp = ExecutableType("CSharp")
)
View Source
var (
	GatewayKind             = "gateway"
	NetworkLoadBalancerKind = "nlb"

	Verbs = map[Verb]struct{}{
		VerbAny:     {},
		VerbGet:     {},
		VerbPost:    {},
		VerbPut:     {},
		VerbDelete:  {},
		VerbPatch:   {},
		VerbOptions: {},
		VerbHead:    {},
	}
)
View Source
var DiagramEntityToCode = TopoMap{
	{}: "",

	{Kind: GatewayKind}:                     `generic_network.Subnet("%s")`,
	{Kind: ExecutionUnitKind}:               `generic_compute.Rack("%s")`,
	{Kind: string(PersistKVKind)}:           `generic_storage.Storage("%s")`,
	{Kind: string(PersistFileKind)}:         `generic_storage.Storage("%s")`,
	{Kind: string(PersistSecretKind)}:       `generic_storage.Storage("%s")`,
	{Kind: string(PersistORMKind)}:          `generic_database.Sql("%s")`,
	{Kind: string(PersistRedisNodeKind)}:    `generic_storage.Storage("%s")`,
	{Kind: string(PersistRedisClusterKind)}: `generic_storage.Storage("%s")`,
	{Kind: PubSubKind}:                      `generic_blank.Blank("%s")`,

	{Kind: GatewayKind, Provider: ProviderAWS, Type: "apigateway"}: `aws_network.APIGateway("%s")`,
	{Kind: GatewayKind, Provider: ProviderAWS, Type: "alb"}:        `aws_network.ElbNetworkLoadBalancer("%s")`,

	{Kind: ExecutionUnitKind, Provider: ProviderAWS}:                    `aws_compute.Lambda("%s")`,
	{Kind: string(PersistKVKind), Provider: ProviderAWS}:                `aws_database.Dynamodb("%s")`,
	{Kind: string(PersistFileKind), Provider: ProviderAWS}:              `aws_storage.S3("%s")`,
	{Kind: string(PersistSecretKind), Provider: ProviderAWS}:            `aws_security.SecretsManager("%s")`,
	{Kind: string(PersistORMKind), Provider: ProviderAWS}:               `aws_database.RDS("%s")`,
	{Kind: string(PersistRedisNodeKind), Provider: ProviderAWS}:         `aws_database.ElasticacheForRedis("%s")`,
	{Kind: string(PersistRedisClusterKind), Provider: ProviderAWS}:      `aws_database.ElasticacheForRedis("%s")`,
	{Kind: string(PubSubKind), Provider: ProviderAWS}:                   `aws_integration.SNS("%s")`,
	{Kind: ConfigKind, Type: "secrets_manager", Provider: ProviderAWS}:  `aws_security.SecretsManager("%s")`,
	{Kind: ConfigKind, Type: "s3", Provider: ProviderAWS}:               `aws_storage.S3("%s")`,
	{Kind: ExecutionUnitKind, Type: "ecs", Provider: ProviderAWS}:       `aws_compute.Fargate("%s")`,
	{Kind: ExecutionUnitKind, Type: "eks", Provider: ProviderAWS}:       `aws_compute.EKS("%s")`,
	{Kind: ExecutionUnitKind, Type: "apprunner", Provider: ProviderAWS}: `generic_compute.Rack("AR: %s")`,
	{Kind: NetworkLoadBalancerKind, Provider: ProviderAWS}:              `aws_network.ElbNetworkLoadBalancer("%s")`,

	{Kind: GatewayKind, Provider: ProviderGCP}:               `custom.Custom("%s", "./images/gcp-api-gateway.png")`,
	{Kind: string(PersistKVKind), Provider: ProviderGCP}:     `gcp_database.Firestore("%s")`,
	{Kind: ExecutionUnitKind, Provider: ProviderGCP}:         `gcp_compute.Run("%s")`,
	{Kind: string(PersistFileKind), Provider: ProviderGCP}:   `gcp_storage.Filestore("%s")`,
	{Kind: string(PersistSecretKind), Provider: ProviderGCP}: `gcp_security.ResourceManager("%s")`,
	{Kind: string(PersistORMKind), Provider: ProviderGCP}:    `gcp_database.SQL("%s")`,
	{Kind: PubSubKind, Provider: ProviderGCP}:                `gcp_analytics.Pubsub("%s")`,

	{Kind: GatewayKind, Provider: ProviderAzure}:               `azure_network.ApplicationGateway("%s")`,
	{Kind: string(PersistKVKind), Provider: ProviderAzure}:     `azure_database.CosmosDb("%s")`,
	{Kind: ExecutionUnitKind, Provider: ProviderAzure}:         `azure_compute.FunctionApps("%s")`,
	{Kind: string(PersistFileKind), Provider: ProviderAzure}:   `azure_storage.BlobStorage("%s")`,
	{Kind: string(PersistSecretKind), Provider: ProviderAzure}: `azure_security.KeyVaults("%s")`,
	{Kind: string(PersistORMKind), Provider: ProviderAzure}:    `azure_database.SQLDatabases("%s")`,
	{Kind: PubSubKind, Provider: ProviderAzure}:                `azure_analytics.EventHubs("%s")`,
}

DiagramEntityToCode values are modules from https://github.com/CloudCompilers/topology-visualizer/blob/main/app/app.py and the class from https://github.com/mingrammer/diagrams/tree/master/diagrams

View Source
var DiagramEntityToImgPath = TopoMap{
	{}: "generic/blank/blank.png",

	{Kind: GatewayKind}:                     "generic/network/subnet.png",
	{Kind: ExecutionUnitKind}:               "generic/compute/rack.png",
	{Kind: string(PersistKVKind)}:           "generic/storage/storage.png",
	{Kind: string(PersistFileKind)}:         "generic/storage/storage.png",
	{Kind: string(PersistSecretKind)}:       "generic/storage/storage.png",
	{Kind: string(PersistORMKind)}:          "generic/database/sql.png",
	{Kind: string(PersistRedisNodeKind)}:    "generic/storage/storage.png",
	{Kind: string(PersistRedisClusterKind)}: "generic/storage/storage.png",
	{Kind: PubSubKind}:                      "generic/blank/blank.png",
	{Kind: ConfigKind}:                      "generic/storage/storage.png",

	{Kind: GatewayKind, Provider: ProviderAWS, Type: "apigateway"}:      "aws/network/api-gateway.png",
	{Kind: GatewayKind, Provider: ProviderAWS, Type: "alb"}:             "aws/network/elb-application-load-balancer.png",
	{Kind: ExecutionUnitKind, Provider: ProviderAWS}:                    "aws/compute/lambda.png",
	{Kind: string(PersistKVKind), Provider: ProviderAWS}:                "aws/database/dynamodb.png",
	{Kind: string(PersistFileKind), Provider: ProviderAWS}:              "aws/compute/simple-storage-service-s3.png",
	{Kind: string(PersistSecretKind), Provider: ProviderAWS}:            "aws/security/secrets-manager.png",
	{Kind: string(PersistORMKind), Provider: ProviderAWS}:               "aws/database/rds.png",
	{Kind: string(PersistRedisNodeKind), Provider: ProviderAWS}:         "aws/database/elasticache-for-redis.png",
	{Kind: string(PersistRedisClusterKind), Provider: ProviderAWS}:      "aws/database/elasticache-for-redis.png",
	{Kind: PubSubKind, Provider: ProviderAWS}:                           "aws/integration/simple-notification-service-sns.png",
	{Kind: NetworkLoadBalancerKind, Provider: ProviderAWS}:              "aws/network/elb-network-load-balancer.png",
	{Kind: ExecutionUnitKind, Type: "ecs", Provider: ProviderAWS}:       "aws/compute/fargate.png",
	{Kind: ExecutionUnitKind, Type: "eks", Provider: ProviderAWS}:       "aws/compute/elastic-kubernetes-service.png",
	{Kind: ExecutionUnitKind, Type: "apprunner", Provider: ProviderAWS}: "aws/compute/app-runner.png",
	{Kind: ConfigKind, Type: "secret_manager", Provider: ProviderAWS}:   "aws/security/secrets-manager.png",
	{Kind: ConfigKind, Type: "s3", Provider: ProviderAWS}:               "aws/compute/simple-storage-service-s3.png",

	{Kind: GatewayKind, Provider: ProviderGCP}:               "gcp/network/api-gateway.png",
	{Kind: ExecutionUnitKind, Provider: ProviderGCP}:         "gcp/compute/run.png",
	{Kind: string(PersistKVKind), Provider: ProviderGCP}:     "gcp/database/firestore.png",
	{Kind: string(PersistFileKind), Provider: ProviderGCP}:   "gcp/storage/filestore.png",
	{Kind: string(PersistSecretKind), Provider: ProviderGCP}: "gcp/security/resource-manager.png",
	{Kind: string(PersistORMKind), Provider: ProviderGCP}:    "gcp/database/sql.png",
	{Kind: PubSubKind, Provider: ProviderGCP}:                "gcp/analytics/pubsub.png",

	{Kind: GatewayKind, Provider: ProviderAzure}:               "azure/network/application-gateway.png",
	{Kind: ExecutionUnitKind, Provider: ProviderAzure}:         "azure/compute/function-apps.png",
	{Kind: string(PersistKVKind), Provider: ProviderAzure}:     "azure/database/cosmos-db.png",
	{Kind: string(PersistFileKind), Provider: ProviderAzure}:   "azure/storage/blob-storage.png",
	{Kind: string(PersistSecretKind), Provider: ProviderAzure}: "azure/security/key-vaults.png",
	{Kind: string(PersistORMKind), Provider: ProviderAzure}:    "azure/database/sql-databases.png",
	{Kind: PubSubKind, Provider: ProviderAzure}:                "azure/analytics/event-hubs.png",
}

DiagramEntityToImgPath values are relative to the base URL: https://github.com/mingrammer/diagrams/tree/master/resources

View Source
var ExecutionUnitKind = "exec_unit"
View Source
var InfraAsCodeKind = "infra_as_code"
View Source
var InputFilesKind = "input_files"
View Source
var InternalStorageVariable = EnvironmentVariable{
	Name:       KLOTHO_PROXY_ENV_VAR_NAME,
	Kind:       InternalKind,
	ResourceID: KlothoPayloadName,
	Value:      string(BUCKET_NAME),
}
View Source
var StaticUnitKind = "static_unit"
View Source
var TopologyKind = "topology"

Functions

func CheckForProjectFile

func CheckForProjectFile(result *CompilationResult, unit *ExecutionUnit, filename string) string

CheckForProjectFile will find an existing inputFile, corresponding to the filename param,that best matches the path where the execution unit annotation lives and returns the path to the corresponding project file

func ContainsCapability

func ContainsCapability(a *SourceFile, capName string) bool

ContainsCapability returns whether 'a' is annotated with a capability of the supplied capability name

func FileExecUnitName

func FileExecUnitName(f *SourceFile) string

func FilePathMatchesGlob

func FilePathMatchesGlob(patterns ...string) predicate.Predicate[File]

func GetFirstResource

func GetFirstResource[T CloudResource](result *CompilationResult) (res T)

func GetResourcesOfType

func GetResourcesOfType[T CloudResource](result *CompilationResult) (filtered []T)

func InSameExecutionUnit

func InSameExecutionUnit(a, b *SourceFile) bool

func LowerCaseFilePathMatchesGlob

func LowerCaseFilePathMatchesGlob(patterns ...string) predicate.Predicate[File]

Types

type Annotation

type Annotation struct {
	Capability *annotation.Capability
	// Node is the node that has been annotated; not the comment node representing the annotation itself.
	Node *sitter.Node
}

func (Annotation) Format

func (a Annotation) Format(s fmt.State, verb rune)

func (Annotation) Key

func (a Annotation) Key() AnnotationKey

func (*Annotation) MarshalJSON

func (a *Annotation) MarshalJSON() ([]byte, error)

type AnnotationKey

type AnnotationKey struct {
	Capability string
	ID         string
}

type AnnotationMap

type AnnotationMap map[AnnotationKey]*Annotation

func (AnnotationMap) Add

func (m AnnotationMap) Add(a *Annotation)

func (AnnotationMap) InSourceOrder

func (m AnnotationMap) InSourceOrder() []*Annotation

InSourceOrder returns a list of annotations in the order they are defined.

func (AnnotationMap) Update

func (m AnnotationMap) Update(other AnnotationMap)

type CapabilityFinder

type CapabilityFinder interface {
	FindAllCapabilities(*SourceFile) (AnnotationMap, error)
}

type CloudResource

type CloudResource interface {
	// Key returns the unique identifier for the resource.
	Key() ResourceKey
}

type Commenter

type Commenter func(string) string

type CompilationResult

type CompilationResult ConcurrentMap[ResourceKey, CloudResource]

func (*CompilationResult) Add

func (result *CompilationResult) Add(resource CloudResource)

func (*CompilationResult) AddAll

func (result *CompilationResult) AddAll(ress []CloudResource)

func (*CompilationResult) Get

func (result *CompilationResult) Get(key ResourceKey) CloudResource

func (*CompilationResult) GetExecUnitForPath

func (result *CompilationResult) GetExecUnitForPath(fp string) (*ExecutionUnit, File)

func (*CompilationResult) GetFirstResource

func (result *CompilationResult) GetFirstResource(rType string) (res CloudResource)

GetFirstResource returns the first resource found of type `rType` or nil if not found.

func (*CompilationResult) GetResourcesOfType

func (result *CompilationResult) GetResourcesOfType(rType string) (filtered []CloudResource)

func (*CompilationResult) Keys

func (result *CompilationResult) Keys() []ResourceKey

func (*CompilationResult) Len

func (result *CompilationResult) Len() int

func (*CompilationResult) Resources

func (result *CompilationResult) Resources() []CloudResource

type CompileError

type CompileError struct {
	File       *SourceFile
	Annotation *Annotation
	Cause      error
}

func NewCompilerError

func NewCompilerError(f *SourceFile, annotation *Annotation, cause error) *CompileError

func (*CompileError) Error

func (err *CompileError) Error() string

func (*CompileError) Format

func (err *CompileError) Format(s fmt.State, verb rune)

func (*CompileError) Unwrap

func (err *CompileError) Unwrap() error

type Compiler

type Compiler struct {
	Plugins []Plugin
}

func (*Compiler) Compile

func (c *Compiler) Compile(main *InputFiles) (*CompilationResult, error)

type ConcurrentMap

type ConcurrentMap[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func (*ConcurrentMap[K, V]) AddAll

func (cf *ConcurrentMap[K, V]) AddAll(entries map[K]V)

func (*ConcurrentMap[K, V]) Compute

func (cf *ConcurrentMap[K, V]) Compute(k K, computeFunc func(k K, v V) (val V, ok bool))

Compute sets the value of key 'k' to the result of the supplied computeFunc. If the value of 'ok' is 'false', the entry for key 'k' will be removed from the ConcurrentMap.

func (*ConcurrentMap[K, V]) Delete

func (cf *ConcurrentMap[K, V]) Delete(k K) (v V, existed bool)

func (*ConcurrentMap[K, V]) Each

func (cf *ConcurrentMap[K, V]) Each(f func(k K, v V) (stop bool))

Each executes `f` for each key-value pair in the map, while holding the lock. ! Avoid doing expensive operations in `f`, instead create a copy (eg via `Entries()`).

func (*ConcurrentMap[K, V]) Entries

func (cf *ConcurrentMap[K, V]) Entries() []MapEntry[K, V]

func (*ConcurrentMap[K, V]) Get

func (cf *ConcurrentMap[K, V]) Get(k K) (v V, ok bool)

func (*ConcurrentMap[K, V]) Keys

func (cf *ConcurrentMap[K, V]) Keys() []K

func (*ConcurrentMap[K, V]) Len

func (cf *ConcurrentMap[K, V]) Len() int

func (*ConcurrentMap[K, V]) Set

func (cf *ConcurrentMap[K, V]) Set(k K, v V)

func (*ConcurrentMap[K, V]) Values

func (cf *ConcurrentMap[K, V]) Values() []V

type Config added in v0.6.3

type Config struct {
	Name   string
	Secret bool
}

func (*Config) Key added in v0.6.3

func (p *Config) Key() ResourceKey

type CountingWriter

type CountingWriter struct {
	Delegate     io.Writer
	BytesWritten int
}

func (*CountingWriter) Write

func (w *CountingWriter) Write(p []byte) (int, error)

type Dependencies

type Dependencies ConcurrentMap[Dependency, struct{}]

func (*Dependencies) Add

func (d *Dependencies) Add(source ResourceKey, target ResourceKey)

func (*Dependencies) Clone

func (d *Dependencies) Clone() *Dependencies

func (*Dependencies) Contains

func (d *Dependencies) Contains(dep Dependency) bool

func (*Dependencies) Downstream

func (d *Dependencies) Downstream(source ResourceKey) (targets []ResourceKey)

func (*Dependencies) Remove

func (d *Dependencies) Remove(source ResourceKey, target ResourceKey) bool

func (*Dependencies) RemoveSource

func (d *Dependencies) RemoveSource(source ResourceKey) (changed bool)

func (*Dependencies) RemoveTarget

func (d *Dependencies) RemoveTarget(target ResourceKey) (changed bool)

func (*Dependencies) String

func (d *Dependencies) String() string

func (*Dependencies) ToArray

func (d *Dependencies) ToArray() []Dependency

func (*Dependencies) Upstream

func (d *Dependencies) Upstream(target ResourceKey) (sources []ResourceKey)

type Dependency

type Dependency struct {
	Source ResourceKey
	Target ResourceKey
}

type EnvironmentVariable

type EnvironmentVariable struct {
	Name       string
	Kind       string
	ResourceID string
	Value      string
}

func GenerateOrmConnStringEnvVar

func GenerateOrmConnStringEnvVar(id string, kind string) EnvironmentVariable

func GenerateRedisHostEnvVar

func GenerateRedisHostEnvVar(id string, kind string) EnvironmentVariable

func GenerateRedisPortEnvVar

func GenerateRedisPortEnvVar(id string, kind string) EnvironmentVariable

type EnvironmentVariableValue

type EnvironmentVariableValue string
var (
	HOST              EnvironmentVariableValue = "host"
	PORT              EnvironmentVariableValue = "port"
	CONNECTION_STRING EnvironmentVariableValue = "connection_string"
	BUCKET_NAME       EnvironmentVariableValue = "bucket_name"
)

type EnvironmentVariables added in v0.6.3

type EnvironmentVariables []EnvironmentVariable

func (*EnvironmentVariables) Add added in v0.6.3

Add the given environment variable to the list. If a variable of the same name already exists, replace it.

func (*EnvironmentVariables) AddAll added in v0.6.3

func (vars *EnvironmentVariables) AddAll(vs EnvironmentVariables)

AddAll is a convenience over `Add` to add many variables.

type Event

type Event struct {
	Name        string
	Publishers  []ResourceKey
	Subscribers []ResourceKey
}

type EventReference

type EventReference struct {
	ResourceKey
	FilePath string
}

type Executable

type Executable struct {
	Type ExecutableType

	// Entrypoints is a set of paths to source files that act as entrypoints to the Executable
	// These entrypoints are used by execunit.SourceFilesResolver as root nodes in the Executable's
	// dependency tree when resolving its set of SourceFiles.
	Entrypoints map[string]struct{}

	// Resources is a set of paths to files in the Executable's owning ExecutionUnit that represent
	// non source files required by the Executable (e.g. NodeJS's package.json file).
	Resources map[string]struct{}

	// SourceFiles is a set of paths to files in the Executable's owning ExecutionUnit that represent
	// source files that compose the Executable's application code
	SourceFiles map[string]struct{}

	// SourceFiles is a set of paths to files in the Executable's owning ExecutionUnit that represent
	// files that have been statically included for runtime use rather than active processing by the compiler.
	StaticAssets map[string]struct{}
}

Executable represents the slice of a project that is deployed to and executed on an ExecutionUnit

func NewExecutable

func NewExecutable() Executable

func (*Executable) RemoveFile

func (e *Executable) RemoveFile(path string)

type ExecutableType

type ExecutableType string

type ExecutionUnit

type ExecutionUnit struct {
	Name string

	Executable           Executable
	EnvironmentVariables EnvironmentVariables
	DockerfilePath       string
	// contains filtered or unexported fields
}

func (*ExecutionUnit) Add

func (unit *ExecutionUnit) Add(f File)

func (*ExecutionUnit) AddEntrypoint

func (unit *ExecutionUnit) AddEntrypoint(f File)

func (*ExecutionUnit) AddResource

func (unit *ExecutionUnit) AddResource(f File)

func (*ExecutionUnit) AddSourceFile

func (unit *ExecutionUnit) AddSourceFile(f File)

func (*ExecutionUnit) AddStaticAsset

func (unit *ExecutionUnit) AddStaticAsset(f File)

func (*ExecutionUnit) Files

func (unit *ExecutionUnit) Files() map[string]File

func (*ExecutionUnit) FilesOfLang

func (unit *ExecutionUnit) FilesOfLang(lang LanguageId) []*SourceFile

func (*ExecutionUnit) Get

func (unit *ExecutionUnit) Get(path string) File

func (*ExecutionUnit) GetDeclaringFiles

func (unit *ExecutionUnit) GetDeclaringFiles() []*SourceFile

GetDeclaringFiles returns a slice of files containing capability declarations for this ExecutionUnit

func (*ExecutionUnit) HasSourceFilesFor

func (unit *ExecutionUnit) HasSourceFilesFor(language LanguageId) bool

func (*ExecutionUnit) Key

func (unit *ExecutionUnit) Key() ResourceKey

func (*ExecutionUnit) OutputTo

func (unit *ExecutionUnit) OutputTo(dest string) error

func (*ExecutionUnit) Remove

func (unit *ExecutionUnit) Remove(path string)

type File

type File interface {
	Path() string
	WriteTo(io.Writer) (int64, error)
	Clone() File
}

type FileRef

type FileRef struct {
	FPath          string
	RootConfigPath string
}

FileRef is a lightweight representation of a file, deferring reading its contents until `WriteTo` is called.

func (*FileRef) Clone

func (r *FileRef) Clone() File

func (*FileRef) Path

func (r *FileRef) Path() string

func (*FileRef) WriteTo

func (r *FileRef) WriteTo(w io.Writer) (int64, error)

type Gateway

type Gateway struct {
	Name   string
	Routes []Route
	// Map of gateway targets with the exec unit name as the key
	DefinedIn     string
	ExportVarName string
}

func FindUpstreamGateways

func FindUpstreamGateways(unit *ExecutionUnit, result *CompilationResult, deps *Dependencies) []*Gateway

func NewGateway

func NewGateway(name string) *Gateway

func (*Gateway) AddRoute

func (gw *Gateway) AddRoute(route Route, unit *ExecutionUnit) string

func (*Gateway) Key

func (gw *Gateway) Key() ResourceKey

type HasLocalOutput

type HasLocalOutput interface {
	OutputTo(dest string) error
}

type InfraFiles

type InfraFiles struct {
	Name  string
	Files ConcurrentMap[string, File]
}

func (*InfraFiles) Add

func (unit *InfraFiles) Add(f File)

func (*InfraFiles) Key

func (iac *InfraFiles) Key() ResourceKey

func (*InfraFiles) OutputTo

func (iac *InfraFiles) OutputTo(dest string) error

type InputFiles

type InputFiles ConcurrentMap[string, File]

func (*InputFiles) Add

func (input *InputFiles) Add(f File)

func (*InputFiles) Files

func (input *InputFiles) Files() map[string]File

func (*InputFiles) FilesOfLang

func (input *InputFiles) FilesOfLang(lang LanguageId) []*SourceFile

func (*InputFiles) Key

func (*InputFiles) Key() ResourceKey

type InternalResource added in v0.6.3

type InternalResource struct {
	Name string
}

func (*InternalResource) Key added in v0.6.3

func (p *InternalResource) Key() ResourceKey

type LanguageId

type LanguageId string

func (LanguageId) CastFile

func (lid LanguageId) CastFile(f File) (*SourceFile, bool)

type MapEntry

type MapEntry[K comparable, V any] struct {
	Key   K
	Value V
}

type NodeContent

type NodeContent struct {
	Endpoints NodeEndpoints
	Content   string
}

func (NodeContent) Format

func (n NodeContent) Format(s fmt.State, verb rune)

type NodeEndpoints

type NodeEndpoints interface {
	StartPoint() sitter.Point
	EndPoint() sitter.Point
}

type NonOverwritable

type NonOverwritable interface {
	Overwrite(*os.File) bool
}

type Persist

type Persist struct {
	Name string
	Kind PersistKind
}

func (*Persist) Key

func (p *Persist) Key() ResourceKey

type PersistKind

type PersistKind string
const (
	PersistKVKind           PersistKind = "persist_kv"
	PersistFileKind         PersistKind = "persist_fs"
	PersistSecretKind       PersistKind = "persist_secret"
	PersistORMKind          PersistKind = "persist_orm"
	PersistRedisNodeKind    PersistKind = "persist_redis_node"
	PersistRedisClusterKind PersistKind = "persist_redis_cluster"
)

type Plugin

type Plugin interface {
	Name() string

	// Transform is expected to mutate the result and any dependencies
	Transform(*CompilationResult, *Dependencies) error
}

type PluginError

type PluginError struct {
	Plugin string
	Cause  error
}

func NewPluginError

func NewPluginError(name string, cause error) *PluginError

func (*PluginError) Error

func (err *PluginError) Error() string

func (*PluginError) Format

func (err *PluginError) Format(s fmt.State, verb rune)

func (*PluginError) Unwrap

func (err *PluginError) Unwrap() error

type PubSub

type PubSub struct {
	Path   string
	Name   string
	Events map[string]*Event
}

func (*PubSub) AddPublisher

func (p *PubSub) AddPublisher(event string, key ResourceKey)

func (*PubSub) AddSubscriber

func (p *PubSub) AddSubscriber(event string, key ResourceKey)

func (*PubSub) EventNames

func (p *PubSub) EventNames() (e []string)

func (PubSub) Key

func (p PubSub) Key() ResourceKey

type RawFile

type RawFile struct {
	FPath   string
	Content []byte
}

RawFile represents a file with its included `Content` in case the compiler needs to read/manipulate it. If the content is not needed except to `WriteTo`, then try using FileRef instead.

func (*RawFile) Clone

func (r *RawFile) Clone() File

func (*RawFile) Path

func (r *RawFile) Path() string

func (*RawFile) WriteTo

func (r *RawFile) WriteTo(w io.Writer) (int64, error)

type ResourceKey

type ResourceKey struct {
	// Kind is the kind of resource it is such as `exec_unit`, `persist_kv`, etc
	Kind string
	// Name must be unique to the compilation for the `Kind` of resource.
	Name string
}

func (ResourceKey) String

func (k ResourceKey) String() string

type ResourcesOrErr

type ResourcesOrErr struct {
	Resources []CloudResource
	Err       error
}

ResourcesOrErr provided as commonly used in async operations for the result channel.

type Route

type Route struct {
	// Path should be expressed using Express's route path syntax or a subset thereof
	// (see: http://expressjs.com/en/4x/api.html#path-examples)
	Path         string
	ExecUnitName string
	Verb         Verb
	// HandledInFile is the path to the file which this route is defined/handled in
	HandledInFile string
}

type Secrets

type Secrets struct {
	Persist
	Secrets []string
}

type SourceFile

type SourceFile struct {
	Language SourceLanguage
	// contains filtered or unexported fields
}

func NewSourceFile

func NewSourceFile(path string, content io.Reader, language SourceLanguage) (f *SourceFile, err error)

func (*SourceFile) Annotations

func (f *SourceFile) Annotations() AnnotationMap

func (*SourceFile) Clone

func (f *SourceFile) Clone() File

func (*SourceFile) CloneSourceFile

func (f *SourceFile) CloneSourceFile() *SourceFile

CloneSourceFile implements the same behavior as `Clone()` (from the `File` interface), but returns the result as a `*SourceFile` so that you don't need to cast it.

func (*SourceFile) IsAnnotatedWith

func (f *SourceFile) IsAnnotatedWith(capability string) bool

func (*SourceFile) Path

func (f *SourceFile) Path() string

func (*SourceFile) Program

func (f *SourceFile) Program() []byte

func (*SourceFile) Reparse

func (f *SourceFile) Reparse(newProgram []byte) (err error)

func (*SourceFile) ReplaceNodeContent

func (f *SourceFile) ReplaceNodeContent(node *sitter.Node, content string) error

func (*SourceFile) Tree

func (f *SourceFile) Tree() *sitter.Tree

func (*SourceFile) WriteTo

func (f *SourceFile) WriteTo(out io.Writer) (int64, error)

type SourceLanguage

type SourceLanguage struct {
	ID               LanguageId
	Sitter           *sitter.Language
	CapabilityFinder CapabilityFinder
	TurnIntoComment  Commenter
}

type StaticUnit

type StaticUnit struct {
	Name          string
	IndexDocument string
	StaticFiles   ConcurrentMap[string, File]
	SharedFiles   ConcurrentMap[string, File]
}

func (*StaticUnit) AddSharedFile

func (unit *StaticUnit) AddSharedFile(f File)

func (*StaticUnit) AddStaticFile

func (unit *StaticUnit) AddStaticFile(f File)

func (*StaticUnit) Files

func (unit *StaticUnit) Files() map[string]File

func (*StaticUnit) GetSharedFile

func (unit *StaticUnit) GetSharedFile(path string) File

func (*StaticUnit) GetStaticFile

func (unit *StaticUnit) GetStaticFile(path string) File

func (*StaticUnit) Key

func (unit *StaticUnit) Key() ResourceKey

func (*StaticUnit) OutputTo

func (unit *StaticUnit) OutputTo(dest string) error

func (*StaticUnit) RemoveSharedFile

func (unit *StaticUnit) RemoveSharedFile(path string)

func (*StaticUnit) RemoveStaticFile

func (unit *StaticUnit) RemoveStaticFile(path string)

type TopoKey

type TopoKey struct {
	Kind     string
	Type     string
	Provider string
}

type TopoMap

type TopoMap map[TopoKey]string

func (TopoMap) Get

func (m TopoMap) Get(kind string, resType string, provider string) (string, TopoKey)

Get returns an exact match for `k` if present, otherwise fallback to `resType = ""` then further to `provider = ""`. Finally, if no matches, uses the default/blank of `kind = ""` (all fields empty). Returns the value and the Key which resolved to that value.

type Topology

type Topology struct {
	Name string
	// contains filtered or unexported fields
}

func NewTopology

func NewTopology(name string, data TopologyData, image []byte) *Topology

func (*Topology) GetTopologyData

func (t *Topology) GetTopologyData() TopologyData

func (*Topology) Key

func (t *Topology) Key() ResourceKey

func (*Topology) OutputTo

func (t *Topology) OutputTo(dest string) error

func (Topology) Type

func (Topology) Type() string

type TopologyData

type TopologyData struct {
	IconData []TopologyIconData `json:"topologyIconData"`
	EdgeData []TopologyEdgeData `json:"topologyEdgeData"`
}

type TopologyEdgeData

type TopologyEdgeData struct {
	Source string `json:"source"`
	Target string `json:"target"`
}

type TopologyIconData

type TopologyIconData struct {
	ID    string `json:"id"`
	Title string `json:"title"`
	Image string `json:"image"`
	Kind  string `json:"kind"`
	Type  string `json:"type"`
}

type Verb

type Verb string

Verb is the HTTP verb used in the route. May be upper or lower case, users are expected to convert to their needs.

func (Verb) String added in v0.6.3

func (v Verb) String() string

type WrappedError

type WrappedError struct {
	Message string
	Cause   error
	Stack   errors.StackTrace
}

func WrapErrf

func WrapErrf(err error, msg string, args ...interface{}) *WrappedError

func (*WrappedError) Error

func (err *WrappedError) Error() string

func (*WrappedError) Format

func (err *WrappedError) Format(s fmt.State, verb rune)

func (*WrappedError) Unwrap

func (err *WrappedError) Unwrap() error

Jump to

Keyboard shortcuts

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