Browse Source

删除无关代码

becivells 5 years ago
parent
commit
c5d4430791
7 changed files with 3 additions and 232 deletions
  1. 0 8
      conf/__init__.py
  2. 0 137
      conf/confapi.py
  3. 0 3
      config.py
  4. 0 73
      config.py.product
  5. 0 2
      core.py
  6. 1 3
      requirements.txt
  7. 2 6
      webhooks.py

+ 0 - 8
conf/__init__.py

@@ -1,8 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-# @File  : __init__.py
-# @Author: becivells
-#@Contact : becivells@gmail.com
-# @Date  : 2017/12/6
-#@Software : PyCharm
-# @Desc  :

+ 0 - 137
conf/confapi.py

@@ -1,137 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-# @File  : confapi.py
-# @Author: becivells
-#@Contact : becivells@gmail.com
-# @Date  : 2017/12/6
-#@Software : PyCharm
-# @Desc  :
-import os
-import sys
-import json
-import shutil
-import argparse
-
-BASE_DIR = os.path.dirname(os.path.realpath(__file__))
-conf_path = BASE_DIR + os.sep + 'git.conf'
-
-git_serverip = '123.206.177.125'
-
-def addconf(uid,name,path,ip=None,user='apache',interval=3,cmd='git pull origin master',update=False):
-    if isinstance(ip,list):
-        ip.append(git_serverip)
-        _ip = ','.join('"%s"'%(i) for i in ip)
-    else:
-        _ip = '"{git_serverip}"'.format(git_serverip=git_serverip)
-
-    repo = '''{{
-        "{uid}": {{
-            "name": "{name}",
-            "path": "{path}",
-            "ip": ["127.0.0.1",{ip}],
-            "cmd": "{cmd}",
-            "user": "{user}",
-            "interval": {interval}
-        }}
-    }}'''.format(uid=uid, name=name, path=path,ip=_ip,user=user,cmd=cmd,interval=interval)
-    repos = getconf()
-    if uid in repos and not update:
-       print ('uuid is exist if you want to update  please use --update')
-       print (json.dumps({uid:(repos.get(uid))},indent=4))
-       print ('----------error---------')
-       sys.exit(-1)
-    with open(conf_path,'a') as f:
-        f.write(json.dumps(json.loads(repo)))
-        f.write('\n')
-    print (repo)
-
-
-def getconf():
-    _conf_dict = {}
-    with open(conf_path,'r') as f:
-        for line in f:
-            if line.strip():
-                _conf_dict.update(json.loads(line))
-            else:
-                print ('blank line')
-    return _conf_dict
-
-
-def check():
-    repo_dict = getconf()
-    flag = False
-    shutil.copy(conf_path,conf_path+'.bak')
-    with open(conf_path,'w') as f:
-        for k,v in repo_dict.items():
-            f.write(json.dumps({k:v}))
-            f.write('\n')
-    # print(json.dumps(getconf(),indent=4))
-
-
-def parse_cmd_args():
-    '''处理命令行选项
-
-    '''
-
-    import argparse
-    import uuid
-
-    parser = argparse.ArgumentParser(
-        prog='add gitconf',
-        description='add repo')
-
-    parser.add_argument("--uid", dest='uid', action="store",
-                       help="repo sync uid")
-
-    parser.add_argument("--update", dest='update', action="store",
-                        # default=  str(uuid.uuid1()), # 不能有默认值
-                        default=False,
-                       help="update date")
-
-    parser.add_argument("--cmd", dest='cmd', action="store",
-                        default=  'git pull origin master', # 不能有默认值
-                       help=("please use --cmd \"git pull origin master\" "
-                            "not --cmd 'git pull origin master' .etc "))
-
-
-    parser.add_argument("--name", action="store",
-                       dest='name',
-                       help="repo name")
-
-    parser.add_argument("--path", action="store",
-                       dest='path',
-                       help="repo name")
-
-    parser.add_argument('--ip',
-                        action="store",
-                        nargs='+',
-                        default=git_serverip,
-                        help="allow access ip address")
-
-    parser.add_argument("--user", action="store_true", default='apache',
-                        dest='user',
-                        help="user")
-
-    parser.add_argument('--interval',
-                        action="store",
-                        default='3',
-                        dest='interval',
-                        help='interval default 3s',type=int)
-
-    args = parser.parse_args()
-    if not (args.uid and args.name and args.path):
-        parser.print_help()
-        sys.exit(0)
-
-    return args
-if __name__ == '__main__':
-    args = parse_cmd_args()
-    cmd = args.cmd
-    if args.update:
-        print('update data')
-        addconf(args.uid, args.name, args.path, ip=args.ip, user=args.user,
-                interval=args.interval,cmd=cmd, update=True)
-        check()
-    else:
-        addconf(args.uid, args.name, args.path, ip=args.ip, user=args.user,
-                interval=args.interval,cmd=cmd, update=False)

+ 0 - 3
config.py

@@ -27,9 +27,6 @@ GIT_SERVER = [
 #访问的路径
 SYNC_PATH = 'hookssync'
 
-##如果token不存在路径访问正确那么访问时频繁更新配置间隔的时间
-CONF_UPDATE_TIME = 30
-
 #允许执行命令时的路径
 PATH_WHITE_LIST = [
     # 匹配所有

+ 0 - 73
config.py.product

@@ -1,73 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-# @File  : config.py
-# @Author: becivells
-#@Contact : becivells@gmail.com
-# @Date  : 2017/10/19
-#@Software : PyCharm
-# @Desc  :
-
-
-HOST = '0.0.0.0'
-PORT = 5000
-DEBUG = False   #True or False
-
-#允许git server地址访问
-GIT_SERVER = [
-    #localhost
-    '127.0.0.1',
-    '123.206.177.125'
-]
-
-#访问的路径
-SYNC_PATH = 'hookssync'
-
-##如果token不存在路径访问正确那么访问时频繁更新配置间隔的时间
-CONF_UPDATE_TIME = 30
-
-#允许执行命令时的路径
-PATH_WHITE_LIST = [
-    # /app/web/test
-    '^/app/web/.*',
-    # /app/web/tests
-    '^/var/www/html/.*'
-]
-
-#允许在webhooks执行时执行的命令 使用正则表达式进行匹配
-EXEC_WHITE_LIST = [
-     # git pull origin master
-    '^git pull \w+ \w+$',
-     # git fetch origin master && git reset --hard origin/master
-    '^git fetch \w+ \w+ && git reset --hard \w+/\w+$',
-    # git pull origin master && supervisorctl restart webhooks
-    '^git pull \w+ \w+ && supervisorctl restart \w+$',
-    # git fetch origin master && git reset --hard origin/master && supervisorctl restart webhooks
-    '^git fetch \w+ \w+ && git reset --hard \w+/\w+ && supervisorctl restart \w+$'
-]
-
-
-
-repo = {
-    "9901b6deb47111e7b832704d7b885ead":{
-        "name":"shop",
-        "path":"/app/web/game",
-        "ip":['127.0.0.1','123.206.177.125'],
-        "cmd":'git pull origin master',
-        "user":'apache',
-        'interval':3
-    }
-}
-
-# repo = {
-#     "9901b6deb47111e7b832704d7b885ead":{
-#         "name":"fanghuishop",
-#         "path":"/app/web/fanghuishop",
-#         "ip":['127.0.0.1','123.206.177.125'],
-#         "cmd":'git fetch origin master && git reset --hard origin/master',
-#         "user":'apache',
-#         'interval':3
-#     }
-# }
-
-
-

+ 0 - 2
core.py

@@ -13,7 +13,6 @@ import subprocess
 from config import repo
 from config import EXEC_WHITE_LIST
 from config import PATH_WHITE_LIST
-from conf.confapi import getconf
 def runcmd(cmd,path):
     out_temp = tempfile.SpooledTemporaryFile(max_size=10 * 1000)
     try:
@@ -67,5 +66,4 @@ def getrepo():
     更新配置文件
     :return:
     '''
-    repo.update(getconf())
     return repo

+ 1 - 3
requirements.txt

@@ -1,4 +1,2 @@
 flask
-gunicorn
-pymysql
-sqlalchemy
+gunicorn

+ 2 - 6
webhooks.py

@@ -20,7 +20,6 @@ from config import PORT
 from config import DEBUG
 from config import SYNC_PATH
 from config import GIT_SERVER
-from config import CONF_UPDATE_TIME
 
 app = Flask(__name__)
 
@@ -52,15 +51,12 @@ def sync(token):
     ip = request.remote_addr.strip()
     global repo
     if token not in repo:
-        if gettime() - confsync > CONF_UPDATE_TIME:
-            repo = getrepo()
-            if token not in repo:
             #token错误
-                return u'Hello %s !!\n'%(ip),403
+                return u'Hello %s token error !!\n'%(ip),403
 
     if (ip not in repo[token]['ip']) and (ip not in GIT_SERVER):
         #ip 来源错误
-        return u'Hello %s !!!\n'%(ip),403
+        return u'Hello %s ip error!!!\n'%(ip),403
 
     interval = repo[token]['interval']
     path = repo[token]['path']