server

package
v0.0.0-...-562cd84 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 22, 2020 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	JwtRefreshInt time.Duration
	JwtValidInt   time.Duration
)

Functions

func AddRoute

func AddRoute(name, method, pattern string, handler http.HandlerFunc)

AddRoute appends specified routes to the routes collection. Called by init functions of swagger generated router.go files.

func Authenticate

func Authenticate(w http.ResponseWriter, r *http.Request)

func BasicAuthenAndAuthor

func BasicAuthenAndAuthor(r *http.Request, rc *RequestContext) error

func ClientCertAuthenAndAuthor

func ClientCertAuthenAndAuthor(r *http.Request, rc *RequestContext) error

func GenerateJwtSecretKey

func GenerateJwtSecretKey()

func GetUserRoles

func GetUserRoles(usr *user.User) ([]string, error)

func JwtAuthenAndAuthor

func JwtAuthenAndAuthor(r *http.Request, rc *RequestContext) (jwtToken, error)

func NewRouter

func NewRouter(auth UserAuth) http.Handler

NewRouter creates a new http router instance for the REST server. Includes all routes registered via AddRoute API as well as few in-built routes.

func PAMAuthUser

func PAMAuthUser(u string, p string) error

func PopulateAuthStruct

func PopulateAuthStruct(username string, auth *AuthInfo) error

func Process

func Process(w http.ResponseWriter, r *http.Request)

Process function is the common landing place for all REST requests. Swagger code-gen should be configured to invoke this function from all generated stub functions.

func Refresh

func Refresh(w http.ResponseWriter, r *http.Request)

func RequestValidate

func RequestValidate(payload []byte, ctype *MediaType, rc *RequestContext) ([]byte, error)

RequestValidate performas payload validation of request body.

func UserPwAuth

func UserPwAuth(username string, passwd string) (bool, error)

Types

type AuthInfo

type AuthInfo struct {
	// Username
	User string

	// Roles
	Roles []string
}

AuthInfo holds data about the authenticated user

type Claims

type Claims struct {
	Username string   `json:"username"`
	Roles    []string `json:"roles"`
	jwt.StandardClaims
}

type Credentials

type Credentials struct {
	Password string `json:"password"`
	Username string `json:"username"`
}

type MediaType

type MediaType struct {
	Type   string
	Params map[string]string

	TypePrefix string
	TypeSuffix string
	TypeMiddle string
}

MediaType represents the parsed media type value. Includes a MIME type string and optional parameters.

func (*MediaType) Format

func (m *MediaType) Format() string

Format function returns the full media type string - including MIME type and parameters.

func (*MediaType) Matches

func (m *MediaType) Matches(other *MediaType) bool

Matches verifies if this Mediatype matches the another MediaType.

type MediaTypes

type MediaTypes []MediaType

MediaTypes is a collection of parsed media type values

func (*MediaTypes) Add

func (m *MediaTypes) Add(mimeType string) error

Add function parses and adds a media type to the MediaTypes object. Any parameters in the media type value are ignored.

func (*MediaTypes) Contains

func (m *MediaTypes) Contains(mimeType string) bool

Contains function checks if a given media type value is present in the ContentTypes. Ignores the media type parameters.

func (*MediaTypes) GetMatching

func (m *MediaTypes) GetMatching(mimeType string) MediaTypes

GetMatching returns registered full content type value matching a given hint.

func (MediaTypes) String

func (m MediaTypes) String() string

type NameMap

type NameMap map[string]string

NameMap is a simple mapping of names (string to string)

func (*NameMap) Get

func (m *NameMap) Get(name string) string

Get function returns the mapped name for a given name. Returns given name itself if no mapping exists.

type RequestContext

type RequestContext struct {

	// Unique reqiest id
	ID string

	// Name represents the operationId from OpenAPI spec
	Name string

	// "consumes" and "produces" data from OpenAPI spec
	Consumes MediaTypes
	Produces MediaTypes

	// Model holds pointer to the OpenAPI data model object for
	// the body. When set, the request handler can validate the
	// request payload by loading the body into this model object.
	Model interface{}

	// PMap is the mapping of URI parameter names to actual yang
	// leaf names. Yang xpaths can have duplicate parameter names,
	// which is not supported by swagger and mux libraries. We
	// work around it by assigning different parameter names in
	// swagger and map them back to yang names while converting
	// REST paths to TransLib paths.
	PMap NameMap

	// Auth contains the authorized user information
	Auth AuthInfo

	ClientAuth UserAuth
	// contains filtered or unexported fields
}

RequestContext holds metadata about REST request.

func GetContext

func GetContext(r *http.Request) (*RequestContext, *http.Request)

GetContext function returns the RequestContext object for a HTTP request. RequestContext is maintained as a context value of the request. Creates a new RequestContext object is not already available; in which case this function also creates a copy of the HTTP request object with new context.

func GetContextWithRouteInfo

func GetContextWithRouteInfo(r *http.Request) (*RequestContext, *http.Request)

GetContextWithRouteInfo returns the RequestContext object for a http request r. Uses GetContext() to resolve the context object. If the request was serviced by mux router, fills the route match info into the context.

type Router

type Router struct {
	// contains filtered or unexported fields
}

Router dispatches http request to corresponding handlers.

func (*Router) ServeHTTP

func (router *Router) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP resolves and invokes the handler for http request r. RESTCONF paths are served from the routeTree; rest from mux router.

type UserAuth

type UserAuth map[string]bool

func (UserAuth) Any

func (i UserAuth) Any() bool

func (UserAuth) Enabled

func (i UserAuth) Enabled(mode string) bool

func (UserAuth) Set

func (i UserAuth) Set(mode string) error

func (UserAuth) String

func (i UserAuth) String() string

func (UserAuth) Unset

func (i UserAuth) Unset(mode string) error

type UserCredential

type UserCredential struct {
	Username string
	Password string
}

func (UserCredential) PAMAuthenticate

func (u UserCredential) PAMAuthenticate() error

PAMAuthenticate performs PAM authentication for the user credentials provided

func (UserCredential) PAMConvHandler

func (u UserCredential) PAMConvHandler(s pam.Style, msg string) (string, error)

PAM conversation handler.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL