cleanup logging a bit
This commit is contained in:
parent
0e692ac43c
commit
0512f043cf
7
cmds.go
7
cmds.go
@ -6,6 +6,7 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Command struct {
|
||||
@ -19,8 +20,11 @@ type Command struct {
|
||||
func (c *Command) Run(fp string) bool {
|
||||
cmd := &exec.Cmd{}
|
||||
if len(c.Args) == 0 {
|
||||
cmd = exec.Command(c.Path, fmt.Sprintf(c.MsgFormat, fp))
|
||||
msg := fmt.Sprintf(c.MsgFormat, fp)
|
||||
log.Printf("running %q\n", fmt.Sprintf("%s %s", c.Path, msg))
|
||||
cmd = exec.Command(c.Path, msg)
|
||||
} else {
|
||||
log.Printf("running %q\n", fmt.Sprintf("%s %s", c.Path, strings.Join(c.Args, " ")))
|
||||
cmd = exec.Command(c.Path, c.Args...)
|
||||
}
|
||||
|
||||
@ -39,6 +43,7 @@ func (c *Command) Run(fp string) bool {
|
||||
if exit.ExitCode() == c.AllowExitCode {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
|
9
main.go
9
main.go
@ -30,6 +30,8 @@ func main() {
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
cmds := LoadCommands(*cmdList)
|
||||
tagent := Traygent{
|
||||
listener: l,
|
||||
addChan: make(chan ssh.PublicKey),
|
||||
@ -57,26 +59,21 @@ func main() {
|
||||
}
|
||||
}()
|
||||
|
||||
cmds := LoadCommands(*cmdList)
|
||||
|
||||
for {
|
||||
select {
|
||||
case added := <-tagent.addChan:
|
||||
fp := ssh.FingerprintSHA256(added)
|
||||
log.Printf("NOTICE: added %q\n", fp)
|
||||
c := cmds.Get("added")
|
||||
if c != nil {
|
||||
c.Run(fp)
|
||||
}
|
||||
case rm := <-tagent.rmChan:
|
||||
log.Printf("NOTICE: removed %q\n", rm)
|
||||
c := cmds.Get("removed")
|
||||
if c != nil {
|
||||
c.Run(rm)
|
||||
}
|
||||
case pub := <-tagent.sigReq:
|
||||
fp := ssh.FingerprintSHA256(pub)
|
||||
log.Printf("NOTICE: access request for: %q?\n", fp)
|
||||
c := cmds.Get("sign")
|
||||
if c != nil {
|
||||
if c.Run(fp) {
|
||||
@ -84,8 +81,6 @@ func main() {
|
||||
} else {
|
||||
go func() { tagent.sigResp <- false }()
|
||||
}
|
||||
} else {
|
||||
panic("nope")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user