From c55196a525b0301abf3802b817abadab9383ef2f Mon Sep 17 00:00:00 2001 From: Nicola Murino Date: Mon, 25 Sep 2023 18:20:09 +0200 Subject: [PATCH] portable mode: allow to set config dir/config file The -c flag is no longer used for SSH commands. This is a backward incompatible change Fixes #1423 Signed-off-by: Nicola Murino --- docs/full-configuration.md | 2 +- docs/portable-mode.md | 25 ++++++++++++++++++++++++- go.mod | 2 +- go.sum | 4 ++-- internal/cmd/portable.go | 8 +++++--- internal/cmd/root.go | 8 ++++---- 6 files changed, 37 insertions(+), 12 deletions(-) diff --git a/docs/full-configuration.md b/docs/full-configuration.md index 92939af1..01a61fdb 100644 --- a/docs/full-configuration.md +++ b/docs/full-configuration.md @@ -31,7 +31,7 @@ Use "sftpgo [command] --help" for more information about a command. The `serve` command supports the following flags: -- `--config-dir` string. Location of the config dir. This directory is used as the base for files with a relative path, eg. the private keys for the SFTP server or the SQLite database if you use SQLite as data provider. The configuration file, if not explicitly set, is looked for in this dir. We support reading from JSON, TOML, YAML, HCL, envfile and Java properties config files. The default config file name is `sftpgo` and therefore `sftpgo.json`, `sftpgo.yaml` and so on are searched. The default value is the working directory (".") or the value of `SFTPGO_CONFIG_DIR` environment variable. +- `--config-dir` string. Location of the config dir. This directory is used as the base for files with a relative path, e.g. the private keys for the SFTP server or the database file if you use a file-based data provider.. The configuration file, if not explicitly set, is looked for in this dir. We support reading from JSON, TOML, YAML, HCL, envfile and Java properties config files. The default config file name is `sftpgo` and therefore `sftpgo.json`, `sftpgo.yaml` and so on are searched. The default value is the working directory (".") or the value of `SFTPGO_CONFIG_DIR` environment variable. - `--config-file` string. This flag explicitly defines the path, name and extension of the config file. If must be an absolute path or a path relative to the configuration directory. The specified file name must have a supported extension (JSON, YAML, TOML, HCL or Java properties). The default value is empty or the value of `SFTPGO_CONFIG_FILE` environment variable. - `--grace-time`, integer. Graceful shutdown is an option to initiate a shutdown without abrupt cancellation of the currently ongoing client-initiated transfer sessions. This grace time defines the number of seconds allowed for existing transfers to get completed before shutting down. 0 means disabled. The default value is `0` or the value of `SFTPGO_GRACE_TIME` environment variable. A graceful shutdown is triggered by an interrupt signal or by a service `stop` request on Windows, if a grace time is configured. - `--loaddata-from` string. Load users and folders from this file. The file must be specified as absolute path and it must contain a backup obtained using the `dumpdata` REST API or compatible content. The default value is empty or the value of `SFTPGO_LOADDATA_FROM` environment variable. diff --git a/docs/portable-mode.md b/docs/portable-mode.md index 9f1cda47..47365fb5 100644 --- a/docs/portable-mode.md +++ b/docs/portable-mode.md @@ -39,6 +39,29 @@ Flags: --az-upload-part-size int The buffer size for multipart uploads (MB) (default 5) --az-use-emulator + -c, --config-dir string Location of the config dir. This directory + is used as the base for files with a relative + path, e.g. the private keys for the SFTP + server or the database file if you use a + file-based data provider. + The configuration file, if not explicitly set, + is looked for in this dir. We support reading + from JSON, TOML, YAML, HCL, envfile and Java + properties config files. The default config + file name is "sftpgo" and therefore + "sftpgo.json", "sftpgo.yaml" and so on are + searched. + This flag can be set using SFTPGO_CONFIG_DIR + env var too. (default ".") + --config-file string Path to SFTPGo configuration file. + This flag explicitly defines the path, name + and extension of the config file. If must be + an absolute path or a path relative to the + configuration directory. The specified file + name must have a supported extension (JSON, + YAML, TOML, HCL or Java properties). + This flag can be set using SFTPGO_CONFIG_FILE + env var too. --crypto-passphrase string Passphrase for encryption/decryption --denied-patterns stringArray Denied file patterns case insensitive. The format is: @@ -135,7 +158,7 @@ Flags: --sftp-username string SFTP user for SFTP provider -s, --sftpd-port int 0 means a random unprivileged port, < 0 disabled - -c, --ssh-commands strings SSH commands to enable. + --ssh-commands strings SSH commands to enable. "*" means any supported SSH command including scp (default [md5sum,sha1sum,sha256sum,cd,pwd,scp]) diff --git a/go.mod b/go.mod index e6492f4e..f9cf744b 100644 --- a/go.mod +++ b/go.mod @@ -52,7 +52,7 @@ require ( github.com/robfig/cron/v3 v3.0.1 github.com/rs/cors v1.10.0 github.com/rs/xid v1.5.0 - github.com/rs/zerolog v1.30.0 + github.com/rs/zerolog v1.31.0 github.com/sftpgo/sdk v0.1.6-0.20230812162553-b7d33eb36639 github.com/shirou/gopsutil/v3 v3.23.8 github.com/spf13/afero v1.10.0 diff --git a/go.sum b/go.sum index 82a594d1..ed907aae 100644 --- a/go.sum +++ b/go.sum @@ -429,8 +429,8 @@ github.com/rs/cors v1.10.0 h1:62NOS1h+r8p1mW6FM0FSB0exioXLhd/sh15KpjWBZ+8= github.com/rs/cors v1.10.0/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU= github.com/rs/xid v1.5.0 h1:mKX4bl4iPYJtEIxp6CYiUuLQ/8DYMoz0PUdtGgMFRVc= github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= -github.com/rs/zerolog v1.30.0 h1:SymVODrcRsaRaSInD9yQtKbtWqwsfoPcRff/oRXLj4c= -github.com/rs/zerolog v1.30.0/go.mod h1:/tk+P47gFdPXq4QYjvCmT5/Gsug2nagsFWBWhAiSi1w= +github.com/rs/zerolog v1.31.0 h1:FcTR3NnLWW+NnTwwhFWiJSZr4ECLpqCm6QsEnyvbV4A= +github.com/rs/zerolog v1.31.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/secsy/goftp v0.0.0-20200609142545-aa2de14babf4 h1:PT+ElG/UUFMfqy5HrxJxNzj3QBOf7dZwupeVC+mG1Lo= diff --git a/internal/cmd/portable.go b/internal/cmd/portable.go index 93034295..56340114 100644 --- a/internal/cmd/portable.go +++ b/internal/cmd/portable.go @@ -32,6 +32,7 @@ import ( "github.com/drakkan/sftpgo/v2/internal/kms" "github.com/drakkan/sftpgo/v2/internal/service" "github.com/drakkan/sftpgo/v2/internal/sftpd" + "github.com/drakkan/sftpgo/v2/internal/util" "github.com/drakkan/sftpgo/v2/internal/version" "github.com/drakkan/sftpgo/v2/internal/vfs" ) @@ -198,8 +199,8 @@ Please take a look at the usage below to customize the serving parameters`, } service.SetGraceTime(graceTime) service := service.Service{ - ConfigDir: filepath.Clean(defaultConfigDir), - ConfigFile: defaultConfigFile, + ConfigDir: util.CleanDirInput(configDir), + ConfigFile: configFile, LogFilePath: portableLogFile, LogMaxSize: defaultLogMaxSize, LogMaxBackups: defaultLogMaxBackup, @@ -317,7 +318,7 @@ path`) < 0 disabled`) portableCmd.Flags().IntVar(&portableHTTPPort, "httpd-port", -1, `0 means a random unprivileged port, < 0 disabled`) - portableCmd.Flags().StringSliceVarP(&portableSSHCommands, "ssh-commands", "c", sftpd.GetDefaultSSHCommands(), + portableCmd.Flags().StringSliceVar(&portableSSHCommands, "ssh-commands", sftpd.GetDefaultSSHCommands(), `SSH commands to enable. "*" means any supported SSH command including scp @@ -441,6 +442,7 @@ to get completed before shutting down. A graceful shutdown is triggered by an interrupt signal. `) + addConfigFlags(portableCmd) rootCmd.AddCommand(portableCmd) } diff --git a/internal/cmd/root.go b/internal/cmd/root.go index 10d9ccf0..32a6e6f1 100644 --- a/internal/cmd/root.go +++ b/internal/cmd/root.go @@ -115,11 +115,11 @@ func addConfigFlags(cmd *cobra.Command) { viper.SetDefault(configDirKey, defaultConfigDir) viper.BindEnv(configDirKey, "SFTPGO_CONFIG_DIR") //nolint:errcheck // err is not nil only if the key to bind is missing cmd.Flags().StringVarP(&configDir, configDirFlag, "c", viper.GetString(configDirKey), - `Location for the config dir. This directory + `Location of the config dir. This directory is used as the base for files with a relative -path, eg. the private keys for the SFTP -server or the SQLite database if you use -SQLite as data provider. +path, e.g. the private keys for the SFTP +server or the database file if you use a +file-based data provider. The configuration file, if not explicitly set, is looked for in this dir. We support reading from JSON, TOML, YAML, HCL, envfile and Java