Ejemplo n.º 1
0
def update_secret_key(id, pull_num):
    global conn
    try:
        curs = conn.cursor(pymysql.cursors.DictCursor)

        # sql문 조합
        sql = 'update file set '

        args = []
        if name:
            args.append(name)
            sql += 'name = %s,'
        if last_commit_sha:
            args.append(last_commit_sha)
            sql += 'lastCommitSha = %s,'
        if repo_fullname:
            args.append(repo_fullname)
            sql += 'repoFullname = %s,'
        if sha:
            args.append(sha)
            sql += 'sha = %s,'

        sql = sql[:-1]  # 마지막 문자 자르기(, 때문)
        args.append(fullname)
        sql += ' where fullname = %s'

        #sql문 실행
        curs.execute(sql, args)
        conn.commit()
    except pymysql.err.IntegrityError as e:
        raise CustomError(error='SECRET_KEY_UPDATE_ERROR',
                          status=500,
                          exception=e)
Ejemplo n.º 2
0
 def plainread(self):
     try:
         config = ConfigObj(self.configfile)
     except:
         raise CustomError(
             'CONFIG',
             'Could not read configuration file %s' % self.configfile)
     return config
Ejemplo n.º 3
0
def github_account_validate(github_username, github_password):
    try:
        g = Github(github_username, github_password)
        # data = [(s.name, s.name) for s in g.get_user().get_repos()]
        return True
    except Exception as e:
        raise CustomError(error='INVALID_GITHUB_ACCOUNT',
                          msg='깃허브 계정정보가 잘못되었습니다.',
                          status=401)
Ejemplo n.º 4
0
def insertIntoRegister(teacher, student):
    conn = engine.connect()
    query = registerTbl.insert().values(temail=teacher, semail=student)
    try:
        conn.execute(query)
    except exc.IntegrityError as e:
        raise CustomError(e.code,
                          'Integrity Error with inserting into register')
    finally:
        conn.close()
Ejemplo n.º 5
0
def login_route():
    try:
        id = request.json['id']
        password = request.json['password']
        user = db.get_user(id)  # db에서 계정정보 가져오기

        # password에는 암호화가 적용되어있기 때문에 이렇게 해야함.
        if user is None:
            raise CustomError(error='LOGIN_ID_UNDEFINED',
                              msg='해당 아이디가 존재하지 않습니다.',
                              status=401)
        elif not bcrypt.check_password_hash(user['password'], password):
            raise CustomError(error='LOGIN_PASSWORD_NOT_EQUAL',
                              msg='비밀번호가 일치하지 않습니다.',
                              status=401)
        else:
            return jsonify(token=create_access_token(identity=id)), 200
    except CustomError as e:
        print(e)
        return e.to_response()
Ejemplo n.º 6
0
def add_user(u: User):
    global conn
    try:
        curs = conn.cursor(pymysql.cursors.DictCursor)
        #sql문 실행

        # githubUsername 중복 확인
        sql = "select * from account where githubUsername = %s"
        curs.execute(sql, (u.github_username))
        if curs.rowcount > 0:
            raise CustomError(error='USER_GITHUB_ACCOUNT_DUPLICATE',
                              msg='이미 등록된 깃허브 계정 입니다.',
                              status=500)

        sql = 'insert into account(id, password, githubUsername) values(%s,%s,%s)'
        curs.execute(sql, (u.id, u.password, u.github_username))
        conn.commit()
    except pymysql.err.IntegrityError as e:
        raise CustomError(error='USER_DUPLICATE',
                          msg='이미 가입되어 있는 아이디 입니다.',
                          status=500)
Ejemplo n.º 7
0
def add_file(f: File):
    global conn
    try:
        curs = conn.cursor(pymysql.cursors.DictCursor)
        #sql문 실행
        sql = 'insert into file(fullname,name,lastCommitSha,repoFullname,sha) values(%s,%s,%s,%s,%s)'
        curs.execute(
            sql,
            (f.fullname, f.name, f.last_commit_sha, f.repo_fullname, f.sha))
        conn.commit()
    except pymysql.err.IntegrityError as e:
        raise CustomError(error='File_DUPLICATE', status=500, exception=e)
Ejemplo n.º 8
0
 def validate(self, validationfile):
     try:
         config = ConfigObj(self.configfile,
                            configspec=validationfile,
                            stringify=True)
     except:
         raise CustomError(
             'CONFIG',
             'Could not read configuration file %s' % self.configfile)
     validator = Validator()
     result = config.validate(validator)
     return result
Ejemplo n.º 9
0
def add_repository(r: Repository):
    global conn
    try:
        curs = conn.cursor(pymysql.cursors.DictCursor)
        #sql문 실행
        sql = 'insert into repository(fullname,name,lastCommitDate, lastCommitSha,owner) values(%s,%s,%s,%s,%s)'
        curs.execute(sql, (r.fullname, r.name, r.last_commit_date,
                           r.last_commit_sha, r.owner))
        conn.commit()
    except pymysql.err.IntegrityError as e:
        raise CustomError(error='REPOSITORY_DUPLICATE',
                          status=500,
                          exception=e)
Ejemplo n.º 10
0
def add_secret_key(s: SecretKey):
    global conn
    try:
        curs = conn.cursor(pymysql.cursors.DictCursor)
        #sql문 실행
        sql = 'insert into secret_key(y,x,fileFullname,fileCommitSha,content,pullNum,repoLastCommitSha) values(%s,%s,%s,%s,%s,%s,%s)'
        curs.execute(sql, (s.y, s.x, s.file_fullname, s.file_commit_sha,
                           s.content, s.pull_num, s.repo_last_commit_sha))
        conn.commit()
    except pymysql.err.IntegrityError as e:
        raise CustomError(error='SECRET_KEY_DUPLICATE',
                          status=500,
                          exception=e)
Ejemplo n.º 11
0
    def read(self, validationfile=None):
        try:
            if validationfile:
                config = ConfigObj(self.configfile,
                                   configspec=validationfile,
                                   stringify=True)
            else:
                config = ConfigObj(self.configfile)
        except:
            raise CustomError(
                'CONFIG',
                'Could not read configuration file %s' % self.configfile)

        if validationfile:
            validator = Validator()
            ctest = config.validate(validator)
            if not ctest:
                raise CustomError(
                    'CONFIG',
                    'Configuration file has bad format or out-of-range values')

        cdict = self.convertdict(config)
        return cdict
Ejemplo n.º 12
0
def get_secret_keys():
    account_id = get_jwt_identity()
    repo_fullname = request.json['repo_fullname']

    repo = db.repo_dict_to_obj(db.get_repository(fullname=repo_fullname))

    if repo.owner != account_id:
        raise CustomError(error='UNAUTHORIZED', msg='접근할 수 없습니다.', status=401)

    secret_key_dicts = []

    for secret_key_dict in db.get_recent_secret_keys(repo=repo):
        secret_key_dicts.append(secret_key_dict)

    return jsonify(secret_key_dicts), 200
Ejemplo n.º 13
0
def update_repository(fullname,
                      name=None,
                      last_commit_date=None,
                      last_commit_sha=None,
                      owner=None):
    global conn
    try:
        curs = conn.cursor(pymysql.cursors.DictCursor)

        # sql문 조합
        sql = 'update repository set '
        args = []
        if name:
            args.append(name)
            sql += 'name = %s,'
        if last_commit_date:
            args.append(last_commit_date)
            sql += 'lastCommitDate = %s,'
        if last_commit_sha:
            args.append(last_commit_sha)
            sql += 'lastCommitSha = %s,'
        if owner:
            args.append(owner)
            sql += 'owner = %s,'

        args.append(fullname)
        sql = sql[:-1]  # 마지막 문자 자르기(, 때문)
        sql += ' where fullname = %s'

        #sql문 실행
        curs.execute(sql, args)
        conn.commit()
    except pymysql.err.IntegrityError as e:
        raise CustomError(error='REPOSITORY_UPDATE_ERROR',
                          status=500,
                          exception=e)