func DBParams(cmd *cobra.Command) (*DBParameters, error) {
	var err error
	params := &DBParameters{}
	params.URL, err = cmdutils.GetUserSetVarFromString(cmd, DatabaseURLFlagName, DatabaseURLEnvKey, false)
	if err != nil {
		return nil, fmt.Errorf("failed to configure dbURL: %w", err)
	}
	params.Prefix, err = cmdutils.GetUserSetVarFromString(cmd, DatabasePrefixFlagName, DatabasePrefixEnvKey, false)
	if err != nil {
		return nil, fmt.Errorf("failed to configure dbPrefix: %w", err)
	}
	timeout, err := cmdutils.GetUserSetVarFromString(cmd, DatabaseTimeoutFlagName, DatabaseTimeoutEnvKey, true)
	if err != nil && !strings.Contains(err.Error(), "value is empty") {
		return nil, fmt.Errorf("failed to configure dbTimeout: %w", err)
	}
	if timeout == "" {
		timeout = strconv.Itoa(DatabaseTimeoutDefault)
	}
	params.Timeout, err = strconv.ParseUint(timeout, 10, 64)
	if err != nil {
		return nil, fmt.Errorf("failed to parse dbTimeout %s: %w", timeout, err)
	}
	return params, nil
}
DBParams fetches the DB parameters configured for this command.
package common
import (
	"fmt"
	"net/http"
	"strconv"
	"strings"
	"time"
	"github.com/cenkalti/backoff/v4"
	"github.com/hyperledger/aries-framework-go-ext/component/storage/couchdb"
	"github.com/hyperledger/aries-framework-go-ext/component/storage/mongodb"
	"github.com/hyperledger/aries-framework-go-ext/component/storage/mysql"
	"github.com/hyperledger/aries-framework-go/component/storageutil/mem"
	"github.com/hyperledger/aries-framework-go/pkg/doc/ld"
	"github.com/hyperledger/aries-framework-go/pkg/doc/ldcontext/remote"
	ldstore "github.com/hyperledger/aries-framework-go/pkg/store/ld"
	"github.com/hyperledger/aries-framework-go/spi/storage"
	jsonld "github.com/piprate/json-gold/ld"
	"github.com/spf13/cobra"
	"github.com/trustbloc/edge-core/pkg/log"
	cmdutils "github.com/trustbloc/edge-core/pkg/utils/cmd"
)
const (
	LogLevelFlagName = "log-level"
	LogLevelEnvKey = "LOG_LEVEL"
	LogLevelFlagShorthand = "l"
	LogLevelPrefixFlagUsage = "Logging level to set. Supported options: CRITICAL, ERROR, WARNING, INFO, DEBUG." +
		`Defaults to info if not set. Setting to debug may adversely impact performance. Alternatively, this can be ` +
		"set with the following environment variable: " + LogLevelEnvKey
)
const (
	DatabaseURLFlagName = "database-url"
	DatabaseURLFlagUsage = "Database URL with credentials if required." +
		" Format must be <driver>:[//]<driver-specific-dsn>." +
		" Examples: 'mysql://root:secret@tcp(localhost:3306)/component', 'mem://test'," +
		"'mongodb://mongodb.example.com:27017'. Supported drivers are [mem, mysql, couchdb, mongodb]." +
		" Alternatively, this can be set with the following environment variable: " + DatabaseURLEnvKey
	DatabaseURLEnvKey = "DATABASE_URL"
	DatabaseTimeoutFlagName = "database-timeout"
	DatabaseTimeoutFlagUsage = "Total time in seconds to wait until the datasource is available before giving up." +
		" Default: " + string(rune(DatabaseTimeoutDefault)) + " seconds." +
		" Alternatively, this can be set with the following environment variable: " + DatabaseTimeoutEnvKey
	DatabaseTimeoutEnvKey = "DATABASE_TIMEOUT"
	DatabasePrefixFlagName = "database-prefix"
	DatabasePrefixEnvKey = "DATABASE_PREFIX"
	DatabasePrefixFlagUsage = "An optional prefix to be used when creating and retrieving underlying databases. " +
		"Alternatively, this can be set with the following environment variable: " + DatabasePrefixEnvKey
	DatabaseTimeoutDefault = 30
	databaseTypeMemOption     = "mem"
	databaseTypeMYSQLDBOption = "mysql"
	databaseTypeCouchDBOption = "couchdb"
	databaseTypeMongoDBOption = "mongodb"
)
type DBParameters struct {
	URL     string
	Prefix  string
	Timeout uint64
}
var supportedStorageProviders = map[string]func(string, string) (storage.Provider, error){
	databaseTypeMYSQLDBOption: func(dbURL, prefix string) (storage.Provider, error) {
		return mysql.NewProvider(dbURL, mysql.WithDBPrefix(prefix))
	},
	databaseTypeMemOption: func(_, _ string) (storage.Provider, error) {  
		return mem.NewProvider(), nil
	},
	databaseTypeCouchDBOption: func(dbURL, prefix string) (storage.Provider, error) {
		return couchdb.NewProvider(dbURL, couchdb.WithDBPrefix(prefix))
	},
	databaseTypeMongoDBOption: func(dbURL, prefix string) (storage.Provider, error) {
		return mongodb.NewProvider(dbURL, mongodb.WithDBPrefix(prefix))
	},
}
func SetDefaultLogLevel(logger log.Logger, userLogLevel string) {
	logLevel, err := log.ParseLevel(userLogLevel)
	if err != nil {
		logger.Warnf(`%s is not a valid logging level. It must be one of the following: `+
			log.ParseString(log.CRITICAL)+", "+
			log.ParseString(log.ERROR)+", "+
			log.ParseString(log.WARNING)+", "+
			log.ParseString(log.INFO)+", "+
			log.ParseString(log.DEBUG)+". Defaulting to info.", userLogLevel)
		logLevel = log.INFO
	} else if logLevel == log.DEBUG {
		logger.Infof(`Log level set to "debug". Performance may be adversely impacted.`)
	}
	log.SetLevel("", logLevel)
}
func Flags(cmd *cobra.Command) {
	cmd.Flags().StringP(DatabaseURLFlagName, "", "", DatabaseURLFlagUsage)
	cmd.Flags().StringP(DatabasePrefixFlagName, "", "", DatabasePrefixFlagUsage)
	cmd.Flags().StringP(DatabaseTimeoutFlagName, "", "", DatabaseTimeoutFlagUsage)
}