-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Description
Description of Issue/Question
REST SDB module cannot be used without specifying a request parameter. The documentation indicates that the SDB URI can be used without requiring any query parameters and the SDB REST configuration allows for configuration without a template variable. When attempting to retrieve the value without specifying a query parameter, the following error is given:
Exception occurred in runner sdb.get: Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/salt/client/mixins.py", line 382, in _low
data['return'] = self.functions[fun](*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/salt/runners/sdb.py", line 27, in get
return salt.utils.sdb.sdb_get(uri, __opts__, __utils__)
File "/usr/lib/python2.7/dist-packages/salt/utils/sdb.py", line 46, in sdb_get
return loaded_db[fun](query, profile=profile)
File "/usr/lib/python2.7/dist-packages/salt/sdb/rest.py", line 94, in get
return query(key, None, service, profile)
File "/usr/lib/python2.7/dist-packages/salt/sdb/rest.py", line 115, in query
for pair in comps[1].split('&'):
IndexError: list index out of range
Looking at the code for '/salt/sdb/rest.py', the logic is such that it always assumes there is a value from performing the split('?') and does not perform any safety checks to ensure that it is not there:
'''
Get a value from the REST interface
'''
comps = key.split('?')
key = comps[0]
key_vars = {}
for pair in comps[1].split('&'):
pair_key, pair_val = pair.split('=')
key_vars[pair_key] = pair_val
In order to get the SDB value to return properly, you have to pass any arbitrary query string to the sdb URI in order for the value to return:
Assuming the SDB configuration in the Setup section below:
This does not work: salt-run sdb.get sdb://my-rest-api/urls
This works: salt-run sdb.get sdb://my-rest-api/urls?foo=bar
Setup
SDB Rest configuration from the rest example:
/etc/salt/master.d/sdb-github.sls
my-rest-api:
driver: rest
urls:
url: https://api.github.com/
keys:
url: https://api.github.com/users/{{user}}/keys
backend: requests
Steps to Reproduce Issue
- Add the above SDB configuration to /etc/salt/master.d/github.sls
- Execute the following Salt Run:
salt-run sdb.get sdb://my-rest-api/urls
Versions Report
Salt Version:
Salt: 2017.7.2
Dependency Versions:
cffi: Not Installed
cherrypy: 3.5.0
dateutil: 2.4.2
docker-py: Not Installed
gitdb: 0.6.4
gitpython: 1.0.1
ioflo: Not Installed
Jinja2: 2.8
libgit2: Not Installed
libnacl: 1.6.1
M2Crypto: Not Installed
Mako: 1.0.3
msgpack-pure: Not Installed
msgpack-python: 0.4.6
mysql-python: Not Installed
pycparser: Not Installed
pycrypto: 2.6.1
pycryptodome: Not Installed
pygit2: Not Installed
Python: 2.7.12 (default, Nov 19 2016, 06:48:10)
python-gnupg: Not Installed
PyYAML: 3.11
PyZMQ: 15.2.0
RAET: Not Installed
smmap: 0.9.0
timelib: Not Installed
Tornado: 4.2.1
ZMQ: 4.1.4
System Versions:
dist: Ubuntu 16.04 xenial
locale: UTF-8
machine: x86_64
release: 4.4.0-87-generic
system: Linux
version: Ubuntu 16.04 xenial