// checkEnvironUUID checks if the expected envionUUID matches the // current environUUID set on this Server. It returns nil for a match // and an error on mismatch. func (srv *Server) checkEnvironUUID(expected string) error { actual := srv.getEnvironUUID() if actual != expected { return common.UnknownEnvironmentError(expected) } return nil }
func (h *httpHandler) validateEnvironUUID(r *http.Request) error { // Note: this is only true until we have support for multiple // environments. For now, there is only one, so we make sure that is // the one being addressed. envUUID := h.getEnvironUUID(r) logger.Tracef("got a request for env %q", envUUID) if envUUID == "" { return nil } env, err := h.state.Environment() if err != nil { logger.Infof("error looking up environment: %v", err) return err } if env.UUID() != envUUID { logger.Infof("environment uuid mismatch: %v != %v", envUUID, env.UUID()) return common.UnknownEnvironmentError(envUUID) } return nil }
func (srv *Server) validateEnvironUUID(envUUID string) error { if envUUID == "" { // We allow the environUUID to be empty for 2 cases // 1) Compatibility with older clients // 2) On first connect. The environment UUID is currently // generated by 'jujud bootstrap-state', and we haven't // threaded that information all the way back to the 'juju // bootstrap' process to be able to cache the value until // after we've connected one time. return nil } if srv.environUUID == "" { env, err := srv.state.Environment() if err != nil { return err } srv.environUUID = env.UUID() } if envUUID != srv.environUUID { return common.UnknownEnvironmentError(envUUID) } return nil }
func (s *errorsSuite) TestUnknownEnvironment(c *gc.C) { err := common.UnknownEnvironmentError("dead-beef") c.Check(err, gc.ErrorMatches, `unknown environment: "dead-beef"`) }
}, { err: &state.HasAssignedUnitsError{"42", []string{"a"}}, code: params.CodeHasAssignedUnits, helperFunc: params.IsCodeHasAssignedUnits, }, { err: common.ErrTryAgain, code: params.CodeTryAgain, helperFunc: params.IsCodeTryAgain, }, { err: stderrors.New("an error"), code: "", }, { err: unhashableError{"foo"}, code: "", }, { err: common.UnknownEnvironmentError("dead-beef-123456"), code: params.CodeNotFound, helperFunc: params.IsCodeNotFound, }, { err: nil, code: "", }} type unhashableError []string func (err unhashableError) Error() string { return err[0] } func (s *errorsSuite) TestErrorTransform(c *gc.C) { for _, t := range errorTransformTests {