From f8a52ab8dad0e89879d1dc7f214afe9aa3dc873b Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Fri, 31 Jan 2025 10:20:19 +0200 Subject: [PATCH 1/2] Fix some typos (with crate-ci/typos + manual assistance) --- README.rst | 2 +- src/rasenmaeher_api/db/people.py | 2 +- src/rasenmaeher_api/kchelpers.py | 4 +-- ...dcutapihelpers.py => productapihelpers.py} | 34 +++++++++---------- src/rasenmaeher_api/rmsettings.py | 2 +- src/rasenmaeher_api/web/api/descriptions.py | 2 +- .../web/api/firstuser/schema.py | 4 +-- .../web/api/firstuser/views.py | 4 +-- .../web/api/healthcheck/views.py | 2 +- .../web/api/instructions/schema.py | 4 +-- .../web/api/instructions/views.py | 18 +++++----- .../web/api/product/__init__.py | 2 +- src/rasenmaeher_api/web/api/product/views.py | 2 +- tests/conftest.py | 4 +-- tests/test_descriptions.py | 2 +- tests/test_enrollment.py | 2 +- 16 files changed, 45 insertions(+), 45 deletions(-) rename src/rasenmaeher_api/{prodcutapihelpers.py => productapihelpers.py} (82%) diff --git a/README.rst b/README.rst index be195e5c..b7a2b716 100644 --- a/README.rst +++ b/README.rst @@ -172,7 +172,7 @@ Example usage ```curl -L -H "Content-Type: application/json" -d '{ "request": {"hosts":["harjoitus1.pvarki.fi"], "names":[{"C":"FI", "ST":"Jyvaskyla", "L":"KeskiSuomi", "O":"harjoitus1.pvarki.fi"}], "CN": "harjoitus1.pvarki.fi"}, "bundle":true, "profile":"client"}' 127.0.0.1:8000/takreg | jq``` -The cfssl used behind API listents this kind of stuff https://github.com/cloudflare/cfssl/blob/master/doc/api/endpoint_newcert.txt +The cfssl used behind API listens this kind of stuff https://github.com/cloudflare/cfssl/blob/master/doc/api/endpoint_newcert.txt # Enrollment - Enroll a new work_id diff --git a/src/rasenmaeher_api/db/people.py b/src/rasenmaeher_api/db/people.py index d1ef8882..a70864a7 100644 --- a/src/rasenmaeher_api/db/people.py +++ b/src/rasenmaeher_api/db/people.py @@ -23,7 +23,7 @@ from ..web.api.middleware.datatypes import MTLSorJWTPayload from .errors import NotFound, Deleted, BackendError, CallsignReserved from ..cfssl.private import sign_csr, revoke_pem, validate_reason, ReasonTypes, refresh_ocsp -from ..prodcutapihelpers import post_to_all_products +from ..productapihelpers import post_to_all_products from ..rmsettings import RMSettings from ..kchelpers import KCClient, KCUserData from .engine import EngineWrapper diff --git a/src/rasenmaeher_api/kchelpers.py b/src/rasenmaeher_api/kchelpers.py index fdfc9a42..496d2f65 100644 --- a/src/rasenmaeher_api/kchelpers.py +++ b/src/rasenmaeher_api/kchelpers.py @@ -75,14 +75,14 @@ async def _check_admin_role(self) -> None: if self._kc_admin_role: return ret = await self.kcadmin.a_get_realm_roles(search_text="admin") - # If multipe roles match the search choose exact match + # If multiple roles match the search choose exact match flt = [rolerep for rolerep in ret if rolerep["name"] == "admin"] if not flt: raise ValueError("KC has no configured 'admin' role") self._kc_admin_role = flt[0] async def check_user_roles(self, user: KCUserData) -> bool: - """Chekc users roles in KC and update as needed, returns true if changes were made""" + """Check users roles in KC and update as needed, returns true if changes were made""" await self._check_admin_role() kc_roles = {role["name"]: role for role in await self.kcadmin.a_get_realm_roles_of_user(user.kc_id)} LOGGER.debug("Found KC roles: {} (user: {})".format(list(kc_roles.keys()), user.roles)) diff --git a/src/rasenmaeher_api/prodcutapihelpers.py b/src/rasenmaeher_api/productapihelpers.py similarity index 82% rename from src/rasenmaeher_api/prodcutapihelpers.py rename to src/rasenmaeher_api/productapihelpers.py index 74c4af2d..a4739d85 100644 --- a/src/rasenmaeher_api/prodcutapihelpers.py +++ b/src/rasenmaeher_api/productapihelpers.py @@ -23,52 +23,52 @@ def check_kraftwerk_manifest() -> bool: async def post_to_all_products( - url_suffix: str, data: Mapping[str, Any], respose_schema: Type[pydantic.BaseModel], collect_responses: bool = True + url_suffix: str, data: Mapping[str, Any], response_schema: Type[pydantic.BaseModel], collect_responses: bool = True ) -> Optional[Dict[str, Optional[pydantic.BaseModel]]]: """Call given POST endpoint on all products in the manifest""" - return await _method_to_all_products("post", url_suffix, data, respose_schema, collect_responses) + return await _method_to_all_products("post", url_suffix, data, response_schema, collect_responses) async def put_to_all_products( - url_suffix: str, data: Mapping[str, Any], respose_schema: Type[pydantic.BaseModel], collect_responses: bool = True + url_suffix: str, data: Mapping[str, Any], response_schema: Type[pydantic.BaseModel], collect_responses: bool = True ) -> Optional[Dict[str, Optional[pydantic.BaseModel]]]: """Call given PUT endpoint on all products in the manifest""" - return await _method_to_all_products("put", url_suffix, data, respose_schema, collect_responses) + return await _method_to_all_products("put", url_suffix, data, response_schema, collect_responses) async def get_from_all_products( - url_suffix: str, respose_schema: Type[pydantic.BaseModel], collect_responses: bool = True + url_suffix: str, response_schema: Type[pydantic.BaseModel], collect_responses: bool = True ) -> Optional[Dict[str, Optional[pydantic.BaseModel]]]: """Call given GET endpoint on all products in the manifest""" - return await _method_to_all_products("get", url_suffix, None, respose_schema, collect_responses) + return await _method_to_all_products("get", url_suffix, None, response_schema, collect_responses) async def get_from_product( - name: str, url_suffix: str, respose_schema: Type[pydantic.BaseModel] + name: str, url_suffix: str, response_schema: Type[pydantic.BaseModel] ) -> Optional[pydantic.BaseModel]: """Call given GET endpoint on named product in the manifest""" - return await _method_to_product(name, "get", url_suffix, None, respose_schema) + return await _method_to_product(name, "get", url_suffix, None, response_schema) async def post_to_product( - name: str, url_suffix: str, data: Mapping[str, Any], respose_schema: Type[pydantic.BaseModel] + name: str, url_suffix: str, data: Mapping[str, Any], response_schema: Type[pydantic.BaseModel] ) -> Optional[pydantic.BaseModel]: """Call given POST endpoint on named product in the manifest""" - return await _method_to_product(name, "post", url_suffix, data, respose_schema) + return await _method_to_product(name, "post", url_suffix, data, response_schema) async def put_to_product( - name: str, url_suffix: str, data: Mapping[str, Any], respose_schema: Type[pydantic.BaseModel] + name: str, url_suffix: str, data: Mapping[str, Any], response_schema: Type[pydantic.BaseModel] ) -> Optional[pydantic.BaseModel]: """Call given PUT endpoint on named product in the manifest""" - return await _method_to_product(name, "put", url_suffix, data, respose_schema) + return await _method_to_product(name, "put", url_suffix, data, response_schema) async def _method_to_all_products( methodname: str, url_suffix: str, data: Optional[Mapping[str, Any]], - respose_schema: Type[pydantic.BaseModel], + response_schema: Type[pydantic.BaseModel], collect_responses: bool = True, ) -> Optional[Dict[str, Optional[pydantic.BaseModel]]]: """Call given POST endpoint on call products in the manifest""" @@ -83,9 +83,9 @@ async def _method_to_all_products( async def handle_one(name: str) -> Tuple[str, Optional[pydantic.BaseModel]]: """Do one call""" - nonlocal url_suffix, methodname, respose_schema, data + nonlocal url_suffix, methodname, response_schema, data try: - return name, await _method_to_product(name, methodname, url_suffix, data, respose_schema) + return name, await _method_to_product(name, methodname, url_suffix, data, response_schema) except Exception as exc: # pylint: disable=W0718 LOGGER.exception(exc) return name, None @@ -107,7 +107,7 @@ async def _method_to_product( methodname: str, url_suffix: str, data: Optional[Mapping[str, Any]], - respose_schema: Type[pydantic.BaseModel], + response_schema: Type[pydantic.BaseModel], ) -> Optional[Optional[pydantic.BaseModel]]: """Do a call to named product""" @@ -130,7 +130,7 @@ async def _method_to_product( resp.raise_for_status() payload = await resp.json() LOGGER.debug("{}({}) payload={}".format(methodname, url, payload)) - retval = respose_schema.parse_obj(payload) + retval = response_schema.parse_obj(payload) # Log a common error case here for DRY if isinstance(retval, OperationResultResponse): if not retval.success: diff --git a/src/rasenmaeher_api/rmsettings.py b/src/rasenmaeher_api/rmsettings.py index 27897405..365f6439 100644 --- a/src/rasenmaeher_api/rmsettings.py +++ b/src/rasenmaeher_api/rmsettings.py @@ -71,7 +71,7 @@ class Config: # pylint: disable=too-few-public-methods test_api_client_cert_header_value: str = "CN=fake.localmaeher.dev.pvarki.fi,O=N/A" api_healthcheck_proto: str = "http://" api_healthcheck_url: str = "/api/v1/healthcheck" - api_healthcheck_headers: str = '{"propably":"not_needed"}' + api_healthcheck_headers: str = '{"probably":"not_needed"}' # Sentry's configuration. sentry_dsn: Optional[str] = None diff --git a/src/rasenmaeher_api/web/api/descriptions.py b/src/rasenmaeher_api/web/api/descriptions.py index 97832fce..2847035d 100644 --- a/src/rasenmaeher_api/web/api/descriptions.py +++ b/src/rasenmaeher_api/web/api/descriptions.py @@ -6,7 +6,7 @@ from pydantic import BaseModel, Extra, Field from pydantic_collections import BaseCollectionModel -from ...prodcutapihelpers import get_from_all_products, get_from_product +from ...productapihelpers import get_from_all_products, get_from_product LOGGER = logging.getLogger(__name__) diff --git a/src/rasenmaeher_api/web/api/firstuser/schema.py b/src/rasenmaeher_api/web/api/firstuser/schema.py index 7bbcecce..7968c134 100644 --- a/src/rasenmaeher_api/web/api/firstuser/schema.py +++ b/src/rasenmaeher_api/web/api/firstuser/schema.py @@ -16,7 +16,7 @@ class Config: # pylint: disable=too-few-public-methods { "name": "normal", "summary": "Description text", - "description": "This containts **description** of values.", + "description": "This contains **description** of values.", "value": {"temp_admin_code": "[str] - temporary init admin users string"}, }, { @@ -60,7 +60,7 @@ class Config: # pylint: disable=too-few-public-methods { "name": "normal", "summary": "Description text", - "description": "This containts **description** of values.", + "description": "This contains **description** of values.", "value": { "callsign": "[str] - id/name for new user that is elevated to admin", }, diff --git a/src/rasenmaeher_api/web/api/firstuser/views.py b/src/rasenmaeher_api/web/api/firstuser/views.py index bf8bfde3..54eea638 100644 --- a/src/rasenmaeher_api/web/api/firstuser/views.py +++ b/src/rasenmaeher_api/web/api/firstuser/views.py @@ -43,7 +43,7 @@ async def get_check_code( LOGGER.error("{} : {}".format(request.url, _reason)) raise HTTPException(status_code=500, detail=_reason) - # Code alreay used err. + # Code already used err. if res.used_on is not None: _reason = "Code already used" LOGGER.error("{} : {}".format(request.url, _reason)) @@ -84,7 +84,7 @@ async def post_admin_add( anon_admin_user = await Person.by_callsign(callsign="anon_admin") new_admin = await enrollment.approve(approver=anon_admin_user) - # FIXME Should tbe TaskMaster feature + # FIXME Should the TaskMaster feature async def tms_wait() -> None: """Wait for background tasks to avoid race conditions""" tma = TaskMaster.singleton() diff --git a/src/rasenmaeher_api/web/api/healthcheck/views.py b/src/rasenmaeher_api/web/api/healthcheck/views.py index 3009d185..0e36b677 100644 --- a/src/rasenmaeher_api/web/api/healthcheck/views.py +++ b/src/rasenmaeher_api/web/api/healthcheck/views.py @@ -10,7 +10,7 @@ from .schema import BasicHealthCheckResponse, AllProductsHealthCheckResponse from ....db import Person from ....rmsettings import switchme_to_singleton_call -from ....prodcutapihelpers import check_kraftwerk_manifest, get_from_all_products +from ....productapihelpers import check_kraftwerk_manifest, get_from_all_products router = APIRouter() LOGGER = logging.getLogger(__name__) diff --git a/src/rasenmaeher_api/web/api/instructions/schema.py b/src/rasenmaeher_api/web/api/instructions/schema.py index 49b7b5f7..31ed3a86 100644 --- a/src/rasenmaeher_api/web/api/instructions/schema.py +++ b/src/rasenmaeher_api/web/api/instructions/schema.py @@ -8,7 +8,7 @@ # pylint: disable=too-few-public-methods -class AllProdcutsInstructionFragments(BaseModel): +class AllProductsInstructionFragments(BaseModel): """DEPRECATED! Fragments for all products""" fragments: Dict[str, Optional[UserInstructionFragment]] = Field( @@ -56,7 +56,7 @@ class Config: # pylint: disable=too-few-public-methods extra = Extra.forbid -class AllProdcutsInstructionFiles(BaseModel): +class AllProductsInstructionFiles(BaseModel): """DEPRECATED! user files for all products""" files: Dict[str, Optional[ProductFileList]] = Field( diff --git a/src/rasenmaeher_api/web/api/instructions/views.py b/src/rasenmaeher_api/web/api/instructions/views.py index c92323f2..d941f942 100644 --- a/src/rasenmaeher_api/web/api/instructions/views.py +++ b/src/rasenmaeher_api/web/api/instructions/views.py @@ -7,13 +7,13 @@ from .schema import ( - AllProdcutsInstructionFragments, + AllProductsInstructionFragments, ProductFileList, - AllProdcutsInstructionFiles, + AllProductsInstructionFiles, InstructionData, ) from ..middleware.user import ValidUser -from ....prodcutapihelpers import get_from_all_products, post_to_all_products, post_to_product +from ....productapihelpers import get_from_all_products, post_to_all_products, post_to_product from ....db import Person @@ -23,27 +23,27 @@ @router.get( "/admin", - response_model=AllProdcutsInstructionFragments, + response_model=AllProductsInstructionFragments, dependencies=[Depends(ValidUser(auto_error=True))], deprecated=True, ) -async def admin_instruction_fragment() -> AllProdcutsInstructionFragments: +async def admin_instruction_fragment() -> AllProductsInstructionFragments: """Return admin instructions""" responses = await get_from_all_products("api/v1/admins/fragment", UserInstructionFragment) if responses is None: raise ValueError("Everything is broken") - return AllProdcutsInstructionFragments( + return AllProductsInstructionFragments( fragments={key: cast(UserInstructionFragment, val) for key, val in responses.items()} ) @router.get( "/user", - response_model=AllProdcutsInstructionFiles, + response_model=AllProductsInstructionFiles, dependencies=[Depends(ValidUser(auto_error=True))], deprecated=True, ) -async def user_instruction_fragment(request: Request) -> AllProdcutsInstructionFiles: +async def user_instruction_fragment(request: Request) -> AllProductsInstructionFiles: """Return end-user files""" person = cast(Person, request.state.person) user = UserCRUDRequest( @@ -53,7 +53,7 @@ async def user_instruction_fragment(request: Request) -> AllProdcutsInstructionF responses = await post_to_all_products("api/v1/clients/fragment", user.dict(), ProductFileList) if responses is None: raise ValueError("Everything is broken") - return AllProdcutsInstructionFiles(files={key: cast(ProductFileList, val) for key, val in responses.items()}) + return AllProductsInstructionFiles(files={key: cast(ProductFileList, val) for key, val in responses.items()}) @router.get( diff --git a/src/rasenmaeher_api/web/api/product/__init__.py b/src/rasenmaeher_api/web/api/product/__init__.py index 87e9f8ed..574fe05b 100644 --- a/src/rasenmaeher_api/web/api/product/__init__.py +++ b/src/rasenmaeher_api/web/api/product/__init__.py @@ -1,4 +1,4 @@ -"""Product registeration API.""" +"""Product registration API.""" from rasenmaeher_api.web.api.product.views import router __all__ = ["router"] diff --git a/src/rasenmaeher_api/web/api/product/views.py b/src/rasenmaeher_api/web/api/product/views.py index 6c17725b..6744ee34 100644 --- a/src/rasenmaeher_api/web/api/product/views.py +++ b/src/rasenmaeher_api/web/api/product/views.py @@ -1,4 +1,4 @@ -"""Product registeration API views.""" +"""Product registration API views.""" import logging from fastapi import APIRouter, Depends, HTTPException, Request diff --git a/tests/conftest.py b/tests/conftest.py index 0eb31fad..0aa54d83 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -23,7 +23,7 @@ from rasenmaeher_api.web.application import get_app from rasenmaeher_api.rmsettings import switchme_to_singleton_call -from rasenmaeher_api.prodcutapihelpers import check_kraftwerk_manifest +from rasenmaeher_api.productapihelpers import check_kraftwerk_manifest from rasenmaeher_api.testhelpers import create_test_users from rasenmaeher_api.mtlsinit import check_settings_clientpaths, CERT_NAME_PREFIX from rasenmaeher_api.db.dbinit import init_db @@ -35,7 +35,7 @@ JWT_PATH = DATA_PATH / Path("jwt") -# FIXME Should tbe TaskMaster feature +# FIXME Should the TaskMaster feature async def tms_wait() -> None: """Wait for background tasks to avoid race conditions""" tma = TaskMaster.singleton() diff --git a/tests/test_descriptions.py b/tests/test_descriptions.py index 8070fcd5..e9935393 100644 --- a/tests/test_descriptions.py +++ b/tests/test_descriptions.py @@ -33,7 +33,7 @@ async def test_product_description(unauth_client: TestClient, lang: str) -> None @pytest.mark.parametrize("lang", ["fi", "en"]) @pytest.mark.asyncio(loop_scope="session") -async def test_product_instructons(user_mtls_client: TestClient, lang: str) -> None: +async def test_product_instructions(user_mtls_client: TestClient, lang: str) -> None: """Make sure we get product instructions""" resp = await user_mtls_client.get(f"/api/v1/instructions/fake/{lang}") assert resp diff --git a/tests/test_enrollment.py b/tests/test_enrollment.py index ed41e470..6629fc96 100644 --- a/tests/test_enrollment.py +++ b/tests/test_enrollment.py @@ -429,7 +429,7 @@ async def test_create_as_usr(tilauspalvelu_jwt_user_client: TestClient) -> None: # INVITE CODE DEACTIVATE @pytest.mark.asyncio(loop_scope="session") @pytest.mark.parametrize("tilauspalvelu_jwt_admin_client", [{"test": "value", "xclientcert": False}], indirect=True) -async def test_invitecode_dectivate(tilauspalvelu_jwt_admin_client: TestClient) -> None: +async def test_invitecode_deactivate(tilauspalvelu_jwt_admin_client: TestClient) -> None: """ Test - deactivate invite code """ From 9d3f422f9e5676e4fd60fa9d8faa262b5906214a Mon Sep 17 00:00:00 2001 From: Eero af Heurlin Date: Fri, 7 Mar 2025 12:29:40 +0200 Subject: [PATCH 2/2] bump version --- .bumpversion.cfg | 2 +- pyproject.toml | 2 +- src/rasenmaeher_api/__init__.py | 2 +- tests/test_rasenmaeher_api.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 5fe48c6b..075f90ee 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 1.6.2 +current_version = 1.6.3 commit = False tag = False diff --git a/pyproject.toml b/pyproject.toml index af9bcabd..45819217 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "rasenmaeher_api" -version = "1.6.2" +version = "1.6.3" description = "python-rasenmaeher-api" authors = [ "Aciid <703382+Aciid@users.noreply.github.com>", diff --git a/src/rasenmaeher_api/__init__.py b/src/rasenmaeher_api/__init__.py index c958ad89..ef8c5bb2 100644 --- a/src/rasenmaeher_api/__init__.py +++ b/src/rasenmaeher_api/__init__.py @@ -1,2 +1,2 @@ """ python-rasenmaeher-api """ -__version__ = "1.6.2" # NOTE Use `bump2version --config-file patch` to bump versions correctly +__version__ = "1.6.3" # NOTE Use `bump2version --config-file patch` to bump versions correctly diff --git a/tests/test_rasenmaeher_api.py b/tests/test_rasenmaeher_api.py index 4f001c90..7cc4f12e 100644 --- a/tests/test_rasenmaeher_api.py +++ b/tests/test_rasenmaeher_api.py @@ -15,7 +15,7 @@ def test_version() -> None: """Make sure version matches expected""" - assert __version__ == "1.6.2" + assert __version__ == "1.6.3" @pytest.mark.asyncio(loop_scope="session")