(identity *authsession.Identity, name string, publicKey string)
| 60 | } |
| 61 | |
| 62 | func (d *DeviceManager) AddDevice(identity *authsession.Identity, name string, publicKey string) (*storage.Device, error) { |
| 63 | if name == "" { |
| 64 | return nil, errors.New("device name must not be empty") |
| 65 | } |
| 66 | |
| 67 | clientAddr, err := d.nextClientAddress() |
| 68 | if err != nil { |
| 69 | return nil, errors.Wrap(err, "failed to generate an ip address for device") |
| 70 | } |
| 71 | |
| 72 | device := &storage.Device{ |
| 73 | Owner: identity.Subject, |
| 74 | OwnerName: identity.Name, |
| 75 | OwnerEmail: identity.Email, |
| 76 | OwnerProvider: identity.Provider, |
| 77 | Name: name, |
| 78 | PublicKey: publicKey, |
| 79 | Address: clientAddr, |
| 80 | CreatedAt: time.Now(), |
| 81 | } |
| 82 | |
| 83 | if err := d.SaveDevice(device); err != nil { |
| 84 | return nil, errors.Wrap(err, "failed to save the new device") |
| 85 | } |
| 86 | |
| 87 | return device, nil |
| 88 | } |
| 89 | |
| 90 | func (d *DeviceManager) SaveDevice(device *storage.Device) error { |
| 91 | return d.storage.Save(device) |
nothing calls this directly
no test coverage detected