继续完善按服务器管理SSH密钥
This commit is contained in:
1 parent
38c3e2a389
commit
8211ac4973
8 files changed
+149
-12
No files matched your search
@@ -119,6 +119,28 @@ func (s *Service) CreateGenerated(ctx context.Context, name string) (Metadata, s
|
||||
}
|
||||
return metadata, strings.TrimSpace(string(ssh.MarshalAuthorizedKey(sshPublicKey))), nil
|
||||
}
|
||||
func (s *Service) AuthorizedPublicKey(ctx context.Context, reference string) (string, error) {
|
||||
if s == nil || s.store == nil {
|
||||
return "", errors.New("SSH 私钥存储未初始化")
|
||||
}
|
||||
metadata, err := s.metadata(ctx, strings.TrimSpace(reference), time.Time{}, true)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
payload, err := s.store.Get(ctx, metadata.Reference)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("读取 SSH 私钥失败:%w", err)
|
||||
}
|
||||
signer, err := parsePrivateKey(payload["private_key"], payload["passphrase"])
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
publicKey, err := ssh.NewPublicKey(signer.PublicKey())
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("编码 SSH 公钥失败:%w", err)
|
||||
}
|
||||
return strings.TrimSpace(string(ssh.MarshalAuthorizedKey(publicKey))), nil
|
||||
}
|
||||
func (s *Service) List(ctx context.Context) ([]Metadata, error) {
|
||||
if s == nil || s.store == nil {
|
||||
return nil, errors.New("SSH 私钥存储未初始化")
|
||||
|
||||
Reference in new issue
Block a user