@@ -61,7 +61,36 @@ func ValidateConfig(conf EnvConfig, offline bool) error {
6161 return fmt .Errorf ("STRICT_LOGGING must be either 'true' or 'false', '%s' is not valid" , conf .getStrictLogging ())
6262 }
6363 }
64- log .Debugf ("Validated config: %s" , conf .DebugString ())
64+ if conf .GetKeybaseUsername () != "" || conf .GetKeybasePaperKey () != "" {
65+ if conf .GetKeybaseUsername () == "" && conf .GetKeybasePaperKey () != "" {
66+ return fmt .Errorf ("you must set set a username if you set a paper key (username='%s', key='%s')" , conf .GetKeybaseUsername (), conf .GetKeybasePaperKey ())
67+ }
68+ if conf .GetKeybasePaperKey () == "" && conf .GetKeybaseUsername () != "" {
69+ return fmt .Errorf ("you must set set a paper key if you set a username (username='%s', key='%s')" , conf .GetKeybaseUsername (), conf .GetKeybasePaperKey ())
70+ }
71+ if ! offline {
72+ err := validateUsernamePaperkey (conf .GetKeybaseHomeDir (), conf .GetKeybaseUsername (), conf .GetKeybasePaperKey ())
73+ if err != nil {
74+ return fmt .Errorf ("failed to validate KEYBASE_USERNAME and KEYBASE_PAPERKEY: %v" , err )
75+ }
76+ }
77+ }
78+ log .Debugf ("Validated config: %s" , conf .DebugString ())
79+ return nil
80+ }
81+
82+ func validateUsernamePaperkey (homedir , username , paperkey string ) error {
83+ api , err := botwrapper .GetKBChat (homedir , username , paperkey )
84+ if err != nil {
85+ return err
86+ }
87+ validatedUsername := api .GetUsername ()
88+ if validatedUsername == "" {
89+ return fmt .Errorf ("failed to get a username from kbChat, got an empty string" )
90+ }
91+ if validatedUsername != username {
92+ return fmt .Errorf ("validated_username=%s and expected_username=%s do not match" , validatedUsername , username )
93+ }
6594 return nil
6695}
6796
0 commit comments