config

package
v1.7.1 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2021 License: MIT Imports: 18 Imported by: 16

Documentation

Overview

Package config provides configuration structures, validation, and defaulting for up.json config.

Index

Examples

Constants

View Source
const (
	RuntimeUnknown    Runtime = "unknown"
	RuntimeGo                 = "go"
	RuntimeNode               = "node"
	RuntimeClojure            = "clojure"
	RuntimeCrystal            = "crystal"
	RuntimePython             = "python"
	RuntimeStatic             = "static"
	RuntimeJavaMaven          = "java maven"
	RuntimeJavaGradle         = "java gradle"
)

Runtimes available.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backoff

type Backoff struct {
	// Min time in milliseconds.
	Min int `json:"min"`

	// Max time in milliseconds.
	Max int `json:"max"`

	// Factor applied for every attempt.
	Factor float64 `json:"factor"`

	// Attempts performed before failing.
	Attempts int `json:"attempts"`

	// Jitter is applied when true.
	Jitter bool `json:"jitter"`
}

Backoff config.

func (*Backoff) Backoff

func (b *Backoff) Backoff() *backoff.Backoff

Backoff returns the backoff from config.

func (*Backoff) Default

func (b *Backoff) Default() error

Default implementation.

type CORS

type CORS struct {
	// AllowedOrigins is a list of origins a cross-domain request can be executed from.
	// If the special "*" value is present in the list, all origins will be allowed.
	// An origin may contain a wildcard (*) to replace 0 or more characters
	// (i.e.: http://*.domain.com). Usage of wildcards implies a small performance penalty.
	// Only one wildcard can be used per origin.
	// Default value is ["*"]
	AllowedOrigins []string `json:"allowed_origins"`

	// AllowedMethods is a list of methods the client is allowed to use with
	// cross-domain requests. Default value is simple methods (GET and POST)
	AllowedMethods []string `json:"allowed_methods"`

	// AllowedHeaders is list of non simple headers the client is allowed to use with
	// cross-domain requests.
	// If the special "*" value is present in the list, all headers will be allowed.
	// Default value is [] but "Origin" is always appended to the list.
	AllowedHeaders []string `json:"allowed_headers"`

	// ExposedHeaders indicates which headers are safe to expose to the API of a CORS
	// API specification
	ExposedHeaders []string `json:"exposed_headers"`

	// AllowCredentials indicates whether the request can include user credentials like
	// cookies, HTTP authentication or client side SSL certificates.
	AllowCredentials bool `json:"allow_credentials"`

	// MaxAge indicates how long (in seconds) the results of a preflight request
	// can be cached.
	MaxAge int `json:"max_age"`

	// Debugging flag adds additional output to debug server side CORS issues
	Debug bool `json:"debug"`
}

CORS configuration.

type Config

type Config struct {
	Name        string         `json:"name"`
	Description string         `json:"description"`
	Type        string         `json:"type"`
	Headers     header.Rules   `json:"headers"`
	Redirects   redirect.Rules `json:"redirects"`
	Hooks       Hooks          `json:"hooks"`
	Environment Environment    `json:"environment"`
	Regions     []string       `json:"regions"`
	Profile     string         `json:"profile"`
	Inject      inject.Rules   `json:"inject"`
	Lambda      Lambda         `json:"lambda"`
	CORS        *CORS          `json:"cors"`
	ErrorPages  ErrorPages     `json:"error_pages"`
	Proxy       Relay          `json:"proxy"`
	Static      Static         `json:"static"`
	Logs        Logs           `json:"logs"`
	Stages      Stages         `json:"stages"`
	DNS         DNS            `json:"dns"`
}

Config for the project.

func MustParseConfigString

func MustParseConfigString(s string) *Config

MustParseConfigString returns config from JSON string.

func ParseConfig

func ParseConfig(b []byte) (*Config, error)

ParseConfig returns config from JSON bytes.

func ParseConfigString

func ParseConfigString(s string) (*Config, error)

ParseConfigString returns config from JSON string.

func ReadConfig

func ReadConfig(path string) (*Config, error)

ReadConfig reads the configuration from `path`.

func (*Config) Default

func (c *Config) Default() error

Default implementation.

func (*Config) Override

func (c *Config) Override(stage string) error

Override with stage config if present, and re-validate.

func (*Config) Validate

func (c *Config) Validate() error

Validate implementation.

type DNS

type DNS struct {
	Zones []*Zone `json:"zones"`
}

DNS config.

Example
s := `{
		"something.sh": [
			{
				"name": "something.com",
				"type": "A",
				"ttl": 60,
				"value": ["35.161.83.243"]
			},
			{
				"name": "blog.something.com",
				"type": "CNAME",
				"ttl": 60,
				"value": ["34.209.172.67"]
			},
			{
				"name": "api.something.com",
				"type": "A",
				"value": ["54.187.185.18"]
			}
		]
	}`

var c DNS

if err := json.Unmarshal([]byte(s), &c); err != nil {
	log.Fatalf("error unmarshaling: %s", err)
}

sort.Slice(c.Zones[0].Records, func(i int, j int) bool {
	a := c.Zones[0].Records[i]
	b := c.Zones[0].Records[j]
	return a.Name > b.Name
})

if err := c.Validate(); err != nil {
	log.Fatalf("error validating: %s", err)
}

if err := c.Default(); err != nil {
	log.Fatalf("error defaulting: %s", err)
}

enc := json.NewEncoder(os.Stdout)
enc.SetIndent("", "  ")
enc.Encode(c)
Output:

	{
  "zones": [
    {
      "name": "something.sh",
      "records": [
        {
          "name": "something.com",
          "type": "A",
          "ttl": 60,
          "value": [
            "35.161.83.243"
          ]
        },
        {
          "name": "blog.something.com",
          "type": "CNAME",
          "ttl": 60,
          "value": [
            "34.209.172.67"
          ]
        },
        {
          "name": "api.something.com",
          "type": "A",
          "ttl": 300,
          "value": [
            "54.187.185.18"
          ]
        }
      ]
    }
  ]
}

func (*DNS) Default

func (d *DNS) Default() error

Default implementation.

func (*DNS) UnmarshalJSON

func (d *DNS) UnmarshalJSON(b []byte) error

UnmarshalJSON implementation.

func (*DNS) Validate

func (d *DNS) Validate() error

Validate implementation.

type Duration

type Duration time.Duration

Duration may be specified as numerical seconds or as a duration string such as "1.5m".

func (*Duration) MarshalJSON

func (d *Duration) MarshalJSON() ([]byte, error)

MarshalJSON implement.

func (*Duration) Seconds

func (d *Duration) Seconds() float64

Seconds returns the duration in seconds.

func (*Duration) UnmarshalJSON

func (d *Duration) UnmarshalJSON(b []byte) error

UnmarshalJSON implementation.

type Environment

type Environment map[string]string

Environment variables.

type ErrorPages

type ErrorPages struct {
	// Enable error pages.
	Enable bool `json:"enable"`

	// Dir containing error pages.
	Dir string `json:"dir"`

	// Variables are passed to the template for use.
	Variables map[string]interface{} `json:"variables"`
}

ErrorPages configuration.

func (*ErrorPages) Default

func (e *ErrorPages) Default() error

Default implementation.

type Hook

type Hook []string

Hook is one or more commands.

func (*Hook) IsEmpty

func (h *Hook) IsEmpty() bool

IsEmpty returns true if the hook is empty.

func (*Hook) UnmarshalJSON

func (h *Hook) UnmarshalJSON(b []byte) error

UnmarshalJSON implementation.

type Hooks

type Hooks struct {
	Build      Hook `json:"build"`
	Clean      Hook `json:"clean"`
	PreBuild   Hook `json:"prebuild"`
	PostBuild  Hook `json:"postbuild"`
	PreDeploy  Hook `json:"predeploy"`
	PostDeploy Hook `json:"postdeploy"`
}

Hooks for the project.

func (*Hooks) Get

func (h *Hooks) Get(s string) Hook

Get returns the hook by name or nil.

func (*Hooks) Override

func (h *Hooks) Override(c *Config)

Override config.

type IAMPolicyStatement

type IAMPolicyStatement map[string]interface{}

IAMPolicyStatement configuration.

type Lambda

type Lambda struct {
	// Memory of the function.
	Memory int `json:"memory"`

	// Timeout of the function.
	Timeout int `json:"timeout"`

	// Role of the function.
	Role string `json:"role"`

	// Runtime of the function.
	Runtime string `json:"runtime"`

	// Policy of the function role.
	Policy []IAMPolicyStatement `json:"policy"`

	// VPC configuration.
	VPC *VPC `json:"vpc"`
}

Lambda configuration.

func (*Lambda) Default

func (l *Lambda) Default() error

Default implementation.

func (*Lambda) Override

func (l *Lambda) Override(c *Config)

Override config.

func (*Lambda) Validate

func (l *Lambda) Validate() error

Validate implementation.

type Logs

type Logs struct {
	// Disable json log output.
	Disable bool `json:"disable"`

	// Stdout default log level.
	Stdout string `json:"stdout"`

	// Stderr default log level.
	Stderr string `json:"stderr"`
}

Logs configuration.

func (*Logs) Default

func (l *Logs) Default() error

Default implementation.

type Record

type Record struct {
	Name  string   `json:"name"`
	Type  string   `json:"type"`
	TTL   int      `json:"ttl"`
	Value []string `json:"value"`
}

Record is a DNS record.

func (*Record) Default

func (r *Record) Default() error

Default implementation.

func (*Record) Validate

func (r *Record) Validate() error

Validate implementation.

type Relay

type Relay struct {
	// Command run to start your server.
	Command string `json:"command"`

	// Timeout in seconds to wait for a response.
	Timeout int `json:"timeout"`

	// ListenTimeout in seconds when waiting for the app to bind to PORT.
	ListenTimeout int `json:"listen_timeout"`
}

Relay config.

func (*Relay) Default

func (r *Relay) Default() error

Default implementation.

func (*Relay) Override

func (r *Relay) Override(c *Config)

Override config.

func (*Relay) Validate

func (r *Relay) Validate() error

Validate will try to perform sanity checks for this Relay configuration.

type Runtime

type Runtime string

Runtime is an app runtime.

type Stage

type Stage struct {
	Domain string      `json:"domain"`
	Zone   interface{} `json:"zone"`
	Path   string      `json:"path"`
	Cert   string      `json:"cert"`
	Name   string      `json:"-"`
	StageOverrides
}

Stage config.

func (*Stage) Default

func (s *Stage) Default() error

Default implementation.

func (*Stage) IsLocal

func (s *Stage) IsLocal() bool

IsLocal returns true if the stage represents a local environment.

func (*Stage) IsRemote

func (s *Stage) IsRemote() bool

IsRemote returns true if the stage represents a remote environment.

func (*Stage) Validate

func (s *Stage) Validate() error

Validate implementation.

type StageOverrides

type StageOverrides struct {
	Hooks  Hooks  `json:"hooks"`
	Lambda Lambda `json:"lambda"`
	Proxy  Relay  `json:"proxy"`
}

StageOverrides config.

func (*StageOverrides) Override

func (s *StageOverrides) Override(c *Config)

Override config.

type Stages

type Stages map[string]*Stage

Stages config.

func (Stages) Default

func (s Stages) Default() error

Default implementation.

func (Stages) Domains

func (s Stages) Domains() (v []string)

Domains returns configured domains.

func (Stages) GetByDomain

func (s Stages) GetByDomain(domain string) *Stage

GetByDomain returns the stage by domain or nil.

func (Stages) GetByName

func (s Stages) GetByName(name string) *Stage

GetByName returns the stage by name or nil.

func (Stages) List

func (s Stages) List() (v []*Stage)

List returns configured stages.

func (Stages) Names

func (s Stages) Names() (v []string)

Names returns configured stage names.

func (Stages) RemoteNames

func (s Stages) RemoteNames() (v []string)

RemoteNames returns configured remote stage names.

func (Stages) Validate

func (s Stages) Validate() error

Validate implementation.

type Static

type Static struct {
	// Dir containing static files.
	Dir string `json:"dir"`

	// Prefix is an optional URL prefix for serving static files.
	Prefix string `json:"prefix"`
}

Static configuration.

func (*Static) Validate

func (s *Static) Validate() error

Validate implementation.

type VPC

type VPC struct {
	Subnets        []string `json:"subnets"`
	SecurityGroups []string `json:"security_groups"`
}

VPC configuration.

type Zone

type Zone struct {
	Name    string    `json:"name"`
	Records []*Record `json:"records"`
}

Zone is a DNS zone.

func (*Zone) Default

func (z *Zone) Default() error

Default implementation.

func (*Zone) Validate

func (z *Zone) Validate() error

Validate implementation.

Jump to

Keyboard shortcuts

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