From a4ecbae369c93b79afc7ab4496152358f6a64722 Mon Sep 17 00:00:00 2001 From: Matheus Lima Date: Wed, 6 Mar 2019 17:11:16 -0300 Subject: [PATCH] Moving the cache instance to the PublicEndpoint class --- api/public/public_api/endpoints/account_device.py | 2 -- api/public/public_api/endpoints/device_activate.py | 2 -- api/public/public_api/endpoints/device_code.py | 2 -- api/public/public_api/endpoints/device_refresh_token.py | 2 -- shared/selene/api/public_endpoint.py | 3 +++ 5 files changed, 3 insertions(+), 8 deletions(-) diff --git a/api/public/public_api/endpoints/account_device.py b/api/public/public_api/endpoints/account_device.py index 4dab054a..67f05fcf 100644 --- a/api/public/public_api/endpoints/account_device.py +++ b/api/public/public_api/endpoints/account_device.py @@ -6,7 +6,6 @@ from schematics.types import StringType, UUIDType from selene.api import PublicEndpoint from selene.data.device import DeviceRepository -from selene.util.cache import SeleneCache from selene.util.db import get_db_connection @@ -21,7 +20,6 @@ class AccountDeviceEndpoint(PublicEndpoint): def __init__(self): super(AccountDeviceEndpoint, self).__init__() - self.cache: SeleneCache = self.config['SELENE_CACHE'] self.device_pairing_time = 86400 def post(self, account_id): diff --git a/api/public/public_api/endpoints/device_activate.py b/api/public/public_api/endpoints/device_activate.py index 78243d7a..8aa4194c 100644 --- a/api/public/public_api/endpoints/device_activate.py +++ b/api/public/public_api/endpoints/device_activate.py @@ -8,7 +8,6 @@ from schematics.types import StringType from selene.api import PublicEndpoint from selene.data.device import DeviceRepository -from selene.util.cache import SeleneCache from selene.util.db import get_db_connection @@ -27,7 +26,6 @@ class DeviceActivateEndpoint(PublicEndpoint): def __init__(self): super(DeviceActivateEndpoint, self).__init__() - self.cache: SeleneCache = self.config.get('SELENE_CACHE') self.sha512 = hashlib.sha512() def post(self): diff --git a/api/public/public_api/endpoints/device_code.py b/api/public/public_api/endpoints/device_code.py index 5723356a..3aaaa2a7 100644 --- a/api/public/public_api/endpoints/device_code.py +++ b/api/public/public_api/endpoints/device_code.py @@ -4,7 +4,6 @@ import random import uuid from selene.api import PublicEndpoint -from selene.util.cache import SeleneCache class DeviceCodeEndpoint(PublicEndpoint): @@ -17,7 +16,6 @@ class DeviceCodeEndpoint(PublicEndpoint): def __init__(self): super(DeviceCodeEndpoint, self).__init__() self.device_pairing_time = 86400 - self.cache: SeleneCache = self.config.get('SELENE_CACHE') self.sha512 = hashlib.sha512() def get(self): diff --git a/api/public/public_api/endpoints/device_refresh_token.py b/api/public/public_api/endpoints/device_refresh_token.py index e24ccf92..2988ca2d 100644 --- a/api/public/public_api/endpoints/device_refresh_token.py +++ b/api/public/public_api/endpoints/device_refresh_token.py @@ -4,7 +4,6 @@ import uuid from http import HTTPStatus from selene.api import PublicEndpoint -from selene.util.cache import SeleneCache class DeviceRefreshTokenEndpoint(PublicEndpoint): @@ -13,7 +12,6 @@ class DeviceRefreshTokenEndpoint(PublicEndpoint): def __init__(self): super(DeviceRefreshTokenEndpoint, self).__init__() - self.cache: SeleneCache = self.config['SELENE_CACHE'] self.sha512 = hashlib.sha512() def get(self): diff --git a/shared/selene/api/public_endpoint.py b/shared/selene/api/public_endpoint.py index 2808b072..dd6acaf6 100644 --- a/shared/selene/api/public_endpoint.py +++ b/shared/selene/api/public_endpoint.py @@ -1,6 +1,8 @@ from flask import current_app, request from flask.views import MethodView +from ..util.cache import SeleneCache + class PublicEndpoint(MethodView): """Abstract class for all endpoints used by Mycroft devices""" @@ -8,3 +10,4 @@ class PublicEndpoint(MethodView): def __init__(self): self.config: dict = current_app.config self.request = request + self.cache: SeleneCache = self.config['SELENE_CACHE']