summaryrefslogtreecommitdiff
path: root/workhorse/backend.go
blob: 5aa246aa0e8414969b028afe410cc2816bfccc1c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
		}
	}

	if backendURL.Scheme != "http" && backendURL.Scheme != "https" {
		return nil, fmt.Errorf("invalid scheme, only 'http' and 'https' are allowed: %q", authBackend)
	}

	if backendURL.Host == "" {
		return nil, fmt.Errorf("missing host in %q", authBackend)
	}

	return backendURL, nil
}