datastore

package
v0.0.0-...-7940cbf Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2023 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ConfigCollection              = "configurations"
	ProjectsCollection            = "projects"
	OrganisationCollection        = "organisations"
	OrganisationInvitesCollection = "organisation_invites"
	OrganisationMembersCollection = "organisation_members"
	EndpointCollection            = "endpoints"
	EventCollection               = "events"
	SourceCollection              = "sources"
	UserCollection                = "users"
	SubscriptionCollection        = "subscriptions"
	FilterCollection              = "filters"
	DataMigrationsCollection      = "data_migrations"
	EventDeliveryCollection       = "eventdeliveries"
	APIKeyCollection              = "apiKeys"
	DeviceCollection              = "devices"
	PortalLinkCollection          = "portal_links"
)
View Source
const (
	DefaultStrategyProvider     = LinearStrategyProvider
	LinearStrategyProvider      = "linear"
	ExponentialStrategyProvider = "exponential"
)

Variables

View Source
var (
	DefaultStrategyConfig = StrategyConfiguration{
		Type:       DefaultStrategyProvider,
		Duration:   100,
		RetryCount: 10,
	}

	DefaultRateLimitConfig = RateLimitConfiguration{
		Count:    1000,
		Duration: 60,
	}

	DefaultRetryConfig = RetryConfiguration{
		Type:       LinearStrategyProvider,
		Duration:   10,
		RetryCount: 3,
	}

	DefaultAlertConfig = AlertConfiguration{
		Count:     4,
		Threshold: "1h",
	}
	DefaultStoragePolicy = StoragePolicyConfiguration{
		Type: OnPrem,
		OnPrem: &OnPremStorage{
			Path: convoy.DefaultOnPremDir,
		},
	}

	DefaultRetentionPolicy = RetentionPolicyConfiguration{
		Policy: "30d",
	}
)
View Source
var (
	ErrOrgNotFound       = errors.New("organisation not found")
	ErrDeviceNotFound    = errors.New("device not found")
	ErrOrgInviteNotFound = errors.New("organisation invite not found")
	ErrOrgMemberNotFound = errors.New("organisation member not found")
)
View Source
var (
	ErrUserNotFound                  = errors.New("user not found")
	ErrSourceNotFound                = errors.New("source not found")
	ErrEventNotFound                 = errors.New("event not found")
	ErrProjectNotFound               = errors.New("project not found")
	ErrAPIKeyNotFound                = errors.New("api key not found")
	ErrEndpointNotFound              = errors.New("endpoint not found")
	ErrSubscriptionNotFound          = errors.New("subscription not found")
	ErrEventDeliveryNotFound         = errors.New("event delivery not found")
	ErrEventDeliveryAttemptNotFound  = errors.New("event delivery attempt not found")
	ErrPortalLinkNotFound            = errors.New("portal link not found")
	ErrDuplicateEndpointName         = errors.New("an endpoint with this name exists")
	ErrNotAuthorisedToAccessDocument = errors.New("your credentials cannot access or modify this resource")
	ErrConfigNotFound                = errors.New("config not found")
	ErrDuplicateProjectName          = errors.New("a project with this name already exists")
	ErrDuplicateEmail                = errors.New("a user with this email already exists")
	ErrNoActiveSecret                = errors.New("no active secret found")
)
View Source
var ErrInvalidCollection = errors.New("Invalid collection type")
View Source
var ErrInvalidPtr = errors.New("out param is not a valid pointer")
View Source
var PeriodValues = map[string]Period{
	"daily":   Daily,
	"weekly":  Weekly,
	"monthly": Monthly,
	"yearly":  Yearly,
}

Functions

func IsValidPeriod

func IsValidPeriod(period string) bool

func IsValidPointer

func IsValidPointer(i interface{}) bool

Types

type APIKey

type APIKey struct {
	ID        primitive.ObjectID  `json:"-" bson:"_id"`
	UID       string              `json:"uid" bson:"uid"`
	MaskID    string              `json:"mask_id,omitempty" bson:"mask_id"`
	Name      string              `json:"name" bson:"name"`
	Role      auth.Role           `json:"role" bson:"role"`
	Hash      string              `json:"hash,omitempty" bson:"hash"`
	Salt      string              `json:"salt,omitempty" bson:"salt"`
	Type      KeyType             `json:"key_type" bson:"key_type"`
	UserID    string              `json:"user_id" bson:"user_id"`
	ExpiresAt primitive.DateTime  `json:"expires_at,omitempty" bson:"expires_at,omitempty"`
	CreatedAt primitive.DateTime  `json:"created_at,omitempty" bson:"created_at"`
	UpdatedAt primitive.DateTime  `json:"updated_at,omitempty" bson:"updated_at"`
	DeletedAt *primitive.DateTime `json:"deleted_at,omitempty" bson:"deleted_at"`
}

type APIKeyRepository

type APIKeyRepository interface {
	CreateAPIKey(context.Context, *APIKey) error
	UpdateAPIKey(context.Context, *APIKey) error
	FindAPIKeyByID(context.Context, string) (*APIKey, error)
	FindAPIKeyByProjectID(context.Context, string) (*APIKey, error)
	FindAPIKeyByMaskID(context.Context, string) (*APIKey, error)
	FindAPIKeyByHash(context.Context, string) (*APIKey, error)
	RevokeAPIKeys(context.Context, []string) error
	LoadAPIKeysPaged(context.Context, *ApiKeyFilter, *Pageable) ([]APIKey, PaginationData, error)
}

type AlertConfiguration

type AlertConfiguration struct {
	Count     int    `json:"count" bson:"count,omitempty"`
	Threshold string `json:"threshold" bson:"threshold,omitempty" valid:"duration~please provide a valid time duration"`
}

type ApiKey

type ApiKey struct {
	HeaderValue string `json:"header_value" bson:"header_value" valid:"required"`
	HeaderName  string `json:"header_name" bson:"header_name" valid:"required"`
}

type ApiKeyFilter

type ApiKeyFilter struct {
	ProjectID   string
	EndpointID  string
	EndpointIDs []string
	UserID      string
	KeyType     KeyType
}

type AppMetadata

type AppMetadata struct {
	UID          string `json:"uid" bson:"uid"`
	Title        string `json:"title" bson:"title"`
	ProjectID    string `json:"project_id" bson:"project_id"`
	SupportEmail string `json:"support_email" bson:"support_email"`
}

type Application

type Application struct {
	ID              primitive.ObjectID `json:"-" bson:"_id"`
	UID             string             `json:"uid" bson:"uid"`
	ProjectID       string             `json:"project_id" bson:"project_id"`
	Title           string             `json:"name" bson:"title"`
	SupportEmail    string             `json:"support_email,omitempty" bson:"support_email"`
	SlackWebhookURL string             `json:"slack_webhook_url,omitempty" bson:"slack_webhook_url"`
	IsDisabled      bool               `json:"is_disabled,omitempty" bson:"is_disabled"`

	Endpoints []DeprecatedEndpoint `json:"endpoints,omitempty" bson:"endpoints"`
	CreatedAt primitive.DateTime   `json:"created_at,omitempty" bson:"created_at,omitempty" swaggertype:"string"`
	UpdatedAt primitive.DateTime   `json:"updated_at,omitempty" bson:"updated_at,omitempty" swaggertype:"string"`
	DeletedAt *primitive.DateTime  `json:"deleted_at,omitempty" bson:"deleted_at,omitempty" swaggertype:"string"`

	Events int64 `json:"events,omitempty" bson:"-"`
}

Deprecated

type BasicAuth

type BasicAuth struct {
	UserName string `json:"username" bson:"username" valid:"required" `
	Password string `json:"password" bson:"password" valid:"required"`
}

type CLIMetadata

type CLIMetadata struct {
	EventType string `json:"event_type" bson:"event_type"`
	SourceID  string `json:"source_id" bson:"source_id"`
}

type CollectionKey

type CollectionKey string
const CollectionCtx CollectionKey = "collection"

type Configuration

type Configuration struct {
	ID                 primitive.ObjectID          `json:"-" bson:"_id"`
	UID                string                      `json:"uid" bson:"uid"`
	IsAnalyticsEnabled bool                        `json:"is_analytics_enabled" bson:"is_analytics_enabled"`
	IsSignupEnabled    bool                        `json:"is_signup_enabled" bson:"is_signup_enabled"`
	StoragePolicy      *StoragePolicyConfiguration `json:"storage_policy" bson:"storage_policy"`

	CreatedAt primitive.DateTime  `json:"created_at,omitempty" bson:"created_at,omitempty" swaggertype:"string"`
	UpdatedAt primitive.DateTime  `json:"updated_at,omitempty" bson:"updated_at,omitempty" swaggertype:"string"`
	DeletedAt *primitive.DateTime `json:"deleted_at,omitempty" bson:"deleted_at" swaggertype:"string"`
}

type ConfigurationRepository

type ConfigurationRepository interface {
	CreateConfiguration(context.Context, *Configuration) error
	LoadConfiguration(context.Context) (*Configuration, error)
	UpdateConfiguration(context.Context, *Configuration) error
}

type DeliveryAttempt

type DeliveryAttempt struct {
	ID         primitive.ObjectID `json:"-" bson:"_id"`
	UID        string             `json:"uid" bson:"uid"`
	MsgID      string             `json:"msg_id" bson:"msg_id"`
	URL        string             `json:"url" bson:"url"`
	Method     string             `json:"method" bson:"method"`
	EndpointID string             `json:"endpoint_id" bson:"endpoint_id"`
	APIVersion string             `json:"api_version" bson:"api_version"`

	IPAddress        string     `json:"ip_address,omitempty" bson:"ip_address,omitempty"`
	RequestHeader    HttpHeader `json:"request_http_header,omitempty" bson:"request_http_header,omitempty"`
	ResponseHeader   HttpHeader `json:"response_http_header,omitempty" bson:"response_http_header,omitempty"`
	HttpResponseCode string     `json:"http_status,omitempty" bson:"http_status,omitempty"`
	ResponseData     string     `json:"response_data,omitempty" bson:"response_data,omitempty"`
	Error            string     `json:"error,omitempty" bson:"error,omitempty"`
	Status           bool       `json:"status,omitempty" bson:"status,omitempty"`

	CreatedAt primitive.DateTime  `json:"created_at,omitempty" bson:"created_at,omitempty" swaggertype:"string"`
	UpdatedAt primitive.DateTime  `json:"updated_at,omitempty" bson:"updated_at,omitempty" swaggertype:"string"`
	DeletedAt *primitive.DateTime `json:"deleted_at,omitempty" bson:"deleted_at" swaggertype:"string"`
}

type DeprecatedEndpoint

type DeprecatedEndpoint struct {
	UID                string   `json:"uid" bson:"uid"`
	TargetURL          string   `json:"target_url" bson:"target_url"`
	Description        string   `json:"description" bson:"description"`
	Secret             string   `json:"-" bson:"secret"`
	Secrets            []Secret `json:"secrets" bson:"secrets"`
	AdvancedSignatures bool     `json:"advanced_signatures" bson:"advanced_signatures"`

	HttpTimeout       string                  `json:"http_timeout" bson:"http_timeout"`
	RateLimit         int                     `json:"rate_limit" bson:"rate_limit"`
	RateLimitDuration string                  `json:"rate_limit_duration" bson:"rate_limit_duration"`
	Authentication    *EndpointAuthentication `json:"authentication" bson:"authentication"`

	CreatedAt primitive.DateTime  `json:"created_at,omitempty" bson:"created_at,omitempty" swaggertype:"string"`
	UpdatedAt primitive.DateTime  `json:"updated_at,omitempty" bson:"updated_at,omitempty" swaggertype:"string"`
	DeletedAt *primitive.DateTime `json:"deleted_at,omitempty" bson:"deleted_at,omitempty" swaggertype:"string"`
}

Deprecated

type Device

type Device struct {
	ID         primitive.ObjectID  `json:"-" bson:"_id"`
	UID        string              `json:"uid" bson:"uid"`
	ProjectID  string              `json:"project_id,omitempty" bson:"project_id"`
	EndpointID string              `json:"endpoint_id,omitempty" bson:"endpoint_id"`
	HostName   string              `json:"host_name,omitempty" bson:"host_name"`
	Status     DeviceStatus        `json:"status,omitempty" bson:"status"`
	LastSeenAt primitive.DateTime  `json:"last_seen_at,omitempty" bson:"last_seen_at,omitempty" swaggertype:"string"`
	CreatedAt  primitive.DateTime  `json:"created_at,omitempty" bson:"created_at,omitempty" swaggertype:"string"`
	UpdatedAt  primitive.DateTime  `json:"updated_at,omitempty" bson:"updated_at,omitempty" swaggertype:"string"`
	DeletedAt  *primitive.DateTime `json:"deleted_at,omitempty" bson:"deleted_at" swaggertype:"string"`
}

type DeviceRepository

type DeviceRepository interface {
	CreateDevice(ctx context.Context, device *Device) error
	UpdateDevice(ctx context.Context, device *Device, appID, projectID string) error
	UpdateDeviceLastSeen(ctx context.Context, device *Device, appID, projectID string, status DeviceStatus) error
	DeleteDevice(ctx context.Context, uid string, appID, projectID string) error
	FetchDeviceByID(ctx context.Context, uid string, appID, projectID string) (*Device, error)
	FetchDeviceByHostName(ctx context.Context, hostName string, appID, projectID string) (*Device, error)
	LoadDevicesPaged(ctx context.Context, projectID string, filter *ApiKeyFilter, pageable Pageable) ([]Device, PaginationData, error)
}

type DeviceStatus

type DeviceStatus string
const (
	DeviceStatusOffline  DeviceStatus = "offline"
	DeviceStatusOnline   DeviceStatus = "online"
	DeviceStatusDisabled DeviceStatus = "disabled"
)

type EncodingType

type EncodingType string
const (
	Base64Encoding EncodingType = "base64"
	HexEncoding    EncodingType = "hex"
)

func (EncodingType) String

func (e EncodingType) String() string

type Endpoint

type Endpoint struct {
	ID                 primitive.ObjectID `json:"-" bson:"_id"`
	UID                string             `json:"uid" bson:"uid"`
	ProjectID          string             `json:"project_id" bson:"project_id"`
	OwnerID            string             `json:"owner_id,omitempty" bson:"owner_id"`
	TargetURL          string             `json:"target_url" bson:"target_url"`
	Title              string             `json:"title" bson:"title"`
	Secrets            []Secret           `json:"secrets" bson:"secrets"`
	AdvancedSignatures bool               `json:"advanced_signatures" bson:"advanced_signatures"`
	Description        string             `json:"description" bson:"description"`
	SlackWebhookURL    string             `json:"slack_webhook_url,omitempty" bson:"slack_webhook_url"`
	SupportEmail       string             `json:"support_email,omitempty" bson:"support_email"`
	AppID              string             `json:"-" bson:"app_id"` // Deprecated but necessary for backward compatibility

	HttpTimeout string         `json:"http_timeout" bson:"http_timeout"`
	RateLimit   int            `json:"rate_limit" bson:"rate_limit"`
	Events      int64          `json:"events,omitempty" bson:"-"`
	Status      EndpointStatus `json:"status" bson:"status"`

	RateLimitDuration string                  `json:"rate_limit_duration" bson:"rate_limit_duration"`
	Authentication    *EndpointAuthentication `json:"authentication" bson:"authentication"`

	CreatedAt primitive.DateTime  `json:"created_at,omitempty" bson:"created_at,omitempty" swaggertype:"string"`
	UpdatedAt primitive.DateTime  `json:"updated_at,omitempty" bson:"updated_at,omitempty" swaggertype:"string"`
	DeletedAt *primitive.DateTime `json:"deleted_at,omitempty" bson:"deleted_at" swaggertype:"string"`
}

func (*Endpoint) GetActiveSecretIndex

func (e *Endpoint) GetActiveSecretIndex() (int, error)

type EndpointAuthentication

type EndpointAuthentication struct {
	Type   EndpointAuthenticationType `json:"type,omitempty" bson:"type" valid:"optional,in(api_key)~unsupported authentication type"`
	ApiKey *ApiKey                    `json:"api_key" bson:"api_key"`
}

type EndpointAuthenticationType

type EndpointAuthenticationType string
const (
	APIKeyAuthentication EndpointAuthenticationType = "api_key"
)

type EndpointRepository

type EndpointRepository interface {
	CreateEndpoint(ctx context.Context, endpoint *Endpoint, projectID string) error
	FindEndpointByID(çtx context.Context, id string) (*Endpoint, error)
	FindEndpointsByID(ctx context.Context, ids []string) ([]Endpoint, error)
	FindEndpointsByAppID(ctx context.Context, appID string) ([]Endpoint, error)
	FindEndpointsByOwnerID(ctx context.Context, projectID string, ownerID string) ([]Endpoint, error)
	UpdateEndpoint(ctx context.Context, endpoint *Endpoint, projectID string) error
	UpdateEndpointStatus(ctx context.Context, projectID, endpointID string, status EndpointStatus) error
	DeleteEndpoint(ctx context.Context, endpoint *Endpoint) error
	CountProjectEndpoints(ctx context.Context, projectID string) (int64, error)
	DeleteProjectEndpoints(context.Context, string) error
	LoadEndpointsPaged(ctx context.Context, projectID string, query string, pageable Pageable) ([]Endpoint, PaginationData, error)
	LoadEndpointsPagedByProjectId(ctx context.Context, projectID string, pageable Pageable) ([]Endpoint, PaginationData, error)
	SearchEndpointsByProjectId(ctx context.Context, projectID string, params SearchParams) ([]Endpoint, error)
	ExpireSecret(ctx context.Context, projectID string, endpointID string, secrets []Secret) error
}

type EndpointStatus

type EndpointStatus string
const (
	ActiveEndpointStatus   EndpointStatus = "active"
	InactiveEndpointStatus EndpointStatus = "inactive"
	PendingEndpointStatus  EndpointStatus = "pending"
)

type Event

type Event struct {
	ID               primitive.ObjectID `json:"-" bson:"_id"`
	UID              string             `json:"uid" bson:"uid"`
	EventType        EventType          `json:"event_type" bson:"event_type"`
	MatchedEndpoints int                `json:"matched_endpoints" bson:"matched_enpoints"` // TODO(all) remove this field

	SourceID         string                `json:"source_id,omitempty" bson:"source_id"`
	AppID            string                `json:"app_id,omitempty" bson:"app_id"` // Deprecated
	ProjectID        string                `json:"project_id,omitempty" bson:"project_id"`
	Endpoints        []string              `json:"endpoints" bson:"endpoints"`
	Headers          httpheader.HTTPHeader `json:"headers" bson:"headers"`
	EndpointMetadata []*Endpoint           `json:"endpoint_metadata,omitempty" bson:"endpoint_metadata"`
	Source           *Source               `json:"source_metadata,omitempty" bson:"source_metadata"`

	// Data is an arbitrary JSON value that gets sent as the body of the
	// webhook to the endpoints
	Data json.RawMessage `json:"data,omitempty" bson:"data"`
	Raw  string          `json:"raw,omitempty" bson:"raw"`

	CreatedAt primitive.DateTime  `json:"created_at,omitempty" bson:"created_at,omitempty" swaggertype:"string"`
	UpdatedAt primitive.DateTime  `json:"updated_at,omitempty" bson:"updated_at,omitempty" swaggertype:"string"`
	DeletedAt *primitive.DateTime `json:"deleted_at,omitempty" bson:"deleted_at" swaggertype:"string"`
}

Event defines a payload to be sent to an application

func (*Event) GetRawHeaders

func (e *Event) GetRawHeaders() map[string]interface{}

func (*Event) GetRawHeadersJSON

func (e *Event) GetRawHeadersJSON() ([]byte, error)

type EventDelivery

type EventDelivery struct {
	ID             primitive.ObjectID    `json:"-" bson:"_id"`
	UID            string                `json:"uid" bson:"uid"`
	ProjectID      string                `json:"project_id,omitempty" bson:"project_id"`
	EventID        string                `json:"event_id,omitempty" bson:"event_id"`
	EndpointID     string                `json:"endpoint_id,omitempty" bson:"endpoint_id"`
	DeviceID       string                `json:"device_id" bson:"device_id"`
	SubscriptionID string                `json:"subscription_id,omitempty" bson:"subscription_id"`
	Headers        httpheader.HTTPHeader `json:"headers" bson:"headers"`

	Endpoint *Endpoint `json:"endpoint_metadata,omitempty" bson:"endpoint_metadata"`
	Event    *Event    `json:"event_metadata,omitempty" bson:"event_metadata"`

	DeliveryAttempts []DeliveryAttempt   `json:"-" bson:"attempts"`
	Status           EventDeliveryStatus `json:"status" bson:"status"`
	Metadata         *Metadata           `json:"metadata" bson:"metadata"`
	CLIMetadata      *CLIMetadata        `json:"cli_metadata" bson:"cli_metadata"`
	Description      string              `json:"description,omitempty" bson:"description"`
	CreatedAt        primitive.DateTime  `json:"created_at,omitempty" bson:"created_at,omitempty" swaggertype:"string"`
	UpdatedAt        primitive.DateTime  `json:"updated_at,omitempty" bson:"updated_at,omitempty" swaggertype:"string"`
	DeletedAt        *primitive.DateTime `json:"deleted_at,omitempty" bson:"deleted_at" swaggertype:"string"`
}

EventDelivery defines a payload to be sent to an application

type EventDeliveryFilter

type EventDeliveryFilter struct {
	ProjectID      string `json:"project_id" bson:"project_id"`
	CreatedAtStart int64  `json:"created_at_start" bson:"created_at_start"`
	CreatedAtEnd   int64  `json:"created_at_end" bson:"created_at_end"`
}

type EventDeliveryRepository

type EventDeliveryRepository interface {
	CreateEventDelivery(context.Context, *EventDelivery) error
	FindEventDeliveryByID(context.Context, string) (*EventDelivery, error)
	FindEventDeliveriesByIDs(context.Context, []string) ([]EventDelivery, error)
	FindEventDeliveriesByEventID(context.Context, string) ([]EventDelivery, error)
	CountDeliveriesByStatus(context.Context, EventDeliveryStatus, SearchParams) (int64, error)
	UpdateStatusOfEventDelivery(context.Context, EventDelivery, EventDeliveryStatus) error
	UpdateStatusOfEventDeliveries(context.Context, []string, EventDeliveryStatus) error
	FindDiscardedEventDeliveries(ctx context.Context, appId, deviceId string, searchParams SearchParams) ([]EventDelivery, error)

	UpdateEventDeliveryWithAttempt(context.Context, EventDelivery, DeliveryAttempt) error
	CountEventDeliveries(context.Context, string, []string, string, []EventDeliveryStatus, SearchParams) (int64, error)
	DeleteProjectEventDeliveries(ctx context.Context, filter *EventDeliveryFilter, hardDelete bool) error
	LoadEventDeliveriesPaged(context.Context, string, []string, string, []EventDeliveryStatus, SearchParams, Pageable) ([]EventDelivery, PaginationData, error)
	LoadEventDeliveriesIntervals(context.Context, string, SearchParams, Period, int) ([]EventInterval, error)
}

type EventDeliveryStatus

type EventDeliveryStatus string
const (
	// ScheduledEventStatus : when an Event has been scheduled for delivery
	ScheduledEventStatus  EventDeliveryStatus = "Scheduled"
	ProcessingEventStatus EventDeliveryStatus = "Processing"
	DiscardedEventStatus  EventDeliveryStatus = "Discarded"
	FailureEventStatus    EventDeliveryStatus = "Failure"
	SuccessEventStatus    EventDeliveryStatus = "Success"
	RetryEventStatus      EventDeliveryStatus = "Retry"
)

func (EventDeliveryStatus) IsValid

func (e EventDeliveryStatus) IsValid() bool

type EventFilter

type EventFilter struct {
	ProjectID      string `json:"project_id" bson:"project_id"`
	CreatedAtStart int64  `json:"created_at_start" bson:"created_at_start"`
	CreatedAtEnd   int64  `json:"created_at_end" bson:"created_at_end"`
}

type EventInterval

type EventInterval struct {
	Data  EventIntervalData `json:"data" bson:"_id"`
	Count uint64            `json:"count" bson:"count"`
}

type EventIntervalData

type EventIntervalData struct {
	Interval int64  `json:"index" bson:"index"`
	Time     string `json:"date" bson:"total_time"`
}

type EventRepository

type EventRepository interface {
	CreateEvent(context.Context, *Event) error
	FindEventByID(ctx context.Context, id string) (*Event, error)
	FindEventsByIDs(context.Context, []string) ([]Event, error)
	CountProjectMessages(ctx context.Context, projectID string) (int64, error)
	CountEvents(ctx context.Context, f *Filter) (int64, error)
	LoadEventsPaged(context.Context, *Filter) ([]Event, PaginationData, error)
	DeleteProjectEvents(context.Context, *EventFilter, bool) error
}

type EventType

type EventType string

EventType is used to identify a specific event. This could be "user.new" This will be used for data indexing Makes it easy to filter by a list of events

type Filter

type Filter struct {
	Query        string
	Project      *Project
	EndpointID   string
	EndpointIDs  []string
	EventID      string
	SourceID     string
	Pageable     Pageable
	Status       []EventDeliveryStatus
	SearchParams SearchParams
}

type FilterBy

type FilterBy struct {
	EndpointID   string
	EndpointIDs  []string
	ProjectID    string
	SourceID     string
	SearchParams SearchParams
}

func (*FilterBy) String

func (f *FilterBy) String() *string

type FilterConfiguration

type FilterConfiguration struct {
	EventTypes []string     `json:"event_types" bson:"event_types,omitempty"`
	Filter     FilterSchema `json:"filter" bson:"filter"`
}

type FilterSchema

type FilterSchema struct {
	Headers map[string]interface{} `json:"headers" bson:"headers"`
	Body    map[string]interface{} `json:"body" bson:"body"`
}

type HMac

type HMac struct {
	Header   string       `json:"header" bson:"header" valid:"required"`
	Hash     string       `json:"hash" bson:"hash" valid:"supported_hash,required"`
	Secret   string       `json:"secret" bson:"secret" valid:"required"`
	Encoding EncodingType `json:"encoding" bson:"encoding" valid:"supported_encoding~please provide a valid encoding type,required"`
}

type HttpHeader

type HttpHeader map[string]string

func (HttpHeader) SetHeadersInRequest

func (h HttpHeader) SetHeadersInRequest(r *http.Request)

type InviteStatus

type InviteStatus string
const (
	InviteStatusAccepted  InviteStatus = "accepted"
	InviteStatusDeclined  InviteStatus = "declined"
	InviteStatusPending   InviteStatus = "pending"
	InviteStatusCancelled InviteStatus = "cancelled"
)

func (InviteStatus) String

func (i InviteStatus) String() string

type KeyType

type KeyType string
const (
	ProjectKey   KeyType = "project"
	AppPortalKey KeyType = "app_portal"
	CLIKey       KeyType = "cli"
	PersonalKey  KeyType = "personal_key"
)

func (KeyType) IsValid

func (k KeyType) IsValid() bool

func (KeyType) IsValidAppKey

func (k KeyType) IsValidAppKey() bool

type Metadata

type Metadata struct {
	// Data to be sent to endpoint.
	Data     json.RawMessage  `json:"data" bson:"data"`
	Raw      string           `json:"raw" bson:"raw"`
	Strategy StrategyProvider `json:"strategy" bson:"strategy"`

	NextSendTime primitive.DateTime `json:"next_send_time" bson:"next_send_time"`

	// NumTrials: number of times we have tried to deliver this Event to
	// an application
	NumTrials uint64 `json:"num_trials" bson:"num_trials"`

	IntervalSeconds uint64 `json:"interval_seconds" bson:"interval_seconds"`

	RetryLimit uint64 `json:"retry_limit" bson:"retry_limit"`
}

func (Metadata) Value

func (em Metadata) Value() (driver.Value, error)

type MongoStore

type MongoStore struct {
	IsConnected bool
	Database    *mongo.Database
}

func (*MongoStore) Aggregate

func (d *MongoStore) Aggregate(ctx context.Context, pipeline mongo.Pipeline, output interface{}, allowDiskUse bool) error

func (*MongoStore) Count

func (d *MongoStore) Count(ctx context.Context, filter map[string]interface{}) (int64, error)

func (*MongoStore) CountWithDeleted

func (d *MongoStore) CountWithDeleted(ctx context.Context, filter map[string]interface{}) (int64, error)

func (*MongoStore) DeleteByID

func (d *MongoStore) DeleteByID(ctx context.Context, id string, hardDelete bool) error

*

  • DeleteByID
  • Deletes a single record by id
  • where ID can be a string or whatever. *
  • param: interface{} id
  • param: bool hardDelete
  • return: error
  • If hard delete is false, a soft delete is executed where the document status is changed.
  • If hardDelete is true, the document is completely deleted.

func (*MongoStore) DeleteMany

func (d *MongoStore) DeleteMany(ctx context.Context, filter, payload bson.M, hardDelete bool) error

*

  • DeleteMany
  • Hard Deletes many items in the collection
  • `filter` this is the search criteria *
  • param: bson.M filter
  • param: bool hardDelete
  • If hardDelete is false, a soft delete is executed where the document status is changed.
  • If hardDelete is true, the document is completely deleted.
  • return: error

func (*MongoStore) DeleteOne

func (d *MongoStore) DeleteOne(ctx context.Context, filter bson.M, hardDelete bool) error

*

  • DeleteOne
  • Deletes one item from the MongoStore using filter a hash map to properly filter what is to be deleted. *
  • param: bson.M filter
  • param: bool hardDelete
  • return: error
  • If hard delete is false, a soft delete is executed where the document status is changed.
  • If hardDelete is true, the document is completely deleted.

func (*MongoStore) FindAll

func (d *MongoStore) FindAll(ctx context.Context, filter bson.M, sort interface{}, projection, results interface{}) error

func (*MongoStore) FindByID

func (d *MongoStore) FindByID(ctx context.Context, id string, projection bson.M, result interface{}) error

*

  • FindByID
  • FindByID finds a single record by id in the MongoStore
  • returns nil if record is not found. *
  • param: interface{} id
  • param: bson.M projection
  • return: bson.M

func (*MongoStore) FindMany

func (d *MongoStore) FindMany(ctx context.Context, filter, projection bson.M, sort interface{}, lastID primitive.ObjectID, limit int64, results interface{}) error

func (*MongoStore) FindManyWithDeletedAt

func (d *MongoStore) FindManyWithDeletedAt(ctx context.Context, filter, projection bson.M, sort interface{}, limit, skip int64, results interface{}) error

func (*MongoStore) FindOne

func (d *MongoStore) FindOne(ctx context.Context, filter, projection bson.M, result interface{}) error

*

  • Find One by

func (*MongoStore) Inc

func (d *MongoStore) Inc(ctx context.Context, filter bson.M, payload interface{}) error

func (*MongoStore) Save

func (d *MongoStore) Save(ctx context.Context, payload interface{}, out interface{}) error

*

  • Save
  • Save is used to save a record in the MongoStore

func (*MongoStore) SaveMany

func (d *MongoStore) SaveMany(ctx context.Context, payload []interface{}) error

*

  • SaveMany
  • SaveMany is used to bulk insert into the MongoStore *
  • param: []interface{} payload
  • return: error

func (*MongoStore) UpdateByID

func (d *MongoStore) UpdateByID(ctx context.Context, id string, payload interface{}) error

*

  • UpdateByID
  • Updates a single record by id in the MongoStore *
  • param: interface{} id
  • param: interface{} payload
  • return: error

func (*MongoStore) UpdateMany

func (d *MongoStore) UpdateMany(ctx context.Context, filter, payload bson.M, bulk bool) error

*

  • UpdateMany
  • Updates many items in the collection
  • `filter` this is the search criteria
  • `payload` this is the update payload. *
  • param: bson.M filter
  • param: interface{} payload
  • return: error

func (*MongoStore) UpdateOne

func (d *MongoStore) UpdateOne(ctx context.Context, filter bson.M, payload interface{}) error

func (*MongoStore) WithTransaction

func (d *MongoStore) WithTransaction(ctx context.Context, fn func(sessCtx mongo.SessionContext) error) error

type OnPremStorage

type OnPremStorage struct {
	Path string `json:"path" bson:"path"`
}

type Organisation

type Organisation struct {
	ID             primitive.ObjectID  `json:"-" bson:"_id"`
	UID            string              `json:"uid" bson:"uid"`
	OwnerID        string              `json:"-" bson:"owner_id"`
	Name           string              `json:"name" bson:"name"`
	CustomDomain   string              `json:"custom_domain" bson:"custom_domain"`
	AssignedDomain string              `json:"assigned_domain" bson:"assigned_domain"`
	CreatedAt      primitive.DateTime  `json:"created_at,omitempty" bson:"created_at,omitempty" swaggertype:"string"`
	UpdatedAt      primitive.DateTime  `json:"updated_at,omitempty" bson:"updated_at,omitempty" swaggertype:"string"`
	DeletedAt      *primitive.DateTime `json:"deleted_at,omitempty" bson:"deleted_at" swaggertype:"string"`
}

type OrganisationInvite

type OrganisationInvite struct {
	ID               primitive.ObjectID  `json:"-" bson:"_id"`
	UID              string              `json:"uid" bson:"uid"`
	OrganisationID   string              `json:"organisation_id" bson:"organisation_id"`
	InviteeEmail     string              `json:"invitee_email" bson:"invitee_email"`
	Token            string              `json:"token" bson:"token"`
	Role             auth.Role           `json:"role" bson:"role"`
	Status           InviteStatus        `json:"status" bson:"status"`
	ExpiresAt        primitive.DateTime  `json:"-" bson:"expires_at"`
	CreatedAt        primitive.DateTime  `json:"created_at,omitempty" bson:"created_at,omitempty" swaggertype:"string"`
	UpdatedAt        primitive.DateTime  `json:"updated_at,omitempty" bson:"updated_at,omitempty" swaggertype:"string"`
	OrganisationName string              `json:"organisation_name,omitempty" bson:"-"`
	DeletedAt        *primitive.DateTime `json:"deleted_at,omitempty" bson:"deleted_at" swaggertype:"string"`
}

type OrganisationInviteRepository

type OrganisationInviteRepository interface {
	LoadOrganisationsInvitesPaged(ctx context.Context, orgID string, inviteStatus InviteStatus, pageable Pageable) ([]OrganisationInvite, PaginationData, error)
	CreateOrganisationInvite(ctx context.Context, iv *OrganisationInvite) error
	UpdateOrganisationInvite(ctx context.Context, iv *OrganisationInvite) error
	DeleteOrganisationInvite(ctx context.Context, uid string) error
	FetchOrganisationInviteByID(ctx context.Context, uid string) (*OrganisationInvite, error)
	FetchOrganisationInviteByToken(ctx context.Context, token string) (*OrganisationInvite, error)
}

type OrganisationMember

type OrganisationMember struct {
	ID             primitive.ObjectID  `json:"-" bson:"_id"`
	UID            string              `json:"uid" bson:"uid"`
	OrganisationID string              `json:"organisation_id" bson:"organisation_id"`
	UserID         string              `json:"user_id" bson:"user_id"`
	Role           auth.Role           `json:"role" bson:"role"`
	UserMetadata   *UserMetadata       `json:"user_metadata" bson:"-"`
	CreatedAt      primitive.DateTime  `json:"created_at,omitempty" bson:"created_at,omitempty" swaggertype:"string"`
	UpdatedAt      primitive.DateTime  `json:"updated_at,omitempty" bson:"updated_at,omitempty" swaggertype:"string"`
	DeletedAt      *primitive.DateTime `json:"deleted_at,omitempty" bson:"deleted_at" swaggertype:"string"`
}

type OrganisationMemberRepository

type OrganisationMemberRepository interface {
	LoadOrganisationMembersPaged(ctx context.Context, organisationID string, pageable Pageable) ([]*OrganisationMember, PaginationData, error)
	LoadUserOrganisationsPaged(ctx context.Context, userID string, pageable Pageable) ([]Organisation, PaginationData, error)
	FindUserProjects(ctx context.Context, userID string) ([]Project, error)
	CreateOrganisationMember(ctx context.Context, member *OrganisationMember) error
	UpdateOrganisationMember(ctx context.Context, member *OrganisationMember) error
	DeleteOrganisationMember(ctx context.Context, memberID string, orgID string) error
	FetchOrganisationMemberByID(ctx context.Context, memberID string, organisationID string) (*OrganisationMember, error)
	FetchOrganisationMemberByUserID(ctx context.Context, userID string, organisationID string) (*OrganisationMember, error)
}

type OrganisationRepository

type OrganisationRepository interface {
	LoadOrganisationsPaged(context.Context, Pageable) ([]Organisation, PaginationData, error)
	CreateOrganisation(context.Context, *Organisation) error
	UpdateOrganisation(context.Context, *Organisation) error
	DeleteOrganisation(context.Context, string) error
	FetchOrganisationByID(context.Context, string) (*Organisation, error)
	FetchOrganisationByCustomDomain(context.Context, string) (*Organisation, error)
	FetchOrganisationByAssignedDomain(context.Context, string) (*Organisation, error)
}

type Pageable

type Pageable struct {
	Page    int `json:"page" bson:"page"`
	PerPage int `json:"per_page" bson:"per_page"`
	Sort    int `json:"sort" bson:"sort"`
}

type PaginationData

type PaginationData struct {
	Total     int64 `json:"total"`
	Page      int64 `json:"page"`
	PerPage   int64 `json:"perPage"`
	Prev      int64 `json:"prev"`
	Next      int64 `json:"next"`
	TotalPage int64 `json:"totalPage"`
}

type Password

type Password struct {
	Plaintext string
	Hash      []byte
}

func (*Password) GenerateHash

func (p *Password) GenerateHash() error

func (*Password) Matches

func (p *Password) Matches() (bool, error)

type Period

type Period int
const (
	Daily Period = iota
	Weekly
	Monthly
	Yearly
)
type PortalLink struct {
	ID                primitive.ObjectID `json:"-" bson:"_id"`
	UID               string             `json:"uid" bson:"uid"`
	Name              string             `json:"name" bson:"name"`
	ProjectID         string             `json:"project_id" bson:"project_id"`
	Token             string             `json:"-" bson:"token"`
	Endpoints         []string           `json:"endpoints" bson:"endpoints"`
	EndpointsMetadata []Endpoint         `json:"endpoints_metadata" bson:"endpoints_metadata"`

	CreatedAt primitive.DateTime  `json:"created_at,omitempty" bson:"created_at,omitempty" swaggertype:"string"`
	UpdatedAt primitive.DateTime  `json:"updated_at,omitempty" bson:"updated_at,omitempty" swaggertype:"string"`
	DeletedAt *primitive.DateTime `json:"deleted_at,omitempty" bson:"deleted_at,omitempty" swaggertype:"string"`
}

type PortalLinkRepository

type PortalLinkRepository interface {
	CreatePortalLink(context.Context, *PortalLink) error
	UpdatePortalLink(ctx context.Context, projectID string, portal *PortalLink) error
	FindPortalLinkByID(ctx context.Context, projectID string, id string) (*PortalLink, error)
	FindPortalLinkByToken(ctx context.Context, token string) (*PortalLink, error)
	LoadPortalLinksPaged(ctx context.Context, projectID string, f *FilterBy, pageable Pageable) ([]PortalLink, PaginationData, error)
	RevokePortalLink(ctx context.Context, projectID string, id string) error
}

type Project

type Project struct {
	ID             primitive.ObjectID `json:"-" bson:"_id"`
	UID            string             `json:"uid" bson:"uid"`
	Name           string             `json:"name" bson:"name"`
	LogoURL        string             `json:"logo_url" bson:"logo_url"`
	OrganisationID string             `json:"organisation_id" bson:"organisation_id"`
	Type           ProjectType        `json:"type" bson:"type"`
	Config         *ProjectConfig     `json:"config" bson:"config"`
	Statistics     *ProjectStatistics `json:"statistics" bson:"-"`

	// TODO(subomi): refactor this into the Instance API.
	RateLimit         int              `json:"rate_limit" bson:"rate_limit"`
	RateLimitDuration string           `json:"rate_limit_duration" bson:"rate_limit_duration"`
	Metadata          *ProjectMetadata `json:"metadata" bson:"metadata"`

	CreatedAt primitive.DateTime  `json:"created_at,omitempty" bson:"created_at,omitempty" swaggertype:"string"`
	UpdatedAt primitive.DateTime  `json:"updated_at,omitempty" bson:"updated_at,omitempty" swaggertype:"string"`
	DeletedAt *primitive.DateTime `json:"deleted_at,omitempty" bson:"deleted_at" swaggertype:"string"`
}

func (*Project) IsDeleted

func (o *Project) IsDeleted() bool

func (*Project) IsOwner

func (o *Project) IsOwner(e *Endpoint) bool

type ProjectConfig

type ProjectConfig struct {
	RateLimit                *RateLimitConfiguration       `json:"ratelimit"`
	Strategy                 *StrategyConfiguration        `json:"strategy"`
	Signature                *SignatureConfiguration       `json:"signature"`
	RetentionPolicy          *RetentionPolicyConfiguration `json:"retention_policy" bson:"retention_policy"`
	MaxIngestSize            uint64                        `json:"max_payload_read_size" bson:"max_payload_read_size"`
	ReplayAttacks            bool                          `json:"replay_attacks" bson:"replay_attacks"`
	IsRetentionPolicyEnabled bool                          `json:"is_retention_policy_enabled" bson:"is_retention_policy_enabled"`
}

type ProjectFilter

type ProjectFilter struct {
	OrgID string   `json:"org_id" bson:"org_id"`
	Names []string `json:"name" bson:"name"`
}

func (*ProjectFilter) ToGenericMap

func (g *ProjectFilter) ToGenericMap() map[string]interface{}

func (*ProjectFilter) WithNamesTrimmed

func (g *ProjectFilter) WithNamesTrimmed() *ProjectFilter

type ProjectMetadata

type ProjectMetadata struct {
	RetainedEvents int `json:"retained_events" bson:"retained_events"`
}

type ProjectRepository

type ProjectRepository interface {
	LoadProjects(context.Context, *ProjectFilter) ([]*Project, error)
	CreateProject(context.Context, *Project) error
	UpdateProject(context.Context, *Project) error
	DeleteProject(ctx context.Context, uid string) error
	FetchProjectByID(context.Context, string) (*Project, error)
	FetchProjectsByIDs(context.Context, []string) ([]Project, error)
	FillProjectsStatistics(ctx context.Context, project *Project) error
}

type ProjectStatistics

type ProjectStatistics struct {
	ProjectID    string `json:"-" bson:"project_id"`
	MessagesSent int64  `json:"messages_sent" bson:"messages_sent"`
	TotalApps    int64  `json:"total_endpoints" bson:"total_endpoints"`
}

type ProjectType

type ProjectType string
const (
	OutgoingProject ProjectType = "outgoing"
	IncomingProject ProjectType = "incoming"
)

type ProviderConfig

type ProviderConfig struct {
	Twitter *TwitterProviderConfig `json:"twitter" bson:"twitter"`
}

type RateLimitConfiguration

type RateLimitConfiguration struct {
	Count    int    `json:"count" bson:"count"`
	Duration uint64 `json:"duration" bson:"duration"`
}

type RetentionPolicyConfiguration

type RetentionPolicyConfiguration struct {
	Policy string `json:"policy" valid:"required~please provide a valid retention policy"`
}

type RetryConfiguration

type RetryConfiguration struct {
	Type       StrategyProvider `json:"type,omitempty" bson:"type,omitempty" valid:"supported_retry_strategy~please provide a valid retry strategy type"`
	Duration   uint64           `json:"duration,omitempty" bson:"duration,omitempty" valid:"duration~please provide a valid time duration"`
	RetryCount uint64           `json:"retry_count" bson:"retry_count" valid:"int~please provide a valid retry count"`
}

type S3Storage

type S3Storage struct {
	Bucket       string `json:"bucket" bson:"bucket" valid:"required~please provide a bucket name"`
	AccessKey    string `json:"access_key,omitempty" bson:"access_key" valid:"required~please provide an access key"`
	SecretKey    string `json:"secret_key,omitempty" bson:"secret_key" valid:"required~please provide a secret key"`
	Region       string `json:"region,omitempty" bson:"region"`
	SessionToken string `json:"-" bson:"session_token"`
	Endpoint     string `json:"endpoint,omitempty" bson:"endpoint"`
}

type SearchFilter

type SearchFilter struct {
	Query    string
	FilterBy FilterBy
	Pageable Pageable
}

type SearchParams

type SearchParams struct {
	CreatedAtStart int64 `json:"created_at_start" bson:"created_at_start"`
	CreatedAtEnd   int64 `json:"created_at_end" bson:"created_at_end"`
}

type Secret

type Secret struct {
	UID   string `json:"uid" bson:"uid"`
	Value string `json:"value" bson:"value"`

	ExpiresAt primitive.DateTime  `json:"expires_at,omitempty" bson:"expires_at,omitempty" swaggertype:"string"`
	CreatedAt primitive.DateTime  `json:"created_at,omitempty" bson:"created_at,omitempty" swaggertype:"string"`
	UpdatedAt primitive.DateTime  `json:"updated_at,omitempty" bson:"updated_at,omitempty" swaggertype:"string"`
	DeletedAt *primitive.DateTime `json:"deleted_at,omitempty" bson:"deleted_at" swaggertype:"string"`
}

type SignatureConfiguration

type SignatureConfiguration struct {
	Header   config.SignatureHeaderProvider `json:"header,omitempty" valid:"required~please provide a valid signature header"`
	Versions []SignatureVersion             `json:"versions" bson:"versions"`

	Hash string `json:"-" bson:"hash"`
}

func GetDefaultSignatureConfig

func GetDefaultSignatureConfig() *SignatureConfiguration

type SignatureVersion

type SignatureVersion struct {
	UID       string             `json:"uid" bson:"uid"`
	Hash      string             `json:"hash,omitempty" valid:"required~please provide a valid hash,supported_hash~unsupported hash type"`
	Encoding  EncodingType       `json:"encoding" bson:"encoding" valid:"required~please provide a valid signature header"`
	CreatedAt primitive.DateTime `json:"created_at,omitempty" bson:"created_at,omitempty" swaggertype:"string"`
}

type Source

type Source struct {
	ID             primitive.ObjectID `json:"-" bson:"_id"`
	UID            string             `json:"uid" bson:"uid"`
	ProjectID      string             `json:"project_id" bson:"project_id"`
	MaskID         string             `json:"mask_id" bson:"mask_id"`
	Name           string             `json:"name" bson:"name"`
	Type           SourceType         `json:"type" bson:"type"`
	Provider       SourceProvider     `json:"provider" bson:"provider"`
	IsDisabled     bool               `json:"is_disabled" bson:"is_disabled"`
	Verifier       *VerifierConfig    `json:"verifier" bson:"verifier"`
	ProviderConfig *ProviderConfig    `json:"provider_config" bson:"provider_config"`
	ForwardHeaders []string           `json:"forward_headers" bson:"forward_headers"`

	CreatedAt primitive.DateTime  `json:"created_at,omitempty" bson:"created_at" swaggertype:"string"`
	UpdatedAt primitive.DateTime  `json:"updated_at,omitempty" bson:"updated_at" swaggertype:"string"`
	DeletedAt *primitive.DateTime `json:"deleted_at,omitempty" bson:"deleted_at" swaggertype:"string"`
}

type SourceFilter

type SourceFilter struct {
	Type     string
	Provider string
}

type SourceProvider

type SourceProvider string
const (
	GithubSourceProvider  SourceProvider = "github"
	TwitterSourceProvider SourceProvider = "twitter"
	ShopifySourceProvider SourceProvider = "shopify"
)

func (SourceProvider) IsValid

func (s SourceProvider) IsValid() bool

type SourceRepository

type SourceRepository interface {
	CreateSource(context.Context, *Source) error
	UpdateSource(ctx context.Context, projectID string, source *Source) error
	FindSourceByID(ctx context.Context, projectID string, id string) (*Source, error)
	FindSourceByName(ctx context.Context, projectId string, name string) (*Source, error)
	FindSourceByMaskID(ctx context.Context, maskID string) (*Source, error)
	DeleteSourceByID(ctx context.Context, projectID string, id string) error
	LoadSourcesPaged(ctx context.Context, projectID string, filter *SourceFilter, pageable Pageable) ([]Source, PaginationData, error)
}

type SourceType

type SourceType string
const (
	HTTPSource     SourceType = "http"
	RestApiSource  SourceType = "rest_api"
	PubSubSource   SourceType = "pub_sub"
	DBChangeStream SourceType = "db_change_stream"
)

func (SourceType) IsValid

func (s SourceType) IsValid() bool

type StoragePolicyConfiguration

type StoragePolicyConfiguration struct {
	Type   StorageType    `json:"type,omitempty" bson:"type" valid:"supported_storage~please provide a valid storage type,required"`
	S3     *S3Storage     `json:"s3" bson:"s3"`
	OnPrem *OnPremStorage `json:"on_prem" bson:"on_prem"`
}

type StorageType

type StorageType string
const (
	S3     StorageType = "s3"
	OnPrem StorageType = "on_prem"
)

type Store

type Store interface {
	Save(ctx context.Context, payload interface{}, result interface{}) error
	SaveMany(ctx context.Context, payload []interface{}) error

	FindByID(ctx context.Context, id string, projection bson.M, result interface{}) error
	FindOne(ctx context.Context, filter, projection bson.M, result interface{}) error
	FindMany(ctx context.Context, filter, projection bson.M, sort interface{}, lastID primitive.ObjectID, limit int64, results interface{}) error
	FindManyWithDeletedAt(ctx context.Context, filter, projection bson.M, sort interface{}, limit, skip int64, results interface{}) error
	FindAll(ctx context.Context, filter bson.M, sort interface{}, projection, results interface{}) error

	UpdateByID(ctx context.Context, id string, payload interface{}) error
	UpdateOne(ctx context.Context, filter bson.M, payload interface{}) error
	UpdateMany(ctx context.Context, filter, payload bson.M, bulk bool) error

	Inc(ctx context.Context, filter bson.M, payload interface{}) error

	DeleteByID(ctx context.Context, id string, hardDelete bool) error
	DeleteOne(ctx context.Context, filter bson.M, hardDelete bool) error
	DeleteMany(ctx context.Context, filter, payload bson.M, hardDelete bool) error

	Count(ctx context.Context, filter map[string]interface{}) (int64, error)
	CountWithDeleted(ctx context.Context, filter map[string]interface{}) (int64, error)

	Aggregate(ctx context.Context, pipeline mongo.Pipeline, result interface{}, allowDiskUse bool) error
	WithTransaction(ctx context.Context, fn func(sessCtx mongo.SessionContext) error) error
}

func New

func New(database *mongo.Database) Store

* New * This initialises a new MongoDB repo for the collection

type StrategyConfiguration

type StrategyConfiguration struct {
	Type       StrategyProvider `json:"type" valid:"optional~please provide a valid strategy type, in(linear|exponential)~unsupported strategy type"`
	Duration   uint64           `json:"duration" valid:"optional~please provide a valid duration in seconds,int"`
	RetryCount uint64           `json:"retry_count" valid:"optional~please provide a valid retry count,int"`
}

type StrategyProvider

type StrategyProvider string

type Subscription

type Subscription struct {
	ID         primitive.ObjectID `json:"-" bson:"_id"`
	UID        string             `json:"uid" bson:"uid"`
	Name       string             `json:"name" bson:"name"`
	Type       SubscriptionType   `json:"type" bson:"type"`
	ProjectID  string             `json:"-" bson:"project_id"`
	SourceID   string             `json:"-" bson:"source_id"`
	EndpointID string             `json:"-" bson:"endpoint_id"`
	DeviceID   string             `json:"device_id" bson:"device_id"`

	Source   *Source   `json:"source_metadata" bson:"source_metadata"`
	Endpoint *Endpoint `json:"endpoint_metadata" bson:"endpoint_metadata"`

	// subscription config
	AlertConfig     *AlertConfiguration     `json:"alert_config,omitempty" bson:"alert_config,omitempty"`
	RetryConfig     *RetryConfiguration     `json:"retry_config,omitempty" bson:"retry_config,omitempty"`
	FilterConfig    *FilterConfiguration    `json:"filter_config,omitempty" bson:"filter_config,omitempty"`
	RateLimitConfig *RateLimitConfiguration `json:"rate_limit_config,omitempty" bson:"rate_limit_config,omitempty"`

	CreatedAt primitive.DateTime  `json:"created_at,omitempty" bson:"created_at" swaggertype:"string"`
	UpdatedAt primitive.DateTime  `json:"updated_at,omitempty" bson:"updated_at" swaggertype:"string"`
	DeletedAt *primitive.DateTime `json:"deleted_at,omitempty" bson:"deleted_at" swaggertype:"string"`
}

type SubscriptionFilter

type SubscriptionFilter struct {
	ID        primitive.ObjectID     `json:"-" bson:"_id"`
	UID       string                 `json:"uid" bson:"uid"`
	Filter    map[string]interface{} `json:"filter" bson:"filter"`
	DeletedAt *primitive.DateTime    `json:"deleted_at,omitempty" bson:"deleted_at"`
}

type SubscriptionRepository

type SubscriptionRepository interface {
	CreateSubscription(context.Context, string, *Subscription) error
	UpdateSubscription(context.Context, string, *Subscription) error
	LoadSubscriptionsPaged(context.Context, string, *FilterBy, Pageable) ([]Subscription, PaginationData, error)
	DeleteSubscription(context.Context, string, *Subscription) error
	FindSubscriptionByID(context.Context, string, string) (*Subscription, error)
	FindSubscriptionsByEventType(context.Context, string, string, EventType) ([]Subscription, error)
	FindSubscriptionsBySourceID(context.Context, string, string) ([]Subscription, error)
	FindSubscriptionsByEndpointID(ctx context.Context, projectId string, endpointID string) ([]Subscription, error)
	FindSubscriptionByDeviceID(ctx context.Context, projectId string, deviceID string, subscriptionType SubscriptionType) (*Subscription, error)
	FindCLISubscriptions(ctx context.Context, projectID string) ([]Subscription, error)
	TestSubscriptionFilter(ctx context.Context, payload map[string]interface{}, filter map[string]interface{}) (bool, error)
}

type SubscriptionType

type SubscriptionType string
const (
	SubscriptionTypeCLI SubscriptionType = "cli"
	SubscriptionTypeAPI SubscriptionType = "api"
)

type TwitterProviderConfig

type TwitterProviderConfig struct {
	CrcVerifiedAt primitive.DateTime `json:"crc_verified_at" bson:"crc_verified_at"`
}

type User

type User struct {
	ID                         primitive.ObjectID  `json:"-" bson:"_id"`
	UID                        string              `json:"uid" bson:"uid"`
	FirstName                  string              `json:"first_name" bson:"first_name"`
	LastName                   string              `json:"last_name" bson:"last_name"`
	Email                      string              `json:"email" bson:"email"`
	EmailVerified              bool                `json:"email_verified" bson:"email_verified"`
	Password                   string              `json:"-" bson:"password"`
	Role                       auth.Role           `json:"role" bson:"role"`
	ResetPasswordToken         string              `json:"-" bson:"reset_password_token"`
	EmailVerificationToken     string              `json:"-" bson:"email_verification_token"`
	CreatedAt                  primitive.DateTime  `json:"created_at,omitempty" bson:"created_at,omitempty" swaggertype:"string"`
	UpdatedAt                  primitive.DateTime  `json:"updated_at,omitempty" bson:"updated_at,omitempty" swaggertype:"string"`
	DeletedAt                  *primitive.DateTime `json:"deleted_at,omitempty" bson:"deleted_at" swaggertype:"string"`
	ResetPasswordExpiresAt     primitive.DateTime  `json:"reset_password_expires_at,omitempty" bson:"reset_password_expires_at,omitempty" swaggertype:"string"`
	EmailVerificationExpiresAt primitive.DateTime  `json:"-" bson:"email_verification_expires_at,omitempty" swaggertype:"string"`
}

type UserMetadata

type UserMetadata struct {
	UserID    string `json:"-" bson:"user_id"`
	FirstName string `json:"first_name" bson:"first_name"`
	LastName  string `json:"last_name" bson:"last_name"`
	Email     string `json:"email" bson:"email"`
}

type UserRepository

type UserRepository interface {
	CreateUser(context.Context, *User) error
	UpdateUser(ctx context.Context, user *User) error
	FindUserByEmail(context.Context, string) (*User, error)
	FindUserByID(context.Context, string) (*User, error)
	FindUserByToken(context.Context, string) (*User, error)
	FindUserByEmailVerificationToken(ctx context.Context, token string) (*User, error)
	LoadUsersPaged(context.Context, Pageable) ([]User, PaginationData, error)
}

type VerifierConfig

type VerifierConfig struct {
	Type      VerifierType `json:"type,omitempty" bson:"type" valid:"supported_verifier~please provide a valid verifier type,required"`
	HMac      *HMac        `json:"hmac" bson:"hmac"`
	BasicAuth *BasicAuth   `json:"basic_auth" bson:"basic_auth"`
	ApiKey    *ApiKey      `json:"api_key" bson:"api_key"`
}

type VerifierType

type VerifierType string
const (
	NoopVerifier      VerifierType = "noop"
	HMacVerifier      VerifierType = "hmac"
	BasicAuthVerifier VerifierType = "basic_auth"
	APIKeyVerifier    VerifierType = "api_key"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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