Skip to content

Commit

Permalink
chore: refine code for signers
Browse files Browse the repository at this point in the history
  • Loading branch information
yankeguo committed Jan 23, 2024
1 parent f228a7c commit 4d3f00e
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions signers.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,26 @@ func loadOrCreateSigner(log *zap.SugaredLogger, filename string, generator SSHPr
func createSigners(log *zap.SugaredLogger, dir DataDir) (signers *Signers, err error) {
signers = &Signers{}

for kind, generator := range sshPrivateKeyGenerators {
var sgn ssh.Signer
if sgn, err = loadOrCreateSigner(log, filepath.Join(dir.String(), "ssh_host_"+kind+"_key"), generator); err != nil {
return
}
signers.Host = append(signers.Host, sgn)
}

for kind, generator := range sshPrivateKeyGenerators {
var sgn ssh.Signer
if sgn, err = loadOrCreateSigner(log, filepath.Join(dir.String(), "ssh_client_"+kind+"_key"), generator); err != nil {
return
for _, item := range []struct {
output *[]ssh.Signer
prefix string
}{
{
output: &signers.Host,
prefix: "ssh_host_",
},
{
output: &signers.Client,
prefix: "ssh_client_",
},
} {
for kind, generator := range sshPrivateKeyGenerators {
var sgn ssh.Signer
if sgn, err = loadOrCreateSigner(log, filepath.Join(dir.String(), item.prefix+kind+"_key"), generator); err != nil {
return
}
*item.output = append(*item.output, sgn)
}
signers.Client = append(signers.Client, sgn)
}

for _, sgn := range signers.Client {
Expand Down

0 comments on commit 4d3f00e

Please sign in to comment.