Skip to content

Commit

Permalink
> remove password option from command line.
Browse files Browse the repository at this point in the history
  • Loading branch information
kebe7jun committed Jun 18, 2019
1 parent 076206d commit 5ae55ed
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
2 changes: 1 addition & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

CMD="/usr/local/bin/ropee -log-file-path - "

args="splunk-url splunk-user splunk-password splunk-hec-url splunk-hec-token listen-addr splunk-metrics-index splunk-metrics-sourcetype timeout debug"
args="splunk-url splunk-hec-url splunk-hec-token listen-addr splunk-metrics-index splunk-metrics-sourcetype timeout debug"

for i in $args
do
Expand Down
31 changes: 12 additions & 19 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (

type Config struct {
SplunkUrl string
SplunkUsername, SplunkPassword string
SplunkMetricsIndex string
SplunkMetricsSourceType string
SplunkHECURL string
Expand Down Expand Up @@ -63,8 +62,6 @@ func loadLogger() log.Logger {
func init() {
// init config
flag.StringVar(&config.SplunkUrl, "splunk-url", "https://127.0.0.1:8089", "Splunk Manage Url.")
flag.StringVar(&config.SplunkUsername, "splunk-user", "", "Splunk Manage Username.")
flag.StringVar(&config.SplunkPassword, "splunk-password", "", "Splunk Manage Password.")
flag.StringVar(&config.SplunkHECURL, "splunk-hec-url", "https://127.0.0.1:8088", "Splunk Http event collector url.")
flag.StringVar(&config.SplunkHECToken, "splunk-hec-token", "", "Splunk Http event collector token.")
flag.StringVar(&config.ListenAddr, "listen-addr", "127.0.0.1:9970", "Sopee listen addr.")
Expand All @@ -78,16 +75,6 @@ func init() {

func main() {
l := loadLogger()
client, _ := storage.NewClient(
config.SplunkUrl,
config.SplunkUsername,
config.SplunkPassword,
config.SplunkMetricsIndex,
config.SplunkMetricsSourceType,
config.SplunkHECURL, config.SplunkHECToken,
time.Second*time.Duration(config.TimeoutSeconds),
l,
)
http.Handle("/metrics", promhttp.Handler())
http.HandleFunc("/read", func(w http.ResponseWriter, r *http.Request) {
compressed, err := ioutil.ReadAll(r.Body)
Expand All @@ -110,11 +97,7 @@ func main() {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
user, pass, ok := r.BasicAuth()
if !ok {
user = config.SplunkUsername
pass = config.SplunkPassword
}
user, pass, _ := r.BasicAuth()
readClient, _ := storage.NewClient(
config.SplunkUrl,
user,
Expand Down Expand Up @@ -147,6 +130,16 @@ func main() {
return
}
})
writeClient, _ := storage.NewClient(
config.SplunkUrl,
"",
"",
config.SplunkMetricsIndex,
config.SplunkMetricsSourceType,
config.SplunkHECURL, config.SplunkHECToken,
time.Second*time.Duration(config.TimeoutSeconds),
l,
)
http.HandleFunc("/write", func(w http.ResponseWriter, r *http.Request) {
compressed, err := ioutil.ReadAll(r.Body)
if err != nil {
Expand All @@ -168,7 +161,7 @@ func main() {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
err = client.Write(&req)
err = writeClient.Write(&req)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
Expand Down

0 comments on commit 5ae55ed

Please sign in to comment.