lib, pgp: Remove direct logger usage
This cleans things up a little bit more.
This commit is contained in:
@@ -388,6 +388,9 @@ func (obj *Main) Run() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !obj.NoPgp {
|
if !obj.NoPgp {
|
||||||
|
pgpLogf := func(format string, v ...interface{}) {
|
||||||
|
obj.Logf("pgp: "+format, v...)
|
||||||
|
}
|
||||||
pgpPrefix := fmt.Sprintf("%s/", path.Join(prefix, "pgp"))
|
pgpPrefix := fmt.Sprintf("%s/", path.Join(prefix, "pgp"))
|
||||||
if err := os.MkdirAll(pgpPrefix, 0770); err != nil {
|
if err := os.MkdirAll(pgpPrefix, 0770); err != nil {
|
||||||
return errwrap.Wrapf(err, "can't create pgp prefix")
|
return errwrap.Wrapf(err, "can't create pgp prefix")
|
||||||
@@ -403,6 +406,9 @@ func (obj *Main) Run() error {
|
|||||||
if obj.pgpKeys, err = pgp.Import(pgpKeyringPath); err != nil && !os.IsNotExist(err) {
|
if obj.pgpKeys, err = pgp.Import(pgpKeyringPath); err != nil && !os.IsNotExist(err) {
|
||||||
return errwrap.Wrapf(err, "can't import pgp key")
|
return errwrap.Wrapf(err, "can't import pgp key")
|
||||||
}
|
}
|
||||||
|
if obj.pgpKeys != nil { // it might have not been created!
|
||||||
|
pgpLogf("imported key: %s", obj.pgpKeys.Entity.PrivateKey.KeyIdShortString())
|
||||||
|
}
|
||||||
|
|
||||||
if obj.pgpKeys == nil {
|
if obj.pgpKeys == nil {
|
||||||
identity := fmt.Sprintf("%s <%s> %s", obj.Program, "root@"+hostname, "generated by "+obj.Program)
|
identity := fmt.Sprintf("%s <%s> %s", obj.Program, "root@"+hostname, "generated by "+obj.Program)
|
||||||
@@ -420,6 +426,7 @@ func (obj *Main) Run() error {
|
|||||||
if obj.pgpKeys, err = pgp.Generate(name, comment, email, nil); err != nil {
|
if obj.pgpKeys, err = pgp.Generate(name, comment, email, nil); err != nil {
|
||||||
return errwrap.Wrapf(err, "can't create pgp key")
|
return errwrap.Wrapf(err, "can't create pgp key")
|
||||||
}
|
}
|
||||||
|
pgpLogf("created key: %s", obj.pgpKeys.Entity.PrivateKey.KeyIdShortString())
|
||||||
|
|
||||||
if err := obj.pgpKeys.SaveKey(pgpKeyringPath); err != nil {
|
if err := obj.pgpKeys.SaveKey(pgpKeyringPath); err != nil {
|
||||||
return errwrap.Wrapf(err, "can't save pgp key")
|
return errwrap.Wrapf(err, "can't save pgp key")
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ import (
|
|||||||
"crypto"
|
"crypto"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -81,7 +80,6 @@ func Import(privKeyPath string) (*PGP, error) {
|
|||||||
Entity: entity,
|
Entity: entity,
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("PGP: Imported key: %s", obj.Entity.PrivateKey.KeyIdShortString())
|
|
||||||
return obj, nil
|
return obj, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,7 +99,6 @@ func Generate(name, comment, email string, hash *crypto.Hash) (*PGP, error) {
|
|||||||
Entity: entity,
|
Entity: entity,
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("PGP: Created key: %s", obj.Entity.PrivateKey.KeyIdShortString())
|
|
||||||
return obj, nil
|
return obj, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user