storagemongodb

package module
v0.0.0-...-0308431 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2021 License: Apache-2.0 Imports: 27 Imported by: 0

README

caddy-mongodb

Documentation

Index

Constants

View Source
const (
	// InactiveLockDuration is when the lock is considered as stale and need to be refreshed
	InactiveLockDuration = 4 * time.Hour

	// LockDuration is lock time duration in seconds
	LockDuration = 600

	// ScanCount is how many scan command might return
	ScanCount int64 = 100

	// DefaultAESKey needs to be 32 bytes long
	DefaultAESKey = ""

	// DefaultKeyPrefix defines the default prefix in KV store
	DefaultKeyPrefix = "caddytls"

	// DefaultValuePrefix sets a prefix to KV values to check validation
	DefaultValuePrefix = "caddy-storage-MongoDb"

	// DefaultMongoDbHost define the MongoDb instance host
	DefaultMongoDbHost = "127.0.0.1"

	// DefaultMongoDbPort define the MongoDb instance port
	DefaultMongoDbPort = "27017"

	// DefaultDatabase define the mongo database
	DefaultMongoDbDatabase = "caddycerts"

	// DefaultCollection define the mongo database collection
	DefaultMongoDbBucket = "caddycollection"

	// DefaultMongoDbPassword define the MongoDb instance Username, if any
	DefaultMongoDbUsername = ""

	// DefaultMongoDbPassword define the MongoDb instance password, if any
	DefaultMongoDbPassword = ""

	// DefaultMongoDbTimeout define the MongoDb wait time in (s)
	DefaultMongoDbTimeout = 5

	// DefaultMongoDbTLS define the MongoDb TLS connection
	DefaultMongoDbTLS = false

	// DefaultMongoDbTLSInsecure define the MongoDb TLS connection
	DefaultMongoDbTLSInsecure = true

	// EnvNameMongoDbHost defines the env variable name to override MongoDb host
	EnvNameMongoDbHost = "CADDY_CLUSTERING_MONGODB_HOST"

	// EnvNameMongoDBPort defines the env variable name to override MongoDb port
	EnvNameMongoDBPort = "CADDY_CLUSTERING_MONGODB_PORT"

	// EnvNameMongoDBDatabase defines the env variable name to override MongoDb db number
	EnvNameMongoDBDatabase = "CADDY_CLUSTERING_MONGODB_DB"

	// EnvNameMongoDBBucketName define the env variable name to
	EnvNameMongoDBBucketName = "CADDY_CLUSTERING_MONGODB_BUCKET_NAME"

	// EnvNameMongoDbUsername defines the env variable name to override MongoDb username
	EnvNameMongoDbUsername = "CADDY_CLUSTERING_MONGODB_USERNAME"

	// EnvNameMongoDbPassword defines the env variable name to override MongoDb password
	EnvNameMongoDbPassword = "CADDY_CLUSTERING_MONGODB_PASSWORD"

	// EnvNameMongoDbTimeout defines the env variable name to override MongoDb wait timeout for dial, read, write
	EnvNameMongoDbTimeout = "CADDY_CLUSTERING_MONGODB_TIMEOUT"

	// EnvNameAESKey defines the env variable name to override AES key
	EnvNameAESKey = "CADDY_CLUSTERING_MONGODB_AESKEY"

	// EnvNameKeyPrefix defines the env variable name to override KV key prefix
	EnvNameKeyPrefix = "CADDY_CLUSTERING_MONGODB_KEYPREFIX"

	// EnvNameValuePrefix defines the env variable name to override KV value prefix
	EnvNameValuePrefix = "CADDY_CLUSTERING_MONGODB_VALUEPREFIX"

	// EnvNameTLSEnabled defines the env variable name to whether enable MongoDb TLS Connection or not
	EnvNameTLSEnabled = "CADDY_CLUSTERING_MONGODB_TLS"

	// EnvNameTLSInsecure defines the env variable name to whether verify MongoDb TLS Connection or not
	EnvNameTLSInsecure = "CADDY_CLUSTERING_MONGODB_TLS_INSECURE"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type StorageData

type StorageData struct {
	Value    []byte    `json:"value"`
	Modified time.Time `json:"modified"`
}

StorageData describe the data that is stored in KV storage

type StorageMongodb

type StorageMongodb struct {
	ClientMongo *mongo.Client

	Logger *zap.SugaredLogger

	IPAddress net.IP

	Host         string `json:"host"`
	Username     string `json:"username"`
	Password     string `json:"password"`
	Port         string `json:"port"`
	DataBaseName string `json:"database"`
	BucketName   string `json:"bucket"`
	Timeout      int    `json:"timeout"`
	KeyPrefix    string `json:"key_prefix"`
	ValuePrefix  string `json:"value_prefix"`
	AesKey       string `json:"aes_key"`
	TlsEnabled   bool   `json:"tls_enabled"`
	TlsInsecure  bool   `json:"tls_insecure"`
	// contains filtered or unexported fields
}

StorageMongodb contain MongoDb client, and plugin option

func (*StorageMongodb) BuildMongoDbClient

func (rd *StorageMongodb) BuildMongoDbClient() error

*

  • Build a new mongo client, and connect the client to use. The client has a timeout of 10 seconds for operations

func (StorageMongodb) CaddyModule

func (StorageMongodb) CaddyModule() caddy.ModuleInfo

register caddy module with ID caddy.storage.MongoDb

func (*StorageMongodb) CertMagicStorage

func (rd *StorageMongodb) CertMagicStorage() (certmagic.Storage, error)

CertMagicStorage converts s to a certmagic.Storage instance.

func (*StorageMongodb) DecryptStorageData

func (rd *StorageMongodb) DecryptStorageData(bytes []byte) (*StorageData, error)

DecryptStorageData decrypt storage data, so we can read it

func (StorageMongodb) Delete

func (rd StorageMongodb) Delete(key string) error

Delete deletes key.

func (*StorageMongodb) EncryptStorageData

func (rd *StorageMongodb) EncryptStorageData(data *StorageData) ([]byte, error)

EncryptStorageData encrypt storage data, so it won't be plain data

func (StorageMongodb) Exists

func (rd StorageMongodb) Exists(key string) bool

Exists returns true if the key exists

func (*StorageMongodb) GetAESKeyByte

func (rd *StorageMongodb) GetAESKeyByte() []byte

*

  • Regresa la llave para encriptacion como un arreglo de bytes

func (*StorageMongodb) GetConfigValue

func (rd *StorageMongodb) GetConfigValue()

GetConfigValue get Config value from env, if already been set by Caddyfile, don't overwrite

func (StorageMongodb) GetOutboundIP

func (rd StorageMongodb) GetOutboundIP() net.IP

*

  • Recupera la direccion ip utilizada para conectarse al exteriror

func (StorageMongodb) List

func (rd StorageMongodb) List(prefix string, recursive bool) ([]string, error)

List returns all keys that match prefix.

func (StorageMongodb) Load

func (rd StorageMongodb) Load(key string) ([]byte, error)

Load retrieves the value at key.

func (StorageMongodb) Lock

func (rd StorageMongodb) Lock(ctx context.Context, key string) error

Lock is to lock value

func (*StorageMongodb) Provision

func (rd *StorageMongodb) Provision(ctx caddy.Context) error

func (StorageMongodb) Stat

func (rd StorageMongodb) Stat(key string) (certmagic.KeyInfo, error)

Stat returns information about key.

func (StorageMongodb) Store

func (rd StorageMongodb) Store(key string, value []byte) error

Store values at key

func (StorageMongodb) String

func (rd StorageMongodb) String() string

func (StorageMongodb) Unlock

func (rd StorageMongodb) Unlock(key string) error

Unlock is to unlock value

func (*StorageMongodb) UnmarshalCaddyfile

func (rd *StorageMongodb) UnmarshalCaddyfile(d *caddyfile.Dispenser) error

Jump to

Keyboard shortcuts

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