From 60335863c35989f0ef909c11e4d3390b7f11e79b Mon Sep 17 00:00:00 2001 From: jamshale <31809382+jamshale@users.noreply.github.com> Date: Mon, 12 Aug 2024 15:49:15 -0700 Subject: [PATCH] Remove local firebase plugin (#169) Signed-off-by: jamshale --- acapy/Dockerfile.acapy | 3 +- .../firebase_push_notifications/README.md | 12 -- .../firebase_push_notifications/definition.py | 10 -- .../v1_0/__init__.py | 0 .../v1_0/constants.py | 11 -- .../v1_0/handlers/handler.py | 29 ---- .../v1_0/manager.py | 128 ----------------- .../v1_0/message_types.py | 11 -- .../v1_0/messages/set_device_info.py | 49 ------- .../v1_0/models.py | 55 ------- .../v1_0/routes.py | 135 ------------------ .../v1_0/tests/__init__.py | 0 .../v1_0/tests/test_manager.py | 116 --------------- .../v1_0/tests/test_routes.py | 14 -- .../requirements.dev.txt | 8 -- .../requirements.txt | 5 - .../firebase_push_notifications/setup.py | 25 ---- .../firebase_push_notifications/version.py | 3 - 18 files changed, 1 insertion(+), 613 deletions(-) delete mode 100644 acapy/plugins/firebase_push_notifications/README.md delete mode 100644 acapy/plugins/firebase_push_notifications/firebase_push_notifications/definition.py delete mode 100644 acapy/plugins/firebase_push_notifications/firebase_push_notifications/v1_0/__init__.py delete mode 100644 acapy/plugins/firebase_push_notifications/firebase_push_notifications/v1_0/constants.py delete mode 100644 acapy/plugins/firebase_push_notifications/firebase_push_notifications/v1_0/handlers/handler.py delete mode 100644 acapy/plugins/firebase_push_notifications/firebase_push_notifications/v1_0/manager.py delete mode 100644 acapy/plugins/firebase_push_notifications/firebase_push_notifications/v1_0/message_types.py delete mode 100644 acapy/plugins/firebase_push_notifications/firebase_push_notifications/v1_0/messages/set_device_info.py delete mode 100644 acapy/plugins/firebase_push_notifications/firebase_push_notifications/v1_0/models.py delete mode 100644 acapy/plugins/firebase_push_notifications/firebase_push_notifications/v1_0/routes.py delete mode 100644 acapy/plugins/firebase_push_notifications/firebase_push_notifications/v1_0/tests/__init__.py delete mode 100644 acapy/plugins/firebase_push_notifications/firebase_push_notifications/v1_0/tests/test_manager.py delete mode 100644 acapy/plugins/firebase_push_notifications/firebase_push_notifications/v1_0/tests/test_routes.py delete mode 100644 acapy/plugins/firebase_push_notifications/requirements.dev.txt delete mode 100644 acapy/plugins/firebase_push_notifications/requirements.txt delete mode 100644 acapy/plugins/firebase_push_notifications/setup.py delete mode 100644 acapy/plugins/firebase_push_notifications/version.py diff --git a/acapy/Dockerfile.acapy b/acapy/Dockerfile.acapy index 3db72ac..5d4a62f 100644 --- a/acapy/Dockerfile.acapy +++ b/acapy/Dockerfile.acapy @@ -15,8 +15,7 @@ COPY acapy/start.sh start.sh COPY acapy/configs configs # Copy and install plugins -COPY acapy/plugins plugins -RUN pip3 install --no-cache-dir -e plugins/firebase_push_notifications +RUN pip3 install git+https://github.com/hyperledger/aries-acapy-plugins@0.12.2#subdirectory=firebase_push_notifications RUN chmod +x start.sh && \ aca-py --version > ./acapy-version.txt diff --git a/acapy/plugins/firebase_push_notifications/README.md b/acapy/plugins/firebase_push_notifications/README.md deleted file mode 100644 index 60ad609..0000000 --- a/acapy/plugins/firebase_push_notifications/README.md +++ /dev/null @@ -1,12 +0,0 @@ -To use the push notification protocol plugin you must have a firebase project to send the notifications to and a service account json file with `Firebase Service Management Service Agent` roles. - -In the project .env file you need to supply the information in the `Firebase Plugin Configuration` section. -> USE_FIREBASE_PLUGIN=true -FIREBASE_PROJECT_ID=287275049656 -FIREBASE_NOTIFICATION_TITLE=You have important information in your digital wallet -FIREBASE_NOTIFICATION_BODY=Please open your wallet -FIREBASE_SERVICE_ACCOUNT={ flattend service account json } - -* If `USE_FIREBASE_PLUGIN` is false it will not load the plugin. -* `FIREBASE_PROJECT_ID` can be found in the firebase console -* `FIREBASE_NOTIFICATION_TITLE` and `FIREBASE_NOTIFICATION_BODY` is the information displayed in the push notification. \ No newline at end of file diff --git a/acapy/plugins/firebase_push_notifications/firebase_push_notifications/definition.py b/acapy/plugins/firebase_push_notifications/firebase_push_notifications/definition.py deleted file mode 100644 index 62bddef..0000000 --- a/acapy/plugins/firebase_push_notifications/firebase_push_notifications/definition.py +++ /dev/null @@ -1,10 +0,0 @@ -"""Version definitions for this protocol.""" - -versions = [ - { - "major_version": 1, - "minimum_minor_version": 0, - "current_minor_version": 0, - "path": "v1_0", - } -] diff --git a/acapy/plugins/firebase_push_notifications/firebase_push_notifications/v1_0/__init__.py b/acapy/plugins/firebase_push_notifications/firebase_push_notifications/v1_0/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/acapy/plugins/firebase_push_notifications/firebase_push_notifications/v1_0/constants.py b/acapy/plugins/firebase_push_notifications/firebase_push_notifications/v1_0/constants.py deleted file mode 100644 index 8f3c80c..0000000 --- a/acapy/plugins/firebase_push_notifications/firebase_push_notifications/v1_0/constants.py +++ /dev/null @@ -1,11 +0,0 @@ -"""Acapy""" -FORWARDING_EVENT = 'acapy::forward::received' - -"""Firebase""" -SCOPES = ['https://www.googleapis.com/auth/firebase.messaging'] -BASE_URL = 'https://fcm.googleapis.com' -ENDPOINT_PREFIX = 'v1/projects/' -ENDPOINT_SUFFIX = '/messages:send' - -"""Config""" -MAX_SEND_RATE_MINUTES = 0 \ No newline at end of file diff --git a/acapy/plugins/firebase_push_notifications/firebase_push_notifications/v1_0/handlers/handler.py b/acapy/plugins/firebase_push_notifications/firebase_push_notifications/v1_0/handlers/handler.py deleted file mode 100644 index f97a6c2..0000000 --- a/acapy/plugins/firebase_push_notifications/firebase_push_notifications/v1_0/handlers/handler.py +++ /dev/null @@ -1,29 +0,0 @@ -import logging - -from aries_cloudagent.messaging.base_handler import ( - BaseHandler, - BaseResponder, - RequestContext, -) - -from ..messages.set_device_info import SetDeviceInfo -from ..manager import save_device_token - -LOGGER = logging.getLogger(__name__) - - -class SetDeviceInfoHandler(BaseHandler): - """Message handler class for push notifications.""" - - async def handle(self, context: RequestContext, responder: BaseResponder): - connection_id = context.connection_record.connection_id - LOGGER.info( - f'set-device-info protocol handler called for connection: {connection_id}') - assert isinstance(context.message, SetDeviceInfo) - - device_token = context.message.device_token - device_platform = context.message.device_platform - - await save_device_token(context.profile, device_token, connection_id) - - await responder.send_reply(SetDeviceInfo(device_token=device_token, device_platform=device_platform)) diff --git a/acapy/plugins/firebase_push_notifications/firebase_push_notifications/v1_0/manager.py b/acapy/plugins/firebase_push_notifications/firebase_push_notifications/v1_0/manager.py deleted file mode 100644 index 3b92c53..0000000 --- a/acapy/plugins/firebase_push_notifications/firebase_push_notifications/v1_0/manager.py +++ /dev/null @@ -1,128 +0,0 @@ -import json -import logging -import os -from datetime import timedelta - -import google.auth.transport.requests -import requests -from aries_cloudagent.messaging.util import datetime_now, time_now -from aries_cloudagent.storage.base import StorageNotFoundError -from dateutil import parser -from google.oauth2 import service_account - -from .constants import ( - BASE_URL, - ENDPOINT_PREFIX, - ENDPOINT_SUFFIX, - MAX_SEND_RATE_MINUTES, - SCOPES, -) -from .models import FirebaseConnectionRecord - -PROJECT_ID = os.environ.get('FIREBASE_PROJECT_ID') -FCM_ENDPOINT = ENDPOINT_PREFIX + PROJECT_ID + ENDPOINT_SUFFIX -FCM_URL = BASE_URL + '/' + FCM_ENDPOINT - -LOGGER = logging.getLogger(__name__) - -""" Gets an access token for sending firebase messages with the service account credentials """ -def _get_access_token(): - credentials = service_account.Credentials.from_service_account_info( - json.loads(os.environ.get('FIREBASE_SERVICE_ACCOUNT')), scopes=SCOPES) - request = google.auth.transport.requests.Request() - credentials.refresh(request) - return credentials.token - -""" Attempt to send a push notification to the device associated with the connection id if passes the following checks""" -async def send_message(profile, connection_id): - headers = { - 'Authorization': 'Bearer ' + _get_access_token(), - 'Content-Type': 'application/json; UTF-8' - } - - async with profile.session() as session: - record = None - try: - record = await FirebaseConnectionRecord.retrieve_by_connection_id(session, connection_id) - except StorageNotFoundError as e: - LOGGER.debug( - f'Could not retrieve device token for connection {connection_id} : {e}') - return - - """ Don't send token if it is blank. This is the same as being disabled """ - if not record or record.device_token == '': - return - - """ - To avoid spamming the user with push notifications, - we will only send a push notification if the last one was sent more than MAX_SEND_RATE_MINUTES minutes ago. - """ - if record.sent_time is not None and parser.parse(record.sent_time) > datetime_now() - timedelta(minutes=MAX_SEND_RATE_MINUTES): - LOGGER.info( - f'Connection {connection_id} was sent a push notification within the last {MAX_SEND_RATE_MINUTES} minutes. Skipping.') - return - - LOGGER.info( - f'Sending push notification to firebase from connection: {connection_id}') - - resp = requests.post(FCM_URL, data=json.dumps({ - "message": { - "token": record.device_token, - "notification": { - "title": os.environ.get('FIREBASE_NOTIFICATION_TITLE'), - "body": os.environ.get('FIREBASE_NOTIFICATION_BODY') - }, - "apns": { - "payload": { - "aps": { - "alert": { - "title": os.environ.get('FIREBASE_NOTIFICATION_TITLE'), - "body": os.environ.get('FIREBASE_NOTIFICATION_BODY') - }, - "badge": 1 - } - } - } - } - }), headers=headers) - - if resp.status_code == 200: - LOGGER.info( - f'Successfully sent message to firebase for delivery. response: {resp.text}') - record.sent_time = time_now() - await record.save(session, reason="Sent push notification") - else: - LOGGER.error( - f'Unable to send message to Firebase. response: {resp.text}') - - -""" Save or update the device token for the connection id """ -async def save_device_token(profile, token, connection_id): - conn_token_obj = { - 'connection_id': connection_id, - 'device_token': token, - } - - LOGGER.info(f'Saving device token for connection: {connection_id}') - - conn_token_record: FirebaseConnectionRecord = FirebaseConnectionRecord.deserialize( - conn_token_obj) - - try: - async with profile.session() as session: - records = await FirebaseConnectionRecord.query( - session, - { - "connection_id": connection_id - }, - ) - - if (len(records) == 0): - await conn_token_record.save(session, reason="Saving device token") - elif records[0].device_token != token: - records[0].device_token = token - await records[0].save(session, reason="Updating device token") - except Exception as e: - LOGGER.error( - f'Error saving device token for connection: {connection_id}') - LOGGER.error(e) diff --git a/acapy/plugins/firebase_push_notifications/firebase_push_notifications/v1_0/message_types.py b/acapy/plugins/firebase_push_notifications/firebase_push_notifications/v1_0/message_types.py deleted file mode 100644 index 5316dbb..0000000 --- a/acapy/plugins/firebase_push_notifications/firebase_push_notifications/v1_0/message_types.py +++ /dev/null @@ -1,11 +0,0 @@ -from aries_cloudagent.protocols.didcomm_prefix import DIDCommPrefix - -ARIES_PROTOCOL = "push-notifications-fcm/1.0" -SET_DEVICE_INFO = f"{ARIES_PROTOCOL}/set-device-info" -PROTOCOL_PACKAGE = "firebase_push_notifications.v1_0" - -MESSAGE_TYPES = DIDCommPrefix.qualify_all( - { - SET_DEVICE_INFO: f"{PROTOCOL_PACKAGE}.messages.set_device_info.SetDeviceInfo", - }, -) diff --git a/acapy/plugins/firebase_push_notifications/firebase_push_notifications/v1_0/messages/set_device_info.py b/acapy/plugins/firebase_push_notifications/firebase_push_notifications/v1_0/messages/set_device_info.py deleted file mode 100644 index b81150c..0000000 --- a/acapy/plugins/firebase_push_notifications/firebase_push_notifications/v1_0/messages/set_device_info.py +++ /dev/null @@ -1,49 +0,0 @@ -from marshmallow import EXCLUDE, fields - -from aries_cloudagent.messaging.agent_message import AgentMessage, AgentMessageSchema - -from ..message_types import PROTOCOL_PACKAGE, SET_DEVICE_INFO - -HANDLER_CLASS = ( - f"{PROTOCOL_PACKAGE}.handlers.handler.SetDeviceInfoHandler" -) - - -class SetDeviceInfo(AgentMessage): - """Class defining the structure of a set device info message.""" - - class Meta: - """Metadata for a set device info message.""" - handler_class = HANDLER_CLASS - message_type = SET_DEVICE_INFO - schema_class = "SetDeviceInfoSchema" - - def __init__( - self, - *, - device_token: str = None, - device_platform: str = "Unknown", - **kwargs - ): - super().__init__(**kwargs) - self.device_token = device_token - self.device_platform = device_platform - - -class SetDeviceInfoSchema(AgentMessageSchema): - - class Meta: - model_class = SetDeviceInfo - unknown = EXCLUDE - - device_token = fields.Str( - required=True, - description="Firebase device token", - example="kMCFR-6R6GTfH_XeuXy5v:APA91bHqZgXLV3VtxOxXGy1Sq14_jU5Yhnhc6kTDlF2At3IcuxNK1_kmjak9_f2WAJ8bJHV2GSJj6DBT60j_BqrdTOi9sXIcWEtSBNiJ1vyr9BG0IEsmDuqO4jkIDGNbe2kU_LZf8Q24" - ) - - device_platform = fields.Str( - required=True, - description="Platform of the device", - example="Android" - ) diff --git a/acapy/plugins/firebase_push_notifications/firebase_push_notifications/v1_0/models.py b/acapy/plugins/firebase_push_notifications/firebase_push_notifications/v1_0/models.py deleted file mode 100644 index 5ca9c95..0000000 --- a/acapy/plugins/firebase_push_notifications/firebase_push_notifications/v1_0/models.py +++ /dev/null @@ -1,55 +0,0 @@ -from marshmallow import fields - -from aries_cloudagent.core.profile import ProfileSession -from aries_cloudagent.messaging.models.base_record import BaseRecord, BaseRecordSchema -from aries_cloudagent.messaging.valid import INDY_ISO8601_DATETIME_VALIDATE - - -class FirebaseConnectionRecord(BaseRecord): - """Firebase Connection Record.""" - - RECORD_ID_NAME = "record_id" - RECORD_TYPE = "push_notification_record" - TAG_NAMES = {"connection_id", "device_token", "sent_time"} - - class Meta: - """FirebaseConnectionRecord metadata.""" - - schema_class = "FirebaseConnectionRecordSchema" - - def __init__( - self, - *, - record_id: str = None, - connection_id: str = None, - device_token: str = None, - sent_time: str = None, - **kwargs - ): - """Initialize a new SchemaRecord.""" - super().__init__(record_id, None, **kwargs) - self.connection_id = connection_id - self.device_token = device_token - self.sent_time = sent_time - - @property - def record_id(self) -> str: - """Accessor for this schema's id.""" - return self._id - - @classmethod - async def retrieve_by_connection_id( - cls, session: ProfileSession, connection_id: str - ) -> "FirebaseConnectionRecord": - """Retrieve a firebase connection record by connection ID.""" - tag_filter = {"connection_id": connection_id} - return await cls.retrieve_by_tag_filter(session, tag_filter) - - -class FirebaseConnectionRecordSchema(BaseRecordSchema): - class Meta: - model_class = FirebaseConnectionRecord - - connection_id = fields.Str(required=True) - device_token = fields.Str(required=True) - sent_time = fields.Str(required=False, validate=INDY_ISO8601_DATETIME_VALIDATE) diff --git a/acapy/plugins/firebase_push_notifications/firebase_push_notifications/v1_0/routes.py b/acapy/plugins/firebase_push_notifications/firebase_push_notifications/v1_0/routes.py deleted file mode 100644 index 80d6fe3..0000000 --- a/acapy/plugins/firebase_push_notifications/firebase_push_notifications/v1_0/routes.py +++ /dev/null @@ -1,135 +0,0 @@ -import logging -import re - -from aiohttp import web -from aiohttp_apispec import docs, match_info_schema, request_schema, response_schema -from marshmallow import fields - -from aries_cloudagent.admin.request_context import AdminRequestContext -from aries_cloudagent.connections.models.conn_record import ConnRecord -from aries_cloudagent.messaging.models.openapi import OpenAPISchema -from aries_cloudagent.messaging.valid import UUIDFour -from aries_cloudagent.storage.error import StorageNotFoundError -from aries_cloudagent.core.event_bus import EventBus, Event -from aries_cloudagent.core.profile import Profile - -from .manager import save_device_token, send_message -from .messages.set_device_info import SetDeviceInfoSchema -from .constants import FORWARDING_EVENT - -LOGGER = logging.getLogger(__name__) - - -""" - Event bus registration and handling -""" - - -def register_events(event_bus: EventBus): - LOGGER.info("Registering firebase service on forwarding event") - event_bus.subscribe(re.compile(FORWARDING_EVENT), handle_event_forwarding) - - -async def handle_event_forwarding(profile: Profile, event: Event): - LOGGER.info( - f'handling event forwarding of connection {event.payload["connection_id"]}') - await send_message(profile, event.payload["connection_id"]) - - -""" - Shared schemas -""" - - -class BasicConnIdMatchInfoSchema(OpenAPISchema): - """Path parameters and validators for request taking connection id.""" - - conn_id = fields.Str( - description="Connection identifier", required=True, example=UUIDFour.EXAMPLE - ) - - -""" - Send push notification -""" - - -class SendRequestSchema(OpenAPISchema): - """Schema to allow serialization/deserialization of push notifcation send request.""" - - -class SendResponseSchema(OpenAPISchema): - """Schema to allow serialization/deserialization of push notifcation send request.""" - - -@docs(tags=["push-notification"], summary="Send a push notification to the device of the connection") -@request_schema(SendRequestSchema()) -@response_schema(SendResponseSchema(), 200, description="") -async def send_push_notification(request: web.BaseRequest): - connection_id = request.match_info["conn_id"] - LOGGER.info( - f"Sending push notification to connection {connection_id} from api") - send_message(connection_id) - return web.json_response() - - -""" - Set push notification device info -""" - -class SetDeviceResponseSchema(OpenAPISchema): - """Schema to allow serialization/deserialization of device info request.""" - - -@docs(tags=["push-notification"], summary="Set device info of the connection") -@match_info_schema(BasicConnIdMatchInfoSchema()) -@request_schema(SetDeviceInfoSchema()) -@response_schema(SetDeviceResponseSchema(), 200, description="") -async def set_connection_device_info(request: web.BaseRequest): - context: AdminRequestContext = request["context"] - connection_id = request.match_info["conn_id"] - - try: - async with context.profile.session() as session: - await ConnRecord.retrieve_by_id(session, connection_id) - except StorageNotFoundError as err: - raise web.HTTPNotFound(reason=err.roll_up) from err - - try: - await save_device_token(context.profile, request.get('device_token'), connection_id) - except Exception as e: - raise web.HTTPBadRequest(reason=e) - - return web.json_response({'success': True}) - - -""" - Routes -""" - - -async def register(app: web.Application): - """Register routes.""" - - app.add_routes( - [web.post("/push-notification-fcm/1.0/{conn_id}/send", - send_push_notification)] - ) - app.add_routes( - [web.post("/push-notification-fcm/1.0/{conn_id}/set_device_info", - set_connection_device_info)] - ) - - -def post_process_routes(app: web.Application): - """Amend swagger API.""" - - # Add top-level tags description - if "tags" not in app._state["swagger_dict"]: - app._state["swagger_dict"]["tags"] = [] - app._state["swagger_dict"]["tags"].append( - { - "name": "fcm-push-notification", - "description": "Firebase push notification v1.0", - } - ) diff --git a/acapy/plugins/firebase_push_notifications/firebase_push_notifications/v1_0/tests/__init__.py b/acapy/plugins/firebase_push_notifications/firebase_push_notifications/v1_0/tests/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/acapy/plugins/firebase_push_notifications/firebase_push_notifications/v1_0/tests/test_manager.py b/acapy/plugins/firebase_push_notifications/firebase_push_notifications/v1_0/tests/test_manager.py deleted file mode 100644 index 7df1cbd..0000000 --- a/acapy/plugins/firebase_push_notifications/firebase_push_notifications/v1_0/tests/test_manager.py +++ /dev/null @@ -1,116 +0,0 @@ -import logging -from datetime import timedelta - -import asynctest -import mock -from aries_cloudagent.core.in_memory import InMemoryProfile -from aries_cloudagent.messaging.util import datetime_now, datetime_to_str -from aries_cloudagent.storage.base import StorageNotFoundError - -from ..constants import MAX_SEND_RATE_MINUTES -from ..manager import send_message -from ..models import FirebaseConnectionRecord - -test_logger = logging.getLogger('v1_0.manager') - - -class TestManager(asynctest.TestCase): - async def setUp(self): - self.profile = InMemoryProfile.test_profile() - self.context = self.profile.context - self.test_conn_id = "connection-id" - - @asynctest.patch('requests.post') - @asynctest.patch.object(FirebaseConnectionRecord, 'save') - @asynctest.patch.object(FirebaseConnectionRecord, 'retrieve_by_connection_id') - async def test_send_message_should_retrieve_send_push_and_save_for_valid_connection_with_no_last_sent_time(self, mock_retrieve, mock_save, mock_post): - mock_retrieve.return_value = FirebaseConnectionRecord( - connection_id=self.test_conn_id, - sent_time=None, - device_token="device-token" - ) - mock_post.return_value = mock.Mock(status_code=200) - await send_message(self.profile, self.test_conn_id) - - assert mock_retrieve.await_count == 1 - assert mock_post.called - assert mock_save.await_count == 1 - - @asynctest.patch('requests.post') - @asynctest.patch.object(FirebaseConnectionRecord, 'save') - @asynctest.patch.object(FirebaseConnectionRecord, 'retrieve_by_connection_id') - async def test_send_message_should_do_nothing_when_retrieved_device_token_is_blank(self, mock_retrieve, mock_save, mock_post): - mock_retrieve.return_value = FirebaseConnectionRecord( - connection_id=self.test_conn_id, - sent_time=None, - device_token="" - ) - mock_post.return_value = mock.Mock(status_code=200) - await send_message(self.profile, self.test_conn_id) - - assert mock_retrieve.await_count == 1 - assert not mock_post.called - assert mock_save.await_count == 0 - - @asynctest.patch('requests.post') - @asynctest.patch.object(FirebaseConnectionRecord, 'save') - @asynctest.patch.object(FirebaseConnectionRecord, 'retrieve_by_connection_id') - async def test_send_message_should_do_nothing_for_second_message_less_than_configured_time(self, mock_retrieve, mock_save, mock_post): - mock_retrieve.return_value = FirebaseConnectionRecord( - connection_id=self.test_conn_id, - sent_time=datetime_to_str( - datetime_now() - timedelta(minutes=MAX_SEND_RATE_MINUTES - 1)), - device_token="device-token" - ) - mock_post.return_value = mock.Mock(status_code=200) - await send_message(self.profile, self.test_conn_id) - - assert mock_retrieve.await_count == 1 - assert not mock_post.called - assert mock_save.await_count == 0 - - @asynctest.patch('requests.post') - @asynctest.patch.object(FirebaseConnectionRecord, 'save') - @asynctest.patch.object(FirebaseConnectionRecord, 'retrieve_by_connection_id') - async def test_send_message_should_retrieve_send_push_and_save_for_valid_connection_with_sent_time_greater_than_configured_time(self, mock_retrieve, mock_save, mock_post): - mock_retrieve.return_value = FirebaseConnectionRecord( - connection_id=self.test_conn_id, - sent_time=datetime_to_str( - datetime_now() - timedelta(minutes=MAX_SEND_RATE_MINUTES + 1)), - device_token="device-token" - ) - mock_post.return_value = mock.Mock(status_code=200) - await send_message(self.profile, self.test_conn_id) - - assert mock_retrieve.await_count == 1 - assert mock_post.called - assert mock_save.await_count == 1 - - @asynctest.patch('requests.post') - @asynctest.patch.object(FirebaseConnectionRecord, 'save') - @asynctest.patch.object(FirebaseConnectionRecord, 'retrieve_by_connection_id') - async def test_send_message_should_not_update_record_with_sent_time_when_firebase_fails(self, mock_retrieve, mock_save, mock_post): - mock_retrieve.return_value = FirebaseConnectionRecord( - connection_id=self.test_conn_id, - sent_time=datetime_to_str( - datetime_now() - timedelta(minutes=MAX_SEND_RATE_MINUTES + 1)), - device_token="device-token" - ) - mock_post.return_value = mock.Mock(status_code=400) - await send_message(self.profile, self.test_conn_id) - - assert mock_retrieve.await_count == 1 - assert mock_post.called - assert mock_save.await_count == 0 - - @asynctest.patch.object(FirebaseConnectionRecord, 'retrieve_by_connection_id') - @asynctest.patch.object(test_logger, 'debug') - @asynctest.patch('requests.post') - async def test_send_message_should_log_debug_when_retrieve_raises_error(self, mock_post, mock_logger_debug, mock_retrieve): - mock_retrieve.side_effect = StorageNotFoundError("test") - await send_message(self.profile, self.test_conn_id) - - assert mock_retrieve.await_count == 1 - assert mock_logger_debug.call_count == 1 - assert not mock_post.called - diff --git a/acapy/plugins/firebase_push_notifications/firebase_push_notifications/v1_0/tests/test_routes.py b/acapy/plugins/firebase_push_notifications/firebase_push_notifications/v1_0/tests/test_routes.py deleted file mode 100644 index 1235b8a..0000000 --- a/acapy/plugins/firebase_push_notifications/firebase_push_notifications/v1_0/tests/test_routes.py +++ /dev/null @@ -1,14 +0,0 @@ -from aries_cloudagent.core.event_bus import MockEventBus -from asynctest import TestCase as AsyncTestCase -from asynctest import mock - -from ..routes import register_events - - -class TestRoutes(AsyncTestCase): - - async def test_register_events_subscribes_to_event_bus(self): - mock_event_bus = MockEventBus() - mock_event_bus.subscribe = mock.MagicMock() - register_events(mock_event_bus) - self.assertEqual(mock_event_bus.subscribe.called, True) diff --git a/acapy/plugins/firebase_push_notifications/requirements.dev.txt b/acapy/plugins/firebase_push_notifications/requirements.dev.txt deleted file mode 100644 index 5520fb2..0000000 --- a/acapy/plugins/firebase_push_notifications/requirements.dev.txt +++ /dev/null @@ -1,8 +0,0 @@ -asynctest~=0.13.0 -async-case~=10.1 -pytest~=6.2 -pytest-asyncio==0.14.0 -pytest-cov==2.10.1 -pytest-flake8==1.0.6 -pytest-dotenv==0.5.2 -mock~=4.0 \ No newline at end of file diff --git a/acapy/plugins/firebase_push_notifications/requirements.txt b/acapy/plugins/firebase_push_notifications/requirements.txt deleted file mode 100644 index 8e18519..0000000 --- a/acapy/plugins/firebase_push_notifications/requirements.txt +++ /dev/null @@ -1,5 +0,0 @@ -aries-cloudagent>=0.9.0,<1.0.0 -marshmallow~=3.20.1 -google-auth~=2.25.2 -google-api-python-client~=2.111.0 -requests~=2.31.0 diff --git a/acapy/plugins/firebase_push_notifications/setup.py b/acapy/plugins/firebase_push_notifications/setup.py deleted file mode 100644 index 065ce90..0000000 --- a/acapy/plugins/firebase_push_notifications/setup.py +++ /dev/null @@ -1,25 +0,0 @@ -"""Module setup.""" - -import runpy -from setuptools import setup, find_packages - -PACKAGE_NAME = "firebase_push_notifications" -version_meta = runpy.run_path("./version.py".format(PACKAGE_NAME)) -VERSION = version_meta["__version__"] - - -def parse_requirements(filename): - """Load requirements from a pip requirements file.""" - lineiter = (line.strip() for line in open(filename)) - return [line for line in lineiter if line and not line.startswith("#")] - - -if __name__ == "__main__": - setup( - name=PACKAGE_NAME, - version=VERSION, - packages=find_packages(), - include_package_data=True, - install_requires=parse_requirements("requirements.txt"), - python_requires=">=3.9.16", - ) diff --git a/acapy/plugins/firebase_push_notifications/version.py b/acapy/plugins/firebase_push_notifications/version.py deleted file mode 100644 index 7d0e957..0000000 --- a/acapy/plugins/firebase_push_notifications/version.py +++ /dev/null @@ -1,3 +0,0 @@ -"""Library version information.""" - -__version__ = "0.1.0" \ No newline at end of file