web.go: adjust order of functions to match call order in RequestHandler
This commit is contained in:
parent
8479da58bc
commit
de9cc37738
1 changed files with 29 additions and 29 deletions
58
web.go
58
web.go
|
|
@ -30,6 +30,35 @@ func isAuthenticated(cfg *Config, r *http.Request) *User {
|
|||
return user
|
||||
}
|
||||
|
||||
// returns api-response on failure and RRConfig on success
|
||||
func verifyHostname(cfg *Config, user *User, hostname string) (string, *RRConfig) {
|
||||
if len(hostname) <= 0 {
|
||||
return "nohost", nil
|
||||
}
|
||||
|
||||
// check whether the authenticated user is allowed to update the dns record
|
||||
_, ok := user.records[hostname]
|
||||
if !ok {
|
||||
return "badauth", nil
|
||||
}
|
||||
|
||||
// this should not fail as it is verified in LoadConfig, but better be safe
|
||||
entry, ok := cfg.rrconfigs[hostname]
|
||||
if !ok {
|
||||
return "nohost", nil
|
||||
}
|
||||
|
||||
// TODO: return notfqdn -> differentiate between 'hostname doesnt exist' and
|
||||
// 'hostname is not fqdn'
|
||||
|
||||
// again, this should not fail since 'hostname' was the key used for
|
||||
// cfg.rrconfigs to acquire the entry
|
||||
if hostname != entry.Recordname {
|
||||
return "nohost", nil
|
||||
}
|
||||
return "", entry
|
||||
}
|
||||
|
||||
func getIpAddress(r *http.Request) net.IP {
|
||||
addr := r.URL.Query().Get("myip")
|
||||
if len(addr) > 0 {
|
||||
|
|
@ -61,35 +90,6 @@ func getIpAddress(r *http.Request) net.IP {
|
|||
return net.ParseIP(addr)
|
||||
}
|
||||
|
||||
// returns api-response on failure and RRConfig on success
|
||||
func verifyHostname(cfg *Config, user *User, hostname string) (string, *RRConfig) {
|
||||
if len(hostname) <= 0 {
|
||||
return "nohost", nil
|
||||
}
|
||||
|
||||
// check whether the authenticated user is allowed to update the dns record
|
||||
_, ok := user.records[hostname]
|
||||
if !ok {
|
||||
return "badauth", nil
|
||||
}
|
||||
|
||||
// this should not fail as it is verified in LoadConfig, but better be safe
|
||||
entry, ok := cfg.rrconfigs[hostname]
|
||||
if !ok {
|
||||
return "nohost", nil
|
||||
}
|
||||
|
||||
// TODO: return notfqdn -> differentiate between 'hostname doesnt exist' and
|
||||
// 'hostname is not fqdn'
|
||||
|
||||
// again, this should not fail since 'hostname' was the key used for
|
||||
// cfg.rrconfigs to acquire the entry
|
||||
if hostname != entry.Recordname {
|
||||
return "nohost", nil
|
||||
}
|
||||
return "", entry
|
||||
}
|
||||
|
||||
func RequestHandler(cfg *Config) func(w http.ResponseWriter, r *http.Request) {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
user := isAuthenticated(cfg, r)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue