Skip to content

Commit 68035d8

Browse files
committed
scheduler/config: add auth.jwt (realm, key, timeout, maxRefresh) with defaults and validation
Signed-off-by: sabarixr <[email protected]>
1 parent 94070a3 commit 68035d8

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

scheduler/config/config.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ type Config struct {
6464

6565
// Network configuration.
6666
Network NetworkConfig `yaml:"network" mapstructure:"network"`
67+
68+
// Auth configuration.
69+
Auth AuthConfig `yaml:"auth" mapstructure:"auth"`
6770
}
6871

6972
type ServerConfig struct {
@@ -313,6 +316,25 @@ type NetworkConfig struct {
313316
EnableIPv6 bool `mapstructure:"enableIPv6" yaml:"enableIPv6"`
314317
}
315318

319+
type AuthConfig struct {
320+
// JWT configuration.
321+
JWT JWTConfig `yaml:"jwt" mapstructure:"jwt"`
322+
}
323+
324+
type JWTConfig struct {
325+
// Realm name to display to the user, default value is Dragonfly.
326+
Realm string `yaml:"realm" mapstructure:"realm"`
327+
328+
// Key is secret key used for signing. Please change the key in production
329+
Key string `yaml:"key" mapstructure:"key"`
330+
331+
// Timeout is duration that a jwt token is valid.
332+
Timeout time.Duration `yaml:"timeout" mapstructure:"timeout"`
333+
334+
// MaxRefresh allows clients to refresh their token until MaxRefresh has passed.
335+
MaxRefresh time.Duration `yaml:"maxRefresh" mapstructure:"maxRefresh"`
336+
}
337+
316338
// New default configuration.
317339
func New() *Config {
318340
return &Config{
@@ -384,6 +406,13 @@ func New() *Config {
384406
Network: NetworkConfig{
385407
EnableIPv6: DefaultNetworkEnableIPv6,
386408
},
409+
Auth: AuthConfig{
410+
JWT: JWTConfig{
411+
Realm: "Dragonfly",
412+
Timeout: 14 * 24 * time.Hour,
413+
MaxRefresh: 7 * 24 * time.Hour,
414+
},
415+
},
387416
}
388417
}
389418

@@ -543,6 +572,20 @@ func (cfg *Config) Validate() error {
543572
}
544573
}
545574

575+
// Auth validation
576+
if cfg.Auth.JWT.Realm == "" {
577+
return errors.New("jwt requires parameter realm")
578+
}
579+
if cfg.Auth.JWT.Key == "" {
580+
return errors.New("jwt requires parameter key")
581+
}
582+
if cfg.Auth.JWT.Timeout == 0 {
583+
return errors.New("jwt requires parameter timeout")
584+
}
585+
if cfg.Auth.JWT.MaxRefresh == 0 {
586+
return errors.New("jwt requires parameter maxRefresh")
587+
}
588+
546589
return nil
547590
}
548591

0 commit comments

Comments
 (0)