-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
71 lines (57 loc) · 1.55 KB
/
config.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
71
package googlecal
import (
"encoding/json"
"golang.org/x/oauth2/google"
"golang.org/x/oauth2/jwt"
)
//DomainName name of domain
type DomainName string
//CalendarConfig config for calendar. Maps domains to configs
type CalendarConfig map[DomainName]*jwt.Config
//revive:disable:var-naming
//UnmarshalJSON -
func (c *CalendarConfig) UnmarshalJSON(b []byte) (err error) {
//Parse config structure and convert
//credentials section to an actual JWT config
//credentials structure
type Temp map[string]struct {
Scopes []string `json:",omitempty"`
Type string
Project_id string
Private_key_id string
Private_key string
Client_email string
Client_id string
Auth_uri string
Token_uri string
Auth_provider_x509_cert_url string
Client_x509_cert_url string
}
temp := Temp{}
json.Unmarshal(b, &temp)
//initialize config and get jwtconfig for each credential
*c = CalendarConfig{}
for account, v := range temp {
scopes := v.Scopes
v.Scopes = []string{}
data, err := json.Marshal(v)
if err != nil {
c = nil
return err
}
config, err := google.JWTConfigFromJSON(data, scopes...)
config.Subject = "REPLACEME"
if err != nil {
c = nil
return err
}
(*c)[DomainName(account)] = config
}
return nil
}
//revive:enable:var-naming
//ParseConfig parses config
func ParseConfig(b []byte) (config CalendarConfig, err error) {
err = json.Unmarshal(b, &config)
return
}