Skip to content

Commit

Permalink
Merge pull request #67 from pvarki/tak_ldap
Browse files Browse the repository at this point in the history
TAK LDAP related things
  • Loading branch information
rambo authored Jan 24, 2025
2 parents e2afe33 + 8188d8d commit 15eb584
Show file tree
Hide file tree
Showing 13 changed files with 96 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 1.3.1
current_version = 1.4.0
commit = False
tag = False

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
2 changes: 1 addition & 1 deletion docker/container-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <rambo@iki.fi>", "Ari Karhunen <FIXME@example.com>"]
homepage = "https://github.com/pvarki/python-tak-rmapi"
Expand Down
2 changes: 1 addition & 1 deletion src/takrmapi/__init__.py
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions src/takrmapi/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@
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
all_routers.include_router(usercrud_router, prefix="/users", tags=["users"])
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"])
2 changes: 1 addition & 1 deletion src/takrmapi/api/admininfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
2 changes: 1 addition & 1 deletion src/takrmapi/api/clientinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
60 changes: 60 additions & 0 deletions src/takrmapi/api/description.py
Original file line number Diff line number Diff line change
@@ -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",
)
21 changes: 21 additions & 0 deletions src/takrmapi/api/instructions.py
Original file line number Diff line number Diff line change
@@ -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",
}
4 changes: 2 additions & 2 deletions src/takrmapi/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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")))

Expand Down
2 changes: 1 addition & 1 deletion src/takrmapi/tak_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_takrmapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

def test_version() -> None:
"""Make sure version matches expected"""
assert __version__ == "1.3.1"
assert __version__ == "1.4.0"

0 comments on commit 15eb584

Please sign in to comment.