rustus icon indicating copy to clipboard operation
rustus copied to clipboard

Webhook Documentation Suggestions

Open Kaelten opened this issue 2 years ago • 7 comments

While understanding hooks I ran across a few thoughts.

  1. The documentation provided for the schema doesn't include the variations of possible values/types depending on when the hook is triggered.
  2. The fastapi example could benefit from providing the pydantic models needed to parse the api.
  3. It strikes me as odd that only URI is uppercase, guessing this is an encoding artifact based on how rust's serialization works
  4. I was a little surprised that the hook name wasn't available in the payload, but not a huge deal either way.

To help address the first two thoughts, here is the schema I've reversed engineered from watching the hooks over several types of uploads. I'm not sure I've captured all the variations yet.

import datetime
import uuid

from pydantic import BaseModel, conint, Field

class UploadInfo(BaseModel):
    id: uuid.UUID
    offset: conint(ge=0)
    length: conint(ge=0) | None
    path: str | None
    created_at: datetime.datetime
    deferred_size: bool
    is_partial: bool
    is_final: bool
    parts: list[uuid.UUID] | None
    storage: str
    metadata: dict


class RequestInfo(BaseModel):
    uri: str = Field(alias='URI')
    method: str
    remote_addr: str
    headers: dict


class RustusPayload(BaseModel):
    upload: UploadInfo
    request: RequestInfo

I'd also suggest providing example payloads for each event type that covers the variations or at least document when a field can be in different states. i.e. parts is None unless it's a concat finalization in which it gives the ids of the other parts.

Kaelten avatar Jun 23 '22 17:06 Kaelten

Maybe it would be better if we change the format of hooks to be more intuitive.

And I guess changing URI to uri is a good thing.

s3rius avatar Jun 23 '22 21:06 s3rius

I think there's an argument for cleaning up and introducing a new format (for backwards compatibility at least) that'd be a little clearer. Happy to collaborate on the schema if you'd like.

Kaelten avatar Jun 23 '22 23:06 Kaelten

I guess we can break backwards compatibility, if we bump major version of the project. I don't think there will be a lot of difference to current format. But if the difference is huge I don't mind introducing new format.

s3rius avatar Jun 24 '22 20:06 s3rius

I updated docs and added new format (v2) where URI is lowercase. Will release in 0.5.8. Please check it out.

s3rius avatar Jul 24 '22 15:07 s3rius

will look soon!

Kaelten avatar Jul 25 '22 17:07 Kaelten

New documentation updates is a big upgrade. I'll test upgraded to .8 and switching over to the v2 format soon.

Kaelten avatar Jul 25 '22 21:07 Kaelten

New documentation updates is a big upgrade. I'll test upgraded to .8 and switching over to the v2 format soon.

Cool. I'm waiting for it.

s3rius avatar Jul 26 '22 00:07 s3rius

Closed due to inactivity.

s3rius avatar Jan 09 '23 09:01 s3rius