From dcaa99c2fa684b5b05092bfe130fdb0adc6231c5 Mon Sep 17 00:00:00 2001 From: Vignesh Rao Date: Sun, 27 Oct 2024 13:39:48 -0500 Subject: [PATCH] Fix payload for `put-file` endpoint --- doc_gen/index.rst | 5 ----- docs/_sources/index.rst.txt | 5 ----- docs/genindex.html | 17 ----------------- docs/index.html | 28 ++-------------------------- docs/objects.inv | Bin 2023 -> 2001 bytes docs/searchindex.js | 2 +- pyninja/modules/payloads.py | 13 ------------- pyninja/routes/fullaccess.py | 24 +++++++++++++----------- 8 files changed, 16 insertions(+), 78 deletions(-) diff --git a/doc_gen/index.rst b/doc_gen/index.rst index b68bc21..c8f3d05 100644 --- a/doc_gen/index.rst +++ b/doc_gen/index.rst @@ -150,11 +150,6 @@ Payloads .. autoclass:: pyninja.modules.payloads.GetFile(BaseModel) :exclude-members: _abc_impl, model_config, model_fields, model_computed_fields -==== - -.. autoclass:: pyninja.modules.payloads.PutFile(BaseModel) - :exclude-members: _abc_impl, model_config, model_fields, model_computed_fields - RateLimit --------- .. automodule:: pyninja.modules.rate_limit diff --git a/docs/_sources/index.rst.txt b/docs/_sources/index.rst.txt index b68bc21..c8f3d05 100644 --- a/docs/_sources/index.rst.txt +++ b/docs/_sources/index.rst.txt @@ -150,11 +150,6 @@ Payloads .. autoclass:: pyninja.modules.payloads.GetFile(BaseModel) :exclude-members: _abc_impl, model_config, model_fields, model_computed_fields -==== - -.. autoclass:: pyninja.modules.payloads.PutFile(BaseModel) - :exclude-members: _abc_impl, model_config, model_fields, model_computed_fields - RateLimit --------- .. automodule:: pyninja.modules.rate_limit diff --git a/docs/genindex.html b/docs/genindex.html index 24e9412..80d63e3 100644 --- a/docs/genindex.html +++ b/docs/genindex.html @@ -56,7 +56,6 @@

Index

| L | M | N - | O | P | R | S @@ -186,11 +185,7 @@

D

  • description (pyninja.modules.models.ServiceStatus attribute)
  • directory (pyninja.modules.payloads.ListFiles attribute) - -
  • disk_lib (pyninja.modules.models.EnvConfig attribute)
  • DiskLib (class in pyninja.modules.models) @@ -228,8 +223,6 @@

    F

    -

    O

    - - -
    -

    P

      @@ -577,8 +562,6 @@

      P

    • put_file() (in module pyninja.routes.fullaccess)
    • put_record() (in module pyninja.executors.database) -
    • -
    • PutFile (class in pyninja.modules.payloads)
    • pyninja.executors.auth diff --git a/docs/index.html b/docs/index.html index 0a7c55d..1d2778f 100644 --- a/docs/index.html +++ b/docs/index.html @@ -337,12 +337,13 @@

      PyNinja - Executors
      -async pyninja.routes.fullaccess.put_file(request: Request, payload: PutFile, apikey: HTTPAuthorizationCredentials = Depends(HTTPBearer), token: Optional[str] = Header(None))
      +async pyninja.routes.fullaccess.put_file(request: Request, file: UploadFile, directory: Path, overwrite: bool = False, apikey: HTTPAuthorizationCredentials = Depends(HTTPBearer), token: Optional[str] = Header(None))

      Upload a file to th.

      Args:

      • request: Reference to the FastAPI request object.

      • +
      • file: Upload object for the file param.

      • payload: Payload received as request body.

      • apikey: API Key to authenticate the request.

      • token: API secret to authenticate the request.

      • @@ -2051,31 +2052,6 @@

        Payloads -
        -
        -class pyninja.modules.payloads.PutFile(BaseModel)
        -

        Payload for put-file endpoint.

        -
        >>> PutFile
        -
        -
        -
        -
        -file: UploadFile
        -
        - -
        -
        -directory: Path
        -
        - -
        -
        -overwrite: bool
        -
        - -
        -

        RateLimit

        diff --git a/docs/objects.inv b/docs/objects.inv index 8ca682b0815d465016cf1e4d154d078e4e175ebf..83136d0101eabd378ad35ac927e600f54d24cc59 100644 GIT binary patch delta 614 zcmV-s0-62i577^>cLjgP$$U5+#HqFYNzKlV^R)GY#Zyvts(q%rd>E`O{+`6AG%GL2 z8!d7jfOD^^9=tKLo2pLDT?$z&x_$F+-oczP+#U}u31G+sDYTq)v_~&|PeSzY+A@YH zuNy$BDy8%UH$o*vd2xF4BwW$wqOlBII_Tn6p?yPl*iPUw@A!YGDHIjA2Ls7zrM1th z#ZcvSP1U=aYnW0ZYzL(bBo6JY=tyRPQ@bPAcCRWqr#z$5i?R@tG7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- file: UploadFile - directory: DirectoryPath - overwrite: bool = False diff --git a/pyninja/routes/fullaccess.py b/pyninja/routes/fullaccess.py index 5329a06..10eed76 100644 --- a/pyninja/routes/fullaccess.py +++ b/pyninja/routes/fullaccess.py @@ -6,9 +6,10 @@ from http import HTTPStatus from typing import Optional -from fastapi import APIRouter, Depends, Header, Request +from fastapi import APIRouter, Depends, Header, Request, UploadFile from fastapi.responses import FileResponse from fastapi.security import HTTPAuthorizationCredentials, HTTPBasic, HTTPBearer +from pydantic import DirectoryPath from pyninja.executors import auth, squire from pyninja.modules import exceptions, payloads, tree @@ -139,7 +140,9 @@ async def get_file( async def put_file( request: Request, - payload: payloads.PutFile, + file: UploadFile, + directory: DirectoryPath, + overwrite: bool = False, apikey: HTTPAuthorizationCredentials = Depends(BEARER_AUTH), token: Optional[str] = Header(None), ): @@ -148,6 +151,7 @@ async def put_file( **Args:** - request: Reference to the FastAPI request object. + - file: Upload object for the file param. - payload: Payload received as request body. - apikey: API Key to authenticate the request. - token: API secret to authenticate the request. @@ -155,21 +159,19 @@ async def put_file( await auth.level_2(request, apikey, token) LOGGER.info( "Requested file: '%s' for upload at %s", - payload.file.filename, - payload.directory, + file.filename, + directory, ) - content = await payload.file.read() - if not payload.overwrite and os.path.isfile( - os.path.join(payload.directory, payload.file.filename) - ): + content = await file.read() + if not overwrite and os.path.isfile(os.path.join(directory, file.filename)): raise exceptions.APIResponse( status_code=HTTPStatus.BAD_REQUEST.real, - detail=f"File {payload.file.filename!r} exists at {str(payload.directory)!r} already, " + detail=f"File {file.filename!r} exists at {str(directory)!r} already, " "set 'overwrite' flag to True to overwrite.", ) - with open(os.path.join(payload.directory, payload.file.filename), "wb") as f_stream: + with open(os.path.join(directory, file.filename), "wb") as f_stream: f_stream.write(content) raise exceptions.APIResponse( status_code=HTTPStatus.OK.real, - detail=f"{payload.file.filename!r} was uploaded to {payload.directory}.", + detail=f"{file.filename!r} was uploaded to {directory}.", )