// FromYAML loads a macine from a YAML definition
350644
func FromYAML(file string, manager WatcherManager) (m *Machine, err error) {
	afile, err := filepath.Abs(file)
	if err != nil {
		return nil, errors.Wrapf(err, "could not determine absolute path for %s", file)
	}

	f, err := ioutil.ReadFile(afile)
	if err != nil {
		return nil, err
	}

	m = &Machine{}
	err = yaml.Unmarshal(f, m)
	if err != nil {
		return nil, err
	}

	m.notifiers = []NotificationService{}
	m.manager = manager
	m.directory = filepath.Dir(afile)
	m.manifest = afile
	m.instanceID = m.UniqueID()

	err = m.manager.SetMachine(m)
	if err != nil {
		return nil, errors.Wrap(err, "could not register with manager")
	}

	err = m.Setup()
	if err != nil {
		return nil, err
	}

	return m, nil
}
348575
func (p *PlateCarreeProjection) FromLatLng(ll LatLng) r2.Point {
	return r2.Point{
		X: p.fromRadians * ll.Lng.Radians(),
		Y: p.fromRadians * ll.Lat.Radians(),
	}
}
938454
func ParseEnvsYML(bytes []byte) ([]models.EnvironmentItemModel, error) {
	var envsYML models.EnvsSerializeModel
	if err := yaml.Unmarshal(bytes, &envsYML); err != nil {
		return []models.EnvironmentItemModel{}, err
	}
	for _, env := range envsYML.Envs {
		if err := env.NormalizeValidateFillDefaults(); err != nil {
			return []models.EnvironmentItemModel{}, err
		}
	}
	return envsYML.Envs, nil
}
828852
func (c *JWTClaims) FromMap(m map[string]interface{}) {
	c.Extra = make(map[string]interface{})
	for k, v := range m {
		switch k {
		case "jti":
			if s, ok := v.(string); ok {
				c.JTI = s
			}
		case "sub":
			if s, ok := v.(string); ok {
				c.Subject = s
			}
		case "iss":
			if s, ok := v.(string); ok {
				c.Issuer = s
			}
		case "aud":
			if s, ok := v.(string); ok {
				c.Audience = []string{s}
			} else if s, ok := v.([]string); ok {
				c.Audience = s
			}
		case "iat":
			switch v.(type) {
			case float64:
				c.IssuedAt = time.Unix(int64(v.(float64)), 0).UTC()
			case int64:
				c.IssuedAt = time.Unix(v.(int64), 0).UTC()
			}
		case "nbf":
			switch v.(type) {
			case float64:
				c.NotBefore = time.Unix(int64(v.(float64)), 0).UTC()
			case int64:
				c.NotBefore = time.Unix(v.(int64), 0).UTC()
			}
		case "exp":
			switch v.(type) {
			case float64:
				c.ExpiresAt = time.Unix(int64(v.(float64)), 0).UTC()
			case int64:
				c.ExpiresAt = time.Unix(v.(int64), 0).UTC()
			}
		case "scp":
			switch v.(type) {
			case []string:
				c.Scope = v.([]string)
			case []interface{}:
				c.Scope = make([]string, len(v.([]interface{})))
				for i, vi := range v.([]interface{}) {
					if s, ok := vi.(string); ok {
						c.Scope[i] = s
					}
				}
			}
		default:
			c.Extra[k] = v
		}
	}
}
161754
func (u URL) MarshalYAML() (interface{}, error) {
	if u.URL != nil {
		return u.String(), nil
	}
	return nil, nil
}
1253578
func NewYAML(filename string) *YAML {
	var r YAML
	fs, _ := os.Open(filename)
	if fs != nil {
		yaml.NewDecoder(fs).Decode(&r.d)
	}
	return &r
}
890324
func FromRaw(configBytes []byte, configType string, opts ...Option) core.ConfigProvider {
	return func() ([]core.ConfigBackend, error) {
		buf := bytes.NewBuffer(configBytes)
		return initFromReader(buf, configType, opts...)
	}
}
908757
func verifyAppYAML(ctx context.Context, repoRes *argoappv1.Repository, spec *argoappv1.ApplicationSpec, repoClient repository.RepoServerServiceClient) error {
	// Default revision to HEAD if unspecified
	if spec.Source.TargetRevision == "" {
		spec.Source.TargetRevision = "HEAD"
	}

	req := repository.GetFileRequest{
		Repo: &argoappv1.Repository{
			Repo: spec.Source.RepoURL,
		},
		Revision: spec.Source.TargetRevision,
		Path:     path.Join(spec.Source.Path, "app.yaml"),
	}
	if repoRes != nil {
		req.Repo.Username = repoRes.Username
		req.Repo.Password = repoRes.Password
		req.Repo.SSHPrivateKey = repoRes.SSHPrivateKey
	}
	getRes, err := repoClient.GetFile(ctx, &req)
	if err != nil {
		return fmt.Errorf("Unable to load app.yaml: %v", err)
	}

	// Verify the specified environment is defined in the app spec
	if spec.Source.Ksonnet == nil {
		return fmt.Errorf("Ksonnet environment not specified")
	}

	dest, err := ksonnet.Destination(getRes.Data, spec.Source.Ksonnet.Environment)
	if err != nil {
		return err
	}

	// If server and namespace are not supplied, pull it from the app.yaml
	if spec.Destination.Server == "" {
		spec.Destination.Server = dest.Server
	}
	if spec.Destination.Namespace == "" {
		spec.Destination.Namespace = dest.Namespace
	}

	return nil
}
325296
func (v *VersionInfo) MarshalYAML() (interface{}, error) {

	return &struct {
		SemVer         string `yaml:"semver"`
		ShaLong        string `yaml:"shaLong"`
		BuildTimestamp int64  `yaml:"buildTimestamp"`
		Branch         string `yaml:"branch"`
		Arch           string `yaml:"arch"`
	}{
		SemVer:         v.SemVer,
		ShaLong:        v.ShaLong,
		BuildTimestamp: v.BuildTimestamp.Unix(),
		Branch:         v.Branch,
		Arch:           v.Arch,
	}, nil
}
1291202
func FromFile(s string) Source {
	f, err := os.Open(s)
	if err != nil {
		return FromMap(nil)
	}
	defer f.Close()
	return FromReader(f)
}
219658
func (s Strings) MarshalYAML() (interface{}, error) {
	if len(s) == 1 {
		return s[0], nil
	}
	return []string(s), nil
}
891747
func (b Build) MarshalYAML() (interface{}, error) {
	m := map[string]interface{}{}
	if b.Context != "" {
		m["context"] = b.Context
	}
	if b.Dockerfile != "" {
		m["dockerfile"] = b.Dockerfile
	}
	if len(b.Args) > 0 {
		m["args"] = b.Args
	}
	if len(b.CacheFrom) > 0 {
		m["cache_from"] = b.CacheFrom
	}
	if len(b.Labels) > 0 {
		m["labels"] = b.Labels
	}
	if b.Target != "" {
		m["target"] = b.Target
	}
	if b.Network != "" {
		m["network"] = b.Network
	}
	return m, nil
}
1058491
func FromFile(filename string, dst interface{}, opts ...Opts) error {
	return DefaultLoader.FromFile(filename, dst, opts...)
}
313780
func _yaml(v map[string]interface{}) string {
	data, err := yaml.Marshal(v)
	if err != nil {
		return err.Error()
	}
	return string(data)
}
29240
func FromFile(file []byte) (*Config, error) {
	config := &Config{}
	if errYAML := yaml.Unmarshal(file, config); errYAML != nil {
		if errJSON := json.Unmarshal(file, config); errJSON != nil {
			return nil, errors.New("could not parse the config file: YAML: " + errYAML.Error() + ", JSON: " + errJSON.Error())
		}
	}

	// We use name and hostname maps to test uniqueness
	resourceNames := make(map[string]struct{})
	resourceHostnames := make(map[string]struct{})
	resourceValidator := validateResource(resourceNames, resourceHostnames)
	if config.Resources != nil {
		for _, resource := range config.Resources {
			if err := resourceValidator(&resource); err != nil {
				return nil, err
			}
			resourceNames[resource.Name] = struct{}{}
			resourceHostnames[resource.Hostname] = struct{}{}
		}
	}

	// We use a name map to test uniqueness
	policyNames := make(map[string]struct{})
	policyValidator := validatePolicy(policyNames, resourceNames)
	if config.Policies != nil {
		for _, policy := range config.Policies {
			if err := policyValidator(&policy); err != nil {
				return nil, err
			}
			policyNames[policy.Name] = struct{}{}
		}
	}

	return config, nil
}
1311981
func FromString(templ string) (*ImportHelper, error) {
	var s ImportHelper
	if err := yaml.Unmarshal([]byte(templ), &s); err != nil {
		log.Info(nil, map[string]interface{}{
			"template": templ,
			"err":      err,
		}, "failed to unmarshal YAML space template")
		return nil, errs.Wrapf(err, "failed to parse YAML space template: \n%s", templ)
	}
	// If the space template has no ID, create one on the fly
	if uuid.Equal(s.Template.ID, uuid.Nil) {
		s.Template.ID = uuid.NewV4()
	}
	// update all refs to this ID
	s.SetID(s.Template.ID)
	if err := s.Validate(); err != nil {
		return nil, errs.Wrap(err, "failed to validate space template")
	}
	return &s, nil
}
260437
func ToYaml(v interface{}) string {
	data, err := yaml.Marshal(v)
	if err != nil {
		// Swallow errors inside of a template.
		return ""
	}
	return string(data)
}