grim/hgkeeper

dc46af0b583b
Spit out a warning if we find a duplicated key.

We're going to continue the existing behavior of overwriting the keys to not
break potential set ups for the time being.

Fixes HGKEEPER-22
package authorized_keys
import (
"fmt"
"strings"
log "github.com/sirupsen/logrus"
"keep.imfreedom.org/grim/hgkeeper/access"
"keep.imfreedom.org/grim/hgkeeper/globals"
)
type Command struct {
FingerPrint string `kong:"arg,help='The fingerprint of the calling user'"`
HGKeeperExec string `kong:"flag,help='The path to hgkeeper executable',default='hgkeeper'"`
}
func (c *Command) Run(g *globals.Globals) error {
// we're generating output for another command so we need to turn off our
// normal logging.
log.SetLevel(log.FatalLevel)
if err := access.Setup(g.ReposPath, g.AdminRepo); err != nil {
return err
}
defer access.Teardown()
pubkey, err := access.PubkeyFromFingerprint(c.FingerPrint)
if err != nil {
return err
}
username, err := access.UsernameFromFingerprint(c.FingerPrint)
if err != nil {
return err
}
options := []string{
fmt.Sprintf("command=\"%s once %s\"", c.HGKeeperExec, username),
"restrict",
fmt.Sprintf("environment=\"HGK_REPOS_PATH=%s\"", g.ReposPath),
}
fmt.Printf("%s %s", strings.Join(options, ","), pubkey)
return nil
}