mirror of
https://github.com/Mic92/sops-nix.git
synced 2026-01-01 02:14:59 +08:00
Also print imported age keys
This commit is contained in:
parent
33041373c9
commit
cb4c79633d
1 changed files with 9 additions and 5 deletions
|
|
@ -619,14 +619,14 @@ func importSSHKeys(logcfg loggingConfig, keyPaths []string, gpgHome string) erro
|
|||
}
|
||||
|
||||
if logcfg.KeyImport {
|
||||
fmt.Printf("%s: Imported %s with fingerprint %s\n", path.Base(os.Args[0]), p, hex.EncodeToString(gpgKey.PrimaryKey.Fingerprint[:]))
|
||||
fmt.Printf("%s: Imported %s as GPG key with fingerprint %s\n", path.Base(os.Args[0]), p, hex.EncodeToString(gpgKey.PrimaryKey.Fingerprint[:]))
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func importAgeSSHKeys(keyPaths []string, ageFile os.File) error {
|
||||
func importAgeSSHKeys(logcfg loggingConfig, keyPaths []string, ageFile os.File) error {
|
||||
for _, p := range keyPaths {
|
||||
// Read the key
|
||||
sshKey, err := ioutil.ReadFile(p)
|
||||
|
|
@ -634,15 +634,19 @@ func importAgeSSHKeys(keyPaths []string, ageFile os.File) error {
|
|||
return fmt.Errorf("Cannot read ssh key '%s': %w", p, err)
|
||||
}
|
||||
// Convert the key to age
|
||||
bech32, err := agessh.SSHPrivateKeyToAge(sshKey)
|
||||
privKey, pubKey, err := agessh.SSHPrivateKeyToAge(sshKey)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Cannot convert ssh key '%s': %w", p, err)
|
||||
}
|
||||
// Append it to the file
|
||||
_, err = ageFile.WriteString(*bech32 + "\n")
|
||||
_, err = ageFile.WriteString(*privKey + "\n")
|
||||
if err != nil {
|
||||
return fmt.Errorf("Cannot write key to age file: %w", err)
|
||||
}
|
||||
|
||||
if logcfg.KeyImport {
|
||||
fmt.Printf("%s: Imported %s as age key with fingerprint %s\n", path.Base(os.Args[0]), p, *pubKey)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
@ -925,7 +929,7 @@ func installSecrets(args []string) error {
|
|||
|
||||
// Import SSH keys
|
||||
if len(manifest.AgeSshKeyPaths) != 0 {
|
||||
err = importAgeSSHKeys(manifest.AgeSshKeyPaths, *ageFile)
|
||||
err = importAgeSSHKeys(manifest.Logging, manifest.AgeSshKeyPaths, *ageFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue