2020-12-02 10:09:37 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/url"
|
|
|
|
)
|
|
|
|
|
|
|
|
func parseAuthBackend(authBackend string) (*url.URL, error) {
|
|
|
|
backendURL, err := url.Parse(authBackend)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if backendURL.Host == "" {
|
|
|
|
backendURL, err = url.Parse("http://" + authBackend)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-07 07:16:11 -05:00
|
|
|
if backendURL.Scheme != "http" && backendURL.Scheme != "https" {
|
|
|
|
return nil, fmt.Errorf("invalid scheme, only 'http' and 'https' are allowed: %q", authBackend)
|
2020-12-02 10:09:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if backendURL.Host == "" {
|
|
|
|
return nil, fmt.Errorf("missing host in %q", authBackend)
|
|
|
|
}
|
|
|
|
|
|
|
|
return backendURL, nil
|
|
|
|
}
|