github.com/mattyw/juju@v0.0.0-20140610034352-732aecd63861/state/apiserver/utils.go (about) 1 // Copyright 2013 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package apiserver 5 6 import ( 7 "fmt" 8 9 "github.com/juju/juju/state" 10 ) 11 12 // isMachineWithJob returns whether the given entity is a machine that 13 // is configured to run the given job. 14 func isMachineWithJob(e state.Authenticator, j state.MachineJob) bool { 15 m, ok := e.(*state.Machine) 16 if !ok { 17 return false 18 } 19 for _, mj := range m.Jobs() { 20 if mj == j { 21 return true 22 } 23 } 24 return false 25 } 26 27 // isAgent returns whether the given entity is an agent. 28 func isAgent(e state.Authenticator) bool { 29 _, isUser := e.(*state.User) 30 return !isUser 31 } 32 33 func setPassword(e state.Authenticator, password string) error { 34 // Catch expected common case of misspelled 35 // or missing Password parameter. 36 if password == "" { 37 return fmt.Errorf("password is empty") 38 } 39 return e.SetPassword(password) 40 }