Exemplo n.º 1
0
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
}
Exemplo n.º 2
0
/*
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
}
Exemplo n.º 3
0
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
}
Exemplo n.º 4
0
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
}
Exemplo n.º 5
0
func grabUsername(c *gcli.Context) string {
	if val, success := getVal("user", c); success {
		return val
	}
	return cfg.Get("user")
}