mirror of
https://github.com/rclone/rclone.git
synced 2024-11-22 13:22:16 +08:00
serve sftp: convert options to new style
This commit is contained in:
parent
28ba4b832d
commit
eff2497633
|
@ -133,7 +133,7 @@ func (s *server) serve() (err error) {
|
|||
var authorizedKeysMap map[string]struct{}
|
||||
|
||||
// ensure the user isn't trying to use conflicting flags
|
||||
if proxyflags.Opt.AuthProxy != "" && s.opt.AuthorizedKeys != "" && s.opt.AuthorizedKeys != DefaultOpt.AuthorizedKeys {
|
||||
if proxyflags.Opt.AuthProxy != "" && s.opt.AuthorizedKeys != "" && s.opt.AuthorizedKeys != Opt.AuthorizedKeys {
|
||||
return errors.New("--auth-proxy and --authorized-keys cannot be used at the same time")
|
||||
}
|
||||
|
||||
|
@ -142,7 +142,7 @@ func (s *server) serve() (err error) {
|
|||
authKeysFile := env.ShellExpand(s.opt.AuthorizedKeys)
|
||||
authorizedKeysMap, err = loadAuthorizedKeys(authKeysFile)
|
||||
// If user set the flag away from the default then report an error
|
||||
if err != nil && s.opt.AuthorizedKeys != DefaultOpt.AuthorizedKeys {
|
||||
if err != nil && s.opt.AuthorizedKeys != Opt.AuthorizedKeys {
|
||||
return err
|
||||
}
|
||||
fs.Logf(nil, "Loaded %d authorized keys from %q", len(authorizedKeysMap), authKeysFile)
|
||||
|
|
|
@ -11,7 +11,6 @@ import (
|
|||
"github.com/rclone/rclone/cmd/serve/proxy/proxyflags"
|
||||
"github.com/rclone/rclone/fs"
|
||||
"github.com/rclone/rclone/fs/config/flags"
|
||||
"github.com/rclone/rclone/fs/rc"
|
||||
"github.com/rclone/rclone/lib/systemd"
|
||||
"github.com/rclone/rclone/vfs"
|
||||
"github.com/rclone/rclone/vfs/vfsflags"
|
||||
|
@ -19,36 +18,58 @@ import (
|
|||
"github.com/spf13/pflag"
|
||||
)
|
||||
|
||||
// OptionsInfo descripts the Options in use
|
||||
var OptionsInfo = fs.Options{{
|
||||
Name: "addr",
|
||||
Default: "localhost:2022",
|
||||
Help: "IPaddress:Port or :Port to bind server to",
|
||||
}, {
|
||||
Name: "key",
|
||||
Default: []string{},
|
||||
Help: "SSH private host key file (Can be multi-valued, leave blank to auto generate)",
|
||||
}, {
|
||||
Name: "authorized_keys",
|
||||
Default: "~/.ssh/authorized_keys",
|
||||
Help: "Authorized keys file",
|
||||
}, {
|
||||
Name: "user",
|
||||
Default: "",
|
||||
Help: "User name for authentication",
|
||||
}, {
|
||||
Name: "pass",
|
||||
Default: "",
|
||||
Help: "Password for authentication",
|
||||
}, {
|
||||
Name: "no_auth",
|
||||
Default: false,
|
||||
Help: "Allow connections with no authentication if set",
|
||||
}, {
|
||||
Name: "stdio",
|
||||
Default: false,
|
||||
Help: "Run an sftp server on stdin/stdout",
|
||||
}}
|
||||
|
||||
// Options contains options for the http Server
|
||||
type Options struct {
|
||||
ListenAddr string // Port to listen on
|
||||
HostKeys []string // Paths to private host keys
|
||||
AuthorizedKeys string // Path to authorized keys file
|
||||
User string // single username
|
||||
Pass string // password for user
|
||||
NoAuth bool // allow no authentication on connections
|
||||
Stdio bool // serve on stdio
|
||||
ListenAddr string `config:"addr"` // Port to listen on
|
||||
HostKeys []string `config:"key"` // Paths to private host keys
|
||||
AuthorizedKeys string `config:"authorized_keys"` // Path to authorized keys file
|
||||
User string `config:"user"` // single username
|
||||
Pass string `config:"pass"` // password for user
|
||||
NoAuth bool `config:"no_auth"` // allow no authentication on connections
|
||||
Stdio bool `config:"stdio"` // serve on stdio
|
||||
}
|
||||
|
||||
// DefaultOpt is the default values used for Options
|
||||
var DefaultOpt = Options{
|
||||
ListenAddr: "localhost:2022",
|
||||
AuthorizedKeys: "~/.ssh/authorized_keys",
|
||||
func init() {
|
||||
fs.RegisterGlobalOptions(fs.OptionsInfo{Name: "sftp", Opt: &Opt, Options: OptionsInfo})
|
||||
}
|
||||
|
||||
// Opt is options set by command line flags
|
||||
var Opt = DefaultOpt
|
||||
var Opt Options
|
||||
|
||||
// AddFlags adds flags for the sftp
|
||||
func AddFlags(flagSet *pflag.FlagSet, Opt *Options) {
|
||||
rc.AddOption("sftp", &Opt)
|
||||
flags.StringVarP(flagSet, &Opt.ListenAddr, "addr", "", Opt.ListenAddr, "IPaddress:Port or :Port to bind server to", "")
|
||||
flags.StringArrayVarP(flagSet, &Opt.HostKeys, "key", "", Opt.HostKeys, "SSH private host key file (Can be multi-valued, leave blank to auto generate)", "")
|
||||
flags.StringVarP(flagSet, &Opt.AuthorizedKeys, "authorized-keys", "", Opt.AuthorizedKeys, "Authorized keys file", "")
|
||||
flags.StringVarP(flagSet, &Opt.User, "user", "", Opt.User, "User name for authentication", "")
|
||||
flags.StringVarP(flagSet, &Opt.Pass, "pass", "", Opt.Pass, "Password for authentication", "")
|
||||
flags.BoolVarP(flagSet, &Opt.NoAuth, "no-auth", "", Opt.NoAuth, "Allow connections with no authentication if set", "")
|
||||
flags.BoolVarP(flagSet, &Opt.Stdio, "stdio", "", Opt.Stdio, "Run an sftp server on stdin/stdout", "")
|
||||
flags.AddFlagsFromOptions(flagSet, "", OptionsInfo)
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
|
|
@ -40,7 +40,7 @@ var (
|
|||
func TestSftp(t *testing.T) {
|
||||
// Configure and start the server
|
||||
start := func(f fs.Fs) (configmap.Simple, func()) {
|
||||
opt := DefaultOpt
|
||||
opt := Opt
|
||||
opt.ListenAddr = testBindAddress
|
||||
opt.User = testUser
|
||||
opt.Pass = testPass
|
||||
|
|
Loading…
Reference in New Issue
Block a user