| 242 | } |
| 243 | |
| 244 | func (k *Kontrol) HandleMachine(r *kite.Request) (interface{}, error) { |
| 245 | var args struct { |
| 246 | AuthType string |
| 247 | } |
| 248 | |
| 249 | err := r.Args.One().Unmarshal(&args) |
| 250 | if err != nil { |
| 251 | return nil, err |
| 252 | } |
| 253 | |
| 254 | var keyPair *KeyPair |
| 255 | |
| 256 | if k.MachineAuthenticate != nil { |
| 257 | // an empty authType is ok, the implementer is responsible of it. It |
| 258 | // can care of it or it can return an error |
| 259 | if err := k.MachineAuthenticate(args.AuthType, r); err != nil { |
| 260 | k.Kite.Log.Error("machine authentication error: %s", err) |
| 261 | |
| 262 | return nil, fmt.Errorf("cannot authenticate user: %s", err) |
| 263 | } |
| 264 | |
| 265 | keyPair, err = k.KeyPair() |
| 266 | } else { |
| 267 | keyPair, err = k.pickKey(r) |
| 268 | } |
| 269 | |
| 270 | if err != nil { |
| 271 | return nil, err |
| 272 | } |
| 273 | |
| 274 | return k.registerUser(r.Client.Kite.Username, keyPair.Public, keyPair.Private) |
| 275 | } |
| 276 | |
| 277 | func (k *Kontrol) HandleGetKey(r *kite.Request) (interface{}, error) { |
| 278 | // Only accept requests with kiteKey because we need this info |