Skip to content

Commit 933edfd

Browse files
loresusopoiana
authored andcommitted
refactor: match config file to artifact install and follow commands
Signed-off-by: Lorenzo Susini <[email protected]>
1 parent 71daaaa commit 933edfd

File tree

3 files changed

+44
-44
lines changed

3 files changed

+44
-44
lines changed

internal/artifact/follow/follow.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ func NewArtifactFollowCmd(ctx context.Context, opt *options.CommonOptions) *cobr
9494
if f == nil {
9595
// should never happen
9696
o.Printer.CheckErr(fmt.Errorf("unable to retrieve flag every"))
97-
} else if !f.Changed && viper.IsSet(config.FollowerEveryKey) {
98-
val := viper.Get(config.FollowerEveryKey)
97+
} else if !f.Changed && viper.IsSet(config.ArtifactFollowEveryKey) {
98+
val := viper.Get(config.ArtifactFollowEveryKey)
9999
if err := cmd.Flags().Set(f.Name, fmt.Sprintf("%v", val)); err != nil {
100100
o.Printer.CheckErr(fmt.Errorf("unable to overwrite \"every\" flag: %w", err))
101101
}
@@ -106,8 +106,8 @@ func NewArtifactFollowCmd(ctx context.Context, opt *options.CommonOptions) *cobr
106106
if f == nil {
107107
// should never happen
108108
o.Printer.CheckErr(fmt.Errorf("unable to retrieve flag falco-versions"))
109-
} else if !f.Changed && viper.IsSet(config.FollowerFalcoVersionsKey) {
110-
val := viper.Get(config.FollowerFalcoVersionsKey)
109+
} else if !f.Changed && viper.IsSet(config.ArtifactFollowFalcoVersionsKey) {
110+
val := viper.Get(config.ArtifactFollowFalcoVersionsKey)
111111
if err := cmd.Flags().Set(f.Name, fmt.Sprintf("%v", val)); err != nil {
112112
o.Printer.CheckErr(fmt.Errorf("unable to overwrite \"falco-versions\" flag: %w", err))
113113
}
@@ -118,8 +118,8 @@ func NewArtifactFollowCmd(ctx context.Context, opt *options.CommonOptions) *cobr
118118
if f == nil {
119119
// should never happen
120120
o.Printer.CheckErr(fmt.Errorf("unable to retrieve flag rulesfiles-dir"))
121-
} else if !f.Changed && viper.IsSet(config.FollowerRulesfilesDirKey) {
122-
val := viper.Get(config.FollowerRulesfilesDirKey)
121+
} else if !f.Changed && viper.IsSet(config.ArtifactFollowRulesfilesDirKey) {
122+
val := viper.Get(config.ArtifactFollowRulesfilesDirKey)
123123
if err := cmd.Flags().Set(f.Name, fmt.Sprintf("%v", val)); err != nil {
124124
o.Printer.CheckErr(fmt.Errorf("unable to overwrite \"rulesfiles-dir\" flag: %w", err))
125125
}
@@ -130,8 +130,8 @@ func NewArtifactFollowCmd(ctx context.Context, opt *options.CommonOptions) *cobr
130130
if f == nil {
131131
// should never happen
132132
o.Printer.CheckErr(fmt.Errorf("unable to retrieve flag plugins-dir"))
133-
} else if !f.Changed && viper.IsSet(config.FollowerPluginsDirKey) {
134-
val := viper.Get(config.FollowerPluginsDirKey)
133+
} else if !f.Changed && viper.IsSet(config.ArtifactFollowPluginsDirKey) {
134+
val := viper.Get(config.ArtifactFollowPluginsDirKey)
135135
if err := cmd.Flags().Set(f.Name, fmt.Sprintf("%v", val)); err != nil {
136136
o.Printer.CheckErr(fmt.Errorf("unable to overwrite \"plugins-dir\" flag: %w", err))
137137
}
@@ -142,8 +142,8 @@ func NewArtifactFollowCmd(ctx context.Context, opt *options.CommonOptions) *cobr
142142
if f == nil {
143143
// should never happen
144144
o.Printer.CheckErr(fmt.Errorf("unable to retrieve flag working-dir"))
145-
} else if !f.Changed && viper.IsSet(config.FollowerWorkingDirKey) {
146-
val := viper.Get(config.FollowerWorkingDirKey)
145+
} else if !f.Changed && viper.IsSet(config.ArtifactFollowWorkingDirKey) {
146+
val := viper.Get(config.ArtifactFollowWorkingDirKey)
147147
if err := cmd.Flags().Set(f.Name, fmt.Sprintf("%v", val)); err != nil {
148148
o.Printer.CheckErr(fmt.Errorf("unable to overwrite \"working-dir\" flag: %w", err))
149149
}

internal/artifact/install/install.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ func NewArtifactInstallCmd(ctx context.Context, opt *options.CommonOptions) *cob
5656
if f == nil {
5757
// should never happen
5858
o.Printer.CheckErr(fmt.Errorf("unable to retrieve flag rulesfiles-dir"))
59-
} else if !f.Changed && viper.IsSet(config.InstallerRulesfilesDirKey) {
60-
val := viper.Get(config.InstallerRulesfilesDirKey)
59+
} else if !f.Changed && viper.IsSet(config.ArtifactInstallRulesfilesDirKey) {
60+
val := viper.Get(config.ArtifactInstallRulesfilesDirKey)
6161
if err := cmd.Flags().Set(f.Name, fmt.Sprintf("%v", val)); err != nil {
6262
o.Printer.CheckErr(fmt.Errorf("unable to overwrite \"rulesfiles-dir\" flag: %w", err))
6363
}
@@ -68,8 +68,8 @@ func NewArtifactInstallCmd(ctx context.Context, opt *options.CommonOptions) *cob
6868
if f == nil {
6969
// should never happen
7070
o.Printer.CheckErr(fmt.Errorf("unable to retrieve flag plugins-dir"))
71-
} else if !f.Changed && viper.IsSet(config.InstallerPluginsDirKey) {
72-
val := viper.Get(config.InstallerPluginsDirKey)
71+
} else if !f.Changed && viper.IsSet(config.ArtifactInstallPluginsDirKey) {
72+
val := viper.Get(config.ArtifactInstallPluginsDirKey)
7373
if err := cmd.Flags().Set(f.Name, fmt.Sprintf("%v", val)); err != nil {
7474
o.Printer.CheckErr(fmt.Errorf("unable to overwrite \"plugins-dir\" flag: %w", err))
7575
}

internal/config/config.go

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -66,24 +66,24 @@ const (
6666
BasicAuthsKey = "basicauths"
6767
// IndexesKey is the Viper key for indexes configuration.
6868
IndexesKey = "indexes"
69-
// FollowerEveryKey is the Viper key for follower "every" configuration.
70-
FollowerEveryKey = "follower.every"
71-
// FollowerArtifactsKey is the Viper key for follower "artifacts" configuration.
72-
FollowerArtifactsKey = "follower.artifacts"
73-
// FollowerFalcoVersionsKey is the Viper key for follower "falcoVersions" configuration.
74-
FollowerFalcoVersionsKey = "follower.falcoversions"
75-
// FollowerRulesfilesDirKey is the Viper key for follower "rulesFilesDir" configuration.
76-
FollowerRulesfilesDirKey = "follower.rulesfilesdir"
77-
// FollowerPluginsDirKey is the Viper key for follower "pluginsDir" configuration.
78-
FollowerPluginsDirKey = "follower.pluginsdir"
79-
// FollowerWorkingDirKey is the Viper key for follower "pluginsDir" configuration.
80-
FollowerWorkingDirKey = "follower.workingdir"
81-
// InstallerArtifactsKey is the Viper key for installer "artifacts" configuration.
82-
InstallerArtifactsKey = "installer.artifacts"
83-
// InstallerRulesfilesDirKey is the Viper key for follower "rulesFilesDir" configuration.
84-
InstallerRulesfilesDirKey = "installer.rulesfilesdir"
85-
// InstallerPluginsDirKey is the Viper key for follower "pluginsDir" configuration.
86-
InstallerPluginsDirKey = "installer.pluginsdir"
69+
// ArtifactFollowEveryKey is the Viper key for follower "every" configuration.
70+
ArtifactFollowEveryKey = "artifact.follow.every"
71+
// ArtifactFollowRefsKey is the Viper key for follower "artifacts" configuration.
72+
ArtifactFollowRefsKey = "artifact.follow.refs"
73+
// ArtifactFollowFalcoVersionsKey is the Viper key for follower "falcoVersions" configuration.
74+
ArtifactFollowFalcoVersionsKey = "artifact.follow.falcoversions"
75+
// ArtifactFollowRulesfilesDirKey is the Viper key for follower "rulesFilesDir" configuration.
76+
ArtifactFollowRulesfilesDirKey = "artifact.follow.rulesfilesdir"
77+
// ArtifactFollowPluginsDirKey is the Viper key for follower "pluginsDir" configuration.
78+
ArtifactFollowPluginsDirKey = "artifact.follow.pluginsdir"
79+
// ArtifactFollowWorkingDirKey is the Viper key for follower "pluginsDir" configuration.
80+
ArtifactFollowWorkingDirKey = "artifact.follow.workingdir"
81+
// ArtifactInstallArtifactsKey is the Viper key for installer "artifacts" configuration.
82+
ArtifactInstallArtifactsKey = "artifact.install.refs"
83+
// ArtifactInstallRulesfilesDirKey is the Viper key for follower "rulesFilesDir" configuration.
84+
ArtifactInstallRulesfilesDirKey = "artifact.install.rulesfilesdir"
85+
// ArtifactInstallPluginsDirKey is the Viper key for follower "pluginsDir" configuration.
86+
ArtifactInstallPluginsDirKey = "artifact.install.pluginsdir"
8787
)
8888

8989
// Index represents a configured index.
@@ -159,9 +159,9 @@ func Load(path string) error {
159159
viper.SetDefault(IndexesKey, []Index{DefaultIndex})
160160

161161
// Set default follower options
162-
viper.SetDefault(FollowerEveryKey, DefaultFollower.Every)
163-
viper.SetDefault(FollowerArtifactsKey, DefaultFollower.Artifacts)
164-
viper.SetDefault(FollowerFalcoVersionsKey, DefaultFollower.FalcoVersions)
162+
viper.SetDefault(ArtifactFollowEveryKey, DefaultFollower.Every)
163+
viper.SetDefault(ArtifactFollowRefsKey, DefaultFollower.Artifacts)
164+
viper.SetDefault(ArtifactFollowFalcoVersionsKey, DefaultFollower.FalcoVersions)
165165

166166
err = viper.ReadInConfig()
167167
if errors.As(err, &viper.ConfigFileNotFoundError{}) || os.IsNotExist(err) {
@@ -346,34 +346,34 @@ func oathAuthListHookFunc() mapstructure.DecodeHookFuncType {
346346
func Follower() (Follow, error) {
347347
// with Follow we can just use nested keys.
348348
// env variables can just make use of ";" to separat
349-
artifacts := viper.GetStringSlice(FollowerArtifactsKey)
349+
artifacts := viper.GetStringSlice(ArtifactFollowRefsKey)
350350
if len(artifacts) == 1 { // in this case it might come from the env
351351
artifacts = strings.Split(artifacts[0], ";")
352352
}
353353

354354
return Follow{
355-
Every: viper.GetDuration(FollowerEveryKey),
355+
Every: viper.GetDuration(ArtifactFollowEveryKey),
356356
Artifacts: artifacts,
357-
FalcoVersions: viper.GetString(FollowerFalcoVersionsKey),
358-
RulesfilesDir: viper.GetString(FollowerRulesfilesDirKey),
359-
PluginsDir: viper.GetString(FollowerPluginsDirKey),
360-
WorkingDir: viper.GetString(FollowerWorkingDirKey),
357+
FalcoVersions: viper.GetString(ArtifactFollowFalcoVersionsKey),
358+
RulesfilesDir: viper.GetString(ArtifactFollowRulesfilesDirKey),
359+
PluginsDir: viper.GetString(ArtifactFollowPluginsDirKey),
360+
WorkingDir: viper.GetString(ArtifactFollowWorkingDirKey),
361361
}, nil
362362
}
363363

364364
// Installer retrieves the installer section of the config file.
365365
func Installer() (Install, error) {
366366
// with Install we can just use nested keys.
367367
// env variables can just make use of ";" to separat
368-
artifacts := viper.GetStringSlice(InstallerArtifactsKey)
368+
artifacts := viper.GetStringSlice(ArtifactInstallArtifactsKey)
369369
if len(artifacts) == 1 { // in this case it might come from the env
370370
artifacts = strings.Split(artifacts[0], ";")
371371
}
372372

373373
return Install{
374374
Artifacts: artifacts,
375-
RulesfilesDir: viper.GetString(InstallerRulesfilesDirKey),
376-
PluginsDir: viper.GetString(InstallerPluginsDirKey),
375+
RulesfilesDir: viper.GetString(ArtifactInstallRulesfilesDirKey),
376+
PluginsDir: viper.GetString(ArtifactInstallPluginsDirKey),
377377
}, nil
378378
}
379379

0 commit comments

Comments
 (0)