Make the Vault gitea creds path selectable
agentpr always read gitea/creds/unkin-agent from a bare const, so a service like repospawner could not run it as its own Gitea identity. - Replace the GiteaCredsPath const with a function: GITEA_CREDS_PATH when set, otherwise gitea/creds/<AGENT_LOGIN>. Unset env still resolves to gitea/creds/unkin-agent, so existing callers are unchanged. - Thread the creds path through fetchGiteaToken/readGiteaCreds instead of reading a package-level const, and report it in the error messages. - Make agentpr's help text login-agnostic and document both variables.
This commit is contained in:
+7
-7
@@ -1,7 +1,7 @@
|
||||
// Command agentpr manages Gitea pull requests and comments as the unkin-agent
|
||||
// user. It obtains a scoped Gitea token from Vault (AppRole login, then reads
|
||||
// gitea/creds/unkin-agent) so actions are attributed to the agent rather than
|
||||
// to whoever runs the tool.
|
||||
// Command agentpr manages Gitea pull requests and comments as an agent user. It
|
||||
// obtains a scoped Gitea token from Vault (AppRole login, then reads
|
||||
// gitea/creds/<AGENT_LOGIN>, or GITEA_CREDS_PATH when set) so actions are
|
||||
// attributed to that agent rather than to whoever runs the tool.
|
||||
//
|
||||
// agentpr pr create --repo owner/repo --base main --head feature --title T --body B
|
||||
// agentpr pr comment --repo owner/repo --pr 12 --body "..."
|
||||
@@ -33,8 +33,8 @@ func main() {
|
||||
func newRootCmd() *cobra.Command {
|
||||
root := &cobra.Command{
|
||||
Use: "agentpr",
|
||||
Short: "Manage Gitea PRs and comments as the unkin-agent user.",
|
||||
Long: "agentpr manages Gitea pull requests and comments as unkin-agent, using a\nGitea token minted from Vault (AppRole login + gitea/creds/unkin-agent).",
|
||||
Short: "Manage Gitea PRs and comments as an agent user.",
|
||||
Long: "agentpr manages Gitea pull requests and comments as an agent user, using a\nGitea token minted from Vault (AppRole login + gitea/creds/<AGENT_LOGIN>).\nSet AGENT_LOGIN to act as another agent identity, or GITEA_CREDS_PATH to name\nthe Vault creds path outright.",
|
||||
Version: version,
|
||||
SilenceUsage: true,
|
||||
}
|
||||
@@ -146,7 +146,7 @@ func newPRCommentCmd() *cobra.Command {
|
||||
func newWhoamiCmd() *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "whoami",
|
||||
Short: "Print the authenticated Gitea login (should be unkin-agent)",
|
||||
Short: "Print the authenticated Gitea login (the identity PRs are opened as)",
|
||||
SilenceUsage: true,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
c, err := client()
|
||||
|
||||
Reference in New Issue
Block a user