handlers

package
v0.0.0-...-e61e643 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2019 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package handlers contains the HTTP handlers for Go-NEB.

This includes detail on the API paths and top-level JSON keys. For specific service JSON, see the service you're interested in.

See also

Package "api" for the format of the JSON request bodies.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConfigureAuthRealm

type ConfigureAuthRealm struct {
	Db *database.ServiceDB
}

ConfigureAuthRealm represents an HTTP handler capable of processing /admin/configureAuthRealm requests.

func (*ConfigureAuthRealm) OnIncomingRequest

func (h *ConfigureAuthRealm) OnIncomingRequest(req *http.Request) util.JSONResponse

OnIncomingRequest handles POST requests to /admin/configureAuthRealm. The JSON object provided is of type "api.ConfigureAuthRealmRequest".

Request:

POST /admin/configureAuthRealm
{
    "ID": "my-realm-id",
    "Type": "github",
    "Config": {
        // Realm-specific configuration information
    }
}

Response:

HTTP/1.1 200 OK
{
    "ID": "my-realm-id",
    "Type": "github",
    "OldConfig": {
        // Old auth realm config information
    },
    "NewConfig": {
        // New auth realm config information
    },
}

type ConfigureClient

type ConfigureClient struct {
	Clients *clients.Clients
}

ConfigureClient represents an HTTP handler capable of processing /admin/configureClient requests.

func (*ConfigureClient) OnIncomingRequest

func (s *ConfigureClient) OnIncomingRequest(req *http.Request) util.JSONResponse

OnIncomingRequest handles POST requests to /admin/configureClient. The JSON object provided is of type "api.ClientConfig".

If a DisplayName is supplied, this request will set this client's display name if the old ClientConfig DisplayName differs from the new ClientConfig DisplayName.

Request:

POST /admin/configureClient
{
    "UserID": "@my_bot:localhost",
    "HomeserverURL": "http://localhost:8008",
    "Sync": true,
    "DisplayName": "My Bot"
}

Response:

HTTP/1.1 200 OK
{
     "OldClient": {
       // The old api.ClientConfig
     },
     "NewClient": {
       // The new api.ClientConfig
     }
}

type ConfigureService

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

ConfigureService represents an HTTP handler which can process /admin/configureService requests.

func NewConfigureService

func NewConfigureService(db *database.ServiceDB, clients *clients.Clients) *ConfigureService

NewConfigureService creates a new ConfigureService handler

func (*ConfigureService) OnIncomingRequest

func (s *ConfigureService) OnIncomingRequest(req *http.Request) util.JSONResponse

OnIncomingRequest handles POST requests to /admin/configureService.

The request body MUST be of type "api.ConfigureServiceRequest".

Request:

POST /admin/configureService
{
    "ID": "my_service_id",
    "Type": "service-type",
    "UserID": "@my_bot:localhost",
    "Config": {
        // service-specific config information
    }
}

Response:

HTTP/1.1 200 OK
{
    "ID": "my_service_id",
    "Type": "service-type",
    "OldConfig": {
        // old service-specific config information
    },
    "NewConfig": {
        // new service-specific config information
    },
}

type GetService

type GetService struct {
	Db *database.ServiceDB
}

GetService represents an HTTP handler which can process /admin/getService requests.

func (*GetService) OnIncomingRequest

func (h *GetService) OnIncomingRequest(req *http.Request) util.JSONResponse

OnIncomingRequest handles POST requests to /admin/getService.

The request body MUST be a JSON body which has an "ID" key which represents the service ID to get.

Request:

POST /admin/getService
{
    "ID": "my_service_id"
}

Response:

HTTP/1.1 200 OK
{
    "ID": "my_service_id",
    "Type": "github",
    "Config": {
        // service-specific config information
    }
}

type GetSession

type GetSession struct {
	Db *database.ServiceDB
}

GetSession represents an HTTP handler capable of processing /admin/getSession requests.

func (*GetSession) OnIncomingRequest

func (h *GetSession) OnIncomingRequest(req *http.Request) util.JSONResponse

OnIncomingRequest handles POST requests to /admin/getSession.

The JSON object provided MUST have a "RealmID" and "UserID" in order to fetch the correct AuthSession. If there is no session for this tuple of realm and user ID, a 200 OK is still returned with "Authenticated" set to false.

Request:

POST /admin/getSession
{
    "RealmID": "my-realm",
    "UserID": "@my_user:localhost"
}

Response:

HTTP/1.1 200 OK
{
    "ID": "session_id",
    "Authenticated": true,
    "Info": {
        // Session-specific config info
    }
}

Response if session not found:

HTTP/1.1 200 OK
{
    "Authenticated": false
}

type Heartbeat

type Heartbeat struct{}

Heartbeat implements the heartbeat API

func (*Heartbeat) OnIncomingRequest

func (*Heartbeat) OnIncomingRequest(req *http.Request) util.JSONResponse

OnIncomingRequest returns an empty JSON object which can be used to detect liveness of Go-NEB.

Request:

GET /test

Response:

HTTP/1.1 200 OK
{}

type RealmRedirect

type RealmRedirect struct {
	Db *database.ServiceDB
}

RealmRedirect represents an HTTP handler which can process incoming redirects for auth realms.

func (*RealmRedirect) Handle

func (rh *RealmRedirect) Handle(w http.ResponseWriter, req *http.Request)

Handle requests for an auth realm.

The last path segment of the URL MUST be the base64 form of the Realm ID. What response this returns depends on the specific AuthRealm implementation.

type RemoveAuthSession

type RemoveAuthSession struct {
	Db *database.ServiceDB
}

RemoveAuthSession represents an HTTP handler capable of processing /admin/removeAuthSession requests.

func (*RemoveAuthSession) OnIncomingRequest

func (h *RemoveAuthSession) OnIncomingRequest(req *http.Request) util.JSONResponse

OnIncomingRequest handles POST requests to /admin/removeAuthSession.

The JSON object MUST contain the keys "RealmID" and "UserID" to identify the session to remove.

Request

POST /admin/removeAuthSession
{
    "RealmID": "github-realm",
    "UserID": "@my_user:localhost"
}

Response:

HTTP/1.1 200 OK
{}

type RequestAuthSession

type RequestAuthSession struct {
	Db *database.ServiceDB
}

RequestAuthSession represents an HTTP handler capable of processing /admin/requestAuthSession requests.

func (*RequestAuthSession) OnIncomingRequest

func (h *RequestAuthSession) OnIncomingRequest(req *http.Request) util.JSONResponse

OnIncomingRequest handles POST requests to /admin/requestAuthSession. The HTTP body MUST be a JSON object representing type "api.RequestAuthSessionRequest".

This will return HTTP 400 if there are missing fields or the Realm ID is unknown. For the format of the response, see the specific AuthRealm that the Realm ID corresponds to.

Request:

POST /admin/requestAuthSession
{
    "RealmID": "github_realm_id",
    "UserID": "@my_user:localhost",
    "Config": {
        // AuthRealm specific config info
    }
}

Response:

HTTP/1.1 200 OK
{
    // AuthRealm-specific information
}

type Webhook

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

Webhook represents an HTTP handler capable of accepting webhook requests on behalf of services.

func NewWebhook

func NewWebhook(db *database.ServiceDB, cli *clients.Clients) *Webhook

NewWebhook returns a new webhook HTTP handler

func (*Webhook) Handle

func (wh *Webhook) Handle(w http.ResponseWriter, req *http.Request)

Handle an incoming webhook HTTP request.

The webhook MUST have a known base64 encoded service ID as the last path segment in order for this request to be passed to the correct service, or else this will return HTTP 400. If the base64 encoded service ID is unknown, this will return HTTP 404. Beyond this, the exact response is determined by the specific Service implementation.

Jump to

Keyboard shortcuts

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