diff options
author | Francis Lavoie <[email protected]> | 2024-01-23 19:36:59 -0500 |
---|---|---|
committer | GitHub <[email protected]> | 2024-01-23 19:36:59 -0500 |
commit | 750d0b83319ac0ea6b7f057b8270c19404c3d6fa (patch) | |
tree | d0c3fb610cde8ae9d73a0a2caba94542af099770 /modules/caddyhttp/caddyauth | |
parent | 54823f52bc9aed66a1a37f820daf6e494181211a (diff) | |
download | caddy-750d0b83319ac0ea6b7f057b8270c19404c3d6fa.tar.gz caddy-750d0b83319ac0ea6b7f057b8270c19404c3d6fa.zip |
caddyfile: Normalize & flatten all unmarshalers (#6037)
Diffstat (limited to 'modules/caddyhttp/caddyauth')
-rw-r--r-- | modules/caddyhttp/caddyauth/caddyfile.go | 80 |
1 files changed, 40 insertions, 40 deletions
diff --git a/modules/caddyhttp/caddyauth/caddyfile.go b/modules/caddyhttp/caddyauth/caddyfile.go index 05c023209..66201dd94 100644 --- a/modules/caddyhttp/caddyauth/caddyfile.go +++ b/modules/caddyhttp/caddyauth/caddyfile.go @@ -34,56 +34,56 @@ func init() { // // If no hash algorithm is supplied, bcrypt will be assumed. func parseCaddyfile(h httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler, error) { + h.Next() // consume directive name + var ba HTTPBasicAuth ba.HashCache = new(Cache) - for h.Next() { - var cmp Comparer - args := h.RemainingArgs() + var cmp Comparer + args := h.RemainingArgs() - var hashName string - switch len(args) { - case 0: - hashName = "bcrypt" - case 1: - hashName = args[0] - case 2: - hashName = args[0] - ba.Realm = args[1] - default: - return nil, h.ArgErr() - } - - switch hashName { - case "bcrypt": - cmp = BcryptHash{} - case "scrypt": - cmp = ScryptHash{} - default: - return nil, h.Errf("unrecognized hash algorithm: %s", hashName) - } + var hashName string + switch len(args) { + case 0: + hashName = "bcrypt" + case 1: + hashName = args[0] + case 2: + hashName = args[0] + ba.Realm = args[1] + default: + return nil, h.ArgErr() + } - ba.HashRaw = caddyconfig.JSONModuleObject(cmp, "algorithm", hashName, nil) + switch hashName { + case "bcrypt": + cmp = BcryptHash{} + case "scrypt": + cmp = ScryptHash{} + default: + return nil, h.Errf("unrecognized hash algorithm: %s", hashName) + } - for h.NextBlock(0) { - username := h.Val() + ba.HashRaw = caddyconfig.JSONModuleObject(cmp, "algorithm", hashName, nil) - var b64Pwd, b64Salt string - h.Args(&b64Pwd, &b64Salt) - if h.NextArg() { - return nil, h.ArgErr() - } + for h.NextBlock(0) { + username := h.Val() - if username == "" || b64Pwd == "" { - return nil, h.Err("username and password cannot be empty or missing") - } + var b64Pwd, b64Salt string + h.Args(&b64Pwd, &b64Salt) + if h.NextArg() { + return nil, h.ArgErr() + } - ba.AccountList = append(ba.AccountList, Account{ - Username: username, - Password: b64Pwd, - Salt: b64Salt, - }) + if username == "" || b64Pwd == "" { + return nil, h.Err("username and password cannot be empty or missing") } + + ba.AccountList = append(ba.AccountList, Account{ + Username: username, + Password: b64Pwd, + Salt: b64Salt, + }) } return Authentication{ |