github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/apiserver/common/apihttp/handler.go (about) 1 // Copyright 2016 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package apihttp 5 6 import ( 7 "net/http" 8 9 "github.com/juju/juju/state" 10 ) 11 12 // NewHandlerArgs holds the args to the func in the NewHandler 13 // field of HandlerSpec. 14 type NewHandlerArgs struct { 15 // Connect is the function that is used to connect to Juju's state 16 // for the given HTTP request. It is the caller's responsibility 17 // to call the release function returned. If the error arg is nil 18 // the release function will always be a valid function. 19 Connect func(*http.Request) (*state.State, func(), state.Entity, error) 20 } 21 22 // HandlerConstraints describes conditions under which a handler 23 // may operate. 24 type HandlerConstraints struct { 25 // AuthKinds defines the kinds of authenticated "user" that the 26 // handler supports. This correlates directly to entities, as 27 // identified by tag kinds (e.g. names.UserTagKind). An empty list 28 // will block all authentication. 29 AuthKinds []string 30 31 // StrictValidation is the value that will be used for the handler's 32 // httpContext (see apiserver/httpcontext.go). 33 StrictValidation bool 34 35 // ControllerModelOnly is the value that will be used for the handler's 36 // httpContext (see apiserver/httpcontext.go). 37 ControllerModelOnly bool 38 } 39 40 // HandlerSpec defines an HTTP handler for a specific endpoint 41 // on Juju's HTTP server. Such endpoints facilitate behavior that is 42 // not supported through normal (websocket) RPC. That includes file 43 // transfer. 44 type HandlerSpec struct { 45 // Constraints are the handler's constraints. 46 Constraints HandlerConstraints 47 48 // NewHandler returns a new HTTP handler for the given args. 49 // The function is idempotent--if given the same args, it will 50 // produce an equivalent handler each time. 51 NewHandler func(NewHandlerArgs) http.Handler 52 }