github.com/mattyw/juju@v0.0.0-20140610034352-732aecd63861/agent/export_test.go (about) 1 // Copyright 2013 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package agent 5 6 import ( 7 "fmt" 8 "os" 9 10 "github.com/juju/juju/state/api/params" 11 ) 12 13 func Password(config Config) string { 14 c := config.(*configInternal) 15 if c.stateDetails == nil { 16 return c.apiDetails.password 17 } else { 18 return c.stateDetails.password 19 } 20 return "" 21 } 22 23 func PatchConfig(config Config, fieldName string, value interface{}) error { 24 conf := config.(*configInternal) 25 switch fieldName { 26 case "DataDir": 27 conf.dataDir = value.(string) 28 case "LogDir": 29 conf.logDir = value.(string) 30 case "Jobs": 31 conf.jobs = value.([]params.MachineJob)[:] 32 case "DeleteValues": 33 for _, key := range value.([]string) { 34 delete(conf.values, key) 35 } 36 case "Values": 37 for key, val := range value.(map[string]string) { 38 if conf.values == nil { 39 conf.values = make(map[string]string) 40 } 41 conf.values[key] = val 42 } 43 default: 44 return fmt.Errorf("unknown field %q", fieldName) 45 } 46 conf.configFilePath = ConfigPath(conf.dataDir, conf.tag) 47 return nil 48 } 49 50 func ConfigFileExists(config Config) bool { 51 conf := config.(*configInternal) 52 _, err := os.Lstat(conf.configFilePath) 53 return err == nil 54 }