cli: add missing options for configuring sftp known_hosts
Possibly the cause of
@@ -28,6 +28,8 @@ func(cmd *kingpin.CmdClause) {
cmd.Flag("username", "SFTP/SSH server username").Required().StringVar(&options.Username)
cmd.Flag("keyfile", "path to private key file for SFTP/SSH server").StringVar(&options.Keyfile)
cmd.Flag("key-data", "private key data").StringVar(&options.KeyData)
+ cmd.Flag("known-hosts", "path to known_hosts file").StringVar(&options.KnownHostsFile)
+ cmd.Flag("known-hosts-data", "known_hosts file entries").StringVar(&options.KnownHostsData)
cmd.Flag("embed-credentials", "Embed key and known_hosts in Kopia configuration").BoolVar(&embedCredentials)
cmd.Flag("flat", "Use flat directory structure").BoolVar(&connectFlat)
},
@@ -35,6 +37,7 @@ func(ctx context.Context, isNew bool) (blob.Storage, error) {
sftpo := options
if embedCredentials {
+ if sftpo.KeyData == "" {
d, err := ioutil.ReadFile(sftpo.Keyfile)
if err != nil {
return nil, err
@@ -44,6 +47,17 @@ func(ctx context.Context, isNew bool) (blob.Storage, error) {
sftpo.Keyfile = ""
}
+ if sftpo.KnownHostsData == "" && sftpo.KnownHostsFile != "" {
+ d, err := ioutil.ReadFile(sftpo.KnownHostsFile)
+ if err != nil {
+ return nil, err
+ }
+
+ sftpo.KnownHostsData = string(d)
+ sftpo.KnownHostsFile = ""
+ }
+ }
+
if sftpo.KeyData == "" && sftpo.Keyfile == "" {
return nil, errors.Errorf("must provide either key file or key data")
}
