-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathauthHost.go
More file actions
40 lines (32 loc) · 860 Bytes
/
authHost.go
File metadata and controls
40 lines (32 loc) · 860 Bytes
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
31
32
33
34
35
36
37
38
39
40
package auth
import (
"net/url"
"strings"
"github.com/snyk/go-application-framework/internal/api"
"github.com/snyk/go-application-framework/pkg/utils"
)
func redirectAuthHost(instance string) (string, error) {
// handle both cases if instance is a URL or just a host
if !strings.HasPrefix(instance, "http") {
instance = "https://" + instance
}
instanceUrl, err := url.Parse(instance)
if err != nil {
return "", err
}
canonicalizedInstanceUrl, err := api.GetCanonicalApiAsUrl(*instanceUrl)
if err != nil {
return "", err
}
return canonicalizedInstanceUrl.Host, nil
}
func IsValidAuthHost(instance string, authHostRegex string) (bool, error) {
if api.IsKnownHostName(instance) {
return true, nil
}
isValidHost, err := utils.MatchesRegex(instance, authHostRegex)
if err != nil {
return false, err
}
return isValidHost, nil
}