func proxyConf(host string, port int) (proxy *ogcli.ProxyConfiguration) {
	printVerboseMessage("Configuring proxy settings with host " + host + " and port " + strconv.Itoa(port))
	pc := new(ogcli.ProxyConfiguration)
	pc.Protocol = cfg.Get("proxyProtocol")
	pc.Host = host
	pc.Port = port
	username := cfg.Get("proxyUsername")
	password := cfg.Get("proxyPassword")
	if username != "" && password != "" {
		pc.Username = username
		pc.Password = password
	}
	return pc
}
/*
The 'API Key' is the most common parameter for all commands.
It is provided either on command line or on the configuration file.
*/
func grabAPIKey(c *gcli.Context) string {
	if val, success := getVal("apiKey", c); success {
		return val
	}
	apiKey := cfg.Get("apiKey")
	printVerboseMessage("apiKey flag is not set in the command, reading apiKey from config..")
	return apiKey
}
func initialize(c *gcli.Context) *ogcli.OpsGenieClient {
	if c.IsSet("v") {
		verbose = true
		printVerboseMessage("Will execute command in verbose mode.")
	}
	readConfigFile(c)
	apiKey := grabAPIKey(c)
	cli := new(ogcli.OpsGenieClient)
	cli.SetAPIKey(apiKey)
	if apiURL := cfg.Get("opsgenie.api.url"); apiURL != "" {
		cli.SetOpsGenieAPIUrl(apiURL)
	}
	proxyHost := cfg.Get("proxyHost")
	proxyPort, err := strconv.Atoi(cfg.Get("proxyPort"))
	if err == nil && proxyPort != 0 && proxyHost != "" {
		cli.SetProxyConfiguration(proxyConf(proxyHost, proxyPort))
	}
	cli.SetHTTPTransportSettings(connectionConf())
	return cli
}
func parseDuration(key string) time.Duration {
	strDuration := cfg.Get(key)
	if strDuration != "" {
		printVerboseMessage("Will try to parse [" + key + "] with value [" + strDuration + "] from string to time duration in seconds..")
		var reqTimeout time.Duration
		var err error
		if strings.HasSuffix(strDuration, "s") {
			reqTimeout, err = time.ParseDuration(strDuration)
		} else {
			reqTimeout, err = time.ParseDuration(strDuration + "s")
		}
		if err != nil {
			printVerboseMessage("Could not parse " + strDuration + " from string to time duration, opsgenie client will use default value.")
			return 0
		}
		return reqTimeout
	}
	printVerboseMessage("Could not parse [" + key + "] with value [" + strDuration + "].")
	return 0
}
func grabUsername(c *gcli.Context) string {
	if val, success := getVal("user", c); success {
		return val
	}
	return cfg.Get("user")
}