deploy

package
v0.10.4 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2022 License: AGPL-3.0 Imports: 48 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultFilename = "granted-deployment.yml"

Variables

View Source
var AvailableRegions = []string{
	"ap-southeast-2",
	"us-west-2",
	"us-east-1",
}

AvailableRegions are the regions that we currently release CloudFormation templates to.

View Source
var DeploymentConfigContextKey contextkey
View Source
var ErrConfigNotExist = errors.New("config does not exist")
View Source
var ErrConfigNotNotSetInContext = errors.New("config has not been set in context")
View Source
var ErrFeatureNotDefined = errors.New("feature is not defined")

Functions

func BackupDetailsToString

func BackupDetailsToString(b *ddbTypes.BackupDetails) string

func BackupStatus

func BackupStatus(ctx context.Context, backupARN string) (*ddbTypes.BackupDescription, error)

func CLIPrompt added in v0.3.1

func CLIPrompt(f *gconfig.Field) error

CLIPrompt prompts the user to enter a value for the config varsiable in a CLI context. If the config variable implements Defaulter, the default value is returned and the user is not prompted for any input.

func CleanName

func CleanName(name string) string

CleanName will replace all non letter characters from the string with "-"

when creating labels from git branch names, they may contain slashes etc which are incompatible

See the DynamoDB table naming guide: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.NamingRulesDataTypes.html

It panics if the regex cannot be parsed.

func DeployProductionFrontend

func DeployProductionFrontend(ctx context.Context, cfg config.FrontendDeployerConfig) error

func PublishManifest

func PublishManifest(ctx context.Context, releaseBucket, version string) error

PublishManifest updates the manifest.json file in the release bucket.

func RenderLocalFrontendConfig

func RenderLocalFrontendConfig(rfc RenderFrontendConfig) (string, error)

RenderLocalFrontendConfig renders the aws-exports.js file to be used in local development. This accepts a specific config so this function can be reused easily

func RenderProductionFrontendConfig

func RenderProductionFrontendConfig(rfc RenderFrontendConfig) (string, error)

RenderProductionFrontendConfig renders the aws-exports.json file to be used in a production deployment of the frontend to AWS S3 This accepts a specific config so this function can be reused easily in a custom resource lamda

func RestoreStatus

func RestoreStatus(ctx context.Context, targetTableName string) (*ddbTypes.TableDescription, error)

func RestoreSummaryToString

func RestoreSummaryToString(r *ddbTypes.RestoreSummary) string

func RunConfigTest added in v0.3.1

func RunConfigTest(ctx context.Context, testable interface{}) error

RunConfigTest runs ConfigTest() if it is implemented on the interface

func SetConfigInContext added in v0.2.0

func SetConfigInContext(ctx context.Context, cfg Config) context.Context

func StackExists

func StackExists(ctx context.Context, stackName string) (bool, error)

func StartBackup

func StartBackup(ctx context.Context, tableName string, backupName string) (*ddbTypes.BackupDetails, error)

func StartRestore

func StartRestore(ctx context.Context, backupARN string, targetTableName string) (*ddbTypes.TableDescription, error)

func TryGetCurrentAccountID added in v0.3.1

func TryGetCurrentAccountID(ctx context.Context) (string, error)

TryGetCurrentAccountID uses AWS STS to try and load the current account ID.

Types

type Config

type Config struct {
	Version    int        `yaml:"version"`
	Deployment Deployment `yaml:"deployment"`
	// contains filtered or unexported fields
}

func ConfigFromContext added in v0.2.0

func ConfigFromContext(ctx context.Context) (Config, error)

func LoadConfig

func LoadConfig(f string) (Config, error)

LoadConfig attempts to load the config file at path f if it does not exist, returns ErrConfigNotExist else returns the config or any other error

in CLI commands, it is preferable to use deploy.ConfigFromContext(ctx) where gdeploy.RequireDeploymentConfig has run as a before function for the command gdeploy.RequireDeploymentConfig will return a helpful cli error if there are any issues

func NewStagingConfig

func NewStagingConfig(ctx context.Context, stage string) *Config

NewStagingConfig sets up a Config for staging deployments. These deployments currently still use the CDK rather than CloudFormation.

func SetupDevConfig

func SetupDevConfig() (*Config, error)

SetupDevConfig sets up the config for local development.

func SetupReleaseConfig

func SetupReleaseConfig(c *cli.Context) (*Config, error)

SetupReleaseConfig sets up the release configuration used in production deployments.

func (Config) CDKContextArgs

func (c Config) CDKContextArgs() []string

CDKContextArgs returns the CDK context arguments in the form "-c" "ArgName=ArgValue"

This should only be used in development, where the StackName variable is always of the form "granted-approvals-$STAGE". It panics if this is not the case.

func (*Config) CfnParams

func (c *Config) CfnParams() ([]types.Parameter, error)

CfnParams converts the parameters to types supported by CloudFormation deployments.

func (*Config) CfnTemplateURL

func (c *Config) CfnTemplateURL() string

CfnTemplateURL returns the CloudFormation template URL. If the deployment release points to an S3 object (https://custom-bucket.s3.amazonaws.com/path/to/template.json) It is turned into a HTTPS URL. If a regular version number (v0.1.0) is used, we point to our official release bucket.

func (*Config) DeployCloudFormation

func (c *Config) DeployCloudFormation(ctx context.Context, confirm bool) (string, error)

DeployCloudFormation creates a CloudFormation stack based on the config

func (Config) GetDevStageName

func (c Config) GetDevStageName() (string, error)

GetDevStageName returns the stage name to be used in a CDK deployment. It expects that the stack name is in the form "granted-approvals-$STAGE".

func (*Config) GetStackStatus added in v0.1.2

func (c *Config) GetStackStatus(ctx context.Context) (types.StackStatus, error)

GetStackStatus indicates whether the Cloud Formation stack is online (via "CREATE_COMPLETE")

func (*Config) LoadOutput

func (c *Config) LoadOutput(ctx context.Context) (Output, error)

LoadOutput loads the outputs for the current deployment.

func (*Config) ResetIdentityProviderToCognito added in v0.4.0

func (c *Config) ResetIdentityProviderToCognito(filepath string) error

Reset Identity Provider to cognito settings

func (*Config) Save

func (c *Config) Save(f string) error

func (*Config) SetDNSRecord

func (c *Config) SetDNSRecord(ctx context.Context) error

type DeployConfigReader added in v0.5.0

type DeployConfigReader interface {
	ReadProviders(ctx context.Context) (ProviderMap, error)
	ReadNotifications(ctx context.Context) (*Notifications, error)
}

DeployConfigReader reads configuration about this Granted Approvals deployment, including provider and notification information.

func GetDeploymentConfig added in v0.6.0

func GetDeploymentConfig() (DeployConfigReader, error)

type Deployment

type Deployment struct {
	StackName string `yaml:"stackName"`
	Account   string `yaml:"account"`
	Region    string `yaml:"region"`
	// Release may be one of two formats:
	//
	// 1. A release version tag (e.g. 'v0.1.0'). This uses a release
	// from Common Fate's release bucket.
	//
	// 2. A path to a CloudFormation template in S3, in the format
	// 'https://custom-bucket.s3.amazonaws.com/path/to/template.json'.
	// Note that the S3 bucket must be in the same region as the 'Region' parameter.
	Release string `yaml:"release"`
	// Dev is set to true for internal development deployments only.
	Dev        *bool      `yaml:"dev,omitempty"`
	Parameters Parameters `yaml:"parameters"`
}

type EnvDeploymentConfig added in v0.5.0

type EnvDeploymentConfig struct{}

EnvDeploymentConfig reads config values from environment variables.

func (*EnvDeploymentConfig) ReadNotifications added in v0.5.0

func (el *EnvDeploymentConfig) ReadNotifications(ctx context.Context) (*Notifications, error)

func (*EnvDeploymentConfig) ReadProviders added in v0.5.0

func (el *EnvDeploymentConfig) ReadProviders(ctx context.Context) (ProviderMap, error)

type FeatureMap added in v0.3.1

type FeatureMap map[string]map[string]string

Feature map represents the type used for features like identity and notifications

func UnmarshalFeatureMap added in v0.3.1

func UnmarshalFeatureMap(data string) (FeatureMap, error)

UnmarshalFeatureMap parses the JSON configuration data and returns an initialised FeatureMap. If `data` is an empty string an empty FeatureMap is returned.

func (FeatureMap) Remove added in v0.3.1

func (f FeatureMap) Remove(id string)

Remove the feature in the map, if the map is not initialised, it does nothing

func (*FeatureMap) Upsert added in v0.3.1

func (f *FeatureMap) Upsert(id string, feature map[string]string)

Upserts the feature in the map, if the map is not initialised, it initialises it first

type Manifest

type Manifest struct {
	// Version is the version of the manifest itself. Used for forwards-compatibility.
	Version                 int    `json:"manifestVersion"`
	LatestDeploymentVersion string `json:"latestDeploymentVersion"`
}

func GetManifest

func GetManifest(ctx context.Context, region string) (Manifest, error)

GetManifest retrieves the manifest.json file for the current deployment region

type Notifications

type Notifications struct {
	Slack                 map[string]string `yaml:"slack,omitempty" json:"slack,omitempty"`
	SlackIncomingWebhooks FeatureMap        `yaml:"slackIncomingWebhooks,omitempty" json:"slackIncomingWebhooks,omitempty"`
}

func UnmarshalNotifications added in v0.2.0

func UnmarshalNotifications(data string) (*Notifications, error)

UnmarshalNotifications parses the JSON configuration data and returns an initialised Notifications. If `data` is an empty string an empty Notifications is returned.

type Output

type Output struct {
	CognitoClientID               string `json:"CognitoClientID"`
	CloudFrontDomain              string `json:"CloudFrontDomain"`
	FrontendDomainOutput          string `json:"FrontendDomainOutput"`
	CloudFrontDistributionID      string `json:"CloudFrontDistributionID"`
	S3BucketName                  string `json:"S3BucketName"`
	UserPoolID                    string `json:"UserPoolID"`
	UserPoolDomain                string `json:"UserPoolDomain"`
	APIURL                        string `json:"APIURL"`
	WebhookURL                    string `json:"WebhookURL"`
	WebhookLogGroupName           string `json:"WebhookLogGroupName"`
	APILogGroupName               string `json:"APILogGroupName"`
	IDPSyncLogGroupName           string `json:"IDPSyncLogGroupName"`
	AccessHandlerLogGroupName     string `json:"AccessHandlerLogGroupName"`
	EventBusLogGroupName          string `json:"EventBusLogGroupName"`
	EventsHandlerLogGroupName     string `json:"EventsHandlerLogGroupName"`
	GranterLogGroupName           string `json:"GranterLogGroupName"`
	SlackNotifierLogGroupName     string `json:"SlackNotifierLogGroupName"`
	DynamoDBTable                 string `json:"DynamoDBTable"`
	GranterStateMachineArn        string `json:"GranterStateMachineArn"`
	EventBusArn                   string `json:"EventBusArn"`
	EventBusSource                string `json:"EventBusSource"`
	IdpSyncFunctionName           string `json:"IdpSyncFunctionName"`
	Region                        string `json:"Region"`
	PaginationKMSKeyARN           string `json:"PaginationKMSKeyARN"`
	AccessHandlerExecutionRoleARN string `json:"AccessHandlerExecutionRoleARN"`
	CacheSyncLogGroupName         string `json:"CacheSyncLogGroupName"`
	RestAPIExecutionRoleARN       string `json:"RestAPIExecutionRoleARN"`
	IDPSyncExecutionRoleARN       string `json:"IDPSyncExecutionRoleARN"`
	CacheSyncFunctionName         string `json:"CacheSyncFunctionName"`
}

Output is the output from deploying the CDK stack to AWS.

func (Output) DeployFrontend

func (o Output) DeployFrontend() error

DeployFrontend uploads the frontend to S3 and invalidates CloudFront

func (Output) FrontendURL

func (c Output) FrontendURL() string

func (Output) Get added in v0.5.0

func (o Output) Get(key string) (string, error)

Get a value by it's key in the output struct

func (Output) Keys added in v0.5.0

func (o Output) Keys() []string

Keys returns the names of the output variables.

func (Output) PrintSAMLTable added in v0.8.0

func (o Output) PrintSAMLTable()

func (Output) PrintTable

func (c Output) PrintTable()

func (Output) ToRenderFrontendConfig

func (o Output) ToRenderFrontendConfig() RenderFrontendConfig

type Parameters

type Parameters struct {
	CognitoDomainPrefix             string         `yaml:"CognitoDomainPrefix"`
	AdministratorGroupID            string         `yaml:"AdministratorGroupID"`
	DeploymentSuffix                string         `yaml:"DeploymentSuffix,omitempty"`
	IdentityProviderType            string         `yaml:"IdentityProviderType,omitempty"`
	SamlSSOMetadata                 string         `yaml:"SamlSSOMetadata,omitempty"`
	SamlSSOMetadataURL              string         `yaml:"SamlSSOMetadataURL,omitempty"`
	FrontendDomain                  string         `yaml:"FrontendDomain,omitempty"`
	FrontendCertificateARN          string         `yaml:"FrontendCertificateARN,omitempty"`
	CloudfrontWAFACLARN             string         `yaml:"CloudfrontWAFACLARN,omitempty"`
	APIGatewayWAFACLARN             string         `yaml:"APIGatewayWAFACLARN,omitempty"`
	ExperimentalRemoteConfigURL     string         `yaml:"ExperimentalRemoteConfigURL,omitempty"`
	ExperimentalRemoteConfigHeaders string         `yaml:"ExperimentalRemoteConfigHeaders,omitempty"`
	ProviderConfiguration           ProviderMap    `yaml:"ProviderConfiguration,omitempty"`
	IdentityConfiguration           FeatureMap     `yaml:"IdentityConfiguration,omitempty"`
	NotificationsConfiguration      *Notifications `yaml:"NotificationsConfiguration,omitempty"`
	AnalyticsDisabled               string         `yaml:"AnalyticsDisabled,omitempty"`
	AnalyticsURL                    string         `yaml:"AnalyticsURL,omitempty"`
	AnalyticsLogLevel               string         `yaml:"AnalyticsLogLevel,omitempty"`
	AnalyticsDeploymentStage        string         `yaml:"AnalyticsDeploymentStage,omitempty"`
}

type Provider

type Provider struct {
	Uses string            `yaml:"uses" json:"uses"`
	With map[string]string `yaml:"with" json:"with"`
}

type ProviderMap added in v0.3.1

type ProviderMap map[string]Provider

func UnmarshalProviderMap added in v0.3.1

func UnmarshalProviderMap(data string) (ProviderMap, error)

UnmarshalProviderMap parses the JSON configuration data and returns an initialised struct. If `data` is an empty string an empty IdentityConfig{} object is returned.

func (*ProviderMap) Add added in v0.3.1

func (f *ProviderMap) Add(id string, p Provider) error

Adds the Provider if it does not exist

func (ProviderMap) GetIDForNewProvider added in v0.4.0

func (p ProviderMap) GetIDForNewProvider(defaultID string) string

GetIDForNewProvider returns an ID for a provider based on the following rules:

1. If the provider isn't used in the config, the default ID is returned (e.g. `aws-sso`). 2. If the provider exists in the config, a numbered suffix is added to the default ID (e.g. `aws-sso-2`). The numbers start at 2 and increment until an available ID is found.

func (*ProviderMap) Update added in v0.5.0

func (f *ProviderMap) Update(id string, p Provider) error

Update the Provider if it exist

type ProviderWriter added in v0.6.0

type ProviderWriter interface {
	WriteProviders(ctx context.Context, pm ProviderMap) error
}

type Release

type Release struct {
	ProductionReleasesBucket      string
	ProductionReleaseBucketPrefix string
}

func (Release) CDKContextArgs

func (s Release) CDKContextArgs() []string

CDKContextArgs returns the CDK context arguments in the form "-c" "ArgName=ArgValue"

type RemoteDeploymentConfig added in v0.6.0

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

RemoteDeploymentConfig reads config values from an API.

func NewRemoteDeploymentConfig added in v0.6.0

func NewRemoteDeploymentConfig(url string, headersString string) (*RemoteDeploymentConfig, error)

NewRemoteDeploymentConfig sets up a deployment config loader which fetches deployment configuration from a remote API.

headers should be passed as a comma-separated string in the following format:

KEY=VALUE,KEY=VALUE

func (*RemoteDeploymentConfig) ReadNotifications added in v0.6.0

func (r *RemoteDeploymentConfig) ReadNotifications(ctx context.Context) (*Notifications, error)

func (*RemoteDeploymentConfig) ReadProviders added in v0.6.0

func (r *RemoteDeploymentConfig) ReadProviders(ctx context.Context) (ProviderMap, error)

func (*RemoteDeploymentConfig) WriteProviders added in v0.6.0

func (r *RemoteDeploymentConfig) WriteProviders(ctx context.Context, pm ProviderMap) error

type RenderFrontendConfig

type RenderFrontendConfig struct {
	Region          string
	UserPoolID      string
	CognitoClientID string
	UserPoolDomain  string
	FrontendDomain  string
	APIURL          string
}

RenderFrontendConfig contains all the required mappings for the templates

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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