add docs
This commit is contained in:
@@ -21,11 +21,12 @@ from layercake.dynamodb import (
|
||||
)
|
||||
from pydantic import UUID4, BaseModel, StringConstraints
|
||||
|
||||
import cognito
|
||||
import elastic
|
||||
from boto3clients import dynamodb_client
|
||||
from boto3clients import dynamodb_client, idp_client
|
||||
from middlewares import AuditLogMiddleware
|
||||
from models import User
|
||||
from settings import ELASTIC_CONN, USER_TABLE
|
||||
from settings import ELASTIC_CONN, USER_POOOL_ID, USER_TABLE
|
||||
|
||||
|
||||
class BadRequestError(MissingError, PowertoolsBadRequestError): ...
|
||||
@@ -37,12 +38,7 @@ user_collect = DynamoDBCollection(user_layer, exception_cls=BadRequestError)
|
||||
elastic_client = Elasticsearch(**ELASTIC_CONN)
|
||||
|
||||
|
||||
@router.get(
|
||||
'/',
|
||||
compress=True,
|
||||
tags=['User'],
|
||||
summary='Get users',
|
||||
)
|
||||
@router.get('/', compress=True, tags=['User'], summary='Get users')
|
||||
def get_users():
|
||||
event = router.current_event
|
||||
query = event.get_query_string_value('query', '{}')
|
||||
@@ -67,29 +63,28 @@ def post_user(payload: User):
|
||||
return Response(status_code=HTTPStatus.CREATED)
|
||||
|
||||
|
||||
class NewPasswordPayload(BaseModel):
|
||||
class NewPassword(BaseModel):
|
||||
cognito_sub: UUID4
|
||||
new_password: Annotated[str, StringConstraints(min_length=6)]
|
||||
|
||||
|
||||
@router.patch('/<id>', compress=True, tags=['User'])
|
||||
def patch_reset(id: str, payload: NewPasswordPayload):
|
||||
def patch_newpassword(id: str, payload: NewPassword):
|
||||
return Response(status_code=HTTPStatus.OK)
|
||||
|
||||
|
||||
@router.get(
|
||||
'/<id>',
|
||||
compress=True,
|
||||
tags=['User'],
|
||||
summary='Get user',
|
||||
)
|
||||
@router.get('/<id>', compress=True, tags=['User'], summary='Get user')
|
||||
def get_user(id: str):
|
||||
return user_collect.get_item(KeyPair(id, '0'))
|
||||
|
||||
|
||||
@router.get('/<id>/idp', compress=True, include_in_schema=False)
|
||||
def get_idp(id: str):
|
||||
return []
|
||||
return cognito.admin_get_user(
|
||||
sub=id,
|
||||
user_pool_id=USER_POOOL_ID,
|
||||
idp_client=idp_client,
|
||||
)
|
||||
|
||||
|
||||
@router.get(
|
||||
@@ -99,7 +94,7 @@ def get_idp(id: str):
|
||||
summary='Get user emails',
|
||||
)
|
||||
def get_emails(id: str):
|
||||
return user_collect.get_items(
|
||||
return user_collect.query(
|
||||
KeyPair(id, PrefixKey('emails')),
|
||||
start_key=router.current_event.get_query_string_value('start_key', None),
|
||||
)
|
||||
@@ -112,7 +107,7 @@ def get_emails(id: str):
|
||||
summary='Get user logs',
|
||||
)
|
||||
def get_logs(id: str):
|
||||
return user_collect.get_items(
|
||||
return user_collect.query(
|
||||
# Post-migration: uncomment to enable PartitionKey with a composite key (id with `logs` prefix).
|
||||
# PartitionKey(ComposeKey(id, prefix='logs')),
|
||||
PartitionKey(ComposeKey(id, prefix='log', delimiter=':')),
|
||||
@@ -127,7 +122,7 @@ def get_logs(id: str):
|
||||
summary='Get user orgs',
|
||||
)
|
||||
def get_orgs(id: str):
|
||||
return user_collect.get_items(
|
||||
return user_collect.query(
|
||||
KeyPair(id, PrefixKey('orgs')),
|
||||
start_key=router.current_event.get_query_string_value('start_key', None),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user