Skip to content

Commit dfa06f8

Browse files
committed
Fix kong config handling and name expansion
* Fix up the janky config handling that claude wrote for me * stop using env var for command and allow renaming binary to imply command
1 parent 68572bb commit dfa06f8

File tree

3 files changed

+14
-30
lines changed

3 files changed

+14
-30
lines changed

cmd/epithet/main.go

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ var cli struct {
2323
Version kong.VersionFlag `short:"V" help:"Print version information"`
2424
Verbose int `short:"v" type:"counter" help:"Increase verbosity (-v for debug, -vv for trace)"`
2525
LogFile string `name:"log-file" help:"Path to log file (supports ~ expansion)" env:"EPITHET_LOG_FILE"`
26-
Config kong.ConfigFlag `help:"Path to config file"`
26+
Config kongcue.Config `help:"Path to config file" default:"~/.epithet/*.yaml,~/.epithet/*.yml,~/.epithet/*.cue,~/.epithet/*.json"`
2727

2828
// TLS configuration flags (global)
2929
Insecure bool `help:"Disable TLS certificate verification (NOT RECOMMENDED)" env:"EPITHET_INSECURE"`
@@ -37,30 +37,17 @@ var cli struct {
3737
}
3838

3939
func main() {
40-
// Check if we're running in Lambda mode via environment variable
41-
if epithetCmd := os.Getenv("EPITHET_CMD"); epithetCmd != "" {
42-
// Parse the command from environment (e.g., "aws ca")
43-
args := strings.Fields(epithetCmd)
44-
os.Args = append([]string{os.Args[0]}, args...)
45-
}
46-
47-
// Load and unify config files
48-
configPaths := []string{
49-
"~/.epithet/*.yaml",
50-
"~/.epithet/*.yml",
51-
"~/.epithet/*.cue",
52-
"~/.epithet/*.json",
53-
}
54-
55-
unifiedConfig, err := kongcue.LoadAndUnifyPaths(configPaths)
56-
if err != nil {
57-
slog.Error("failed to load config", "error", err)
58-
os.Exit(1)
40+
// we also allow command to be named epithet-agent and such, to imply a command
41+
if baseName := filepath.Base(os.Args[0]); strings.Contains(baseName, "-") {
42+
parts := strings.SplitN(baseName, "-", 2)
43+
if len(parts) == 2 {
44+
// Transform [epithet-policy, --woof, --meow] -> [epithet, policy, --woof, --meow]
45+
os.Args = append([]string{parts[0], parts[1]}, os.Args[1:]...)
46+
}
5947
}
6048

6149
ktx := kong.Parse(&cli,
6250
kong.Vars{"version": version + " (" + commit + ", " + date + ")"},
63-
kong.Resolvers(kongcue.NewResolver(unifiedConfig)),
6451
)
6552
logger := setupLogger()
6653

@@ -72,8 +59,7 @@ func main() {
7259

7360
ktx.Bind(logger)
7461
ktx.Bind(tlsCfg)
75-
ktx.Bind(unifiedConfig) // Bind CUE value for commands that need full config (e.g., policy)
76-
err = ktx.Run()
62+
err := ktx.Run()
7763
if err != nil {
7864
logger.Error("error", "error", err)
7965
os.Exit(1)

go.mod

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,10 @@ require (
3232
github.com/int128/listener v1.3.0 // indirect
3333
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
3434
github.com/opencontainers/go-digest v1.0.0 // indirect
35-
github.com/opencontainers/image-spec v1.1.1 // indirect
3635
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
3736
github.com/pkg/errors v0.9.1 // indirect
3837
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
3938
github.com/protocolbuffers/txtpbfmt v0.0.0-20251124094003-fcb97cc64c7b // indirect
40-
github.com/rogpeppe/go-internal v1.14.1 // indirect
4139
github.com/secure-systems-lab/go-securesystemslib v0.9.1 // indirect
4240
github.com/sigstore/protobuf-specs v0.5.0 // indirect
4341
github.com/sigstore/sigstore v1.10.0 // indirect
@@ -52,4 +50,4 @@ require (
5250
gopkg.in/yaml.v3 v3.0.1 // indirect
5351
)
5452

55-
require github.com/brianm/kongcue v0.0.3
53+
require github.com/brianm/kongcue v0.0.5

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ github.com/alecthomas/repr v0.5.2 h1:SU73FTI9D1P5UNtvseffFSGmdNci/O6RsqzeXJtP0Qs
1010
github.com/alecthomas/repr v0.5.2/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4=
1111
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 h1:DklsrG3dyBCFEj5IhUbnKptjxatkF07cF2ak3yi77so=
1212
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw=
13-
github.com/brianm/kongcue v0.0.2 h1:M4flU9mHn42zRNsr8u8F+v0YN9bcVCE+OoNnkWMhTN4=
14-
github.com/brianm/kongcue v0.0.2/go.mod h1:qOIMLB26kkEXsYeySsnEV5iKg/pwCESNAAGvLyoXSbY=
15-
github.com/brianm/kongcue v0.0.3 h1:v90uLLQs1E9eh0re0JnRmP4N7MEsPBXungmsDP4trBw=
16-
github.com/brianm/kongcue v0.0.3/go.mod h1:mK5P6Z4xIurnR0SlehqrbYjVu4k5nq7csMYrHbW5jD8=
13+
github.com/brianm/kongcue v0.0.4 h1:cZKknHIK5W34m8eJ6JvVrpNVNp+jKZQeoK6LjCdEYxo=
14+
github.com/brianm/kongcue v0.0.4/go.mod h1:mK5P6Z4xIurnR0SlehqrbYjVu4k5nq7csMYrHbW5jD8=
15+
github.com/brianm/kongcue v0.0.5 h1:kmP1/i9jUr/TPmYtWdHIBQ2pGdXMiQKL9HaKEMYTFDw=
16+
github.com/brianm/kongcue v0.0.5/go.mod h1:mK5P6Z4xIurnR0SlehqrbYjVu4k5nq7csMYrHbW5jD8=
1717
github.com/cbroglie/mustache v1.4.0 h1:Azg0dVhxTml5me+7PsZ7WPrQq1Gkf3WApcHMjMprYoU=
1818
github.com/cbroglie/mustache v1.4.0/go.mod h1:SS1FTIghy0sjse4DUVGV1k/40B1qE1XkD9DtDsHo9iM=
1919
github.com/cockroachdb/apd/v3 v3.2.1 h1:U+8j7t0axsIgvQUqthuNm82HIrYXodOV2iWLWtEaIwg=

0 commit comments

Comments
 (0)