server

package
v0.0.0-...-ec710cb Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2021 License: MIT Imports: 21 Imported by: 1

Documentation

Index

Constants

View Source
const ApplicationName = "CaptainHook"

ApplicationName is the name of the application

View Source
const ApplicationVersionPath = "/version"

ApplicationVersionPath will return the version of the CaptainHook server

View Source
const ClientPath = VersionPath + "/clients"

ClientPath is the REST-path to manage clients

View Source
const ConnectPath = VersionPath + "/connect"

ConnectPath is the REST-path to where clients can connect to a websocket to receive webhooks

View Source
const ExternalHookPath = "/h"

ExternalHookPath is the path external applications will call to notify a webhook

View Source
const FullVersion = VersionMajor + "." + VersionMinor + "." + VersionPatch

FullVersion is the full semantic version

View Source
const HookByUUIDPath = VersionPath + "/hookByUUID"

HookByUUIDPath is the REST-path to manage Hooks given by a UUID

View Source
const HookPath = VersionPath + "/hooks"

HookPath is the REST-path to manage hooks

View Source
const VersionMajor = "0"

VersionMajor is the major version according to semver

View Source
const VersionMinor = "1"

VersionMinor is the minor version according to semver

View Source
const VersionPatch = "0"

VersionPatch is the patch according to semver

View Source
const VersionPath = "/v1"

VersionPath is the base path for most API calls. This has to be changed if there are major changes in the API that break compatibility

Variables

This section is empty.

Functions

func InitConfig

func InitConfig()

InitConfig initializes the config with default values

func InitLogger

func InitLogger(opts *badger.Options) badger.Options

InitLogger initializes the logger with some settings

func SetupAPI

func SetupAPI(hostname string, extPort, intPort int, server *Server)

SetupAPI will set up the HTTP-REST-API server without SSL. extPort is the Port the public interfaces will listen to, intPort will be used for private connection, e.g. the CLI

func SetupSSLAPI

func SetupSSLAPI(hostname string, extPort, extSSLPort, intPort int, server *Server, sslCertFile, sslKeyFile string)

SetupSSLAPI will set up the HTTP-REST-API server with SSL. extPort will redirect everything to HTTPS, extSSLPort is the Port the public interfaces will listen to, intPort will be used for private connection, e.g. the CLI

Types

type Client

type Client struct {
	Name       string              `json:"name"`
	Secret     []byte              `json:"-"`
	CreatedAt  time.Time           `json:"createdAt"`
	LastAction time.Time           `json:"lastAction"`
	Hooks      map[string]*Webhook `json:"hooks"`
	// contains filtered or unexported fields
}

Client contains the information and hooks of a registered client

func (*Client) Destroy

func (c *Client) Destroy()

Destroy this client and all related webhooks and connections

func (*Client) MarshalJSON

func (c *Client) MarshalJSON() ([]byte, error)

MarshalJSON marshals a client to the correct json representation

func (*Client) OpenWebsocket

func (c *Client) OpenWebsocket(con *gin.Context)

OpenWebsocket opens a socket for this client that listens to all hooks

func (*Client) UnmarshalJSON

func (c *Client) UnmarshalJSON(in []byte) error

UnmarshalJSON unmarshals the JSON representation of a client

type DB

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

DB is the database

func Open

func Open(path string) *DB

Open opens the database

func (*DB) Delete

func (db *DB) Delete(clientName string) error

Delete deletes a client from the database

func (*DB) Load

func (db *DB) Load() (map[string]*Client, error)

Load loads all clients in the database

func (*DB) Store

func (db *DB) Store(client *Client) error

Store stores a client in the database

type ErrClientAlreadyExists

type ErrClientAlreadyExists struct {
	Name string
}

ErrClientAlreadyExists occurs if someone tries to add a client with an existing name

func (*ErrClientAlreadyExists) Error

func (e *ErrClientAlreadyExists) Error() string

type ErrClientNotExists

type ErrClientNotExists struct {
	Name string
}

ErrClientNotExists occurs if someone tries to edit a client that does not exist

func (*ErrClientNotExists) Error

func (e *ErrClientNotExists) Error() string

type ErrCouldNotConnect

type ErrCouldNotConnect struct {
	Message string
}

ErrCouldNotConnect occurs if the client could not connect to the server

func (*ErrCouldNotConnect) Error

func (e *ErrCouldNotConnect) Error() string

type ErrCreatingUUID

type ErrCreatingUUID struct {
	Message string
}

ErrCreatingUUID occurs if something went wrong while generating the uuid

func (*ErrCreatingUUID) Error

func (e *ErrCreatingUUID) Error() string

type ErrHookAlreadyExists

type ErrHookAlreadyExists struct {
	Identifier string
}

ErrHookAlreadyExists occurs if someone tries to add a hook with an existing identifier

func (*ErrHookAlreadyExists) Error

func (e *ErrHookAlreadyExists) Error() string

type ErrHookNotExists

type ErrHookNotExists struct {
	Identifier string
}

ErrHookNotExists occurs if someone tries to edit a hook that does not exist

func (*ErrHookNotExists) Error

func (e *ErrHookNotExists) Error() string

type ErrInvalidClientName

type ErrInvalidClientName struct {
	Name string
}

ErrInvalidClientName occurs if someone tries to add a client with an invalid name

func (*ErrInvalidClientName) Error

func (e *ErrInvalidClientName) Error() string

type ErrInvalidLocation

type ErrInvalidLocation struct {
	Message string
}

ErrInvalidLocation occurs if the redirect for a client is invalid

func (*ErrInvalidLocation) Error

func (e *ErrInvalidLocation) Error() string

type ErrSecretGenerationFailed

type ErrSecretGenerationFailed struct {
	Message string
}

ErrSecretGenerationFailed occurs if something went wrong while generating the client secret

func (*ErrSecretGenerationFailed) Error

func (e *ErrSecretGenerationFailed) Error() string

type ErrSecretTooShort

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

ErrSecretTooShort occurs if a client sent a secret that is too short

func (*ErrSecretTooShort) Error

func (e *ErrSecretTooShort) Error() string

type ErrUnknownServerError

type ErrUnknownServerError struct {
	Message string
}

ErrUnknownServerError occurs on clients if any unknown error occurs

func (*ErrUnknownServerError) Error

func (e *ErrUnknownServerError) Error() string

type Error

type Error struct {
	Message string `json:"message"`
}

Error is a simple error message struct used to represent an error in the api

type Server

type Server struct {
	Clients map[string]*Client
	Hooks   map[string]*Webhook
	DB      *DB
	// contains filtered or unexported fields
}

Server contains all the information about clients and webhooks

func NewServer

func NewServer(host, port string) *Server

NewServer creates a new CaptainHook Server

func (*Server) AddClient

func (s *Server) AddClient(name string) (string, error)

AddClient adds a new client to the server

func (*Server) AddHook

func (s *Server) AddHook(clientname, identifier string) (*Webhook, error)

AddHook will add a hook identified by identifier to the given client

func (*Server) DeleteHook

func (s *Server) DeleteHook(clientname, identifier string) error

DeleteHook removes the webhook identified by identifier from the given client

func (*Server) DeleteHookByUUID

func (s *Server) DeleteHookByUUID(uuid string) error

DeleteHookByUUID will remove the webhook identified by the uuid from the CaptainHook instance

func (*Server) HandleHook

func (s *Server) HandleHook(uuid string, req *http.Request) error

HandleHook will proxy the http request sent by the 3rd party to the client this webhook belongs to

func (*Server) Load

func (s *Server) Load()

Load loads the initial database content

func (*Server) RegenerateClientSecret

func (s *Server) RegenerateClientSecret(clientname string) (string, error)

RegenerateClientSecret will recreate a secret for the given client and invalidate the old one

func (*Server) RemoveClient

func (s *Server) RemoveClient(name string) error

RemoveClient will delete a client

func (*Server) Run

func (s *Server) Run()

Run blocks endlessly

func (*Server) Stop

func (s *Server) Stop()

Stop stops the server

type Webhook

type Webhook struct {
	URL        string    `json:"url"`
	Identifier string    `json:"identifier"`
	UUID       string    `json:"uuid"`
	CreatedAt  time.Time `json:"createdAt"`
	LastCall   time.Time `json:"lastCall"`
	// contains filtered or unexported fields
}

Webhook contains the information about a webhook

func (*Webhook) Handle

func (w *Webhook) Handle(req *http.Request) error

Handle relays the request to all connected clients

Jump to

Keyboard shortcuts

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