コード例 #1
0
ファイル: apiserver.go プロジェクト: jiasir/juju
// 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
ファイル: httphandler.go プロジェクト: rogpeppe/juju
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
ファイル: apiserver.go プロジェクト: rogpeppe/juju
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
ファイル: errors_test.go プロジェクト: rogpeppe/juju
func (s *errorsSuite) TestUnknownEnvironment(c *gc.C) {
	err := common.UnknownEnvironmentError("dead-beef")
	c.Check(err, gc.ErrorMatches, `unknown environment: "dead-beef"`)
}
コード例 #5
0
ファイル: errors_test.go プロジェクト: rogpeppe/juju
}, {
	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 {