-
Notifications
You must be signed in to change notification settings - Fork 649
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Improved server, security and commands #529
Conversation
Signed-off-by: Luca Simone <[email protected]>
@okotek |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your contributions, please see the comments
log_context["api_url"] = url | ||
with get_logger().contextualize(**log_context): | ||
background_tasks.add_task(PRAgent().handle_request, url, body) | ||
|
||
|
||
@router.post("/webhook") | ||
@router.post("/") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you change the webhook endpoint to /?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
router = APIRouter() | ||
|
||
|
||
def handle_request(background_tasks: BackgroundTasks, url: str, body: str, log_context: dict): | ||
def handle_request( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you change the parenthesis styling?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Black... I linted and formatted with black
if webhook_secret: | ||
body_bytes = await request.body() | ||
signature_header = request.headers.get("x-hub-signature", None) | ||
verify_signature(body_bytes, webhook_secret, signature_header) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you verify that it works as expected?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it works... the HMAC method is the same as GitHub just the header has a slightly different name (without -256)
elif data["eventKey"] == "pr:comment:added": | ||
body = data["comment"]["text"] | ||
else: | ||
return JSONResponse( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should return 200 in this case, this is not an error, unless you know differently?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well we can, but you have to configure which events you want to be pushed as webhook. If you push some events that are not supported it could be a bad request, or could be a 200 and who cares or, could also be a 501 not implemented which makes also sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm asking before in some cases, after a certain threshold of errors the webhook is disabled.
app.include_router(router) | ||
uvicorn.run(app, host="0.0.0.0", port=3000) | ||
uvicorn.run(app, host="0.0.0.0", port=int(os.environ.get("PORT", "3000"))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change this to BITBUCKET_SERVER.PORT, use get_settings().get(), add to configuration file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's like this because some cloud providers uses an environment variable PORT to bind the ingress... also in bitbucket_app.py
is done like this:
https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/servers/bitbucket_app.py#L162
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can't complain on my own code :(
…ements feat: Improved server, security and commands
I improved the Bitbucket server to enable all commands like review, ask and so on... plus I added the missing webhook HMAC security check.