2020-09-29 07:44:35 +00:00
|
|
|
package device
|
|
|
|
|
2020-10-12 14:16:28 +00:00
|
|
|
import "git.nutfactory.org/hoernschen/Matrix/utils"
|
2020-10-04 12:22:52 +00:00
|
|
|
|
|
|
|
func New(name string) (err error, device *Device) {
|
|
|
|
err, id := utils.CreateUUID()
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
err, token := utils.CreateToken()
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
device = &Device{
|
|
|
|
Id: id,
|
|
|
|
Name: name,
|
|
|
|
AccessToken: token,
|
|
|
|
Keys: make(map[string]*Key),
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (device *Device) RenewAccesToken() (err error) {
|
|
|
|
err, token := utils.CreateToken()
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
device.AccessToken = token
|
2020-10-01 15:45:57 +00:00
|
|
|
return
|
|
|
|
}
|