mirror of
https://github.com/hacdias/webdav.git
synced 2026-09-22 03:20:41 +08:00
feat!: remove Auth option
This commit is contained in:
@@ -70,10 +70,6 @@ prefix: /
|
|||||||
# Enable or disable debug logging. Default is false.
|
# Enable or disable debug logging. Default is false.
|
||||||
debug: false
|
debug: false
|
||||||
|
|
||||||
# Whether or not to have authentication. With authentication on, you need to
|
|
||||||
# define one or more users. Default is false.
|
|
||||||
auth: true
|
|
||||||
|
|
||||||
# The directory that will be able to be accessed by the users when connecting.
|
# The directory that will be able to be accessed by the users when connecting.
|
||||||
# This directory will be used by users unless they have their own 'scope' defined.
|
# This directory will be used by users unless they have their own 'scope' defined.
|
||||||
# Default is "." (current directory).
|
# Default is "." (current directory).
|
||||||
@@ -85,7 +81,7 @@ modify: true
|
|||||||
# Default permissions rules to apply at the paths.
|
# Default permissions rules to apply at the paths.
|
||||||
rules: []
|
rules: []
|
||||||
|
|
||||||
# The list of users. Must be defined if auth is set to true.
|
# The list of users. If users is empty, then there will be no authentication.
|
||||||
users:
|
users:
|
||||||
# Example 'admin' user with plaintext password.
|
# Example 'admin' user with plaintext password.
|
||||||
- username: admin
|
- username: admin
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ func init() {
|
|||||||
flags := rootCmd.Flags()
|
flags := rootCmd.Flags()
|
||||||
flags.StringP("config", "c", "", "config file path")
|
flags.StringP("config", "c", "", "config file path")
|
||||||
flags.BoolP("tls", "t", lib.DefaultTLS, "enable TLS")
|
flags.BoolP("tls", "t", lib.DefaultTLS, "enable TLS")
|
||||||
flags.Bool("auth", lib.DefaultAuth, "enable authentication")
|
|
||||||
flags.String("cert", lib.DefaultCert, "path to TLS certificate")
|
flags.String("cert", lib.DefaultCert, "path to TLS certificate")
|
||||||
flags.String("key", lib.DefaultKey, "path to TLS key")
|
flags.String("key", lib.DefaultKey, "path to TLS key")
|
||||||
flags.StringP("address", "a", lib.DefaultAddress, "address to listen on")
|
flags.StringP("address", "a", lib.DefaultAddress, "address to listen on")
|
||||||
|
|||||||
+3
-9
@@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/go-viper/mapstructure/v2"
|
"github.com/go-viper/mapstructure/v2"
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -17,7 +18,6 @@ const (
|
|||||||
DefaultDebug = false
|
DefaultDebug = false
|
||||||
DefaultNoSniff = false
|
DefaultNoSniff = false
|
||||||
DefaultTLS = false
|
DefaultTLS = false
|
||||||
DefaultAuth = false
|
|
||||||
DefaultCert = "cert.pem"
|
DefaultCert = "cert.pem"
|
||||||
DefaultKey = "key.pem"
|
DefaultKey = "key.pem"
|
||||||
DefaultAddress = "0.0.0.0"
|
DefaultAddress = "0.0.0.0"
|
||||||
@@ -37,7 +37,6 @@ type Config struct {
|
|||||||
Prefix string
|
Prefix string
|
||||||
NoSniff bool
|
NoSniff bool
|
||||||
LogFormat string `mapstructure:"log_format"`
|
LogFormat string `mapstructure:"log_format"`
|
||||||
Auth bool
|
|
||||||
CORS CORS
|
CORS CORS
|
||||||
Users []User
|
Users []User
|
||||||
}
|
}
|
||||||
@@ -84,7 +83,6 @@ func ParseConfig(filename string, flags *pflag.FlagSet) (*Config, error) {
|
|||||||
v.SetDefault("Key", DefaultKey)
|
v.SetDefault("Key", DefaultKey)
|
||||||
v.SetDefault("Address", DefaultAddress)
|
v.SetDefault("Address", DefaultAddress)
|
||||||
v.SetDefault("Port", DefaultPort)
|
v.SetDefault("Port", DefaultPort)
|
||||||
v.SetDefault("Auth", DefaultAuth)
|
|
||||||
v.SetDefault("Prefix", DefaultPrefix)
|
v.SetDefault("Prefix", DefaultPrefix)
|
||||||
v.SetDefault("Log_Format", DefaultLogFormat)
|
v.SetDefault("Log_Format", DefaultLogFormat)
|
||||||
|
|
||||||
@@ -137,12 +135,8 @@ func ParseConfig(filename string, flags *pflag.FlagSet) (*Config, error) {
|
|||||||
func (c *Config) Validate() error {
|
func (c *Config) Validate() error {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
if c.Auth && len(c.Users) == 0 {
|
if len(c.Users) == 0 {
|
||||||
return errors.New("invalid config: auth cannot be enabled without users")
|
zap.L().Warn("unprotected config: no users have been set, so no authentication will be used")
|
||||||
}
|
|
||||||
|
|
||||||
if !c.Auth && len(c.Users) != 0 {
|
|
||||||
return errors.New("invalid config: auth cannot be disabled with users defined")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Scope, err = filepath.Abs(c.Scope)
|
c.Scope, err = filepath.Abs(c.Scope)
|
||||||
|
|||||||
+1
-5
@@ -28,7 +28,6 @@ func TestConfigDefaults(t *testing.T) {
|
|||||||
cfg := writeAndParseConfig(t, "", ".yml")
|
cfg := writeAndParseConfig(t, "", ".yml")
|
||||||
require.NoError(t, cfg.Validate())
|
require.NoError(t, cfg.Validate())
|
||||||
|
|
||||||
require.EqualValues(t, DefaultAuth, cfg.Auth)
|
|
||||||
require.EqualValues(t, DefaultTLS, cfg.TLS)
|
require.EqualValues(t, DefaultTLS, cfg.TLS)
|
||||||
require.EqualValues(t, DefaultAddress, cfg.Address)
|
require.EqualValues(t, DefaultAddress, cfg.Address)
|
||||||
require.EqualValues(t, DefaultPort, cfg.Port)
|
require.EqualValues(t, DefaultPort, cfg.Port)
|
||||||
@@ -65,7 +64,6 @@ func TestConfigCascade(t *testing.T) {
|
|||||||
|
|
||||||
t.Run("YAML", func(t *testing.T) {
|
t.Run("YAML", func(t *testing.T) {
|
||||||
content := `
|
content := `
|
||||||
auth: true
|
|
||||||
scope: /
|
scope: /
|
||||||
modify: true
|
modify: true
|
||||||
rules:
|
rules:
|
||||||
@@ -89,7 +87,6 @@ users:
|
|||||||
|
|
||||||
t.Run("JSON", func(t *testing.T) {
|
t.Run("JSON", func(t *testing.T) {
|
||||||
content := `{
|
content := `{
|
||||||
"auth": true,
|
|
||||||
"scope": "/",
|
"scope": "/",
|
||||||
"modify": true,
|
"modify": true,
|
||||||
"rules": [
|
"rules": [
|
||||||
@@ -120,7 +117,7 @@ users:
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("`TOML", func(t *testing.T) {
|
t.Run("`TOML", func(t *testing.T) {
|
||||||
content := `auth = true
|
content := `
|
||||||
scope = "/"
|
scope = "/"
|
||||||
modify = true
|
modify = true
|
||||||
|
|
||||||
@@ -175,7 +172,6 @@ cors:
|
|||||||
|
|
||||||
func TestConfigRules(t *testing.T) {
|
func TestConfigRules(t *testing.T) {
|
||||||
content := `
|
content := `
|
||||||
auth: false
|
|
||||||
scope: /
|
scope: /
|
||||||
modify: true
|
modify: true
|
||||||
rules:
|
rules:
|
||||||
|
|||||||
@@ -90,7 +90,6 @@ func TestServerAuthentication(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
srv := makeTestServer(t, fmt.Sprintf(`
|
srv := makeTestServer(t, fmt.Sprintf(`
|
||||||
auth: true
|
|
||||||
scope: %s
|
scope: %s
|
||||||
modify: true
|
modify: true
|
||||||
|
|
||||||
@@ -153,7 +152,6 @@ func TestServerRules(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
srv := makeTestServer(t, fmt.Sprintf(`
|
srv := makeTestServer(t, fmt.Sprintf(`
|
||||||
auth: true
|
|
||||||
scope: %s
|
scope: %s
|
||||||
modify: true
|
modify: true
|
||||||
|
|
||||||
@@ -196,7 +194,6 @@ func TestServerPermissions(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
srv := makeTestServer(t, fmt.Sprintf(`
|
srv := makeTestServer(t, fmt.Sprintf(`
|
||||||
auth: true
|
|
||||||
scope: %s
|
scope: %s
|
||||||
modify: true
|
modify: true
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user