@@ -61,7 +61,36 @@ func ValidateConfig(conf EnvConfig, offline bool) error {
61
61
return fmt .Errorf ("STRICT_LOGGING must be either 'true' or 'false', '%s' is not valid" , conf .getStrictLogging ())
62
62
}
63
63
}
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
+ }
65
94
return nil
66
95
}
67
96
0 commit comments