command to retrieve token#124
Conversation
|
It would be nice to have an option to specify hostname or URL in the key command, and use the same command for all forges. Some password databases come organized like that. |
Can you give an example of what you want ? For the moment : |
|
eg. in here You can see subprocess.check_output(['secret-tool', 'lookup', 'service', host, 'username', self.user]) That is same command used for every forge, and looked up by the 'service' tag. The 'host' argument is the host name of the forge. This is a database that is arbitrarily created like this by another tool, the secret-tool is generic tagged storage that does not itself interpret the tags in any way. |
|
Your solution still makes it possible (hopefully) to manually configure for each forge something like token = !secret-tool lookup service github.com type token or somesuch but does not provide the option to configure such command globally replacing the 'github.com' with the hostname of the forge. |
|
the command has now the environment so your example can be written as: token = !secret-tool lookup service $FORGE_DOMAIN type token |
andrew
left a comment
There was a problem hiding this comment.
Thanks for picking up #67. The ! prefix matches what people know from git's credential.helper, and the allowTokens=false guard correctly stops a checked-in .forge from running arbitrary commands, which is the obvious trap here. Good that there's an explicit test for it.
The main thing blocking this is the execution model: token commands run eagerly at config parse time, for every domain, on every invocation. See inline comments. Making resolution lazy (store the raw value, exec only when that domain's token is actually needed) fixes most of the issues at once.
Small thing: "retreive" → "retrieve" in the PR title.
andrew
left a comment
There was a problem hiding this comment.
Thanks for the rework — all the points from the last round are addressed (lazy resolution, --token-cmd, stderr/stdin wiring, escape-sequence handling, ! stripped from display).
The branch doesn't compile though; looks like the rebase left some damage in auth.go — see inline. Once that's sorted I'm happy to merge.
|
There is also the thing that storing the token retrieval command in the same field as the token is probably fairly bad design. While there are no known tokens that can start with a ! at the moment it can change, or when passwords or other authentication methods are supported in the future it will change. There is a possibility to use different field for this, or a type flag that tells how to interpret the existing field. Without either this is bound to break. |
local stuff accidentaly added !
There is a separate field : func authLoginCmd() *cobra.Command {
var (
domain string
token string
+ tokenCmd string
forgeType string
)So maybe the design is not so fairly bad ? 😉 |
`rootCmd`` is a package-level variable in interal/cli/root.go, shared across all tests in the cli package. Cobra does not reset flag values or their Changed state between `Execute()` calls, so a flag set by one test leaks into the next. This commit adds a `resetCmd` helper that recursively walks the command tree and restores each flag to its default value and `Changed=false`. Let's call it at the start of each test that invokes `rootCmd.Execute()`.
|
In https://github.com/git-pkgs/forge/pull/124/commits/0a9d4554cba93eb14f196589d596b60ce731fe80` I also added a test helper to reset |
That's not what the docs say: [github.com] token = !rbw get github-token |
[github.com]
token = ghp_abc123
[gitlab.com]
token-cmd = rbw get gitlab-token ? |
Yes, the config file is the actual user-visible API, the internal representation can be changed without anyone noticing. This is one way to do it. There is the open question what happens when both |
Error, not permitted I suppose. |
|
Reporting an error is an option. Some priority scheme is another but that is not much better in the end, some weird patchy configuration file may contain data that would allow accessing the forge but it's not used in the end. |
closes #67
Instead of storing a token in plain text, a config entry can now reference a shell command prefixed with !. The command is executed at runtime and its stdout is used as the token, enabling integration with password managers such as
rbworpass.forge auth logingains a Ctrl+E shortcut at the token prompt to enter a command interactively.forge auth statusdisplays the command.