Merged in feature/device-secret-reset (pull request #50)
Add route for resetting device secretdevelop
commit
0ab5e8c285
|
@ -24,6 +24,7 @@ def add_resources():
|
||||||
DeviceTypeListResource,
|
DeviceTypeListResource,
|
||||||
DeviceConfigurationResource,
|
DeviceConfigurationResource,
|
||||||
DeviceSecretResource,
|
DeviceSecretResource,
|
||||||
|
DeviceSecretResetResource,
|
||||||
DeviceShareResource,
|
DeviceShareResource,
|
||||||
DeviceShareActivationResource)
|
DeviceShareActivationResource)
|
||||||
from .resources.dashboard import (DashboardResource,
|
from .resources.dashboard import (DashboardResource,
|
||||||
|
@ -55,6 +56,8 @@ def add_resources():
|
||||||
'/v1/devices/<int:device_id>/configuration')
|
'/v1/devices/<int:device_id>/configuration')
|
||||||
api.add_resource(DeviceSecretResource,
|
api.add_resource(DeviceSecretResource,
|
||||||
'/v1/devices/<int:device_id>/secret')
|
'/v1/devices/<int:device_id>/secret')
|
||||||
|
api.add_resource(DeviceSecretResetResource,
|
||||||
|
'/v1/devices/<int:device_id>/secret/reset')
|
||||||
api.add_resource(DeviceShareResource,
|
api.add_resource(DeviceShareResource,
|
||||||
'/v1/devices/<int:device_id>/share')
|
'/v1/devices/<int:device_id>/share')
|
||||||
api.add_resource(
|
api.add_resource(
|
||||||
|
|
|
@ -174,6 +174,14 @@ class DeviceSecretResource(ProtectedResource):
|
||||||
return DeviceSecretSchema().dump(devices.get_device(device_id)), 200
|
return DeviceSecretSchema().dump(devices.get_device(device_id)), 200
|
||||||
|
|
||||||
|
|
||||||
|
class DeviceSecretResetResource(ProtectedResource):
|
||||||
|
@swag_from('swagger/reset_device_secret_spec.yaml')
|
||||||
|
def post(self, device_id):
|
||||||
|
validate_device_ownership(device_id)
|
||||||
|
return DeviceSecretSchema().dump(
|
||||||
|
devices.reset_device_secret(device_id)), 200
|
||||||
|
|
||||||
|
|
||||||
class DeviceShareResource(ProtectedResource):
|
class DeviceShareResource(ProtectedResource):
|
||||||
@use_args(DeviceShareSchema(), locations=('json',))
|
@use_args(DeviceShareSchema(), locations=('json',))
|
||||||
@swag_from('swagger/create_device_share_token_spec.yaml')
|
@swag_from('swagger/create_device_share_token_spec.yaml')
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
Resets a device secret info
|
||||||
|
---
|
||||||
|
tags:
|
||||||
|
- Device
|
||||||
|
parameters:
|
||||||
|
- in: path
|
||||||
|
name: device_id
|
||||||
|
required: true
|
||||||
|
type: integer
|
||||||
|
description: Id of the device
|
||||||
|
responses:
|
||||||
|
200:
|
||||||
|
description: Success
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
required:
|
||||||
|
- content
|
||||||
|
properties:
|
||||||
|
content:
|
||||||
|
$ref: '#/definitions/DeviceSecretInfo'
|
|
@ -2,6 +2,7 @@ import sys
|
||||||
import hmac
|
import hmac
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
import datetime
|
import datetime
|
||||||
|
from secrets import token_urlsafe
|
||||||
from .models import (Device,
|
from .models import (Device,
|
||||||
Recording,
|
Recording,
|
||||||
DeviceAssociation,
|
DeviceAssociation,
|
||||||
|
@ -150,6 +151,17 @@ def get_device(device_id):
|
||||||
return Device.get(id=device_id)
|
return Device.get(id=device_id)
|
||||||
|
|
||||||
|
|
||||||
|
def reset_device_secret(device_id):
|
||||||
|
"""
|
||||||
|
Resets device secret for device with given parameters. Raises error on
|
||||||
|
failure
|
||||||
|
"""
|
||||||
|
device = Device.get(id=device_id)
|
||||||
|
device.device_secret = token_urlsafe(32)
|
||||||
|
device.save()
|
||||||
|
return device
|
||||||
|
|
||||||
|
|
||||||
def can_user_access_device(account_id, device_id):
|
def can_user_access_device(account_id, device_id):
|
||||||
"""
|
"""
|
||||||
Checks if user with given account_id can access device with given device_id
|
Checks if user with given account_id can access device with given device_id
|
||||||
|
|
Loading…
Reference in New Issue