/
keys.go
67 lines (66 loc) · 2.07 KB
/
keys.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
package auth
//
// func (m *Module) setPublicKey(pemData string) error {
// m.lock.Lock()
// defer m.lock.Unlock()
//
// block, _ := pem.Decode([]byte(pemData))
// if block == nil {
// return errors.New("failed to parse PEM block containing the key")
// }
//
// pub, err := x509.ParsePKIXPublicKey(block.Bytes)
// if err != nil {
// return err
// }
//
// key, ok := pub.(*rsa.PublicKey)
//
// if !ok {
// return errors.New("key type is not a RSA public key")
// }
//
// // Set the public key
// m.config.PublicKey = key
// helpers.Logger.LogInfoln("Public key of runner server set successfully")
// return nil
// }
//
// // We need to retrieve the public key used by the runner server instance. This needs to be done on a periodic
// // basis since the server may generate new pair of public private keys. Let's call this once a week
// func (m *Module) routineGetPublicKey() {
// ticker := time.NewTicker(168 * time.Hour)
// for range ticker.C {
// m.fetchPublicKey()
// }
// }
//
// func (m *Module) fetchPublicKey() (success bool) {
// ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
// defer cancel()
//
// req, err := http.NewRequestWithContext(ctx, "GET", "http://api.spaceuptech.com/v1/runner/runner/public-key", nil)
// if err != nil {
// helpers.Logger.LogError(helpers.GetRequestID(ctx),"Could not fetch runner public key - %s", err.Error())
// return false
// }
//
// res, err := http.DefaultClient.Do(req)
// if err != nil {
// helpers.Logger.LogError(helpers.GetRequestID(ctx),"Could not fetch runner public key - %s", err.Error())
// return false
// }
//
// publicKey := new(model.PublicKeyPayload)
// if err := json.NewDecoder(res.Body).Decode(publicKey); err != nil {
// helpers.Logger.LogError(helpers.GetRequestID(ctx),"Could not decode runner public key payload - %s", err.Error())
// return false
// }
//
// if err := m.setPublicKey(publicKey.PemData); err != nil {
// helpers.Logger.LogError(helpers.GetRequestID(ctx),"Could not parse runner public key - %s", err.Error())
// return false
// }
//
// return true
// }