| |
@@ -1,61 +0,0 @@
|
| |
- # Copyright 2013, Red Hat, Inc
|
| |
- #
|
| |
- # This program is free software; you can redistribute it and/or modify
|
| |
- # it under the terms of the GNU General Public License as published by
|
| |
- # the Free Software Foundation; either version 2 of the License, or
|
| |
- # (at your option) any later version.
|
| |
- #
|
| |
- # This program is distributed in the hope that it will be useful,
|
| |
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| |
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| |
- # GNU General Public License for more details.
|
| |
- #
|
| |
- # You should have received a copy of the GNU General Public License along
|
| |
- # with this program; if not, write to the Free Software Foundation, Inc.,
|
| |
- # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
| |
- #
|
| |
- # Authors:
|
| |
- # Martin Krizek <mkrizek@redhat.com>
|
| |
-
|
| |
- """ORM class for various user related information"""
|
| |
-
|
| |
- import string
|
| |
- import random
|
| |
- import crypt
|
| |
-
|
| |
- from blockerbugs import db, BaseModel
|
| |
-
|
| |
- # FIXME: This is not needed anymore after https://pagure.io/fedora-qa/blockerbugs/issue/230
|
| |
- # It also supports storing and checking API keys, but we don't use it anywhere.
|
| |
- # Get rid of this table?
|
| |
-
|
| |
- class UserInfo(BaseModel):
|
| |
- id = db.Column(db.Integer, primary_key=True)
|
| |
- fas_login = db.Column(db.String(255), unique=True)
|
| |
- bz_user = db.Column(db.String(255), unique=True)
|
| |
- api_key_hash = db.Column(db.String(255), unique=True)
|
| |
-
|
| |
-
|
| |
- def __init__(self, fas_login=None, bz_user=None):
|
| |
- self.fas_login = fas_login
|
| |
- self.bz_user = bz_user
|
| |
-
|
| |
- def generate_api_key(self):
|
| |
- def _random_string(length=16, chars=string.ascii_letters):
|
| |
- return ''.join(random.choice(chars) for _ in range(length))
|
| |
-
|
| |
- salt = '$6$%s$' % _random_string() #SHA-512, man crypt 3
|
| |
- password = _random_string()
|
| |
- self.api_key_hash = crypt.crypt(password, salt)
|
| |
- return password
|
| |
-
|
| |
- def check_api_key(self, key):
|
| |
- if not self.api_key_hash:
|
| |
- return False
|
| |
- if self.api_key_hash == crypt.crypt(key, self.api_key_hash):
|
| |
- return True
|
| |
- return False
|
| |
-
|
| |
-
|
| |
- def __repr__(self):
|
| |
- return '<userinfo %d: %s>' % (self.fas_login, self.bz_user)
|
| |
We no longer need the
UserInfo
table. Bugzilla credentials are not checked atthe moment (and even if we start to use them again, we'll probably don't need to
validate them), and API keys are not used at all.
This also solves a DeprecationWarning that the
crypt
module (used insideUserInfo
) will be removed from Python soon.