apps: various fixes and improvements for python3
This commit is contained in:
parent
c1e6b72cf9
commit
c231b4c990
18 changed files with 309 additions and 245 deletions
|
|
@ -63,23 +63,23 @@ class SshWrapper(object):
|
|||
from rhodecode.model.meta import raw_query_executor, Base
|
||||
|
||||
table = Table('user_ssh_keys', Base.metadata, autoload=False)
|
||||
atime = datetime.datetime.utcnow()
|
||||
stmt = (
|
||||
table.update()
|
||||
.where(table.c.ssh_key_id == key_id)
|
||||
.values(accessed_on=datetime.datetime.utcnow())
|
||||
.returning(table.c.accessed_on, table.c.ssh_key_fingerprint)
|
||||
.values(accessed_on=atime)
|
||||
# no MySQL Support for .returning :((
|
||||
#.returning(table.c.accessed_on, table.c.ssh_key_fingerprint)
|
||||
)
|
||||
|
||||
scalar_res = None
|
||||
res_count = None
|
||||
with raw_query_executor() as session:
|
||||
result = session.execute(stmt)
|
||||
if result.rowcount:
|
||||
scalar_res = result.first()
|
||||
res_count = result.rowcount
|
||||
|
||||
if scalar_res:
|
||||
atime, ssh_key_fingerprint = scalar_res
|
||||
log.debug('Update key id:`%s` fingerprint:`%s` access time',
|
||||
key_id, ssh_key_fingerprint)
|
||||
if res_count:
|
||||
log.debug('Update key id:`%s` access time', key_id)
|
||||
|
||||
def get_user(self, user_id):
|
||||
user = AttributeDict()
|
||||
|
|
|
|||
|
|
@ -40,8 +40,8 @@ SSH_OPTS = 'no-pty,no-port-forwarding,no-X11-forwarding,no-agent-forwarding'
|
|||
|
||||
def get_all_active_keys():
|
||||
result = UserSshKeys.query() \
|
||||
.options(joinedload(UserSshKeys.user)) \
|
||||
.filter(UserSshKeys.user != User.get_default_user()) \
|
||||
.join(User) \
|
||||
.filter(User != User.get_default_user()) \
|
||||
.filter(User.active == true()) \
|
||||
.all()
|
||||
return result
|
||||
|
|
@ -55,6 +55,10 @@ def _generate_ssh_authorized_keys_file(
|
|||
os.path.expanduser(authorized_keys_file_path))
|
||||
tmp_file_dir = os.path.dirname(authorized_keys_file_path)
|
||||
|
||||
if not os.path.exists(tmp_file_dir):
|
||||
log.debug('SSH authorized_keys file dir does not exist, creating one now...')
|
||||
os.makedirs(tmp_file_dir)
|
||||
|
||||
all_active_keys = get_all_active_keys()
|
||||
|
||||
if allow_shell:
|
||||
|
|
@ -65,6 +69,7 @@ def _generate_ssh_authorized_keys_file(
|
|||
if not os.path.isfile(authorized_keys_file_path):
|
||||
log.debug('Creating file at %s', authorized_keys_file_path)
|
||||
with open(authorized_keys_file_path, 'w'):
|
||||
# create a file with write access
|
||||
pass
|
||||
|
||||
if not os.access(authorized_keys_file_path, os.R_OK):
|
||||
|
|
@ -78,7 +83,7 @@ def _generate_ssh_authorized_keys_file(
|
|||
dir=tmp_file_dir)
|
||||
|
||||
now = datetime.datetime.utcnow().isoformat()
|
||||
keys_file = os.fdopen(fd, 'wb')
|
||||
keys_file = os.fdopen(fd, 'wt')
|
||||
keys_file.write(HEADER.format(len(all_active_keys), now))
|
||||
ini_path = rhodecode.CONFIG['__file__']
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue