
    Vh                     R    d Z dZdZddlmZ  G d de      Zd Zedk(  r e        y	y	)
a  
---
module: federation_mapping
short_description: Manage a federation mapping
author: OpenStack Ansible SIG
description:
  - Manage a federation mapping.
options:
  name:
    description:
      - The name of the mapping to manage.
    required: true
    type: str
    aliases: ['id']
  rules:
    description:
      - The rules that comprise the mapping. These are pairs of I(local) and
        I(remote) definitions. For more details on how these work please see
        the OpenStack documentation
        U(https://docs.openstack.org/keystone/latest/admin/federation/mapping_combinations.html).
      - Required if I(state) is C(present).
    type: list
    elements: dict
    suboptions:
      local:
        description:
        - Information on what local attributes will be mapped.
        required: true
        type: list
        elements: dict
      remote:
        description:
        - Information on what remote attributes will be mapped.
        required: true
        type: list
        elements: dict
  state:
    description:
      - Whether the mapping should be C(present) or C(absent).
    choices: ['present', 'absent']
    default: present
    type: str
notes:
    - Name equals the ID of a mapping.
extends_documentation_fragment:
  - openstack.cloud.openstack
a  
- name: Create a new mapping
  openstack.cloud.federation_mapping:
    cloud: example_cloud
    name: example_mapping
    rules:
    - local:
      - user:
          name: '{0}'
      - group:
          id: '0cd5e9'
      remote:
      - type: UserName
      - type: orgPersonType
        any_one_of:
        - Contractor
        - SubContractor

- name: Delete a mapping
  openstack.cloud.federation_mapping:
    name: example_mapping
    state: absent
a  
mapping:
  description: Dictionary describing the federation mapping.
  returned: always
  type: dict
  contains:
    id:
      description: The id of the mapping
      type: str
      sample: "ansible-test-mapping"
    name:
      description: Name of the mapping. Equal to C(id).
      type: str
      sample: "ansible-test-mapping"
    rules:
      description: List of rules for the mapping
      type: list
    )OpenStackModulec                       e Zd Z e eddg       edd e eddd       eddd                   ed	d
d	g            Z edd	dgfgd      Zd Zd Zd Zd Z	d Z
d Zy)IdentityFederationMappingModuleTid)requiredaliaseslistdict)r   typeelements)localremote)r   r   optionspresentabsent)defaultchoices)namerulesstater   r   )required_ifsupports_check_modec                    | j                   d   }| j                   d   }| j                  j                  j                  |      }| j                  j
                  r"| j                  | j                  ||             |dk(  r6|s4| j                         }| j                  d|j                  d             y |dk(  rT|rR| j                  |      }|r| j                  ||      }| j                  t        |      |j                  d             y |d	k(  r&|r$| j                  |       | j                  d       y |d	k(  r|s| j                  d       y y y )
Nr   r   )changedr   TF)computed)r   mappingr   )paramsconnidentityfind_mappingansible
check_mode	exit_json_will_change_createto_dict_build_update_updatebool_delete)selfr   r   r   updates        v/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/openstack/cloud/plugins/modules/federation_mapping.pyrunz#IdentityFederationMappingModule.runw   s2   G$[[ ))$$11"5<<""NN4#4#4UG#DNEIgllnGNN4#*??E?#B  D iG''0F,,w7NN4<#*??E?#B  D h7LL!NN4N(hwNN5N) (/    c                      i }t         j                  d         dk  r j                  d       t         fddD              }|r||d<   |S )Nr      z At least one rule must be passed)msgc              3      K   | ]G  }|j                   v r7j                   |   (j                   |   |   k7  r|j                   |   f I y wN)r   ).0kr   r+   s     r-   	<genexpr>z@IdentityFederationMappingModule._build_update.<locals>.<genexpr>   sR      <!$++-$++a.2L"kk!n
: dkk!n- <s   AA)r   
attributes)lenr   	fail_jsonr
   r+   r   r,   r8   s   ``  r-   r'   z-IdentityFederationMappingModule._build_update   sW    t{{7#$q(NNANB <y < <
 #-F< r/   c                     | j                   j                  j                  | j                  d   | j                  d         S )Nr   r   )r   r   )r   r   create_mappingr   )r+   s    r-   r%   z'IdentityFederationMappingModule._create   s=    yy!!00DKK4G7;{{77K 1 M 	Mr/   c                 b    | j                   j                  j                  |j                         y r4   )r   r   delete_mappingr   )r+   r   s     r-   r*   z'IdentityFederationMappingModule._delete   s    		))'**5r/   c                     |j                  d      }|r1 | j                  j                  j                  |j                  fi |}|S )Nr8   )getr   r   update_mappingr   r;   s       r-   r(   z'IdentityFederationMappingModule._update   sF    ZZ-
7dii((77

 F:DFG r/   c                 f    |dk(  r|sy|dk(  r|rt        | j                  |            S |dk(  r|ryy)Nr   Tr   F)r)   r'   )r+   r   r   s      r-   r$   z,IdentityFederationMappingModule._will_change   sA    IgiG**7344h7 r/   N)__name__
__module____qualname__r
   argument_specmodule_kwargsr.   r'   r%   r*   r(   r$    r/   r-   r   r   e   s    4$0DvGTH 9x.CD
M y7)45 M
*BM6	r/   r   c                  &    t               }  |         y r4   )r   )modules    r-   mainrL      s    ,.F
Hr/   __main__N)DOCUMENTATIONEXAMPLESRETURNBansible_collections.openstack.cloud.plugins.module_utils.openstackr   r   rL   rD   rI   r/   r-   <module>rR      sI   .`0
& _Zo Zz
 zF r/   