1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

#2124 renamed release fragment to match pr, removed parse_params.

This commit is contained in:
fkuep 2021-03-31 01:04:39 +02:00
parent c50b1cf9d4
commit d2869b2f22
2 changed files with 19 additions and 42 deletions

View file

@ -1,5 +1,5 @@
--- ---
bugfixes: bugfixes:
- consul_kv lookup - use ``self.get_option`` and - consul_kv lookup - use ``self.get_option`` and
wire the existing ``token`` attribute into consul_api call remove the function parse_params all together with its for loop
(https://github.com/ansible-collections/community.general/issues/2124). (https://github.com/ansible-collections/community.general/issues/2124).

View file

@ -126,7 +126,7 @@ class LookupModule(LookupBase):
# get options # get options
self.set_options(direct=kwargs) self.set_options(direct=kwargs)
key = terms[0].split(' ')[0]
scheme = self.get_option('scheme') scheme = self.get_option('scheme')
host = self.get_option('host') host = self.get_option('host')
port = self.get_option('port') port = self.get_option('port')
@ -139,21 +139,22 @@ class LookupModule(LookupBase):
if u.port is not None: if u.port is not None:
port = u.port port = u.port
token = self.get_option('token') token = self.get_option('token')
datacenter=self.get_option('datacenter')
recurse=self.get_option('recurse')
index=self.get_option('index')
validate_certs = self.get_option('validate_certs') validate_certs = self.get_option('validate_certs')
client_cert = self.get_option('client_cert') client_cert = self.get_option('client_cert')
values = [] values = []
try: try:
for term in terms: consul_api = consul.Consul(host=host, port=port, scheme=scheme, token=token, dc=datacenter,
params = self.parse_params(term) verify=validate_certs, cert=client_cert)
consul_api = consul.Consul(host=host, port=port, scheme=scheme, token=token, verify=validate_certs, cert=client_cert)
results = consul_api.kv.get(params['key'], results = consul_api.kv.get(key,
token=params['token'], index=index,
index=params['index'], recurse=recurse,
recurse=params['recurse'], )
dc=params['datacenter'])
if results[1]: if results[1]:
# responds with a single or list of result maps # responds with a single or list of result maps
if isinstance(results[1], list): if isinstance(results[1], list):
@ -163,30 +164,6 @@ class LookupModule(LookupBase):
values.append(to_text(results[1]['Value'])) values.append(to_text(results[1]['Value']))
except Exception as e: except Exception as e:
raise AnsibleError( raise AnsibleError(
"Error locating '%s' in kv store. Error was %s" % (term, e)) "Error locating '%s' in kv store. Error was %s" % (key, e))
return values return values
def parse_params(self, term):
params = term.split(' ')
paramvals = {
'key': params[0],
'token': None,
'recurse': False,
'index': None,
'datacenter': None
}
# parameters specified?
try:
for param in params[1:]:
if param and len(param) > 0:
name, value = param.split('=')
if name not in paramvals:
raise AnsibleAssertionError("%s not a valid consul lookup parameter" % name)
paramvals[name] = value
except (ValueError, AssertionError) as e:
raise AnsibleError(e)
return paramvals