mirror of
https://github.com/saltstack/salt.git
synced 2025-04-16 17:50:20 +00:00
Fix resource leakage
This commit is contained in:
parent
843e218572
commit
281e0cafb2
5 changed files with 20 additions and 16 deletions
|
@ -642,8 +642,9 @@ def get_public_keys(vm_):
|
|||
)
|
||||
)
|
||||
ssh_keys = []
|
||||
for key in salt.utils.fopen(key_filename).readlines():
|
||||
ssh_keys.append(key)
|
||||
with salt.utils.fopen(key_filename) as rfh:
|
||||
for key in rfh.readlines():
|
||||
ssh_keys.append(key)
|
||||
|
||||
return ssh_keys
|
||||
|
||||
|
|
|
@ -91,7 +91,7 @@ def _publish_file(token, room, filepath, message='', api_url=None):
|
|||
headers['Authorization'] = "Bearer " + token
|
||||
msg = json.dumps({'message': message})
|
||||
|
||||
with open(filepath, 'rb') as rfh:
|
||||
with salt.utils.fopen(filepath, 'rb') as rfh:
|
||||
payload = """\
|
||||
--boundary123456
|
||||
Content-Type: application/json; charset=UTF-8
|
||||
|
|
|
@ -145,19 +145,21 @@ class KiwiExporter(object):
|
|||
'''
|
||||
# Get real local users with the local passwords
|
||||
shadow = {}
|
||||
for sh_line in salt.utils.fopen('/etc/shadow').read().split(os.linesep):
|
||||
if sh_line.strip():
|
||||
login, pwd = sh_line.split(":")[:2]
|
||||
if pwd and pwd[0] not in '!*':
|
||||
shadow[login] = {'p': pwd}
|
||||
with salt.utils.fopen('/etc/shadow') as rfh:
|
||||
for sh_line in rfh.read().split(os.linesep):
|
||||
if sh_line.strip():
|
||||
login, pwd = sh_line.split(":")[:2]
|
||||
if pwd and pwd[0] not in '!*':
|
||||
shadow[login] = {'p': pwd}
|
||||
|
||||
for ps_line in salt.utils.fopen('/etc/passwd').read().split(os.linesep):
|
||||
if ps_line.strip():
|
||||
ps_line = ps_line.strip().split(':')
|
||||
if ps_line[0] in shadow:
|
||||
shadow[ps_line[0]]['h'] = ps_line[5]
|
||||
shadow[ps_line[0]]['s'] = ps_line[6]
|
||||
shadow[ps_line[0]]['g'] = self._get_user_groups(ps_line[0])
|
||||
with salt.utils.fopen('/etc/passwd') as rfh:
|
||||
for ps_line in rfh.read().split(os.linesep):
|
||||
if ps_line.strip():
|
||||
ps_line = ps_line.strip().split(':')
|
||||
if ps_line[0] in shadow:
|
||||
shadow[ps_line[0]]['h'] = ps_line[5]
|
||||
shadow[ps_line[0]]['s'] = ps_line[6]
|
||||
shadow[ps_line[0]]['g'] = self._get_user_groups(ps_line[0])
|
||||
|
||||
users_groups = []
|
||||
users_node = etree.SubElement(node, 'users')
|
||||
|
|
2
setup.py
2
setup.py
|
@ -5,7 +5,7 @@ The setup script for salt
|
|||
'''
|
||||
|
||||
# pylint: disable=file-perms,ungrouped-imports,wrong-import-order,wrong-import-position,repr-flag-used-in-string
|
||||
# pylint: disable=3rd-party-local-module-not-gated
|
||||
# pylint: disable=3rd-party-local-module-not-gated,resource-leakage
|
||||
# pylint: disable=C0111,E1101,E1103,F0401,W0611,W0201,W0232,R0201,R0902,R0903
|
||||
|
||||
# For Python 2.5. A no-op on 2.6 and above.
|
||||
|
|
|
@ -11,6 +11,7 @@ To use this commit parser script pipe git log into the stdin:
|
|||
|
||||
git log | committer_parser.py -c -
|
||||
'''
|
||||
# pylint: disable=resource-leakage
|
||||
|
||||
# Import python libs
|
||||
from __future__ import absolute_import
|
||||
|
|
Loading…
Add table
Reference in a new issue