
    Vh]!                        d dl mZmZmZ eZdZdZdZd dl	m
Z
 d dlmZmZmZ  G d de      Z e ed	
       ed	
            Z e ed	ddg       ed	d            Z e ed	ddg       edd	            Z e ed	d       ed
            Z ed	d       ed	
       eddedgdg       edde       edde       edde       edddg      dZej-                  e       d Zedk(  r e        yy)    )absolute_importdivisionprint_functionuq  
module: consul_role
short_description: Manipulate Consul roles
version_added: 7.5.0
description:
  - Allows the addition, modification and deletion of roles in a Consul cluster using the agent. For more details on using
    and configuring ACLs, see U(https://www.consul.io/docs/guides/acl.html).
author:
  - Håkon Lerring (@Hakon)
extends_documentation_fragment:
  - community.general.consul
  - community.general.consul.token
  - community.general.consul.actiongroup_consul
  - community.general.attributes
attributes:
  check_mode:
    support: full
  diff_mode:
    support: partial
    details:
      - In check mode the diff will miss operational attributes.
    version_added: 8.3.0
  action_group:
    version_added: 8.3.0
options:
  name:
    description:
      - A name used to identify the role.
    required: true
    type: str
  state:
    description:
      - Whether the role should be present or absent.
    choices: ['present', 'absent']
    default: present
    type: str
  description:
    description:
      - Description of the role.
      - If not specified, the assigned description will not be changed.
    type: str
  policies:
    type: list
    elements: dict
    description:
      - List of policies to attach to the role. Each policy is a dict.
      - If the parameter is left blank, any policies currently assigned will not be changed.
      - Any empty array (V([])) will clear any policies previously set.
    suboptions:
      name:
        description:
          - The name of the policy to attach to this role; see M(community.general.consul_policy) for more info.
          - Either this or O(policies[].id) must be specified.
        type: str
      id:
        description:
          - The ID of the policy to attach to this role; see M(community.general.consul_policy) for more info.
          - Either this or O(policies[].name) must be specified.
        type: str
  templated_policies:
    description:
      - The list of templated policies that should be applied to the role.
    type: list
    elements: dict
    version_added: 8.3.0
    suboptions:
      template_name:
        description:
          - The templated policy name.
        type: str
        required: true
      template_variables:
        description:
          - The templated policy variables.
          - Not all templated policies require variables.
        type: dict
  service_identities:
    type: list
    elements: dict
    description:
      - List of service identities to attach to the role.
      - If not specified, any service identities currently assigned will not be changed.
      - If the parameter is an empty array (V([])), any node identities assigned will be unassigned.
    suboptions:
      service_name:
        description:
          - The name of the node.
          - Must not be longer than 256 characters, must start and end with a lowercase alphanumeric character.
          - May only contain lowercase alphanumeric characters as well as V(-) and V(_).
          - This suboption has been renamed from O(service_identities[].name) to O(service_identities[].service_name) in community.general
            8.3.0. The old name can still be used.
        type: str
        required: true
        aliases:
          - name
      datacenters:
        description:
          - The datacenters the policies will be effective.
          - This will result in effective policy only being valid in this datacenter.
          - If an empty array (V([])) is specified, the policies will valid in all datacenters.
          - Including those which do not yet exist but may in the future.
        type: list
        elements: str
  node_identities:
    type: list
    elements: dict
    description:
      - List of node identities to attach to the role.
      - If not specified, any node identities currently assigned will not be changed.
      - If the parameter is an empty array (V([])), any node identities assigned will be unassigned.
    suboptions:
      node_name:
        description:
          - The name of the node.
          - Must not be longer than 256 characters, must start and end with a lowercase alphanumeric character.
          - May only contain lowercase alphanumeric characters as well as V(-) and V(_).
          - This suboption has been renamed from O(node_identities[].name) to O(node_identities[].node_name) in community.general
            8.3.0. The old name can still be used.
        type: str
        required: true
        aliases:
          - name
      datacenter:
        description:
          - The nodes datacenter.
          - This will result in effective policy only being valid in this datacenter.
        type: str
        required: true
aZ  
- name: Create a role with 2 policies
  community.general.consul_role:
    host: consul1.example.com
    token: some_management_acl
    name: foo-role
    policies:
      - id: 783beef3-783f-f41f-7422-7087dc272765
      - name: "policy-1"

- name: Create a role with service identity
  community.general.consul_role:
    host: consul1.example.com
    token: some_management_acl
    name: foo-role-2
    service_identities:
      - name: web
        datacenters:
          - dc1

- name: Create a role with node identity
  community.general.consul_role:
    host: consul1.example.com
    token: some_management_acl
    name: foo-role-3
    node_identities:
      - name: node-1
        datacenter: dc2

- name: Remove a role
  community.general.consul_role:
    host: consul1.example.com
    token: some_management_acl
    name: foo-role-3
    state: absent
a,  
role:
  description: The role object.
  returned: success
  type: dict
  sample:
    {
      "CreateIndex": 39,
      "Description": "",
      "Hash": "Trt0QJtxVEfvTTIcdTUbIJRr6Dsi6E4EcwSFxx9tCYM=",
      "ID": "9a300b8d-48db-b720-8544-a37c0f5dafb5",
      "ModifyIndex": 39,
      "Name": "foo-role",
      "Policies": [
        {
          "ID": "b1a00172-d7a1-0e66-a12e-7a4045c4b774",
          "Name": "foo-access"
        }
      ]
    }
operation:
  description: The operation performed on the role.
  returned: changed
  type: str
  sample: update
)AnsibleModule)AUTH_ARGUMENTS_SPECOPERATION_READ_ConsulModulec                   .     e Zd ZdZdZdgZd fd	Z xZS )ConsulRoleModulezacl/roleroleidc                 v    |t         k(  r| j                  d| j                  d   gS t        t        |   ||      S )Nname)r   api_endpointparamssuperr   endpoint_url)self	operation
identifier	__class__s      q/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/consul_role.pyr   zConsulRoleModule.endpoint_url   s<    &%%vt{{6/BCC%t9)ZPP    )N)__name__
__module____qualname__r   
result_keyunique_identifiersr   __classcell__)r   s   @r   r   r      s!    LJQ Qr   r   str)type)r   r   Tr   )r!   requiredaliases)r!   r"   )	node_name
datacenterlist)r!   elements)service_namedatacentersdict)template_nametemplate_variables)r!   r'   optionsmutually_exclusiverequired_one_of)r!   r'   r-   presentabsent)defaultchoices)r   descriptionpoliciestemplated_policiesnode_identitiesservice_identitiesstatec                  \    t        t        d      } t        |       }|j                          y )NT)supports_check_mode)r   _ARGUMENT_SPECr   execute)moduleconsul_modules     r   mainr@     s*     F %V,Mr   __main__N)
__future__r   r   r   r!   __metaclass__DOCUMENTATIONEXAMPLESRETURNansible.module_utils.basicr   Aansible_collections.community.general.plugins.module_utils.consulr   r   r	   r   r*   NAME_ID_SPECNODE_ID_SPECSERVICE_ID_SPECTEMPLATE_POLICY_SPECr<   updater@   r    r   r   <module>rO      sw   A @@D#J
6 5 Q} Q 	5	
 vh?.
 54&B&51
 ED1(  ed+U#*+'( $
 
 
 )i-BC36   ) * zF r   