func (c *CLIConfig) IsLoggingEnabledFor(level logging.Level) bool {
	return logging.IsEnabledFor(loggerName, level)
}
IsLoggingEnabledFor indicates whether the logger is enabled for the given logging level
package cliconfig
import (
	"fmt"
	"strconv"
	"strings"
	"time"
	fabApi "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
	mspApi "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/msp"
	"github.com/hyperledger/fabric-sdk-go/pkg/core/config"
	"github.com/hyperledger/fabric-sdk-go/pkg/core/cryptosuite/bccsp/multisuite"
	"github.com/hyperledger/fabric-sdk-go/pkg/fab"
	"github.com/hyperledger/fabric-sdk-go/pkg/msp"
	"github.com/hyperledger/fabric-sdk-go/pkg/common/logging"
	"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/core"
	"github.com/hyperledger/fabric-sdk-go/pkg/core/cryptosuite"
	"github.com/securekey/fabric-snaps/util/errors"
	"github.com/spf13/pflag"
)
const (
	ConfigSnapID = "configurationsnap"
	loggerName = "configcli"
)
const (
	loggingLevelFlag        = "logging-level"
	loggingLevelDescription = "Logging level - ERROR, WARN, INFO, DEBUG"
	defaultLoggingLevel     = "ERROR"
	clientConfigFileFlag        = "clientconfig"
	clientConfigFileDescription = "The path of the client SDK's config.yaml file"
	defaultClientConfigFile     = ""
	userFlag        = "user"
	userDescription = "The user used to connect to Fabric"
	defaultUser     = ""
	passwordFlag        = "pw"
	passwordDescription = "The password of the user"
	defaultPassword     = ""
	channelIDFlag        = "cid"
	channelIDDescription = "The channel ID"
	defaultChannelID     = ""
	orgIDFlag        = "orgid"
	orgIDDescription = "A comma-separated set of peers, e.g. org1,org2. If specified then the request is made to all peers for the given organization"
	defaultOrgID     = ""
	peerURLFlag        = "peerurl"
	peerURLDescription = "A comma-separated list of target peers to query/update, e.g. 'grpcs://localhost:7051,grpcs://localhost:8051'"
	defaultPeerURL     = ""
	configKeyFlag        = "configkey"
	configKeyDescription = "The config key in JSON format. Example: {\"MspID\":\"Org1MSP\",\"PeerID\":\"peer0.org1.example.com\",\"AppName\":\"app1\",\"Version\":\"1\"}"
	configFlag        = "config"
	configDescription = "The config update string in JSON format. Example: {\"MspID\":\"Org1MSP\",\"Peers\":[{\"PeerID\":\"peer0.org1.example.com\",\"App\":[{\"AppName\":\"myapp\",\"Version\":\"1\",\"Config\":\"some config\"}]}]}"
	configFileFlag        = "configfile"
	configFileDescription = "The path to the config file"
	timeoutFlag        = "timeout"
	timeoutDescription = "The timeout (in milliseconds) for the operation"
	defaultTimeout     = "3000"
	outputFormatFlag        = "format"
	outputFormatDescription = "The output format - display, raw"
	defaultOutputFormat     = "formatted"
	mspIDFlag        = "mspid"
	mspIDDescription = "The ID of the MSP"
	defaultMSPID     = ""
	peerIDFlag        = "peerid"
	peerIDDescription = "The ID of the peer to query for"
	appNameFlag        = "appname"
	appNameDescription = "The name of the application to query for"
	appVerFlag        = "appver"
	appVerDescription = "The app version"
	componentNameFlag        = "componentname"
	componentNameDescription = "The name of the component to query for"
	componentVerFlag        = "componentver"
	componentVerDescription = "The component version"
	noPromptFlag        = "noprompt"
	noPromptDescription = "If specified then update and delete operations will not prompt for confirmation"
	defaultNoPrompt     = false
	keyType            = "keyType"
	keyTypeDescription = "Key type to be used to generate CSR"
	ephemeral            = "ephemeral"
	ephemeralDescription = "To be used in generate CSR - default false - long lived keys"
	ephemeralDefault     = "false"
	sigAlg            = "sigAlg"
	sigAlgDescription = "Signature Algorithm used to generate CSR"
	csrCommonName     = "csrCommonName"
	csrCommonNameDesc = "CSR common name"
)
var opts *options
var instance *CLIConfig
type options struct {
	user             string
	password         string
	loggingLevel     string
	orgID            string
	channelID        string
	peerURL          string
	clientConfigFile string
	configFile       string
	configKey        string
	config           string
	timeout          int64
	outputFormat     string
	mspID            string
	peerID           string
	appName          string
	appVer           string
	componentName    string
	componentVer     string
	noPrompt         bool
	keyType          string
	ephemeralFlag    string
	sigAlg           string
	csrCommonName    string
}
func init() {
	opts = &options{
		user:         defaultUser,
		password:     defaultPassword,
		loggingLevel: defaultLoggingLevel,
		channelID:    defaultChannelID,
	}
}
type CLIConfig struct {
	fabApi.EndpointConfig
	mspApi.IdentityConfig
	core.CryptoSuiteConfig
	logger *logging.Logger
}
func InitConfig() error {
	instance = &CLIConfig{
		logger: logging.NewLogger(loggerName),
	}
	if opts.clientConfigFile == "" {
		return errors.New(errors.GeneralError, "no client config file specified")
	}
	provider := config.FromFile(opts.clientConfigFile)
	cnfg, err := provider()
	if err != nil {
		return errors.WithMessage(errors.GeneralError, err, "error loading the configs")
	}
	cryptoConfig := cryptosuite.ConfigFromBackend(cnfg...)
	cryptoSuiteProvider, err := multisuite.GetSuiteByConfig(cryptoConfig)
	if err != nil {
		instance.logger.Warnf("Failed to get cryptosuite from config, will switch to default cryptosuite, %s", err)
	} else {
		err = cryptosuite.SetDefault(cryptoSuiteProvider)
		if err != nil {
			instance.logger.Warnf("Error setting default cryptosuite, %s", err)
		}
	}
	endpointConfig, err := fab.ConfigFromBackend(cnfg...)
	if err != nil {
		return errors.WithMessage(errors.GeneralError, err, "from backend returned error")
	}
	identityConfig, err := msp.ConfigFromBackend(cnfg...)
	if err != nil {
		return errors.WithMessage(errors.GeneralError, err, "from backend returned error")
	}
	instance.EndpointConfig = endpointConfig
	instance.IdentityConfig = identityConfig
	instance.CryptoSuiteConfig = cryptoConfig
	return nil
}
func Config() *CLIConfig {
	return instance
}
func (c *CLIConfig) Logger() *logging.Logger {
	return c.logger
}
func (c *CLIConfig) LoggingLevel() string {
	return opts.loggingLevel
}
func InitLoggingLevel(flags *pflag.FlagSet) {
	flags.StringVar(&opts.loggingLevel, loggingLevelFlag, defaultLoggingLevel, loggingLevelDescription)
}
func (c *CLIConfig) ClientConfigFile() string {
	return opts.clientConfigFile
}
func InitClientConfigFile(flags *pflag.FlagSet) {
	flags.StringVar(&opts.clientConfigFile, clientConfigFileFlag, defaultClientConfigFile, clientConfigFileDescription)
}
func (c *CLIConfig) OrgID() string {
	return opts.orgID
}
func InitOrgID(flags *pflag.FlagSet) {
	flags.StringVar(&opts.orgID, orgIDFlag, defaultOrgID, orgIDDescription)
}
func (c *CLIConfig) GetMspID() string {
	return opts.mspID
}
func InitMspID(flags *pflag.FlagSet) {
	flags.StringVar(&opts.mspID, mspIDFlag, defaultMSPID, mspIDDescription)
}
func (c *CLIConfig) ChannelID() string {
	return opts.channelID
}
func InitChannelID(flags *pflag.FlagSet) {
	flags.StringVar(&opts.channelID, channelIDFlag, defaultChannelID, channelIDDescription)
}
func (c *CLIConfig) UserName() string {
	return opts.user
}
func InitUserName(flags *pflag.FlagSet) {
	flags.StringVar(&opts.user, userFlag, defaultUser, userDescription)
}
func (c *CLIConfig) UserPassword() string {
	return opts.password
}
func InitUserPassword(flags *pflag.FlagSet) {
	flags.StringVar(&opts.password, passwordFlag, defaultPassword, passwordDescription)
}
func (c *CLIConfig) Peers() []string {
	if opts.peerURL == "" {
		return nil
	}
	return strings.Split(opts.peerURL, ",")
}
func InitPeerURL(flags *pflag.FlagSet) {
	flags.StringVar(&opts.peerURL, peerURLFlag, defaultPeerURL, peerURLDescription)
}
func (c *CLIConfig) PeerID() string {
	return opts.peerID
}
func InitPeerID(flags *pflag.FlagSet) {
	flags.StringVar(&opts.peerID, peerIDFlag, "", peerIDDescription)
}
func (c *CLIConfig) AppName() string {
	return opts.appName
}
func InitAppName(flags *pflag.FlagSet) {
	flags.StringVar(&opts.appName, appNameFlag, "", appNameDescription)
}
func (c *CLIConfig) AppVer() string {
	return opts.appVer
}
func InitAppVer(flags *pflag.FlagSet) {
	flags.StringVar(&opts.appVer, appVerFlag, "", appVerDescription)
}
func (c *CLIConfig) ComponentName() string {
	return opts.componentName
}
func InitComponentName(flags *pflag.FlagSet) {
	flags.StringVar(&opts.componentName, componentNameFlag, "", componentNameDescription)
}
func (c *CLIConfig) ComponentVer() string {
	return opts.componentVer
}
func InitComponentVer(flags *pflag.FlagSet) {
	flags.StringVar(&opts.componentVer, componentVerFlag, "", componentVerDescription)
}
func (c *CLIConfig) KeyType() string {
	return opts.keyType
}
func InitKeyType(flags *pflag.FlagSet) {
	flags.StringVar(&opts.keyType, keyType, "", keyTypeDescription)
}
func (c *CLIConfig) EphemeralFlag() string {
	return opts.ephemeralFlag
}
func InitEphemeralFlag(flags *pflag.FlagSet) {
	flags.StringVar(&opts.ephemeralFlag, ephemeral, ephemeralDefault, ephemeralDescription)
}
func (c *CLIConfig) SigAlg() string {
	return opts.sigAlg
}
func InitSigAlg(flags *pflag.FlagSet) {
	flags.StringVar(&opts.sigAlg, sigAlg, "", sigAlgDescription)
}
func (c *CLIConfig) CSRCommonName() string {
	return opts.csrCommonName
}
func InitCSRCommonName(flags *pflag.FlagSet) {
	flags.StringVar(&opts.csrCommonName, csrCommonName, "", csrCommonNameDesc)
}
func (c *CLIConfig) NoPrompt() bool {
	return opts.noPrompt
}
func InitNoPrompt(flags *pflag.FlagSet) {
	flags.BoolVar(&opts.noPrompt, noPromptFlag, defaultNoPrompt, noPromptDescription)
}
func (c *CLIConfig) ConfigKey() string {
	return opts.configKey
}
func InitConfigKey(flags *pflag.FlagSet) {
	flags.StringVar(&opts.configKey, configKeyFlag, "", configKeyDescription)
}
func (c *CLIConfig) ConfigString() string {
	return opts.config
}
func InitConfigString(flags *pflag.FlagSet) {
	flags.StringVar(&opts.config, configFlag, "", configDescription)
}
func (c *CLIConfig) Timeout(conn fabApi.TimeoutType) time.Duration {
	return time.Duration(opts.timeout) * time.Millisecond
}
func InitTimeout(flags *pflag.FlagSet) {
	i, err := strconv.Atoi(defaultTimeout)
	if err != nil {
		fmt.Printf("Invalid number: %s\n", defaultTimeout)
		i = 1000
	}
	flags.Int64Var(&opts.timeout, timeoutFlag, int64(i), timeoutDescription)
}
func (c *CLIConfig) OutputFormat() string {
	return opts.outputFormat
}
func InitOutputFormat(flags *pflag.FlagSet) {
	flags.StringVar(&opts.outputFormat, outputFormatFlag, defaultOutputFormat, outputFormatDescription)
}