
    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 d dlmZ d dlmZmZmZ d d	lmZmZmZmZ d
 Zedk(  r e        yy)    )absolute_importdivisionprint_functionaU  
module: ssh_key
short_description: Add, remove or update SSH key
version_added: 1.2.0
author:
  - Felix Fontein (@felixfontein)
description:
  - Add, remove or update an SSH key stored in Hetzner's Robot.
seealso:
  - module: community.hrobot.ssh_key_info
    description: Query information on SSH keys.
extends_documentation_fragment:
  - community.hrobot.robot
  - community.hrobot.attributes
  - community.hrobot.attributes.actiongroup_robot

attributes:
  action_group:
    version_added: 1.6.0
  check_mode:
    support: full
  diff_mode:
    support: none
  idempotent:
    support: full

options:
  state:
    description:
      - Whether to make sure a public SSH key is present or absent.
      - V(present) makes sure that the SSH key is available, and potentially updates names for existing SSH public keys.
      - V(absent) makes sure that the SSH key is not available. The fingerprint or public key data is used for matching the
        key.
    required: true
    type: str
    choices:
      - present
      - absent
  name:
    description:
      - The public key's name.
      - Required if O(state=present), and ignored if O(state=absent).
    type: str
  fingerprint:
    description:
      - The MD5 fingerprint of the public SSH key to remove.
      - One of O(public_key) and O(fingerprint) are required if O(state=absent).
    type: str
  public_key:
    description:
      - The public key data in OpenSSH format.
      - 'Example: V(ssh-rsa AAAAB3NzaC1yc+..).'
      - One of O(public_key) and O(fingerprint) are required if O(state=absent).
      - Required if O(state=present).
    type: str
a~  
---
- name: Add an SSH key
  community.hrobot.ssh_key:
    hetzner_user: foo
    hetzner_password: bar
    state: present
    name: newKey
    public_key: ssh-rsa AAAAB3NzaC1yc+...

- name: Remove a SSH key by fingerprint
  community.hrobot.ssh_key:
    hetzner_user: foo
    hetzner_password: bar
    state: absent
    fingerprint: cb:8b:ef:a7:fe:04:87:3f:e5:55:cd:12:e3:e8:9f:99
a  
fingerprint:
  description:
    - The MD5 fingerprint of the key.
    - This is the value used to reference the SSH public key, for example in the M(community.hrobot.boot) module.
  returned: success
  type: str
  sample: cb:8b:ef:a7:fe:04:87:3f:e5:55:cd:12:e3:e8:9f:99
)AnsibleModule)	to_native)	urlencode)BASE_URLROBOT_DEFAULT_ARGUMENT_SPECfetch_url_json)FingerprintErrornormalize_fingerprintextract_fingerprintremove_commentc            
      z   t        t        ddddg      t        d      t        d      t        d            } | j                  t               t        | ddgd	dd
dgfd	dddgdfg      }|j                  d	   }|j                  d
   }|j                  d   }|j                  d   }	 |t        |      }nt        |      }dj                  t        |      }|dk(  rl|j                  rt        ||dg      \  }}	nt        ||dgdd      \  }}	|	dk(  rd}
n|	t        dj                  |	            d}
|j                  |
|       t        ||dg      \  }}	|	dk(  rd}
d}n9|	t        dj                  |	            d}d}
|d   j!                  d
      |k7  rd}
|
rU|j                  sId
|i}|s#t#        |      |d<   dj                  t              }ddi}t        ||t%        |      |d      \  }}|j                  |
|       y # t        $ r&}|j                  t        |             Y d }~qd }~ww xY w)NstrTpresentabsent)typerequiredchoices)r   )statenamefingerprint
public_key)r   r   r   r   r   r   )argument_specsupports_check_modemutually_exclusiverequired_if)msgz{0}/key/{1}	NOT_FOUND)accept_errorsDELETE)r!   methodallow_empty_resultFzUnexpected error {0})changedr   keydataz{0}/keyzContent-typez!application/x-www-form-urlencodedPOST)r'   headersr#   )dictupdater
   r   paramsr   r   r   	fail_jsonr   formatr	   
check_moder   AssertionError	exit_jsongetr   r   )r   moduler   r   r   r   excurldummyerrorr%   resultexistsr'   r)   s                  l/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/hrobot/plugins/modules/ssh_key.pymainr;   s   s   y(6KLue$U#	M 45# )
 i&,!78h =tD

F MM'"E== D--.K|,J-"/<K-j9K 

x
5C )&#k]SLE5)&#k][cx|}LE5KG !7!>!>u!EFFGkB #63{mLMFE		3::5ABB%=V$,Gv((D
 )*5DL""8,C!#FG&4
 W+>g  -Ys^,,-s   +H 	H:H55H:__main__N)
__future__r   r   r   r   __metaclass__DOCUMENTATIONEXAMPLESRETURNansible.module_utils.basicr   +ansible.module_utils.common.text.convertersr   +ansible.module_utils.six.moves.urllib.parser   ?ansible_collections.community.hrobot.plugins.module_utils.robotr	   r
   r   =ansible_collections.community.hrobot.plugins.module_utils.sshr   r   r   r   r;   __name__     r:   <module>rJ      sc    A @7r$
 5 A A  Q?h zF rI   