// UnmarshalServerResource unmarshals role from JSON or YAML,
// sets defaults and checks the schema
UnmarshalServerResource unmarshals role from JSON or YAML,
sets defaults and checks the schema
// UnmarshalServerResource unmarshals role from JSON or YAML // sets defaults and checks the schema
func UnmarshalServerResource(data []byte, kind string, cfg *MarshalConfig) (Server, error) {
	if len(data) == 0 {
		return nil, trace.BadParameter("missing server data")
	}
	var h ResourceHeader
	err := utils.FastUnmarshal(data, &h)
	if err != nil {
		return nil, trace.Wrap(err)
	}
	switch h.Version {
	case V2:
		var s ServerV2
		if cfg.SkipValidation {
			if err := utils.FastUnmarshal(data, &s); err != nil {
				return nil, trace.BadParameter(err.Error())
			}
		} else {
			if err := utils.UnmarshalWithSchema(GetServerSchema(), &s, data); err != nil {
				return nil, trace.BadParameter(err.Error())
			}
		}
		s.Kind = kind
		if err := s.CheckAndSetDefaults(); err != nil {
			return nil, trace.Wrap(err)
		}
		if cfg.ID != 0 {
			s.SetResourceID(cfg.ID)
		}
		if !cfg.Expires.IsZero() {
			s.SetExpiry(cfg.Expires)
		}
		return &s, nil
	}
	return nil, trace.BadParameter("server resource version %q is not supported", h.Version)
}
func UnmarshalServerResource ( data [ ] byte , kind string , cfg * MarshalConfig ) ( Server , error ) { if len ( data ) == 0 { return nil , trace . BadParameter ( " " ) } var h ResourceHeader err := utils . FastUnmarshal ( data , & h ) if err != nil { return nil , trace . Wrap ( err ) } switch h . Version { case V2 : var s ServerV2 if cfg . SkipValidation { if err := utils . FastUnmarshal ( data , & s ) ; err != nil { return nil , trace . BadParameter ( err . Error ( ) ) } } else { if err := utils . UnmarshalWithSchema ( GetServerSchema ( ) , & s , data ) ; err != nil { return nil , trace . BadParameter ( err . Error ( ) ) } } s . Kind = kind if err := s . CheckAndSetDefaults ( ) ; err != nil { return nil , trace . Wrap ( err ) } if cfg . ID != 0 { s . SetResourceID ( cfg . ID ) } if ! cfg . Expires . IsZero ( ) { s . SetExpiry ( cfg . Expires ) } return & s , nil } return nil , trace . BadParameter ( " " , h . Version ) }
UnmarshalServerResource unmarshals role from JSON or YAML,
sets defaults and checks the schema
UnmarshalServerResource unmarshals role from JSON or YAML sets defaults and checks the schema