Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self, opts, backends='flat'):
self.opts = opts
if isinstance(backends, list):
self.backends = backends
elif isinstance(backends, six.string_types):
self.backends = backends.split(',')
else:
self.backends = backends
if not backends:
self.backends = ['flat']
utils = salt.loader.utils(self.opts)
runner = salt.loader.runner(self.opts, utils=utils)
self.rosters = salt.loader.roster(self.opts, runner=runner, utils=utils)
_append = False
elif r['Object Name'].startswith(exclude):
# Startswith is well and good, but it needs to be a parent directory or it doesn't count
_, _, leftover = r['Object Name'].partition(exclude)
if leftover.startswith(os.sep):
_append = False
if _append and config_found:
new_ret.append(r)
ret = new_ret
if ret and 'return' in config:
__opts__['grains'] = __grains__
__opts__['pillar'] = __pillar__
__returners__ = salt.loader.returners(__opts__, __salt__)
return_config = config['return']
if isinstance(return_config, salt.ext.six.string_types):
tmp = {}
for conf in return_config.split(','):
tmp[conf] = None
return_config = tmp
for returner_mod in return_config:
returner = '{0}.returner'.format(returner_mod)
if returner not in __returners__:
log.error('Could not find {0} returner for pulsar beacon'.format(config['return']))
return ret
batch_config = config.get('batch')
if isinstance(return_config[returner_mod], dict) and return_config[returner_mod].get('batch'):
batch_config = True
if batch_config:
transformed = []
for item in ret:
transformed.append({'return': item})
except KeyError:
_options[k] = v
else:
# Use "returner.postgres" options.
defaults.pop("pass")
defaults["passwd"] = "salt"
defaults["port"] = 5432
for k, v in six.iteritems(defaults):
try:
_options[k] = __opts__["{}.{}".format("returner.postgres", k)]
except KeyError:
_options[k] = v
# post processing
for k, v in six.iteritems(_options):
if isinstance(v, six.string_types) and v.lower() == "none":
# Ensure 'None' is rendered as None
_options[k] = None
if k == "port":
# Ensure port is an int
_options[k] = int(v)
return _options
}
if EBSOptions is None:
EBSOptions = {
'EBSEnabled': False,
}
if SnapshotOptions is None:
SnapshotOptions = {
'AutomatedSnapshotStartHour': 0
}
if AdvancedOptions is None:
AdvancedOptions = {
'rest.action.multi.allow_explicit_index': 'true'
}
if Tags is None:
Tags = {}
if AccessPolicies is not None and isinstance(AccessPolicies, six.string_types):
try:
AccessPolicies = json.loads(AccessPolicies)
except ValueError as e:
ret['result'] = False
ret['comment'] = 'Failed to create domain: {0}.'.format(e.message)
return ret
r = __salt__['boto_elasticsearch_domain.exists'](DomainName=DomainName,
region=region, key=key, keyid=keyid, profile=profile)
if 'error' in r:
ret['result'] = False
ret['comment'] = 'Failed to create domain: {0}.'.format(r['error']['message'])
return ret
if not r.get('exists'):
if __opts__['test']:
def match(tgt, opts=None):
'''
Runs the compound target check
'''
if not opts:
opts = __opts__
nodegroups = opts.get('nodegroups', {})
matchers = salt.loader.matchers(opts)
minion_id = opts.get('minion_id', __opts__['id'])
if not isinstance(tgt, six.string_types) and not isinstance(tgt, (list, tuple)):
log.error('Compound target received that is neither string, list nor tuple')
return False
log.debug('compound_match: %s ? %s', minion_id, tgt)
ref = {'G': 'grain',
'P': 'grain_pcre',
'I': 'pillar',
'J': 'pillar_pcre',
'L': 'list',
'N': None, # Nodegroups should already be expanded
'S': 'ipcidr',
'E': 'pcre'}
if HAS_RANGE:
ref['R'] = 'range'
results = []
opers = ['and', 'or', 'not', '(', ')']
List all datasources in an organisation.
orgname
Name of the organization.
profile
Configuration profile used to connect to the Grafana instance.
Default is 'grafana'.
CLI Example:
.. code-block:: bash
salt '*' grafana4.get_datasources
'''
if isinstance(profile, string_types):
profile = __salt__['config.option'](profile)
if orgname:
switch_org(orgname, profile)
response = requests.get(
'{0}/api/datasources'.format(profile['grafana_url']),
auth=_get_auth(profile),
headers=_get_headers(profile),
timeout=profile.get('grafana_timeout', 3),
)
if response.status_code >= 400:
response.raise_for_status()
return response.json()
if __opts__['test']:
msg = 'Apache site {0} is set to be disabled.'.format(name)
ret['comment'] = msg
ret['changes']['old'] = name
ret['changes']['new'] = None
ret['result'] = None
return ret
status = __salt__['apache.a2dissite'](name)['Status']
if isinstance(status, string_types) and 'disabled' in status:
ret['result'] = True
ret['changes']['old'] = name
ret['changes']['new'] = None
else:
ret['result'] = False
ret['comment'] = 'Failed to disable {0} Apache site'.format(name)
if isinstance(status, string_types):
ret['comment'] = ret['comment'] + ' ({0})'.format(status)
return ret
else:
ret['comment'] = '{0} already disabled.'.format(name)
return ret
if v != rec_set[record_str].get(k):
ret['changes'] = {'new': {record_str: record}}
elif record_str[-1] == 's':
if not isinstance(record, list):
ret['comment'] = '{0} record information must be specified as a list of dictionaries!'.format(
record_str
)
return ret
local, remote = [sorted(config) for config in (record, rec_set[record_str])]
for idx in six_range(0, len(local)):
for key in local[idx]:
local_val = local[idx][key]
remote_val = remote[idx].get(key)
if isinstance(local_val, six.string_types):
local_val = local_val.lower()
if isinstance(remote_val, six.string_types):
remote_val = remote_val.lower()
if local_val != remote_val:
ret['changes'] = {'new': {record_str: record}}
if not ret['changes']:
ret['result'] = True
ret['comment'] = 'Record set {0} is already present.'.format(name)
return ret
if __opts__['test']:
ret['result'] = None
ret['comment'] = 'Record set {0} would be updated.'.format(name)
return ret
else:
ret['changes'] = {
def insert(queue, items):
'''
Add an item or items to a queue
'''
con = _conn(queue)
with con:
cur = con.cursor()
if isinstance(items, six.string_types):
items = _quote_escape(items)
cmd = '''INSERT INTO {0}(name) VALUES('{1}')'''.format(queue, items)
log.debug('SQL Query: %s', cmd)
try:
cur.execute(cmd)
except sqlite3.IntegrityError as esc:
return('Item already exists in this queue. '
'sqlite error: {0}'.format(esc))
if isinstance(items, list):
items = [_quote_escape(el) for el in items]
cmd = "INSERT INTO {0}(name) VALUES(?)".format(queue)
log.debug('SQL Query: %s', cmd)
newitems = []
for item in items:
newitems.append((item,))
# we need a list of one item tuples here
comment='',
result=None,
changes=None):
if not changes:
changes = {}
if exec_status is None:
exec_status = {}
if exec_status:
if result is None:
result = exec_status['status']
scomment = exec_status.get('comment', None)
if scomment:
comment += '\n' + scomment
out = exec_status.get('out', None)
if out:
if isinstance(out, string_types):
comment += '\n' + out
return {
'changes': changes,
'result': result,
'name': name,
'comment': comment,
}