Replace json module usage with a helper to ensure unicode content is handled properly

This adds wrappers for json.dump{,s} which disable `ensure_ascii` by
default.
This commit is contained in:
Erik Johnson 2017-12-22 13:54:53 -06:00
parent 66e090e75d
commit 7b13a7df8b
No known key found for this signature in database
GPG key ID: 5E5583C437808F3F
222 changed files with 1676 additions and 1546 deletions

View file

@ -72,7 +72,7 @@ Other optional functions can be included to add support for
.. code-block:: python
import redis
import json
import salt.utils.json
def returner(ret):
'''
@ -84,7 +84,7 @@ Other optional functions can be included to add support for
port=6379,
db='0')
serv.sadd("%(id)s:jobs" % ret, ret['jid'])
serv.set("%(jid)s:%(id)s" % ret, json.dumps(ret['return']))
serv.set("%(jid)s:%(id)s" % ret, salt.utils.json.dumps(ret['return']))
serv.sadd('jobs', ret['jid'])
serv.sadd(ret['jid'], ret['id'])
@ -168,6 +168,8 @@ must implement the following functions:
.. code-block:: python
import salt.utils.json
def save_load(jid, load):
'''
Save the load to the specified jid id
@ -176,7 +178,7 @@ must implement the following functions:
jid, load
) VALUES (
'{0}', '{1}'
);'''.format(jid, json.dumps(load))
);'''.format(jid, salt.utils.json.dumps(load))
# cassandra_cql.cql_query may raise a CommandExecutionError
try:
@ -185,8 +187,9 @@ must implement the following functions:
log.critical('Could not save load in jids table.')
raise
except Exception as e:
log.critical('''Unexpected error while inserting into
jids: {0}'''.format(str(e)))
log.critical(
'Unexpected error while inserting into jids: {0}'.format(e)
)
raise
@ -316,6 +319,8 @@ contains the jid and therefore is guaranteed to be unique.
.. code-block:: python
import salt.utils.json
def event_return(events):
'''
Return event to mysql server
@ -329,7 +334,7 @@ contains the jid and therefore is guaranteed to be unique.
data = event.get('data', '')
sql = '''INSERT INTO `salt_events` (`tag`, `data`, `master_id` )
VALUES (%s, %s, %s)'''
cur.execute(sql, (tag, json.dumps(data), __opts__['id']))
cur.execute(sql, (tag, salt.utils.json.dumps(data), __opts__['id']))
Testing the Returner

View file

@ -753,7 +753,7 @@ This proxymodule enables "package" installation.
from __future__ import absolute_import
# Import python libs
import json
import salt.utils.json
import logging
# Import Salt's libs
@ -821,7 +821,7 @@ This proxymodule enables "package" installation.
jsonret.append(ln_)
if '}' in ln_:
in_json = False
return json.loads('\n'.join(jsonret))
return salt.utils.json.loads('\n'.join(jsonret))
def package_list():

View file

@ -3,11 +3,10 @@
Create ssh executor system
'''
# Import python libs
from __future__ import absolute_import, print_function, unicode_literals
from __future__ import absolute_import, print_function
import base64
import copy
import getpass
import json
import logging
import multiprocessing
import subprocess
@ -1017,7 +1016,7 @@ class Single(object):
if '_error' in opts_pkg:
#Refresh failed
retcode = opts_pkg['retcode']
ret = json.dumps({'local': opts_pkg})
ret = salt.utils.json.dumps({'local': opts_pkg})
return ret, retcode
opts_pkg['file_roots'] = self.opts['file_roots']
@ -1139,9 +1138,9 @@ class Single(object):
# Mimic the json data-structure that "salt-call --local" will
# emit (as seen in ssh_py_shim.py)
if isinstance(result, dict) and 'local' in result:
ret = json.dumps({'local': result['local']})
ret = salt.utils.json.dumps({'local': result['local']})
else:
ret = json.dumps({'local': {'return': result}})
ret = salt.utils.json.dumps({'local': {'return': result}})
return ret, retcode
def _cmd_str(self):

View file

@ -2,19 +2,19 @@
'''
Manage transport commands via ssh
'''
from __future__ import absolute_import, print_function, unicode_literals
from __future__ import absolute_import, print_function
# Import python libs
import re
import os
import sys
import json
import time
import logging
import subprocess
# Import salt libs
import salt.defaults.exitcodes
import salt.utils.json
import salt.utils.nb_popen
import salt.utils.vt
@ -420,7 +420,7 @@ class Shell(object):
'flag:\n{0}').format(stdout)
return ret_stdout, '', 254
elif buff and buff.endswith('_||ext_mods||_'):
mods_raw = json.dumps(self.mods, separators=(',', ':')) + '|_E|0|'
mods_raw = salt.utils.json.dumps(self.mods, separators=(',', ':')) + '|_E|0|'
term.sendline(mods_raw)
if stdout:
old_stdout = stdout

View file

@ -7,8 +7,7 @@ This is not intended to be instantiated as a module, rather it is a
helper script used by salt.client.ssh.Single. It is here, in a
separate file, for convenience of development.
'''
from __future__ import absolute_import, print_function, unicode_literals
from __future__ import absolute_import, print_function
import hashlib
import tarfile

View file

@ -2,13 +2,12 @@
'''
Create ssh executor system
'''
from __future__ import absolute_import, print_function, unicode_literals
from __future__ import absolute_import, print_function
# Import python libs
import logging
import os
import tarfile
import tempfile
import json
import shutil
from contextlib import closing
@ -16,6 +15,7 @@ from contextlib import closing
import salt.client.ssh.shell
import salt.client.ssh
import salt.utils.files
import salt.utils.json
import salt.utils.path
import salt.utils.stringutils
import salt.utils.thin
@ -181,13 +181,13 @@ def prep_trans_tar(opts, file_client, chunks, file_refs, pillar=None, id_=None,
[salt.utils.url.create('_utils')],
]
with salt.utils.files.fopen(lowfn, 'w+') as fp_:
fp_.write(salt.utils.stringutils.to_str(json.dumps(chunks)))
salt.utils.json.dump(chunks, fp_)
if pillar:
with salt.utils.files.fopen(pillarfn, 'w+') as fp_:
fp_.write(salt.utils.stringutils.to_str(json.dumps(pillar)))
salt.utils.json.dump(pillar, fp_)
if roster_grains:
with salt.utils.files.fopen(roster_grainsfn, 'w+') as fp_:
fp_.write(salt.utils.stringutils.to_str(json.dumps(roster_grains)))
salt.utils.json.dump(roster_grains, fp_)
if id_ is None:
id_ = ''

View file

@ -7,13 +7,13 @@ as ZeroMQ salt, but via ssh.
'''
# Import python libs
from __future__ import absolute_import, print_function, unicode_literals
import json
from __future__ import absolute_import, print_function
import copy
# Import salt libs
import salt.loader
import salt.utils.data
import salt.utils.json
import salt.client.ssh
# Import 3rd-party libs
@ -103,8 +103,12 @@ class FunctionWrapper(object):
The remote execution function
'''
argv = [cmd]
argv.extend([json.dumps(arg) for arg in args])
argv.extend(['{0}={1}'.format(key, json.dumps(val)) for key, val in six.iteritems(kwargs)])
argv.extend([salt.utils.json.dumps(arg) for arg in args])
argv.extend(
['{0}={1}'.format(salt.utils.stringutils.to_str(key),
salt.utils.json.dumps(val))
for key, val in six.iteritems(kwargs)]
)
single = salt.client.ssh.Single(
self.opts,
argv,
@ -121,7 +125,7 @@ class FunctionWrapper(object):
'stderr': stderr,
'retcode': retcode}
try:
ret = json.loads(stdout, object_hook=salt.utils.data.decode_dict)
ret = salt.utils.json.loads(stdout, object_hook=salt.utils.data.decode_dict)
if len(ret) < 2 and 'local' in ret:
ret = ret['local']
ret = ret.get('return', {})

View file

@ -4,7 +4,7 @@ Return config information
'''
# Import python libs
from __future__ import absolute_import, print_function, unicode_literals
from __future__ import absolute_import, print_function
import re
import os

View file

@ -3,7 +3,7 @@
Wrap the cp module allowing for managed ssh file transfers
'''
# Import Python libs
from __future__ import absolute_import, print_function, unicode_literals
from __future__ import absolute_import, print_function
import logging
import os

View file

@ -4,15 +4,15 @@ Return/control aspects of the grains data
'''
# Import python libs
from __future__ import absolute_import, print_function, unicode_literals
from __future__ import absolute_import, print_function
import collections
import copy
import math
import json
# Import salt libs
import salt.utils.data
import salt.utils.dictupdate
import salt.utils.json
from salt.defaults import DEFAULT_TARGET_DELIM
from salt.exceptions import SaltException
@ -74,7 +74,7 @@ def get(key, default='', delimiter=DEFAULT_TARGET_DELIM, ordered=True):
if ordered is True:
grains = __grains__
else:
grains = json.loads(json.dumps(__grains__))
grains = salt.utils.json.loads(salt.utils.json.dumps(__grains__))
return salt.utils.data.traverse_dict_and_list(
__grains__,
key,

View file

@ -7,7 +7,7 @@ Wrapper function for mine operations for salt-ssh
'''
# Import python libs
from __future__ import absolute_import, print_function, unicode_literals
from __future__ import absolute_import, print_function
import copy
# Import salt libs

View file

@ -2,7 +2,7 @@
'''
Extract the pillar data for this minion
'''
from __future__ import absolute_import, print_function, unicode_literals
from __future__ import absolute_import, print_function
# Import python libs
import collections

View file

@ -10,7 +10,7 @@ salt-ssh calls and return the data from them.
No access control is needed because calls cannot originate from the minions.
'''
# Import python libs
from __future__ import absolute_import, print_function, unicode_literals
from __future__ import absolute_import, print_function
import copy
import logging

View file

@ -2,12 +2,10 @@
'''
Create ssh executor system
'''
from __future__ import absolute_import, print_function, unicode_literals
from __future__ import absolute_import, print_function
# Import python libs
import os
import time
import json
import logging
# Import salt libs
@ -19,6 +17,7 @@ import salt.utils.data
import salt.utils.files
import salt.utils.hashutils
import salt.utils.jid
import salt.utils.json
import salt.utils.platform
import salt.utils.state
import salt.utils.thin
@ -174,7 +173,7 @@ def sls(mods, saltenv='base', test=None, exclude=None, **kwargs):
# Read in the JSON data and return the data structure
try:
return json.loads(stdout, object_hook=salt.utils.data.decode_dict)
return salt.utils.json.loads(stdout, object_hook=salt.utils.data.decode_dict)
except Exception as e:
log.error("JSON Render failed for: %s\n%s", stdout, stderr)
log.error(six.text_type(e))
@ -318,7 +317,7 @@ def low(data, **kwargs):
# Read in the JSON data and return the data structure
try:
return json.loads(stdout, object_hook=salt.utils.data.decode_dict)
return salt.utils.json.loads(stdout, object_hook=salt.utils.data.decode_dict)
except Exception as e:
log.error("JSON Render failed for: %s\n%s", stdout, stderr)
log.error(six.text_type(e))
@ -407,7 +406,7 @@ def high(data, **kwargs):
# Read in the JSON data and return the data structure
try:
return json.loads(stdout, object_hook=salt.utils.data.decode_dict)
return salt.utils.json.loads(stdout, object_hook=salt.utils.data.decode_dict)
except Exception as e:
log.error("JSON Render failed for: %s\n%s", stdout, stderr)
log.error(six.text_type(e))
@ -650,7 +649,7 @@ def highstate(test=None, **kwargs):
# Read in the JSON data and return the data structure
try:
return json.loads(stdout, object_hook=salt.utils.data.decode_dict)
return salt.utils.json.loads(stdout, object_hook=salt.utils.data.decode_dict)
except Exception as e:
log.error("JSON Render failed for: %s\n%s", stdout, stderr)
log.error(six.text_type(e))
@ -731,7 +730,7 @@ def top(topfn, test=None, **kwargs):
# Read in the JSON data and return the data structure
try:
return json.loads(stdout, object_hook=salt.utils.data.decode_dict)
return salt.utils.json.loads(stdout, object_hook=salt.utils.data.decode_dict)
except Exception as e:
log.error("JSON Render failed for: %s\n%s", stdout, stderr)
log.error(six.text_type(e))
@ -1094,7 +1093,7 @@ def single(fun, name, test=None, **kwargs):
# Read in the JSON data and return the data structure
try:
return json.loads(stdout, object_hook=salt.utils.data.decode_dict)
return salt.utils.json.loads(stdout, object_hook=salt.utils.data.decode_dict)
except Exception as e:
log.error("JSON Render failed for: %s\n%s", stdout, stderr)
log.error(six.text_type(e))

View file

@ -28,7 +28,6 @@ Set up the cloud configuration at ``/etc/salt/cloud.providers`` or
# Import python libs
from __future__ import absolute_import
import time
import json
import pprint
import logging
import hmac
@ -43,6 +42,7 @@ from salt.ext.six.moves.urllib.parse import quote as _quote # pylint: disable=i
# Import salt cloud libs
import salt.utils.cloud
import salt.utils.data
import salt.utils.json
import salt.config as config
from salt.exceptions import (
SaltCloudNotFound,
@ -824,7 +824,7 @@ def query(params=None):
content = request.text
result = json.loads(content, object_hook=salt.utils.data.encode_dict)
result = salt.utils.json.loads(content, object_hook=salt.utils.data.encode_dict)
if 'Code' in result:
raise SaltCloudSystemExit(
pprint.pformat(result.get('Message', {}))

View file

@ -63,14 +63,14 @@ cloud configuration at
# Import python libs
from __future__ import absolute_import
import importlib
import logging
import time
import json
# Import salt libs
import importlib
from salt.exceptions import SaltCloudSystemExit
# Import salt cloud libs
import salt.config as config
import salt.utils.json
from salt.exceptions import SaltCloudSystemExit
# Get logging started
log = logging.getLogger(__name__)
@ -157,8 +157,8 @@ def list_nodes_full(call=None, for_output=True):
creds = get_creds()
clc.v1.SetCredentials(creds["token"], creds["token_pass"])
servers_raw = clc.v1.Server.GetServers(location=None)
servers_raw = json.dumps(servers_raw)
servers = json.loads(servers_raw)
servers_raw = salt.utils.json.dumps(servers_raw)
servers = salt.utils.json.loads(servers_raw)
return servers
@ -181,8 +181,8 @@ def get_monthly_estimate(call=None, for_output=True):
)
try:
billing_raw = clc.v1.Billing.GetAccountSummary(alias=creds["accountalias"])
billing_raw = json.dumps(billing_raw)
billing = json.loads(billing_raw)
billing_raw = salt.utils.json.dumps(billing_raw)
billing = salt.utils.json.loads(billing_raw)
billing = round(billing["MonthlyEstimate"], 2)
return {"Monthly Estimate": billing}
except RuntimeError:
@ -201,8 +201,8 @@ def get_month_to_date(call=None, for_output=True):
)
try:
billing_raw = clc.v1.Billing.GetAccountSummary(alias=creds["accountalias"])
billing_raw = json.dumps(billing_raw)
billing = json.loads(billing_raw)
billing_raw = salt.utils.json.dumps(billing_raw)
billing = salt.utils.json.loads(billing_raw)
billing = round(billing["MonthToDateTotal"], 2)
return {"Month To Date": billing}
except RuntimeError:
@ -243,8 +243,8 @@ def get_group_estimate(call=None, for_output=True, **kwargs):
)
try:
billing_raw = clc.v1.Billing.GetGroupEstimate(group=group, alias=creds["accountalias"], location=location)
billing_raw = json.dumps(billing_raw)
billing = json.loads(billing_raw)
billing_raw = salt.utils.json.dumps(billing_raw)
billing = salt.utils.json.loads(billing_raw)
estimate = round(billing["MonthlyEstimate"], 2)
month_to_date = round(billing["MonthToDate"], 2)
return {"Monthly Estimate": estimate, "Month to Date": month_to_date}

View file

@ -27,16 +27,16 @@ under the "SSH Keys" section.
# Import Python Libs
from __future__ import absolute_import
import os
import time
import json
import pprint
import logging
import decimal
import logging
import os
import pprint
import time
# Import Salt Libs
import salt.utils.cloud
import salt.utils.files
import salt.utils.json
import salt.config as config
from salt.exceptions import (
SaltCloudConfigError,
@ -562,7 +562,7 @@ def query(method='droplets', droplet_id=None, command=None, args=None, http_meth
'personal_access_token', get_configured_provider(), __opts__, search_global=False
)
data = json.dumps(args)
data = salt.utils.json.dumps(args)
requester = getattr(requests, http_method)
request = requester(path, data=data, headers={'Authorization': 'Bearer ' + personal_access_token, 'Content-Type': 'application/json'})
@ -584,7 +584,7 @@ def query(method='droplets', droplet_id=None, command=None, args=None, http_meth
content = request.text
result = json.loads(content)
result = salt.utils.json.loads(content)
if result.get('status', '').lower() == 'error':
raise SaltCloudSystemExit(
pprint.pformat(result.get('error_message', {}))

View file

@ -84,7 +84,6 @@ import binascii
import datetime
import base64
import msgpack
import json
import re
import decimal
@ -92,6 +91,7 @@ import decimal
import salt.utils.cloud
import salt.utils.files
import salt.utils.hashutils
import salt.utils.json
from salt._compat import ElementTree as ET
import salt.utils.http as http
import salt.utils.aws as aws
@ -4845,7 +4845,7 @@ def _parse_pricing(url, name):
# Turn the data into something that's easier/faster to process
regions = {}
price_json = json.loads(price_js)
price_json = salt.utils.json.loads(price_js)
for region in price_json['config']['regions']:
sizes = {}
for itype in region['instanceTypes']:

View file

@ -53,7 +53,6 @@ included:
# Import python libs
from __future__ import absolute_import
import os
import json
import logging
import base64
import pprint
@ -70,6 +69,7 @@ from salt.ext.six.moves import http_client # pylint: disable=import-error,no-na
import salt.utils.cloud
import salt.utils.files
import salt.utils.http
import salt.utils.json
import salt.config as config
from salt.cloud.libcloudfuncs import node_state
from salt.exceptions import (
@ -357,7 +357,7 @@ def create_node(**kwargs):
if firewall_enabled is not None:
create_data['firewall_enabled'] = firewall_enabled
data = json.dumps(create_data)
data = salt.utils.json.dumps(create_data)
ret = query(command='/my/machines', data=data, method='POST',
location=location)
@ -503,7 +503,7 @@ def take_action(name=None, call=None, command=None, data=None, method='GET',
)
if data:
data = json.dumps(data)
data = salt.utils.json.dumps(data)
ret = []
try:
@ -956,7 +956,7 @@ def import_key(kwargs=None, call=None):
kwargs['key'] = fp_.read()
send_data = {'name': kwargs['keyname'], 'key': kwargs['key']}
kwargs['data'] = json.dumps(send_data)
kwargs['data'] = salt.utils.json.dumps(send_data)
rcode, data = query(
command='my/keys',
@ -1095,7 +1095,7 @@ def query(action=None,
# post form data
if not data:
data = json.dumps({})
data = salt.utils.json.dumps({})
return_content = None
result = salt.utils.http.query(

View file

@ -10,7 +10,6 @@ Please read :ref:`core config documentation <config_lxc>`.
# Import python libs
from __future__ import absolute_import
import json
import os
import logging
import copy
@ -19,6 +18,7 @@ from pprint import pformat
# Import salt cloud libs
import salt.utils.cloud
import salt.utils.json
import salt.config as config
from salt.exceptions import SaltCloudSystemExit
@ -137,15 +137,15 @@ def _salt(fun, *args, **kw):
cache = True
laps = laps // __CACHED_FUNS[fun]
try:
sargs = json.dumps(args)
sargs = salt.utils.json.dumps(args)
except TypeError:
sargs = ''
try:
skw = json.dumps(kw)
skw = salt.utils.json.dumps(kw)
except TypeError:
skw = ''
try:
skwargs = json.dumps(kwargs)
skwargs = salt.utils.json.dumps(kwargs)
except TypeError:
skwargs = ''
cache_key = (laps, target, fun, sargs, skw, skwargs)

View file

@ -194,13 +194,13 @@ from __future__ import absolute_import
# Import Python Libs
import copy
import json
import logging
import os
import pprint
import socket
# Import Salt Libs
import salt.utils.json
import salt.config as config
import salt.ext.six as six
from salt.exceptions import (
@ -817,7 +817,7 @@ def call(conn=None, call=None, kwargs=None):
func = kwargs.pop('func')
for key, value in kwargs.items():
try:
kwargs[key] = json.loads(value)
kwargs[key] = salt.utils.json.loads(value)
except ValueError:
continue
try:

View file

@ -32,11 +32,10 @@ import time
import pprint
import logging
import re
import json
# Import salt libs
from salt.ext import six
import salt.utils
import salt.utils.cloud
import salt.utils.json
# Import salt cloud libs
import salt.config as config
@ -45,9 +44,10 @@ from salt.exceptions import (
SaltCloudExecutionFailure,
SaltCloudExecutionTimeout
)
from salt.ext.six.moves import range
# Import Third Party Libs
# Import 3rd-party Libs
from salt.ext import six
from salt.ext.six.moves import range
try:
import requests
HAS_REQUESTS = True
@ -632,7 +632,7 @@ def _import_api():
re_filter = re.compile('(?<=pveapi =)(.*)(?=^;)', re.DOTALL | re.MULTILINE)
api_json = re_filter.findall(returned_data.text)[0]
api = json.loads(api_json)
api = salt.utils.json.loads(api_json)
def _get_properties(path="", method="GET", forced_params=None):

View file

@ -29,7 +29,6 @@ Set up the cloud configuration at ``/etc/salt/cloud.providers`` or
# Import python libs
from __future__ import absolute_import
import time
import json
import pprint
import logging
import hmac
@ -41,6 +40,7 @@ from salt.ext.six.moves.urllib.parse import quote as _quote # pylint: disable=i
from salt.ext.six.moves import range
import salt.utils.cloud
import salt.utils.data
import salt.utils.json
import salt.config as config
from salt.exceptions import (
SaltCloudNotFound,
@ -156,8 +156,7 @@ def query(params=None):
if isinstance(value[i - 1], dict):
for sk, sv in value[i - 1].items():
if isinstance(sv, dict) or isinstance(sv, list):
# sv = json_dump(sv)
sv = json.dumps(sv, separators=(',', ':'))
sv = salt.utils.json.dumps(sv, separators=(',', ':'))
real_parameters['{0}.{1}.{2}'.format(key, i, sk)] = sv
else:
real_parameters['{0}.{1}'.format(key, i)] = value[i - 1]
@ -188,7 +187,7 @@ def query(params=None):
log.debug(request.url)
content = request.text
result = json.loads(content, object_hook=salt.utils.data.encode_dict)
result = salt.utils.json.loads(content, object_hook=salt.utils.data.encode_dict)
# print('response:')
# pprint.pprint(result)

View file

@ -25,7 +25,6 @@ the cloud configuration at ``/etc/salt/cloud.providers`` or
# Import Python Libs
from __future__ import absolute_import
import json
import logging
import pprint
import time
@ -33,6 +32,7 @@ import time
# Import Salt Libs
from salt.ext.six.moves import range
import salt.utils.cloud
import salt.utils.json
import salt.config as config
from salt.exceptions import (
SaltCloudNotFound,
@ -347,7 +347,7 @@ def query(method='servers', server_id=None, command=None, args=None,
'token', get_configured_provider(), __opts__, search_global=False
)
data = json.dumps(args)
data = salt.utils.json.dumps(args)
requester = getattr(requests, http_method)
request = requester(

View file

@ -14,7 +14,6 @@ import logging
import traceback
import multiprocessing
import subprocess
import json
# Import salt libs
from salt.ext import six
@ -22,6 +21,7 @@ import salt.daemons.masterapi
import salt.utils.args
import salt.utils.data
import salt.utils.files
import salt.utils.json
import salt.utils.kinds as kinds
import salt.utils.process
import salt.utils.stringutils
@ -62,7 +62,7 @@ def jobber_check(self):
rms.append(jid)
data = self.shells.value[jid]
stdout, stderr = data['proc'].communicate()
ret = json.loads(salt.utils.stringutils.to_str(stdout), object_hook=salt.utils.data.encode_dict)['local']
ret = salt.utils.json.loads(stdout, object_hook=salt.utils.data.encode_dict)['local']
route = {'src': (self.stack.value.local.name, 'manor', 'jid_ret'),
'dst': (data['msg']['route']['src'][0], None, 'remote_cmd')}
ret['cmd'] = '_return'

View file

@ -7,10 +7,10 @@ Send events from Docker events
# Import Python Libs
from __future__ import absolute_import
import json
import logging
import traceback
import salt.utils.json
import salt.utils.event
# pylint: disable=import-error
@ -83,7 +83,7 @@ def start(docker_url='unix://var/run/docker.sock',
try:
events = client.events()
for event in events:
data = json.loads(event.decode(__salt_system_encoding__, errors='replace'))
data = salt.utils.json.loads(event.decode(__salt_system_encoding__, errors='replace'))
# https://github.com/docker/cli/blob/master/cli/command/system/events.go#L109
# https://github.com/docker/engine-api/blob/master/types/events/events.go
# Each output includes the event type, actor id, name and action.

View file

@ -38,7 +38,6 @@ keys make the engine interactive.
from __future__ import absolute_import
import logging
import time
import json
import os
@ -52,6 +51,7 @@ import salt.utils.args
import salt.utils.event
import salt.utils.files
import salt.utils.http
import salt.utils.json
import salt.runner
import salt.client
import salt.loader
@ -93,10 +93,11 @@ def _publish_file(token, room, filepath, message='', outputter=None, api_url=Non
url = "{0}/v2/room/{1}/share/file".format(api_url, room)
headers = {'Content-type': 'multipart/related; boundary=boundary123456'}
headers['Authorization'] = "Bearer " + token
msg = json.dumps({'message': message})
msg = salt.utils.json.dumps({'message': message})
# future lint: disable=blacklisted-function
with salt.utils.files.fopen(filepath, 'rb') as rfh:
payload = """\
payload = str("""\
--boundary123456
Content-Type: application/json; charset=UTF-8
Content-Disposition: attachment; name="metadata"
@ -109,7 +110,10 @@ Content-Disposition: attachment; name="file"; filename="{1}"
{2}
--boundary123456--\
""".format(msg, os.path.basename(filepath), rfh.read())
""").format(msg,
os.path.basename(salt.utils.stringutils.to_str(filepath)),
salt.utils.stringutils.to_str(rfh.read()))
# future lint: enable=blacklisted-function
salt.utils.http.query(url, method='POST', header_dict=headers, data=payload)
@ -414,7 +418,7 @@ def start(token,
else:
tmp_path_fn = salt.utils.files.mkstemp()
with salt.utils.files.fopen(tmp_path_fn, 'w+') as fp_:
fp_.write(json.dumps(ret, sort_keys=True, indent=4))
salt.utils.json.dump(ret, fp_, sort_keys=True, indent=4)
_publish_file(token, room, tmp_path_fn, message=message_string, api_url=api_url)
salt.utils.files.safe_rm(tmp_path_fn)
time.sleep(wait_time or _DEFAULT_SLEEP)

View file

@ -32,12 +32,12 @@ them onto a logstash endpoint via HTTP requests.
from __future__ import absolute_import
# Import python lib
import json
import fnmatch
# Import salt libs
import salt.utils.http
import salt.utils.event
import salt.utils.json
# ----------------------------------------------------------------------------------------------------------------------
# module properties
@ -62,7 +62,7 @@ def _logstash(url, data):
url,
'POST',
header_dict=_HEADERS,
data=json.dumps(data),
data=salt.utils.json.dumps(data),
decode=True,
status=True,
opts=__opts__

View file

@ -42,11 +42,10 @@ To test this engine
salt '*' test.ping cmd.run uptime
'''
from __future__ import absolute_import
from __future__ import absolute_import, print_function, unicode_literals
# Import Salt libs
import salt.utils.event
from salt.ext import six
import salt.utils.json
# Import third party libs
try:
@ -67,33 +66,14 @@ except ImportError: # for systems without TLS support.
import socket
import random
import time
import codecs
import uuid
import logging
import json
log = logging.getLogger(__name__)
def __virtual__():
if not HAS_CERTIFI:
return False
if not HAS_SSL:
return False
return True
def _to_unicode(ch):
return codecs.unicode_escape_decode(ch)[0]
def _is_unicode(ch):
return isinstance(ch, six.text_type)
def _create_unicode(ch):
return six.text_type(ch, 'utf-8')
return True if HAS_CERTIFI and HAS_SSL else False
class PlainTextSocketAppender(object):
@ -111,8 +91,8 @@ class PlainTextSocketAppender(object):
# Error message displayed when an incorrect Token has been detected
self.INVALID_TOKEN = ("\n\nIt appears the LOGENTRIES_TOKEN "
"parameter you entered is incorrect!\n\n")
# Unicode Line separator character \u2028
self.LINE_SEP = _to_unicode(r'\u2028')
# Encoded unicode line separator
self.LINE_SEP = salt.utils.stringutils.to_str('\u2028')
self.verbose = verbose
self._conn = None
@ -149,17 +129,12 @@ class PlainTextSocketAppender(object):
self._conn.close()
def put(self, data):
# Replace newlines with Unicode line separator
# for multi-line events
if not _is_unicode(data):
multiline = _create_unicode(data).replace('\n', self.LINE_SEP)
else:
multiline = data.replace('\n', self.LINE_SEP)
multiline += "\n"
# Replace newlines with Unicode line separator for multi-line events
multiline = data.replace('\n', self.LINE_SEP) + str('\n') # future lint: disable=blacklisted-function
# Send data, reconnect if needed
while True:
try:
self._conn.send(multiline.encode('utf-8'))
self._conn.send(multiline)
except socket.error:
self.reopen_connection()
continue
@ -196,14 +171,6 @@ else:
SocketAppender = TLSSocketAppender
def _get_appender(endpoint='data.logentries.com', port=10000):
return SocketAppender(verbose=False, LE_API=endpoint, LE_PORT=port)
def _emit(token, msg):
return '{0} {1}'.format(token, msg)
def start(endpoint='data.logentries.com',
port=10000,
token=None,
@ -230,13 +197,19 @@ def start(endpoint='data.logentries.com',
except ValueError:
log.warning('Not a valid logentries token')
appender = _get_appender(endpoint, port)
appender = SocketAppender(verbose=False, LE_API=endpoint, LE_PORT=port)
appender.reopen_connection()
while True:
event = event_bus.get_event()
if event:
msg = '{0} {1}'.format(tag, json.dumps(event))
appender.put(_emit(token, msg))
# future lint: disable=blacklisted-function
msg = str(' ').join((
salt.utils.stringutils.to_str(token),
salt.utils.stringutils.to_str(tag),
salt.utils.json.dumps(event)
))
# future lint: enable=blacklisted-function
appender.put(msg)
appender.close_connection()

View file

@ -94,7 +94,6 @@ In addition, other groups are being loaded from pillars.
from __future__ import absolute_import
import ast
import datetime
import json
import itertools
import logging
import time
@ -118,6 +117,7 @@ import salt.runner
import salt.utils.args
import salt.utils.event
import salt.utils.http
import salt.utils.json
import salt.utils.slack
from salt.utils.yamldumper import OrderedDumper
@ -372,7 +372,7 @@ class SlackClient(object):
log.warn('Got a message that I could not log. The reason is: {}'.format(uee))
# Convert UTF to string
_text = json.dumps(_text)
_text = salt.utils.json.dumps(_text)
_text = yaml.safe_load(_text)
if not _text:
@ -574,7 +574,7 @@ class SlackClient(object):
indent=0)
try:
#return yaml.dump(data, **params).replace("\n\n", "\n")
return json.dumps(data, sort_keys=True, indent=1)
return salt.utils.json.dumps(data, sort_keys=True, indent=1)
# pylint: disable=broad-except
except Exception as exc:
import pprint
@ -626,7 +626,7 @@ class SlackClient(object):
# emulate lookup_jid's return, which is just minion:return
# pylint is tripping
# pylint: disable=missing-whitespace-after-comma
job_data = json.dumps({key:val['return'] for key, val in jid_result.items()})
job_data = salt.utils.json.dumps({key:val['return'] for key, val in jid_result.items()})
results[jid] = yaml.load(job_data)
return results
@ -692,7 +692,7 @@ class SlackClient(object):
content=return_text)
# Handle unicode return
log.debug('Got back {} via the slack client'.format(r))
resp = yaml.safe_load(json.dumps(r))
resp = yaml.safe_load(salt.utils.json.dumps(r))
if 'ok' in resp and resp['ok'] is False:
this_job['channel'].send_message('Error: {0}'.format(resp['error']))
del outstanding[jid]

View file

@ -77,9 +77,9 @@ Additionally you can define cross account sqs:
from __future__ import absolute_import
import logging
import time
import json
# Import salt libs
import salt.utils.json
import salt.utils.event
# Import third party libs
@ -140,7 +140,7 @@ def _process_queue(q, q_name, fire_master, tag='salt/engine/sqs', owner_acct_id=
msgs = q.get_messages(wait_time_seconds=20)
for msg in msgs:
if message_format == "json":
fire_master(tag=tag, data={'message': json.loads(msg.get_body())})
fire_master(tag=tag, data={'message': salt.utils.json.loads(msg.get_body())})
else:
fire_master(tag=tag, data={'message': msg.get_body()})
msg.delete()

View file

@ -5,11 +5,11 @@ A simple test engine, not intended for real use but as an example
# Import python libs
from __future__ import absolute_import
import json
import logging
# Import salt libs
import salt.utils.event
import salt.utils.json
log = logging.getLogger(__name__)
@ -34,6 +34,6 @@ def start():
while True:
event = event_bus.get_event()
jevent = json.dumps(event)
jevent = salt.utils.json.dumps(event)
if event:
log.debug(jevent)

View file

@ -4,13 +4,13 @@ Sudo executor module
'''
# Import python libs
from __future__ import absolute_import
import json
try:
from shlex import quote as _cmd_quote # pylint: disable=E0611
except ImportError:
from pipes import quote as _cmd_quote
# Import salt libs
import salt.utils.json
import salt.utils.path
import salt.syspaths
@ -70,7 +70,7 @@ def execute(opts, data, func, args, kwargs):
cmd_ret = __salt__['cmd.run_all'](cmd, use_vt=True, python_shell=False)
if cmd_ret['retcode'] == 0:
cmd_meta = json.loads(cmd_ret['stdout'])['local']
cmd_meta = salt.utils.json.loads(cmd_ret['stdout'])['local']
ret = cmd_meta['return']
__context__['retcode'] = cmd_meta.get('retcode', 0)
else:

View file

@ -47,10 +47,8 @@ permissions.
# Import python libs
from __future__ import absolute_import
import base64
import json
import logging
import os
import os.path
import shutil
# Import salt libs
@ -58,6 +56,7 @@ import salt.fileserver
import salt.utils.files
import salt.utils.gzip_util
import salt.utils.hashutils
import salt.utils.json
import salt.utils.path
from salt.utils.versions import LooseVersion
@ -260,7 +259,7 @@ def update():
with salt.utils.files.fopen(lk_fn, 'w+') as fp_:
fp_.write('')
with salt.utils.files.fopen(container_list, 'w') as fp_:
fp_.write(json.dumps(blob_names))
salt.utils.json.dump(blob_names, fp_)
try:
os.unlink(lk_fn)
except Exception:
@ -314,7 +313,7 @@ def file_list(load):
if not os.path.exists(container_list):
continue
with salt.utils.files.fopen(container_list, 'r') as fp_:
ret.update(set(json.load(fp_)))
ret.update(set(salt.utils.json.load(fp_)))
except Exception as exc:
log.error('azurefs: an error ocurred retrieving file lists. '
'It should be resolved next time the fileserver '

View file

@ -14,11 +14,11 @@ from __future__ import absolute_import
# Import python libs
import os
import json
import logging
# Import salt libs
import salt.utils.dictupdate
import salt.utils.json
import salt.utils.path
import salt.utils.platform
@ -119,7 +119,7 @@ def _sdc_mdata(mdata_list=None, mdata_get=None):
mdata_grain = mdata_grain.replace('-', '_')
mdata_grain = mdata_grain.replace(':', '_')
if mdata_grain in sdc_json_keys:
grains['mdata']['sdc'][mdata_grain] = json.loads(mdata_value)
grains['mdata']['sdc'][mdata_grain] = salt.utils.json.loads(mdata_value)
else:
grains['mdata']['sdc'][mdata_grain] = mdata_value

View file

@ -17,12 +17,12 @@ metadata server set `metadata_server_grains: True`.
from __future__ import absolute_import
# Import python libs
import json
import os
import socket
# Import salt libs
import salt.utils.http as http
import salt.utils.json
# metadata server information
@ -69,7 +69,7 @@ def _search(prefix="latest/"):
# (gtmanfred) This try except block is slightly faster than
# checking if the string starts with a curly brace
try:
ret[line] = json.loads(retdata)
ret[line] = salt.utils.json.loads(retdata)
except ValueError:
ret[line] = retdata
return ret

View file

@ -15,11 +15,11 @@ from __future__ import absolute_import
# Import python libs
import os
import re
import json
import logging
# Import salt libs
import salt.utils.dictupdate
import salt.utils.json
import salt.utils.path
import salt.utils.platform
from salt.ext.six.moves import zip
@ -84,7 +84,7 @@ def _smartos_computenode_data():
grains['computenode_vms_type'][vms[vm]['type']] += 1
# sysinfo derived grains
sysinfo = json.loads(__salt__['cmd.run']('sysinfo'))
sysinfo = salt.utils.json.loads(__salt__['cmd.run']('sysinfo'))
grains['computenode_sdc_version'] = sysinfo['SDC Version']
grains['computenode_vm_capable'] = sysinfo['VM Capable']
if sysinfo['VM Capable']:

View file

@ -8,7 +8,6 @@ used to manage salt keys directly without interfacing with the CLI.
from __future__ import absolute_import, print_function, unicode_literals
import os
import copy
import json
import stat
import shutil
import fnmatch
@ -27,6 +26,7 @@ import salt.utils.crypt
import salt.utils.data
import salt.utils.event
import salt.utils.files
import salt.utils.json
import salt.utils.kinds
import salt.utils.master
import salt.utils.sdb
@ -1032,10 +1032,8 @@ class RaetKey(Key):
continue
path = os.path.join(road_cache, road)
with salt.utils.files.fopen(path, 'rb') as fp_:
# Do not use to_unicode to decode this. It needs to stay as
# bytes to be deserialized.
if ext == '.json':
data = json.load(fp_)
data = salt.utils.json.load(fp_)
elif ext == '.msgpack':
data = msgpack.load(fp_)
role = salt.utils.stringutils.to_unicode(data['role'])

View file

@ -158,7 +158,6 @@
# Import python libs
from __future__ import absolute_import
import os
import json
import logging
import logging.handlers
import datetime
@ -166,6 +165,7 @@ import datetime
# Import salt libs
from salt.log.setup import LOG_LEVELS
from salt.log.mixins import NewStyleClassMixIn
import salt.utils.json
import salt.utils.network
# Import Third party libs
@ -325,7 +325,7 @@ class LogstashFormatter(logging.Formatter, NewStyleClassMixIn):
continue
message_dict['@fields'][key] = repr(value)
return json.dumps(message_dict)
return salt.utils.json.dumps(message_dict)
def format_v1(self, record):
message_dict = {
@ -369,7 +369,7 @@ class LogstashFormatter(logging.Formatter, NewStyleClassMixIn):
continue
message_dict[key] = repr(value)
return json.dumps(message_dict)
return salt.utils.json.dumps(message_dict)
class DatagramLogstashHandler(logging.handlers.DatagramHandler):

View file

@ -338,14 +338,15 @@ class SaltLoggingClass(six.with_metaclass(LoggingMixInMeta, LOGGING_LOGGER_CLASS
extra = None
# Let's try to make every logging message unicode
if isinstance(msg, six.string_types) \
and not isinstance(msg, six.text_type):
salt_system_encoding = __salt_system_encoding__
if salt_system_encoding == 'ascii':
# Encoding detection most likely failed, let's use the utf-8
# value which we defaulted before __salt_system_encoding__ was
# implemented
salt_system_encoding = 'utf-8'
if isinstance(msg, six.string_types) \
and not isinstance(msg, six.text_type):
try:
_msg = msg.decode(salt_system_encoding, 'replace')
except UnicodeDecodeError:
@ -353,11 +354,23 @@ class SaltLoggingClass(six.with_metaclass(LoggingMixInMeta, LOGGING_LOGGER_CLASS
else:
_msg = msg
_args = []
for item in args:
if isinstance(item, six.string_types) \
and not isinstance(item, six.text_type):
try:
_args.append(item.decode(salt_system_encoding, 'replace'))
except UnicodeDecodeError:
_args.append(item.decode(salt_system_encoding, 'ignore'))
else:
_args.append(item)
_args = tuple(_args)
if six.PY3:
logrecord = _LOG_RECORD_FACTORY(name, level, fn, lno, _msg, args,
logrecord = _LOG_RECORD_FACTORY(name, level, fn, lno, _msg, _args,
exc_info, func, sinfo)
else:
logrecord = _LOG_RECORD_FACTORY(name, level, fn, lno, _msg, args,
logrecord = _LOG_RECORD_FACTORY(name, level, fn, lno, _msg, _args,
exc_info, func)
if extra is not None:

View file

@ -36,8 +36,8 @@ import importlib
import yaml
import fnmatch
import subprocess
import json
import salt.utils.json
from salt.exceptions import LoaderError, CommandExecutionError
from salt.utils import timed_subprocess
@ -150,7 +150,8 @@ class AnsibleModuleCaller(object):
'')))
if args:
kwargs['_raw_params'] = ' '.join(args)
js_args = '{{"ANSIBLE_MODULE_ARGS": {args}}}'.format(args=json.dumps(kwargs))
js_args = str('{{"ANSIBLE_MODULE_ARGS": {args}}}') # future lint: disable=blacklisted-function
js_args = js_args.format(args=salt.utils.json.dumps(kwargs))
proc_out = timed_subprocess.TimedProc(["echo", "{0}".format(js_args)],
stdout=subprocess.PIPE, timeout=self.timeout)
@ -160,7 +161,7 @@ class AnsibleModuleCaller(object):
proc_exc.run()
try:
out = json.loads(proc_exc.stdout)
out = salt.utils.json.loads(proc_exc.stdout)
except ValueError as ex:
out = {'Error': (proc_exc.stderr and (proc_exc.stderr + '.') or str(ex))}
if proc_exc.stdout:

View file

@ -6,13 +6,13 @@ Aptly Debian repository manager.
'''
# Import python libs
from __future__ import absolute_import
import json
import logging
import os
import re
# Import salt libs
from salt.exceptions import SaltInvocationError
import salt.utils.json
import salt.utils.path
import salt.utils.stringutils as stringutils
@ -123,7 +123,7 @@ def get_config(config_path=_DEFAULT_CONFIG_PATH):
cmd_ret = _cmd_run(cmd)
return json.loads(cmd_ret)
return salt.utils.json.loads(cmd_ret)
def list_repos(config_path=_DEFAULT_CONFIG_PATH, with_packages=False):

View file

@ -23,7 +23,6 @@ import os
import re
import logging
import time
import json
# Import third party libs
import yaml
@ -42,6 +41,7 @@ import salt.utils.data
import salt.utils.files
import salt.utils.functools
import salt.utils.itertools
import salt.utils.json
import salt.utils.path
import salt.utils.pkg
import salt.utils.pkg.deb
@ -137,7 +137,7 @@ def _get_ppa_info_from_launchpad(owner_name, ppa_name):
owner_name, ppa_name)
request = _Request(lp_url, headers={'Accept': 'application/json'})
lp_page = _urlopen(request)
return json.load(lp_page)
return salt.utils.json.load(lp_page)
def _reconstruct_ppa_name(owner_name, ppa_name):

View file

@ -6,9 +6,9 @@ Support for the Amazon Simple Queue Service.
# Import Python libs
from __future__ import absolute_import
import logging
import json
# Import salt libs
import salt.utils.json
import salt.utils.path
from salt.ext import six
@ -65,7 +65,7 @@ def _run_aws(cmd, region, opts, user, **kwargs):
rtn = __salt__['cmd.run'](cmd, runas=user, python_shell=False)
return json.loads(rtn) if rtn else ''
return salt.utils.json.loads(rtn) if rtn else ''
def receive_message(queue, region, num=1, opts=None, user=None):

View file

@ -7,7 +7,7 @@ An execution module which can manipulate an f5 bigip via iControl REST
# Import python libs
from __future__ import absolute_import
import json
import salt.utils.json
import logging as logger
# Import third party libs
@ -72,7 +72,7 @@ def _load_response(response):
'''
try:
data = json.loads(response.text)
data = salt.utils.json.loads(response.text)
except ValueError:
data = response.text
@ -181,7 +181,7 @@ def _set_value(value):
value = value.replace('}j', '}')
try:
return json.loads(value)
return salt.utils.json.loads(value)
except Exception:
raise salt.exceptions.CommandExecutionError
@ -252,7 +252,10 @@ def start_transaction(hostname, username, password, label):
#post to REST to get trans id
try:
response = bigip_session.post(BIG_IP_URL_BASE.format(host=hostname)+'/transaction', data=json.dumps(payload))
response = bigip_session.post(
BIG_IP_URL_BASE.format(host=hostname) + '/transaction',
data=salt.utils.json.dumps(payload)
)
except requests.exceptions.ConnectionError as e:
return _load_connection_error(hostname, e)
@ -342,7 +345,10 @@ def commit_transaction(hostname, username, password, label):
#patch to REST to get trans id
try:
response = bigip_session.patch(BIG_IP_URL_BASE.format(host=hostname)+'/transaction/{trans_id}'.format(trans_id=trans_id), data=json.dumps(payload))
response = bigip_session.patch(
BIG_IP_URL_BASE.format(host=hostname) + '/transaction/{trans_id}'.format(trans_id=trans_id),
data=salt.utils.json.dumps(payload)
)
return _load_response(response)
except requests.exceptions.ConnectionError as e:
return _load_connection_error(hostname, e)
@ -460,7 +466,9 @@ def create_node(hostname, username, password, name, address, trans_label=None):
#post to REST
try:
response = bigip_session.post(BIG_IP_URL_BASE.format(host=hostname)+'/ltm/node', data=json.dumps(payload))
response = bigip_session.post(
BIG_IP_URL_BASE.format(host=hostname) + '/ltm/node',
data=salt.utils.json.dumps(payload))
except requests.exceptions.ConnectionError as e:
return _load_connection_error(hostname, e)
@ -537,7 +545,10 @@ def modify_node(hostname, username, password, name,
#put to REST
try:
response = bigip_session.put(BIG_IP_URL_BASE.format(host=hostname)+'/ltm/node/{name}'.format(name=name), data=json.dumps(payload))
response = bigip_session.put(
BIG_IP_URL_BASE.format(host=hostname) + '/ltm/node/{name}'.format(name=name),
data=salt.utils.json.dumps(payload)
)
except requests.exceptions.ConnectionError as e:
return _load_connection_error(hostname, e)
@ -758,7 +769,10 @@ def create_pool(hostname, username, password, name, members=None,
#post to REST
try:
response = bigip_session.post(BIG_IP_URL_BASE.format(host=hostname)+'/ltm/pool', data=json.dumps(payload))
response = bigip_session.post(
BIG_IP_URL_BASE.format(host=hostname) + '/ltm/pool',
data=salt.utils.json.dumps(payload)
)
except requests.exceptions.ConnectionError as e:
return _load_connection_error(hostname, e)
@ -902,7 +916,10 @@ def modify_pool(hostname, username, password, name,
#post to REST
try:
response = bigip_session.put(BIG_IP_URL_BASE.format(host=hostname)+'/ltm/pool/{name}'.format(name=name), data=json.dumps(payload))
response = bigip_session.put(
BIG_IP_URL_BASE.format(host=hostname) + '/ltm/pool/{name}'.format(name=name),
data=salt.utils.json.dumps(payload)
)
except requests.exceptions.ConnectionError as e:
return _load_connection_error(hostname, e)
@ -999,7 +1016,10 @@ def replace_pool_members(hostname, username, password, name, members):
#put to REST
try:
response = bigip_session.put(BIG_IP_URL_BASE.format(host=hostname)+'/ltm/pool/{name}'.format(name=name), data=json.dumps(payload))
response = bigip_session.put(
BIG_IP_URL_BASE.format(host=hostname) + '/ltm/pool/{name}'.format(name=name),
data=salt.utils.json.dumps(payload)
)
except requests.exceptions.ConnectionError as e:
return _load_connection_error(hostname, e)
@ -1052,7 +1072,10 @@ def add_pool_member(hostname, username, password, name, member):
#post to REST
try:
response = bigip_session.post(BIG_IP_URL_BASE.format(host=hostname)+'/ltm/pool/{name}/members'.format(name=name), data=json.dumps(payload))
response = bigip_session.post(
BIG_IP_URL_BASE.format(host=hostname) + '/ltm/pool/{name}/members'.format(name=name),
data=salt.utils.json.dumps(payload)
)
except requests.exceptions.ConnectionError as e:
return _load_connection_error(hostname, e)
@ -1138,7 +1161,10 @@ def modify_pool_member(hostname, username, password, name, member,
#put to REST
try:
response = bigip_session.put(BIG_IP_URL_BASE.format(host=hostname)+'/ltm/pool/{name}/members/{member}'.format(name=name, member=member), data=json.dumps(payload))
response = bigip_session.put(
BIG_IP_URL_BASE.format(host=hostname) + '/ltm/pool/{name}/members/{member}'.format(name=name, member=member),
data=salt.utils.json.dumps(payload)
)
except requests.exceptions.ConnectionError as e:
return _load_connection_error(hostname, e)
@ -1493,7 +1519,10 @@ def create_virtual(hostname, username, password, name, destination,
#post to REST
try:
response = bigip_session.post(BIG_IP_URL_BASE.format(host=hostname)+'/ltm/virtual', data=json.dumps(payload))
response = bigip_session.post(
BIG_IP_URL_BASE.format(host=hostname) + '/ltm/virtual',
data=salt.utils.json.dumps(payload)
)
except requests.exceptions.ConnectionError as e:
return _load_connection_error(hostname, e)
@ -1762,7 +1791,10 @@ def modify_virtual(hostname, username, password, name,
#put to REST
try:
response = bigip_session.put(BIG_IP_URL_BASE.format(host=hostname)+'/ltm/virtual/{name}'.format(name=name), data=json.dumps(payload))
response = bigip_session.put(
BIG_IP_URL_BASE.format(host=hostname) + '/ltm/virtual/{name}'.format(name=name),
data=salt.utils.json.dumps(payload)
)
except requests.exceptions.ConnectionError as e:
return _load_connection_error(hostname, e)
@ -1879,7 +1911,10 @@ def create_monitor(hostname, username, password, monitor_type, name, **kwargs):
#post to REST
try:
response = bigip_session.post(BIG_IP_URL_BASE.format(host=hostname)+'/ltm/monitor/{type}'.format(type=monitor_type), data=json.dumps(payload))
response = bigip_session.post(
BIG_IP_URL_BASE.format(host=hostname) + '/ltm/monitor/{type}'.format(type=monitor_type),
data=salt.utils.json.dumps(payload)
)
except requests.exceptions.ConnectionError as e:
return _load_connection_error(hostname, e)
@ -1926,7 +1961,10 @@ def modify_monitor(hostname, username, password, monitor_type, name, **kwargs):
#put to REST
try:
response = bigip_session.put(BIG_IP_URL_BASE.format(host=hostname)+'/ltm/monitor/{type}/{name}'.format(type=monitor_type, name=name), data=json.dumps(payload))
response = bigip_session.put(
BIG_IP_URL_BASE.format(host=hostname) + '/ltm/monitor/{type}/{name}'.format(type=monitor_type, name=name),
data=salt.utils.json.dumps(payload)
)
except requests.exceptions.ConnectionError as e:
return _load_connection_error(hostname, e)
@ -2077,7 +2115,10 @@ def create_profile(hostname, username, password, profile_type, name, **kwargs):
#post to REST
try:
response = bigip_session.post(BIG_IP_URL_BASE.format(host=hostname)+'/ltm/profile/{type}'.format(type=profile_type), data=json.dumps(payload))
response = bigip_session.post(
BIG_IP_URL_BASE.format(host=hostname) + '/ltm/profile/{type}'.format(type=profile_type),
data=salt.utils.json.dumps(payload)
)
except requests.exceptions.ConnectionError as e:
return _load_connection_error(hostname, e)
@ -2162,7 +2203,10 @@ def modify_profile(hostname, username, password, profile_type, name, **kwargs):
#put to REST
try:
response = bigip_session.put(BIG_IP_URL_BASE.format(host=hostname)+'/ltm/profile/{type}/{name}'.format(type=profile_type, name=name), data=json.dumps(payload))
response = bigip_session.put(
BIG_IP_URL_BASE.format(host=hostname) + '/ltm/profile/{type}/{name}'.format(type=profile_type, name=name),
data=salt.utils.json.dumps(payload)
)
except requests.exceptions.ConnectionError as e:
return _load_connection_error(hostname, e)

View file

@ -78,13 +78,13 @@ Connection module for Amazon APIGateway
# Import Python libs
from __future__ import absolute_import
import logging
import json
import datetime
# Import Salt libs
from salt.ext import six
import salt.utils.boto3
import salt.utils.compat
import salt.utils.json
from salt.utils.versions import LooseVersion as _LooseVersion
log = logging.getLogger(__name__)
@ -1161,7 +1161,7 @@ def update_api_model_schema(restApiId, modelName, schema, region=None, key=None,
'''
try:
schema_json = json.dumps(schema) if isinstance(schema, dict) else schema
schema_json = salt.utils.json.dumps(schema) if isinstance(schema, dict) else schema
conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
response = _api_model_patch_replace(conn, restApiId, modelName, '/schema', schema_json)
return {'updated': True, 'model': _convert_datetime_str(response)}
@ -1202,7 +1202,7 @@ def create_api_model(restApiId, modelName, modelDescription, schema, contentType
'''
try:
schema_json = json.dumps(schema) if isinstance(schema, dict) else schema
schema_json = salt.utils.json.dumps(schema) if isinstance(schema, dict) else schema
conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
model = conn.create_model(restApiId=restApiId, name=modelName, description=modelDescription,
schema=schema_json, contentType=contentType)

View file

@ -50,7 +50,6 @@ from __future__ import absolute_import
import datetime
import time
import logging
import json
import sys
import time
import email.mime.multipart
@ -79,6 +78,7 @@ except ImportError:
# Import Salt libs
import salt.utils.boto3
import salt.utils.compat
import salt.utils.json
import salt.utils.odict as odict
@ -235,13 +235,13 @@ def create(name, launch_config_name, availability_zones, min_size, max_size,
'''
conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
if isinstance(availability_zones, six.string_types):
availability_zones = json.loads(availability_zones)
availability_zones = salt.utils.json.loads(availability_zones)
if isinstance(load_balancers, six.string_types):
load_balancers = json.loads(load_balancers)
load_balancers = salt.utils.json.loads(load_balancers)
if isinstance(vpc_zone_identifier, six.string_types):
vpc_zone_identifier = json.loads(vpc_zone_identifier)
vpc_zone_identifier = salt.utils.json.loads(vpc_zone_identifier)
if isinstance(tags, six.string_types):
tags = json.loads(tags)
tags = salt.utils.json.loads(tags)
# Make a list of tag objects from the dict.
_tags = []
if tags:
@ -261,11 +261,11 @@ def create(name, launch_config_name, availability_zones, min_size, max_size,
propagate_at_launch=propagate_at_launch)
_tags.append(_tag)
if isinstance(termination_policies, six.string_types):
termination_policies = json.loads(termination_policies)
termination_policies = salt.utils.json.loads(termination_policies)
if isinstance(suspended_processes, six.string_types):
suspended_processes = json.loads(suspended_processes)
suspended_processes = salt.utils.json.loads(suspended_processes)
if isinstance(scheduled_actions, six.string_types):
scheduled_actions = json.loads(scheduled_actions)
scheduled_actions = salt.utils.json.loads(scheduled_actions)
retries = 30
while True:
try:
@ -325,19 +325,19 @@ def update(name, launch_config_name, availability_zones, min_size, max_size,
if not conn:
return False, "failed to connect to AWS"
if isinstance(availability_zones, six.string_types):
availability_zones = json.loads(availability_zones)
availability_zones = salt.utils.json.loads(availability_zones)
if isinstance(load_balancers, six.string_types):
load_balancers = json.loads(load_balancers)
load_balancers = salt.utils.json.loads(load_balancers)
if isinstance(vpc_zone_identifier, six.string_types):
vpc_zone_identifier = json.loads(vpc_zone_identifier)
vpc_zone_identifier = salt.utils.json.loads(vpc_zone_identifier)
if isinstance(tags, six.string_types):
tags = json.loads(tags)
tags = salt.utils.json.loads(tags)
if isinstance(termination_policies, six.string_types):
termination_policies = json.loads(termination_policies)
termination_policies = salt.utils.json.loads(termination_policies)
if isinstance(suspended_processes, six.string_types):
suspended_processes = json.loads(suspended_processes)
suspended_processes = salt.utils.json.loads(suspended_processes)
if isinstance(scheduled_actions, six.string_types):
scheduled_actions = json.loads(scheduled_actions)
scheduled_actions = salt.utils.json.loads(scheduled_actions)
# Massage our tagset into add / remove lists
# Use a boto3 call here b/c the boto2 call doeesn't implement filters
@ -510,7 +510,7 @@ def get_cloud_init_mime(cloud_init):
salt myminion boto.get_cloud_init_mime <cloud init>
'''
if isinstance(cloud_init, six.string_types):
cloud_init = json.loads(cloud_init)
cloud_init = salt.utils.json.loads(cloud_init)
_cloud_init = email.mime.multipart.MIMEMultipart()
if 'boothooks' in cloud_init:
for script_name, script in six.iteritems(cloud_init['boothooks']):
@ -655,9 +655,9 @@ def create_launch_configuration(name, image_id, key_name=None,
'''
conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
if isinstance(security_groups, six.string_types):
security_groups = json.loads(security_groups)
security_groups = salt.utils.json.loads(security_groups)
if isinstance(block_device_mappings, six.string_types):
block_device_mappings = json.loads(block_device_mappings)
block_device_mappings = salt.utils.json.loads(block_device_mappings)
_bdms = []
if block_device_mappings:
# Boto requires objects for the mappings and the devices.

View file

@ -48,9 +48,9 @@ from __future__ import absolute_import
# Import Python libs
import logging
import json
import yaml
import salt.utils.json
import salt.utils.odict as odict
log = logging.getLogger(__name__)
@ -66,7 +66,7 @@ try:
except ImportError:
HAS_BOTO = False
from salt.ext.six import string_types
from salt.ext import six
def __virtual__():
@ -220,16 +220,16 @@ def create_or_update_alarm(
period = int(period)
if evaluation_periods:
evaluation_periods = int(evaluation_periods)
if isinstance(dimensions, string_types):
dimensions = json.loads(dimensions)
if isinstance(dimensions, six.string_types):
dimensions = salt.utils.json.loads(dimensions)
if not isinstance(dimensions, dict):
log.error("could not parse dimensions argument: must be json encoding of a dict: '{0}'".format(dimensions))
return False
if isinstance(alarm_actions, string_types):
if isinstance(alarm_actions, six.string_types):
alarm_actions = alarm_actions.split(",")
if isinstance(insufficient_data_actions, string_types):
if isinstance(insufficient_data_actions, six.string_types):
insufficient_data_actions = insufficient_data_actions.split(",")
if isinstance(ok_actions, string_types):
if isinstance(ok_actions, six.string_types):
ok_actions = ok_actions.split(",")
# convert provided action names into ARN's

View file

@ -48,7 +48,7 @@ from __future__ import absolute_import
# Import Python libs
import logging
import json
import salt.utils.json
import salt.utils.compat
log = logging.getLogger(__name__)
@ -67,7 +67,7 @@ except ImportError as e:
HAS_BOTO = False
# pylint: enable=import-error
from salt.ext.six import string_types
from salt.ext import six
def __virtual__():
@ -281,8 +281,8 @@ def put_targets(Rule, Targets,
'''
try:
conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
if isinstance(Targets, string_types):
Targets = json.loads(Targets)
if isinstance(Targets, six.string_types):
Targets = salt.utils.json.loads(Targets)
failures = conn.put_targets(Rule=Rule, Targets=Targets)
if failures and failures.get('FailedEntryCount', 0) > 0:
return {'failures': failures.get('FailedEntries')}
@ -311,8 +311,8 @@ def remove_targets(Rule, Ids,
'''
try:
conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
if isinstance(Ids, string_types):
Ids = json.loads(Ids)
if isinstance(Ids, six.string_types):
Ids = salt.utils.json.loads(Ids)
failures = conn.remove_targets(Rule=Rule, Ids=Ids)
if failures and failures.get('FailedEntryCount', 0) > 0:
return {'failures': failures.get('FailedEntries', 1)}

View file

@ -49,11 +49,11 @@ Connection module for Amazon EC2
from __future__ import absolute_import
import logging
import time
import json
# Import Salt libs
import salt.utils.compat
import salt.utils.data
import salt.utils.json
from salt.ext import six
from salt.exceptions import SaltInvocationError, CommandExecutionError
from salt.utils.versions import LooseVersion as _LooseVersion
@ -822,7 +822,7 @@ def _to_blockdev_map(thing):
if isinstance(thing, BlockDeviceMapping):
return thing
if isinstance(thing, six.string_types):
thing = json.loads(thing)
thing = salt.utils.json.loads(thing)
if not isinstance(thing, dict):
log.error("Can't convert '{0}' of type {1} to a "
"boto.ec2.blockdevicemapping.BlockDeviceMapping".format(thing, type(thing)))

View file

@ -77,12 +77,12 @@ Connection module for Amazon Elasticsearch Service
# Import Python libs
from __future__ import absolute_import
import logging
import json
# Import Salt libs
from salt.ext import six
import salt.utils.boto3
import salt.utils.compat
import salt.utils.json
from salt.exceptions import SaltInvocationError
from salt.utils.versions import LooseVersion as _LooseVersion
@ -256,12 +256,12 @@ def create(DomainName, ElasticsearchClusterConfig=None, EBSOptions=None,
val = locals()[k]
if isinstance(val, six.string_types):
try:
val = json.loads(val)
val = salt.utils.json.loads(val)
except ValueError as e:
return {'updated': False, 'error': 'Error parsing {0}: {1}'.format(k, e.message)}
kwargs[k] = val
if 'AccessPolicies' in kwargs:
kwargs['AccessPolicies'] = json.dumps(kwargs['AccessPolicies'])
kwargs['AccessPolicies'] = salt.utils.json.dumps(kwargs['AccessPolicies'])
if 'ElasticsearchVersion' in kwargs:
kwargs['ElasticsearchVersion'] = str(kwargs['ElasticsearchVersion'])
domain = conn.create_elasticsearch_domain(DomainName=DomainName, **kwargs)
@ -330,12 +330,12 @@ def update(DomainName, ElasticsearchClusterConfig=None, EBSOptions=None,
val = locals()[k]
if isinstance(val, six.string_types):
try:
val = json.loads(val)
val = salt.utils.json.loads(val)
except ValueError as e:
return {'updated': False, 'error': 'Error parsing {0}: {1}'.format(k, e.message)}
call_args[k] = val
if 'AccessPolicies' in call_args:
call_args['AccessPolicies'] = json.dumps(call_args['AccessPolicies'])
call_args['AccessPolicies'] = salt.utils.json.dumps(call_args['AccessPolicies'])
try:
conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
domain = conn.update_elasticsearch_domain_config(DomainName=DomainName, **call_args)

View file

@ -48,18 +48,17 @@ from __future__ import absolute_import
# Import Python libs
import logging
import json
import time
log = logging.getLogger(__name__)
# Import Salt libs
import salt.utils.json
import salt.utils.odict as odict
from salt.utils.versions import LooseVersion as _LooseVersion
# Import third party libs
from salt.ext import six
from salt.ext.six import string_types
try:
import boto
import boto.ec2 # pylint: enable=unused-import
@ -254,11 +253,11 @@ def create(name, availability_zones, listeners, subnets=None,
conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
if exists(name, region, key, keyid, profile):
return True
if isinstance(availability_zones, string_types):
availability_zones = json.loads(availability_zones)
if isinstance(availability_zones, six.string_types):
availability_zones = salt.utils.json.loads(availability_zones)
if isinstance(listeners, string_types):
listeners = json.loads(listeners)
if isinstance(listeners, six.string_types):
listeners = salt.utils.json.loads(listeners)
_complex_listeners = []
for listener in listeners:
@ -321,8 +320,8 @@ def create_listeners(name, listeners, region=None, key=None, keyid=None,
'''
conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
if isinstance(listeners, string_types):
listeners = json.loads(listeners)
if isinstance(listeners, six.string_types):
listeners = salt.utils.json.loads(listeners)
_complex_listeners = []
for listener in listeners:
@ -352,8 +351,8 @@ def delete_listeners(name, ports, region=None, key=None, keyid=None,
'''
conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
if isinstance(ports, string_types):
ports = json.loads(ports)
if isinstance(ports, six.string_types):
ports = salt.utils.json.loads(ports)
try:
conn.delete_load_balancer_listeners(name, ports)
msg = 'Deleted ELB listeners on {0}'.format(name)
@ -379,8 +378,8 @@ def apply_security_groups(name, security_groups, region=None, key=None,
'''
conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
if isinstance(security_groups, string_types):
security_groups = json.loads(security_groups)
if isinstance(security_groups, six.string_types):
security_groups = salt.utils.json.loads(security_groups)
try:
conn.apply_security_groups_to_lb(name, security_groups)
msg = 'Applied security_groups on ELB {0}'.format(name)
@ -407,8 +406,8 @@ def enable_availability_zones(name, availability_zones, region=None, key=None,
'''
conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
if isinstance(availability_zones, string_types):
availability_zones = json.loads(availability_zones)
if isinstance(availability_zones, six.string_types):
availability_zones = salt.utils.json.loads(availability_zones)
try:
conn.enable_availability_zones(name, availability_zones)
msg = 'Enabled availability_zones on ELB {0}'.format(name)
@ -434,8 +433,8 @@ def disable_availability_zones(name, availability_zones, region=None, key=None,
'''
conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
if isinstance(availability_zones, string_types):
availability_zones = json.loads(availability_zones)
if isinstance(availability_zones, six.string_types):
availability_zones = salt.utils.json.loads(availability_zones)
try:
conn.disable_availability_zones(name, availability_zones)
msg = 'Disabled availability_zones on ELB {0}'.format(name)
@ -461,8 +460,8 @@ def attach_subnets(name, subnets, region=None, key=None, keyid=None,
'''
conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
if isinstance(subnets, string_types):
subnets = json.loads(subnets)
if isinstance(subnets, six.string_types):
subnets = salt.utils.json.loads(subnets)
try:
conn.attach_lb_to_subnets(name, subnets)
msg = 'Attached ELB {0} on subnets.'.format(name)
@ -488,8 +487,8 @@ def detach_subnets(name, subnets, region=None, key=None, keyid=None,
'''
conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
if isinstance(subnets, string_types):
subnets = json.loads(subnets)
if isinstance(subnets, six.string_types):
subnets = salt.utils.json.loads(subnets)
try:
conn.detach_lb_from_subnets(name, subnets)
msg = 'Detached ELB {0} from subnets.'.format(name)

View file

@ -38,15 +38,15 @@ Connection module for Amazon IAM
#pylint: disable=E0602
# Import Python libs
from __future__ import absolute_import
from __future__ import absolute_import, print_function, unicode_literals
import logging
import json
import yaml
import time
# Import salt libs
from salt.ext import six
import salt.utils.compat
import salt.utils.json
import salt.utils.odict as odict
# Import third party libs
@ -123,11 +123,10 @@ def create_instance_profile(name, region=None, key=None, keyid=None,
# This call returns an instance profile if successful and an exception
# if not. It's annoying.
conn.create_instance_profile(name)
log.info('Created {0} instance profile.'.format(name))
log.info('Created %s instance profile.', name)
except boto.exception.BotoServerError as e:
log.debug(e)
msg = 'Failed to create {0} instance profile.'
log.error(msg.format(name))
log.error('Failed to create %s instance profile.', name)
return False
return True
@ -149,11 +148,10 @@ def delete_instance_profile(name, region=None, key=None, keyid=None,
return True
try:
conn.delete_instance_profile(name)
log.info('Deleted {0} instance profile.'.format(name))
log.info('Deleted %s instance profile.', name)
except boto.exception.BotoServerError as e:
log.debug(e)
msg = 'Failed to delete {0} instance profile.'
log.error(msg.format(name))
log.error('Failed to delete %s instance profile.', name)
return False
return True
@ -192,7 +190,7 @@ def describe_role(name, region=None, key=None, keyid=None, profile=None):
if not info:
return False
role = info.get_role_response.get_role_result.role
role['assume_role_policy_document'] = json.loads(_unquote(
role['assume_role_policy_document'] = salt.utils.json.loads(_unquote(
role.assume_role_policy_document
))
# If Sid wasn't defined by the user, boto will still return a Sid in
@ -206,8 +204,7 @@ def describe_role(name, region=None, key=None, keyid=None, profile=None):
return role
except boto.exception.BotoServerError as e:
log.debug(e)
msg = 'Failed to get {0} information.'
log.error(msg.format(name))
log.error('Failed to get %s information.', name)
return False
@ -231,12 +228,11 @@ def create_user(user_name, path=None, region=None, key=None, keyid=None,
conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
try:
conn.create_user(user_name, path)
log.info('Created user : {0}.'.format(user_name))
log.info('Created IAM user : %s.', user_name)
return True
except boto.exception.BotoServerError as e:
log.debug(e)
msg = 'Failed to create user {0}.'
log.error(msg.format(user_name))
log.error('Failed to create IAM user %s.', user_name)
return False
@ -258,8 +254,8 @@ def get_all_access_keys(user_name, marker=None, max_items=None,
return conn.get_all_access_keys(user_name, marker, max_items)
except boto.exception.BotoServerError as e:
log.debug(e)
log.error('Failed to get user\'s {0} access keys.'.format(user_name))
return str(e)
log.error('Failed to get access keys for IAM user %s.', user_name)
return six.text_type(e)
def create_access_key(user_name, region=None, key=None, keyid=None, profile=None):
@ -280,7 +276,7 @@ def create_access_key(user_name, region=None, key=None, keyid=None, profile=None
except boto.exception.BotoServerError as e:
log.debug(e)
log.error('Failed to create access key.')
return str(e)
return six.text_type(e)
def delete_access_key(access_key_id, user_name=None, region=None, key=None,
@ -301,8 +297,8 @@ def delete_access_key(access_key_id, user_name=None, region=None, key=None,
return conn.delete_access_key(access_key_id, user_name)
except boto.exception.BotoServerError as e:
log.debug(e)
log.error('Failed to delete access key id {0}.'.format(access_key_id))
return str(e)
log.error('Failed to delete access key id %s.', access_key_id)
return six.text_type(e)
def delete_user(user_name, region=None, key=None, keyid=None,
@ -323,12 +319,12 @@ def delete_user(user_name, region=None, key=None, keyid=None,
conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
try:
conn.delete_user(user_name)
log.info('Deleted user : {0} .'.format(user_name))
log.info('Deleted IAM user : %s .', user_name)
return True
except boto.exception.BotoServerError as e:
log.debug(e)
log.error('Failed to delete user {0}'.format(user_name))
return str(e)
log.error('Failed to delete IAM user %s', user_name)
return six.text_type(e)
def get_user(user_name=None, region=None, key=None, keyid=None, profile=None):
@ -351,8 +347,7 @@ def get_user(user_name=None, region=None, key=None, keyid=None, profile=None):
return info
except boto.exception.BotoServerError as e:
log.debug(e)
msg = 'Failed to get user {0} info.'
log.error(msg.format(user_name))
log.error('Failed to get IAM user %s info.', user_name)
return False
@ -377,12 +372,11 @@ def create_group(group_name, path=None, region=None, key=None, keyid=None,
conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
try:
conn.create_group(group_name, path)
log.info('Created group : {0}.'.format(group_name))
log.info('Created IAM group : %s.', group_name)
return True
except boto.exception.BotoServerError as e:
log.debug(e)
msg = 'Failed to create group {0}.'
log.error(msg.format(group_name))
log.error('Failed to create IAM group %s.', group_name)
return False
@ -406,8 +400,7 @@ def get_group(group_name, region=None, key=None, keyid=None, profile=None):
return info['get_group_response']['get_group_result']['group']
except boto.exception.BotoServerError as e:
log.debug(e)
msg = 'Failed to get group {0} info.'
log.error(msg.format(group_name))
log.error('Failed to get IAM group %s info.', group_name)
return False
@ -442,8 +435,7 @@ def get_group_members(group_name, region=None, key=None, keyid=None, profile=Non
return users
except boto.exception.BotoServerError as e:
log.debug(e)
msg = 'Failed to get group {0} members.'
log.error(msg.format(group_name))
log.error('Failed to get members for IAM group %s.', group_name)
return False
@ -462,8 +454,7 @@ def add_user_to_group(user_name, group_name, region=None, key=None, keyid=None,
'''
user = get_user(user_name, region, key, keyid, profile)
if not user:
msg = 'Username : {0} does not exist.'
log.error(msg.format(user_name, group_name))
log.error('Username : %s does not exist.', user_name)
return False
if user_exists_in_group(user_name, group_name, region=region, key=key,
keyid=keyid, profile=profile):
@ -476,8 +467,7 @@ def add_user_to_group(user_name, group_name, region=None, key=None, keyid=None,
return info
except boto.exception.BotoServerError as e:
log.debug(e)
msg = 'Failed to add user {0} to group {1}.'
log.error(msg.format(user_name, group_name))
log.error('Failed to add IAM user %s to group %s.', user_name, group_name)
return False
@ -502,8 +492,7 @@ def user_exists_in_group(user_name, group_name, region=None, key=None, keyid=Non
if users:
for _user in users:
if user_name == _user['user_name']:
msg = 'Username : {0} is already in group {1}.'
log.info(msg.format(user_name, group_name))
log.debug('IAM user %s is already in IAM group %s.', user_name, group_name)
return True
return False
@ -523,8 +512,7 @@ def remove_user_from_group(group_name, user_name, region=None, key=None, keyid=N
'''
user = get_user(user_name, region, key, keyid, profile)
if not user:
msg = 'Username : {0} does not exist.'
log.error(msg.format(user_name, group_name))
log.error('IAM user %s does not exist.', user_name)
return False
if not user_exists_in_group(user_name, group_name, region=region, key=key,
keyid=keyid, profile=profile):
@ -537,8 +525,7 @@ def remove_user_from_group(group_name, user_name, region=None, key=None, keyid=N
return info
except boto.exception.BotoServerError as e:
log.debug(e)
msg = 'Failed to remove user {0} from group {1}.'
log.error(msg.format(user_name, group_name))
log.error('Failed to remove IAM user %s from group %s', user_name, group_name)
return False
@ -558,23 +545,21 @@ def put_group_policy(group_name, policy_name, policy_json, region=None, key=None
group = get_group(group_name, region=region, key=key, keyid=keyid,
profile=profile)
if not group:
log.error('Group {0} does not exist'.format(group_name))
log.error('Group %s does not exist', group_name)
return False
conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
try:
if not isinstance(policy_json, six.string_types):
policy_json = json.dumps(policy_json)
policy_json = salt.utils.json.dumps(policy_json)
created = conn.put_group_policy(group_name, policy_name,
policy_json)
if created:
log.info('Created policy for group {0}.'.format(group_name))
log.info('Created policy for IAM group %s.', group_name)
return True
msg = 'Could not create policy for group {0}'
log.error(msg.format(group_name))
log.error('Could not create policy for IAM group %s', group_name)
except boto.exception.BotoServerError as e:
log.debug(e)
msg = 'Failed to create policy for group {0}'
log.error(msg.format(group_name))
log.error('Failed to create policy for IAM group %s', group_name)
return False
@ -599,13 +584,11 @@ def delete_group_policy(group_name, policy_name, region=None, key=None,
return True
try:
conn.delete_group_policy(group_name, policy_name)
msg = 'Successfully deleted {0} policy for group {1}.'
log.info(msg.format(policy_name, group_name))
log.info('Successfully deleted policy %s for IAM group %s.', policy_name, group_name)
return True
except boto.exception.BotoServerError as e:
log.debug(e)
msg = 'Failed to delete {0} policy for group {1}.'
log.error(msg.format(policy_name, group_name))
log.error('Failed to delete policy %s for IAM group %s.', policy_name, group_name)
return False
@ -625,17 +608,16 @@ def get_group_policy(group_name, policy_name, region=None, key=None,
conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
try:
info = conn.get_group_policy(group_name, policy_name)
log.debug('info for group policy is : {0}'.format(info))
log.debug('info for group policy is : %s', info)
if not info:
return False
info = info.get_group_policy_response.get_group_policy_result.policy_document
info = _unquote(info)
info = json.loads(info, object_pairs_hook=odict.OrderedDict)
info = salt.utils.json.loads(info, object_pairs_hook=odict.OrderedDict)
return info
except boto.exception.BotoServerError as e:
log.debug(e)
msg = 'Failed to get group {0} info.'
log.error(msg.format(group_name))
log.error('Failed to get IAM group %s info.', group_name)
return False
@ -750,13 +732,11 @@ def delete_group(group_name, region=None, key=None,
return True
try:
conn.delete_group(group_name)
msg = 'Successfully deleted group {0}.'
log.info(msg.format(group_name))
log.info('Successfully deleted IAM group %s.', group_name)
return True
except boto.exception.BotoServerError as e:
log.debug(e)
msg = 'Failed to delete group {0}.'
log.error(msg.format(group_name))
log.error('Failed to delete IAM group %s.', group_name)
return False
@ -776,21 +756,19 @@ def create_login_profile(user_name, password, region=None, key=None,
'''
user = get_user(user_name, region, key, keyid, profile)
if not user:
msg = 'Username {0} does not exist'
log.error(msg.format(user_name))
log.error('IAM user %s does not exist', user_name)
return False
conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
try:
info = conn.create_login_profile(user_name, password)
log.info('Created profile for user {0}.'.format(user_name))
log.info('Created profile for IAM user %s.', user_name)
return info
except boto.exception.BotoServerError as e:
log.debug(e)
if 'Conflict' in e:
log.info('Profile already exists for user {0}.'.format(user_name))
log.info('Profile already exists for IAM user %s.', user_name)
return 'Conflict'
msg = 'Failed to update profile for user {0}.'
log.error(msg.format(user_name))
log.error('Failed to update profile for IAM user %s.', user_name)
return False
@ -809,21 +787,19 @@ def delete_login_profile(user_name, region=None, key=None, keyid=None,
'''
user = get_user(user_name, region, key, keyid, profile)
if not user:
msg = 'Username {0} does not exist'
log.error(msg.format(user_name))
log.error('IAM user %s does not exist', user_name)
return False
conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
try:
info = conn.delete_login_profile(user_name)
log.info('Deleted login profile for user {0}.'.format(user_name))
log.info('Deleted login profile for IAM user %s.', user_name)
return True
except boto.exception.BotoServerError as e:
log.debug(e)
if 'Not Found' in e:
log.info('Login profile already deleted for user {0}.'.format(user_name))
log.info('Login profile already deleted for IAM user %s.', user_name)
return True
msg = 'Failed to delete login profile for user {0}.'
log.error(msg.format(user_name))
log.error('Failed to delete login profile for IAM user %s.', user_name)
return False
@ -842,8 +818,7 @@ def get_all_mfa_devices(user_name, region=None, key=None, keyid=None,
'''
user = get_user(user_name, region, key, keyid, profile)
if not user:
msg = 'Username {0} does not exist'
log.error(msg.format(user_name))
log.error('IAM user %s does not exist', user_name)
return False
conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
try:
@ -853,10 +828,9 @@ def get_all_mfa_devices(user_name, region=None, key=None, keyid=None,
except boto.exception.BotoServerError as e:
log.debug(e)
if 'Not Found' in e:
log.info('Could not find user {0}.'.format(user_name))
log.info('Could not find IAM user %s.', user_name)
return []
msg = 'Failed to get all MFA devices for user {0}.'
log.error(msg.format(user_name))
log.error('Failed to get all MFA devices for IAM user %s.', user_name)
return False
@ -876,21 +850,19 @@ def deactivate_mfa_device(user_name, serial, region=None, key=None, keyid=None,
'''
user = get_user(user_name, region, key, keyid, profile)
if not user:
msg = 'Username {0} does not exist'
log.error(msg.format(user_name))
log.error('IAM user %s does not exist', user_name)
return False
conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
try:
conn.deactivate_mfa_device(user_name, serial)
log.info('Deactivated MFA device {1} for user {0}.'.format(user_name, serial))
log.info('Deactivated MFA device %s for IAM user %s.', serial, user_name)
return True
except boto.exception.BotoServerError as e:
log.debug(e)
if 'Not Found' in e:
log.info('MFA device {1} not associated with user {0}.'.format(user_name, serial))
log.info('MFA device %s not associated with IAM user %s.', serial, user_name)
return True
msg = 'Failed to deactivate MFA device {1} for user {0}.'
log.error(msg.format(user_name, serial))
log.error('Failed to deactivate MFA device %s for IAM user %s.', serial, user_name)
return False
@ -907,15 +879,14 @@ def delete_virtual_mfa_device(serial, region=None, key=None, keyid=None, profile
conn = __utils__['boto3.get_connection_func']('iam')()
try:
conn.delete_virtual_mfa_device(SerialNumber=serial)
log.info('Deleted virtual MFA device {0}.'.format(serial))
log.info('Deleted virtual MFA device %s.', serial)
return True
except botocore.exceptions.ClientError as e:
log.debug(e)
if 'NoSuchEntity' in str(e):
log.info('Virtual MFA device {0} not found.'.format(serial))
if 'NoSuchEntity' in six.text_type(e):
log.info('Virtual MFA device %s not found.', serial)
return True
msg = 'Failed to delete virtual MFA device {0}.'
log.error(msg.format(serial))
log.error('Failed to delete virtual MFA device %s.', serial)
return False
@ -1000,12 +971,11 @@ def create_role(name, policy_document=None, path=None, region=None, key=None,
try:
conn.create_role(name, assume_role_policy_document=policy_document,
path=path)
log.info('Created {0} iam role.'.format(name))
log.info('Created IAM role %s.', name)
return True
except boto.exception.BotoServerError as e:
log.error(e)
msg = 'Failed to create {0} iam role.'
log.error(msg.format(name))
log.error('Failed to create IAM role %s.', name)
return False
@ -1025,12 +995,11 @@ def delete_role(name, region=None, key=None, keyid=None, profile=None):
return True
try:
conn.delete_role(name)
log.info('Deleted {0} iam role.'.format(name))
log.info('Deleted %s IAM role.', name)
return True
except boto.exception.BotoServerError as e:
log.debug(e)
msg = 'Failed to delete {0} iam role.'
log.error(msg.format(name))
log.error('Failed to delete %s IAM role.', name)
return False
@ -1076,10 +1045,10 @@ def associate_profile_to_role(profile_name, role_name, region=None, key=None,
conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
if not role_exists(role_name, region, key, keyid, profile):
log.error('IAM role {0} does not exist.'.format(role_name))
log.error('IAM role %s does not exist.', role_name)
return False
if not instance_profile_exists(profile_name, region, key, keyid, profile):
log.error('Instance profile {0} does not exist.'.format(profile_name))
log.error('Instance profile %s does not exist.', profile_name)
return False
associated = profile_associated(role_name, profile_name, region, key, keyid, profile)
if associated:
@ -1087,13 +1056,11 @@ def associate_profile_to_role(profile_name, role_name, region=None, key=None,
else:
try:
conn.add_role_to_instance_profile(profile_name, role_name)
msg = 'Added {0} instance profile to {1} role.'
log.info(msg.format(profile_name, role_name))
log.info('Added %s instance profile to IAM role %s.', profile_name, role_name)
return True
except boto.exception.BotoServerError as e:
log.debug(e)
msg = 'Failed to add {0} instance profile to {1} role.'
log.error(msg.format(profile_name, role_name))
log.error('Failed to add %s instance profile to IAM role %s', profile_name, role_name)
return False
@ -1111,10 +1078,10 @@ def disassociate_profile_from_role(profile_name, role_name, region=None,
conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
if not role_exists(role_name, region, key, keyid, profile):
log.error('IAM role {0} does not exist.'.format(role_name))
log.error('IAM role %s does not exist.', role_name)
return False
if not instance_profile_exists(profile_name, region, key, keyid, profile):
log.error('Instance profile {0} does not exist.'.format(profile_name))
log.error('Instance profile %s does not exist.', profile_name)
return False
associated = profile_associated(role_name, profile_name, region, key, keyid, profile)
if not associated:
@ -1122,13 +1089,11 @@ def disassociate_profile_from_role(profile_name, role_name, region=None,
else:
try:
conn.remove_role_from_instance_profile(profile_name, role_name)
msg = 'Removed {0} instance profile from {1} role.'
log.info(msg.format(profile_name, role_name))
log.info('Removed %s instance profile from IAM role %s.', profile_name, role_name)
return True
except boto.exception.BotoServerError as e:
log.debug(e)
msg = 'Failed to remove {0} instance profile from {1} role.'
log.error(msg.format(profile_name, role_name))
log.error('Failed to remove %s instance profile from IAM role %s.', profile_name, role_name)
return False
@ -1173,7 +1138,7 @@ def get_role_policy(role_name, policy_name, region=None, key=None,
_policy = _policy.get_role_policy_response.policy_document
# Policy is url encoded
_policy = _unquote(_policy)
_policy = json.loads(_policy, object_pairs_hook=odict.OrderedDict)
_policy = salt.utils.json.loads(_policy, object_pairs_hook=odict.OrderedDict)
return _policy
except boto.exception.BotoServerError:
return {}
@ -1199,20 +1164,20 @@ def create_role_policy(role_name, policy_name, policy, region=None, key=None,
return True
mode = 'modify'
if isinstance(policy, six.string_types):
policy = json.loads(policy, object_pairs_hook=odict.OrderedDict)
policy = salt.utils.json.loads(policy, object_pairs_hook=odict.OrderedDict)
try:
_policy = json.dumps(policy)
_policy = salt.utils.json.dumps(policy)
conn.put_role_policy(role_name, policy_name, _policy)
if mode == 'create':
msg = 'Successfully added {0} policy to {1} role.'
msg = 'Successfully added policy %s to IAM role %s.'
else:
msg = 'Successfully modified {0} policy for role {1}.'
log.info(msg.format(policy_name, role_name))
msg = 'Successfully modified policy %s for IAM role %s.'
log.info(msg, policy_name, role_name)
return True
except boto.exception.BotoServerError as e:
log.error(e)
msg = 'Failed to {0} {1} policy for role {2}.'
log.error(msg.format(mode, policy_name, role_name))
log.error('Failed to %s policy %s for IAM role %s.',
mode, policy_name, role_name)
return False
@ -1234,13 +1199,13 @@ def delete_role_policy(role_name, policy_name, region=None, key=None,
return True
try:
conn.delete_role_policy(role_name, policy_name)
msg = 'Successfully deleted {0} policy for role {1}.'
log.info(msg.format(policy_name, role_name))
log.info('Successfully deleted policy %s for IAM role %s.',
policy_name, role_name)
return True
except boto.exception.BotoServerError as e:
log.debug(e)
msg = 'Failed to delete {0} policy for role {1}.'
log.error(msg.format(policy_name, role_name))
log.error('Failed to delete policy %s for IAM role %s.',
policy_name, role_name)
return False
@ -1260,18 +1225,16 @@ def update_assume_role_policy(role_name, policy_document, region=None,
conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
if isinstance(policy_document, six.string_types):
policy_document = json.loads(policy_document,
policy_document = salt.utils.json.loads(policy_document,
object_pairs_hook=odict.OrderedDict)
try:
_policy_document = json.dumps(policy_document)
_policy_document = salt.utils.json.dumps(policy_document)
conn.update_assume_role_policy(role_name, _policy_document)
msg = 'Successfully updated assume role policy for role {0}.'
log.info(msg.format(role_name))
log.info('Successfully updated assume role policy for IAM role %s.', role_name)
return True
except boto.exception.BotoServerError as e:
log.error(e)
msg = 'Failed to update assume role policy for role {0}.'
log.error(msg.format(role_name))
log.error('Failed to update assume role policy for IAM role %s.', role_name)
return False
@ -1289,9 +1252,9 @@ def build_policy(region=None, key=None, keyid=None, profile=None):
'''
conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
if hasattr(conn, 'build_policy'):
policy = json.loads(conn.build_policy())
policy = salt.utils.json.loads(conn.build_policy())
elif hasattr(conn, '_build_policy'):
policy = json.loads(conn._build_policy())
policy = salt.utils.json.loads(conn._build_policy())
else:
return {}
# The format we get from build_policy isn't going to be what we get back
@ -1416,7 +1379,7 @@ def get_all_user_policies(user_name, marker=None, max_items=None, region=None, k
.. code-block:: bash
salt myminion boto_iam.get_group mygroup
salt myminion boto_iam.get_all_user_policies myuser
'''
conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
try:
@ -1427,8 +1390,7 @@ def get_all_user_policies(user_name, marker=None, max_items=None, region=None, k
return _list.policy_names
except boto.exception.BotoServerError as e:
log.debug(e)
msg = 'Failed to get user {0} policy.'
log.error(msg.format(user_name))
log.error('Failed to get policies for user %s.', user_name)
return False
@ -1447,17 +1409,16 @@ def get_user_policy(user_name, policy_name, region=None, key=None, keyid=None, p
conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
try:
info = conn.get_user_policy(user_name, policy_name)
log.debug('Info for user policy is : {0}.'.format(info))
log.debug('Info for IAM user %s policy %s: %s.', user_name, policy_name, info)
if not info:
return False
info = info.get_user_policy_response.get_user_policy_result.policy_document
info = _unquote(info)
info = json.loads(info, object_pairs_hook=odict.OrderedDict)
info = salt.utils.json.loads(info, object_pairs_hook=odict.OrderedDict)
return info
except boto.exception.BotoServerError as e:
log.debug(e)
msg = 'Failed to get user {0} policy.'
log.error(msg.format(user_name))
log.error('Failed to get policy %s for IAM user %s.', policy_name, user_name)
return False
@ -1475,23 +1436,21 @@ def put_user_policy(user_name, policy_name, policy_json, region=None, key=None,
'''
user = get_user(user_name, region, key, keyid, profile)
if not user:
log.error('User {0} does not exist'.format(user_name))
log.error('IAM user %s does not exist', user_name)
return False
conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
try:
if not isinstance(policy_json, six.string_types):
policy_json = json.dumps(policy_json)
policy_json = salt.utils.json.dumps(policy_json)
created = conn.put_user_policy(user_name, policy_name,
policy_json)
if created:
log.info('Created policy for user {0}.'.format(user_name))
log.info('Created policy %s for IAM user %s.', policy_name, user_name)
return True
msg = 'Could not create policy for user {0}.'
log.error(msg.format(user_name))
log.error('Could not create policy %s for IAM user %s.', policy_name, user_name)
except boto.exception.BotoServerError as e:
log.debug(e)
msg = 'Failed to create policy for user {0}.'
log.error(msg.format(user_name))
log.error('Failed to create policy %s for IAM user %s.', policy_name, user_name)
return False
@ -1515,13 +1474,11 @@ def delete_user_policy(user_name, policy_name, region=None, key=None, keyid=None
return True
try:
conn.delete_user_policy(user_name, policy_name)
msg = 'Successfully deleted {0} policy for user {1}.'
log.info(msg.format(policy_name, user_name))
log.info('Successfully deleted policy %s for IAM user %s.', policy_name, user_name)
return True
except boto.exception.BotoServerError as e:
log.debug(e)
msg = 'Failed to delete {0} policy for user {1}.'
log.error(msg.format(policy_name, user_name))
log.error('Failed to delete policy %s for IAM user %s.', policy_name, user_name)
return False
@ -1556,12 +1513,11 @@ def upload_server_cert(cert_name, cert_body, private_key, cert_chain=None, path=
conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
try:
info = conn.upload_server_cert(cert_name, cert_body, private_key, cert_chain)
log.info('Created certificate {0}.'.format(cert_name))
log.info('Created certificate %s.', cert_name)
return info
except boto.exception.BotoServerError as e:
log.debug(e)
msg = 'Failed to failed to create certificate {0}.'
log.error(msg.format(cert_name))
log.error('Failed to failed to create certificate %s.', cert_name)
return False
@ -1585,8 +1541,7 @@ def get_server_certificate(cert_name, region=None, key=None, keyid=None, profile
return info
except boto.exception.BotoServerError as e:
log.debug(e)
msg = 'Failed to get certificate {0} information.'
log.error(msg.format(cert_name))
log.error('Failed to get certificate %s information.', cert_name)
return False
@ -1607,8 +1562,7 @@ def delete_server_cert(cert_name, region=None, key=None, keyid=None, profile=Non
return conn.delete_server_cert(cert_name)
except boto.exception.BotoServerError as e:
log.debug(e)
msg = 'Failed to delete certificate {0}.'
log.error(msg.format(cert_name))
log.error('Failed to delete certificate %s.', cert_name)
return False
@ -1651,7 +1605,7 @@ def export_users(path_prefix='/', region=None, key=None, keyid=None,
policies = {}
for policy_name in _policies:
_policy = conn.get_user_policy(name, policy_name)
_policy = json.loads(_unquote(
_policy = salt.utils.json.loads(_unquote(
_policy.get_user_policy_response.get_user_policy_result.policy_document
))
policies[policy_name] = _policy
@ -1684,14 +1638,14 @@ def export_roles(path_prefix='/', region=None, key=None, keyid=None, profile=Non
policies = {}
for policy_name in _policies:
_policy = conn.get_role_policy(name, policy_name)
_policy = json.loads(_unquote(
_policy = salt.utils.json.loads(_unquote(
_policy.get_role_policy_response.get_role_policy_result.policy_document
))
policies[policy_name] = _policy
role_sls = []
role_sls.append({"name": name})
role_sls.append({"policies": policies})
role_sls.append({'policy_document': json.loads(_unquote(role.assume_role_policy_document))})
role_sls.append({'policy_document': salt.utils.json.loads(_unquote(role.assume_role_policy_document))})
role_sls.append({"path": role.path})
results["manage role " + name] = {"boto_iam_role.present": role_sls}
return _safe_dump(results)
@ -1763,7 +1717,7 @@ def create_policy(policy_name, policy_document, path=None, description=None,
conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
if not isinstance(policy_document, six.string_types):
policy_document = json.dumps(policy_document)
policy_document = salt.utils.json.dumps(policy_document)
params = {}
for arg in 'path', 'description':
if locals()[arg] is not None:
@ -1772,11 +1726,10 @@ def create_policy(policy_name, policy_document, path=None, description=None,
return True
try:
conn.create_policy(policy_name, policy_document, **params)
log.info('Created {0} policy.'.format(policy_name))
log.info('Created IAM policy %s.', policy_name)
except boto.exception.BotoServerError as e:
log.debug(e)
msg = 'Failed to create {0} policy.'
log.error(msg.format(policy_name))
log.error('Failed to create IAM policy %s.', policy_name)
return False
return True
@ -1799,12 +1752,11 @@ def delete_policy(policy_name,
return True
try:
conn.delete_policy(policy_arn)
log.info('Deleted {0} policy.'.format(policy_name))
log.info('Deleted %s policy.', policy_name)
except boto.exception.BotoServerError as e:
aws = __utils__['boto.get_error'](e)
log.debug(aws)
msg = 'Failed to delete {0} policy: {1}.'
log.error(msg.format(policy_name, aws.get('message')))
log.error('Failed to delete %s policy: %s.', policy_name, aws.get('message'))
return False
return True
@ -1891,7 +1843,7 @@ def create_policy_version(policy_name, policy_document, set_as_default=None,
conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
if not isinstance(policy_document, six.string_types):
policy_document = json.dumps(policy_document)
policy_document = salt.utils.json.dumps(policy_document)
params = {}
for arg in ('set_as_default',):
if locals()[arg] is not None:
@ -1900,12 +1852,11 @@ def create_policy_version(policy_name, policy_document, set_as_default=None,
try:
ret = conn.create_policy_version(policy_arn, policy_document, **params)
vid = ret.get('create_policy_version_response', {}).get('create_policy_version_result', {}).get('policy_version', {}).get('version_id')
log.info('Created {0} policy version {1}.'.format(policy_name, vid))
log.info('Created IAM policy %s version %s.', policy_name, vid)
return {'created': True, 'version_id': vid}
except boto.exception.BotoServerError as e:
log.debug(e)
msg = 'Failed to create {0} policy version.'
log.error(msg.format(policy_name))
log.error('Failed to create IAM policy %s version %s.', policy_name, vid)
return {'created': False, 'error': __utils__['boto.get_error'](e)}
@ -1927,12 +1878,12 @@ def delete_policy_version(policy_name, version_id,
return True
try:
conn.delete_policy_version(policy_arn, version_id)
log.info('Deleted {0} policy version {1}.'.format(policy_name, version_id))
log.info('Deleted IAM policy %s version %s.', policy_name, version_id)
except boto.exception.BotoServerError as e:
aws = __utils__['boto.get_error'](e)
log.debug(aws)
msg = 'Failed to delete {0} policy version {1}: {2}'
log.error(msg.format(policy_name, version_id, aws.get('message')))
log.error('Failed to delete IAM policy %s version %s: %s',
policy_name, version_id, aws.get('message'))
return False
return True
@ -1956,8 +1907,7 @@ def list_policy_versions(policy_name,
return ret.get('list_policy_versions_response', {}).get('list_policy_versions_result', {}).get('versions')
except boto.exception.BotoServerError as e:
log.debug(e)
msg = 'Failed to list {0} policy versions.'
log.error(msg.format(policy_name))
log.error('Failed to list versions for IAM policy %s.', policy_name)
return []
@ -1977,12 +1927,12 @@ def set_default_policy_version(policy_name, version_id,
policy_arn = _get_policy_arn(policy_name, region, key, keyid, profile)
try:
conn.set_default_policy_version(policy_arn, version_id)
log.info('Set {0} policy to version {1}.'.format(policy_name, version_id))
log.info('Set %s policy to version %s.', policy_name, version_id)
except boto.exception.BotoServerError as e:
aws = __utils__['boto.get_error'](e)
log.debug(aws)
msg = 'Failed to set {0} policy to version {1}: {2}'
log.error(msg.format(policy_name, version_id, aws.get('message')))
log.error('Failed to set %s policy to version %s: %s',
policy_name, version_id, aws.get('message'))
return False
return True
@ -2003,11 +1953,10 @@ def attach_user_policy(policy_name, user_name,
policy_arn = _get_policy_arn(policy_name, region, key, keyid, profile)
try:
conn.attach_user_policy(policy_arn, user_name)
log.info('Attached {0} policy to user {1}.'.format(policy_name, user_name))
log.info('Attached policy %s to IAM user %s.', policy_name, user_name)
except boto.exception.BotoServerError as e:
log.debug(e)
msg = 'Failed to attach {0} policy to user {1}.'
log.error(msg.format(policy_name, user_name))
log.error('Failed to attach %s policy to IAM user %s.', policy_name, user_name)
return False
return True
@ -2028,11 +1977,10 @@ def detach_user_policy(policy_name, user_name,
policy_arn = _get_policy_arn(policy_name, region, key, keyid, profile)
try:
conn.detach_user_policy(policy_arn, user_name)
log.info('Detached {0} policy to user {1}.'.format(policy_name, user_name))
log.info('Detached %s policy from IAM user %s.', policy_name, user_name)
except boto.exception.BotoServerError as e:
log.debug(e)
msg = 'Failed to detach {0} policy to user {1}.'
log.error(msg.format(policy_name, user_name))
log.error('Failed to detach %s policy from IAM user %s.', policy_name, user_name)
return False
return True
@ -2053,11 +2001,10 @@ def attach_group_policy(policy_name, group_name,
policy_arn = _get_policy_arn(policy_name, region, key, keyid, profile)
try:
conn.attach_group_policy(policy_arn, group_name)
log.info('Attached {0} policy to group {1}.'.format(policy_name, group_name))
log.info('Attached policy %s to IAM group %s.', policy_name, group_name)
except boto.exception.BotoServerError as e:
log.debug(e)
msg = 'Failed to attach {0} policy to group {1}.'
log.error(msg.format(policy_name, group_name))
log.error('Failed to attach policy %s to IAM group %s.', policy_name, group_name)
return False
return True
@ -2078,11 +2025,10 @@ def detach_group_policy(policy_name, group_name,
policy_arn = _get_policy_arn(policy_name, region, key, keyid, profile)
try:
conn.detach_group_policy(policy_arn, group_name)
log.info('Detached {0} policy to group {1}.'.format(policy_name, group_name))
log.info('Detached policy %s from IAM group %s.', policy_name, group_name)
except boto.exception.BotoServerError as e:
log.debug(e)
msg = 'Failed to detach {0} policy to group {1}.'
log.error(msg.format(policy_name, group_name))
log.error('Failed to detach policy %s from IAM group %s.', policy_name, group_name)
return False
return True
@ -2103,11 +2049,10 @@ def attach_role_policy(policy_name, role_name,
policy_arn = _get_policy_arn(policy_name, region, key, keyid, profile)
try:
conn.attach_role_policy(policy_arn, role_name)
log.info('Attached {0} policy to role {1}.'.format(policy_name, role_name))
log.info('Attached policy %s to IAM role %s.', policy_name, role_name)
except boto.exception.BotoServerError as e:
log.debug(e)
msg = 'Failed to attach {0} policy to role {1}.'
log.error(msg.format(policy_name, role_name))
log.error('Failed to attach policy %s to IAM role %s.', policy_name, role_name)
return False
return True
@ -2128,11 +2073,10 @@ def detach_role_policy(policy_name, role_name,
policy_arn = _get_policy_arn(policy_name, region, key, keyid, profile)
try:
conn.detach_role_policy(policy_arn, role_name)
log.info('Detached {0} policy to role {1}.'.format(policy_name, role_name))
log.info('Detached policy %s from IAM role %s.', policy_name, role_name)
except boto.exception.BotoServerError as e:
log.debug(e)
msg = 'Failed to detach {0} policy to role {1}.'
log.error(msg.format(policy_name, role_name))
log.error('Failed to detach policy %s from IAM role %s.', policy_name, role_name)
return False
return True
@ -2174,7 +2118,7 @@ def list_entities_for_policy(policy_name, path_prefix=None, entity_filter=None,
time.sleep(5)
retries -= 1
continue
log.error('Failed to list {0} policy entities: {1}'.format(policy_name, e.message))
log.error('Failed to list entities for IAM policy %s: %s', policy_name, e.message)
return {}
return {}
@ -2206,8 +2150,7 @@ def list_attached_user_policies(user_name, path_prefix=None, entity_filter=None,
return policies
except boto.exception.BotoServerError as e:
log.debug(e)
msg = 'Failed to list user {0} attached policies.'
log.error(msg.format(user_name))
log.error('Failed to list attached policies for IAM user %s.', user_name)
return []
@ -2238,8 +2181,7 @@ def list_attached_group_policies(group_name, path_prefix=None, entity_filter=Non
return policies
except boto.exception.BotoServerError as e:
log.debug(e)
msg = 'Failed to list group {0} attached policies.'
log.error(msg.format(group_name))
log.error('Failed to list attached policies for IAM group %s.', group_name)
return []
@ -2270,8 +2212,7 @@ def list_attached_role_policies(role_name, path_prefix=None, entity_filter=None,
return policies
except boto.exception.BotoServerError as e:
log.debug(e)
msg = 'Failed to list role {0} attached policies.'
log.error(msg.format(role_name))
log.error('Failed to list attached policies for IAM role %s.', role_name)
return []
@ -2288,14 +2229,12 @@ def create_saml_provider(name, saml_metadata_document, region=None, key=None, ke
conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
try:
conn.create_saml_provider(saml_metadata_document, name)
msg = 'Successfully created {0} SAML provider.'
log.info(msg.format(name))
log.info('Successfully created %s SAML provider.', name)
return True
except boto.exception.BotoServerError as e:
aws = __utils__['boto.get_error'](e)
log.debug(aws)
msg = 'Failed to create SAML provider {0}.'
log.error(msg.format(name))
log.error('Failed to create SAML provider %s.', name)
return False
@ -2319,8 +2258,7 @@ def get_saml_provider_arn(name, region=None, key=None, keyid=None, profile=None)
except boto.exception.BotoServerError as e:
aws = __utils__['boto.get_error'](e)
log.debug(aws)
msg = 'Failed to get ARN of SAML provider {0}.'
log.error(msg.format(name))
log.error('Failed to get ARN of SAML provider %s.', name)
return False
@ -2338,18 +2276,15 @@ def delete_saml_provider(name, region=None, key=None, keyid=None, profile=None):
try:
saml_provider_arn = get_saml_provider_arn(name, region=region, key=key, keyid=keyid, profile=profile)
if not saml_provider_arn:
msg = 'SAML provider {0} not found.'
log.info(msg.format(name))
log.info('SAML provider %s not found.', name)
return True
conn.delete_saml_provider(saml_provider_arn)
msg = 'Successfully deleted {0} SAML provider.'
log.info(msg.format(name))
log.info('Successfully deleted SAML provider %s.', name)
return True
except boto.exception.BotoServerError as e:
aws = __utils__['boto.get_error'](e)
log.debug(aws)
msg = 'Failed to delete {0} SAML provider.'
log.error(msg.format(name))
log.error('Failed to delete SAML provider %s.', name)
return False
@ -2371,10 +2306,8 @@ def list_saml_providers(region=None, key=None, keyid=None, profile=None):
providers.append(arn['arn'].rsplit('/', 1)[1])
return providers
except boto.exception.BotoServerError as e:
aws = __utils__['boto.get_error'](e)
log.debug(aws)
msg = 'Failed to get list of SAML providers.'
log.error(msg)
log.debug(__utils__['boto.get_error'](e))
log.error('Failed to get list of SAML providers.')
return False
@ -2393,10 +2326,8 @@ def get_saml_provider(name, region=None, key=None, keyid=None, profile=None):
provider = conn.get_saml_provider(name)
return provider['get_saml_provider_response']['get_saml_provider_result']['saml_metadata_document']
except boto.exception.BotoServerError as e:
aws = __utils__['boto.get_error'](e)
log.debug(aws)
msg = 'Failed to get SAML provider document.'
log.error(msg)
log.debug(__utils__['boto.get_error'](e))
log.error('Failed to get SAML provider document %s.', name)
return False
@ -2414,15 +2345,12 @@ def update_saml_provider(name, saml_metadata_document, region=None, key=None, ke
try:
saml_provider_arn = get_saml_provider_arn(name, region=region, key=key, keyid=keyid, profile=profile)
if not saml_provider_arn:
msg = 'SAML provider {0} not found.'
log.info(msg.format(name))
log.info('SAML provider %s not found.', name)
return False
if conn.update_saml_provider(name, saml_metadata_document):
return True
return False
except boto.exception.BotoServerError as e:
aws = __utils__['boto.get_error'](e)
log.debug(aws)
msg = 'Failed to update of SAML provider.'
log.error(msg.format(name))
log.debug(__utils__['boto.get_error'](e))
log.error('Failed to update SAML provider %s.', name)
return False

View file

@ -52,12 +52,12 @@ The dependencies listed above can be installed via package or pip.
# Import Python libs
from __future__ import absolute_import
import logging
import json
import datetime
# Import Salt libs
import salt.utils.boto3
import salt.utils.compat
import salt.utils.json
from salt.utils.versions import LooseVersion as _LooseVersion
log = logging.getLogger(__name__)
@ -329,7 +329,7 @@ def create_policy(policyName, policyDocument,
try:
conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
if not isinstance(policyDocument, string_types):
policyDocument = json.dumps(policyDocument)
policyDocument = salt.utils.json.dumps(policyDocument)
policy = conn.create_policy(policyName=policyName,
policyDocument=policyDocument)
if policy:
@ -446,7 +446,7 @@ def create_policy_version(policyName, policyDocument, setAsDefault=False,
try:
conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
if not isinstance(policyDocument, string_types):
policyDocument = json.dumps(policyDocument)
policyDocument = salt.utils.json.dumps(policyDocument)
policy = conn.create_policy_version(policyName=policyName,
policyDocument=policyDocument,
setAsDefault=setAsDefault)

View file

@ -40,11 +40,11 @@ from __future__ import absolute_import
# Import Python libs
import logging
from salt.serializers import json
# Import Salt libs
import salt.utils.compat
import salt.utils.odict as odict
import salt.serializers.json
from salt.utils.versions import LooseVersion as _LooseVersion
log = logging.getLogger(__name__)
@ -146,7 +146,7 @@ def create_key(policy=None, description=None, key_usage=None, region=None,
conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
r = {}
_policy = json.serialize(policy)
_policy = salt.serializers.json.serialize(policy)
try:
key_metadata = conn.create_key(
_policy,
@ -432,7 +432,7 @@ def get_key_policy(key_id, policy_name, region=None, key=None, keyid=None,
r = {}
try:
key_policy = conn.get_key_policy(key_id, policy_name)
r['key_policy'] = json.deserialize(
r['key_policy'] = salt.serializers.json.deserialize(
key_policy['Policy'],
object_pairs_hook=odict.OrderedDict
)
@ -536,7 +536,7 @@ def put_key_policy(key_id, policy_name, policy, region=None, key=None,
r = {}
try:
conn.put_key_policy(key_id, policy_name, json.serialize(policy))
conn.put_key_policy(key_id, policy_name, salt.serializers.json.serialize(policy))
r['result'] = True
except boto.exception.BotoServerError as e:
r['result'] = False

View file

@ -82,7 +82,6 @@ The dependencies listed above can be installed via package or pip.
# Import Python libs
from __future__ import absolute_import
import logging
import json
import time
import random
@ -90,6 +89,7 @@ import random
from salt.ext import six
import salt.utils.compat
import salt.utils.files
import salt.utils.json
from salt.utils.versions import LooseVersion as _LooseVersion
from salt.exceptions import SaltInvocationError
from salt.ext.six.moves import range # pylint: disable=import-error
@ -207,7 +207,7 @@ def _filedata(infile):
def _resolve_vpcconfig(conf, region=None, key=None, keyid=None, profile=None):
if isinstance(conf, six.string_types):
conf = json.loads(conf)
conf = salt.utils.json.loads(conf)
if not conf:
return None
if not isinstance(conf, dict):
@ -583,7 +583,7 @@ def get_permissions(FunctionName, Qualifier=None,
**kwargs)
policy = policy.get('Policy', {})
if isinstance(policy, six.string_types):
policy = json.loads(policy)
policy = salt.utils.json.loads(policy)
if policy is None:
policy = {}
permissions = {}

View file

@ -54,12 +54,12 @@ The dependencies listed above can be installed via package or pip.
# Import Python libs
from __future__ import absolute_import
import logging
import json
# Import Salt libs
from salt.ext import six
from salt.ext.six.moves import range # pylint: disable=import-error
import salt.utils.compat
import salt.utils.json
from salt.exceptions import SaltInvocationError
from salt.utils.versions import LooseVersion as _LooseVersion
@ -227,7 +227,7 @@ def delete_objects(Bucket, Delete, MFA=None, RequestPayer=None,
'''
if isinstance(Delete, six.string_types):
Delete = json.loads(Delete)
Delete = salt.utils.json.loads(Delete)
if not isinstance(Delete, dict):
raise SaltInvocationError("Malformed Delete request.")
if 'Objects' not in Delete:
@ -483,7 +483,7 @@ def put_acl(Bucket,
kwargs = {}
if AccessControlPolicy is not None:
if isinstance(AccessControlPolicy, six.string_types):
AccessControlPolicy = json.loads(AccessControlPolicy)
AccessControlPolicy = salt.utils.json.loads(AccessControlPolicy)
kwargs['AccessControlPolicy'] = AccessControlPolicy
for arg in ('ACL',
'GrantFullControl',
@ -523,7 +523,7 @@ def put_cors(Bucket,
try:
conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
if CORSRules is not None and isinstance(CORSRules, six.string_types):
CORSRules = json.loads(CORSRules)
CORSRules = salt.utils.json.loads(CORSRules)
conn.put_bucket_cors(Bucket=Bucket, CORSConfiguration={'CORSRules': CORSRules})
return {'updated': True, 'name': Bucket}
except ClientError as e:
@ -558,7 +558,7 @@ def put_lifecycle_configuration(Bucket,
try:
conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
if Rules is not None and isinstance(Rules, six.string_types):
Rules = json.loads(Rules)
Rules = salt.utils.json.loads(Rules)
conn.put_bucket_lifecycle_configuration(Bucket=Bucket, LifecycleConfiguration={'Rules': Rules})
return {'updated': True, 'name': Bucket}
except ClientError as e:
@ -596,7 +596,7 @@ def put_logging(Bucket,
else:
logstatus = {}
if TargetGrants is not None and isinstance(TargetGrants, six.string_types):
TargetGrants = json.loads(TargetGrants)
TargetGrants = salt.utils.json.loads(TargetGrants)
conn.put_bucket_logging(Bucket=Bucket, BucketLoggingStatus=logstatus)
return {'updated': True, 'name': Bucket}
except ClientError as e:
@ -629,15 +629,15 @@ def put_notification_configuration(Bucket,
if TopicConfigurations is None:
TopicConfigurations = []
elif isinstance(TopicConfigurations, six.string_types):
TopicConfigurations = json.loads(TopicConfigurations)
TopicConfigurations = salt.utils.json.loads(TopicConfigurations)
if QueueConfigurations is None:
QueueConfigurations = []
elif isinstance(QueueConfigurations, six.string_types):
QueueConfigurations = json.loads(QueueConfigurations)
QueueConfigurations = salt.utils.json.loads(QueueConfigurations)
if LambdaFunctionConfigurations is None:
LambdaFunctionConfigurations = []
elif isinstance(LambdaFunctionConfigurations, six.string_types):
LambdaFunctionConfigurations = json.loads(LambdaFunctionConfigurations)
LambdaFunctionConfigurations = salt.utils.json.loads(LambdaFunctionConfigurations)
# TODO allow the user to use simple names & substitute ARNs for those names
conn.put_bucket_notification_configuration(Bucket=Bucket, NotificationConfiguration={
'TopicConfigurations': TopicConfigurations,
@ -670,7 +670,7 @@ def put_policy(Bucket, Policy,
if Policy is None:
Policy = '{}'
elif not isinstance(Policy, six.string_types):
Policy = json.dumps(Policy)
Policy = salt.utils.json.dumps(Policy)
conn.put_bucket_policy(Bucket=Bucket, Policy=Policy)
return {'updated': True, 'name': Bucket}
except ClientError as e:
@ -714,7 +714,7 @@ def put_replication(Bucket, Role, Rules,
if Rules is None:
Rules = []
elif isinstance(Rules, six.string_types):
Rules = json.loads(Rules)
Rules = salt.utils.json.loads(Rules)
conn.put_bucket_replication(Bucket=Bucket, ReplicationConfiguration={
'Role': Role,
'Rules': Rules
@ -838,7 +838,7 @@ def put_website(Bucket, ErrorDocument=None, IndexDocument=None,
val = locals()[key]
if val is not None:
if isinstance(val, six.string_types):
WebsiteConfiguration[key] = json.loads(val)
WebsiteConfiguration[key] = salt.utils.json.loads(val)
else:
WebsiteConfiguration[key] = val
conn.put_bucket_website(Bucket=Bucket,

View file

@ -48,7 +48,9 @@ from __future__ import absolute_import
# Import Python libs
import logging
import json
# Import Salt libs
import salt.utils.json
# Import 3rd-party libs
from salt.ext import six
@ -87,13 +89,13 @@ def _preprocess_attributes(attributes):
Pre-process incoming queue attributes before setting them
'''
if isinstance(attributes, six.string_types):
attributes = json.loads(attributes)
attributes = salt.utils.json.loads(attributes)
def stringified(val):
# Some attributes take full json policy documents, but they take them
# as json strings. Convert the value back into a json string.
if isinstance(val, dict):
return json.dumps(val)
return salt.utils.json.dumps(val)
return val
return dict(

View file

@ -11,11 +11,11 @@ available.
from __future__ import absolute_import
# Import python libs
import json
import logging
import shlex
# Import salt libs
import salt.utils.json
import salt.utils.path
from salt.exceptions import CommandExecutionError
from salt.utils.versions import LooseVersion as _LooseVersion
@ -129,7 +129,7 @@ def install(pkg,
raise CommandExecutionError(result['stderr'])
# If package is already installed, Bower will emit empty dict to STDOUT
stdout = json.loads(result['stdout'])
stdout = salt.utils.json.loads(result['stdout'])
return stdout != {}
@ -174,7 +174,7 @@ def uninstall(pkg, dir, runas=None, env=None):
raise CommandExecutionError(result['stderr'])
# If package is not installed, Bower will emit empty dict to STDOUT
stdout = json.loads(result['stdout'])
stdout = salt.utils.json.loads(result['stdout'])
return stdout != {}
@ -214,7 +214,7 @@ def list_(dir, runas=None, env=None):
if result['retcode'] != 0:
raise CommandExecutionError(result['stderr'])
return json.loads(result['stdout'])['dependencies']
return salt.utils.json.loads(result['stdout'])['dependencies']
def prune(dir, runas=None, env=None):
@ -255,4 +255,4 @@ def prune(dir, runas=None, env=None):
raise CommandExecutionError(result['stderr'])
# Bower returns an empty dictionary if nothing was pruned
return json.loads(result['stdout'])
return salt.utils.json.loads(result['stdout'])

View file

@ -83,19 +83,19 @@ queries based on the internal schema of said version.
# Import Python Libs
from __future__ import absolute_import
import logging
import json
import re
import ssl
# Import Salt Libs
import salt.utils.json
from salt.exceptions import CommandExecutionError
# Import 3rd-party libs
from salt.ext import six
from salt.ext.six.moves import range
SSL_VERSION = 'ssl_version'
SSL_VERSION = 'ssl_version'
log = logging.getLogger(__name__)
__virtualname__ = 'cassandra_cql'
@ -728,7 +728,7 @@ def create_keyspace(keyspace, replication_strategy='SimpleStrategy', replication
if replication_datacenters:
if isinstance(replication_datacenters, six.string_types):
try:
replication_datacenter_map = json.loads(replication_datacenters)
replication_datacenter_map = salt.utils.json.loads(replication_datacenters)
replication_map.update(**replication_datacenter_map)
except BaseException: # pylint: disable=W0703
log.error("Could not load json replication_datacenters.")

View file

@ -8,9 +8,9 @@ Currently this only works when run through a proxy minion.
'''
from __future__ import absolute_import
import json
import logging
import salt.utils.http
import salt.utils.json
import salt.utils.platform
from salt.exceptions import get_error_message
@ -105,7 +105,7 @@ def update_job(name, config):
'''
if 'name' not in config:
config['name'] = name
data = json.dumps(config)
data = salt.utils.json.dumps(config)
try:
response = salt.utils.http.query(
"{0}/scheduler/iso8601".format(_base_url()),

View file

@ -10,7 +10,6 @@ from __future__ import absolute_import, print_function, unicode_literals
# Import python libs
import functools
import glob
import json
import logging
import os
import shutil
@ -27,6 +26,7 @@ import tempfile
import salt.utils.args
import salt.utils.data
import salt.utils.files
import salt.utils.json
import salt.utils.path
import salt.utils.platform
import salt.utils.powershell
@ -3272,7 +3272,7 @@ def powershell(cmd,
**kwargs)
try:
return json.loads(response)
return salt.utils.json.loads(response)
except Exception:
log.error("Error converting PowerShell JSON return", exc_info=True)
return {}
@ -3578,7 +3578,7 @@ def powershell_all(cmd,
# If we fail to parse stdoutput we will raise an exception
try:
result = json.loads(stdoutput)
result = salt.utils.json.loads(stdoutput)
except Exception:
err_msg = "cmd.powershell_all " + \
"cannot parse the Powershell output."

View file

@ -8,6 +8,12 @@ https://www.consul.io
# Import Python Libs
from __future__ import absolute_import
import base64
import logging
# Import salt libs
import salt.utils.http
import salt.utils.json
# Import 3rd-party libs
# pylint: disable=import-error,no-name-in-module,redefined-builtin
@ -16,13 +22,6 @@ import salt.ext.six
import salt.ext.six.moves.http_client
# pylint: enable=import-error,no-name-in-module
# Import salt libs
import salt.utils.http
import base64
import json
import logging
log = logging.getLogger(__name__)
from salt.exceptions import SaltInvocationError
@ -84,7 +83,7 @@ def _query(function,
if data is None:
data = {}
data = json.dumps(data)
data = salt.utils.json.dumps(data)
result = salt.utils.http.query(
url,

View file

@ -26,7 +26,6 @@ Support for RFC 2136 dynamic DNS updates.
from __future__ import absolute_import
# Import python libs
import logging
import json
log = logging.getLogger(__name__)
@ -40,6 +39,7 @@ except ImportError as e:
dns_support = False
import salt.utils.files
import salt.utils.json
def __virtual__():
@ -71,7 +71,7 @@ def _get_keyring(keyfile):
keyring = None
if keyfile:
with salt.utils.files.fopen(keyfile) as _f:
keyring = dns.tsigkeyring.from_text(json.load(_f))
keyring = dns.tsigkeyring.from_text(salt.utils.json.load(_f))
return keyring

View file

@ -6,7 +6,6 @@ Module to work with salt formula defaults files
from __future__ import absolute_import
import copy
import json
import logging
import os
import yaml
@ -15,6 +14,7 @@ import salt.fileclient
import salt.utils.data
import salt.utils.dictupdate as dictupdate
import salt.utils.files
import salt.utils.json
import salt.utils.url
@ -57,9 +57,9 @@ def _load(formula):
suffix = file_.rsplit('.', 1)[-1]
if suffix == 'yaml':
loader = yaml
loader = yaml.safe_load
elif suffix == 'json':
loader = json
loader = salt.utils.json.load
else:
log.debug("Failed to determine loader for %r", file_)
continue
@ -67,7 +67,7 @@ def _load(formula):
if os.path.exists(file_):
log.debug("Reading defaults from %r", file_)
with salt.utils.files.fopen(file_) as fhr:
defaults = loader.load(fhr)
defaults = loader(fhr)
log.debug("Read defaults %r", defaults)
return defaults or {}

View file

@ -212,6 +212,7 @@ from salt.ext.six.moves import map # pylint: disable=import-error,redefined-bui
import salt.utils.docker.translate.container
import salt.utils.docker.translate.network
import salt.utils.functools
import salt.utils.json
import salt.utils.path
import salt.pillar
import salt.exceptions
@ -357,7 +358,7 @@ def _get_client(timeout=NOTSET, **kwargs):
python_shell=False)
try:
docker_machine_json = \
json.loads(__utils__['stringutils.to_str'](docker_machine_json))
salt.utils.json.loads(docker_machine_json)
docker_machine_tls = \
docker_machine_json['HostOptions']['AuthOptions']
docker_machine_ip = docker_machine_json['Driver']['IPAddress']
@ -3971,12 +3972,7 @@ def build(path=None,
stream_data = []
for line in response:
stream_data.extend(
json.loads(
__utils__['stringutils.to_str'](line),
cls=DockerJSONDecoder
)
)
stream_data.extend(salt.utils.json.loads(line, cls=DockerJSONDecoder))
errors = []
# Iterate through API response and collect information
for item in stream_data:
@ -4511,7 +4507,7 @@ def pull(image,
for event in response:
log.debug('pull event: %s', event)
try:
event = json.loads(__utils__['stringutils.to_str'](event))
event = salt.utils.json.loads(event)
except Exception as exc:
raise CommandExecutionError(
'Unable to interpret API event: \'{0}\''.format(event),
@ -4605,7 +4601,7 @@ def push(image,
# Iterate through API response and collect information
for event in response:
try:
event = json.loads(__utils__['stringutils.to_str'](event))
event = salt.utils.json.loads(event)
except Exception as exc:
raise CommandExecutionError(
'Unable to interpret API event: \'{0}\''.format(event),

View file

@ -12,9 +12,9 @@ except ImportError: # python3
from urllib.parse import quote, unquote
try:
import json
import requests
import salt.defaults.exitcodes
import salt.utils.json
from salt.exceptions import CommandExecutionError
HAS_LIBS = True
except ImportError:
@ -97,7 +97,7 @@ def _api_response(response):
raise CommandExecutionError('Bad username or password')
elif response.status_code == 200 or response.status_code == 500:
try:
data = json.loads(response.content)
data = salt.utils.json.loads(response.content)
if data['exit_code'] != 'SUCCESS':
__context__['retcode'] = salt.defaults.exitcodes.SALT_BUILD_FAIL
raise CommandExecutionError(data['message'])
@ -132,7 +132,7 @@ def _api_post(path, data, server=None):
url=_get_url(server['ssl'], server['url'], server['port'], path),
auth=_get_auth(server['user'], server['password']),
headers=_get_headers(),
data=json.dumps(data),
data=salt.utils.json.dumps(data),
verify=False
)
return _api_response(response)

View file

@ -17,7 +17,6 @@ import random
import logging
import operator
import collections
import json
import math
import yaml
from functools import reduce # pylint: disable=redefined-builtin
@ -27,6 +26,7 @@ from salt.ext import six
import salt.utils.compat
import salt.utils.data
import salt.utils.files
import salt.utils.json
import salt.utils.platform
import salt.utils.yamldumper
from salt.defaults import DEFAULT_TARGET_DELIM
@ -116,7 +116,7 @@ def get(key, default='', delimiter=DEFAULT_TARGET_DELIM, ordered=True):
if ordered is True:
grains = __grains__
else:
grains = json.loads(json.dumps(__grains__))
grains = salt.utils.json.loads(salt.utils.json.dumps(__grains__))
return salt.utils.data.traverse_dict_and_list(
grains,
key,

View file

@ -43,13 +43,13 @@ Module for handling OpenStack Heat calls
# Import Python libs
from __future__ import absolute_import
import time
import json
import logging
import yaml
# Import Salt libs
from salt.ext import six
import salt.utils.files
import salt.utils.json
from salt.exceptions import SaltInvocationError
# pylint: disable=import-error
@ -203,7 +203,7 @@ def _parse_template(tmpl_str):
'''
tmpl_str = tmpl_str.strip()
if tmpl_str.startswith('{'):
tpl = json.loads(tmpl_str)
tpl = salt.utils.json.loads(tmpl_str)
else:
try:
tpl = yaml.load(tmpl_str, Loader=YamlLoader)

View file

@ -30,7 +30,6 @@ Module for sending messages to hipchat.
'''
# Import Python Libs
from __future__ import absolute_import
import json
import logging
# Import 3rd-party Libs
@ -41,6 +40,7 @@ from salt.ext.six.moves import range
import salt.ext.six.moves.http_client
import salt.utils.http
import salt.utils.json
# pylint: enable=import-error,no-name-in-module,redefined-builtin
@ -154,7 +154,7 @@ def _query(function,
elif api_version == 'v2':
headers['Authorization'] = 'Bearer {0}'.format(api_key)
if data:
data = json.dumps(data)
data = salt.utils.json.dumps(data)
if method == 'POST':
headers['Content-Type'] = 'application/json'

View file

@ -14,12 +14,12 @@ Requires an ``api_key`` in ``/etc/salt/minion``:
# Import python libs
from __future__ import absolute_import, print_function
import json
import logging
import time
# Import salt libs
import salt.utils.http
import salt.utils.json
log = logging.getLogger(__name__)
@ -89,7 +89,7 @@ def trigger_event(event=None, **kwargs):
data['occurredat'] = time.strftime("%B %d, %Y %I:%M%p", time.localtime())
result = _query(event=event,
method='POST',
data=json.dumps(data)
data=salt.utils.json.dumps(data)
)
if 'status' in result:
if result['status'] == 200:

View file

@ -36,10 +36,10 @@ except ImportError:
HAS_INFLUXDB = False
import collections
import json
import logging
# Import salt libs
import salt.utils.json
from salt.state import STATE_INTERNAL_KEYWORDS as _STATE_INTERNAL_KEYWORDS
log = logging.getLogger(__name__)
@ -678,7 +678,7 @@ def _pull_query_results(resultset):
for _header, _values in resultset.items():
_header, _group_tags = _header
if _group_tags:
_results[_header][json.dumps(_group_tags)] = [_value for _value in _values]
_results[_header][salt.utils.json.dumps(_group_tags)] = [_value for _value in _values]
else:
_results[_header] = [_value for _value in _values]
return dict(sorted(_results.items()))

View file

@ -9,22 +9,19 @@ Edit ini files
(for example /etc/sysctl.conf)
'''
from __future__ import absolute_import, print_function
# Import Python libs
from __future__ import print_function
from __future__ import absolute_import
from __future__ import absolute_import, print_function
import os
import re
import json
# Import Salt libs
from salt.ext import six
import salt.utils.files
import salt.utils.json
from salt.exceptions import CommandExecutionError
from salt.utils.odict import OrderedDict
# Import 3rd-party libs
from salt.ext import six
__virtualname__ = 'ini'
@ -349,10 +346,10 @@ class _Section(OrderedDict):
def __repr__(self, _repr_running=None):
_repr_running = _repr_running or {}
super_repr = super(_Section, self).__repr__(_repr_running)
return os.linesep.join((super_repr, json.dumps(self, indent=4)))
return os.linesep.join((super_repr, salt.utils.json.dumps(self, indent=4)))
def __str__(self):
return json.dumps(self, indent=4)
return salt.utils.json.dumps(self, indent=4)
def __eq__(self, item):
return (isinstance(item, self.__class__) and

View file

@ -17,7 +17,6 @@ from __future__ import absolute_import
# Import python libraries
import logging
import json
import os
try:
@ -27,6 +26,7 @@ except ImportError:
# Import Salt libs
import salt.utils.files
import salt.utils.json
from salt.ext import six
# Juniper interface libraries
@ -234,7 +234,7 @@ def rpc(cmd=None, dest=None, format='xml', **kwargs):
if format == 'text':
write_response = reply.text
elif format == 'json':
write_response = json.dumps(reply, indent=1)
write_response = salt.utils.json.dumps(reply, indent=1)
else:
write_response = etree.tostring(reply)
with salt.utils.files.fopen(dest, 'w') as fp:

View file

@ -18,7 +18,6 @@ from __future__ import absolute_import
import os
import re
import json
import logging as logger
import base64
from salt.ext import six
@ -28,6 +27,7 @@ from salt.ext.six.moves.urllib.parse import urlparse as _urlparse # pylint: dis
import salt.utils.files
import salt.utils.http as http
import salt.utils.json
__virtualname__ = 'k8s'
@ -74,12 +74,15 @@ def _kpost(url, data):
headers = {"Content-Type": "application/json"}
# Make request
log.trace("url is: {0}, data is: {1}".format(url, data))
ret = http.query(url, method='POST', header_dict=headers, data=json.dumps(data))
ret = http.query(url,
method='POST',
header_dict=headers,
data=salt.utils.json.dumps(data))
# Check requests status
if ret.get('error'):
return ret
else:
return json.loads(ret.get('body'))
return salt.utils.json.loads(ret.get('body'))
def _kput(url, data):
@ -88,12 +91,15 @@ def _kput(url, data):
# Prepare headers
headers = {"Content-Type": "application/json"}
# Make request
ret = http.query(url, method='PUT', header_dict=headers, data=json.dumps(data))
ret = http.query(url,
method='PUT',
header_dict=headers,
data=salt.utils.json.dumps(data))
# Check requests status
if ret.get('error'):
return ret
else:
return json.loads(ret.get('body'))
return salt.utils.json.loads(ret.get('body'))
def _kpatch(url, data):
@ -103,13 +109,13 @@ def _kpatch(url, data):
headers = {"Content-Type": "application/json-patch+json"}
# Make request
ret = http.query(url, method='PATCH', header_dict=headers,
data=json.dumps(data))
data=salt.utils.json.dumps(data))
# Check requests status
if ret.get('error'):
log.error("Got an error: {0}".format(ret.get("error")))
return ret
else:
return json.loads(ret.get('body'))
return salt.utils.json.loads(ret.get('body'))
def _kname(obj):
@ -179,7 +185,7 @@ def _get_labels(node, apiserver_url):
ret = http.query(url)
# Check requests status
if 'body' in ret:
ret = json.loads(ret.get('body'))
ret = salt.utils.json.loads(ret.get('body'))
elif ret.get('status', 0) == 404:
return "Node {0} doesn't exist".format(node)
else:
@ -387,7 +393,7 @@ def _get_namespaces(apiserver_url, name=""):
# Make request
ret = http.query(url)
if ret.get("body"):
return json.loads(ret.get("body"))
return salt.utils.json.loads(ret.get("body"))
else:
return None
@ -493,7 +499,7 @@ def _get_secrets(namespace, name, apiserver_url):
# Make request
ret = http.query(url)
if ret.get("body"):
return json.loads(ret.get("body"))
return salt.utils.json.loads(ret.get("body"))
else:
return None

View file

@ -14,13 +14,12 @@ Kapacitor execution module.
.. versionadded:: 2016.11.0
'''
from __future__ import absolute_import
import json
import logging
import salt.utils.http
import salt.utils.json
import salt.utils.path
from salt.utils.decorators import memoize
@ -68,7 +67,7 @@ def get_task(name):
if response['status'] == 404:
return None
data = json.loads(response['body'])
data = salt.utils.json.loads(response['body'])
if version() < '0.13':
return {

View file

@ -13,21 +13,20 @@ from __future__ import absolute_import
# Import python libs
import copy
import functools
import json
import logging
# Import salt libs
import salt.utils.data
import salt.utils.functools
import salt.utils.json
import salt.utils.path
import salt.utils.pkg
import salt.utils.versions
from salt.exceptions import CommandExecutionError, MinionError
from salt.ext import six
from salt.ext.six.moves import zip
# Import third party libs
import json
from salt.ext import six
from salt.ext.six.moves import zip
log = logging.getLogger(__name__)
@ -292,7 +291,7 @@ def _info(*pkgs):
if brew_result['retcode']:
log.error('Failed to get info about packages: {0}'.format(' '.join(pkgs)))
return {}
output = json.loads(brew_result['stdout'])
output = salt.utils.json.loads(brew_result['stdout'])
return dict(zip(pkgs, output))
@ -422,7 +421,7 @@ def list_upgrades(refresh=True, **kwargs): # pylint: disable=W0613
ret = {}
try:
data = json.loads(res['stdout'])
data = salt.utils.json.loads(res['stdout'])
except ValueError as err:
msg = 'unable to interpret output from "brew outdated": {0}'.format(err)
log.error(msg)

View file

@ -19,10 +19,12 @@ In the minion configuration file, the following block is required:
'''
from __future__ import absolute_import
# import python std lib
import json
# Import Python libs
import logging
# Import Salt libs
import salt.utils.json
# import third party
try:
import requests
@ -115,7 +117,7 @@ def _http_request(url,
log.debug('Querying {}'.format(url))
req = session.post(url,
headers=headers,
data=json.dumps(data))
data=salt.utils.json.dumps(data))
req_body = req.json()
ret = _default_ret()
log.debug('Status code: %d', req.status_code)

View file

@ -8,9 +8,9 @@ Currently this only works when run through a proxy minion.
'''
from __future__ import absolute_import
import json
import logging
import salt.utils.http
import salt.utils.json
import salt.utils.platform
from salt.exceptions import get_error_message
@ -114,7 +114,7 @@ def update_app(id, config):
# mirror marathon-ui handling for uris deprecation (see
# mesosphere/marathon-ui#594 for more details)
config.pop('fetch', None)
data = json.dumps(config)
data = salt.utils.json.dumps(config)
try:
response = salt.utils.http.query(
"{0}/v2/apps/{1}?force=true".format(_base_url(), id),

View file

@ -16,16 +16,12 @@ Module for sending messages to Mattermost
'''
# Import Python libs
from __future__ import absolute_import
import json
from __future__ import absolute_import, print_function, unicode_literals
import logging
# Import 3rd-party libs
# pylint: disable=import-error,no-name-in-module,redefined-builtin
# Import Salt libs
import salt.utils.json
import salt.utils.mattermost
# pylint: enable=import-error,no-name-in-module
from salt.exceptions import SaltInvocationError
log = logging.getLogger(__name__)
@ -136,9 +132,8 @@ def post_message(message,
if username:
parameters['username'] = username
parameters['text'] = '```' + message + '```' # pre-formatted, fixed-width text
log.debug('Parameters: {0}'.format(parameters))
result = salt.utils.mattermost.query(api_url=api_url,
hook=hook,
data='payload={0}'.format(json.dumps(parameters)))
log.debug('Parameters: %s', parameters)
data = str('payload={0}').format(salt.utils.json.dumps(parameters)) # future lint: disable=blacklisted-function
result = salt.utils.mattermost.query(api_url=api_url, hook=hook, data=data)
return bool(result)

View file

@ -17,10 +17,10 @@ from __future__ import absolute_import
# Import python libs
import logging
import json
import re
# Import salt libs
import salt.utils.json
from salt.utils.versions import LooseVersion as _LooseVersion
from salt.exceptions import get_error_message as _get_error_message
@ -80,7 +80,7 @@ def _to_dict(objects):
"""
try:
if isinstance(objects, six.string_types):
objects = json.loads(objects)
objects = salt.utils.json.loads(objects)
except ValueError as err:
log.error("Could not parse objects: %s", err)
raise err

View file

@ -10,19 +10,17 @@ Module for sending messages to MS Teams
msteams:
hook_url: https://outlook.office.com/webhook/837
'''
# Import Python libs
from __future__ import absolute_import
import json
import logging
# Import 3rd-party libs
# pylint: disable=import-error,no-name-in-module,redefined-builtin
import salt.ext.six.moves.http_client
# Import Salt libs
import salt.utils.json
from salt.exceptions import SaltInvocationError
# Import 3rd-party libs
import salt.ext.six.moves.http_client # pylint: disable=import-error,no-name-in-module,redefined-builtin
log = logging.getLogger(__name__)
__virtualname__ = 'msteams'
@ -78,7 +76,10 @@ def post_card(message,
"themeColor": theme_color
}
result = salt.utils.http.query(hook_url, method='POST', data=json.dumps(payload), status=True)
result = salt.utils.http.query(hook_url,
method='POST',
data=salt.utils.json.dumps(payload),
status=True)
if result['status'] <= 201:
return True

View file

@ -9,10 +9,10 @@ except ImportError:
from pipes import quote as _cmd_quote
# Import python libs
import json
import logging
# Import salt libs
import salt.utils.json
import salt.utils.path
import salt.utils.user
import salt.modules.cmdmod
@ -169,7 +169,7 @@ def install(pkg=None,
# npm >1.2.21 is putting the output to stderr even though retcode is 0
npm_output = result['stdout'] or result['stderr']
try:
return json.loads(npm_output)
return salt.utils.json.loads(npm_output)
except ValueError:
pass
@ -192,7 +192,7 @@ def _extract_json(npm_output):
while lines and (lines[0].startswith('[fsevents]') or lines[0].startswith('Pass ')):
lines = lines[1:]
try:
return json.loads(''.join(lines))
return salt.utils.json.loads(''.join(lines))
except ValueError:
pass
return None
@ -322,7 +322,7 @@ def list_(pkg=None, dir=None, runas=None, env=None, depth=None):
if result['retcode'] != 0 and result['stderr']:
raise CommandExecutionError(result['stderr'])
return json.loads(result['stdout']).get('dependencies', {})
return salt.utils.json.loads(result['stdout']).get('dependencies', {})
def cache_clean(path=None, runas=None, env=None, force=False):

View file

@ -22,12 +22,12 @@ Module for sending data to OpsGenie
'''
# Import Python libs
from __future__ import absolute_import
import json
import logging
import requests
# Import Salt libs
import salt.exceptions
import salt.utils.json
API_ENDPOINT = "https://api.opsgenie.com/v1/json/saltstack?apiKey="
@ -93,6 +93,8 @@ def post_data(api_key=None, name='OpsGenie Execution Module', reason=None,
log.debug('Below data will be posted:\n' + str(data))
log.debug('API Key:' + api_key + '\t API Endpoint:' + API_ENDPOINT)
response = requests.post(url=API_ENDPOINT + api_key, data=json.dumps(data),
response = requests.post(
url=API_ENDPOINT + api_key,
data=salt.utils.json.dumps(data),
headers={'Content-Type': 'application/json'})
return response.status_code, response.text

View file

@ -7,13 +7,13 @@ Support for OSQuery - https://osquery.io.
from __future__ import absolute_import
# Import python libs
import json
import logging
# Import Salt libs
import salt.utils.json
import salt.utils.path
import salt.utils.platform
import logging
log = logging.getLogger(__name__)
@ -41,7 +41,7 @@ def _table_attrs(table):
res = __salt__['cmd.run_all'](cmd)
if res['retcode'] == 0:
attrs = []
text = json.loads(res['stdout'])
text = salt.utils.json.loads(res['stdout'])
for item in text:
attrs.append(item['name'])
return attrs
@ -62,7 +62,7 @@ def _osquery(sql, format='json'):
ret['result'] = False
ret['error'] = res['stderr']
else:
ret['data'] = json.loads(res['stdout'])
ret['data'] = salt.utils.json.loads(res['stdout'])
return ret

View file

@ -20,10 +20,10 @@ from __future__ import absolute_import
# Import python libs
import yaml
import json
# Import salt libs
import salt.utils.functools
import salt.utils.json
import salt.utils.pagerduty
from salt.ext.six import string_types
@ -181,7 +181,7 @@ def create_event(service_key=None, description=None, details=None,
if isinstance(details, string_types):
details = {'details': details}
ret = json.loads(salt.utils.pagerduty.query(
ret = salt.utils.json.loads(salt.utils.pagerduty.query(
method='POST',
profile_dict=__salt__['config.option'](profile),
api_key=service_key,

View file

@ -20,8 +20,8 @@ For PagerDuty API details, see https://developer.pagerduty.com/documentation/res
'''
from __future__ import absolute_import
import json
import requests
import salt.utils.json
def __virtual__():
@ -164,7 +164,7 @@ def _query(method='GET', profile=None, url=None, path='api/v1',
url,
headers=headers,
params=params,
data=json.dumps(data),
data=salt.utils.json.dumps(data),
verify=verify_ssl
)
@ -185,7 +185,7 @@ def _query(method='GET', profile=None, url=None, path='api/v1',
url,
headers=headers,
params=params,
data=data, # must not use json.dumps() or offset/limit get lost
data=data, # Already serialized above, don't do it again
verify=verify_ssl).json()
offset = next_page_results['offset']
limit = next_page_results['limit']

View file

@ -83,11 +83,11 @@ import shutil
import logging
import sys
import tempfile
import json
# Import Salt libs
import salt.utils.data
import salt.utils.files
import salt.utils.json
import salt.utils.locales
import salt.utils.platform
import salt.utils.url
@ -1151,7 +1151,7 @@ def list_upgrades(bin_env=None,
packages = {}
try:
json_results = json.loads(result['stdout'])
json_results = salt.utils.json.loads(result['stdout'])
for json_result in json_results:
packages[json_result['name']] = json_result['latest_version']
except ValueError:

View file

@ -4,26 +4,25 @@ Module to provide RabbitMQ compatibility to Salt.
Todo: A lot, need to add cluster support, logging, and minion configuration
data.
'''
# Import Python libs
from __future__ import absolute_import
# Import python libs
import json
import re
import logging
import os
import os.path
import random
import re
import string
# Import salt libs
# Import Salt libs
import salt.utils.itertools
import salt.utils.json
import salt.utils.path
import salt.utils.platform
import salt.utils.user
from salt.exceptions import CommandExecutionError, SaltInvocationError
# Import 3rd-party libs
from salt.ext import six
from salt.exceptions import SaltInvocationError
from salt.ext.six.moves import range
from salt.exceptions import CommandExecutionError
log = logging.getLogger(__name__)
@ -866,7 +865,7 @@ def set_policy(vhost, name, pattern, definition, priority=None, apply_to=None, r
if runas is None and not salt.utils.platform.is_windows():
runas = salt.utils.user.get_user()
if isinstance(definition, dict):
definition = json.dumps(definition)
definition = salt.utils.json.dumps(definition)
if not isinstance(definition, six.string_types):
raise SaltInvocationError(
'The \'definition\' argument must be a dictionary or JSON string'

View file

@ -15,12 +15,12 @@ Requires a ``username`` and a ``password`` in ``/etc/salt/minion``:
# Import python libs
from __future__ import absolute_import, print_function
import json
import logging
# Import salt libs
from salt.exceptions import SaltInvocationError
import salt.utils.http
import salt.utils.json
log = logging.getLogger(__name__)
@ -202,7 +202,7 @@ def update_item(name, id_, field=None, value=None, postdata=None):
action=name,
command=id_,
method='POST',
data=json.dumps(postdata),
data=salt.utils.json.dumps(postdata),
)
return result

View file

@ -22,16 +22,15 @@ from __future__ import absolute_import
import logging
# Import 3rd-party libs
import json
# pylint: disable=import-error,no-name-in-module,redefined-builtin
import salt.ext.six
import salt.ext.six.moves.http_client
from salt.ext.six.moves.urllib.parse import urljoin as _urljoin
# pylint: enable=import-error,no-name-in-module,redefined-builtin
# Import salt libs
import salt.utils.http
# pylint: enable=import-error,no-name-in-module,redefined-builtin
import salt.utils.json
log = logging.getLogger(__name__)
__virtualname__ = 'random_org'
@ -97,7 +96,7 @@ def _query(api_version=None, data=None):
api_url = 'https://api.random.org/'
base_url = _urljoin(api_url, 'json-rpc/' + str(api_version) + '/invoke')
data = json.dumps(data)
data = salt.utils.json.dumps(data)
result = salt.utils.http.query(
base_url,

View file

@ -2,13 +2,12 @@
'''
Control a salt cloud system
'''
from __future__ import absolute_import
# Import python libs
import json
from __future__ import absolute_import
# Import salt libs
import salt.utils.data
import salt.utils.json
HAS_CLOUD = False
try:
@ -43,7 +42,7 @@ def create(name, profile):
cmd = 'salt-cloud --out json -p {0} {1}'.format(profile, name)
out = __salt__['cmd.run_stdout'](cmd, python_shell=False)
try:
ret = json.loads(out, object_hook=salt.utils.data.encode_dict)
ret = salt.utils.json.loads(out, object_hook=salt.utils.data.encode_dict)
except ValueError:
ret = {}
return ret

View file

@ -8,17 +8,18 @@ Wrapper around Server Density API
# Import Python libs
from __future__ import absolute_import
import json
import logging
import os
import tempfile
# Import Salt libs
import salt.utils.json
from salt.exceptions import CommandExecutionError
# Import 3rd-party libs
from salt.ext import six
from salt.ext.six.moves import map # pylint: disable=import-error,no-name-in-module,redefined-builtin
from salt.exceptions import CommandExecutionError
try:
import requests
ENABLED = True
@ -99,7 +100,7 @@ def create(name, **params):
log.debug('Server Density API Response content: {0}'.format(api_response.content))
if api_response.status_code == 200:
try:
return json.loads(api_response.content)
return salt.utils.json.loads(api_response.content)
except ValueError:
log.error('Could not parse API Response content: {0}'.format(api_response.content))
raise CommandExecutionError(
@ -130,7 +131,7 @@ def delete(device_id):
log.debug('Server Density API Response content: {0}'.format(api_response.content))
if api_response.status_code == 200:
try:
return json.loads(api_response.content)
return salt.utils.json.loads(api_response.content)
except ValueError:
log.error('Could not parse API Response content: {0}'.format(api_response.content))
raise CommandExecutionError(
@ -172,13 +173,13 @@ def ls(**params):
api_response = requests.get(
'https://api.serverdensity.io/inventory/{0}'.format(endpoint),
params={'token': get_sd_auth('api_token'), 'filter': json.dumps(params)}
params={'token': get_sd_auth('api_token'), 'filter': salt.utils.json.dumps(params)}
)
log.debug('Server Density API Response: {0}'.format(api_response))
log.debug('Server Density API Response content: {0}'.format(api_response.content))
if api_response.status_code == 200:
try:
return json.loads(api_response.content)
return salt.utils.json.loads(api_response.content)
except ValueError:
log.error(
'Could not parse Server Density API Response content: {0}'
@ -217,7 +218,7 @@ def update(device_id, **params):
log.debug('Server Density API Response content: {0}'.format(api_response.content))
if api_response.status_code == 200:
try:
return json.loads(api_response.content)
return salt.utils.json.loads(api_response.content)
except ValueError:
log.error(
'Could not parse Server Density API Response content: {0}'

View file

@ -18,21 +18,21 @@ Module for sending messages to Slack
# Import Python libs
from __future__ import absolute_import
import json
import logging
# Import Salt libs
import salt.utils.json
import salt.utils.slack
from salt.exceptions import SaltInvocationError
# Import 3rd-party libs
# pylint: disable=import-error,no-name-in-module,redefined-builtin
from salt.ext.six.moves.urllib.parse import urlencode as _urlencode
from salt.ext.six.moves.urllib.parse import urljoin as _urljoin
from salt.ext.six.moves import range
import salt.ext.six.moves.http_client
import salt.utils.slack
# pylint: enable=import-error,no-name-in-module
from salt.exceptions import SaltInvocationError
log = logging.getLogger(__name__)
__virtualname__ = 'slack'
@ -308,7 +308,7 @@ def call_hook(message,
data = _urlencode(
{
'payload': json.dumps(payload, ensure_ascii=False)
'payload': salt.utils.json.dumps(payload)
}
)
result = salt.utils.http.query(url, method='POST', data=data, status=True)

View file

@ -6,9 +6,9 @@ from __future__ import absolute_import
# Import Python libs
import logging
import json
# Import Salt libs
import salt.utils.json
import salt.utils.path
import salt.utils.platform
import salt.utils.decorators as decorators
@ -144,7 +144,7 @@ def avail(search=None, verbose=False):
ret['Error'] = _exit_status(retcode)
return ret
for image in json.loads(res['stdout']):
for image in salt.utils.json.loads(res['stdout']):
if image['manifest']['disabled'] or not image['manifest']['public']:
continue
if search and search not in image['manifest']['name']:
@ -178,7 +178,7 @@ def list_installed(verbose=False):
ret['Error'] = _exit_status(retcode)
return ret
for image in json.loads(res['stdout']):
for image in salt.utils.json.loads(res['stdout']):
result[image['manifest']['uuid']] = _parse_image_meta(image, verbose)
return result
@ -205,7 +205,7 @@ def show(uuid):
if retcode != 0:
ret['Error'] = _exit_status(retcode)
return ret
ret = json.loads(res['stdout'])
ret = salt.utils.json.loads(res['stdout'])
return ret
@ -230,7 +230,7 @@ def get(uuid):
if retcode != 0:
ret['Error'] = _exit_status(retcode)
return ret
ret = json.loads(res['stdout'])
ret = salt.utils.json.loads(res['stdout'])
return ret

View file

@ -6,7 +6,6 @@ from __future__ import absolute_import
# Import Python libs
import logging
import json
import os
try:
from shlex import quote as _quote_args # pylint: disable=E0611
@ -17,8 +16,10 @@ except ImportError:
import salt.utils.args
import salt.utils.decorators as decorators
import salt.utils.files
import salt.utils.json
import salt.utils.path
import salt.utils.platform
import salt.utils.stringutils
from salt.utils.odict import OrderedDict
# Import 3rd-party libs
@ -96,7 +97,7 @@ def _create_update_from_file(mode='create', uuid=None, path=None):
ret['Error'] = _exit_status(retcode)
if 'stderr' in res:
if res['stderr'][0] == '{':
ret['Error'] = json.loads(res['stderr'])
ret['Error'] = salt.utils.json.loads(res['stderr'])
else:
ret['Error'] = res['stderr']
return ret
@ -113,7 +114,7 @@ def _create_update_from_file(mode='create', uuid=None, path=None):
ret['Error'] = _exit_status(retcode)
if 'stderr' in res:
if res['stderr'][0] == '{':
ret['Error'] = json.loads(res['stderr'])
ret['Error'] = salt.utils.json.loads(res['stderr'])
else:
ret['Error'] = res['stderr']
return ret
@ -133,7 +134,7 @@ def _create_update_from_cfg(mode='create', uuid=None, vmcfg=None):
# write json file
vmadm_json_file = __salt__['temp.file'](prefix='vmadm-')
with salt.utils.files.fopen(vmadm_json_file, 'w') as vmadm_json:
vmadm_json.write(json.dumps(vmcfg))
salt.utils.json.dump(vmcfg, vmadm_json)
# vmadm validate create|update [-f <filename>]
cmd = '{vmadm} validate {mode} {brand} -f {vmadm_json_file}'.format(
@ -148,7 +149,7 @@ def _create_update_from_cfg(mode='create', uuid=None, vmcfg=None):
ret['Error'] = _exit_status(retcode)
if 'stderr' in res:
if res['stderr'][0] == '{':
ret['Error'] = json.loads(res['stderr'])
ret['Error'] = salt.utils.json.loads(res['stderr'])
else:
ret['Error'] = res['stderr']
return ret
@ -165,7 +166,7 @@ def _create_update_from_cfg(mode='create', uuid=None, vmcfg=None):
ret['Error'] = _exit_status(retcode)
if 'stderr' in res:
if res['stderr'][0] == '{':
ret['Error'] = json.loads(res['stderr'])
ret['Error'] = salt.utils.json.loads(res['stderr'])
else:
ret['Error'] = res['stderr']
return ret
@ -404,7 +405,7 @@ def lookup(search=None, order=None, one=False):
if one:
result = res['stdout']
else:
for vm in json.loads(res['stdout']):
for vm in salt.utils.json.loads(res['stdout']):
result.append(vm)
return result
@ -525,7 +526,7 @@ def get(vm, key='uuid'):
if retcode != 0:
ret['Error'] = res['stderr'] if 'stderr' in res else _exit_status(retcode)
return ret
return json.loads(res['stdout'])
return salt.utils.json.loads(res['stdout'])
def info(vm, info_type='all', key='uuid'):
@ -570,7 +571,7 @@ def info(vm, info_type='all', key='uuid'):
if retcode != 0:
ret['Error'] = res['stderr'] if 'stderr' in res else _exit_status(retcode)
return ret
return json.loads(res['stdout'])
return salt.utils.json.loads(res['stdout'])
def create_snapshot(vm, name, key='uuid'):
@ -756,10 +757,10 @@ def reprovision(vm, image, key='uuid'):
ret['Error'] = 'Image ({0}) is not present on this host'.format(image)
return ret
# vmadm reprovision <uuid> [-f <filename>]
cmd = 'echo {image} | {vmadm} reprovision {uuid}'.format(
vmadm=vmadm,
uuid=vm,
image=_quote_args(json.dumps({'image_uuid': image}))
cmd = str('echo {image} | {vmadm} reprovision {uuid}').format( # future lint: disable=blacklisted-function
vmadm=salt.utils.stringutils.to_str(vmadm),
uuid=salt.utils.stringutils.to_str(vm),
image=_quote_args(salt.utils.json.dumps({'image_uuid': image}))
)
res = __salt__['cmd.run_all'](cmd, python_shell=True)
retcode = res['retcode']

View file

@ -61,7 +61,6 @@ verbose : True
# Import python Libs
from __future__ import absolute_import
import json
import os
# Import 3rd-party libs
@ -77,6 +76,7 @@ from salt.ext.six.moves.urllib.request import (
# pylint: enable=no-name-in-module,import-error
# Import salt libs
import salt.utils.json
import salt.utils.path
# ######################### PRIVATE METHODS ##############################
@ -258,7 +258,7 @@ def _auth(url):
def _http_request(url, request_timeout=None):
'''
PRIVATE METHOD
Uses json.load to fetch the JSON results from the solr API.
Uses salt.utils.json.load to fetch the JSON results from the solr API.
url : str
a complete URL that can be passed to urllib.open
@ -274,10 +274,8 @@ def _http_request(url, request_timeout=None):
try:
request_timeout = __salt__['config.option']('solr.request_timeout')
if request_timeout is None:
data = json.load(_urlopen(url))
else:
data = json.load(_urlopen(url, timeout=request_timeout))
kwargs = {} if request_timeout is None else {'timeout': request_timeout}
data = salt.utils.json.load(_urlopen(url, **kwargs))
return _get_return_dict(True, data, [])
except Exception as err:
return _get_return_dict(False, {}, ["{0} : {1}".format(url, err)])

View file

@ -14,7 +14,6 @@ states themselves.
# Import python libs
from __future__ import absolute_import, print_function
import fnmatch
import json
import logging
import os
import shutil
@ -34,8 +33,10 @@ import salt.utils.files
import salt.utils.functools
import salt.utils.hashutils
import salt.utils.jid
import salt.utils.json
import salt.utils.platform
import salt.utils.state
import salt.utils.stringutils
import salt.utils.url
import salt.utils.versions
from salt.exceptions import CommandExecutionError, SaltInvocationError
@ -1996,7 +1997,7 @@ def pkg(pkg_path,
s_pkg.close()
lowstate_json = os.path.join(root, 'lowstate.json')
with salt.utils.files.fopen(lowstate_json, 'r') as fp_:
lowstate = json.load(fp_, object_hook=salt.utils.data.encode_dict)
lowstate = salt.utils.json.load(fp_)
# Check for errors in the lowstate
for chunk in lowstate:
if not isinstance(chunk, dict):
@ -2004,14 +2005,14 @@ def pkg(pkg_path,
pillar_json = os.path.join(root, 'pillar.json')
if os.path.isfile(pillar_json):
with salt.utils.files.fopen(pillar_json, 'r') as fp_:
pillar_override = json.load(fp_)
pillar_override = salt.utils.json.load(fp_)
else:
pillar_override = None
roster_grains_json = os.path.join(root, 'roster_grains.json')
if os.path.isfile(roster_grains_json):
with salt.utils.files.fopen(roster_grains_json, 'r') as fp_:
roster_grains = json.load(fp_, object_hook=salt.utils.data.encode_dict)
roster_grains = salt.utils.json.load(fp_, object_hook=salt.utils.data.encode_dict)
if os.path.isfile(roster_grains_json):
popts['grains'] = roster_grains
@ -2237,12 +2238,15 @@ def event(tagmatch='*',
if fnmatch.fnmatch(ret['tag'], tagmatch):
if not quiet:
print('{0}\t{1}'.format(
ret['tag'],
json.dumps(
salt.utils.stringutils.print_cli(
str('{0}\t{1}').format( # future lint: blacklisted-function
salt.utils.stringutils.to_str(ret['tag']),
salt.utils.json.dumps(
ret['data'],
sort_keys=pretty,
indent=None if not pretty else 4)))
indent=None if not pretty else 4)
)
)
sys.stdout.flush()
count -= 1

View file

@ -24,7 +24,7 @@ More information: https://docker-py.readthedocs.io/en/stable/
"""
# Import python libraries
from __future__ import absolute_import
import json
import salt.utils.json
try:
import docker
@ -238,8 +238,8 @@ def swarm_service_info(service_name=str):
salt_return = {}
client = docker.APIClient(base_url='unix://var/run/docker.sock')
service = client.inspect_service(service=service_name)
getdata = json.dumps(service)
dump = json.loads(getdata)
getdata = salt.utils.json.dumps(service)
dump = salt.utils.json.loads(getdata)
version = dump['Version']['Index']
name = dump['Spec']['Name']
network_mode = dump['Spec']['EndpointSpec']['Mode']
@ -316,8 +316,8 @@ def node_ls(server=str):
salt_return = {}
client = docker.APIClient(base_url='unix://var/run/docker.sock')
service = client.nodes(filters=({'name': server}))
getdata = json.dumps(service)
dump = json.loads(getdata)
getdata = salt.utils.json.dumps(service)
dump = salt.utils.json.loads(getdata)
for items in dump:
docker_version = items['Description']['Engine']['EngineVersion']
platform = items['Description']['Platform']

View file

@ -23,11 +23,16 @@ https://github.com/mongolab/mongolab-telemetry-api-docs/blob/master/alerts.md
:depends: requests
'''
# Import Python libs
from __future__ import absolute_import
from salt._compat import string_types
import json
import logging
# Import Salt libs
import salt.utils.json
# Import 3rd-party libs
from salt.ext import six
log = logging.getLogger(__name__)
# Import third party libs
@ -57,7 +62,7 @@ def _auth(api_key=None, profile='telemetry'):
if api_key is None and profile is None:
raise Exception("Missing api_key and profile")
if profile:
if isinstance(profile, string_types):
if isinstance(profile, six.string_types):
_profile = __salt__['config.option'](profile)
elif isinstance(profile, dict):
_profile = profile
@ -184,7 +189,7 @@ def get_notification_channel_id(notify_channel, profile="telemetry"):
"name": notify_channel[:notify_channel.find('@')] + 'EscalationPolicy',
"email": notify_channel
}
response = requests.post(post_url, data=json.dumps(data), headers=auth)
response = requests.post(post_url, data=salt.utils.json.dumps(data), headers=auth)
if response.status_code == 200:
log.info("Successfully created EscalationPolicy {0} with EmailNotificationChannel {1}"
.format(data.get('name'), notify_channel))
@ -224,7 +229,7 @@ def get_alarms(deployment_id, profile="telemetry"):
return 'No alarms defined for deployment: {0}'.format(deployment_id)
else:
# Non 200 response, sent back the error response'
return {'err_code': response.status_code, 'err_msg': json.loads(response.text).get('err', '')}
return {'err_code': response.status_code, 'err_msg': salt.utils.json.loads(response.text).get('err', '')}
def create_alarm(deployment_id, metric_name, data, api_key=None, profile="telemetry"):
@ -259,19 +264,24 @@ def create_alarm(deployment_id, metric_name, data, api_key=None, profile="teleme
}
try:
response = requests.post(request_uri, data=json.dumps(post_body), headers=auth)
response = requests.post(request_uri, data=salt.utils.json.dumps(post_body), headers=auth)
except requests.exceptions.RequestException as e:
# TODO: May be we should retry?
log.error(str(e))
if response.status_code >= 200 and response.status_code < 300:
# update cache
log.info("Created alarm on metric: {0} in deployment: {1}".format(metric_name, deployment_id))
log.debug("Updating cache for metric {0} in deployment {1}: {2}".format(metric_name, deployment_id, response.json()))
log.info('Created alarm on metric: %s in deployment: %s', metric_name, deployment_id)
log.debug('Updating cache for metric %s in deployment %s: %s',
metric_name, deployment_id, response.json())
_update_cache(deployment_id, metric_name, response.json())
else:
log.error("Failed to create alarm on metric: {0} in deployment {1}: payload: {2}".
format(metric_name, deployment_id, json.dumps(post_body)))
log.error(
str('Failed to create alarm on metric: %s in deployment %s: payload: %s'), # future lint: disable=blacklisted-function
salt.utils.stringutils.to_str(metric_name),
salt.utils.stringutils.to_str(deployment_id),
salt.utils.json.dumps(post_body)
)
return response.status_code >= 200 and response.status_code < 300, response.json()
@ -308,19 +318,26 @@ def update_alarm(deployment_id, metric_name, data, api_key=None, profile="teleme
}
try:
response = requests.put(request_uri, data=json.dumps(post_body), headers=auth)
response = requests.put(request_uri, data=salt.utils.json.dumps(post_body), headers=auth)
except requests.exceptions.RequestException as e:
log.error("Update failed {0}" .format(str(e)))
log.error('Update failed: %s', e)
return False, str(e)
if response.status_code >= 200 and response.status_code < 300:
# Also update cache
log.debug("Updating cache for metric {0} in deployment {1}: {2}".format(metric_name, deployment_id, response.json()))
log.debug('Updating cache for metric %s in deployment %s: %s',
metric_name, deployment_id, response.json())
_update_cache(deployment_id, metric_name, response.json())
log.info("Updated alarm on metric: {0} in deployment: {1}".format(metric_name, deployment_id))
log.info('Updated alarm on metric: %s in deployment: %s', metric_name, deployment_id)
return True, response.json()
err_msg = "Failed to create alarm on metric: {0} in deployment {1}: payload: {2}".format(metric_name, deployment_id, json.dumps(post_body))
err_msg = str( # future lint: disable=blacklisted-function
'Failed to create alarm on metric: {0} in deployment: {1} '
'payload: {2}').format(
salt.utils.stringutils.to_str(metric_name),
salt.utils.stringutils.to_str(deployment_id),
salt.utils.json.dumps(post_body)
)
log.error(err_msg)
return False, err_msg

Some files were not shown because too many files have changed in this diff Show more