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

[PR #8091/67736d79 backport][stable-8] Fix consul_token usage without accessor_id. (#8097)

Fix consul_token usage without accessor_id. (#8091)

* Fix consul_token usage without accessor_id.

* Update changelogs/fragments/8091-consul-token-fixes.yaml

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/consul_token.py

Co-authored-by: Felix Fontein <felix@fontein.de>

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit 67736d796a)

Co-authored-by: Florian Apolloner <florian@apolloner.eu>
This commit is contained in:
patchback[bot] 2024-03-14 23:39:10 +01:00 committed by GitHub
parent c47081245c
commit 12ab33df84
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 20 additions and 1 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- "consul_token - fix token creation without ``accessor_id`` (https://github.com/ansible-collections/community.general/pull/8091)."

View file

@ -277,7 +277,7 @@ class _ConsulModule:
headers["X-Consul-Token"] = token headers["X-Consul-Token"] = token
try: try:
if data: if data is not None:
data = json.dumps(data) data = json.dumps(data)
headers["Content-Type"] = "application/json" headers["Content-Type"] = "application/json"
if params: if params:

View file

@ -237,6 +237,12 @@ class ConsulTokenModule(_ConsulModule):
create_only_fields = {"expiration_ttl"} create_only_fields = {"expiration_ttl"}
def read_object(self):
# if `accessor_id` is not supplied we can only create objects and are not idempotent
if not self.params.get(self.unique_identifier):
return None
return super(ConsulTokenModule, self).read_object()
def needs_update(self, api_obj, module_obj): def needs_update(self, api_obj, module_obj):
# SecretID is usually not supplied # SecretID is usually not supplied
if "SecretID" not in module_obj and "SecretID" in api_obj: if "SecretID" not in module_obj and "SecretID" in api_obj:

View file

@ -14,6 +14,17 @@
- foo-access - foo-access
- foo-access2 - foo-access2
- name: Create token without accessor
community.general.consul_token:
state: present
register: simple_create_result
- assert:
that:
- simple_create_result is changed
- simple_create_result.token.AccessorID
- simple_create_result.operation == 'create'
- name: Create token - name: Create token
community.general.consul_token: community.general.consul_token:
state: present state: present