func setAgentPassword(newPw, oldPw string, a agent.Agent, entity *apiagent.Entity) error { // Change the configuration *before* setting the entity // password, so that we avoid the possibility that // we might successfully change the entity's // password but fail to write the configuration, // thus locking us out completely. if err := a.ChangeConfig(func(c agent.ConfigSetter) error { c.SetPassword(newPw) c.SetOldPassword(oldPw) return nil }); err != nil { return err } return entity.SetPassword(newPw) }