/
cloud.go
70 lines (63 loc) · 1.48 KB
/
cloud.go
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package falcon
import (
"fmt"
"strings"
)
// CloudType represents type of CrowdStrike Falcon cloud region.
type CloudType int
const (
CloudUs1 = iota
CloudUs2
CloudEu1
CloudUsGov1
)
// Cloud parses clould string (example: us-1, us-2, eu-1, us-gov-1, etc). If a string is not recognised CloudUs1 is returned.
func Cloud(cloudString string) CloudType {
c, _ := CloudValidate(cloudString)
return c
}
// CloudValidate parses cloud string (example: us-1, us-2, eu-1, us-gov-1, etc.). Error is returned when string cannot be recognised
func CloudValidate(cloudString string) (CloudType, error) {
trimmed := strings.TrimSpace(cloudString)
lower := strings.ToLower(trimmed)
switch lower {
case "us-1":
return CloudUs1, nil
case "us-2":
return CloudUs2, nil
case "eu-1":
return CloudEu1, nil
case "us-gov-1":
return CloudUsGov1, nil
}
return CloudUs1, fmt.Errorf("unrecognized CrowdStrike Falcon Cloud: %s", lower)
}
// Host returns default hostname for given cloud.
func (c CloudType) Host() string {
switch c {
default:
fallthrough
case CloudUs1:
return "api.crowdstrike.com"
case CloudUs2:
return "api.us-2.crowdstrike.com"
case CloudEu1:
return "api.eu-1.crowdstrike.com"
case CloudUsGov1:
return "api.laggar.gcw.crowdstrike.com"
}
}
func (c CloudType) String() string {
switch c {
case CloudUs1:
return "us-1"
case CloudUs2:
return "us-2"
case CloudEu1:
return "eu-1"
case CloudUsGov1:
return "us-gov-1"
default:
return "UNKNOWN FALCON CLOUD REGION"
}
}