forked from kyma-project/kyma
-
Notifications
You must be signed in to change notification settings - Fork 0
/
subject.go
38 lines (28 loc) · 784 Bytes
/
subject.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
package certificates
import "regexp"
func GetOrganization(subject string) string {
return getRegexMatch("O=([^,]+)", subject)
}
func GetOrganizationalUnit(subject string) string {
return getRegexMatch("OU=([^,]+)", subject)
}
func GetCountry(subject string) string {
return getRegexMatch("C=([^,]+)", subject)
}
func GetProvince(subject string) string {
return getRegexMatch("ST=([^,]+)", subject)
}
func GetLocality(subject string) string {
return getRegexMatch("L=([^,]+)", subject)
}
func GetCommonName(subject string) string {
return getRegexMatch("CN=([^,]+)", subject)
}
func getRegexMatch(regex, text string) string {
cnRegex := regexp.MustCompile(regex)
matches := cnRegex.FindStringSubmatch(text)
if len(matches) != 2 {
return ""
}
return matches[1]
}