コード例 #1
0
func (r *RedisConnector) Loop(parsed chan mgollective.Message) {
	for msg := range r.subs.Messages {
		// ruby symbols/YAML encoding is special
		// Pretend like it was just a string with a colon
		silly_ruby, _ := regexp.Compile("!ruby/sym ")
		wire := silly_ruby.ReplaceAll(msg.Elem, []byte(":"))

		var wrapper RedisMessageWrapper
		if err := goyaml.Unmarshal(wire, &wrapper); err != nil {
			r.app.Debug("YAML Unmarshal wrapper", err)
			r.app.Info("Recieved undecodable message, skipping it")
			continue
		}
		r.app.Tracef("unpackged wrapper %+v", wrapper)

		var body mgollective.MessageBody
		if err := goyaml.Unmarshal([]byte(wrapper.Body), &body); err != nil {
			r.app.Debug("YAML Unmarshal body", err)
			continue
		}

		message := mgollective.Message{
			Topic:    msg.Channel,
			Reply_to: wrapper.Headers["reply-to"],
			Body:     body,
		}
		parsed <- message
	}
}
コード例 #2
0
ファイル: get_test.go プロジェクト: jameinel/core
func (s *GetSuite) TestGetConfig(c *gc.C) {
	sch := s.AddTestingCharm(c, "dummy")
	svc := s.AddTestingService(c, "dummy-service", sch)
	err := svc.UpdateConfigSettings(charm.Settings{"title": "Nearly There"})
	c.Assert(err, gc.IsNil)
	for _, t := range getTests {
		ctx := coretesting.Context(c)
		code := cmd.Main(&GetCommand{}, ctx, []string{t.service})
		c.Check(code, gc.Equals, 0)
		c.Assert(ctx.Stderr.(*bytes.Buffer).String(), gc.Equals, "")
		// round trip via goyaml to avoid being sucked into a quagmire of
		// map[interface{}]interface{} vs map[string]interface{}. This is
		// also required if we add json support to this command.
		buf, err := goyaml.Marshal(t.expected)
		c.Assert(err, gc.IsNil)
		expected := make(map[string]interface{})
		err = goyaml.Unmarshal(buf, &expected)
		c.Assert(err, gc.IsNil)

		actual := make(map[string]interface{})
		err = goyaml.Unmarshal(ctx.Stdout.(*bytes.Buffer).Bytes(), &actual)
		c.Assert(err, gc.IsNil)
		c.Assert(actual, gc.DeepEquals, expected)
	}
}
コード例 #3
0
ファイル: hosts.go プロジェクト: ElricleNecro/TOD
// A function to read an hosts file in the YAML format and returns
// a dictionary in the same format as the structured file.
func ReadHostsYAML(
	filename string,
) *Hosts {

	// Start by reading the whole file in byte
	data, _ := ioutil.ReadFile(filename)

	// Create the variable handling the type of the user file
	t := &Hosts{}

	// Now read in the YAML file the structure of the file into
	// the structured dictionary
	err := goyaml.Unmarshal(
		data,
		t,
	)

	// Check error when reading the file
	if err != nil {
		formatter.ColoredPrintln(
			formatter.Red,
			false,
			"The file "+filename+" can't be read for accessing"+
				"the YAML structure!\n"+
				"Reason is: "+err.Error(),
		)
		return nil
	}

	// return the structured file and data
	return t

}
コード例 #4
0
ファイル: decode_test.go プロジェクト: 9cc9/dea_ng
func (s *S) TestUnmarshal(c *C) {
	for i, item := range unmarshalTests {
		t := reflect.ValueOf(item.value).Type()
		var value interface{}
		switch t.Kind() {
		case reflect.Map:
			value = reflect.MakeMap(t).Interface()
		case reflect.String:
			t := reflect.ValueOf(item.value).Type()
			v := reflect.New(t)
			value = v.Interface()
		default:
			pt := reflect.ValueOf(item.value).Type()
			pv := reflect.New(pt.Elem())
			value = pv.Interface()
		}
		err := goyaml.Unmarshal([]byte(item.data), value)
		c.Assert(err, IsNil, Commentf("Item #%d", i))
		if t.Kind() == reflect.String {
			c.Assert(*value.(*string), Equals, item.value, Commentf("Item #%d", i))
		} else {
			c.Assert(value, DeepEquals, item.value, Commentf("Item #%d", i))
		}
	}
}
コード例 #5
0
func LoadConfiguration(configPath *string) {
	if !Exists(*configPath) {
		return
	}

	m := make(map[interface{}]interface{})
	data, err := ioutil.ReadFile(*configPath)
	if err != nil {
		panic(fmt.Sprintf("Error reading file %s : %v", configPath, err))
	}

	goyaml.Unmarshal([]byte(data), &m)

	if val, ok := m["sourceDirectory"]; ok {
		Configuration.SourcePath = val.(string)
	}

	if val, ok := m["destinationDirectory"]; ok {
		Configuration.DestinationPath = val.(string)
	}

	if val, ok := m["processFilesWithExtension"]; ok {
		vals := val.([]interface{})
		exts := make([]string, len(vals))
		for idx, val := range vals {
			exts[idx] = val.(string)
		}
		Configuration.ProcessFileExtensions = exts
	}
}
コード例 #6
0
ファイル: bootstrap.go プロジェクト: prabhakhar/juju-core
// Set decodes the base64 value into yaml then expands that into a map.
func (v *yamlBase64Value) Set(value string) error {
	decoded, err := base64.StdEncoding.DecodeString(value)
	if err != nil {
		return err
	}
	return goyaml.Unmarshal(decoded, v)
}
コード例 #7
0
ファイル: provisioner.go プロジェクト: elimisteve/tsuru
func (p *JujuProvisioner) CollectStatus() ([]provision.Unit, error) {
	output, err := execWithTimeout(30e9, "juju", "status")
	if err != nil {
		return nil, &provision.Error{Reason: string(output), Err: err}
	}
	var out jujuOutput
	err = goyaml.Unmarshal(output, &out)
	if err != nil {
		return nil, &provision.Error{Reason: `"juju status" returned invalid data`, Err: err}
	}
	var units []provision.Unit
	for name, service := range out.Services {
		for unitName, u := range service.Units {
			machine := out.Machines[u.Machine]
			unit := provision.Unit{
				Name:       unitName,
				AppName:    name,
				Machine:    u.Machine,
				InstanceId: machine.InstanceId,
				Ip:         machine.IpAddress,
			}
			typeRegexp := regexp.MustCompile(`^(local:)?(\w+)/(\w+)-\d+$`)
			matchs := typeRegexp.FindStringSubmatch(service.Charm)
			if len(matchs) > 3 {
				unit.Type = matchs[3]
			}
			unit.Status = unitStatus(machine.InstanceState, u.AgentState, machine.AgentState)
			units = append(units, unit)
		}
	}
	return units, nil
}
コード例 #8
0
func (t *cloudinitTest) check(c *C) {
	ci, err := cloudinit.New(&t.cfg)
	c.Assert(err, IsNil)
	c.Check(ci, NotNil)
	// render the cloudinit config to bytes, and then
	// back to a map so we can introspect it without
	// worrying about internal details of the cloudinit
	// package.
	data, err := ci.Render()
	c.Assert(err, IsNil)

	x := make(map[interface{}]interface{})
	err = goyaml.Unmarshal(data, &x)
	c.Assert(err, IsNil)

	c.Check(x["apt_upgrade"], Equals, true)
	c.Check(x["apt_update"], Equals, true)

	scripts := getScripts(x)
	scriptDiff(c, scripts, t.expectScripts)
	if t.cfg.Config != nil {
		checkEnvConfig(c, t.cfg.Config, x, scripts)
	}
	checkPackage(c, x, "git", true)
}
コード例 #9
0
ファイル: config.go プロジェクト: klyachin/juju
// ReadEnvironsBytes parses the contents of an environments.yaml file
// and returns its representation. An environment with an unknown type
// will only generate an error when New is called for that environment.
// Attributes for environments with known types are checked.
func ReadEnvironsBytes(data []byte) (*Environs, error) {
	var raw struct {
		Default      string
		Environments map[string]map[string]interface{}
	}
	err := goyaml.Unmarshal(data, &raw)
	if err != nil {
		return nil, err
	}

	if raw.Default != "" && raw.Environments[raw.Default] == nil {
		return nil, fmt.Errorf("default environment %q does not exist", raw.Default)
	}
	if raw.Default == "" {
		// If there's a single environment, then we get the default
		// automatically.
		if len(raw.Environments) == 1 {
			for name := range raw.Environments {
				raw.Default = name
				break
			}
		}
	}
	for name, attrs := range raw.Environments {
		// store the name of the this environment in the config itself
		// so that providers can see it.
		attrs["name"] = name
	}
	return &Environs{raw.Default, raw.Environments}, nil
}
コード例 #10
0
ファイル: test-instances.go プロジェクト: bortzmeyer/dns-lg
func main() {
	var (
		filename string
	)
	verbose = flag.Bool("v", false, "verbose mode, displays a line for every instance")
	flag.Parse()
	if flag.NArg() == 1 {
		filename = flag.Arg(0)
	} else {
		panic("Usage: test-instances filename.yaml\n")
	}
	file, err := os.Open(filename)
	if err != nil {
		panic(err)
	}
	data := make([]byte, 1000000)
	count, err := file.Read(data)
	if err != nil {
		panic(err)
	}
	list := endpointsArray{}
	err = goyaml.Unmarshal(data[:count], &list)
	if err != nil {
		panic(err)
	}
	toReporter := make(chan instanceTest)
	fromReporter := make(chan string)
	go reporter(toReporter, fromReporter, len(list))

	for i := 0; i < len(list); i++ {
		go checkOne(toReporter, list[i].Endpoint)
	}
	<-fromReporter
}
コード例 #11
0
ファイル: config.go プロジェクト: BillSun/ngrok
func SaveAuthToken(configPath, authtoken string) (err error) {
	// empty configuration by default for the case that we can't read it
	c := new(Configuration)

	// read the configuration
	oldConfigBytes, err := ioutil.ReadFile(configPath)
	if err == nil {
		// unmarshal if we successfully read the configuration file
		if err = goyaml.Unmarshal(oldConfigBytes, c); err != nil {
			return
		}
	}

	// no need to save, the authtoken is already the correct value
	if c.AuthToken == authtoken {
		return
	}

	// update auth token
	c.AuthToken = authtoken

	// rewrite configuration
	newConfigBytes, err := goyaml.Marshal(c)
	if err != nil {
		return
	}

	err = ioutil.WriteFile(configPath, newConfigBytes, 0600)
	return
}
コード例 #12
0
ファイル: server.go プロジェクト: 42floors/waitress
func parseConfigFile(n string) (*proxyHandler, error) {
	file, err := os.Open(n)

	if err != nil {
		return nil, err
	}

	var h *proxyHandler
	data, err := ioutil.ReadAll(file)

	if err != nil {
		return nil, err
	}

	err = goyaml.Unmarshal(data, &h)
	if err != nil {
		return nil, err
	}

	if h.Watermark != "" {
		file, err = os.Open(h.Watermark)
		h.watermarkImage, _, err = image.Decode(file)
		if err != nil {
			return nil, err
		}
	}

	h.backgroundColor = color.RGBA{80, 80, 80, 1}
	return h, nil
}
コード例 #13
0
ファイル: generate.go プロジェクト: kublaj/zas
/*
 * Extracts first HTML commend as map. It expects it as a valid YAML map.
 */
func (gen *Generator) extractPageConfig(doc *html.HtmlDocument) (config map[interface{}]interface{}, err error) {
	result, _ := doc.Search("//comment()")
	if len(result) > 0 {
		err = yaml.Unmarshal([]byte(result[0].Content()), &config)
	}
	return
}
コード例 #14
0
ファイル: frontmatter.go プロジェクト: GeertJohan/hugo
func HandleYamlMetaData(datum []byte) (interface{}, error) {
	m := map[string]interface{}{}
	if err := goyaml.Unmarshal(datum, &m); err != nil {
		return m, err
	}
	return m, nil
}
コード例 #15
0
ファイル: config.go プロジェクト: zorkian/singularity
func parseConfigFile(fn string) {
	file, err := os.Open(fn)
	if err != nil {
		log.Error("failed to open %s: %s", fn, err)
		return
	}

	b, err := ioutil.ReadAll(file)
	if err != nil {
		log.Error("failed reading from %s: %s", fn, err)
		return
	}

	newstanzas := make(map[string]*sngConfig)
	err = yaml.Unmarshal(b, &newstanzas)
	if err != nil {
		log.Error("file is invalid %s: %s", fn, err)
	}

	// Validate configuration stanzas. This ensures that something is not
	// terribly broken with a config.
	for k, v := range newstanzas {
		v.Version = cfgVersion // Force to current version.
		v.Name = k
		v.Running = false
		mergeStanza(v)
	}
	synchronizeStanzas()
}
コード例 #16
0
ファイル: database.go プロジェクト: hc5duke/bones
// Uses connection info from $DATABASE_URL if
// available.
// If not, use info from PROJECT_ROOT/db/database.yaml
func initConnectionString() {
	database_url := os.Getenv("DATABASE_URL")

	if database_url != "" {
		connectionString = database_url
	} else {
		databaseEnvironments := new(DatabaseEnvironments)

		yaml, err := ioutil.ReadFile("./db/database.yaml")

		if err != nil {
			panic(err)
		}

		err = goyaml.Unmarshal(yaml, databaseEnvironments)

		if err != nil {
			panic(err)
		}

		env := Env().String()

		switch env {
		case "development":
			connectionString = databaseEnvironments.Development
		case "test":
			connectionString = databaseEnvironments.Test
		case "production":
			connectionString = databaseEnvironments.Production
		default:
			panic(fmt.Sprintf("No database config for environment %s", env))
		}
	}
}
コード例 #17
0
ファイル: pageset.go プロジェクト: redneckbeard/penny
func (ps *PageSet) Configure(path string) {
	if raw, err := ioutil.ReadFile(path); err == nil {
		if err := goyaml.Unmarshal(raw, ps); err != nil {
			panic(raw)
		}
	}
}
コード例 #18
0
ファイル: config.go プロジェクト: jameinel/core
// ParseSettingsYAML returns settings derived from the supplied YAML data. The
// YAML must unmarshal to a map of strings to settings data; the supplied key
// must be present in the map, and must point to a map in which every value
// must have, or be a string parseable to, the correct type for the associated
// config option. Empty strings and nil values are both interpreted as nil.
func (c *Config) ParseSettingsYAML(yamlData []byte, key string) (Settings, error) {
	var allSettings map[string]Settings
	if err := goyaml.Unmarshal(yamlData, &allSettings); err != nil {
		return nil, fmt.Errorf("cannot parse settings data: %v", err)
	}
	settings, ok := allSettings[key]
	if !ok {
		return nil, fmt.Errorf("no settings found for %q", key)
	}
	out := make(Settings)
	for name, value := range settings {
		option, err := c.option(name)
		if err != nil {
			return nil, err
		}
		// Accept string values for compatibility with python.
		if str, ok := value.(string); ok {
			if value, err = option.parse(name, str); err != nil {
				return nil, err
			}
		} else if value, err = option.validate(name, value); err != nil {
			return nil, err
		}
		out[name] = value
	}
	return out, nil
}
コード例 #19
0
ファイル: config.go プロジェクト: klyachin/juju
func loadConfig(agentConfig agent.Config) (*config, error) {
	config := &config{
		storageDir:  agentConfig.Value(StorageDir),
		storageAddr: agentConfig.Value(StorageAddr),
		authkey:     agentConfig.Value(StorageAuthKey),
	}

	caCertPEM := agentConfig.Value(StorageCACert)
	if len(caCertPEM) > 0 {
		config.caCertPEM = caCertPEM
	}

	caKeyPEM := agentConfig.Value(StorageCAKey)
	if len(caKeyPEM) > 0 {
		config.caKeyPEM = caKeyPEM
	}

	hostnames := agentConfig.Value(StorageHostnames)
	if len(hostnames) > 0 {
		err := goyaml.Unmarshal([]byte(hostnames), &config.hostnames)
		if err != nil {
			return nil, err
		}
	}

	return config, nil
}
コード例 #20
0
ファイル: config.go プロジェクト: jameinel/core
// ReadConfig reads a Config in YAML format.
func ReadConfig(r io.Reader) (*Config, error) {
	data, err := ioutil.ReadAll(r)
	if err != nil {
		return nil, err
	}
	var config *Config
	if err := goyaml.Unmarshal(data, &config); err != nil {
		return nil, err
	}
	if config == nil {
		return nil, fmt.Errorf("invalid config: empty configuration")
	}
	for name, option := range config.Options {
		switch option.Type {
		case "string", "int", "float", "boolean":
		case "":
			// Missing type is valid in python.
			option.Type = "string"
		default:
			return nil, fmt.Errorf("invalid config: option %q has unknown type %q", name, option.Type)
		}
		def := option.Default
		if def == "" && option.Type == "string" {
			// Skip normal validation for compatibility with pyjuju.
		} else if option.Default, err = option.validate(name, def); err != nil {
			option.error(&err, name, def)
			return nil, fmt.Errorf("invalid config default: %v", err)
		}
		config.Options[name] = option
	}
	return config, nil
}
コード例 #21
0
ファイル: config.go プロジェクト: sigmonsays/woodhouse
func (c *BotConfig) LoadYamlBuffer(buf []byte) error {
	err := goyaml.Unmarshal(buf, c)
	if err != nil {
		return err
	}
	return nil
}
コード例 #22
0
ファイル: env.go プロジェクト: kinghrothgar/goat
// unmarshal takes in some bytes and tries to decode them into a GoatEnv
// structure
func unmarshal(genvraw []byte) (*GoatEnv, error) {
	genv := GoatEnv{}
	if err := goyaml.Unmarshal(genvraw, &genv); err != nil {
		return nil, err
	}
	return &genv, nil
}
コード例 #23
0
func TestListIsValid(t *testing.T) {
	contents, err := ioutil.ReadFile(validateYmlPath)
	if err != nil {
		t.Errorf("Error reading validate.yml: %v", err)
		t.FailNow()
	}

	var testData map[interface{}]interface{}
	err = goyaml.Unmarshal(contents, &testData)

	tests, ok := testData["tests"]
	if !ok {
		t.Errorf("Conformance file was not in expected format.")
		t.FailNow()
	}

	listTests, ok := tests.(map[interface{}]interface{})["lists"]
	if !ok {
		t.Errorf("Conformance file did not contain list tests")
		t.FailNow()
	}

	for _, testCase := range listTests.([]interface{}) {
		test := testCase.(map[interface{}]interface{})
		text, _ := test["text"]
		description, _ := test["description"]
		expected, _ := test["expected"]

		actual := ListIsValid(text.(string))
		if actual != expected {
			t.Errorf("ListIsValid returned incorrect value for test [%s]. Expected:%v Got:%v", description, expected, actual)
		}
	}
}
コード例 #24
0
ファイル: script.go プロジェクト: Jyggafey/drone
func ParseBuild(data []byte, params map[string]string) (*Build, error) {
	build := Build{}

	// parse the build configuration file
	err := goyaml.Unmarshal(injectParams(data, params), &build)
	return &build, err
}
コード例 #25
0
ファイル: page.go プロジェクト: GuoJing/hugo
func (page *Page) handleYamlMetaData(datum []byte) (interface{}, error) {
	m := map[string]interface{}{}
	if err := goyaml.Unmarshal(datum, &m); err != nil {
		return m, fmt.Errorf("Invalid YAML in %s \nError parsing page meta data: %s", page.FileName, err)
	}
	return m, nil
}
コード例 #26
0
ファイル: trivial.go プロジェクト: prabhakhar/juju-core
// ReadYaml unmarshals the yaml contained in the file at path into obj. See
// goyaml.Unmarshal.
func ReadYaml(path string, obj interface{}) error {
	data, err := ioutil.ReadFile(path)
	if err != nil {
		return err
	}
	return goyaml.Unmarshal(data, obj)
}
コード例 #27
0
ファイル: application.go プロジェクト: raphael/gotcha
// Load configuration settings and setup database connection
func init() {
	globalSettings := make(map[string]string)
	var confFile string
	flag.StringVar(&confFile, "config", "config.yml", "Path to config file")
	flag.Parse()
	if confFile, err := filepath.Abs(confFile); err != nil {
		log.Printf("Cannot find configuration file '%v', using default settings", confFile)
	} else if raw, err := ioutil.ReadFile(confFile); err != nil {
		log.Printf("[%v] Cannot load configuration file '%v', using default settings", os.Getpid(), confFile)
	} else {
		err := goyaml.Unmarshal(raw, &globalSettings)
		if err != nil {
			log.Printf("Cannot load configuration settings: %v", err)
		}
	}
	for setting, value := range defaultSettings() {
		if _, ok := globalSettings[setting]; !ok {
			globalSettings[setting] = value
		}
	}
	msg, err := goyaml.Marshal(&globalSettings)
	if err != nil {
		log.Fatalf("Could not log settings: %v", err)
	}
	log.Printf("Startup settings:\n%s", msg)

	gotcha.StartSession(globalSettings["mongoHost"], globalSettings["mongoUser"],
		globalSettings["mongoPassword"], globalSettings["environment"])
}
コード例 #28
0
ファイル: user_agent_test.go プロジェクト: lpearce/ua-parser
func uaInitTesting(file string) []map[string]string {
	fmt.Print(file + ": ")
	testFile, _ := ioutil.ReadFile(file)
	testMap := make(map[string][]map[string]string)
	_ = goyaml.Unmarshal(testFile, &testMap)
	return testMap["test_cases"]
}
コード例 #29
0
ファイル: decode_test.go プロジェクト: 9cc9/dea_ng
func (s *S) TestUnmarshalErrors(c *C) {
	for _, item := range unmarshalErrorTests {
		var value interface{}
		err := goyaml.Unmarshal([]byte(item.data), &value)
		c.Assert(err, ErrorMatches, item.error, Commentf("Partial unmarshal: %#v", value))
	}
}
コード例 #30
0
ファイル: config.go プロジェクト: jedibatman/ngrok
func SaveAuthToken(configPath, authtoken string) (err error) {
	// read the configuration
	oldConfigBytes, err := ioutil.ReadFile(configPath)
	if err != nil {
		return
	}

	c := new(Configuration)
	if err = goyaml.Unmarshal(oldConfigBytes, c); err != nil {
		return
	}

	// no need to save, the authtoken is already the correct value
	if c.AuthToken == authtoken {
		return
	}

	// update auth token
	c.AuthToken = authtoken

	// rewrite configuration
	newConfigBytes, err := goyaml.Marshal(c)
	if err != nil {
		return
	}

	err = ioutil.WriteFile(configPath, newConfigBytes, 0600)
	return
}