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