| 1 |
package spnego |
| 2 |
|
| 3 |
import ( |
| 4 |
"net" |
| 5 |
"net/http" |
| 6 |
"strings" |
| 7 |
) |
| 8 |
|
| 9 |
// Provider is the interface that wraps OS agnostic functions for handling SPNEGO communication |
| 10 |
type Provider interface { |
| 11 |
SetSPNEGOHeader(*http.Request) error |
| 12 |
} |
| 13 |
|
| 14 |
func canonicalizeHostname(hostname string) (string, error) { |
| 15 |
addrs, err := net.LookupHost(hostname) |
| 16 |
if err != nil { |
| 17 |
return "", err |
| 18 |
} |
| 19 |
if len(addrs) < 1 { |
| 20 |
return hostname, nil |
| 21 |
} |
| 22 |
|
| 23 |
names, err := net.LookupAddr(addrs[0]) |
| 24 |
if err != nil { |
| 25 |
return "", err |
| 26 |
} |
| 27 |
if len(names) < 1 { |
| 28 |
return hostname, nil |
| 29 |
} |
| 30 |
|
| 31 |
return strings.TrimRight(names[0], "."), nil |
| 32 |
} |