diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 6839c44..342d2de 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 1.3.1 +current_version = 1.4.0 commit = False tag = False diff --git a/Dockerfile b/Dockerfile index 08227a9..38b211a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -180,7 +180,7 @@ RUN apt-get update && apt-get install -y zsh \ && pip3 install git-up \ # Map the special names to docker host internal ip because 127.0.0.1 is *container* localhost on login && echo "sed 's/.*localmaeher.*//g' /etc/hosts >/etc/hosts.new && cat /etc/hosts.new >/etc/hosts" >>/root/.profile \ - && echo "echo \"\$(getent hosts host.docker.internal | awk '{ print $1 }') localmaeher.pvarki.fi mtls.localmaeher.pvarki.fi\" >>/etc/hosts" >>/root/.profile \ + && echo "echo \"\$(getent hosts host.docker.internal | awk '{ print $1 }') localmaeher.dev.pvarki.fi mtls.localmaeher.dev.pvarki.fi\" >>/etc/hosts" >>/root/.profile \ && ln -s /app/docker/container-init.sh /container-init.sh \ && curl https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh -o /usr/bin/wait-for-it.sh \ && chmod a+x /usr/bin/wait-for-it.sh \ diff --git a/docker/container-init.sh b/docker/container-init.sh index 68e0125..ae0ae97 100755 --- a/docker/container-init.sh +++ b/docker/container-init.sh @@ -2,7 +2,7 @@ set -e # Resolve our magic names to docker internal ip sed 's/.*localmaeher.*//g' /etc/hosts >/etc/hosts.new && cat /etc/hosts.new >/etc/hosts -echo "$(getent ahostsv4 host.docker.internal | awk '{ print $1 }') localmaeher.pvarki.fi mtls.localmaeher.pvarki.fi" >>/etc/hosts +echo "$(getent ahostsv4 host.docker.internal | awk '{ print $1 }') localmaeher.dev.pvarki.fi mtls.localmaeher.dev.pvarki.fi" >>/etc/hosts cat /etc/hosts # Make sure /opt/tak and the symlinks to /opt/tak/data exist just in case something still diff --git a/pyproject.toml b/pyproject.toml index 4328fb3..a0a60cd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "takrmapi" -version = "1.3.1" +version = "1.4.0" description = "RASENMAEHER integration API for TAK server" authors = ["Eero af Heurlin ", "Ari Karhunen "] homepage = "https://github.com/pvarki/python-tak-rmapi" diff --git a/src/takrmapi/__init__.py b/src/takrmapi/__init__.py index fa56f33..92ef7b8 100644 --- a/src/takrmapi/__init__.py +++ b/src/takrmapi/__init__.py @@ -1,2 +1,2 @@ """ RASENMAEHER integration API for TAK server """ -__version__ = "1.3.1" # NOTE Use `bump2version --config-file patch` to bump versions correctly +__version__ = "1.4.0" # NOTE Use `bump2version --config-file patch` to bump versions correctly diff --git a/src/takrmapi/api/__init__.py b/src/takrmapi/api/__init__.py index ca4ac09..e3e962f 100644 --- a/src/takrmapi/api/__init__.py +++ b/src/takrmapi/api/__init__.py @@ -6,6 +6,8 @@ from .clientinfo import router as clientinfo_router from .admininfo import router as admininfo_router from .healthcheck import router as healthcheck_router +from .description import router as description_router +from .instructions import router as instructions_router all_routers = APIRouter() all_routers.include_router(testing_router, prefix="/users", tags=["users"]) # REMOVE ME @@ -13,3 +15,5 @@ all_routers.include_router(clientinfo_router, prefix="/clients", tags=["clients"]) all_routers.include_router(admininfo_router, prefix="/admins", tags=["admins"]) all_routers.include_router(healthcheck_router, prefix="/healthcheck", tags=["healthcheck"]) +all_routers.include_router(description_router, prefix="/description", tags=["description"]) +all_routers.include_router(instructions_router, prefix="/instructions", tags=["instructions"]) diff --git a/src/takrmapi/api/admininfo.py b/src/takrmapi/api/admininfo.py index 0c71dfc..f7bb15a 100644 --- a/src/takrmapi/api/admininfo.py +++ b/src/takrmapi/api/admininfo.py @@ -13,7 +13,7 @@ router = APIRouter(dependencies=[Depends(MTLSHeader(auto_error=True))]) -@router.get("/fragment") +@router.get("/fragment", deprecated=True) async def admin_instruction_fragment() -> UserInstructionFragment: """Return user instructions, we use POST because the integration layer might not keep track of callsigns and certs by UUID and will probably need both for the instructions""" diff --git a/src/takrmapi/api/clientinfo.py b/src/takrmapi/api/clientinfo.py index 969fc23..f56fb72 100644 --- a/src/takrmapi/api/clientinfo.py +++ b/src/takrmapi/api/clientinfo.py @@ -13,7 +13,7 @@ router = APIRouter(dependencies=[Depends(MTLSHeader(auto_error=True))]) -@router.post("/fragment") +@router.post("/fragment", deprecated=True) # async def get_missionpkg(user_mission: UserMissionZipRequest) -> List[Dict[str, str]]: async def client_instruction_fragment(user: UserCRUDRequest) -> List[Dict[str, str]]: """Return zip package containing client config and certificates""" diff --git a/src/takrmapi/api/description.py b/src/takrmapi/api/description.py new file mode 100644 index 0000000..fb031d1 --- /dev/null +++ b/src/takrmapi/api/description.py @@ -0,0 +1,60 @@ +"""Descriptions API""" +from typing import Optional +import logging + +from fastapi import APIRouter +from pydantic import BaseModel, Extra, Field # pylint: disable=(no-name-in-module # false-positive + +LOGGER = logging.getLogger(__name__) + +router = APIRouter() # These endpoints are public + + +# FIXME: Move to libpvarki +class ProductDescription(BaseModel): # pylint: disable=too-few-public-methods + """Description of a product""" + + shortname: str = Field(description="Short name for the product, used as slug/key in dicts and urls") + title: str = Field(description="Fancy name for the product") + icon: Optional[str] = Field(description="URL for icon") + description: str = Field(description="Short-ish description of the product") + language: str = Field(description="Language of this response") + + class Config: # pylint: disable=too-few-public-methods + """Pydantic configs""" + + extra = Extra.forbid + + +@router.get( + "/{language}", + response_model=ProductDescription, +) +async def return_product_description(language: str) -> ProductDescription: + """Fetch description from each product in manifest""" + if language == "fi": + # FIXME: Localize + return ProductDescription( + shortname="tak", + title="TAK: Team Awareness Kit", + icon=None, + description="Situational awareness system", + language="en", + ) + if language == "sv": + # FIXME: Localize + return ProductDescription( + shortname="tak", + title="TAK: Team Awareness Kit", + icon=None, + description="Situational awareness system", + language="en", + ) + # Fall back to English + return ProductDescription( + shortname="tak", + title="TAK: Team Awareness Kit", + icon=None, + description="Situational awareness system", + language="en", + ) diff --git a/src/takrmapi/api/instructions.py b/src/takrmapi/api/instructions.py new file mode 100644 index 0000000..adc53be --- /dev/null +++ b/src/takrmapi/api/instructions.py @@ -0,0 +1,21 @@ +"""Instructions endpoints""" +from typing import Dict +import logging + +from fastapi import APIRouter, Depends +from libpvarki.middleware import MTLSHeader +from libpvarki.schemas.product import UserCRUDRequest + +LOGGER = logging.getLogger(__name__) + +router = APIRouter(dependencies=[Depends(MTLSHeader(auto_error=True))]) + + +@router.post("/{language}") +async def user_intructions(user: UserCRUDRequest) -> Dict[str, str]: + """return user instructions""" + return { + "callsign": user.callsign, + "instructions": "FIXME: Return something sane", + "language": "en", + } diff --git a/src/takrmapi/config.py b/src/takrmapi/config.py index 2ba3e0d..04cbc94 100644 --- a/src/takrmapi/config.py +++ b/src/takrmapi/config.py @@ -16,7 +16,7 @@ def load_manifest(filepth: Path = Path("/pvarki/kraftwerk-init.json")) -> Dict[s if not filepth.exists(): # return a dummy manifest LOGGER.warning("Returning dummy manifest") - rm_uri = "https://localmaeher.pvarki.fi" + rm_uri = "https://localmaeher.dev.pvarki.fi" mtls_uri = rm_uri.replace("https://", "https://mtls.") return { "deployment": "localmaeher", @@ -25,7 +25,7 @@ def load_manifest(filepth: Path = Path("/pvarki/kraftwerk-init.json")) -> Dict[s "mtls": {"base_uri": mtls_uri}, "certcn": "rasenmaeher", }, - "product": {"dns": "tak.localmaeher.pvarki.fi"}, + "product": {"dns": "tak.localmaeher.dev.pvarki.fi"}, } return cast(Dict[str, Any], json.loads(filepth.read_text(encoding="utf-8"))) diff --git a/src/takrmapi/tak_helpers.py b/src/takrmapi/tak_helpers.py index 2d7d7ec..83a23af 100644 --- a/src/takrmapi/tak_helpers.py +++ b/src/takrmapi/tak_helpers.py @@ -42,7 +42,7 @@ def callsign(self) -> str: @property def certcn(self) -> str: """return CN for the special cert""" - return f"{self.user.callsign}_tak" + return self.user.callsign @property def rm_certpem(self) -> str: diff --git a/tests/test_takrmapi.py b/tests/test_takrmapi.py index 6f2d6fa..41bfdda 100644 --- a/tests/test_takrmapi.py +++ b/tests/test_takrmapi.py @@ -4,4 +4,4 @@ def test_version() -> None: """Make sure version matches expected""" - assert __version__ == "1.3.1" + assert __version__ == "1.4.0"