Documentation
¶
Index ¶
- func GetClientIdFromContext(r *http.Request) (clientID string, clientRole string, err error)
- func GetRequestParams(r *http.Request) (reqParam transports.RequestParams, err error)
- type HttpServerModule
- func (m *HttpServerModule) DefaultAuthenticate(req *http.Request) (clientID string, clientRole string, err error)
- func (m *HttpServerModule) GetClientIdFromContext(r *http.Request) (string, string, error)
- func (m *HttpServerModule) GetConnectURL() string
- func (m *HttpServerModule) GetProtectedRoute() chi.Router
- func (m *HttpServerModule) GetPublicRoute() chi.Router
- func (m *HttpServerModule) GetRequestParams(r *http.Request) (transports.RequestParams, error)
- func (m *HttpServerModule) SetAuthValidator(validator transports.ValidateTokenHandler)
- func (m *HttpServerModule) Start() (err error)
- func (m *HttpServerModule) Stop()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetClientIdFromContext ¶
GetClientIdFromContext returns the authenticated clientID and role for the given request
func GetRequestParams ¶
func GetRequestParams(r *http.Request) (reqParam transports.RequestParams, err error)
GetRequestParams reads the client session, URL parameters and body payload from the http request context.
The session context is set by the http middleware. This first checks for a clientID from the session context, which gets it from the bearer token auth. If no clientID is available but a client certificate is available then use its common name (cn) the clientID. If the clientID is not available then this returns an error.
This determines {thingID}, {name} and {op} from the path. It unmarshals the request body into 'data', if given.
{operation} is the operation
{thingID} is the agent or digital twin thing ID
{name} is the property, event or action name. '+' means 'all'
Types ¶
type HttpServerModule ¶
type HttpServerModule struct {
modules.HiveModuleBase
// contains filtered or unexported fields
}
HttpServerModule is a module providing a TLS HTTPS server. Intended for use by HTTP based application protocols. This implements IHttpServer and IHiveModule interfaces.
Note that this does not implement the ITransportModule interface as this module provides the http server for use by transport modules.
func NewHttpServerModule ¶
func NewHttpServerModule(moduleID string, config *httpserver.HttpServerConfig) *HttpServerModule
Create a new Https server module instance.
moduleID is the module's instance identification. config MUST have been configured with a CA and server certificate unless NoTLS is set.
func (*HttpServerModule) DefaultAuthenticate ¶
func (m *HttpServerModule) DefaultAuthenticate(req *http.Request) ( clientID string, clientRole string, err error)
The default authentication handler extracts the bearer token from the authorization header and passes it to the configured token validator.
func (*HttpServerModule) GetClientIdFromContext ¶
GetClientIdFromContext
func (*HttpServerModule) GetConnectURL ¶
func (m *HttpServerModule) GetConnectURL() string
Provide the HTTP base URL to connect to the server. Eg "https://addr:port/""
func (*HttpServerModule) GetProtectedRoute ¶
func (m *HttpServerModule) GetProtectedRoute() chi.Router
GetProtectedRouter returns the router with protected accessible routes for this server. This router has cors protection enabled. This returns nil if authentication is not configured and will probably cause a panic when used.
func (*HttpServerModule) GetPublicRoute ¶
func (m *HttpServerModule) GetPublicRoute() chi.Router
GetPublicRouter returns the router with public accessible routes for this server. This router has cors protection enabled.
func (*HttpServerModule) GetRequestParams ¶
func (m *HttpServerModule) GetRequestParams(r *http.Request) (transports.RequestParams, error)
GetRequestParams
func (*HttpServerModule) SetAuthValidator ¶
func (m *HttpServerModule) SetAuthValidator(validator transports.ValidateTokenHandler)
Set the handler that validates tokens. This will enable the protected routes.
func (*HttpServerModule) Start ¶
func (m *HttpServerModule) Start() (err error)
Start readies the module for use. This starts a http server instance and sets-up a public and protected route.
Starts a HTTPS TLS service
func (*HttpServerModule) Stop ¶
func (m *HttpServerModule) Stop()
Stop the TLS server and close all connections. this waits until for up to 3 seconds for connections are closed. After that continue.