Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(21)

Unified Diff: state/apiserver/httphandler.go

Issue 102920048: state/*: login to /ENVUUID/api URLs
Patch Set: state/*: login to /ENVUUID/api URLs Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: state/apiserver/httphandler.go
=== modified file 'state/apiserver/httphandler.go'
--- state/apiserver/httphandler.go 2014-04-07 04:50:31 +0000
+++ state/apiserver/httphandler.go 2014-05-30 07:45:48 +0000
@@ -56,6 +56,31 @@
return err
}
+func (h *httpHandler) getEnvironUUID(r *http.Request) string {
+ return r.URL.Query().Get(":envuuid")
+}
+
+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 != "" {
rog 2014/06/02 10:08:18 if envUUID == "" { return nil } to save inden
jameinel 2014/06/05 13:47:19 Done.
+ 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.ErrInvalidEnviron
+ }
+ }
+ return nil
+}
+
// authError sends an unauthorized error.
func (h *httpHandler) authError(w http.ResponseWriter, sender errorSender) {
w.Header().Set("WWW-Authenticate", `Basic realm="juju"`)

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b