Documentation ¶
Index ¶
- Variables
- func AddRoute(name, method, pattern string, handler http.HandlerFunc)
- func Authenticate(w http.ResponseWriter, r *http.Request)
- func BasicAuthenAndAuthor(r *http.Request, rc *RequestContext) error
- func ClientCertAuthenAndAuthor(r *http.Request, rc *RequestContext) error
- func GenerateJwtSecretKey()
- func GetUserRoles(usr *user.User) ([]string, error)
- func JwtAuthenAndAuthor(r *http.Request, rc *RequestContext) (jwtToken, error)
- func NewRouter(auth UserAuth) http.Handler
- func PAMAuthUser(u string, p string) error
- func PopulateAuthStruct(username string, auth *AuthInfo) error
- func Process(w http.ResponseWriter, r *http.Request)
- func Refresh(w http.ResponseWriter, r *http.Request)
- func RequestValidate(payload []byte, ctype *MediaType, rc *RequestContext) ([]byte, error)
- func UserPwAuth(username string, passwd string) (bool, error)
- type AuthInfo
- type Claims
- type Credentials
- type MediaType
- type MediaTypes
- type NameMap
- type RequestContext
- type Router
- type UserAuth
- type UserCredential
Constants ¶
This section is empty.
Variables ¶
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 JwtAuthenAndAuthor ¶
func JwtAuthenAndAuthor(r *http.Request, rc *RequestContext) (jwtToken, error)
func NewRouter ¶
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 PopulateAuthStruct ¶
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 RequestValidate ¶
func RequestValidate(payload []byte, ctype *MediaType, rc *RequestContext) ([]byte, error)
RequestValidate performas payload validation of request body.
Types ¶
type Claims ¶
type Claims struct { Username string `json:"username"` Roles []string `json:"roles"` jwt.StandardClaims }
type Credentials ¶
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.
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 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.
type UserCredential ¶
func (UserCredential) PAMAuthenticate ¶
func (u UserCredential) PAMAuthenticate() error
PAMAuthenticate performs PAM authentication for the user credentials provided
func (UserCredential) PAMConvHandler ¶
PAM conversation handler.