Пример #1
0
// 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
}
Пример #2
0
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
}
Пример #3
0
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
}
Пример #4
0
func (s *errorsSuite) TestUnknownEnvironment(c *gc.C) {
	err := common.UnknownEnvironmentError("dead-beef")
	c.Check(err, gc.ErrorMatches, `unknown environment: "dead-beef"`)
}
Пример #5
0
}, {
	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 {