Documentation ¶
Index ¶
- Constants
- func GetAllSessionTokens(db *dbhelper.DBhelper) ([]string, error)
- func GetDefaultConfig() string
- func InsertUser(db *dbhelper.DBhelper, username, password, ip string) error
- func LogError(err error, context ...map[string]interface{}) bool
- func LoginQuery(db *dbhelper.DBhelper, username, password, ip string) (string, bool, error)
- func NotifyAllSubscriber(db *dbhelper.DBhelper, config *ConfigStruct, webhook *Webhook, source *Source, ...)
- func RemoveSubscriptionByPK(db *dbhelper.DBhelper, pk uint32) error
- func SubscriptionExists(db *dbhelper.DBhelper, sourceID uint32, callbackURL string) (bool, error)
- func UserExists(db *dbhelper.DBhelper, username string) (bool, error)
- type ConfigStruct
- type CredentialRequest
- type ListSourcesResponse
- type LoginResponse
- type LoginSession
- type NotifyCallback
- type ResponseStatus
- type Retry
- type Role
- type Source
- type SourceAddRequest
- type SourceAddResponse
- type SourceRequest
- type SubscriberNotifyCallback
- type Subscription
- func (subscription *Subscription) Insert(db *dbhelper.DBhelper) error
- func (subscription *Subscription) Notify(db *dbhelper.DBhelper, webhook *Webhook, source *Source, ...) (*http.Response, error)
- func (subscription Subscription) Remove(db *dbhelper.DBhelper) error
- func (subscription *Subscription) Trigger(db *dbhelper.DBhelper)
- func (subscription *Subscription) TriggerAndValidate(db *dbhelper.DBhelper) error
- func (subscription *Subscription) UpdateCallback(db *dbhelper.DBhelper, newCallback string) error
- type SubscriptionRequest
- type SubscriptionResponse
- type SubscriptionUpdateCallbackRequest
- type UnsubscribeRequest
- type User
- func (user *User) AddHookCall(db *dbhelper.DBhelper, addTraffic uint32) error
- func (user User) CanCreateSource(private bool) bool
- func (user User) CanShareWebhooks() bool
- func (user User) CanSubscribe() bool
- func (user *User) GetSourceCount(db *dbhelper.DBhelper, private bool) (uint, error)
- func (user *User) GetSubscriptionCount(db *dbhelper.DBhelper) (uint32, error)
- func (user *User) HasSourceWithName(db *dbhelper.DBhelper, name string) (bool, error)
- func (user User) HasUnlimitedHookCalls() bool
- func (user User) IsAdmin() bool
- func (user User) IsSourceLimitReached(db *dbhelper.DBhelper, private bool) (bool, error)
- func (user *User) IsSubscribedTo(db *dbhelper.DBhelper, sourceID uint32) (bool, error)
- func (user User) IsSubscriptionLimitReached(db *dbhelper.DBhelper) (bool, error)
- func (user *User) UpdateIP(db *dbhelper.DBhelper, ip string) error
- type Webhook
Constants ¶
const ( //NotFoundError error from server NotFoundError string = "Not found" //ActionNotAllowed error from server ActionNotAllowed string = "Action not allowed" //WrongLength error from server WrongLength string = "Wrong length" //ServerError error from server ServerError string = "Server Error" //WrongInputFormatError wrong user input WrongInputFormatError string = "Wrong inputFormat!" //InvalidTokenError token is not valid InvalidTokenError string = "Token not valid" //InvalidCallbackURL token is not valid InvalidCallbackURL string = "Callback url is invalid" //BatchSizeTooLarge batch is too large BatchSizeTooLarge string = "BatchSize soo large!" //WrongIntegerFormat integer is probably no integer WrongIntegerFormat string = "Number is string" //MultipleSourceNameErr err name already exists MultipleSourceNameErr string = "You can't have multiple sources with the same name" //UserIsInvalidErr err if user is invalid UserIsInvalidErr string = "user is invalid" )
const ( //HeaderStatus headerName for status in response HeaderStatus string = "rstatus" //HeaderStatusMessage headerName for status in response HeaderStatusMessage string = "rmess" )
const ( TableSubscriptions = "Subscriptions" TableModes = "Modes" )
TableSubscriptions the tableName for subscriptions
const TableLoginSession = "LoginSessions"
TableLoginSession the table in db for login sessions
const TableRetries = "Retries"
TableRetries table containing retries
const TableRoles = "Roles"
TableRoles the db tableName for the roles
const TableSources = "Sources"
TableSources the db tableName for sources
const TableUser = "User"
TableUser the table in db for user
const TableWebhooks = "Webhooks"
TableWebhooks table for the webhooks
Variables ¶
This section is empty.
Functions ¶
func GetAllSessionTokens ¶
GetAllSessionTokens returns all valid sessions
func GetDefaultConfig ¶
func GetDefaultConfig() string
GetDefaultConfig gets the default config path
func InsertUser ¶
InsertUser inserts user into db
func LoginQuery ¶
LoginQuery loginQuery
func NotifyAllSubscriber ¶
func NotifyAllSubscriber(db *dbhelper.DBhelper, config *ConfigStruct, webhook *Webhook, source *Source, callback NotifyCallback)
NotifyAllSubscriber for a given webhook
func RemoveSubscriptionByPK ¶
RemoveSubscriptionByPK removes a subscription by pk
func SubscriptionExists ¶
SubscriptionExists check if a subscription exists
Types ¶
type ConfigStruct ¶
type ConfigStruct struct { Server configServer Webserver struct { MaxHeaderLength uint `default:"8000" required:"true"` MaxBodyLength int64 `default:"10000" required:"true"` MaxPayloadBodyLength int64 `default:"10000" required:"true"` HTTP configHTTPstruct HTTPS configTLSStruct } }
ConfigStruct config for the server
func InitConfig ¶
func InitConfig(confFile string, createMode bool) (*ConfigStruct, bool)
InitConfig inits the config Returns true if system should exit
func (*ConfigStruct) Check ¶
func (config *ConfigStruct) Check() bool
Check check the config file of logical errors
func (*ConfigStruct) LoadInfo ¶
func (config *ConfigStruct) LoadInfo()
LoadInfo prints debugging config information
type CredentialRequest ¶
CredentialRequest request containing credentials
type ListSourcesResponse ¶
type ListSourcesResponse struct {
Sources []Source `json:"sources,omitempty"`
}
ListSourcesResponse response containing a list of sources
type LoginResponse ¶
type LoginResponse struct {
Token string `json:"token"`
}
LoginResponse response for login
type LoginSession ¶
type LoginSession struct { PkID uint32 `db:"pk_id" orm:"pk,ai"` UserID uint32 `db:"userID"` Token string `db:"sessionToken"` Created time.Time `db:"created"` IsValid bool `db:"isValid"` LastAccessed time.Time `db:"lastAccessed"` User User `db:"-" orm:"-"` }
LoginSession a login session
func (*LoginSession) Insert ¶
func (session *LoginSession) Insert(db *dbhelper.DBhelper) error
Insert insert a loginSession into the database
func (LoginSession) UpdateLastAccessedByToken ¶
func (session LoginSession) UpdateLastAccessedByToken(db *dbhelper.DBhelper)
UpdateLastAccessedByToken updates loginsessions last accessed
type NotifyCallback ¶
type NotifyCallback interface { OnSuccess(Subscription) OnError(Subscription, Source, Webhook) OnUnsubscribe(Subscription) }
NotifyCallback callback for Notify
type ResponseStatus ¶
type ResponseStatus uint8
ResponseStatus the status of response
const ( //ResponseError if there was an error ResponseError ResponseStatus = 0 //ResponseSuccess if the response is successful ResponseSuccess ResponseStatus = 1 )
type Retry ¶
type Retry struct { PKid uint32 `db:"pk_id" orm:"pk,ai"` TryNr uint8 `db:"tryNr"` NextRetry time.Time `db:"nextRetry"` SourcePK uint32 `db:"sourcePK"` WebhookPK uint32 `db:"webhookPK"` }
Retry retries after some time
func NewRetry ¶
func NewRetry(db *dbhelper.DBhelper, sourcePK, webhookPk uint32, nextRetryTime time.Time) (*Retry, error)
NewRetry create now Retry
type Role ¶
type Role struct { PkID uint32 `db:"pk_id" orm:"pk,ai"` Name string `db:"name"` MaxPrivSources int `db:"maxPrivSources"` MaxPubSources int `db:"maxPubSources"` MaxSubscriptions int `db:"maxSubscriptions"` MaxHookCalls int `db:"maxHookCalls"` MaxTraffic int `db:"maxTraffic"` IsAdmin bool `db:"isAdmin"` }
Role the role of a user
type Source ¶
type Source struct { PkID uint32 `db:"pk_id" orm:"pk,ai" json:"-"` Name string `db:"name" json:"name"` SourceID string `db:"sourceID" json:"sourceID"` Description string `db:"description" json:"description"` Secret string `db:"secret" json:"secret"` CreatorID uint32 `db:"creator" json:"-"` CreationTime time.Time `db:"creationTime" json:"crTime"` IsPrivate bool `db:"private" json:"isPrivate"` Mode uint8 `db:"mode" json:"mode"` Creator User `db:"-" orm:"-" json:"-"` }
Source a webhook source
func GetSourceByPK ¶
GetSourceByPK get source by pk_id
func GetSourceFromSourceID ¶
GetSourceFromSourceID get source from sourceID
func GetSourcesForUser ¶
GetSourcesForUser get all sources created by the given user
type SourceAddRequest ¶
type SourceAddRequest struct { Name string `json:"name"` Description string `json:"descr"` Private bool `json:"private"` Mode uint8 `json:"mode"` }
SourceAddRequest request to create a source
type SourceAddResponse ¶
SourceAddResponse response for adding sources
type SourceRequest ¶
type SourceRequest struct { SourceID string `json:"sid,omitempty"` Content string `json:"content,omitempty"` }
SourceRequest request containing sourceData
type SubscriberNotifyCallback ¶
SubscriberNotifyCallback callback for user notifications
type Subscription ¶
type Subscription struct { PkID uint32 `db:"pk_id" orm:"pk,ai,nn"` SubscriptionID string `db:"subscriptionID"` UserID uint32 `db:"subscriber"` Source uint32 `db:"source"` CallbackURL string `db:"callbackURL"` Time time.Time `db:"time"` IsValid bool `db:"isValid"` LastTrigger string `db:"lastTrigger"` }
Subscription the subscription a user made
func GetSubscriptionByPK ¶
func GetSubscriptionByPK(db *dbhelper.DBhelper, pkID uint32) (*Subscription, error)
GetSubscriptionByPK get subscription by pk
func GetSubscriptionBySubsID ¶
func GetSubscriptionBySubsID(db *dbhelper.DBhelper, subscriptionID string) (*Subscription, error)
GetSubscriptionBySubsID get the subscription by subscriptionID
func (*Subscription) Insert ¶
func (subscription *Subscription) Insert(db *dbhelper.DBhelper) error
Insert inserts the subscription into the db
func (*Subscription) Notify ¶
func (subscription *Subscription) Notify(db *dbhelper.DBhelper, webhook *Webhook, source *Source, callback NotifyCallback) (*http.Response, error)
Notify subscriber
func (Subscription) Remove ¶
func (subscription Subscription) Remove(db *dbhelper.DBhelper) error
Remove removes/unsubscribes to a subscription
func (*Subscription) Trigger ¶
func (subscription *Subscription) Trigger(db *dbhelper.DBhelper)
Trigger the subscription
func (*Subscription) TriggerAndValidate ¶
func (subscription *Subscription) TriggerAndValidate(db *dbhelper.DBhelper) error
TriggerAndValidate triggers the subscription and set validate=1
func (*Subscription) UpdateCallback ¶
func (subscription *Subscription) UpdateCallback(db *dbhelper.DBhelper, newCallback string) error
UpdateCallback updates the callback for a subscription
type SubscriptionRequest ¶
SubscriptionRequest request to subscribe
type SubscriptionResponse ¶
type SubscriptionResponse struct { Message string `json:"message,omitempty"` SubscriptionID string `json:"sid"` Name string `json:"name"` Mode uint8 `json:"mode"` }
SubscriptionResponse response for subscription
type SubscriptionUpdateCallbackRequest ¶
type SubscriptionUpdateCallbackRequest struct { SubscriptionID string `json:"subID"` CallbackURL string `json:"cbUrl"` }
SubscriptionUpdateCallbackRequest request for updating callback
type UnsubscribeRequest ¶
type UnsubscribeRequest struct {
SubscriptionID string `json:"sid"`
}
UnsubscribeRequest request for unsubscribing a source
type User ¶
type User struct { Pkid uint32 `db:"pk_id" orm:"pk,ai"` Username string `db:"username"` Password string `db:"password"` Traffic uint32 `db:"traffic"` HookCalls uint32 `db:"hookCalls"` ResetIndex uint16 `db:"resetIndex"` CreatedAt time.Time `db:"createdAt"` IP string `db:"ip"` IsValid bool `db:"isValid"` RoleID uint32 `db:"role"` Role Role `db:"role"` }
User user in db
func GetUserByPK ¶
GetUserByPK get user by pk_id
func GetUserBySession ¶
GetUserBySession get user by sessionToken
func (*User) AddHookCall ¶
AddHookCall adds hookCall (increase hookCall count and traffic)
func (User) CanCreateSource ¶
CanCreateSource returns true if a role allows having private/public a source
func (User) CanShareWebhooks ¶
CanShareWebhooks return true if role is allowed to send webhooks
func (User) CanSubscribe ¶
CanSubscribe return true if user can subscribe to a source
func (*User) GetSourceCount ¶
GetSourceCount gets the count of sources for an user
func (*User) GetSubscriptionCount ¶
GetSubscriptionCount gets count of subscriptions for an user
func (*User) HasSourceWithName ¶
HasSourceWithName if user has source with name
func (User) HasUnlimitedHookCalls ¶
HasUnlimitedHookCalls return true if user has unlimited hook calls
func (User) IsSourceLimitReached ¶
IsSourceLimitReached return true if source limit is reached
func (*User) IsSubscribedTo ¶
IsSubscribedTo if user subscribed the given source
func (User) IsSubscriptionLimitReached ¶
IsSubscriptionLimitReached return true if users subscription limit is reached
type Webhook ¶
type Webhook struct { PkID uint32 `db:"pk_id" orm:"pk,ai"` SourceID uint32 `db:"sourceID"` Headers string `db:"header"` Payload string `db:"payload"` Received time.Time `db:"received"` }
Webhook the actual webhook from a server
func GetWebhookByPK ¶
GetWebhookByPK returns webhook by giving a webhook pk_id