Documentation ¶
Index ¶
- Constants
- func InitConfig()
- func InitLogger(opts *badger.Options) badger.Options
- func SetupAPI(hostname string, extPort, intPort int, server *Server)
- func SetupSSLAPI(hostname string, extPort, extSSLPort, intPort int, server *Server, ...)
- type Client
- type DB
- type ErrClientAlreadyExists
- type ErrClientNotExists
- type ErrCouldNotConnect
- type ErrCreatingUUID
- type ErrHookAlreadyExists
- type ErrHookNotExists
- type ErrInvalidClientName
- type ErrInvalidLocation
- type ErrSecretGenerationFailed
- type ErrSecretTooShort
- type ErrUnknownServerError
- type Error
- type Server
- func (s *Server) AddClient(name string) (string, error)
- func (s *Server) AddHook(clientname, identifier string) (*Webhook, error)
- func (s *Server) DeleteHook(clientname, identifier string) error
- func (s *Server) DeleteHookByUUID(uuid string) error
- func (s *Server) HandleHook(uuid string, req *http.Request) error
- func (s *Server) Load()
- func (s *Server) RegenerateClientSecret(clientname string) (string, error)
- func (s *Server) RemoveClient(name string) error
- func (s *Server) Run()
- func (s *Server) Stop()
- type Webhook
Constants ¶
const ApplicationName = "CaptainHook"
ApplicationName is the name of the application
const ApplicationVersionPath = "/version"
ApplicationVersionPath will return the version of the CaptainHook server
const ClientPath = VersionPath + "/clients"
ClientPath is the REST-path to manage clients
const ConnectPath = VersionPath + "/connect"
ConnectPath is the REST-path to where clients can connect to a websocket to receive webhooks
const ExternalHookPath = "/h"
ExternalHookPath is the path external applications will call to notify a webhook
const FullVersion = VersionMajor + "." + VersionMinor + "." + VersionPatch
FullVersion is the full semantic version
const HookByUUIDPath = VersionPath + "/hookByUUID"
HookByUUIDPath is the REST-path to manage Hooks given by a UUID
const HookPath = VersionPath + "/hooks"
HookPath is the REST-path to manage hooks
const VersionMajor = "0"
VersionMajor is the major version according to semver
const VersionMinor = "1"
VersionMinor is the minor version according to semver
const VersionPatch = "0"
VersionPatch is the patch according to semver
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 InitLogger ¶
InitLogger initializes the logger with some settings
func SetupAPI ¶
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 ¶
MarshalJSON marshals a client to the correct json representation
func (*Client) OpenWebsocket ¶
OpenWebsocket opens a socket for this client that listens to all hooks
func (*Client) UnmarshalJSON ¶
UnmarshalJSON unmarshals the JSON representation of a client
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB is 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 (*Server) DeleteHook ¶
DeleteHook removes the webhook identified by identifier from the given client
func (*Server) DeleteHookByUUID ¶
DeleteHookByUUID will remove the webhook identified by the uuid from the CaptainHook instance
func (*Server) HandleHook ¶
HandleHook will proxy the http request sent by the 3rd party to the client this webhook belongs to
func (*Server) RegenerateClientSecret ¶
RegenerateClientSecret will recreate a secret for the given client and invalidate the old one
func (*Server) RemoveClient ¶
RemoveClient will delete a client