@@ -42,8 +42,9 @@ type CacheConfig struct {
4242}
4343
4444type AuthConfig struct {
45- Enabled bool `mapstructure:"enabled"`
46- Users []UserAuth `mapstructure:"users"`
45+ Enabled bool `mapstructure:"enabled"`
46+ Reader UserAuth `mapstructure:"reader"`
47+ Writer UserAuth `mapstructure:"writer"`
4748}
4849
4950type UserAuth struct {
@@ -106,37 +107,29 @@ func Load(configPath string) (*Config, error) {
106107 // Bind specific environment variables
107108 v .BindEnv ("storage.password" , "REDIS_PASSWORD" )
108109
109- v .BindEnv ("auth.users.0.password" , "CACHE_PASSWORD" )
110+ v .BindEnv ("auth.reader.password" , "CACHE_READER_PASSWORD" )
111+ v .BindEnv ("auth.writer.password" , "CACHE_WRITER_PASSWORD" )
112+
110113 v .BindEnv ("sentry.dsn" , "SENTRY_DSN" )
111114
112115 var cfg Config
113116 if err := v .Unmarshal (& cfg ); err != nil {
114117 return nil , fmt .Errorf ("failed to unmarshal config: %w" , err )
115118 }
116119
117- // Handle CACHE_PASSWORD environment variable for default user
118- if cachePassword := v .GetString ("CACHE_PASSWORD" ); cachePassword != "" {
119- if len (cfg .Auth .Users ) > 0 {
120- cfg .Auth .Users [0 ].Password = cachePassword
121- }
122- }
123-
124120 return & cfg , nil
125121}
126122
127123func (c * Config ) Validate () error {
128124 if c .Storage .Addr == "" {
129125 return fmt .Errorf ("storage.addr is required" )
130126 }
131- if c .Auth .Enabled && len (c .Auth .Users ) == 0 {
132- return fmt .Errorf ("auth.users is required when auth is enabled" )
133- }
134- for i , user := range c .Auth .Users {
135- if user .Username == "" {
136- return fmt .Errorf ("auth.users[%d].username is required" , i )
127+ if c .Auth .Enabled {
128+ if c .Auth .Reader .Username == "" || c .Auth .Reader .Password == "" {
129+ return fmt .Errorf ("auth.reader.username and auth.reader.password are required when auth is enabled" )
137130 }
138- if user .Password == "" {
139- return fmt .Errorf ("auth.users[%d]. password is required" , i )
131+ if c . Auth . Writer . Username == "" || c . Auth . Writer .Password == "" {
132+ return fmt .Errorf ("auth.writer.username and auth.writer. password are required when auth is enabled" )
140133 }
141134 }
142135 if c .Server .TLS .Enabled {
0 commit comments