From 473aaf13be0df62e7bfc8a8010695e77c6dd1bd4 Mon Sep 17 00:00:00 2001 From: cnone Date: Tue, 21 May 2019 01:57:01 +0300 Subject: [PATCH] Check if keys exist in map. Fixes: #736 --- cmd/config.go | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/cmd/config.go b/cmd/config.go index 888a3fa6..278521ed 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -89,25 +89,24 @@ func getAuthentication(flags *pflag.FlagSet, defaults ...interface{}) (settings. secret := mustGetString(flags, "recaptcha.secret") if key == "" { - kmap := defaultAuther["recaptcha"].(map[string]interface{}) - key = kmap["key"].(string) + if kmap, ok := defaultAuther["recaptcha"].(map[string]interface{}); ok { + key = kmap["key"].(string) + } } if secret == "" { - smap := defaultAuther["recaptcha"].(map[string]interface{}) - secret = smap["secret"].(string) + if smap, ok := defaultAuther["recaptcha"].(map[string]interface{}); ok { + secret = smap["secret"].(string) + } } - if key == "" || secret == "" { - checkErr(nerrors.New("you must set the flag 'recaptcha.key' and 'recaptcha.secret' for method 'json'")) + if key != "" && secret != "" { + jsonAuth.ReCaptcha = &auth.ReCaptcha{ + Host: host, + Key: key, + Secret: secret, + } } - - jsonAuth.ReCaptcha = &auth.ReCaptcha{ - Host: host, - Key: key, - Secret: secret, - } - auther = jsonAuth }