// expandConfig creates task queue tasks to create each VM in the given config.
179409
func expandConfig(c context.Context, payload proto.Message) error {
	task, ok := payload.(*tasks.ExpandConfig)
	switch {
	case !ok:
		return errors.Reason("unexpected payload type %T", payload).Err()
	case task.GetId() == "":
		return errors.Reason("ID is required").Err()
	}
	cfg, err := getConfig(c).Get(c, &config.GetRequest{Id: task.Id})
	if err != nil {
		return errors.Annotate(err, "failed to fetch config").Err()
	}
	now := clock.Now(c)
	amt, err := cfg.Amount.GetAmount(now)
	if err != nil {
		return errors.Annotate(err, "failed to parse amount").Err()
	}
	t := make([]*tq.Task, amt)
	for i := int32(0); i < amt; i++ {
		t[i] = &tq.Task{
			Payload: &tasks.CreateVM{
				Id:         fmt.Sprintf("%s-%d", cfg.Prefix, i),
				Attributes: cfg.Attributes,
				Config:     task.Id,
				Created: &timestamp.Timestamp{
					Seconds: now.Unix(),
				},
				Index:    i,
				Lifetime: cfg.Lifetime.GetSeconds(),
				Prefix:   cfg.Prefix,
				Revision: cfg.Revision,
				Swarming: cfg.Swarming,
				Timeout:  cfg.Timeout.GetSeconds(),
			},
		}
	}
	logging.Debugf(c, "creating %d VMs", len(t))
	if err := getDispatcher(c).AddTask(c, t...); err != nil {
		return errors.Annotate(err, "failed to schedule tasks").Err()
	}
	return nil
}
1310063
func newConfig(old *Config, vars Vars) *Config {
	v := mergeVars(old.Vars, vars)

	return &Config{
		AppID: old.AppID,
		Vars:  v,
	}
}
958036
func expandInstanceNetworks(allInstanceNetworks []InstanceNetwork) []servers.Network {
	var networks []servers.Network
	for _, v := range allInstanceNetworks {
		n := servers.Network{
			UUID:    v.UUID,
			Port:    v.Port,
			FixedIP: v.FixedIP,
		}
		networks = append(networks, n)
	}

	return networks
}
19526
func expandEcsVolumes(configured []interface{}) ([]*ecs.Volume, error) {
	volumes := make([]*ecs.Volume, 0, len(configured))

	// Loop over our configured volumes and create
	// an array of aws-sdk-go compatible objects
	for _, lRaw := range configured {
		data := lRaw.(map[string]interface{})

		l := &ecs.Volume{
			Name: aws.String(data["name"].(string)),
		}

		hostPath := data["host_path"].(string)
		if hostPath != "" {
			l.Host = &ecs.HostVolumeProperties{
				SourcePath: aws.String(hostPath),
			}
		}

		configList, ok := data["docker_volume_configuration"].([]interface{})
		if ok && len(configList) > 0 {
			config := configList[0].(map[string]interface{})
			l.DockerVolumeConfiguration = &ecs.DockerVolumeConfiguration{}

			if v, ok := config["scope"].(string); ok && v != "" {
				l.DockerVolumeConfiguration.Scope = aws.String(v)
			}

			if v, ok := config["autoprovision"]; ok && v != "" {
				scope := l.DockerVolumeConfiguration.Scope
				if scope == nil || *scope != ecs.ScopeTask || v.(bool) {
					l.DockerVolumeConfiguration.Autoprovision = aws.Bool(v.(bool))
				}
			}

			if v, ok := config["driver"].(string); ok && v != "" {
				l.DockerVolumeConfiguration.Driver = aws.String(v)
			}

			if v, ok := config["driver_opts"].(map[string]interface{}); ok && len(v) > 0 {
				l.DockerVolumeConfiguration.DriverOpts = stringMapToPointers(v)
			}

			if v, ok := config["labels"].(map[string]interface{}); ok && len(v) > 0 {
				l.DockerVolumeConfiguration.Labels = stringMapToPointers(v)
			}
		}

		volumes = append(volumes, l)
	}

	return volumes, nil
}
917365
func (t *Term) loadConfig() api.LoadConfig {
	r := api.LoadConfig{true, 1, 64, 64, -1}

	if t.conf != nil && t.conf.MaxStringLen != nil {
		r.MaxStringLen = *t.conf.MaxStringLen
	}
	if t.conf != nil && t.conf.MaxArrayValues != nil {
		r.MaxArrayValues = *t.conf.MaxArrayValues
	}

	return r
}
1351291
func ExpandPath(path string) string {
	usr, err := user.Current()
	if err != nil {
		return path
	}

	if path == "~" {
		return usr.HomeDir
	} else if strings.HasPrefix(path, "~/") {
		return filepath.Join(usr.HomeDir, path[2:])
	}

	return path
}
525544
func expandEnvVFS(fs afero.Fs, s string) string {
	return os.Expand(s, func(s string) string {
		return getenvVFS(fs, s)
	})
}
692056
func ExpandConfigPath(path, defaultPath string) (string, error) {
	if path != "" {
		return ExpandPath(path, false)
	}

	configHome := lookupConfigHome()
	if configHome != "" {
		return filepath.Join(configHome, defaultPath), nil
	}

	return ExpandPath(fmt.Sprintf("~/.config/%s", defaultPath), false)
}
679125
func LoadConfig(path string) (*DefaultConfig, error) {
	if path == "" {
		path = DefaultConfigPath
	}
	if v := os.Getenv(ConfigPathEnv); v != "" {
		path = v
	}

	// NOTE: requires HOME env var to be set
	path, err := homedir.Expand(path)
	if err != nil {
		return nil, errwrap.Wrapf(fmt.Sprintf("error expanding config path %q: {{err}}", path), err)
	}

	contents, err := ioutil.ReadFile(path)
	if err != nil && !os.IsNotExist(err) {
		return nil, err
	}

	conf, err := ParseConfig(string(contents))
	if err != nil {
		return nil, errwrap.Wrapf(fmt.Sprintf("error parsing config file at %q: {{err}}; ensure that the file is valid; Ansible Vault is known to conflict with it.", path), err)
	}

	return conf, nil
}
288453
func (v *vserver) expandChecks() map[checkKey]*check {
	checks := make(map[checkKey]*check)
	for _, svc := range v.services {
		for _, dest := range svc.dests {
			dest.checks = make([]*check, 0)
			if !dest.backend.Enabled {
				continue
			}
			for _, hc := range v.config.Healthchecks {
				// vserver-level healthchecks
				key := newCheckKey(svc.ip, dest.ip, 0, 0, hc)
				c := checks[key]
				if c == nil {
					c = newCheck(key, v, hc)
					checks[key] = c
				}
				dest.checks = append(dest.checks, c)
				c.dests = append(c.dests, dest)
			}

			// ventry-level healthchecks
			if v.config.UseFWM {
				for _, ve := range svc.vserver.config.Entries {
					for _, hc := range ve.Healthchecks {
						key := newCheckKey(svc.ip, dest.ip, ve.Port, ve.Proto, hc)
						c := newCheck(key, v, hc)
						checks[key] = c
						dest.checks = append(dest.checks, c)
						c.dests = append(c.dests, dest)
					}
				}
			} else {
				for _, hc := range svc.ventry.Healthchecks {
					key := newCheckKey(svc.ip, dest.ip, svc.port, svc.proto, hc)
					c := newCheck(key, v, hc)
					checks[key] = c
					dest.checks = append(dest.checks, c)
					c.dests = append(c.dests, dest)
				}
			}
		}
	}
	return checks
}
223567
func DefaultExpander() Expander {
	p := Platform{platform.CurrentOS(), platform.CurrentArchitecture()}
	return p.Expander()
}
647148
func (p *Project) AddConfig(name string, config *config.ServiceConfig) error {
	p.Notify(events.ServiceAdd, name, nil)

	p.ServiceConfigs.Add(name, config)
	p.reload = append(p.reload, name)

	return nil
}
890627
func (c *Config) Config() *Config {
	// Guard against nil pointer dereference
	if c == nil {
		return NewConfig()
	}

	// Return a clone of the config so that this is immutable for the receiver
	c2 := *c
	return &c2
}
298689
func Expand(config []byte, envs map[string]string) []byte {
	return []byte(
		ExpandString(string(config), envs),
	)
}
28016
func NewConfig() Config {
	return Config{
		RetentionInterval:   toml.Duration(DefaultRetentionInterval),
		ValidateKeys:        DefaultValidateKeys,
		TraceLoggingEnabled: DefaultTraceLoggingEnabled,

		WAL:    tsm1.NewWALConfig(),
		Engine: tsm1.NewConfig(),
		Index:  tsi1.NewConfig(),
	}
}
1106882
func LoadConfig() (*Config, error) {
	cfg, err := NewConfig(torusRootPath())
	if err != nil {
		return nil, errs.NewErrorExitError("Failed to load config.", err)
	}

	return cfg, nil
}
651375
func (s *Store) Config(service string) *discoverd.ServiceConfig {
	s.mu.RLock()
	defer s.mu.RUnlock()
	return s.data.Services[service]
}