
    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  ed       ed	d
       ed
       edd
       edddg      dZej#                  e        G d de      Zd Zedk(  r e        yy)    )absolute_importdivisionprint_functionux  
module: consul_policy
short_description: Manipulate Consul policies
version_added: 7.2.0
description:
  - Allows the addition, modification and deletion of policies 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.actiongroup_consul
  - community.general.consul.token
  - community.general.attributes
attributes:
  check_mode:
    support: full
    version_added: 8.3.0
  diff_mode:
    support: partial
    version_added: 8.3.0
    details:
      - In check mode the diff will miss operational attributes.
  action_group:
    version_added: 8.3.0
options:
  state:
    description:
      - Whether the policy should be present or absent.
    choices: ['present', 'absent']
    default: present
    type: str
  valid_datacenters:
    description:
      - Valid datacenters for the policy. All if list is empty.
    type: list
    elements: str
  name:
    description:
      - The name that should be associated with the policy, this is opaque to Consul.
    required: true
    type: str
  description:
    description:
      - Description of the policy.
    type: str
  rules:
    type: str
    description:
      - Rule document that should be associated with the current policy.
a  
- name: Create a policy with rules
  community.general.consul_policy:
    host: consul1.example.com
    token: some_management_acl
    name: foo-access
    rules: |
      key "foo" {
          policy = "read"
      }
      key "private/foo" {
          policy = "deny"
      }

- name: Update the rules associated to a policy
  community.general.consul_policy:
    host: consul1.example.com
    token: some_management_acl
    name: foo-access
    rules: |
      key "foo" {
          policy = "read"
      }
      key "private/foo" {
          policy = "deny"
      }
      event "bbq" {
          policy = "write"
      }

- name: Remove a policy
  community.general.consul_policy:
    host: consul1.example.com
    token: some_management_acl
    name: foo-access
    state: absent
a  
policy:
  description: The policy as returned by the Consul HTTP API.
  returned: always
  type: dict
  sample:
    CreateIndex: 632
    Description: Testing
    Hash: rj5PeDHddHslkpW7Ij4OD6N4bbSXiecXFmiw2SYXg2A=
    Name: foo-access
    Rules: |-
      key "foo" {
          policy = "read"
      }
      key "private/foo" {
          policy = "deny"
      }
operation:
  description: The operation performed.
  returned: changed
  type: str
  sample: update
)AnsibleModule)AUTH_ARGUMENTS_SPECOPERATION_READ_ConsulModuleT)requiredFstr)r
   type)r   list)r   elementspresentabsent)defaultchoices)namedescriptionrulesvalid_datacentersstatec                   .     e Zd ZdZdZdgZd fd	Z xZS )ConsulPolicyModulez
acl/policypolicyidc                 v    |t         k(  r| j                  d| j                  d   gS t        t        |   ||      S )Nr   )r   api_endpointparamssuperr   endpoint_url)self	operation
identifier	__class__s      s/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/consul_policy.pyr    zConsulPolicyModule.endpoint_url   s<    &%%vt{{6/BCC';IzRR    )N)__name__
__module____qualname__r   
result_keyunique_identifiersr    __classcell__)r$   s   @r%   r   r      s!    LJS Sr&   r   c                  \    t        t        d      } t        |       }|j                          y )NT)supports_check_mode)r   _ARGUMENT_SPECr   execute)moduleconsul_modules     r%   mainr3      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	   dictr/   updater   r3   r'    r&   r%   <module>r?      s    A @2h$L
0 5  $U3u6E:)i-BC   ) *S S zF r&   