options

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package options implements command-line options that are used by all of the mongo tools.

Index

Constants

View Source
const IncompatibleArgsErrorFormat = "illegal argument combination: cannot specify %s and --uri"

Variables

View Source
var (
	BuiltWithSSL    = true
	BuiltWithGSSAPI = true
)

XXX Force these true as the Go driver supports them always. Once the conditionals that depend on them are removed, these can be removed.

View Source
var ConnectionOptFunctions []OptionRegistrationFunction

Functions

func ConflictingArgsErrorFormat

func ConflictingArgsErrorFormat(optionName, uriValue, cliValue, cliOptionName string) error

func EnableFailpoints

func EnableFailpoints(opts *ToolOptions)

EnableFailpoints removes the failpoints options

func LogSensitiveOptionWarnings

func LogSensitiveOptionWarnings(args []string)

LogSensitiveOptionWarnings logs a warning for any sensitive information (i.e. passwords) that appear on the command line for the --password, --uri and --sslPEMKeyPassword options. This also applies to a connection string that appears as a positional argument.

Types

type Auth

type Auth struct {
	Username        string `short:"u" value-name:"<username>" long:"username" description:"username for authentication"`
	Password        string `short:"p" value-name:"<password>" long:"password" description:"password for authentication"`
	Source          string `long:"authenticationDatabase" value-name:"<database-name>" description:"database that holds the user's credentials"`
	Mechanism       string `long:"authenticationMechanism" value-name:"<mechanism>" description:"authentication mechanism to use"`
	AWSSessionToken string `long:"awsSessionToken" value-name:"<aws-session-token>" description:"session token to authenticate via AWS IAM"`
}

Struct holding auth-related options

func (*Auth) IsSet

func (auth *Auth) IsSet() bool

func (*Auth) RequiresExternalDB

func (auth *Auth) RequiresExternalDB() bool

func (*Auth) ShouldAskForPassword

func (auth *Auth) ShouldAskForPassword() bool

ShouldAskForPassword returns true if the user specifies a username flag but no password, and the authentication mechanism requires a password.

type Connection

type Connection struct {
	Host string `short:"h" long:"host" value-name:"<hostname>" description:"mongodb host to connect to (setname/host1,host2 for replica sets)"`
	Port string `long:"port" value-name:"<port>" description:"server port (can also use --host hostname:port)"`

	Timeout                int    `long:"dialTimeout" default:"3" hidden:"true" description:"dial timeout in seconds"`
	SocketTimeout          int    `long:"socketTimeout" default:"0" hidden:"true" description:"socket timeout in seconds (0 for no timeout)"`
	TCPKeepAliveSeconds    int    `long:"TCPKeepAliveSeconds" default:"30" hidden:"true" description:"seconds between TCP keep alives"`
	ServerSelectionTimeout int    `long:"serverSelectionTimeout" hidden:"true" description:"seconds to wait for server selection; 0 means driver default"`
	Compressors            string `` /* 157-byte string literal not displayed */
}

Struct holding connection-related options

type DestinationAuthOptions

type DestinationAuthOptions interface {
	// Set the password for authentication on the destination.
	SetDestinationPassword(string)
}

Interface for extra options used in mongomirror.

type EnabledOptions

type EnabledOptions struct {
	Auth       bool
	Connection bool
	Namespace  bool
	URI        bool
}

type ExtraOptions

type ExtraOptions interface {
	// Name specifying what type of options these are
	Name() string
}

Interface for extra options that need to be used by specific tools

type General

type General struct {
	Help       bool   `long:"help" description:"print usage"`
	Version    bool   `long:"version" description:"print the tool version and exit"`
	ConfigPath string `long:"config" description:"path to a configuration file"`

	MaxProcs   int    `long:"numThreads" hidden:"true"`
	Failpoints string `long:"failpoints" hidden:"true"`
	Trace      bool   `long:"trace" hidden:"true"`
}

Struct holding generic options

type Kerberos

type Kerberos struct {
	Service     string `` /* 147-byte string literal not displayed */
	ServiceHost string `` /* 155-byte string literal not displayed */
}

Struct for Kerberos/GSSAPI-specific options

type Namespace

type Namespace struct {
	// Specified database and collection
	DB         string `short:"d" long:"db" value-name:"<database-name>" description:"database to use"`
	Collection string `short:"c" long:"collection" value-name:"<collection-name>" description:"collection to use"`
}

func (Namespace) String

func (ns Namespace) String() string

type OptionRegistrationFunction

type OptionRegistrationFunction func(*ToolOptions) error

type SSL

type SSL struct {
	UseSSL              bool   `long:"ssl" description:"connect to a mongod or mongos that has ssl enabled"`
	SSLCAFile           string `` /* 137-byte string literal not displayed */
	SSLPEMKeyFile       string `long:"sslPEMKeyFile" value-name:"<filename>" description:"the .pem file containing the certificate and key"`
	SSLPEMKeyPassword   string `long:"sslPEMKeyPassword" value-name:"<password>" description:"the password to decrypt the sslPEMKeyFile, if necessary"`
	SSLCRLFile          string `long:"sslCRLFile" value-name:"<filename>" description:"the .pem file containing the certificate revocation list"`
	SSLAllowInvalidCert bool   `long:"sslAllowInvalidCertificates" hidden:"true" description:"bypass the validation for server certificates"`
	SSLAllowInvalidHost bool   `long:"sslAllowInvalidHostnames" hidden:"true" description:"bypass the validation for server name"`
	SSLFipsMode         bool   `long:"sslFIPSMode" description:"use FIPS mode of the installed openssl library"`
	TLSInsecure         bool   `long:"tlsInsecure" description:"bypass the validation for server's certificate chain and host name"`
}

Struct holding ssl-related options

func (*SSL) ShouldAskForPassword

func (ssl *SSL) ShouldAskForPassword() (bool, error)

ShouldAskForPassword returns true if the user specifies a ssl pem key file flag but no password for that file, and the key file has any encrypted blocks.

type ToolOptions

type ToolOptions struct {

	// The name of the tool
	AppName string

	// The version of the tool
	VersionStr string

	// The git commit reference of the tool
	GitCommit string

	// Sub-option types
	*URI
	*General
	*Verbosity
	*Connection
	*SSL
	*Auth
	*Kerberos
	*Namespace

	// Force direct connection to the server and disable the
	// drivers automatic repl set discovery logic.
	Direct bool

	// ReplicaSetName, if specified, will prevent the obtained session from
	// communicating with any server which is not part of a replica set
	// with the given name. The default is to communicate with any server
	// specified or discovered via the servers contacted.
	ReplicaSetName string

	// ReadPreference, if specified, sets the client default
	ReadPreference *readpref.ReadPref

	// WriteConcern, if specified, sets the client default
	WriteConcern *writeconcern.WriteConcern

	// RetryWrites, if specified, sets the client default.
	RetryWrites *bool
	// contains filtered or unexported fields
}

Struct encompassing all of the options that are reused across tools: "help", "version", verbosity settings, ssl settings, etc.

func New

func New(appName, versionStr, gitCommit, usageStr string, parsePositionalArgsAsURI bool, enabled EnabledOptions) *ToolOptions

Ask for a new instance of tool options

func (*ToolOptions) AddOptions

func (opts *ToolOptions) AddOptions(extraOpts ExtraOptions)

AddOptions registers an additional options group to this instance

func (*ToolOptions) AddToExtraOptionsRegistry

func (opts *ToolOptions) AddToExtraOptionsRegistry(extraOpts ExtraOptions)

AddToExtraOptionsRegistry appends an additional options group to the extra options registry found in opts.URI.

func (*ToolOptions) CallArgParser

func (opts *ToolOptions) CallArgParser(args []string) ([]string, error)

func (*ToolOptions) EnabledToolOptions

func (opts *ToolOptions) EnabledToolOptions() EnabledOptions

func (*ToolOptions) FindOptionByLongName

func (opts *ToolOptions) FindOptionByLongName(name string) *flags.Option

FindOptionByLongName finds an option in any of the added option groups by matching its long name; useful for modifying the attributes (e.g. description or name) of an option

func (*ToolOptions) GetAuthenticationDatabase

func (opts *ToolOptions) GetAuthenticationDatabase() string

Get the authentication database to use. Should be the value of --authenticationDatabase if it's provided, otherwise, the database that's specified in the tool's --db arg.

func (*ToolOptions) NormalizeOptionsAndURI

func (opts *ToolOptions) NormalizeOptionsAndURI() error

NormalizeOptionsAndURI syncs the connection string and toolOptions objects. It returns an error if there is any conflict between options and the connection string. If a value is set on the options, but not the connection string, that value is added to the connection string. If a value is set on the connection string, but not the options, that value is added to the options.

func (*ToolOptions) ParseArgs

func (opts *ToolOptions) ParseArgs(args []string) ([]string, error)

ParseArgs parses a potential config file followed by the command line args, overriding any values in the config file. Returns any extra args not accounted for by parsing, as well as an error if the parsing returns an error.

func (*ToolOptions) ParseConfigFile

func (opts *ToolOptions) ParseConfigFile(args []string) error

ParseConfigFile iterates over args to find a --config option. If not found, we return. If found, we read the contents of the specified config file in YAML format. We parse any values corresponding to --password, --uri and --sslPEMKeyPassword, and store them in the opts. This also applies to --destinationPassword for mongomirror only.

func (*ToolOptions) PrintHelp

func (opts *ToolOptions) PrintHelp(force bool) bool

Print the usage message for the tool to stdout. Returns whether or not the help flag is specified.

func (*ToolOptions) PrintVersion

func (opts *ToolOptions) PrintVersion() bool

Print the tool version to stdout. Returns whether or not the version flag is specified.

func (*ToolOptions) UseReadOnlyHostDescription

func (opts *ToolOptions) UseReadOnlyHostDescription()

UseReadOnlyHostDescription changes the help description of the --host arg to not mention the shard/host:port format used in the data-mutating tools

type URI

type URI struct {
	ConnectionString string `long:"uri" value-name:"mongodb-uri" description:"mongodb uri connection string"`

	ConnString connstring.ConnString
	// contains filtered or unexported fields
}

func NewURI

func NewURI(unparsed string) (*URI, error)

func (*URI) GetConnectionAddrs

func (uri *URI) GetConnectionAddrs() []string

func (*URI) LogUnsupportedOptions

func (uri *URI) LogUnsupportedOptions()

LogUnsupportedOptions logs warnings regarding unknown/unsupported URI parameters. The unknown options are determined by the driver.

func (*URI) ParsedConnString

func (uri *URI) ParsedConnString() *connstring.ConnString

type URISetter

type URISetter interface {
	// SetOptionsFromURI provides a way for tools to fetch any options that were
	// set in the URI and set them on the ExtraOptions that they pass to the options
	// package.
	SetOptionsFromURI(connstring.ConnString) error
}

type Verbosity

type Verbosity struct {
	SetVerbosity    func(string) `` /* 221-byte string literal not displayed */
	Quiet           bool         `long:"quiet" description:"hide all log output"`
	VLevel          int          `no-flag:"true"`
	VerbosityParsed bool         `no-flag:"true"`
}

Struct holding verbosity-related options

func (Verbosity) IsQuiet

func (v Verbosity) IsQuiet() bool

func (Verbosity) Level

func (v Verbosity) Level() int

type WriteConcern

type WriteConcern struct {
	// Specifies the write concern for each write operation that mongofiles writes to the target database.
	// By default, mongofiles waits for a majority of members from the replica set to respond before returning.
	WriteConcern string `` /* 211-byte string literal not displayed */
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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