/
runner.go
52 lines (46 loc) · 1.07 KB
/
runner.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
package config
import (
"crypto/rsa"
"net/url"
"github.com/golang-jwt/jwt"
)
const (
RunnerKeyFile = "runner.rsa"
)
type Runner struct {
ID string `json:"id"`
ClientID string `json:"clientId"`
ClientSecret string `json:"clientSecret"`
WebhookSecret string `json:"webhookSecret"`
Host url.URL
PrivateKey *rsa.PrivateKey
}
func (r *Runner) UnmarshalYAML(unmarshal func(interface{}) error) error {
type T struct {
ID *string `yaml:"id"`
ClientID *string `yaml:"clientId"`
ClientSecret *string `yaml:"clientSecret"`
WebhookSecret *string `yaml:"webhookSecret"`
HostStr string `yaml:"host"`
PrivateKeyStr string `yaml:"privateKey"`
}
var v T
if err := unmarshal(&v); err != nil {
return err
}
h, err := url.Parse(v.HostStr)
if err != nil {
return err
}
k, err := jwt.ParseRSAPrivateKeyFromPEM([]byte(v.PrivateKeyStr))
if err != nil {
return err
}
r.ID = *v.ID
r.ClientID = *v.ClientID
r.ClientSecret = *v.ClientSecret
r.WebhookSecret = *v.WebhookSecret
r.Host = *h
r.PrivateKey = k
return nil
}