func NewDefaultConfig() *Config {
	return &Config{
		Region:  os.Getenv("AWS_REGION"),
		Timeout: DefaultTimeout,
	}
}
NewDefaultConfig creates a default configuration.
package ecspresso
import (
	"fmt"
	"os"
	"path/filepath"
	"text/template"
	"time"
	"github.com/aws/aws-sdk-go/aws"
	"github.com/aws/aws-sdk-go/aws/session"
	"github.com/fatih/color"
	gv "github.com/hashicorp/go-version"
	"github.com/kayac/ecspresso/appspec"
	gc "github.com/kayac/go-config"
	"github.com/pkg/errors"
)
const (
	DefaultClusterName = "default"
	DefaultTimeout     = 10 * time.Minute
)
type Config struct {
	RequiredVersion       string           `yaml:"required_version,omitempty"`
	Region                string           `yaml:"region"`
	Cluster               string           `yaml:"cluster"`
	Service               string           `yaml:"service"`
	ServiceDefinitionPath string           `yaml:"service_definition"`
	TaskDefinitionPath    string           `yaml:"task_definition"`
	Timeout               time.Duration    `yaml:"timeout"`
	Plugins               []ConfigPlugin   `yaml:"plugins,omitempty"`
	AppSpec               *appspec.AppSpec `yaml:"appspec,omitempty"`
	FilterCommand         string           `yaml:"filter_command,omitempty"`
	templateFuncs      []template.FuncMap
	dir                string
	versionConstraints gv.Constraints
	sess               *session.Session
}
func (c *Config) Load(path string) error {
	if err := gc.LoadWithEnv(c, path); err != nil {
		return err
	}
	c.dir = filepath.Dir(path)
	return c.Restrict()
}
func (c *Config) Restrict() error {
	if c.Cluster == "" {
		c.Cluster = DefaultClusterName
	}
	if c.dir == "" {
		c.dir = "."
	}
	if c.ServiceDefinitionPath != "" && !filepath.IsAbs(c.ServiceDefinitionPath) {
		c.ServiceDefinitionPath = filepath.Join(c.dir, c.ServiceDefinitionPath)
	}
	if c.TaskDefinitionPath != "" && !filepath.IsAbs(c.TaskDefinitionPath) {
		c.TaskDefinitionPath = filepath.Join(c.dir, c.TaskDefinitionPath)
	}
	if c.RequiredVersion != "" {
		constraints, err := gv.NewConstraint(c.RequiredVersion)
		if err != nil {
			return errors.Wrap(err, "required_version has invalid format")
		}
		c.versionConstraints = constraints
	}
	var err error
	c.sess, err = session.NewSessionWithOptions(session.Options{
		Config:            aws.Config{Region: aws.String(c.Region)},
		SharedConfigState: session.SharedConfigEnable,
	})
	return err
}
func (c *Config) setupPlugins() error {
	for _, p := range c.Plugins {
		if err := p.Setup(c); err != nil {
			return err
		}
	}
	return nil
}
func (c *Config) ValidateVersion(version string) error {
	if c.versionConstraints == nil {
		return nil
	}
	v, err := gv.NewVersion(version)
	if err != nil {
		fmt.Println(
			color.YellowString("WARNING: Invalid version format \"%s\". Skip checking required_version.", version),
		)
		return nil
	}
	if !c.versionConstraints.Check(v) {
		return errors.Errorf("version %s does not satisfy constraints required_version: %s", version, c.versionConstraints)
	}
	return nil
}