github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/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.
    17  	Connect func(*http.Request) (*state.State, state.Entity, error)
    18  }
    19  
    20  // HandlerConstraints describes conditions under which a handler
    21  // may operate.
    22  type HandlerConstraints struct {
    23  	// AuthKind defines the kind of authenticated "user" that the
    24  	// handler supports. This correlates directly to entities, as
    25  	// identified by tag kinds (e.g. names.UserTagKind). The empty
    26  	// string indicates support for unauthenticated requests.
    27  	AuthKind string
    28  
    29  	// StrictValidation is the value that will be used for the handler's
    30  	// httpContext (see apiserver/httpcontext.go).
    31  	StrictValidation bool
    32  
    33  	// ControllerModelOnly is the value that will be used for the handler's
    34  	// httpContext (see apiserver/httpcontext.go).
    35  	ControllerModelOnly bool
    36  }
    37  
    38  // HandlerSpec defines an HTTP handler for a specific endpoint
    39  // on Juju's HTTP server. Such endpoints facilitate behavior that is
    40  // not supported through normal (websocket) RPC. That includes file
    41  // transfer.
    42  type HandlerSpec struct {
    43  	// Constraints are the handler's constraints.
    44  	Constraints HandlerConstraints
    45  
    46  	// NewHandler returns a new HTTP handler for the given args.
    47  	// The function is idempotent--if given the same args, it will
    48  	// produce an equivalent handler each time.
    49  	NewHandler func(NewHandlerArgs) http.Handler
    50  }