From 114e5bb951e39b8365a6fe41e7807fd0680e9758 Mon Sep 17 00:00:00 2001 From: Daniel McKnight <34697904+NeonDaniel@users.noreply.github.com> Date: Thu, 12 Aug 2021 11:27:24 -0700 Subject: [PATCH 01/15] Fix bugs found in initial testing (#10) * Handle alternative kwargs in OWM, AV Encapsulate errors in handle_api_input * Update OWM log reference Updated message_id logging --- neon_api_proxy/alpha_vantage_api.py | 2 +- neon_api_proxy/api_connector.py | 36 ++++++++++++++++------------- neon_api_proxy/owm_api.py | 4 ++-- version.py | 2 +- 4 files changed, 24 insertions(+), 20 deletions(-) diff --git a/neon_api_proxy/alpha_vantage_api.py b/neon_api_proxy/alpha_vantage_api.py index 4b39ef7..8e056fb 100644 --- a/neon_api_proxy/alpha_vantage_api.py +++ b/neon_api_proxy/alpha_vantage_api.py @@ -77,7 +77,7 @@ def handle_query(self, **kwargs) -> dict: :return: dict containing stock data from URL response """ symbol = kwargs.get('symbol') - company = kwargs.get('company') + company = kwargs.get('company', kwargs.get('keywords')) search_term = symbol or company if not search_term: return {"status_code": -1, diff --git a/neon_api_proxy/api_connector.py b/neon_api_proxy/api_connector.py index 5dc6944..48b18ba 100644 --- a/neon_api_proxy/api_connector.py +++ b/neon_api_proxy/api_connector.py @@ -56,25 +56,29 @@ def handle_api_input(self, :param method: MQ return method (pika.spec.Basic.Return) :param properties: MQ properties (pika.spec.BasicProperties) :param body: request body (bytes) - """ - if body and isinstance(body, bytes): - request = b64_to_dict(body) - LOG.debug(f"request={request}") - respond = self.proxy.resolve_query(request) - LOG.debug(f"respond={respond}") - data = dict_to_b64(respond) + message_id = None + try: + if body and isinstance(body, bytes): + request = b64_to_dict(body) + message_id = request.get("message_id") + respond = self.proxy.resolve_query(request) + LOG.debug(f"message={message_id} status={respond.get('status_code')}") + data = dict_to_b64(respond) - # queue declare is idempotent, just making sure queue exists - channel.queue_declare(queue='neon_api_output') + # queue declare is idempotent, just making sure queue exists + channel.queue_declare(queue='neon_api_output') - channel.basic_publish(exchange='', - routing_key='neon_api_output', - body=data, - properties=pika.BasicProperties(expiration='1000') - ) - else: - raise TypeError(f'Invalid body received, expected: bytes string; got: {type(body)}') + channel.basic_publish(exchange='', + routing_key='neon_api_output', + body=data, + properties=pika.BasicProperties(expiration='1000') + ) + else: + raise TypeError(f'Invalid body received, expected: bytes string; got: {type(body)}') + except Exception as e: + LOG.error(f"message_id={message_id}") + LOG.error(e) def run(self): self.run_consumers() diff --git a/neon_api_proxy/owm_api.py b/neon_api_proxy/owm_api.py index e00aee2..47d316e 100644 --- a/neon_api_proxy/owm_api.py +++ b/neon_api_proxy/owm_api.py @@ -21,7 +21,7 @@ from requests import Response from neon_api_proxy.cached_api import CachedAPI -from neon_utils.log_utils import LOG +from neon_utils.logger import LOG from neon_utils.authentication_utils import find_neon_owm_key @@ -45,7 +45,7 @@ def handle_query(self, **kwargs) -> dict: :return: dict containing `status_code`, `content`, `encoding` from URL response """ lat = kwargs.get("lat") - lng = kwargs.get("lng") + lng = kwargs.get("lng", kwargs.get("lon")) units = "metric" if kwargs.get("units") == "metric" else "imperial" if not all((lat, lng, units)): diff --git a/version.py b/version.py index 59eb49b..d3ab167 100644 --- a/version.py +++ b/version.py @@ -17,4 +17,4 @@ # US Patents 2008-2021: US7424516, US20140161250, US20140177813, US8638908, US8068604, US8553852, US10530923, US10530924 # China Patent: CN102017585 - Europe Patent: EU2156652 - Patents Pending -__version__ = "0.0.2" +__version__ = "0.0.3" From 96693ef7a1a5ac81c8a9935c847f64792987bb5a Mon Sep 17 00:00:00 2001 From: Daniel McKnight <34697904+NeonDaniel@users.noreply.github.com> Date: Thu, 12 Aug 2021 13:49:21 -0700 Subject: [PATCH 02/15] Add github automation for PRs, Releases, PyPI Publishing (#11) --- .github/workflows/publish_release.yml | 40 ++++++++++++++++++++++++ .github/workflows/publish_test_build.yml | 40 ++++++++++++++++++++++++ .github/workflows/pull_master.yml | 21 +++++++++++++ 3 files changed, 101 insertions(+) create mode 100644 .github/workflows/publish_release.yml create mode 100644 .github/workflows/publish_test_build.yml create mode 100644 .github/workflows/pull_master.yml diff --git a/.github/workflows/publish_release.yml b/.github/workflows/publish_release.yml new file mode 100644 index 0000000..65ee102 --- /dev/null +++ b/.github/workflows/publish_release.yml @@ -0,0 +1,40 @@ +# This workflow will generate a release distribution and upload it to PyPI + +name: Publish Build and GitHub Release +on: + push: + branches: + - master + +jobs: + tag_release: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Get Version + run: | + VERSION=$(python setup.py --version) + echo "VERSION=${VERSION}" >> $GITHUB_ENV + - uses: ncipollo/release-action@v1 + with: + token: ${{secrets.GITHUB_TOKEN}} + tag: ${{env.VERSION}} + build_and_publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Setup Python + uses: actions/setup-python@v1 + with: + python-version: 3.8 + - name: Install Build Tools + run: | + python -m pip install build wheel + + - name: Build Distribution Packages + run: | + python setup.py bdist_wheel + - name: Publish to Test PyPI + uses: pypa/gh-action-pypi-publish@master + with: + password: ${{secrets.PYPI_TOKEN}} \ No newline at end of file diff --git a/.github/workflows/publish_test_build.yml b/.github/workflows/publish_test_build.yml new file mode 100644 index 0000000..37c36ee --- /dev/null +++ b/.github/workflows/publish_test_build.yml @@ -0,0 +1,40 @@ +# This workflow will generate a distribution and upload it to PyPI + +name: Publish Alpha Build +on: + push: + branches: + - dev + paths-ignore: + - 'version.py' + workflow_dispatch: + +jobs: + build_and_publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + ref: ${{ github.head_ref }} + - name: Setup Python + uses: actions/setup-python@v1 + with: + python-version: 3.8 + - name: Install Build Tools + run: | + python -m pip install build wheel + - name: Increment Version + run: | + VER=$(python setup.py --version) + python version_bump.py + - name: Push Version Change + uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: Increment Version + - name: Build Distribution Packages + run: | + python setup.py bdist_wheel + - name: Publish to Test PyPI + uses: pypa/gh-action-pypi-publish@master + with: + password: ${{secrets.PYPI_TOKEN}} diff --git a/.github/workflows/pull_master.yml b/.github/workflows/pull_master.yml new file mode 100644 index 0000000..8e9c5a8 --- /dev/null +++ b/.github/workflows/pull_master.yml @@ -0,0 +1,21 @@ +# This workflow will generate a PR for changes in cert into master + +name: Pull to Master +on: + push: + branches: + - dev + workflow_dispatch: + +jobs: + pull_changes: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: pull-request-action + uses: repo-sync/pull-request@v2 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + pr_reviewer: 'neonreviewers' + pr_assignee: 'neondaniel' + pr_draft: true \ No newline at end of file From 248ccb20e26a3b215ecd8af01a85c237d28e5e3a Mon Sep 17 00:00:00 2001 From: Daniel McKnight <34697904+NeonDaniel@users.noreply.github.com> Date: Thu, 12 Aug 2021 13:53:42 -0700 Subject: [PATCH 03/15] Add version_bump.py for action compatibility (#13) --- version_bump.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 version_bump.py diff --git a/version_bump.py b/version_bump.py new file mode 100644 index 0000000..a55f158 --- /dev/null +++ b/version_bump.py @@ -0,0 +1,45 @@ +# NEON AI (TM) SOFTWARE, Software Development Kit & Application Development System +# +# Copyright 2008-2021 Neongecko.com Inc. | All Rights Reserved +# +# Notice of License - Duplicating this Notice of License near the start of any file containing +# a derivative of this software is a condition of license for this software. +# Friendly Licensing: +# No charge, open source royalty free use of the Neon AI software source and object is offered for +# educational users, noncommercial enthusiasts, Public Benefit Corporations (and LLCs) and +# Social Purpose Corporations (and LLCs). Developers can contact developers@neon.ai +# For commercial licensing, distribution of derivative works or redistribution please contact licenses@neon.ai +# Distributed on an "AS IS” basis without warranties or conditions of any kind, either express or implied. +# Trademarks of Neongecko: Neon AI(TM), Neon Assist (TM), Neon Communicator(TM), Klat(TM) +# Authors: Guy Daniels, Daniel McKnight, Regina Bloomstine, Elon Gasper, Richard Leeds +# +# Specialized conversational reconveyance options from Conversation Processing Intelligence Corp. +# US Patents 2008-2021: US7424516, US20140161250, US20140177813, US8638908, US8068604, US8553852, US10530923, US10530924 +# China Patent: CN102017585 - Europe Patent: EU2156652 - Patents Pending + +import fileinput +from os.path import join, dirname + +with open(join(dirname(__file__), "version.py"), "r", encoding="utf-8") as v: + for line in v.readlines(): + if line.startswith("__version__"): + if '"' in line: + version = line.split('"')[1] + else: + version = line.split("'")[1] + +if "a" not in version: + parts = version.split('.') + parts[-1] = str(int(parts[-1]) + 1) + version = '.'.join(parts) + version = f"{version}a0" +else: + post = version.split("a")[1] + new_post = int(post) + 1 + version = version.replace(f"a{post}", f"a{new_post}") + +for line in fileinput.input(join(dirname(__file__), "version.py"), inplace=True): + if line.startswith("__version__"): + print(f"__version__ = \"{version}\"") + else: + print(line.rstrip('\n')) From cf3cdd5b2e035f34ab016772acac194c57dae8dc Mon Sep 17 00:00:00 2001 From: NeonDaniel Date: Thu, 12 Aug 2021 20:54:27 +0000 Subject: [PATCH 04/15] Increment Version --- version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.py b/version.py index d3ab167..af4ebe4 100644 --- a/version.py +++ b/version.py @@ -17,4 +17,4 @@ # US Patents 2008-2021: US7424516, US20140161250, US20140177813, US8638908, US8068604, US8553852, US10530923, US10530924 # China Patent: CN102017585 - Europe Patent: EU2156652 - Patents Pending -__version__ = "0.0.3" +__version__ = "0.0.4a0" From c56d09ea8e810104f5e31724663ca71581cf8a60 Mon Sep 17 00:00:00 2001 From: Daniel McKnight <34697904+NeonDaniel@users.noreply.github.com> Date: Thu, 12 Aug 2021 13:59:38 -0700 Subject: [PATCH 05/15] Update neon_mq_spec to reference PyPI instead of git repo (#14) --- requirements/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/requirements.txt b/requirements/requirements.txt index 67ec3ce..afc214a 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -1,4 +1,4 @@ requests-cache==0.6.4 requests~=2.25 neon_utils>=0.6.1a6 -neon_mq_connector @ git+https://github.com/neongeckocom/neon_mq_connector +neon_mq_connector>=0.0.4 From 73f0780b923b10d5ee25b90c915de34632ba85d7 Mon Sep 17 00:00:00 2001 From: NeonDaniel Date: Thu, 12 Aug 2021 21:00:24 +0000 Subject: [PATCH 06/15] Increment Version --- version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.py b/version.py index af4ebe4..c0f208f 100644 --- a/version.py +++ b/version.py @@ -17,4 +17,4 @@ # US Patents 2008-2021: US7424516, US20140161250, US20140177813, US8638908, US8068604, US8553852, US10530923, US10530924 # China Patent: CN102017585 - Europe Patent: EU2156652 - Patents Pending -__version__ = "0.0.4a0" +__version__ = "0.0.4a1" From b0af5afa9f0af31e3a80fc36921ac49034bd4813 Mon Sep 17 00:00:00 2001 From: Daniel McKnight <34697904+NeonDaniel@users.noreply.github.com> Date: Thu, 12 Aug 2021 15:43:20 -0700 Subject: [PATCH 07/15] Fix typo in get_proxy_config method (#15) --- neon_api_proxy/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neon_api_proxy/config.py b/neon_api_proxy/config.py index c826268..cd95492 100644 --- a/neon_api_proxy/config.py +++ b/neon_api_proxy/config.py @@ -33,7 +33,7 @@ def get_proxy_config() -> dict: if path.isfile(path.expanduser(config_path)): valid_config_path = path.expanduser(config_path) elif path.isfile(path.expanduser("~/.config/neon/credentials.json")): - valid_config_path = path.expanduser("~/.local/share/neon/credentials.json") + valid_config_path = path.expanduser("~/.config/neon/credentials.json") elif path.isfile(path.expanduser("~/.local/share/neon/credentials.json")): valid_config_path = path.expanduser("~/.local/share/neon/credentials.json") else: From 584159fd110417fda499363fd60212886d2e01f7 Mon Sep 17 00:00:00 2001 From: NeonDaniel Date: Thu, 12 Aug 2021 22:43:57 +0000 Subject: [PATCH 08/15] Increment Version --- version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.py b/version.py index c0f208f..6e367d2 100644 --- a/version.py +++ b/version.py @@ -17,4 +17,4 @@ # US Patents 2008-2021: US7424516, US20140161250, US20140177813, US8638908, US8068604, US8553852, US10530923, US10530924 # China Patent: CN102017585 - Europe Patent: EU2156652 - Patents Pending -__version__ = "0.0.4a1" +__version__ = "0.0.4a2" From f1a2914c9cd0d0dd972679b5fd53f9713bb0161d Mon Sep 17 00:00:00 2001 From: Daniel McKnight <34697904+NeonDaniel@users.noreply.github.com> Date: Fri, 13 Aug 2021 10:42:33 -0700 Subject: [PATCH 09/15] Adds TestAPI class at 'api_test_endpoint' to isolate MQ Connector testing (#16) --- neon_api_proxy/controller.py | 4 +++- neon_api_proxy/test_api.py | 43 ++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 neon_api_proxy/test_api.py diff --git a/neon_api_proxy/controller.py b/neon_api_proxy/controller.py index 17f0f35..0324006 100644 --- a/neon_api_proxy/controller.py +++ b/neon_api_proxy/controller.py @@ -4,6 +4,7 @@ from neon_api_proxy.owm_api import OpenWeatherAPI from neon_api_proxy.alpha_vantage_api import AlphaVantageAPI from neon_api_proxy.wolfram_api import WolframAPI +from neon_api_proxy.test_api import TestAPI class NeonAPIProxyController: @@ -15,7 +16,8 @@ class NeonAPIProxyController: service_class_mapping = { 'wolfram_alpha': WolframAPI, 'alpha_vantage': AlphaVantageAPI, - 'open_weather_map': OpenWeatherAPI + 'open_weather_map': OpenWeatherAPI, + 'api_test_endpoint': TestAPI } def __init__(self, config: dict = None): diff --git a/neon_api_proxy/test_api.py b/neon_api_proxy/test_api.py new file mode 100644 index 0000000..be56bd2 --- /dev/null +++ b/neon_api_proxy/test_api.py @@ -0,0 +1,43 @@ +# NEON AI (TM) SOFTWARE, Software Development Kit & Application Development System +# +# Copyright 2008-2021 Neongecko.com Inc. | All Rights Reserved +# +# Notice of License - Duplicating this Notice of License near the start of any file containing +# a derivative of this software is a condition of license for this software. +# Friendly Licensing: +# No charge, open source royalty free use of the Neon AI software source and object is offered for +# educational users, noncommercial enthusiasts, Public Benefit Corporations (and LLCs) and +# Social Purpose Corporations (and LLCs). Developers can contact developers@neon.ai +# For commercial licensing, distribution of derivative works or redistribution please contact licenses@neon.ai +# Distributed on an "AS IS” basis without warranties or conditions of any kind, either express or implied. +# Trademarks of Neongecko: Neon AI(TM), Neon Assist (TM), Neon Communicator(TM), Klat(TM) +# Authors: Guy Daniels, Daniel McKnight, Regina Bloomstine, Elon Gasper, Richard Leeds +# +# Specialized conversational reconveyance options from Conversation Processing Intelligence Corp. +# US Patents 2008-2021: US7424516, US20140161250, US20140177813, US8638908, US8068604, US8553852, US10530923, US10530924 +# China Patent: CN102017585 - Europe Patent: EU2156652 - Patents Pending + +import urllib.parse + +from enum import Enum +from neon_utils.log_utils import LOG +from neon_utils.authentication_utils import find_neon_wolfram_key +from neon_api_proxy.cached_api import CachedAPI + + +class TestAPI(CachedAPI): + """ + API for querying Wolfram|Alpha. + """ + + def __init__(self, api_key: str = None): + super().__init__("Test") + + def handle_query(self, **kwargs) -> dict: + """ + Handles an incoming query and provides a response + :return: dict containing `status_code`, `content`, `encoding` from URL response + """ + return {"status_code": 200, + "content": "Success", + "encoding": None} From afb3c970fd27cdf4eff27ad74192372711146670 Mon Sep 17 00:00:00 2001 From: NeonDaniel Date: Fri, 13 Aug 2021 17:43:13 +0000 Subject: [PATCH 10/15] Increment Version --- version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.py b/version.py index 6e367d2..06eff6f 100644 --- a/version.py +++ b/version.py @@ -17,4 +17,4 @@ # US Patents 2008-2021: US7424516, US20140161250, US20140177813, US8638908, US8068604, US8553852, US10530923, US10530924 # China Patent: CN102017585 - Europe Patent: EU2156652 - Patents Pending -__version__ = "0.0.4a2" +__version__ = "0.0.4a3" From 7fb0429b1f1881da903a2502c8117d15cb300a7d Mon Sep 17 00:00:00 2001 From: Daniel McKnight <34697904+NeonDaniel@users.noreply.github.com> Date: Tue, 17 Aug 2021 09:47:32 -0700 Subject: [PATCH 11/15] Add dockerfile and github automation (#17) * Update config paths to handle ENV paths for API and MQ configurations Add dockerfile for initial Docker container implementation Document Docker usage in README.md * Update dockerfile to build from local branch Add action to publish docker image * Update vars used in docker action * Troubleshooting vars in Container tags * Troubleshooting IMAGE var in Container tags * Troubleshooting var substitution in docker tags * Troubleshooting docker tags * Troubleshooting docker tag strings * Fix typo in docker workflow * Fix typo in docker workflow * Troubleshooting tags * Troubleshooting tags * Troubleshooting tags * Use example meta extraction * Rollback action changes to match Github example code * Update dockerfile to build from python image instead of ubuntu * Add version to docker tags * Troubleshoot passing version between workflow steps * Cleanup version for semver compat. * Fix typo in version formatting * Troubleshooting version string formatting * Add back branch tag * Update docker container automation to run on alpha build publishing (dev branch) --- .../workflows/publish_docker_container.yml | 59 +++++++++++++++++++ Dockerfile | 18 ++++++ README.md | 6 ++ neon_api_proxy/config.py | 4 +- 4 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/publish_docker_container.yml create mode 100644 Dockerfile diff --git a/.github/workflows/publish_docker_container.yml b/.github/workflows/publish_docker_container.yml new file mode 100644 index 0000000..c36be44 --- /dev/null +++ b/.github/workflows/publish_docker_container.yml @@ -0,0 +1,59 @@ +# This workflow will generate a release distribution and upload it to PyPI + +name: Publish Docker Image +on: + push: + branches: + - master + workflow_run: + workflows: + - "Publish Alpha Build" + types: + - completed + workflow_dispatch: + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build_and_publish: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Log in to the Container registry + uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Get Version + id: version + run: | + VERSION=$(sed "s/a/-a./" <<< $(python setup.py --version)) + echo ::set-output name=version::${VERSION} + env: + image_name: ${{ env.IMAGE_NAME }} + + - name: Extract metadata for Docker + id: meta + uses: docker/metadata-action@v2 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=semver,pattern={{version}},value=${{ steps.version.outputs.version }} + type=ref,event=branch + + - name: Build and push Docker image + uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f9d51e6 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +FROM python:3.8 + +ADD . /neon_api_proxy +WORKDIR /neon_api_proxy +RUN apt-get update && \ + apt-get install -y \ + gcc \ + python3 \ + python3-dev \ + && pip install wheel \ + && pip install . + +WORKDIR /config + +ENV NEON_API_PROXY_CONFIG_PATH /config/config.json +ENV NEON_MQ_PROXY_CONFIG_PATH /config/config.json + +CMD ["neon_api_proxy"] \ No newline at end of file diff --git a/README.md b/README.md index 0be6281..bc9e54e 100644 --- a/README.md +++ b/README.md @@ -22,4 +22,10 @@ Responses will be returned as dictionaries. Responses should contain the followi - `content` - Usually contains the HTTP content (bytes) from the requested API, but may include a string message for errors. - `encoding` = Usually contains the HTTP content encoding if content is the byte representation of a string, may be `None` +## Docker Configuration +When running this as a docker container, the path to configuration files should be mounted to `/config`. +For example, if your configuration resides in `~/.config`: +```commandline +docker run -v /home/$USER/.config:/config neon_api_proxy +``` diff --git a/neon_api_proxy/config.py b/neon_api_proxy/config.py index cd95492..dd96c45 100644 --- a/neon_api_proxy/config.py +++ b/neon_api_proxy/config.py @@ -48,8 +48,8 @@ def get_mq_config() -> dict: Locates a valid MQ config for MQ Authentication :return: dict containing "MQ" key with server and users configurations """ - if path.isfile("config.json"): - valid_config_path = "config.json" + if environ.get('NEON_MQ_CONFIG_PATH', 'config.json'): + valid_config_path = environ.get('NEON_API_PROXY_CONFIG_PATH', 'config.json') elif path.isfile(path.expanduser("~/.config/neon/mq_config.json")): valid_config_path = path.expanduser("~/.config/neon/mq_config.json") elif path.isfile(path.expanduser("~/.local/share/neon/mq_config.json")): From 2fb4e7df82b4f16741d51229e3661d1f7613a43e Mon Sep 17 00:00:00 2001 From: NeonDaniel Date: Tue, 17 Aug 2021 16:48:15 +0000 Subject: [PATCH 12/15] Increment Version --- version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.py b/version.py index 06eff6f..21dda24 100644 --- a/version.py +++ b/version.py @@ -17,4 +17,4 @@ # US Patents 2008-2021: US7424516, US20140161250, US20140177813, US8638908, US8068604, US8553852, US10530923, US10530924 # China Patent: CN102017585 - Europe Patent: EU2156652 - Patents Pending -__version__ = "0.0.4a3" +__version__ = "0.0.4a4" From 023c77c300bac83b21573a8e769b77c1f51d9ba5 Mon Sep 17 00:00:00 2001 From: Daniel McKnight <34697904+NeonDaniel@users.noreply.github.com> Date: Wed, 18 Aug 2021 10:08:31 -0700 Subject: [PATCH 13/15] Fix typo in `get_mq_config` (#19) Update consumer registration to use convenience method Handle re-registration and restart of consumers on error --- neon_api_proxy/api_connector.py | 10 +++++++--- neon_api_proxy/config.py | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/neon_api_proxy/api_connector.py b/neon_api_proxy/api_connector.py index 48b18ba..0efe223 100644 --- a/neon_api_proxy/api_connector.py +++ b/neon_api_proxy/api_connector.py @@ -40,9 +40,6 @@ def __init__(self, config: dict, service_name: str, proxy: NeonAPIProxyControlle self.vhost = '/neon_api' self.proxy = proxy - self.consumers = dict(neon_api_consumer=ConsumerThread(connection=self.create_mq_connection(vhost=self.vhost), - queue='neon_api_input', - callback_func=self.handle_api_input)) def handle_api_input(self, channel: pika.channel.Channel, @@ -80,5 +77,12 @@ def handle_api_input(self, LOG.error(f"message_id={message_id}") LOG.error(e) + def handle_error(self, thread, exception): + LOG.error(exception) + LOG.info(f"Restarting Consumers") + self.stop_consumers() + self.run() + def run(self): + self.register_consumer("neon_api_consumer", self.vhost, 'neon_api_input', self.handle_api_input) self.run_consumers() diff --git a/neon_api_proxy/config.py b/neon_api_proxy/config.py index dd96c45..9b02105 100644 --- a/neon_api_proxy/config.py +++ b/neon_api_proxy/config.py @@ -48,7 +48,7 @@ def get_mq_config() -> dict: Locates a valid MQ config for MQ Authentication :return: dict containing "MQ" key with server and users configurations """ - if environ.get('NEON_MQ_CONFIG_PATH', 'config.json'): + if path.isfile(environ.get('NEON_MQ_CONFIG_PATH', 'config.json')): valid_config_path = environ.get('NEON_API_PROXY_CONFIG_PATH', 'config.json') elif path.isfile(path.expanduser("~/.config/neon/mq_config.json")): valid_config_path = path.expanduser("~/.config/neon/mq_config.json") From 82525fc836df462996d5ad3e0a0e83a4e2c4b65c Mon Sep 17 00:00:00 2001 From: NeonDaniel Date: Wed, 18 Aug 2021 17:09:14 +0000 Subject: [PATCH 14/15] Increment Version --- version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.py b/version.py index 21dda24..a70bd00 100644 --- a/version.py +++ b/version.py @@ -17,4 +17,4 @@ # US Patents 2008-2021: US7424516, US20140161250, US20140177813, US8638908, US8068604, US8553852, US10530923, US10530924 # China Patent: CN102017585 - Europe Patent: EU2156652 - Patents Pending -__version__ = "0.0.4a4" +__version__ = "0.0.4a5" From 70b94cf3c717437660a8f2e034097dda8cde5bc2 Mon Sep 17 00:00:00 2001 From: Daniel McKnight <34697904+NeonDaniel@users.noreply.github.com> Date: Wed, 18 Aug 2021 10:18:35 -0700 Subject: [PATCH 15/15] Promote to v0.1.0 (#20) --- version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.py b/version.py index a70bd00..5c562ec 100644 --- a/version.py +++ b/version.py @@ -17,4 +17,4 @@ # US Patents 2008-2021: US7424516, US20140161250, US20140177813, US8638908, US8068604, US8553852, US10530923, US10530924 # China Patent: CN102017585 - Europe Patent: EU2156652 - Patents Pending -__version__ = "0.0.4a5" +__version__ = "0.1.0"