grim/hgkeeper
Clone
Summary
Browse
Changes
Graph
Fix installing python packages via pip
4 months ago, Gary Kramlich
03e8cbced891
Fix installing python packages via pip
package
ssh
import
(
"errors"
"os"
"path/filepath"
"go.uber.org/zap"
"golang.org/x/crypto/ssh"
)
func
(
s
*
Server
)
setHostKeysPath
(
hostKeysPath
string
)
error
{
files
,
err
:=
os
.
ReadDir
(
hostKeysPath
)
if
err
!=
nil
{
return
err
}
found
:=
false
for
_
,
file
:=
range
files
{
if
!
file
.
IsDir
()
{
path
:=
filepath
.
Join
(
hostKeysPath
,
file
.
Name
())
data
,
err
:=
os
.
ReadFile
(
path
)
if
err
!=
nil
{
zap
.
S
().
Warnf
(
"failed to read %s"
,
path
)
continue
}
key
,
err
:=
ssh
.
ParsePrivateKey
(
data
)
if
err
!=
nil
{
zap
.
S
().
Warnf
(
"%s is not an ssh private key"
,
path
)
continue
}
s
.
server
.
AddHostKey
(
key
)
found
=
true
zap
.
S
().
Infof
(
"added host key from %s"
,
path
)
}
}
if
!
found
{
return
errors
.
New
(
"failed to find a usable host key"
)
}
return
nil
}