From 19dec65c0cb5a151739b3edb87542fccab244fd5 Mon Sep 17 00:00:00 2001 From: Todd Birchard Date: Sun, 25 Feb 2024 23:30:46 -0500 Subject: [PATCH] Rename config variables. --- .github/workflows/python-app.yml | 12 +++++----- app/github/__init__.py | 4 ++-- app/posts/__init__.py | 9 +------- clients/__init__.py | 10 ++++----- clients/ghost.py | 26 ---------------------- clients/tests/conftest.py | 4 ++-- config.py | 8 +++---- poetry.lock | 38 ++++++++++++++++---------------- requirements.txt | 6 ++--- tests/conftest.py | 2 +- 10 files changed, 43 insertions(+), 76 deletions(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 4d7ee657..ee2ba886 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -41,21 +41,21 @@ jobs: ALGOLIA_APP_ID: ${{ secrets.ALGOLIA_APP_ID }} ALGOLIA_INDEX_NAME: ${{ secrets.ALGOLIA_INDEX_NAME }} ALGOLIA_API_KEY: ${{ secrets.ALGOLIA_API_KEY }} - GCP_CREDENTIALS_JSON: ${{ secrets.GCP_CREDENTIALS_JSON }} + GCP_JSON_CREDENTIALS: ${{ secrets.GCP_JSON_CREDENTIALS }} + GCP_CREDENTIALS: ${{ secrets.GCP_CREDENTIALS }} GCP_PROJECT_NAME: ${{ secrets.GCP_PROJECT_NAME }} - GCP_PROJECT: ${{ secrets.GCP_PROJECT }} - GCP_PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }} GCP_BIGQUERY_TABLE: ${{ secrets.GCP_BIGQUERY_TABLE }} GCP_BIGQUERY_DATASET: ${{ secrets.GCP_BIGQUERY_DATASET }} GCP_BUCKET_URL: ${{ secrets.GCP_BUCKET_URL }} GCP_BUCKET_NAME: ${{ secrets.GCP_BUCKET_NAME }} GHOST_BASE_URL: ${{ secrets.GHOST_BASE_URL }} - GHOST_ADMIN_BASE_URL: ${{ secrets.GHOST_ADMIN_BASE_URL }} + GHOST_ADMIN_API_URL: ${{ secrets.GHOST_ADMIN_API_URL }} + GHOST_CONTENT_API_URL: ${{ secrets.GHOST_CONTENT_API_URL }} GHOST_CLIENT_ID: ${{ secrets.GHOST_CLIENT_ID }} - GHOST_ADMIN_API_KEY: ${{ secrets.GHOST_ADMIN_API_KEY }} - GHOST_CONTENT_API_KEY: ${{ secrets.GHOST_CONTENT_API_KEY }} GHOST_API_USERNAME: ${{ secrets.GHOST_API_USERNAME }} GHOST_API_PASSWORD: ${{ secrets.GHOST_API_PASSWORD }} + GHOST_ADMIN_API_KEY: ${{ secrets.GHOST_ADMIN_API_KEY }} + GHOST_CONTENT_API_KEY: ${{ secrets.GHOST_CONTENT_API_KEY }} MAILGUN_EMAIL_SERVER: ${{ secrets.MAILGUN_EMAIL_SERVER }} MAILGUN_NEWSLETTER_TEMPLATE: ${{ secrets.MAILGUN_NEWSLETTER_TEMPLATE }} MAILGUN_SENDER_API_KEY: ${{ secrets.MAILGUN_SENDER_API_KEY }} diff --git a/app/github/__init__.py b/app/github/__init__.py index d73859bc..6f6e984c 100644 --- a/app/github/__init__.py +++ b/app/github/__init__.py @@ -29,7 +29,7 @@ async def github_pr(request: Request) -> JSONResponse: user = payload["sender"].get("login") pull_request = payload["pull_request"] repo = payload["repository"] - if user in (settings.GITHUB_USERNAME, "dependabot-preview[bot]", "renovate[bot]"): + if user in (settings.GH_USERNAME, "dependabot-preview[bot]", "renovate[bot]"): return JSONResponse( { "pr": { @@ -94,7 +94,7 @@ async def github_issue(request: Request) -> JSONResponse: user = payload["sender"].get("login") issue = payload["issue"] repo = payload["repository"] - if user in (settings.GITHUB_USERNAME, "dependabot-preview[bot]", "renovate[bot]"): + if user in (settings.GH_USERNAME, "dependabot-preview[bot]", "renovate[bot]"): return JSONResponse( { "issue": { diff --git a/app/posts/__init__.py b/app/posts/__init__.py index 92f6b6a5..fc5f80cc 100644 --- a/app/posts/__init__.py +++ b/app/posts/__init__.py @@ -87,15 +87,8 @@ async def batch_update_metadata() -> JSONResponse: ) -@router.get("/backup/") -async def backup_database(): - """Export JSON backup of database.""" - json = ghost.get_json_backup() - return json - - @router.get( - "/post/", + "/{post_id}/", summary="Get a post.", ) async def get_single_post(post_id: str) -> JSONResponse: diff --git a/clients/__init__.py b/clients/__init__.py index b3da4896..92544ea8 100644 --- a/clients/__init__.py +++ b/clients/__init__.py @@ -11,8 +11,8 @@ # Google Cloud Storage images = ImageTransformer( - gcp_project_name=settings.GOOGLE_CLOUD_PROJECT_NAME, - gcp_api_credentials=settings.GOOGLE_CLOUD_CREDENTIALS, + gcp_project_name=settings.GCP_PROJECT_NAME, + gcp_api_credentials=settings.GCP_CREDENTIALS, bucket_name=settings.GCP_BUCKET_NAME, bucket_url=settings.GCP_BUCKET_URL, ) @@ -37,8 +37,8 @@ # Google BigQuery gbq = bigquery.Client( - project=settings.GOOGLE_CLOUD_PROJECT_NAME, - credentials=settings.GOOGLE_CLOUD_CREDENTIALS, + project=settings.GCP_PROJECT_NAME, + credentials=settings.GCP_CREDENTIALS, ) # Mailgun SMTP @@ -49,4 +49,4 @@ ) # Github -gh = Github(settings.GITHUB_API_KEY) +gh = Github(settings.GH_API_KEY) diff --git a/clients/ghost.py b/clients/ghost.py index db716e10..1ce9cb3c 100644 --- a/clients/ghost.py +++ b/clients/ghost.py @@ -235,32 +235,6 @@ def create_member(self, body: dict) -> Tuple[str, int]: LOGGER.error(f"Failed to create Ghost member: {e.response.content}") return e.response.content, e.response.status_code - def get_json_backup(self) -> Optional[dict]: - """ - Download JSON snapshot of Ghost database. - - Optional[dict] - """ - self._https_session() - headers = { - "Authorization": self.session_token, - "accept": "text/html,application/xhtml+xml,application/xml;\ - q=0.9,image/webp,image/apng,*/*;\ - q=0.8,application/signed-exchange;\ - v=b3;q=0.9", - "accept-encoding": "gzip, deflate, br", - "Origin": "hackersandslackers.com", - "Authority": "hackersandslackers.com", - } - endpoint = f"{self.admin_api_url}/db/" - try: - resp = requests.get(endpoint, headers=headers, timeout=20) - return resp.json() - except HTTPError as e: - LOGGER.error(f"HTTPError occurred while fetching JSON backup: {e}") - except Exception as e: - LOGGER.error(f"Unexpected error occurred while fetching JSON backup: {e}") - def get_all_posts(self) -> Optional[List[str]]: """ Fetch all Ghost post URLs. diff --git a/clients/tests/conftest.py b/clients/tests/conftest.py index 51a37525..a53f7e96 100644 --- a/clients/tests/conftest.py +++ b/clients/tests/conftest.py @@ -32,6 +32,6 @@ def mailgun() -> Mailgun: @pytest.fixture def gbq() -> gbqClient: return gbqClient( - project=settings.GOOGLE_CLOUD_PROJECT_NAME, - credentials=settings.GOOGLE_CLOUD_CREDENTIALS, + project=settings.GCP_PROJECT_NAME, + credentials=settings.GCP_CREDENTIALS, ) diff --git a/config.py b/config.py index d104661c..0b068f00 100644 --- a/config.py +++ b/config.py @@ -60,9 +60,9 @@ class Settings(BaseSettings): # Google Cloud Auth GCP_PROJECT_NAME: str = getenv("GCP_PROJECT_NAME") - GCP_CREDENTIALS_JSON: str = getenv("GCP_CREDENTIALS_JSON") + GCP_JSON_CREDENTIALS: str = getenv("GCP_JSON_CREDENTIALS") GCP_CREDENTIALS: Credentials = service_account.Credentials.from_service_account_info( - json.loads(GCP_CREDENTIALS_JSON) + json.loads(GCP_JSON_CREDENTIALS) ) # Google BigQuery @@ -125,8 +125,8 @@ class Settings(BaseSettings): TWILIO_ACCOUNT_SID: str = getenv("TWILIO_ACCOUNT_SID") # Github - GITHUB_USERNAME: str = getenv("GH_USERNAME") - GITHUB_API_KEY: str = getenv("GH_API_KEY") + GH_USERNAME: str = getenv("GH_USERNAME") + GH_API_KEY: str = getenv("GH_API_KEY") settings = Settings() diff --git a/poetry.lock b/poetry.lock index 8caee15e..85eb37bd 100644 --- a/poetry.lock +++ b/poetry.lock @@ -192,13 +192,13 @@ trio = ["trio (>=0.23)"] [[package]] name = "astroid" -version = "3.0.3" +version = "3.1.0" description = "An abstract syntax tree for Python with inference support." optional = false python-versions = ">=3.8.0" files = [ - {file = "astroid-3.0.3-py3-none-any.whl", hash = "sha256:92fcf218b89f449cdf9f7b39a269f8d5d617b27be68434912e11e79203963a17"}, - {file = "astroid-3.0.3.tar.gz", hash = "sha256:4148645659b08b70d72460ed1921158027a9e53ae8b7234149b1400eddacbb93"}, + {file = "astroid-3.1.0-py3-none-any.whl", hash = "sha256:951798f922990137ac090c53af473db7ab4e70c770e6d7fae0cec59f74411819"}, + {file = "astroid-3.1.0.tar.gz", hash = "sha256:ac248253bfa4bd924a0de213707e7ebeeb3138abeb48d798784ead1e56d419d4"}, ] [package.dependencies] @@ -752,13 +752,13 @@ test = ["pytest (>=6)"] [[package]] name = "fastapi" -version = "0.109.2" +version = "0.110.0" description = "FastAPI framework, high performance, easy to learn, fast to code, ready for production" optional = false python-versions = ">=3.8" files = [ - {file = "fastapi-0.109.2-py3-none-any.whl", hash = "sha256:2c9bab24667293b501cad8dd388c05240c850b58ec5876ee3283c47d6e1e3a4d"}, - {file = "fastapi-0.109.2.tar.gz", hash = "sha256:f3817eac96fe4f65a2ebb4baa000f394e55f5fccdaf7f75250804bc58f354f73"}, + {file = "fastapi-0.110.0-py3-none-any.whl", hash = "sha256:87a1f6fb632a218222c5984be540055346a8f5d8a68e8f6fb647b1dc9934de4b"}, + {file = "fastapi-0.110.0.tar.gz", hash = "sha256:266775f0dcc95af9d3ef39bad55cff525329a931d5fd51930aadd4f428bf7ff3"}, ] [package.dependencies] @@ -2215,17 +2215,17 @@ tests = ["coverage[toml] (==5.0.4)", "pytest (>=6.0.0,<7.0.0)"] [[package]] name = "pylint" -version = "3.0.4" +version = "3.1.0" description = "python code static checker" optional = false python-versions = ">=3.8.0" files = [ - {file = "pylint-3.0.4-py3-none-any.whl", hash = "sha256:59ab3532506f32affefeb50d5057a221bb351f5a1383fa36c424c2c6c05e7005"}, - {file = "pylint-3.0.4.tar.gz", hash = "sha256:d73b70b3fff8f3fbdcb49a209b9c7d71d8090c138d61d576d1895e152cb392b3"}, + {file = "pylint-3.1.0-py3-none-any.whl", hash = "sha256:507a5b60953874766d8a366e8e8c7af63e058b26345cfcb5f91f89d987fd6b74"}, + {file = "pylint-3.1.0.tar.gz", hash = "sha256:6a69beb4a6f63debebaab0a3477ecd0f559aa726af4954fc948c51f7a2549e23"}, ] [package.dependencies] -astroid = ">=3.0.1,<=3.1.0-dev0" +astroid = ">=3.1.0,<=3.2.0-dev0" colorama = {version = ">=0.4.5", markers = "sys_platform == \"win32\""} dill = [ {version = ">=0.2", markers = "python_version < \"3.11\""}, @@ -2285,13 +2285,13 @@ tests = ["hypothesis (>=3.27.0)", "pytest (>=3.2.1,!=3.3.0)"] [[package]] name = "pytest" -version = "8.0.1" +version = "8.0.2" description = "pytest: simple powerful testing with Python" optional = false python-versions = ">=3.8" files = [ - {file = "pytest-8.0.1-py3-none-any.whl", hash = "sha256:3e4f16fe1c0a9dc9d9389161c127c3edc5d810c38d6793042fb81d9f48a59fca"}, - {file = "pytest-8.0.1.tar.gz", hash = "sha256:267f6563751877d772019b13aacbe4e860d73fe8f651f28112e9ac37de7513ae"}, + {file = "pytest-8.0.2-py3-none-any.whl", hash = "sha256:edfaaef32ce5172d5466b5127b42e0d6d35ebbe4453f0e3505d96afd93f6b096"}, + {file = "pytest-8.0.2.tar.gz", hash = "sha256:d4051d623a2e0b7e51960ba963193b09ce6daeb9759a451844a21e4ddedfc1bd"}, ] [package.dependencies] @@ -2407,13 +2407,13 @@ files = [ [[package]] name = "sniffio" -version = "1.3.0" +version = "1.3.1" description = "Sniff out which async library your code is running under" optional = false python-versions = ">=3.7" files = [ - {file = "sniffio-1.3.0-py3-none-any.whl", hash = "sha256:eecefdce1e5bbfb7ad2eeaabf7c1eeb404d7757c379bd1f7e5cce9d8bf425384"}, - {file = "sniffio-1.3.0.tar.gz", hash = "sha256:e60305c5e5d314f5389259b7f22aaa33d8f7dee49763119234af3755c55b9101"}, + {file = "sniffio-1.3.1-py3-none-any.whl", hash = "sha256:2f6da418d1f1e0fddd844478f41680e794e6051915791a034ff65e5f100525a2"}, + {file = "sniffio-1.3.1.tar.gz", hash = "sha256:f4324edc670a0f49750a81b895f35c3adb843cca46f0530f79fc1babb23789dc"}, ] [[package]] @@ -2561,13 +2561,13 @@ requests = ">=2.0.0" [[package]] name = "typing-extensions" -version = "4.9.0" +version = "4.10.0" description = "Backported and Experimental Type Hints for Python 3.8+" optional = false python-versions = ">=3.8" files = [ - {file = "typing_extensions-4.9.0-py3-none-any.whl", hash = "sha256:af72aea155e91adfc61c3ae9e0e342dbc0cba726d6cba4b6c72c1f34e47291cd"}, - {file = "typing_extensions-4.9.0.tar.gz", hash = "sha256:23478f88c37f27d76ac8aee6c905017a143b0b1b886c3c9f66bc2fd94f9f5783"}, + {file = "typing_extensions-4.10.0-py3-none-any.whl", hash = "sha256:69b1a937c3a517342112fb4c6df7e72fc39a38e7891a5730ed4985b5214b5475"}, + {file = "typing_extensions-4.10.0.tar.gz", hash = "sha256:b0abd7c89e8fb96f98db18d86106ff1d90ab692004eb746cf6eda2682f91b3cb"}, ] [[package]] diff --git a/requirements.txt b/requirements.txt index 4bf67fd8..4480c0fa 100644 --- a/requirements.txt +++ b/requirements.txt @@ -23,7 +23,7 @@ dnspython==2.6.1 ; python_version >= "3.10" and python_version < "4.0" email-validator==2.1.0.post1 ; python_version >= "3.10" and python_version < "4.0" exceptiongroup==1.2.0 ; python_version >= "3.10" and python_version < "3.11" fastapi-mail==1.4.1 ; python_version >= "3.10" and python_version < "4.0" -fastapi==0.109.2 ; python_version >= "3.10" and python_version < "4.0" +fastapi==0.110.0 ; python_version >= "3.10" and python_version < "4.0" frozenlist==1.4.1 ; python_version >= "3.10" and python_version < "4.0" google-api-core==2.17.1 ; python_version >= "3.10" and python_version < "4.0" google-auth==2.28.1 ; python_version >= "3.10" and python_version < "4.0" @@ -70,11 +70,11 @@ pytz==2024.1 ; python_version >= "3.10" and python_version < "4.0" requests==2.31.0 ; python_version >= "3.10" and python_version < "4.0" rsa==4.9 ; python_version >= "3.10" and python_version < "4" six==1.16.0 ; python_version >= "3.10" and python_version < "4.0" -sniffio==1.3.0 ; python_version >= "3.10" and python_version < "4.0" +sniffio==1.3.1 ; python_version >= "3.10" and python_version < "4.0" sqlalchemy==2.0.27 ; python_version >= "3.10" and python_version < "4.0" starlette==0.36.3 ; python_version >= "3.10" and python_version < "4.0" twilio==8.13.0 ; python_version >= "3.10" and python_version < "4.0" -typing-extensions==4.9.0 ; python_version >= "3.10" and python_version < "4.0" +typing-extensions==4.10.0 ; python_version >= "3.10" and python_version < "4.0" tzdata==2024.1 ; python_version >= "3.10" and python_version < "4.0" urllib3==2.0.7 ; python_version >= "3.10" and python_version < "4.0" uvicorn==0.27.1 ; python_version >= "3.10" and python_version < "4.0" diff --git a/tests/conftest.py b/tests/conftest.py index f7ed388e..04807bc3 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -96,7 +96,7 @@ def gh() -> Github: :returns: Github """ return Github( - settings.GITHUB_API_KEY, + settings.GH_API_KEY, )