@@ -221,6 +221,11 @@ func (r *LuetRepository) String() string {
221
221
r .Name , r .Priority , r .Type , r .Enable , r .Cached )
222
222
}
223
223
224
+ type LuetKV struct {
225
+ Key string `json:"key" yaml:"key" mapstructure:"key"`
226
+ Value string `json:"value" yaml:"value" mapstructure:"value"`
227
+ }
228
+
224
229
type LuetConfig struct {
225
230
Viper * v.Viper
226
231
@@ -236,6 +241,8 @@ type LuetConfig struct {
236
241
CacheRepositories []LuetRepository `mapstructure:"repetitors"`
237
242
SystemRepositories []LuetRepository `mapstructure:"repositories"`
238
243
244
+ FinalizerEnvs []LuetKV `json:"finalizer_envs,omitempty" yaml:"finalizer_envs,omitempty" mapstructure:"finalizer_envs,omitempty"`
245
+
239
246
ConfigProtectConfFiles []ConfigProtectConfFile
240
247
}
241
248
@@ -284,6 +291,7 @@ func GenDefault(viper *v.Viper) {
284
291
viper .SetDefault ("config_from_host" , true )
285
292
viper .SetDefault ("cache_repositories" , []string {})
286
293
viper .SetDefault ("system_repositories" , []string {})
294
+ viper .SetDefault ("finalizer_envs" , make (map [string ]string , 0 ))
287
295
288
296
viper .SetDefault ("solver.type" , "" )
289
297
viper .SetDefault ("solver.rate" , 0.7 )
@@ -305,6 +313,58 @@ func (c *LuetConfig) AddSystemRepository(r LuetRepository) {
305
313
c .SystemRepositories = append (c .SystemRepositories , r )
306
314
}
307
315
316
+ func (c * LuetConfig ) GetFinalizerEnvsMap () map [string ]string {
317
+ ans := make (map [string ]string , 0 )
318
+
319
+ for _ , kv := range c .FinalizerEnvs {
320
+ ans [kv .Key ] = kv .Value
321
+ }
322
+ return ans
323
+ }
324
+
325
+ func (c * LuetConfig ) SetFinalizerEnv (k , v string ) {
326
+ keyPresent := false
327
+ envs := []LuetKV {}
328
+
329
+ for _ , kv := range c .FinalizerEnvs {
330
+ if kv .Key == k {
331
+ keyPresent = true
332
+ envs = append (envs , LuetKV {Key : kv .Key , Value : v })
333
+ } else {
334
+ envs = append (envs , kv )
335
+ }
336
+ }
337
+ if ! keyPresent {
338
+ envs = append (envs , LuetKV {Key : k , Value : v })
339
+ }
340
+
341
+ c .FinalizerEnvs = envs
342
+ }
343
+
344
+ func (c * LuetConfig ) GetFinalizerEnvs () []string {
345
+ ans := []string {}
346
+ for _ , kv := range c .FinalizerEnvs {
347
+ ans = append (ans , fmt .Sprintf ("%s=%s" , kv .Key , kv .Value ))
348
+ }
349
+ return ans
350
+ }
351
+
352
+ func (c * LuetConfig ) GetFinalizerEnv (k string ) (string , error ) {
353
+ keyNotPresent := true
354
+ ans := ""
355
+ for _ , kv := range c .FinalizerEnvs {
356
+ if kv .Key == k {
357
+ keyNotPresent = false
358
+ ans = kv .Value
359
+ }
360
+ }
361
+
362
+ if keyNotPresent {
363
+ return "" , errors .New ("Finalizer key " + k + " not found" )
364
+ }
365
+ return ans , nil
366
+ }
367
+
308
368
func (c * LuetConfig ) GetLogging () * LuetLoggingConfig {
309
369
return & c .Logging
310
370
}
0 commit comments