
    Vh                         d Z dZdZ	 ddlmZ ddlmZ ddlmZ ddl	m
Z ddlmZ d	 Zd
 Zd Zd Zd Zedk(  r e        yy# e$ r Y 6w xY w)a  
---
module: wafv2_resources
version_added: 1.5.0
author:
  - "Markus Bergholz (@markuman)"
short_description: wafv2_web_acl
description:
  - Apply or remove wafv2 to other aws resources.
options:
    state:
      description:
        - Whether the rule is present or absent.
      choices: ["present", "absent"]
      required: true
      type: str
    name:
      description:
        - The name of the web acl.
      type: str
    scope:
      description:
        - Scope of waf
      choices: ["CLOUDFRONT","REGIONAL"]
      type: str
    arn:
      description:
        - AWS resources (ALB, API Gateway or AppSync GraphQL API) ARN
      type: str
      required: true

extends_documentation_fragment:
  - amazon.aws.common.modules
  - amazon.aws.region.modules
  - amazon.aws.boto3
z
- name: add test alb to waf string03
  community.aws.wafv2_resources:
    name: string03
    scope: REGIONAL
    state: present
    arn: "arn:aws:elasticloadbalancing:eu-central-1:111111111:loadbalancer/app/test03/dd83ea041ba6f933"
z
resource_arns:
  description: Current resources where the wafv2 is applied on
  sample:
    - "arn:aws:elasticloadbalancing:eu-central-1:111111111:loadbalancer/app/test03/dd83ea041ba6f933"
  returned: Always, as long as the wafv2 exists
  type: list
    )BotoCoreError)ClientError)camel_dict_to_snake_dict)AnsibleCommunityAWSModule)wafv2_list_web_aclsc                 ~    	 | j                  |||      }|S # t        t        f$ r} ||d       Y d }~S d }~ww xY w)N)NameScopeIdzFailed to get wafv2 web acl.msg)get_web_aclr   r   )wafv2namescopeacl_idfail_json_awsresponsees          q/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/aws/plugins/modules/wafv2_resources.pyr   r   J   sO    =$$$e$G O ;' =a;<<O=s    <
7<c                 z    	 | j                  |      }|S # t        t        f$ r} ||d       Y d }~S d }~ww xY w)N)	WebACLArnzFailed to list wafv2 web acl.r   )list_resources_for_web_aclr   r   r   arnr   r   r   s        r   list_wafv2_resourcesr   R   sK    >33c3B O ;' >a<==O>    :
5:c                 |    	 | j                  ||      }|S # t        t        f$ r} ||d       Y d }~S d }~ww xY w)N)r   ResourceArnzFailed to add wafv2 web acl.r   )associate_web_aclr   r   )r   waf_arnr   r   r   r   s         r   add_wafv2_resourcesr"   Z   sM    =**W#*N O ;' =a;<<O=s    ;
6;c                 z    	 | j                  |      }|S # t        t        f$ r} ||d       Y d }~S d }~ww xY w)N)r   zFailed to remove wafv2 web acl.r   )disassociate_web_aclr   r   r   s        r   remove_resourcesr%   b   sN    @--#-> O ;' @a>??O@r   c            	      $   t        t        ddddg      t        d      t        dddg	      t        dd
            } t        | dddddggg      }|j                  j                  d      }|j                  j                  d      }|j                  j                  d      }|j                  j                  d      }|j                  }|j                  d      }t        |||j                        }d }	i }
d}|j                  d      D ](  }|j                  d      |k(  s|j                  d      }	* |	rPt        ||||	|j                        }|j                  d      j                  d      }t        |||j                        }
|dk(  r2|
re||
j                  d      vrRd}|sNt        |||j                        }
n5|dk(  r0|
r.||
j                  d      v rd}|st        |||j                        }
 |j                  dd|it        |
       y )NstrTpresentabsent)typerequiredchoices)r*   
CLOUDFRONTREGIONAL)r*   r,   )r*   r+   )stater   r   r   r/   r   r   )argument_specsupports_check_moderequired_ifr   r   FWebACLsr	   r   WebACLARNResourceArnschanged )dictAnsibleAWSModuleparamsget
check_modeclientr   r   r   r   r"   r%   	exit_jsonr   )arg_specmoduler/   r   r   r   r=   r   r   r   retvalchangeitemexisting_aclr!   s                  r   mainrF   j   s   y(6KLuj'ABed+	H  y67*;<=F MMg&E==V$DMMg&E
--

E
"C""JMM'"E #5%1E1EFHFFFY' $88Ft#XXd^F$ "5$vv?S?ST""8,007%eWf6J6JK	&**^44!0fFZFZ[F	(	fjj00!-eS&:N:NOFFHVH'?'GH    __main__N)DOCUMENTATIONEXAMPLESRETURNbotocore.exceptionsr   r   ImportError0ansible.module_utils.common.dict_transformationsr   >ansible_collections.community.aws.plugins.module_utils.modulesr   r:   <ansible_collections.community.aws.plugins.module_utils.wafv2r   r   r   r"   r%   rF   __name__r8   rG   r   <module>rR      sv   #J
	1/ V x \6Ir zF E  		s   A A
A