fix: Expand tilde in GitHub App privateKeyPath

Merged
KE
5mo ago
+33-1

What type of PR is this?

/kind bug

What this PR does / why we need it:

ensureGitHubAppSecret in internal/cli/run.go passed appCfg.PrivateKeyPath directly to os.ReadFile, which does not perform shell-style tilde expansion. A user following the documented examples (README and docs/reference.md both use ~/.config/my-app.private-key.pem) hit a misleading error:

reading private key file ~/.config/my-app.private-key.pem: open ~/.config/my-app.private-key.pem: no such file or directory

This change calls the existing expandHome helper (already used by resolveContent for @file CLI flag paths) on the configured path before the file read, so leading ~ and ~/ resolve to the user's home directory.

A unit test covering a tilde-prefixed privateKeyPath is added.

Which issue(s) this PR is related to:

Fixes #1134

Special notes for your reviewer:

The outer error message intentionally still references the original appCfg.PrivateKeyPath (with the literal ~) so users see the path they configured; the wrapped os.ReadFile error includes the expanded path for diagnostic purposes.

Does this PR introduce a user-facing change?

Fix `kelos run` failing with "no such file or directory" when workspace `githubApp.privateKeyPath` uses a leading `~` (now expanded to the user's home directory).

Summary by cubic

Expands tilde in the GitHub App privateKeyPath before reading the key to prevent "no such file or directory" when using ~-based paths. Adds a regression test to cover this case.

  • Bug Fixes
    • Apply expandHome to privateKeyPath before os.ReadFile, resolving ~ and ~/ to the user’s home directory.
    • Add a test verifying the expanded path is used (regression for #1134).