Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions app/api/main/krb5_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,14 @@ async def setup_kdc(
)
async def ktadd(
kerberos_adapter: FromDishka[KerberosFastAPIAdapter],
request: KtaddRequest,
names: Annotated[LIMITED_LIST, Body()],
) -> StreamingResponse:
"""Create keytab from kadmin server.

:param Annotated[LDAPSession, Depends ldap_session: ldap
:return bytes: file
"""
request = KtaddRequest(names=names)
return await kerberos_adapter.ktadd(request)


Expand All @@ -183,12 +184,13 @@ async def get_krb_status(


@krb5_router.post(
"/principal",
"/principal/add",
dependencies=[Depends(verify_auth), Depends(require_master_db)],
error_map=error_map,
)
async def add_principal(
request: PrincipalAddRequest,
primary: Annotated[LIMITED_STR, Body()],
instance: Annotated[LIMITED_STR, Body()],
kerberos_adapter: FromDishka[KerberosFastAPIAdapter],
) -> None:
"""Create principal in kerberos with given name.
Expand All @@ -198,6 +200,9 @@ async def add_principal(
:param Annotated[LDAPSession, Depends ldap_session: ldap
:raises HTTPException: on failed kamin request.
"""
request = PrincipalAddRequest(
principal_name=f"{primary}/{instance}",
)
await kerberos_adapter.add_principal(request)


Expand Down
10 changes: 5 additions & 5 deletions tests/test_api/test_main/test_kadmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ async def test_ktadd(
names = ["test1", "test2"]
response = await http_client.post(
"/kerberos/ktadd",
json={"names": names, "is_rand_key": False},
json=names,
)

kadmin.ktadd.assert_called() # type: ignore
Expand Down Expand Up @@ -245,7 +245,7 @@ async def test_ktadd_400(
names = ["test1", "test2"]
response = await http_client.post(
"/kerberos/ktadd",
json={"names": names, "is_rand_key": False},
json=names,
)

assert response.status_code == status.HTTP_400_BAD_REQUEST
Expand Down Expand Up @@ -395,10 +395,10 @@ async def test_add_princ(
:param LDAPSession ldap_session: ldap
"""
response = await http_client.post(
"/kerberos/principal",
"/kerberos/principal/add",
json={
"principal_name": "host/12345",
"password": None,
"primary": "host",
"instance": "12345",
},
)
kadmin_args = kadmin.add_principal.call_args.args # type: ignore
Expand Down
Loading