Documentation ¶
Overview ¶
Package domain provides core mantil domain model. This package is distilled domain knowledge. It should use shared language that allows developers and domain experts to collaborate effectively.
This is the place where all domain decisions are made. It should not depend on other packages, except for the standard library, and project kit package.
Current dependencies: $ run list-packages domain crypto/rand encoding/base32 encoding/json fmt github.com/json-iterator/go github.com/mantil-io/mantil/kit/gz github.com/mantil-io/mantil/kit/schema github.com/mantil-io/mantil/kit/token github.com/pkg/errors gopkg.in/yaml.v2 io io/ioutil os os/user path path/filepath reflect regexp strings time
Index ¶
- Constants
- Variables
- func AppConfigDir() (string, error)
- func Factory(w *Workspace, p *Project, e *EnvironmentConfig) error
- func FindProjectRoot(initialPath string) (string, error)
- func MachineID() string
- func NowMS() int64
- func RemoveAWSCredentials(args []string) []string
- func StoreUserClaims(claims *AccessTokenClaims, context map[string]interface{})
- func UID() string
- func ValidateAWSCron(cron string) bool
- func Version() string
- func WorkspacePathAndName() (string, string, error)
- type AccessTokenClaims
- type AwsResource
- type CliCommand
- func (c *CliCommand) Add(e Event)
- func (c *CliCommand) AddError(e CliError)
- func (c *CliCommand) Clear()
- func (c *CliCommand) End()
- func (c *CliCommand) JSON() ([]byte, error)
- func (c *CliCommand) Marshal() ([]byte, error)
- func (c *CliCommand) Pretty() ([]byte, error)
- func (c *CliCommand) Start()
- func (c *CliCommand) Unmarshal(buf []byte) error
- type CliError
- type CliProject
- type CliStage
- type CliWorkspace
- type CustomDomain
- type Deploy
- type DeployInfo
- type EnvironmentConfig
- type EnvironmentConfigValidationError
- type Event
- type FileStore
- func (s *FileStore) AsCliWorkspace() *CliWorkspace
- func (s *FileStore) DefaultStage() *Stage
- func (s *FileStore) NewProject(name, projectRoot string) error
- func (s *FileStore) Project() *Project
- func (s *FileStore) ProjectRoot() string
- func (s *FileStore) Stage(name string) *Stage
- func (s *FileStore) Store() error
- func (s *FileStore) Workspace() *Workspace
- type Function
- type FunctionConfiguration
- type FunctionEnvironmentConfig
- type GoBuild
- type LastDeployment
- type Node
- func (n *Node) AddStage(name, projectName, path string)
- func (n *Node) AuthEnv() map[string]string
- func (n *Node) AuthToken() (string, error)
- func (n *Node) RemoveStage(name string)
- func (n *Node) ResourceNamingTemplate() string
- func (n *Node) ResourceSuffix() string
- func (n *Node) ResourceTags() map[string]string
- func (n *Node) Resources() []AwsResource
- func (n *Node) SetupLambdaName() string
- func (n *Node) SetupStackName() string
- func (n *Node) UpgradeVersion(version, functionsBbucket, functionsPath string)
- type NodeAlreadyUpToDateError
- type NodeEndpoints
- type NodeEvent
- type NodeExistsError
- type NodeFunctions
- type NodeKeys
- type NodeNotFoundError
- type NodeStage
- type Project
- func (p *Project) AsCliProject() *CliProject
- func (p *Project) DefaultStage() *Stage
- func (p *Project) FunctionsBucketPrefix() string
- func (p *Project) NewStage(stageName, nodeName, path string) (*Stage, error)
- func (p *Project) NumberOfStages() int
- func (p *Project) RemoveStage(stageName string)
- func (p *Project) SetDefaultStage(name string)
- func (p *Project) Stage(name string) *Stage
- func (p *Project) StateBucketPrefix() string
- type ProjectEnvironmentConfig
- type ProjectNew
- type ProjectNoStagesError
- type ProjectNotFoundError
- type Public
- type Resource
- type Role
- type SDKConfig
- type Signal
- type Stage
- func (s *Stage) AddFunctions(names []string) error
- func (s *Stage) ApplyChanges(funcs []Resource, publicHash string) (*StageDiff, error)
- func (s *Stage) AsCliStage() *CliStage
- func (s *Stage) AuthEnv() map[string]string
- func (s *Stage) AuthToken() (string, error)
- func (s *Stage) BucketPrefixes() []string
- func (s *Stage) FindFunction(name string) *Function
- func (s *Stage) FunctionNames() []string
- func (s *Stage) FunctionsBucketPrefix() string
- func (s *Stage) HasPublic() bool
- func (s *Stage) LogGroupsPrefix() string
- func (s *Stage) Node() *Node
- func (s *Stage) Project() *Project
- func (s *Stage) PublicBucketName() string
- func (s *Stage) PublicEnv() ([]byte, error)
- func (s *Stage) RemoveFunctions(removed []string)
- func (s *Stage) ResourceNamingTemplate() string
- func (s *Stage) ResourceTags() map[string]string
- func (s *Stage) Resources() []AwsResource
- func (s *Stage) RestEndpoint() string
- func (s *Stage) SetEndpoints(rest, ws string)
- func (s *Stage) SetLastDeployment()
- func (s *Stage) SetPublicBucket(bucket string)
- func (s *Stage) StateBucketPrefix() string
- func (s *Stage) WsConfig() WsConfig
- func (s *Stage) WsEndpoint() string
- func (s *Stage) WsEnv() map[string]string
- func (s *Stage) WsForwarderLambdaName() string
- type StageDiff
- type StageEndpoints
- type StageEnvironmentConfig
- type StageExistsError
- type StageKeys
- type ValidationError
- type WatchCycle
- type WatchDone
- type Workspace
- func (w *Workspace) AddProject(name, path string)
- func (w *Workspace) FindNode(name string) *Node
- func (w *Workspace) NewNode(name, awsAccountID, awsRegion, functionsBucket, functionsPath, version string) (*Node, error)
- func (w *Workspace) Node(name string) *Node
- func (w *Workspace) NodeNames() []string
- func (w *Workspace) RemoveNode(name string)
- func (w *Workspace) RemoveProject(name string)
- type WorkspaceNoNodesError
- type WorkspaceProject
- type WsConfig
Constants ¶
const ( AccessTokenHeader = "Authorization" EnvPublicKey = "MANTIL_PUBLIC_KEY" ContextUserClaimsKey = "mantilUserClaims" )
const ( AWSCredentialsByArguments = 1 AWSCredentialsByEnv = 2 AWSCredentialsByProfile = 3 )
const ( StateBucketPrefix = "state" FunctionsBucketPrefix = "functions" FunctionsBucketExpireDays = 7 )
const ( AwsResourceLambda = "Lambda Function" AwsResourceAPIGateway = "API Gateway" AwsResourceS3Bucket = "S3 Bucket" AwsResourceDynamoDB = "DynamoDB Table" AwsResourceStack = "CloudFormation Stack" )
const ( DefaultNodeName = "dev" DefaultStageName = "dev" EnvWorkspace = "MANTIL_WORKSPACE" EnvKey = "MANTIL_KEY" EnvProjectName = "MANTIL_PROJECT" EnvStageName = "MANTIL_STAGE" EnvApiURL = "MANTIL_API_URL" TagWorkspace = EnvWorkspace TagKey = EnvKey TagProjectName = EnvProjectName TagStageName = EnvStageName // set to non empty to disable sending events from cli EnvNoEvents = "MANTIL_NO_EVENTS" )
const (
EnvMantilConfig = "MANTIL_CONFIG"
)
const (
EnvSDKConfig = "MANTIL_GO_CONFIG"
)
const EnvWorkspacePath = "MANTIL_WORKSPACE_PATH"
enables setting workspace path outside of default can be used in test to don't mess with the default user workspace
const PublicEnvKey = "mantil_env.js"
Variables ¶
var (
ErrWorkspaceNotFound = fmt.Errorf("workspace not found")
)
Functions ¶
func AppConfigDir ¶
func Factory ¶
func Factory(w *Workspace, p *Project, e *EnvironmentConfig) error
Factory proper object model
func FindProjectRoot ¶
func RemoveAWSCredentials ¶
func StoreUserClaims ¶
func StoreUserClaims(claims *AccessTokenClaims, context map[string]interface{})
func ValidateAWSCron ¶
func WorkspacePathAndName ¶
Types ¶
type AccessTokenClaims ¶
type AccessTokenClaims struct { Workspace string `json:"w,omitempty"` Project string `json:"p,omitempty"` Stage string `json:"s,omitempty"` Runtime string `json:"r,omitempty"` Username string `json:"u,omitempty"` Role Role `json:"o,omitempty"` }
func ReadAccessToken ¶
func ReadAccessToken(headers map[string]string) (*AccessTokenClaims, error)
type AwsResource ¶
func (AwsResource) LogGroup ¶
func (r AwsResource) LogGroup() string
type CliCommand ¶
type CliCommand struct { Timestamp int64 `short:"t,omitempty" json:"timestamp"` Duration int64 `short:"d,omitempty" json:"duration"` Version string `short:"v,omitempty" json:"version"` Args []string `short:"a,omitempty" json:"args"` Device struct { OS string `short:"o,omitempty" json:"os"` ARCH string `short:"h,omitempty" json:"arch"` } `short:"m,omitempty" json:"device,omitempty"` Workspace *CliWorkspace `short:"w,omitempty" json:"workspace,omitempty"` Project *CliProject `short:"p,omitempty" json:"project,omitempty"` Stage *CliStage `short:"s,omitempty" json:"stage,omitempty"` Errors []CliError `short:"r,omitempty" json:"errors,omitempty"` Events []Event `short:"e,omitempty" json:"events,omitempty"` }
event raised after execution of a cli command
func NewCliCommand ¶
func NewCliCommand(buf []byte) (*CliCommand, error)
func (*CliCommand) Add ¶
func (c *CliCommand) Add(e Event)
func (*CliCommand) AddError ¶
func (c *CliCommand) AddError(e CliError)
func (*CliCommand) Clear ¶
func (c *CliCommand) Clear()
func (*CliCommand) End ¶
func (c *CliCommand) End()
func (*CliCommand) JSON ¶
func (c *CliCommand) JSON() ([]byte, error)
func (*CliCommand) Marshal ¶
func (c *CliCommand) Marshal() ([]byte, error)
func (*CliCommand) Pretty ¶
func (c *CliCommand) Pretty() ([]byte, error)
func (*CliCommand) Start ¶
func (c *CliCommand) Start()
func (*CliCommand) Unmarshal ¶
func (c *CliCommand) Unmarshal(buf []byte) error
type CliProject ¶
type CliWorkspace ¶
type CliWorkspace struct { ID string `short:"i,omitempty" json:"id"` Nodes int `short:"o,omitempty" json:"nodes"` Projects int `short:"p,omitempty" json:"projects"` Stages int `short:"s,omitempty" json:"stages"` Functions int `short:"f,omitempty" json:"functions"` AWSAccounts int `short:"a,omitempty" json:"awsAccounts"` AWSRegions int `short:"r,omitempty" json:"awsRegions"` }
type CustomDomain ¶
type Deploy ¶
type Deploy struct { Functions struct { Added int `short:"a,omitempty" json:"added"` Updated int `short:"u,omitempty" json:"updated"` Removed int `short:"r,omitempty" json:"removed"` } `short:"f,omitempty" json:"functions,omitempty"` InfrastructureChanged bool `short:"i,omitempty" json:"infrastructureChanged"` BuildDuration int `short:"b,omitempty" json:"buildDuration"` UploadDuration int `short:"u,omitempty" json:"uploadDuration"` UploadBytes int `short:"m,omitempty" json:"uploadbytes"` UpdateDuration int `short:"d,omitempty" json:"updateDuration"` }
type DeployInfo ¶
type DeployInfo struct {
// contains filtered or unexported fields
}
Collects build time information. Decides where is the deployment location; s3 bucket and key for lambda function pacakges. That information is used in script/deploy.sh to put build artifacts in the right place.
func Deployment ¶
func Deployment() DeployInfo
deployment information where to put/get deployment artifacts (lambda function packages)
func (DeployInfo) GetPath ¶
func (d DeployInfo) GetPath(region string) (string, string)
GetPath returns bucket and key in the bucket for reading deployed functions
func (DeployInfo) LatestBucket ¶
func (d DeployInfo) LatestBucket() string
func (DeployInfo) PutPath ¶
func (d DeployInfo) PutPath() string
PutPath s3 path where we deploy releases it is always in releaseBucket we are replicating this bucket to other regional buckets
func (DeployInfo) Release ¶
func (d DeployInfo) Release() bool
is this release or development deployment
type EnvironmentConfig ¶
type EnvironmentConfig struct {
Project ProjectEnvironmentConfig `yaml:"project" jsonschema:"nullable,default={}"`
}
func ValidateEnvironmentConfig ¶
func ValidateEnvironmentConfig(buf []byte) (*EnvironmentConfig, error)
type EnvironmentConfigValidationError ¶
type EnvironmentConfigValidationError struct {
Err error
}
func (*EnvironmentConfigValidationError) Error ¶
func (e *EnvironmentConfigValidationError) Error() string
type Event ¶
type Event struct { Timestamp int64 `short:"t,omitempty" json:"timestamp"` GoBuild *GoBuild `short:"g,omitempty" json:"goBuild,omitempty"` Deploy *Deploy `short:"d,omitempty" json:"deploy,omitempty"` Signal *Signal `short:"s,omitempty" json:"signal,omitempty"` NodeCreate *NodeEvent `short:"nc,omitempty" json:"nodeCreate,omitempty"` NodeUpgrade *NodeEvent `short:"nu,omitempty" json:"nodeUpgrade,omitempty"` NodeDelete *NodeEvent `short:"nd,omitempty" json:"nodeDelete,omitempty"` ProjectNew *ProjectNew `short:"n,omitempty" json:"projectNew,omitempty"` WatchCycle *WatchCycle `short:"wc,omitempty" json:"watchCycle,omitempty"` WatchDone *WatchDone `short:"wd,omitempty" json:"watchDone,omitempty"` }
placeholder for all events only one attribute is not nil
type FileStore ¶
type FileStore struct {
// contains filtered or unexported fields
}
func NewSingleDeveloperProjectStore ¶
NewSingleDeveloperProject loads workspace and project config files
func NewSingleDeveloperWorkspaceStore ¶
NewSingleDeveloperWorkspaceStore loads workspace allows to be outside of project
func (*FileStore) AsCliWorkspace ¶
func (s *FileStore) AsCliWorkspace() *CliWorkspace
func (*FileStore) DefaultStage ¶
func (*FileStore) NewProject ¶
func (*FileStore) ProjectRoot ¶
type Function ¶
type Function struct { Name string `yaml:"name"` Hash string `yaml:"hash"` S3Key string `yaml:"s3_key"` FunctionConfiguration `yaml:",inline"` // contains filtered or unexported fields }
func (*Function) LambdaName ¶
type FunctionConfiguration ¶
type FunctionConfiguration struct { MemorySize int `yaml:"memory_size,omitempty" jsonschema:"minimum=128,maximum=10240"` Timeout int `yaml:"timeout,omitempty" jsonschema:"minimum=1,maximum=900"` Env map[string]string `yaml:"env,omitempty" jsonschema:"nullable"` Cron string `yaml:"cron,omitempty"` Private bool `yaml:"private,omitempty"` }
type FunctionEnvironmentConfig ¶
type FunctionEnvironmentConfig struct { Name string `yaml:"name"` FunctionConfiguration `yaml:",inline"` }
type LastDeployment ¶
type Node ¶
type Node struct { Name string `yaml:"name,omitempty"` ID string `yaml:"id"` Version string `yaml:"version"` // AWS related attributes AccountID string `yaml:"accountID"` // AWS account id Region string `yaml:"region"` // AWS region Bucket string `yaml:"bucket"` // bucket name created on AWS CliRole string `yaml:"cli_role"` // role name for security node lambda function Keys NodeKeys `yaml:"keys"` Endpoints NodeEndpoints `yaml:"endpoints"` Functions NodeFunctions `yaml:"functions"` Stages []*NodeStage `yaml:"stages,omitempty"` // contains filtered or unexported fields }
func (*Node) RemoveStage ¶
func (*Node) ResourceNamingTemplate ¶
func (*Node) ResourceSuffix ¶
func (*Node) ResourceTags ¶
func (*Node) Resources ¶
func (n *Node) Resources() []AwsResource
func (*Node) SetupLambdaName ¶
func (*Node) SetupStackName ¶
func (*Node) UpgradeVersion ¶
type NodeAlreadyUpToDateError ¶
func (*NodeAlreadyUpToDateError) Error ¶
func (e *NodeAlreadyUpToDateError) Error() string
type NodeEndpoints ¶
type NodeEndpoints struct {
Rest string `yaml:"rest"`
}
type NodeExistsError ¶
type NodeExistsError struct {
Name string
}
func (*NodeExistsError) Error ¶
func (e *NodeExistsError) Error() string
type NodeFunctions ¶
type NodeNotFoundError ¶
type NodeNotFoundError struct {
Name string
}
func (*NodeNotFoundError) Error ¶
func (e *NodeNotFoundError) Error() string
type Project ¶
type Project struct { Name string `yaml:"name"` Stages []*Stage `yaml:"stages,omitempty"` // contains filtered or unexported fields }
func (*Project) AsCliProject ¶
func (p *Project) AsCliProject() *CliProject
func (*Project) DefaultStage ¶
func (*Project) FunctionsBucketPrefix ¶
func (*Project) NumberOfStages ¶
func (*Project) RemoveStage ¶
func (*Project) SetDefaultStage ¶
func (*Project) StateBucketPrefix ¶
type ProjectEnvironmentConfig ¶
type ProjectEnvironmentConfig struct { Stages []StageEnvironmentConfig `yaml:"stages,omitempty" jsonschema:"nullable,default=[]"` FunctionConfiguration `yaml:",inline"` }
func (ProjectEnvironmentConfig) StageEnvConfig ¶
func (c ProjectEnvironmentConfig) StageEnvConfig(name string) StageEnvironmentConfig
type ProjectNew ¶
type ProjectNoStagesError ¶
type ProjectNoStagesError struct{}
func (*ProjectNoStagesError) Error ¶
func (e *ProjectNoStagesError) Error() string
type ProjectNotFoundError ¶
type ProjectNotFoundError struct{}
func (*ProjectNotFoundError) Error ¶
func (e *ProjectNotFoundError) Error() string
type SDKConfig ¶
type SDKConfig struct { ResourceTags map[string]string WsForwarderName string NamingTemplate string }
this is a copy of the Config struct in mantil.go
type Stage ¶
type Stage struct { Name string `yaml:"name"` Default bool `yaml:"default,omitempty"` NodeName string `yaml:"node"` Keys StageKeys `yaml:"keys"` Endpoints *StageEndpoints `yaml:"endpoints,omitempty"` LastDeployment *LastDeployment `yaml:"last_deployment,omitempty"` Functions []*Function `yaml:"functions,omitempty"` Public *Public `yaml:"public,omitempty"` CustomDomain CustomDomain `yaml:"custom_domain,omitempty"` // contains filtered or unexported fields }
func (*Stage) AddFunctions ¶
func (*Stage) ApplyChanges ¶
func (*Stage) AsCliStage ¶
func (*Stage) BucketPrefixes ¶
func (*Stage) FindFunction ¶
func (*Stage) FunctionNames ¶
func (*Stage) FunctionsBucketPrefix ¶
func (*Stage) LogGroupsPrefix ¶
func (*Stage) PublicBucketName ¶
func (*Stage) RemoveFunctions ¶
func (*Stage) ResourceNamingTemplate ¶
func (*Stage) ResourceTags ¶
func (*Stage) Resources ¶
func (s *Stage) Resources() []AwsResource
Resources list of resources created for the stage
func (*Stage) RestEndpoint ¶
func (*Stage) SetEndpoints ¶
func (*Stage) SetLastDeployment ¶
func (s *Stage) SetLastDeployment()
func (*Stage) SetPublicBucket ¶
func (*Stage) StateBucketPrefix ¶
func (*Stage) WsEndpoint ¶
func (*Stage) WsForwarderLambdaName ¶
type StageDiff ¶
type StageDiff struct {
// contains filtered or unexported fields
}
func (*StageDiff) FunctionsAddedUpdatedRemoved ¶
func (*StageDiff) HasFunctionUpdates ¶
func (*StageDiff) HasPublicUpdates ¶
func (*StageDiff) HasUpdates ¶
func (*StageDiff) InfrastructureChanged ¶
func (*StageDiff) UpdatedFunctions ¶
type StageEndpoints ¶
type StageEnvironmentConfig ¶
type StageEnvironmentConfig struct { Name string `yaml:"name"` Functions []FunctionEnvironmentConfig `yaml:"functions,omitempty"` FunctionConfiguration `yaml:",inline"` CustomDomain CustomDomain `yaml:"custom_domain,omitempty" jsonschema:"nullable,default={}"` }
func (StageEnvironmentConfig) FunctionEnvConfig ¶
func (c StageEnvironmentConfig) FunctionEnvConfig(name string) FunctionEnvironmentConfig
type StageExistsError ¶
type StageExistsError struct {
Name string
}
func (*StageExistsError) Error ¶
func (e *StageExistsError) Error() string
type ValidationError ¶
type ValidationError struct {
Name string
}
func ValidateName ¶
func ValidateName(name string) *ValidationError
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string
type WatchCycle ¶
type Workspace ¶
type Workspace struct { ID string `yaml:"id"` Version string `yaml:"version"` CreatedAt int64 `yaml:"created_at"` Projects []*WorkspaceProject `yaml:"projects,omitempty"` Nodes []*Node `yaml:"nodes"` }
func (*Workspace) AddProject ¶
func (*Workspace) RemoveNode ¶
func (*Workspace) RemoveProject ¶
type WorkspaceNoNodesError ¶
type WorkspaceNoNodesError struct{}
func (*WorkspaceNoNodesError) Error ¶
func (e *WorkspaceNoNodesError) Error() string