unknown 6 роки тому
коміт
8e7e6c6b15
12 змінених файлів з 124 додано та 0 видалено
  1. 3 0
      README.md
  2. 0 0
      __init__.py
  3. 0 0
      config/__init__.py
  4. 4 0
      config/base.py
  5. 5 0
      config/dev.py
  6. 5 0
      config/qcloud.py
  7. 14 0
      deployment/gitwebhook.conf
  8. 8 0
      deployment/gitwebhook.ini
  9. 19 0
      deployment/gunicorn.conf
  10. 5 0
      extensions.py
  11. 48 0
      utils.py
  12. 13 0
      views.py

+ 3 - 0
README.md

@@ -0,0 +1,3 @@
+# gitwebhook
+
+git web钩子服务

+ 0 - 0
__init__.py


+ 0 - 0
config/__init__.py


+ 4 - 0
config/base.py

@@ -0,0 +1,4 @@
+# -*-coding: utf-8 -*-
+
+class BaseConfig(object):
+    DEBUG = True

+ 5 - 0
config/dev.py

@@ -0,0 +1,5 @@
+# -*- coding: utf-8 -*-
+from .base import BaseConfig
+
+class DevConfig(BaseConfig):
+    pass

+ 5 - 0
config/qcloud.py

@@ -0,0 +1,5 @@
+# -*- coding: utf-8 -*-
+from .base import BaseConfig
+
+class QcloudConfig(BaseConfig):
+    pass

+ 14 - 0
deployment/gitwebhook.conf

@@ -0,0 +1,14 @@
+server {
+    listen 80;
+    server_name 47:101.46.124:3389;
+    access_log /data/log/nginx/test.nginx.error.log main;
+
+    proxy_redirect off;
+    proxy_set_header Host $host;
+    proxy_set_header X-Real-IP $remote_addr;
+    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+
+    location / {
+        proxy_pass http://unix:/var/run/test.sock;
+    }
+}

+ 8 - 0
deployment/gitwebhook.ini

@@ -0,0 +1,8 @@
+[program:githook]
+environment = CONFIG_NAME="qcloud"
+directory = /root/project/test/
+command = /usr/bin/gunicorn -c deployment/gunicorn.conf views:app
+stdout_logfile = /data/log/web/test.sup.log
+redirect_stderr = true
+autostart = true
+autorestart = true

+ 19 - 0
deployment/gunicorn.conf

@@ -0,0 +1,19 @@
+# -*- coding: utf-8 -*-
+
+APP_NAME = "gitwebhook"
+
+bind = "unix:/var/run/%s.sock" % APP_NAME
+
+workers = 1
+worker_class = "gevent"
+worker_connections = 500
+timeout = 60
+
+daemon = False
+pidfile = "/var/run/%s.pid" % APP_NAME
+chdir = "/root/ncahlx/gitwebhook/"
+
+errorlog = "/data/log/web/%s.log" % APP_NAME
+loglevel = "info"
+accesslog = "-"
+reload = True

+ 5 - 0
extensions.py

@@ -0,0 +1,5 @@
+# -*- coding: utf-8 -*-
+
+from utils import QcloudAPI
+
+qcdapi = QcloudAPI()

+ 48 - 0
utils.py

@@ -0,0 +1,48 @@
+# -*- coding: utf-8 -*-
+import os
+import sys
+import json
+import time
+import datetime
+import random
+import urllib
+import urllib2
+import ssl
+import gzip
+import StringIO
+import binascii
+import hmac
+import hashlib
+from traceback import format_exc
+from copy import deepcopy
+from collections import OrderedDict
+
+class QcloudAPI(object):
+    def __init__(self, secretid="AKIDOh7ZouTY4OWtDZp9zrrfGsyxDLL9mkdy",
+                 secretkey="RhlcaaJuKYzRPGvO3e4MTPBlS6Zq197G"):
+        self.secretid = secretid
+        self.secretkey = secretkey
+        self.params = {}
+
+    def gen_sign(self, url, params, method='GET'):
+        srcstr = method.upper() + url + '?' + "&".join(k.replace("_",".") + "=" + str(params[k]) for k in sorted(params.keys()))
+        # print srcstr
+        hashed = hmac.new(self.secretkey, srcstr, hashlib.sha1)
+        return binascii.b2a_base64(hashed.digest())[:-1]
+
+    def refresh_cnd_dir(self, url):
+        req_url = "cdn.api.qcloud.com/v2/index.php"
+        params = OrderedDict(deepcopy(self.params))
+        params["Action"] = "RefreshCdnDir"
+        params['SecretId'] = self.secretid
+        params["Timestamp"] = int(time.time())
+        params["Nonce"] = random.randint(1, 1000000000)
+        params["dirs.0"] = url
+        print params
+        params["Signature"] = self.gen_sign(req_url, params)
+        _req_url = "?".join(["https://"+req_url, urllib.urlencode(params)])
+        resp = send_req(_req_url)
+        print resp
+        return resp
+
+

+ 13 - 0
views.py

@@ -0,0 +1,13 @@
+# -*- coding: utf-8 -*-
+from flask import Flask
+
+app = Flask(__name__)
+
+
+@app.route("/")
+def index():
+    return "this is my test project!"
+
+
+if __name__ == "__main__":
+    app.run(port=8100, debug=True)