
    Vh                         d dl mZmZmZ eZdZdZdZd dl	Z	d dl
mZ d dlmZmZ d dlmZ  G d	 d
e      Z	 	 ddZd Zd Zd Zedk(  r e        yy)    )absolute_importdivisionprint_functiona  
module: ipa_otpconfig
author: justchris1 (@justchris1)
short_description: Manage FreeIPA OTP Configuration Settings
version_added: 2.5.0
description:
  - Modify global configuration settings of a FreeIPA Server with respect to OTP (One Time Passwords).
attributes:
  check_mode:
    support: full
  diff_mode:
    support: none
options:
  ipatokentotpauthwindow:
    description: TOTP authentication window in seconds.
    aliases: ["totpauthwindow"]
    type: int
  ipatokentotpsyncwindow:
    description: TOTP synchronization window in seconds.
    aliases: ["totpsyncwindow"]
    type: int
  ipatokenhotpauthwindow:
    description: HOTP authentication window in number of hops.
    aliases: ["hotpauthwindow"]
    type: int
  ipatokenhotpsyncwindow:
    description: HOTP synchronization window in hops.
    aliases: ["hotpsyncwindow"]
    type: int
extends_documentation_fragment:
  - community.general.ipa.documentation
  - community.general.attributes
a>  
- name: Ensure the TOTP authentication window is set to 300 seconds
  community.general.ipa_otpconfig:
    ipatokentotpauthwindow: '300'
    ipa_host: localhost
    ipa_user: admin
    ipa_pass: supersecret

- name: Ensure the TOTP synchronization window is set to 86400 seconds
  community.general.ipa_otpconfig:
    ipatokentotpsyncwindow: '86400'
    ipa_host: localhost
    ipa_user: admin
    ipa_pass: supersecret

- name: Ensure the HOTP authentication window is set to 10 hops
  community.general.ipa_otpconfig:
    ipatokenhotpauthwindow: '10'
    ipa_host: localhost
    ipa_user: admin
    ipa_pass: supersecret

- name: Ensure the HOTP synchronization window is set to 100 hops
  community.general.ipa_otpconfig:
    ipatokenhotpsyncwindow: '100'
    ipa_host: localhost
    ipa_user: admin
    ipa_pass: supersecret
ze
otpconfig:
  description: OTP configuration as returned by IPA API.
  returned: always
  type: dict
N)AnsibleModule)	IPAClientipa_argument_spec)	to_nativec                   *     e Zd Z fdZd Zd Z xZS )OTPConfigIPAClientc                 2    t         t        |   ||||       y )N)superr   __init__)selfmodulehostportprotocol	__class__s        s/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/ipa_otpconfig.pyr   zOTPConfigIPAClient.__init__Z   s     $0tXN    c                 (    | j                  dd       S )Notpconfig_show)methodname
_post_json)r   s    r   r   z!OTPConfigIPAClient.otpconfig_show]   s    &6TBBr   c                 *    | j                  d||      S )Notpconfig_mod)r   r   itemr   )r   r   r   s      r   r   z OTPConfigIPAClient.otpconfig_mod`   s    oDtLLr   )__name__
__module____qualname__r   r   r   __classcell__)r   s   @r   r   r   Y   s    OCMr   r   c                     i }| t        |       |d<   |t        |      |d<   |t        |      |d<   |t        |      |d<   |S )Nipatokentotpauthwindowipatokentotpsyncwindowipatokenhotpauthwindowipatokenhotpsyncwindow)str)r%   r&   r'   r(   configs        r   get_otpconfig_dictr+   d   sj     F)+./E+F'()+./E+F'()+./E+F'()+./E+F'(Mr   c                 (    | j                  ||      S )N)ipa_datamodule_data)get_diff)client
ipa_configmodule_configs      r   get_otpconfig_diffr3   t   s    ??JM?JJr   c                 0   t        | j                  j                  d      | j                  j                  d      | j                  j                  d      | j                  j                  d            }|j                         }t	        |||      }d}i }|D ]K  }|j                  |      |j                  |d       k7  s(d}|j                  ||j                  |      i       M |r| j                  s|j                  d |       ||j                         fS )	Nr%   r&   r'   r(   r%   r&   r'   r(   FT)r   r   )r+   paramsgetr   r3   update
check_moder   )r   r0   module_otpconfigipa_otpconfigdiffchangednew_otpconfig
module_keys           r   ensurer@   x   s   )%}}001IJ%}}001IJ%}}001IJ%}}001IJ	 ))+Mfm5EFDGM Q

+}/@/@T/RRG  *.>.B.B:.N!OPQ
 v(($];F))+++r   c            
      X   t               } | j                  t        ddgd      t        ddgd      t        ddgd      t        ddgd             t        | d	
      }t	        ||j
                  d   |j
                  d   |j
                  d         }	 |j                  |j
                  d   |j
                  d          t        ||      \  }}|j                         y # t        $ r8}|j                  t        |      t        j                                Y d }~Pd }~ww xY w)NinttotpauthwindowF)typealiasesno_logtotpsyncwindowhotpauthwindowhotpsyncwindowr5   T)argument_specsupports_check_modeipa_hostipa_portipa_prot)r   r   r   r   ipa_useripa_pass)usernamepassword)msg	exception)r=   	otpconfig)r   r8   dictr   r   r6   loginr@   	Exception	fail_jsonr	   	traceback
format_exc	exit_json)rJ   r   r0   r=   rU   es         r   mainr^      s4   %'M#9I8JSXY#9I8JSXY#9I8JSXY#9I8JSXY	   # F
  ]]:&]]:&z*	FM]]:.]]:. 	 	
 $FF3 W	:  MYq\Y5I5I5KLLMs   <C( (	D)1.D$$D)__main__)NNNN)
__future__r   r   r   rD   __metaclass__DOCUMENTATIONEXAMPLESRETURNrZ   ansible.module_utils.basicr   >ansible_collections.community.general.plugins.module_utils.ipar   r   +ansible.module_utils.common.text.convertersr	   r   r+   r3   r@   r^   r     r   r   <module>ri      sy    A @ D<
  4 g AM M LPKO K,.;B zF r   