From 13bcf3b589fe4c7192e2da84078ee9ca4bef03cc Mon Sep 17 00:00:00 2001 From: windvalley Date: Tue, 16 Jan 2024 13:55:59 +0800 Subject: [PATCH] refactor(config): optimize configuration --- configs/gossh.yaml | 31 +++++++++++--------- docs/config.md | 65 ++++++++++++++++++++++++------------------ internal/cmd/config.go | 28 +++++++++--------- 3 files changed, 69 insertions(+), 55 deletions(-) diff --git a/configs/gossh.yaml b/configs/gossh.yaml index deaf35b..4d4618e 100644 --- a/configs/gossh.yaml +++ b/configs/gossh.yaml @@ -1,9 +1,9 @@ auth: - # Default login user. + # The login user. # Default: $USER user: - # Default password of the login user. + # The password of the login user. # Default: "" password: @@ -15,11 +15,11 @@ auth: # Default: "" file: - # Default identity files of pubkey authentication. - # Default: ["$HOME/.ssh/id_rsa", "$HOME/.ssh/id_dsa"] - identity-files: [] + # The identity files of pubkey authentication. + # Default: [~/.ssh/id_rsa] + identity-files: [~/.ssh/id_rsa] - # Default passphrase of the identity files. + # The passphrase of the identity files. # Default: "" passphrase: @@ -29,6 +29,8 @@ auth: hosts: # Default inventory file that holds the target hosts. + # The file content format can be referred to at: + # https://github.com/windvalley/gossh/blob/main/docs/inventory.md # Default: "" inventory: @@ -58,8 +60,9 @@ run: # Linux Command Blacklist for gossh subcommands 'command' and 'script'. # Commands listed in this blacklist will be prohibited from executing on remote hosts for security reasons. # You can add flag '-n, --no-safe-check' to disable this feature. - # Default: ["rm", "reboot", "halt", "shutdown", "init", "mkfs", "mkfs.*", "umount", "dd"] - command-blacklist: [] + # Default: [rm, reboot, halt, shutdown, init, mkfs, mkfs.*, umount, dd] + command-blacklist: + [rm, reboot, halt, shutdown, init, mkfs, mkfs.*, umount, dd] output: # File to which messages are output. @@ -105,18 +108,18 @@ proxy: # Default: 22 port: 22 - # Login user for proxy. - # Default: value of 'auth.user' + # Proxy server user. + # Default: the same as 'auth.user' user: # Password for proxy. - # Default: value of 'auth.password' + # Default: the same as 'auth.password' password: # Identity files for proxy. - # Default: value of 'auth.identity-files' - identity-files: [] + # Default: the same as 'auth.identity-files' + identity-files: # Passphrase of the identity files for proxy. - # Default: value of 'auth.passphrase' + # Default: the same as 'auth.passphrase' passphrase: diff --git a/docs/config.md b/docs/config.md index 8d28947..c7be243 100644 --- a/docs/config.md +++ b/docs/config.md @@ -14,13 +14,13 @@ Demo file can be found in git repo by location: `configs/gossh.yaml`, or use com ```yaml auth: - # Default login user. + # The login user. # Default: $USER - user: "" + user: - # Default password of the login user. + # The password of the login user. # Default: "" - password: "" + password: # Ask for password of the login user. # Default: false @@ -28,26 +28,26 @@ auth: # File that holds the default password of login user. # Default: "" - file: "" + file: - # Default identity files of pubkey authentication. - # Default: - # - $HOME/.ssh/id_rsa - # - $HOME/.ssh/id_dsa - identity-files: [] + # The identity files of pubkey authentication. + # Default: [~/.ssh/id_rsa] + identity-files: [~/.ssh/id_rsa] - # Default passphrase of the identity files. + # The passphrase of the identity files. # Default: "" - passphrase: "" + passphrase: # File that holds the vault password for encryption and decryption. # Default: "" - vault-pass-file: "" + vault-pass-file: hosts: # Default inventory file that holds the target hosts. + # The file content format can be referred to at: + # https://github.com/windvalley/gossh/blob/main/docs/inventory.md # Default: "" - inventory: "" + inventory: # Default port of target hosts. # Default: 22 @@ -66,26 +66,37 @@ run: # as this value when executing command/script. # Available vaules: zh_CN.UTF-8, en_US.UTF-8, etc. # Default: "" (null means do not export) - lang: "" + lang: # Number of concurrent connections. # Default: 1 concurrency: 1 + # Linux Command Blacklist for gossh subcommands 'command' and 'script'. + # Commands listed in this blacklist will be prohibited from executing on remote hosts for security reasons. + # You can add flag '-n, --no-safe-check' to disable this feature. + # Default: [rm, reboot, halt, shutdown, init, mkfs, mkfs.*, umount, dd] + command-blacklist: + [rm, reboot, halt, shutdown, init, mkfs, mkfs.*, umount, dd] + output: # File to which messages are output. # Default: "" - file: "" + file: # Output messages in json format. # Default: false json: false + # Condense output and disable color. + # Default: false + condense: false + # Show debug messages. # Default: false verbose: false - # Do not output messages to screen (except error messages). + # Do not output messages to screen. # Default: false quite: false @@ -106,27 +117,27 @@ timeout: proxy: # Proxy server address. It will enable proxy if it is not null. # Default: "" - server: "" + server: # Proxy server port. # Default: 22 port: 22 - # Login user for proxy. - # Default: value of 'auth.user' - user: "" + # Proxy server user. + # Default: the same as 'auth.user' + user: # Password for proxy. - # Default: value of 'auth.password' - password: "" + # Default: the same as 'auth.password' + password: # Identity files for proxy. - # Default: value of 'auth.identity-files' - identity-files: [] + # Default: the same as 'auth.identity-files' + identity-files: # Passphrase of the identity files for proxy. - # Default: value of 'auth.passphrase' - passphrase: "" + # Default: the same as 'auth.passphrase' + passphrase: ``` ## Examples diff --git a/internal/cmd/config.go b/internal/cmd/config.go index 062c07b..cd11596 100644 --- a/internal/cmd/config.go +++ b/internal/cmd/config.go @@ -34,11 +34,11 @@ import ( ) const configTemplate = `auth: - # Default login user. + # The login user. # Default: $USER user: {{ .Auth.User }} - # Default password of the login user. + # The password of the login user. # Default: "" password: {{ .Auth.Password }} @@ -50,11 +50,11 @@ const configTemplate = `auth: # Default: "" file: {{ .Auth.PassFile }} - # Default identity files of pubkey authentication. - # Default: ["$HOME/.ssh/id_rsa", "$HOME/.ssh/id_dsa"] - identity-files: [] + # The identity files of pubkey authentication. + # Default: [~/.ssh/id_rsa] + identity-files: [~/.ssh/id_rsa] - # Default passphrase of the identity files. + # The passphrase of the identity files. # Default: "" passphrase: {{ .Auth.Passphrase }} @@ -95,8 +95,8 @@ run: # Linux Command Blacklist for gossh subcommands 'command' and 'script'. # Commands listed in this blacklist will be prohibited from executing on remote hosts for security reasons. # You can add flag '-n, --no-safe-check' to disable this feature. - # Default: ["rm", "reboot", "halt", "shutdown", "init", "mkfs", "mkfs.*", "umount", "dd"] - command-blacklist: [] + # Default: [rm, reboot, halt, shutdown, init, mkfs, mkfs.*, umount, dd] + command-blacklist: [rm, reboot, halt, shutdown, init, mkfs, mkfs.*, umount, dd] output: # File to which messages are output. @@ -142,20 +142,20 @@ proxy: # Default: 22 port: {{ .Proxy.Port }} - # Login user for proxy. - # Default: value of 'auth.user' + # Proxy server user. + # Default: the same as 'auth.user' user: {{ .Proxy.User }} # Password for proxy. - # Default: value of 'auth.password' + # Default: the same as 'auth.password' password: {{ .Proxy.Password }} # Identity files for proxy. - # Default: value of 'auth.identity-files' - identity-files: [] + # Default: the same as 'auth.identity-files' + identity-files: # Passphrase of the identity files for proxy. - # Default: value of 'auth.passphrase' + # Default: the same as 'auth.passphrase' passphrase: {{ .Proxy.Passphrase }}` // configCmd represents the config command