diff options
author | Teddy Wing | 2017-06-03 21:36:20 +0200 |
---|---|---|
committer | Teddy Wing | 2017-06-03 21:37:43 +0200 |
commit | f5b1fb3d0ef37ed44b8f7302343dcd5cd16bd725 (patch) | |
tree | 58b43be49d3e470d68543ced658c22c9ea07bf9b /password_cmd.go | |
parent | 403c92bf583cec66677d93ea470ec58312c8240b (diff) | |
download | timetasker-f5b1fb3d0ef37ed44b8f7302343dcd5cd16bd725.tar.bz2 |
Make the `password_cmd` config setting work
Given a string from `password_cmd`, we should execute it as a shell
command and assume the result is a password. That password then gets
submitted to TimeTask's login form for authentication.
Had to do a bit of wrangling to get the command to execute by
`exec.Command()`, but managed to get it working in a bit of a roundabout
way.
Found these resources in my searches:
- https://stackoverflow.com/questions/39930109/golang-execute-command#39930127
https://stackoverflow.com/questions/28783637/how-to-make-golang-execute-a-string
- https://stackoverflow.com/questions/20437336/how-to-execute-system-command-in-golang-with-unknown-arguments
- https://github.com/codeskyblue/go-sh
Diffstat (limited to 'password_cmd.go')
-rw-r--r-- | password_cmd.go | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/password_cmd.go b/password_cmd.go new file mode 100644 index 0000000..821c8f6 --- /dev/null +++ b/password_cmd.go @@ -0,0 +1,22 @@ +package main + +import ( + "os" + "os/exec" +) + +// Execute the given string as a shell command and return the resulting output +func passwordCmd(password_cmd string) (password string, err error) { + shell := os.Getenv("SHELL") + + // `Command` requires us to pass shell arguments as parameters to the + // function, but we don't know what the arguments are because + // `password_cmd` is an arbitrary command. To get around this, we pass the + // password command to the current shell to execute. + output, err := exec.Command(shell, "-c", password_cmd).Output() + if err != nil { + return "", err + } + + return string(output), nil +} |