config

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package config defines configurable values shared between Source and Destination and implements a method to parse them.

Index

Constants

View Source
const (
	// KeyURI is a config name for a connection string.
	KeyURI = "uri"
	// KeyDB is a config name for a database.
	KeyDB = "db"
	// KeyCollection is a config name for a collection.
	KeyCollection = "collection"
	// KeyAuthUsername is a config name for a username.
	KeyAuthUsername = "auth.username"
	// KeyAuthPassword is a config name for a password.
	KeyAuthPassword = "auth.password"
	// KeyAuthDB is a config name for an authentication database.
	KeyAuthDB = "auth.db"
	// KeyAuthMechanism is a config name for an authentication mechanism.
	KeyAuthMechanism = "auth.mechanism"
	// KeyAuthTLSCAFile is a config name for a TLS CA file.
	KeyAuthTLSCAFile = "auth.tls.caFile"
	// KeyAuthTLSCertificateKeyFile is a config name for a TLS certificate key file.
	KeyAuthTLSCertificateKeyFile = "auth.tls.certificateKeyFile"
	// KeyAuthAWSSessionToken is a config name for an AWS session token.
	KeyAuthAWSSessionToken = "auth.awsSessionToken" //nolint:gosec // it's not hardcoded credential

)

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthConfig

type AuthConfig struct {
	// Username is the username.
	Username string `key:"auth.username"`
	// Password is the user's password.
	Password string `key:"auth.password"`
	// DB is the name of a database that contains
	// the user's authentication data.
	DB string `key:"auth.db"`
	// Mechanism is the authentication mechanism.
	Mechanism AuthMechanism `key:"auth.mechanism"`
	// TLSCAFile is the path to either a single or a bundle of
	// certificate authorities to trust when making a TLS connection.
	TLSCAFile string `key:"auth.tls.caFile" validate:"omitempty,file"`
	// TLSCertificateKeyFile is the path to the client certificate
	// file or the client private key file.
	TLSCertificateKeyFile string `key:"auth.tls.certificateKeyFile" validate:"omitempty,file"`
	// AWSSessionToken is an AWS session token.
	AWSSessionToken string `key:"auth.awsSessionToken"`
}

AuthConfig contains authentication-specific configurable values.

type AuthMechanism

type AuthMechanism string

AuthMechanism defines a MongoDB authentication mechanism.

const (
	SCRAMSHA256 AuthMechanism = "SCRAM-SHA-256"
	SCRAMSHA1   AuthMechanism = "SCRAM-SHA-1"
	MongoDBCR   AuthMechanism = "MONGODB-CR"
	MongoDBAWS  AuthMechanism = "MONGODB-AWS"
	MongoDBX509 AuthMechanism = "MONGODB-X509"
)

The list of available authentication mechanisms is listed below.

func (AuthMechanism) IsValid

func (am AuthMechanism) IsValid() bool

IsValid checks if the underlying AuthMechanism is valid.

type Config

type Config struct {
	// URI is the connection string.
	// The URI can contain host names, IPv4/IPv6 literals, or an SRV record.
	URI *url.URL
	// DB is the name of a database the connector must work with.
	DB string `key:"db" validate:"required,max=64"`
	// Collection is the name of a collection the connector must
	// write to (destination) or read from (source).
	Collection string `key:"collection" validate:"required"`

	Auth AuthConfig
}

Config contains configurable values shared between source and destination MongoDB connector.

func Parse

func Parse(raw map[string]string) (Config, error)

Parse maps the incoming map to the Config and validates it.

func (*Config) GetClientOptions

func (d *Config) GetClientOptions() *options.ClientOptions

GetClientOptions returns generated options for mongo connection depending on mechanism.

type InvalidAuthMechanismError

type InvalidAuthMechanismError struct {
	AuthMechanism AuthMechanism
}

InvalidAuthMechanismError occurs when a string is not a valid AuthMechanism.

func (*InvalidAuthMechanismError) Error

func (e *InvalidAuthMechanismError) Error() string

Error returns a formatted error message for the InvalidAuthMechanismError.

Jump to

Keyboard shortcuts

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