3 Star 5 Fork 1

murphysecurity/murphysec-gitlab-scanner

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
webapi.py 1.89 KB
一键复制 编辑 原始数据 按行查看 历史
LongYLongY 提交于 2022-03-27 14:01 +08:00 . 增加增量扫描功能
# -*- coding:utf-8 -*-
from fastapi import FastAPI, Header, Request, Response
import uvicorn
import hmac
from libs.git import MyGitlab
from libs.murphy import MurphyScan
from datetime import datetime
from pydantic import BaseModel
from uuid import UUID
import configs
app = FastAPI()
APP_NAME = "webhook-listener"
WEBHOOK_SECRET = "My precious"
class WebhookData(BaseModel):
username: str
data: dict
event: str
timestamp: datetime
model: str
request_id: UUID
@app.post("/gitlab/webhook")
async def webhook(
request: Request,
response: Response,
content_length: int = Header(...),
x_hook_signature: str = Header(None)
):
if content_length > 1000000:
response.status_code = 400
return {"result": "Content too long"}
if x_hook_signature:
raw_input = await request.body()
input_hmac = hmac.new(
key=WEBHOOK_SECRET.encode(),
msg=raw_input,
digestmod="sha512"
)
if not hmac.compare_digest(input_hmac.hexdigest(), x_hook_signature):
#logger.error("Invalid message signature")
response.status_code = 400
return {"result": "Invalid message signature"}
#logger.info("Message signature checked ok")
else:
pass
#logger.info("No message signature to check")
body = await request.json()
if body['event_name'] == 'event_name':
branch = body['body'].split('/')[-1]
user_name = body['user_name']
git_http_url = body['git_http_url']
my_gl = MyGitlab(addr=configs.gitlab.address, token=configs.gitlab.token)
mf = MurphyScan(token=configs.murphy.token)
path = my_gl.clone_branch(git_http_url, branch)
scan_res = mf.scan(path)
my_gl.del_code(path)
else:
pass
return {"result": "ok"}
if __name__ == "__main__":
uvicorn.run("webapi:app", host="0.0.0.0", port=8888)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/murphysecurity/murphysec-gitlab-scanner.git
git@gitee.com:murphysecurity/murphysec-gitlab-scanner.git
murphysecurity
murphysec-gitlab-scanner
murphysec-gitlab-scanner
main

搜索帮助