From 76a62cb0c38c63281cbcd96bcebcabf49fbdff05 Mon Sep 17 00:00:00 2001 From: malnick Date: Sun, 8 May 2016 15:02:32 -0700 Subject: [PATCH] Enable SSL for request --- config/config.go | 3 +++ loga/elastic_runner.go | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/config/config.go b/config/config.go index 852683d..3fa64ac 100644 --- a/config/config.go +++ b/config/config.go @@ -33,6 +33,7 @@ type Config struct { LogVerbose bool `yaml:"log_verbose"` SearchHost bool `yaml:"search_host,omitempty"` logaConfigPath string `yaml:",omitempty"` + EnableSSL bool `yaml:"enable_ssl"` } func basicCheckOrExit(err error) { @@ -53,6 +54,7 @@ func defaultConfig() Config { StartTime: 0, Count: 500, LogVerbose: false, + EnableSSL: false, logaConfigPath: "./loga.yaml", ConfDefinedQueries: map[string]string{ "example": "foo AND bar", @@ -99,6 +101,7 @@ func (c *Config) setFlags(fs *flag.FlagSet) { fs.BoolVar(&c.LogVerbose, "v", c.LogVerbose, "Verbose logging option") fs.BoolVar(&c.Highlight, "h", c.Highlight, "Highlight search in output") fs.BoolVar(&c.FlagVersion, "version", false, "Print version and exit") + fs.BoolVar(&c.EnableSSL, "enable-ssl", false, "Using HTTPS for elasticsearch request.") fs.StringVar(&c.logaConfigPath, "c", c.logaConfigPath, "Path to loga.yaml") fs.StringVar(&c.FlagDefinedQuery, "d", c.FlagDefinedQuery, "Define a lookup on the CLI") diff --git a/loga/elastic_runner.go b/loga/elastic_runner.go index 83d495a..27372d3 100644 --- a/loga/elastic_runner.go +++ b/loga/elastic_runner.go @@ -59,7 +59,11 @@ func (esRequest *ESRequest) makeRequest(c *config.Config) (ESResponse, error) { log.Debugf("Elastic Search Request:\n %s", string(jsonpost)) // Craft the request URI - queryURL := strings.Join([]string{"http://", c.ElasticsearchURL, ":", c.ElasticsearchPort, "/_search?pretty"}, "") + requestMethod := "http" + if c.EnableSSL { + requestMethod := "https" + } + queryURL := strings.Join([]string{requestMethod, "://", c.ElasticsearchURL, ":", c.ElasticsearchPort, "/_search?pretty"}, "") log.Debug("Query URI: ", queryURL) // Make request