launchpad.net/~rogpeppe/juju-core/500-errgo-fix@v0.0.0-20140213181702-000000002356/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 "launchpad.net/errgo/errors" 8 "launchpad.net/juju-core/state" 9 ) 10 11 // isMachineWithJob returns whether the given entity is a machine that 12 // is configured to run the given job. 13 func isMachineWithJob(e state.Authenticator, j state.MachineJob) bool { 14 m, ok := e.(*state.Machine) 15 if !ok { 16 return false 17 } 18 for _, mj := range m.Jobs() { 19 if mj == j { 20 return true 21 } 22 } 23 return false 24 } 25 26 // isAgent returns whether the given entity is an agent. 27 func isAgent(e state.Authenticator) bool { 28 _, isUser := e.(*state.User) 29 return !isUser 30 } 31 32 func setPassword(e state.Authenticator, password string) error { 33 // Catch expected common case of misspelled 34 // or missing Password parameter. 35 if password == "" { 36 return errors.Newf("password is empty") 37 } 38 return e.SetPassword(password) 39 }