mongodb

package
v0.12.1 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2024 License: BSD-3-Clause Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsDuplicate

func IsDuplicate(err error) bool

IsDuplicate returns true if error indicates index duplicate key error

func Sanitize

func Sanitize(s string) string

Sanitize sanitizes for mongo input

Types

type CmsIntegrator

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

CmsIntegrator integrator function implementation with mongoDB persistence

func NewCmsIntegrator

func NewCmsIntegrator(sessionProvider *SessionProvider, keySize int) (*CmsIntegrator, error)

NewCmsIntegrator creates CmsIntegrator instance

func (*CmsIntegrator) AddCredits

func (ss *CmsIntegrator) AddCredits(keyID string, input *api.CreditsInput) (*api.Key, error)

AddCredits to the key

func (*CmsIntegrator) Change

func (ss *CmsIntegrator) Change(keyID string) (*api.Key, error)

Change generates new key for keyID, disables the old one, returns new key

func (*CmsIntegrator) Changes

func (ss *CmsIntegrator) Changes(from *time.Time, services []string) (*api.Changes, error)

Changes returns changed keys information

func (*CmsIntegrator) Create

func (ss *CmsIntegrator) Create(input *api.CreateInput) (*api.Key, bool, error)

Create creates new key

func (*CmsIntegrator) GetKey

func (ss *CmsIntegrator) GetKey(keyID string) (*api.Key, error)

GetKey by ID

func (*CmsIntegrator) GetKeyID

func (ss *CmsIntegrator) GetKeyID(key string) (*api.KeyID, error)

GetKeyID returns keyID by key value

func (*CmsIntegrator) Update

func (ss *CmsIntegrator) Update(keyID string, input map[string]interface{}) (*api.Key, error)

Update updates key table fields

func (*CmsIntegrator) Usage

func (ss *CmsIntegrator) Usage(keyID string, from, to *time.Time, full bool) (*api.Usage, error)

Usage returns usage information for the key

type DBProvider

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

DBProvider keeps SessionProvider and database for mongo DB

func NewDBProvider

func NewDBProvider(sessionP SProvider, db string) (*DBProvider, error)

NewDBProvider creates Mongo session provider and opens client with selected db

func (*DBProvider) NewSesionDatabase

func (sdp *DBProvider) NewSesionDatabase() (mongo.Session, *mongo.Database, error)

NewSesionDatabase creates mongo session and databse

type IPSaver

type IPSaver struct {
	SessionProvider *DBProvider
}

IPSaver validates saves ip into DB

func NewIPSaver

func NewIPSaver(sessionProvider *DBProvider) (*IPSaver, error)

NewIPSaver creates IPSaver instance

func (*IPSaver) CheckCreate

func (ss *IPSaver) CheckCreate(ip string, limit float64) error

CheckCreate new key record if no exist

type IndexData

type IndexData struct {
	Table  string
	Fields []string
	Unique bool
}

IndexData keeps index creation data

type KeySaver

type KeySaver struct {
	SessionProvider *SessionProvider
	NewKeySize      int
}

KeySaver saves keys to mongo db

func NewKeySaver

func NewKeySaver(sessionProvider *SessionProvider, keySize int) (*KeySaver, error)

NewKeySaver creates KeySaver instance

func (*KeySaver) Create

func (ss *KeySaver) Create(project string, key *adminapi.Key) (*adminapi.Key, error)

Create key to DB

func (*KeySaver) Get

func (ss *KeySaver) Get(project string, key string) (*adminapi.Key, error)

Get return one key record

func (*KeySaver) List

func (ss *KeySaver) List(project string) ([]*adminapi.Key, error)

List return all keys

func (*KeySaver) RestoreUsage

func (ss *KeySaver) RestoreUsage(project string, manual bool, requestID string, errMsg string) error

RestoreUsage erstores usage by requestID

func (*KeySaver) Update

func (ss *KeySaver) Update(project string, key string, data map[string]interface{}) (*adminapi.Key, error)

Update update key record

type KeyValidator

type KeyValidator struct {
	SessionProvider *DBProvider
}

KeyValidator validates key in mongo db

func NewKeyValidator

func NewKeyValidator(sessionProvider *DBProvider) (*KeyValidator, error)

NewKeyValidator creates KeyValidator instance

func (*KeyValidator) IsValid

func (ss *KeyValidator) IsValid(key string, IP string, manual bool) (bool, string, []string, error)

IsValid validates key

func (*KeyValidator) Restore

func (ss *KeyValidator) Restore(key string, manual bool, qv float64) (float64, float64, error)

Restore restores quota value after failed service call

func (*KeyValidator) SaveValidate

func (ss *KeyValidator) SaveValidate(key string, ip string, manual bool, qv float64) (bool, float64, float64, error)

SaveValidate add qv to quota and validates with quota limit

type LogProvider

type LogProvider struct {
	SessionProvider *SessionProvider
}

LogProvider retrieves the log

func NewLogProvider

func NewLogProvider(sessionProvider *SessionProvider) (*LogProvider, error)

NewLogProvider creates LogProvider instance

func (*LogProvider) Delete

func (ss *LogProvider) Delete(project string, to time.Time) (int, error)

func (*LogProvider) Get

func (ss *LogProvider) Get(project, key string) ([]*adminapi.Log, error)

Get return all logs for key

func (*LogProvider) List

func (ss *LogProvider) List(project string, to time.Time) ([]*adminapi.Log, error)

type LogSaver

type LogSaver struct {
	SessionProvider *DBProvider
}

LogSaver saves log info to mongo db

func NewLogSaver

func NewLogSaver(sessionProvider *DBProvider) (*LogSaver, error)

NewLogSaver creates LogSaver instance

func (*LogSaver) Save

func (ss *LogSaver) Save(log *adminapi.Log) error

Save log key to DB

type Reseter

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

Reseter resets monthly usage

func NewReseter

func NewReseter(sessionProvider *SessionProvider) (*Reseter, error)

NewReseter creates Reseter instance

func (*Reseter) Reset

func (ss *Reseter) Reset(ctx context.Context, project string, since time.Time, limit float64) error

Reset does monthly reset

type SProvider

type SProvider interface {
	NewSession() (mongo.Session, error)
	CheckIndexes(dbs []string) error
}

SProvider session provider wrapper

type SessionProvider

type SessionProvider struct {
	URL string
	// contains filtered or unexported fields
}

SessionProvider connects and provides session for mongo DB

func NewSessionProvider

func NewSessionProvider(url string) (*SessionProvider, error)

NewSessionProvider creates Mongo session provider

func (*SessionProvider) CheckIndexes

func (sp *SessionProvider) CheckIndexes(dbs []string) error

CheckIndexes tries to create indexes in db if not exists

func (*SessionProvider) Close

func (sp *SessionProvider) Close()

Close closes mongo session

func (*SessionProvider) Healthy

func (sp *SessionProvider) Healthy() error

Healthy checks if mongo DB is up

func (*SessionProvider) NewSession

func (sp *SessionProvider) NewSession() (mongo.Session, error)

NewSession creates mongo session

Jump to

Keyboard shortcuts

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