Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Commit 927e768

Browse files
committed
Respond to feedback on PR
1 parent 2c05da6 commit 927e768

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

src/cmd/keybaseca/keybaseca.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ func serviceAction(c *cli.Context) error {
148148
func signAction(c *cli.Context) error {
149149
// Skip validation of the config since that relies on Keybase's servers
150150
conf := config.EnvConfig{}
151+
err := config.ValidateConfig(conf, true)
152+
if err != nil {
153+
return fmt.Errorf("Invalid config: %v", err)
154+
}
151155
principals := strings.Join(conf.GetTeams(), ",")
152156
expiration := conf.GetKeyExpiration()
153157
randomUUID, err := uuid.NewRandom()
@@ -186,7 +190,8 @@ func signAction(c *cli.Context) error {
186190

187191
// The action for the `keybaseca` command. Only used for hidden and unlisted flags.
188192
func mainAction(c *cli.Context) error {
189-
if c.Bool("wipe-all-configs") {
193+
switch {
194+
case c.Bool("wipe-all-configs"):
190195
teams, err := shared.KBFSList("/keybase/team/")
191196
if err != nil {
192197
return err
@@ -215,7 +220,7 @@ func mainAction(c *cli.Context) error {
215220
}(team)
216221
}
217222
semaphore.Wait()
218-
} else if c.Bool("wipe-logs") {
223+
case c.Bool("wipe-logs"):
219224
conf, err := loadServerConfig()
220225
if err != nil {
221226
return err
@@ -233,7 +238,7 @@ func mainAction(c *cli.Context) error {
233238
}
234239
}
235240
fmt.Println("Wiped existing log file at " + logLocation)
236-
} else {
241+
default:
237242
cli.ShowAppHelpAndExit(c, 1)
238243
}
239244
return nil
@@ -316,7 +321,7 @@ func captureControlCToDeleteClientConfig(conf config.Config) {
316321
// Load and validate a server config object from the environment
317322
func loadServerConfig() (config.Config, error) {
318323
conf := config.EnvConfig{}
319-
err := config.ValidateConfig(conf)
324+
err := config.ValidateConfig(conf, false)
320325
if err != nil {
321326
return nil, fmt.Errorf("Failed to validate config: %v", err)
322327
}

src/keybaseca/config/config.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,23 @@ type Config interface {
2525
GetStrictLogging() bool
2626
}
2727

28-
func ValidateConfig(conf EnvConfig) error {
28+
// Validate the given config file. If offline, do so without connecting to keybase (used in code that is meant
29+
// to function without any reliance on Keybase).
30+
func ValidateConfig(conf EnvConfig, offline bool) error {
2931
if len(conf.GetTeams()) == 0 {
3032
return fmt.Errorf("must specify at least one team via the TEAMS environment variable")
3133
}
3234
if conf.GetKeyExpiration() != "" && !strings.HasPrefix(conf.GetKeyExpiration(), "+") {
3335
// Only a basic check for this since ssh will error out later on if it is bogus
3436
return fmt.Errorf("KEY_EXPIRATION must be of the form `+<number><unit> where unit is one of `m`, `h`, `d`, `w`. Eg `+1h`. ")
3537
}
36-
if conf.GetLogLocation() != "" {
38+
if conf.GetLogLocation() != "" && !offline {
3739
err := validatePath(conf.GetLogLocation())
3840
if err != nil {
3941
return fmt.Errorf("LOG_LOCATION '%s' is not a valid path: %v", conf.GetLogLocation(), err)
4042
}
4143
}
42-
if conf.getChatChannel() != "" {
44+
if conf.getChatChannel() != "" && !offline {
4345
team, channel, err := splitTeamChannel(conf.getChatChannel())
4446
if err != nil {
4547
return fmt.Errorf("Failed to parse CHAT_CHANNEL=%s: %v", conf.getChatChannel(), err)

0 commit comments

Comments
 (0)