juju: github.com/juju/juju/apiserver/httpcontext Index | Files

package httpcontext

import "github.com/juju/juju/apiserver/httpcontext"

Index

Package Files

auth.go model.go

func RequestModelUUID Uses

func RequestModelUUID(req *http.Request) string

RequestModelUUID returns the model UUID associated with this request if there is one, or the empty string otherwise. No attempt is made to validate the model UUID; QueryModelHandler does this, and ImpliedModelHandler should always be supplied with a valid UUID.

type AuthInfo Uses

type AuthInfo struct {
    // Entity is the user/machine/unit/etc that has authenticated.
    Entity Entity

    // LastConnection returns the time of the last connection for
    // the authenticated entity. If it's the zero value, then the
    // entity has not previously logged in.
    LastConnection time.Time

    // Controller reports whether or not the authenticated
    // entity is a controller agent.
    Controller bool
}

AuthInfo is returned by Authenticator and RequestAuthInfo.

func RequestAuthInfo Uses

func RequestAuthInfo(req *http.Request) (AuthInfo, bool)

RequestAuthInfo returns the AuthInfo associated with the request, if any, and a boolean indicating whether or not the request was authenticated.

type Authenticator Uses

type Authenticator interface {
    // Authenticate authenticates the given request, returning the
    // auth info.
    //
    // If the request does not contain any authentication details,
    // then an error satisfying errors.IsNotFound will be returned.
    Authenticate(req *http.Request) (AuthInfo, error)

    // AuthenticateLoginRequest authenticates a LoginRequest.
    //
    // TODO(axw) we shouldn't be using params types here.
    AuthenticateLoginRequest(
        serverHost string,
        modelUUID string,
        req params.LoginRequest,
    ) (AuthInfo, error)
}

Authenticator provides an interface for authenticating a request.

TODO(axw) contract should include macaroon discharge error.

If this returns an error, the handler should return StatusUnauthorized.

type Authorizer Uses

type Authorizer interface {
    Authorize(AuthInfo) error
}

Authorizer is a function type for authorizing a request.

If this returns an error, the handler should return StatusForbidden.

type AuthorizerFunc Uses

type AuthorizerFunc func(AuthInfo) error

AuthorizerFunc is a function type implementing Authorizer.

func (AuthorizerFunc) Authorize Uses

func (f AuthorizerFunc) Authorize(info AuthInfo) error

Authorize is part of the Authorizer interface.

type BasicAuthHandler Uses

type BasicAuthHandler struct {
    http.Handler

    // Authenticator is the Authenticator used for authenticating
    // the HTTP requests handled by this handler.
    Authenticator Authenticator

    // Authorizer, if non-nil, will be called with the auth info
    // returned by the Authenticator, to validate it for the route.
    Authorizer Authorizer
}

BasicAuthHandler is an http.Handler that authenticates requests that it handles with a specified Authenticator. The auth details can later be retrieved using the top-level RequestAuthInfo function in this package.

func (*BasicAuthHandler) ServeHTTP Uses

func (h *BasicAuthHandler) ServeHTTP(w http.ResponseWriter, req *http.Request)

ServeHTTP is part of the http.Handler interface.

type Entity Uses

type Entity interface {
    Tag() names.Tag
}

Entity represents a user, machine, or unit that might be authenticated.

type ImpliedModelHandler Uses

type ImpliedModelHandler struct {
    http.Handler
    ModelUUID string
}

ImpliedModelHandler is an http.Handler that associates requests that it handles with a specified model UUID. The model UUID can then be extracted using the RequestModel function in this package.

func (*ImpliedModelHandler) ServeHTTP Uses

func (h *ImpliedModelHandler) ServeHTTP(w http.ResponseWriter, req *http.Request)

ServeHTTP is part of the http.Handler interface.

type LocalMacaroonAuthenticator Uses

type LocalMacaroonAuthenticator interface {
    Authenticator

    // CreateLocalLoginMacaroon creates a macaroon that may be
    // provided to a user as proof that they have logged in with
    // a valid username and password. This macaroon may then be
    // used to obtain a discharge macaroon so that the user can
    // log in without presenting their password for a set amount
    // of time.
    CreateLocalLoginMacaroon(names.UserTag) (*macaroon.Macaroon, error)
}

LocalMacaroonAuthenticator extends Authenticator with a method of creating a local login macaroon. The authenticator is expected to honour the resulting macaroon.

type QueryModelHandler Uses

type QueryModelHandler struct {
    http.Handler
    Query string
}

QueryModelHandler is an http.Handler that associates requests that it handles with a model UUID extracted from a specified query parameter. The model UUID can then be extracted using the RequestModel function in this package.

func (*QueryModelHandler) ServeHTTP Uses

func (h *QueryModelHandler) ServeHTTP(w http.ResponseWriter, req *http.Request)

ServeHTTP is part of the http.Handler interface.

Package httpcontext imports 11 packages (graph) and is imported by 18 packages. Updated 2019-09-09. Refresh now. Tools for package owners.