GetKey is used to get a new public key from kontrol if the current one is invalidated. The key is also replaced in memory and every request is going to use it. This means even if kite.key contains the old key, the kite itself uses the new one.
()
| 252 | // to use it. This means even if kite.key contains the old key, the kite itself |
| 253 | // uses the new one. |
| 254 | func (k *Kite) GetKey() (string, error) { |
| 255 | if err := k.SetupKontrolClient(); err != nil { |
| 256 | return "", err |
| 257 | } |
| 258 | |
| 259 | <-k.kontrol.readyConnected |
| 260 | |
| 261 | result, err := k.kontrol.TellWithTimeout("getKey", k.Config.Timeout) |
| 262 | if err != nil { |
| 263 | return "", err |
| 264 | } |
| 265 | |
| 266 | var key string |
| 267 | err = result.Unmarshal(&key) |
| 268 | if err != nil { |
| 269 | return "", err |
| 270 | } |
| 271 | |
| 272 | k.configMu.Lock() |
| 273 | k.Config.KontrolKey = key |
| 274 | k.configMu.Unlock() |
| 275 | |
| 276 | return key, nil |
| 277 | } |
| 278 | |
| 279 | // NewKeyRenewer renews the internal key every given interval |
| 280 | func (k *Kite) NewKeyRenewer(interval time.Duration) { |