models

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
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"
)
View Source
const (
	//HeaderStatus headerName for status in response
	HeaderStatus string = "rstatus"
	//HeaderStatusMessage headerName for status in response
	HeaderStatusMessage string = "rmess"
)
View Source
const (
	TableSubscriptions = "Subscriptions"
	TableModes         = "Modes"
)

TableSubscriptions the tableName for subscriptions

View Source
const TableLoginSession = "LoginSessions"

TableLoginSession the table in db for login sessions

View Source
const TableRetries = "Retries"

TableRetries table containing retries

View Source
const TableRoles = "Roles"

TableRoles the db tableName for the roles

View Source
const TableSources = "Sources"

TableSources the db tableName for sources

View Source
const TableUser = "User"

TableUser the table in db for user

View Source
const TableWebhooks = "Webhooks"

TableWebhooks table for the webhooks

Variables

This section is empty.

Functions

func GetAllSessionTokens

func GetAllSessionTokens(db *dbhelper.DBhelper) ([]string, error)

GetAllSessionTokens returns all valid sessions

func GetDefaultConfig

func GetDefaultConfig() string

GetDefaultConfig gets the default config path

func InsertUser

func InsertUser(db *dbhelper.DBhelper, username, password, ip string) error

InsertUser inserts user into db

func LogError

func LogError(err error, context ...map[string]interface{}) bool

LogError returns true on error

func LoginQuery

func LoginQuery(db *dbhelper.DBhelper, username, password, ip string) (string, bool, error)

LoginQuery loginQuery

func NotifyAllSubscriber

func NotifyAllSubscriber(db *dbhelper.DBhelper, config *ConfigStruct, webhook *Webhook, source *Source, callback NotifyCallback)

NotifyAllSubscriber for a given webhook

func RemoveSubscriptionByPK

func RemoveSubscriptionByPK(db *dbhelper.DBhelper, pk uint32) error

RemoveSubscriptionByPK removes a subscription by pk

func SubscriptionExists

func SubscriptionExists(db *dbhelper.DBhelper, sourceID uint32, callbackURL string) (bool, error)

SubscriptionExists check if a subscription exists

func UserExists

func UserExists(db *dbhelper.DBhelper, username string) (bool, error)

UserExists if user 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

type CredentialRequest struct {
	Username string `json:"username"`
	Password string `json:"pass"`
}

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

func (Retry) Delete

func (retry Retry) Delete(db *dbhelper.DBhelper) error

Delete deletes a retry from DB

func (*Retry) UpdateNext

func (retry *Retry) UpdateNext(db *dbhelper.DBhelper) error

UpdateNext updates a 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

func GetSourceByPK(db *dbhelper.DBhelper, pkID uint32) (*Source, error)

GetSourceByPK get source by pk_id

func GetSourceFromSourceID

func GetSourceFromSourceID(db *dbhelper.DBhelper, sourceID string) (*Source, error)

GetSourceFromSourceID get source from sourceID

func GetSourcesForUser

func GetSourcesForUser(db *dbhelper.DBhelper, userID uint32) ([]Source, error)

GetSourcesForUser get all sources created by the given user

func (*Source) Delete

func (source *Source) Delete(db *dbhelper.DBhelper) error

Delete source

func (*Source) Insert

func (source *Source) Insert(db *dbhelper.DBhelper) error

Insert source into DB

func (*Source) Update

func (source *Source) Update(db *dbhelper.DBhelper, field, newText string, arg ...bool) error

Update source

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

type SourceAddResponse struct {
	Secret   string `json:"secret"`
	SourceID string `json:"id"`
}

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

type SubscriberNotifyCallback interface {
	OnWebhookReceive(*Webhook, *Source)
}

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

type SubscriptionRequest struct {
	SourceID    string `json:"sid"`
	CallbackURL string `json:"cbUrl"`
}

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

func GetUserByPK(db *dbhelper.DBhelper, pkID uint32) (*User, error)

GetUserByPK get user by pk_id

func GetUserBySession

func GetUserBySession(db *dbhelper.DBhelper, token string) (*User, error)

GetUserBySession get user by sessionToken

func (*User) AddHookCall

func (user *User) AddHookCall(db *dbhelper.DBhelper, addTraffic uint32) error

AddHookCall adds hookCall (increase hookCall count and traffic)

func (User) CanCreateSource

func (user User) CanCreateSource(private bool) bool

CanCreateSource returns true if a role allows having private/public a source

func (User) CanShareWebhooks

func (user User) CanShareWebhooks() bool

CanShareWebhooks return true if role is allowed to send webhooks

func (User) CanSubscribe

func (user User) CanSubscribe() bool

CanSubscribe return true if user can subscribe to a source

func (*User) GetSourceCount

func (user *User) GetSourceCount(db *dbhelper.DBhelper, private bool) (uint, error)

GetSourceCount gets the count of sources for an user

func (*User) GetSubscriptionCount

func (user *User) GetSubscriptionCount(db *dbhelper.DBhelper) (uint32, error)

GetSubscriptionCount gets count of subscriptions for an user

func (*User) HasSourceWithName

func (user *User) HasSourceWithName(db *dbhelper.DBhelper, name string) (bool, error)

HasSourceWithName if user has source with name

func (User) HasUnlimitedHookCalls

func (user User) HasUnlimitedHookCalls() bool

HasUnlimitedHookCalls return true if user has unlimited hook calls

func (User) IsAdmin

func (user User) IsAdmin() bool

IsAdmin return true if user is an admin

func (User) IsSourceLimitReached

func (user User) IsSourceLimitReached(db *dbhelper.DBhelper, private bool) (bool, error)

IsSourceLimitReached return true if source limit is reached

func (*User) IsSubscribedTo

func (user *User) IsSubscribedTo(db *dbhelper.DBhelper, sourceID uint32) (bool, error)

IsSubscribedTo if user subscribed the given source

func (User) IsSubscriptionLimitReached

func (user User) IsSubscriptionLimitReached(db *dbhelper.DBhelper) (bool, error)

IsSubscriptionLimitReached return true if users subscription limit is reached

func (*User) UpdateIP

func (user *User) UpdateIP(db *dbhelper.DBhelper, ip string) error

UpdateIP for an user

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

func GetWebhookByPK(db *dbhelper.DBhelper, webhookID uint32) (*Webhook, error)

GetWebhookByPK returns webhook by giving a webhook pk_id

func (*Webhook) Insert

func (webhook *Webhook) Insert(db *dbhelper.DBhelper) error

Insert webhook

Jump to

Keyboard shortcuts

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