From d7a882cb030e5b51107a1b4c744304e5a722ed37 Mon Sep 17 00:00:00 2001 From: Sergey Fedoseev Date: Mon, 2 Dec 2024 11:26:46 +0100 Subject: [PATCH] Remove unused molecule lambda (#4246) --- .github/dependabot.yml | 5 -- .github/workflows/deploy-lambdas.yaml | 1 - .github/workflows/py-ci.yml | 1 - lambdas/molecule/.python-version | 1 - lambdas/molecule/Dockerfile | 43 ---------- lambdas/molecule/requirements.txt | 30 ------- lambdas/molecule/setup.py | 11 --- .../src/t4_lambda_molecule/__init__.py | 82 ------------------- lambdas/molecule/test-requirements.txt | 4 - lambdas/molecule/tests/__init__.py | 0 lambdas/molecule/tests/test_molecule.py | 77 ----------------- 11 files changed, 255 deletions(-) delete mode 100644 lambdas/molecule/.python-version delete mode 100644 lambdas/molecule/Dockerfile delete mode 100644 lambdas/molecule/requirements.txt delete mode 100644 lambdas/molecule/setup.py delete mode 100644 lambdas/molecule/src/t4_lambda_molecule/__init__.py delete mode 100644 lambdas/molecule/test-requirements.txt delete mode 100644 lambdas/molecule/tests/__init__.py delete mode 100644 lambdas/molecule/tests/test_molecule.py diff --git a/.github/dependabot.yml b/.github/dependabot.yml index a39cef8b6b5..55ae20da8df 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -15,11 +15,6 @@ updates: schedule: interval: "daily" - - package-ecosystem: "docker" - directory: "/lambdas/molecule" - schedule: - interval: "daily" - - package-ecosystem: "docker" directory: "/catalog" schedule: diff --git a/.github/workflows/deploy-lambdas.yaml b/.github/workflows/deploy-lambdas.yaml index 8cf561a973b..abac7e40cd4 100644 --- a/.github/workflows/deploy-lambdas.yaml +++ b/.github/workflows/deploy-lambdas.yaml @@ -65,7 +65,6 @@ jobs: strategy: matrix: path: - - molecule - thumbnail runs-on: ubuntu-latest # These permissions are needed to interact with GitHub's OIDC Token endpoint. diff --git a/.github/workflows/py-ci.yml b/.github/workflows/py-ci.yml index aeeb35486b3..2b8332b060a 100644 --- a/.github/workflows/py-ci.yml +++ b/.github/workflows/py-ci.yml @@ -157,7 +157,6 @@ jobs: path: - access_counts - indexer - - molecule - pkgevents - pkgpush - preview diff --git a/lambdas/molecule/.python-version b/lambdas/molecule/.python-version deleted file mode 100644 index cc1923a40b1..00000000000 --- a/lambdas/molecule/.python-version +++ /dev/null @@ -1 +0,0 @@ -3.8 diff --git a/lambdas/molecule/Dockerfile b/lambdas/molecule/Dockerfile deleted file mode 100644 index 1c91198ced2..00000000000 --- a/lambdas/molecule/Dockerfile +++ /dev/null @@ -1,43 +0,0 @@ -ARG FUNCTION_DIR="/function" - -FROM python:3.8-slim-bullseye@sha256:5c769978386f958886d1301435b77b9921859d0c2216d6b3beadeece51264c76 AS base-image - -FROM base-image as build-image - -# Include global arg in this stage of the build -ARG FUNCTION_DIR -# Create function directory -RUN mkdir -p ${FUNCTION_DIR} - -RUN apt-get update && \ - apt-get install -y --no-install-recommends \ - gcc \ - libc6-dev - -COPY molecule/requirements.txt /requirements/molecule.txt -RUN pip install -U pip setuptools -RUN pip install --target /deps -r /requirements/molecule.txt - -COPY shared/ /src/shared/ -COPY molecule/ /src/molecule/ -RUN pip install --target /lambda --no-deps /src/shared/ /src/molecule/ - -FROM base-image - -RUN apt-get update && \ - apt-get install -y --no-install-recommends \ - openbabel \ - && \ - apt-get clean - -# Include global arg in this stage of the build -ARG FUNCTION_DIR -# Set working directory to function root directory -WORKDIR ${FUNCTION_DIR} - -# Copy in the build image dependencies -COPY --from=build-image /deps ${FUNCTION_DIR} -COPY --from=build-image /lambda ${FUNCTION_DIR} - -ENTRYPOINT ["/usr/local/bin/python", "-m", "awslambdaric"] -CMD ["t4_lambda_molecule.lambda_handler"] diff --git a/lambdas/molecule/requirements.txt b/lambdas/molecule/requirements.txt deleted file mode 100644 index d1e6a1c9add..00000000000 --- a/lambdas/molecule/requirements.txt +++ /dev/null @@ -1,30 +0,0 @@ -# -# This file is autogenerated by pip-compile with Python 3.8 -# by the following command: -# -# pip-compile --extra=lambda --output-file=requirements.txt ../shared/setup.py setup.py -# -attrs==21.4.0 - # via jsonschema -awslambdaric==2.0.4 - # via t4-lambda-shared (../shared/setup.py) -certifi==2024.7.4 - # via requests -charset-normalizer==2.0.12 - # via requests -idna==3.7 - # via requests -importlib-resources==5.7.1 - # via jsonschema -jsonschema==4.6.0 - # via t4-lambda-shared (../shared/setup.py) -pyrsistent==0.18.1 - # via jsonschema -requests==2.32.2 - # via t4_lambda_molecule (setup.py) -simplejson==3.17.2 - # via awslambdaric -urllib3==1.26.19 - # via requests -zipp==3.19.1 - # via importlib-resources diff --git a/lambdas/molecule/setup.py b/lambdas/molecule/setup.py deleted file mode 100644 index 94399bd5cd3..00000000000 --- a/lambdas/molecule/setup.py +++ /dev/null @@ -1,11 +0,0 @@ -from setuptools import find_packages, setup - -setup( - name="t4_lambda_molecule", - version="0.0.1", - packages=find_packages(where="src"), - package_dir={"": "src"}, - install_requires=[ - "requests==2.32.2", - ], -) diff --git a/lambdas/molecule/src/t4_lambda_molecule/__init__.py b/lambdas/molecule/src/t4_lambda_molecule/__init__.py deleted file mode 100644 index 6e85fbf81b1..00000000000 --- a/lambdas/molecule/src/t4_lambda_molecule/__init__.py +++ /dev/null @@ -1,82 +0,0 @@ -""" -Convert molecule files from one format to another. -""" -import gzip -import os -import subprocess -from urllib.parse import urlparse - -import requests - -from t4_lambda_shared.decorator import api, validate -from t4_lambda_shared.utils import get_default_origins, make_json_response - -FORMATS = { - "chemical/x-mdl-molfile": "mol", -} - -SCHEMA = { - "type": "object", - "properties": { - "url": { - "type": "string", - }, - "format": { - "enum": list(FORMATS), - }, - }, - "required": ["url", "format"], - "additionalProperties": False, -} - -OBABEL = "/usr/bin/obabel" - - -@api(cors_origins=get_default_origins()) -@validate(SCHEMA) -def lambda_handler(request): - """ - Convert molecule formats - """ - url = request.args["url"] - format_ = request.args["format"] - - resp = requests.get(url) - if not resp.ok: - # Errored, return error code - ret_val = { - "error": resp.reason, - "text": resp.text, - } - return make_json_response(resp.status_code, ret_val) - input_bytes = resp.content - - filename = urlparse(url).path.rpartition("/")[-1] - input_base, input_ext = os.path.splitext(filename) - if input_ext == ".gz": - input_ext = os.path.splitext(input_base)[1] - input_bytes = gzip.decompress(input_bytes) - input_ext = input_ext[1:] - - p = subprocess.run( - ( - OBABEL, - f"-i{input_ext}", - f"-o{FORMATS[format_]}", - ), - check=False, - input=input_bytes, - capture_output=True, - ) - - if p.returncode != 0: - return make_json_response(403, {"error": p.stderr.decode()}) - - data = p.stdout - - headers = { - "Content-Type": format_, - "Content-Disposition": f'inline; filename="{input_base}.{FORMATS[format_]}"', - } - - return 200, data, headers diff --git a/lambdas/molecule/test-requirements.txt b/lambdas/molecule/test-requirements.txt deleted file mode 100644 index 6d168073336..00000000000 --- a/lambdas/molecule/test-requirements.txt +++ /dev/null @@ -1,4 +0,0 @@ -pytest==6.2.5 -pytest-cov==3.0.0 -pytest-raises==0.11 -responses==0.21.0 diff --git a/lambdas/molecule/tests/__init__.py b/lambdas/molecule/tests/__init__.py deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/lambdas/molecule/tests/test_molecule.py b/lambdas/molecule/tests/test_molecule.py deleted file mode 100644 index a4060b55e4b..00000000000 --- a/lambdas/molecule/tests/test_molecule.py +++ /dev/null @@ -1,77 +0,0 @@ -import json -from unittest.mock import patch - -import pytest -import responses - -import t4_lambda_molecule - -HEADER_403 = { - "x-amz-request-id": "guid123", - "x-amz-id-2": "some/dat/here/+xxxxx+=", - "Content-Type": "application/xml", - "Transfer-Encoding": "chunked", - "Date": "Tue, 08 Sep 2020 00:01:06 GMT", - "Server": "AmazonS3", -} - - -def _make_event(query, headers=None): - return { - "httpMethod": "POST", - "path": "/foo", - "pathParameters": {}, - "queryStringParameters": query or None, - "headers": headers or None, - "body": None, - "isBase64Encoded": False, - } - - -@responses.activate -def test_403(): - """test 403 cases, such as Glacier""" - url = "https://example.com/folder/file.ext" - responses.add( - responses.GET, - url=url, - status=403, - headers=HEADER_403, - ) - event = _make_event({"url": url, "format": "chemical/x-mdl-molfile"}) - - # Get the response - with patch.object(t4_lambda_molecule, "OBABEL", "/bin/false"): - response = t4_lambda_molecule.lambda_handler(event, None) - - assert response["statusCode"] == 403 - body = json.loads(response["body"]) - assert "text" in body - assert "error" in body - - -@responses.activate -@pytest.mark.parametrize( - "format_,expected_extension", - [ - ("chemical/x-mdl-molfile", "mol") - ], -) -def test_format(format_, expected_extension): - filename_base = "file" - url = f"https://example.com/folder/{filename_base}.ext" - responses.add( - responses.GET, - url=url, - status=200, - body="", - ) - event = _make_event({"url": url, "format": format_}) - - # Get the response - with patch.object(t4_lambda_molecule, "OBABEL", "/bin/true"): - response = t4_lambda_molecule.lambda_handler(event, None) - - assert response["statusCode"] == 200 - assert response["body"] == "" - assert response["headers"]["Content-Disposition"] == f'inline; filename="{filename_base}.{expected_extension}"'