github.com/cloud-green/juju@v0.0.0-20151002100041-a00291338d3d/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/multiwatcher" 11 ) 12 13 func Password(config Config) string { 14 c := config.(*configInternal) 15 if c.stateDetails == nil { 16 return c.apiDetails.password 17 } 18 return c.stateDetails.password 19 } 20 21 func PatchConfig(config Config, fieldName string, value interface{}) error { 22 conf := config.(*configInternal) 23 switch fieldName { 24 case "Paths": 25 paths := value.(Paths) 26 if paths.DataDir != "" { 27 conf.paths.DataDir = paths.DataDir 28 } 29 if paths.LogDir != "" { 30 conf.paths.LogDir = paths.LogDir 31 } 32 case "Jobs": 33 conf.jobs = value.([]multiwatcher.MachineJob)[:] 34 case "DeleteValues": 35 for _, key := range value.([]string) { 36 delete(conf.values, key) 37 } 38 case "Values": 39 for key, val := range value.(map[string]string) { 40 if conf.values == nil { 41 conf.values = make(map[string]string) 42 } 43 conf.values[key] = val 44 } 45 default: 46 return fmt.Errorf("unknown field %q", fieldName) 47 } 48 conf.configFilePath = ConfigPath(conf.paths.DataDir, conf.tag) 49 return nil 50 } 51 52 func ConfigFileExists(config Config) bool { 53 conf := config.(*configInternal) 54 _, err := os.Lstat(conf.configFilePath) 55 return err == nil 56 } 57 58 var ( 59 MachineJobFromParams = machineJobFromParams 60 IsLocalEnv = &isLocalEnv 61 )