models

package
v0.0.0-...-55321f0 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2019 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ResourceBox is the packr box containing the resource file templates
	ResourceBox = packr.New("resource", "../../templates/resource")
	// FunctionBox is the packr box containing the function file templates
	FunctionBox = packr.New("function", "../../templates/function")
	// MakeBox is the packr box containing the Makefile template
	MakeBox = packr.New("make", "../../templates/make")
)

Functions

func Contains

func Contains(s []string, v string) bool

Contains checks whether a string slice contains a given string

func CreateLambdaNetwork

func CreateLambdaNetwork()

CreateLambdaNetwork spins up a lambda network for dynamodb and AWS SAM to interact with one another

func GetFuncName

func GetFuncName(resourceName, functionName string) string

GetFuncName returns the generated function name for a given resource/ function group name and a functionName

func GetList

func GetList(projectPath, wish string) []string

GetList returns the list of deployable/ debugable resources/ function groups

func GetWorkingDir

func GetWorkingDir() string

GetWorkingDir get the directory the current command is run out of

func LoadTemplateFromBox

func LoadTemplateFromBox(b *packr.Box, file string) *template.Template

LoadTemplateFromBox loads a *text/template.Template from a packr.Box

func RemoveFiles

func RemoveFiles(pPath, aName, fName string)

RemoveFiles ...

func RunCmd

func RunCmd(name string, args ...string)

RunCmd will run an OS command with the given arguments

func RunCmdWithEnv

func RunCmdWithEnv(envs []string, name string, args ...string)

RunCmdWithEnv will run an OS command with the given arguments and an environment

func StartLocalDynamoDB

func StartLocalDynamoDB()

StartLocalDynamoDB spins up the dynamodb-local docker image

Types

type ALBEvent

type ALBEvent struct {
	ListenerARN string            `yaml:"listenerArn"`
	Priority    int               `yaml:",omitempty"`
	Conditions  map[string]string `yaml:",omitempty"`
}

ALBEvent ...

type AlexaEvent

type AlexaEvent struct {
	AppID   string `yaml:"appId"`
	Enabled bool   `yaml:",omitempty"`
}

AlexaEvent ...

type Attribute

type Attribute struct {
	Name    string      `json:"name"`
	Ident   flect.Ident `json:"ident"`
	GoType  string      `json:"go_type"`
	AwsType string      `json:"aws_type"`
}

Attribute represents a resource model's attribute

func (Attribute) String

func (a Attribute) String() string

String returns the string representation of an attribute

type AttributeDef

type AttributeDef struct {
	AttributeName string `yaml:"AttributeName"`
	AttributeType string `yaml:"AttributeType"`
}

AttributeDef ...

type AttributeDefinition

type AttributeDefinition struct {
	Ident   flect.Ident `json:"ident"`
	AwsType string      `json:"aws_type"`
}

AttributeDefinition represents the definition of a resource's attribute

type Authorizer

type Authorizer struct {
	ARN                          string
	Name                         string `yaml:",omitempty"`
	ResultTTL                    int    `yaml:"resultTtlInSeconds,omitempty"`
	IdentitySource               string `yaml:"identitySource,omitempty"`
	IdentityValidationExpression string `yaml:"identityValidationExpression,omitempty"`
	Type                         string `yaml:",omitempty"`
}

Authorizer ...

type CognitoEvent

type CognitoEvent struct {
	Pool     string
	Trigger  string
	Existing bool
}

CognitoEvent ...

type CustomDomainConfig

type CustomDomainConfig struct {
	BasePath            string `yaml:"basePath"`
	DomanName           string `yaml:"domainName"`
	Stage               string
	CreateRoute53Record bool `yaml:"createRoute53Record"`
}

CustomDomainConfig ...

type DeploymentBucket

type DeploymentBucket struct {
	Name string
	SSE  string            `yaml:"serverSideEncryption,omitempty"`
	Tags map[string]string `yaml:",omitempty"`
}

DeploymentBucket ...

type DomainConfig

type DomainConfig struct {
	Stage        string
	Domains      map[string]string  `yaml:",omitempty"`
	CustomDomain CustomDomainConfig `yaml:"customDoman"`
}

DomainConfig ...

type Events

type Events struct {
	HTTP            *HTTPEvent      `yaml:"http,omitempty"`
	WebSocket       *WebSocketEvent `yaml:"websocket,omitempty"`
	S3              *S3Event        `yaml:"s3,omitempty"`
	Schedule        *ScheduleEvent  `yaml:"schedule,omitempty"`
	SNS             *SNSEvent       `yaml:"sns,omitempty"`
	SQS             *SQSEvent       `yaml:"sqs,omitempty"`
	Stream          *StreamEvent    `yaml:"stream,omitempty"`
	AlexaSkill      *AlexaEvent     `yaml:"alexaSkill,omitempty"`
	AlexaSmartHome  *AlexaEvent     `yaml:"alexaSmartHome,omitempty"`
	IOT             *IOTEvent       `yaml:"iot,omitempty"`
	CognitoUserPool *CognitoEvent   `yaml:"cognitoUserPool,omitempty"`
	ALB             *ALBEvent       `yaml:"alb,omitempty"`
}

Events ...

type FnEnvironment

type FnEnvironment struct {
	Variables map[string]string `yaml:"Variables"`
}

FnEnvironment ...

type Function

type Function struct {
	Name    string `json:"name"`
	Handler string `json:"handler"`
	Path    string `json:"path"`
	Method  string `json:"method"`

	Authentication bool `json:"authentication"`
}

Function represents a Function

type GlobalConfig

type GlobalConfig struct {
	Function SAMFnProp `yaml:"Function"`
}

GlobalConfig ...

type GlobalIndex

type GlobalIndex struct {
	IndexName             string                 `yaml:"IndexName"`
	KeySchema             []KeySchema            `yaml:"KeySchema"`
	Projection            Projection             `yaml:"Projection"`
	ProvisionedThroughput *ProvisionedThroughput `yaml:"ProvisionedTroughput,omitempty"`
}

GlobalIndex ...

type HTTPEvent

type HTTPEvent struct {
	Path       string
	Method     string
	CORS       bool        `yaml:",omitempty"`
	Private    bool        `yaml:",omitempty"`
	Authorizer *Authorizer `yaml:",omitempty"`
	Scopes     []string    `yaml:",omitempty"`
}

HTTPEvent ...

type IOTEvent

type IOTEvent struct {
	Name        string `yaml:",omitempty"`
	Description string `yaml:",omitempty"`
	Enabled     bool   `yaml:",omitempty"`
	SQL         string `yaml:"sql,omitempty"`
	SQLVersion  string `yaml:"sqlVersion,omitempty"`
}

IOTEvent ...

type KeySchema

type KeySchema struct {
	AttributeName string `yaml:"AttributeName"`
	KeyType       string `yaml:"KeyType"`
}

KeySchema ...

type Layer

type Layer struct {
	Path               string
	Name               string   `yaml:",omitempty"`
	Description        string   `yaml:",omitempty"`
	CompatibleRuntimes []string `yaml:"compatibleRuntimes,omitempty"`
	License            string   `yaml:"licenseInfo,omitempty"`
	AllowedAccounts    []string `yaml:"allowedAccounts,omitempty"`
	Retain             bool     `yaml:",omitempty"`
}

Layer ...

type LocalIndex

type LocalIndex struct {
	IndexName  string      `yaml:"IndexName"`
	KeySchema  []KeySchema `yaml:"KeySchema"`
	Projection Projection  `yaml:"Projection"`
}

LocalIndex ...

type LogConfig

type LogConfig struct {
	RESTAPI   bool `yaml:"restApi,omitempty"`
	WebSocket bool `yaml:"websocket,omitempty"`
}

LogConfig ...

type MUGConfig

type MUGConfig struct {
	ProjectName string
	ProjectPath string
	ImportPath  string
	Region      string
	Resources   map[string]*NewResource
}

MUGConfig ...

func ReadMUGConfig

func ReadMUGConfig() MUGConfig

ReadMUGConfig ...

func (MUGConfig) CreateResourceTables

func (m MUGConfig) CreateResourceTables(list []string, mode string, overwrite bool)

CreateResourceTables creates the tables in the local DynamoDB named by the given mode

func (MUGConfig) MakeBuild

func (m MUGConfig) MakeBuild(list []string, test bool)

MakeBuild renders the Makefile and builds the binaries

func (MUGConfig) MakeDebug

func (m MUGConfig) MakeDebug(list []string)

MakeDebug renders the Makefile and builds the debug binaries

func (MUGConfig) NewServerlessConfig

func (m MUGConfig) NewServerlessConfig(resource string) ServerlessConfig

NewServerlessConfig return a new ServerlessConfig with the attributes from the MUGConfig NewFromResourceConfig returns a ServerlessConfig from a provided ResourceConfig

func (MUGConfig) ReadServerlessConfig

func (m MUGConfig) ReadServerlessConfig(rn string) ServerlessConfig

ReadServerlessConfig reads the ServerlessConfig from serverless.yml in the resource or function group directory. If a serverless.yml file does not exist, a new default ServerlessConfig is returned

func (*MUGConfig) RemoveResource

func (m *MUGConfig) RemoveResource(rN string)

RemoveResource removes a given resource from the MUGConfig and ServerlessConfig

func (MUGConfig) Write

func (m MUGConfig) Write()

Write write the MUGConfig to mug.config.json in the project path

type Model

type Model struct {
	Name          string               `json:"name"`
	Type          string               `json:"type"`
	Ident         flect.Ident          `json:"ident"`
	Attributes    map[string]Attribute `json:"attributes"`
	Nested        []Model              `json:"nested"`
	Imports       []string             `json:"imports"`
	KeySchema     map[string]string    `json:"key_schema"`
	GeneratedID   bool                 `json:"generated_id"`
	CompositeKey  bool                 `json:"composite_key"`
	BillingMode   string               `json:"billing_mode"`
	CapacityUnits map[string]int64     `json:"capacity_units"`
}

Model represents a resource model object

func New

func New(name string, slice bool, attributes string, options map[string]interface{}) Model

New returns a new model object

func (Model) GetConfigs

func (m Model) GetConfigs() (MUGConfig, ServerlessConfig)

GetConfigs returns the MUGConfig and ServerlessConfig for this Model

func (*Model) GetImports

func (m *Model) GetImports() []string

GetImports recursively iterates through all import slices and adds the import to the root model

func (Model) String

func (m Model) String() string

String prints a representation of a model

func (Model) Write

func (m Model) Write(path string)

Write write the Model definition to the modelName.json

type NewResource

type NewResource struct {
	Ident      flect.Ident
	Attributes map[string]AttributeDefinition
}

NewResource ...

type Package

type Package struct {
	Excludes     []string `yaml:"exclude,omitempty"`
	Includes     []string `yaml:"include,omitempty"`
	Individually bool     `yaml:",omitempty"`
}

Package ...

type Projection

type Projection struct {
	NonKeyAttributes []string `yaml:"NonKeyAttributes,omitempty"`
	ProjectionType   string   `yaml:"ProjectionType,omitempty"`
}

Projection ...

type Properties

type Properties struct {
	// Properties for Resources
	AttributeDefinitions   []AttributeDef         `yaml:"AttributeDefinitions,omitempty"`
	KeySchema              []KeySchema            `yaml:"KeySchema,omitempty"`
	ProvisionedThroughput  *ProvisionedThroughput `yaml:"ProvisionedThroughput,omitempty"`
	BillingMode            string                 `yaml:"BillingMode,omitempty"`
	TableName              string                 `yaml:"TableName,omitempty"`
	LocalSecondaryIndexes  []LocalIndex           `yaml:"LocalSecondaryIndexes,omitempty"`
	GlobalSecondaryIndexes []GlobalIndex          `yaml:"GlobalSecondaryIndexes,omitempty"`
	TTLSpecification       TTLSpecification       `yaml:"TimeToLiveSpecification,omitempty"`

	//Properties for Authorizer
	Name           string    `yaml:"Name,omitempty"`
	IdentitySource string    `yaml:"IdentitySource,omitempty"`
	RestAPIID      Reference `yaml:"RestApiId,omitempty"`
	Type           string    `yaml:"Type,omitempty"`
	ProviderARNs   []string  `yaml:"ProviderARNs,omitempty"`
}

Properties ...

type Provider

type Provider struct {
	Name                string
	Runtime             string
	Region              string
	Stage               string
	StackName           string `yaml:"stackName,omitempty"`
	APIName             string `yaml:"apiName,omitempty"`
	Profile             string `yaml:",omitempty"`
	MemSize             string `yaml:"memorySize,omitempty"`
	ReservedConcurrency int    `yaml:"reservedConcurrency,omitempty"`
	Timeout             int    `yaml:"timeout,omitempty"`

	DeyploymentBucket DeploymentBucket  `yaml:"deploymendBucket,omitempty"`
	DeploymentPrefix  string            `yaml:"deploymentPrefix,omitempty"`
	Environments      map[string]string `yaml:"environment,omitempty"`
	RoleStatements    []RoleStatement   `yaml:"iamRoleStatements"`
	EndpointType      string            `yaml:"endpointType,omitempty"`
	NotificationARNs  []string          `yaml:"notificationArns,omitempty"`
	Tags              map[string]string `yaml:",omitempty"`
	Tracing           TracingConfig     `yaml:",omitempty"`
	Logs              LogConfig         `yaml:",omitempty"`
	// contains filtered or unexported fields
}

Provider ...

type ProvisionedThroughput

type ProvisionedThroughput struct {
	ReadCapacityUnits  int64 `yaml:"ReadCapacityUnits"`
	WriteCapacityUnits int64 `yaml:"WriteCapacityUnits"`
}

ProvisionedThroughput ...

type Reference

type Reference struct {
	Ref string `yaml:"Ref"`
}

Reference ...

type ResourceDefinition

type ResourceDefinition struct {
	DependsOn      []string   `yaml:"DependsOn,omitempty"`
	Type           string     `yaml:"Type"`
	DeletionPolicy string     `yaml:"DeletionPolicy,omitempty"`
	Properties     Properties `yaml:"Properties"`
}

ResourceDefinition ...

type Resources

type Resources struct {
	Resources map[string]*ResourceDefinition `yaml:"Resources"`
}

Resources ...

type RoleStatement

type RoleStatement struct {
	Effect   string   `yaml:"Effect"`
	Actions  []string `yaml:"Action"`
	Resource string   `yaml:"Resource"`
}

RoleStatement ...

type S3Event

type S3Event struct {
	Bucket string
	Event  string
	Rules  map[string]string `yaml:",omitempty"`
}

S3Event ...

type SAMEvent

type SAMEvent struct {
	Type       string  `yaml:"Type"`
	Properties SAMProp `yaml:"Properties"`
}

SAMEvent ...

type SAMFnProp

type SAMFnProp struct {
	Runtime     string              `yaml:"Runtime,omitempty"`
	Handler     string              `yaml:"Handler,omitempty"`
	CodeURI     string              `yaml:"CodeUri,omitempty"`
	Events      map[string]SAMEvent `yaml:"Events,omitempty"`
	Environment FnEnvironment       `yaml:"Environment,omitempty"`
}

SAMFnProp ...

type SAMFunction

type SAMFunction struct {
	Type       string    `yaml:"Type"`
	Properties SAMFnProp `yaml:"Properties"`
}

SAMFunction ...

type SAMProp

type SAMProp struct {
	Path   string `yaml:"Path"`
	Method string `yaml:"Method"`
}

SAMProp ...

type SNSEvent

type SNSEvent struct {
	TopicName   string `yaml:"topicName"`
	DisplayName string `yaml:"displayName,omitempty"`
}

SNSEvent ...

type SQSEvent

type SQSEvent struct {
	ARN       string `yaml:"arn"`
	BatchSize int    `yaml:"batchSize,omitempty"`
}

SQSEvent ...

type ScheduleEvent

type ScheduleEvent struct {
	Name        string
	Description string `yaml:",omitempty"`
	Rate        string
	Enabled     bool   `yaml:",omitempty"`
	InputPath   string `yaml:"inputPath,omitempty"`
}

ScheduleEvent ...

type ServerlessConfig

type ServerlessConfig struct {
	ProjectPath string `yaml:"-"`
	Service     Service
	Provider    Provider
	Package     Package
	Functions   map[string]*ServerlessFunction `yaml:",omitempty"`
	Layers      map[string]Layer               `yaml:",omitempty"`
	Resources   Resources                      `yaml:",omitempty"`
	Plugins     []string                       `yaml:",omitempty"`
	Custom      DomainConfig                   `yaml:",omitempty"`
}

ServerlessConfig ...

func NewDefaultServerlessConfig

func NewDefaultServerlessConfig() ServerlessConfig

NewDefaultServerlessConfig return a default ServerlessConfig object

func (*ServerlessConfig) AddAuth

func (s *ServerlessConfig) AddAuth(excludes string)

AddAuth adds Authorization to the ServerlessConfig

func (*ServerlessConfig) AddFunction

func (s *ServerlessConfig) AddFunction(fn *Function)

AddFunction adds a function to the ServerlessConfig

func (*ServerlessConfig) AddPoolEnv

func (s *ServerlessConfig) AddPoolEnv(mc MUGConfig, rName, pool string)

AddPoolEnv adds the given cognito user pool arn as environment in .env

func (*ServerlessConfig) RemoveAuth

func (s *ServerlessConfig) RemoveAuth()

RemoveAuth removes Authorization from the ServerlessConfig

func (*ServerlessConfig) RemoveFunction

func (s *ServerlessConfig) RemoveFunction(n string)

RemoveFunction removes a function from the ServerlessConfig

func (*ServerlessConfig) SetFunctions

func (s *ServerlessConfig) SetFunctions(fns []*Function)

SetFunctions sets a slice of Functions to the ServerlessConfig

func (*ServerlessConfig) SetResourceWithModel

func (s *ServerlessConfig) SetResourceWithModel(r *NewResource, m Model, projectName string)

SetResourceWithModel sets a Resource to the ServerlessConfig

func (*ServerlessConfig) Write

func (s *ServerlessConfig) Write(projectPath, mn string)

Write writes the ServerlessConfig to serverless.yml for the given project path and model name

type ServerlessFunction

type ServerlessFunction struct {
	Handler             string
	Package             Package           `yaml:",omitempty"`
	Name                string            `yaml:",omitempty"`
	Description         string            `yaml:",omitempty"`
	MemorySize          int               `yaml:",omitempty"`
	ReservedConcurrency int               `yaml:"reservedConcurrency,omitempty"`
	RunTime             string            `yaml:"runtime,omitempty"`
	Timeout             int               `yaml:",omitempty"`
	AWSKMSKeyARN        string            `yaml:"awsKmsKeyArn,omitempty"`
	Environments        map[string]string `yaml:"environment,omitempty"`
	Tags                map[string]string `yaml:",omitempty"`
	Layers              []string          `yaml:",omitempty"`
	Events              []Events
}

ServerlessFunction ...

type Service

type Service struct {
	Name         string
	AWSKMSKeyARN string `yaml:"awsKmsKeyArn,omitempty"`
}

Service ...

type StreamEvent

type StreamEvent struct {
	ARN              string `yaml:"arn"`
	BatchSize        int    `yaml:"batchSize,omitempty"`
	StartingPosition string `yaml:"startingPosition,omitempty"`
	Enabled          bool   `yaml:",omitempty"`
}

StreamEvent ...

type TTLSpecification

type TTLSpecification struct {
	AttributeName string `yaml:"AttributeName"`
	Enabled       bool   `yaml:"Enabled"`
}

TTLSpecification ...

type TemplateConfig

type TemplateConfig struct {
	Transform string                 `yaml:"Transform"`
	Globals   GlobalConfig           `yaml:"Globals"`
	Resources map[string]SAMFunction `yaml:"Resources"`
}

TemplateConfig ...

func NewTemplate

func NewTemplate() TemplateConfig

NewTemplate returns a new TemplateConfig

func (*TemplateConfig) AddFunctionsFromServerlessConfig

func (t *TemplateConfig) AddFunctionsFromServerlessConfig(s ServerlessConfig, r string)

AddFunctionsFromServerlessConfig adds the functions from the given ServerlessConfig and resource/ function group

func (*TemplateConfig) Write

func (t *TemplateConfig) Write(projectPath string)

Write writes the TemplateConfig to template.yml

type TracingConfig

type TracingConfig struct {
	APIGateway bool `yaml:"apiGateway,omitempty"`
	Lambda     bool `yaml:",omitempty"`
}

TracingConfig ...

type WebSocketEvent

type WebSocketEvent struct {
	Route      string
	Authorizer *Authorizer `yaml:",omitempty"`
}

WebSocketEvent ...

Jump to

Keyboard shortcuts

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