-
Notifications
You must be signed in to change notification settings - Fork 39
/
eum-registry.go
51 lines (43 loc) · 1.06 KB
/
eum-registry.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
//go:generate curl -o eum-registry.json https://euicc-manual.osmocom.org/docs/pki/eum/manifest.json
package main
import (
_ "embed"
"encoding/json"
"path/filepath"
"strings"
)
//go:embed eum-registry.json
var eumRegistryBundle []byte
type EUMIdentifier struct {
EUM string `json:"eum"`
Country string `json:"country"`
Manufacturer string `json:"manufacturer"`
Products []*EUMProduct `json:"products"`
}
func (e EUMIdentifier) ProductName(eid string) string {
for _, product := range e.Products {
if match, err := filepath.Match(product.Pattern, eid); err != nil || !match {
continue
}
return product.Name
}
return ""
}
type EUMProduct struct {
Pattern string `json:"pattern"`
Name string `json:"name"`
}
var EUMRegistry []*EUMIdentifier
func init() {
if err := json.Unmarshal(eumRegistryBundle, &EUMRegistry); err != nil {
panic(err)
}
}
func GetEUM(eid string) *EUMIdentifier {
for _, identifier := range EUMRegistry {
if strings.HasPrefix(eid, identifier.EUM) {
return identifier
}
}
return nil
}