관리-도구
편집 파일: rpm_key.cpython-39.pyc
a �)g�! � @ s� d dl mZmZmZ eZdZdZdZd dl Z d dl Zd dlZd dl mZ d dlmZ d dlmZ d d � ZG dd� de�Zd d� Zedkr�e� dS )� )�absolute_import�division�print_functiona --- module: rpm_key author: - Hector Acosta (@hacosta) <hector.acosta@gazzang.com> short_description: Adds or removes a gpg key from the rpm db description: - Adds or removes (rpm --import) a gpg key to your rpm database. version_added: "1.3" options: key: description: - Key that will be modified. Can be a url, a file on the managed node, or a keyid if the key already exists in the database. type: str required: true state: description: - If the key will be imported or removed from the rpm db. type: str default: present choices: [ absent, present ] validate_certs: description: - If C(false) and the C(key) is a url starting with https, SSL certificates will not be validated. - This should only be used on personally controlled sites using self-signed certificates. type: bool default: 'yes' fingerprint: description: - The long-form fingerprint of the key being imported. - This will be used to verify the specified key. type: str version_added: 2.9 extends_documentation_fragment: - action_common_attributes attributes: check_mode: support: full diff_mode: support: none platform: platforms: rhel a - name: Import a key from a url ansible.builtin.rpm_key: state: present key: http://apt.sw.be/RPM-GPG-KEY.dag.txt - name: Import a key from a file ansible.builtin.rpm_key: state: present key: /path/to/key.gpg - name: Ensure a key is not present in the db ansible.builtin.rpm_key: state: absent key: DEADB33F - name: Verify the key, using a fingerprint, before import ansible.builtin.rpm_key: key: /path/to/RPM-GPG-KEY.dag.txt fingerprint: EBC6 E12C 62B1 C734 026B 2122 A20E 5214 6B8D 79E6 �#N)� AnsibleModule)� fetch_url)� to_nativec C s d}t t�|t| dd�tj��S )zVerifies if string is a pubkeyzP.*?(-----BEGIN PGP PUBLIC KEY BLOCK-----.*?-----END PGP PUBLIC KEY BLOCK-----).*Zsurrogate_or_strict)�errors)�bool�re�matchr �DOTALL)�stringZ pgp_regex� r �;/usr/lib/python3.9/site-packages/ansible/modules/rpm_key.py� is_pubkey[ s r c @ s\ e Zd Zdd� Zdd� Zdd� Zdd� Zd d � Zdd� Zd d� Z dd� Z dd� Zdd� ZdS )�RpmKeyc C s� d }d}|| _ | j �dd�| _|jd }|jd }|jd }|rP|�dd��� }| j �d �| _| jsv| j jd dd�| _d|v r�| �|�}| �|�}d}n>| � |�r�|}n.t j�|�r�|}| �|�}n| j j d | d� | �|�}|dk�rr| �|��r|jdd� nl|�s| j j dd� |�rH| �|�}||k�rH| j j d||f d� | �|� |�rd| j �|� |jdd� n0| �|��r�| �|� |jdd� n|jdd� d S )NF�rpmT�state�key�fingerprint� � �gpgZgpg2)�requiredz://zNot a valid key %s��msg�present)Zchangedz0When importing a key, a valid file must be givenzHThe specified fingerprint, '%s', does not match the key fingerprint '%s')�moduleZget_bin_pathr �params�replace�upperr � fetch_key�getkeyid�is_keyid�os�path�isfile� fail_json�normalize_keyid�is_key_importedZ exit_json�getfingerprint� import_keyZcleanup�drop_key) �selfr �keyfileZshould_cleanup_keyfiler r r �keyidZhas_fingerprintr r r �__init__c sT � zRpmKey.__init__c C s� t | j|�\}}|d dkr6| jjd||d f d� |�� }t|�sX| jjd| d� t�� \}}| j�|� t� |d�}|� |� |�� |S )z;Downloads a key from url, returns a valid path to a gpg key�status�� z)failed to fetch key at %s , error was: %sr r zNot a public key: %szw+b)r r r( �readr �tempfileZmkstempZadd_cleanup_filer% �fdopen�write�close)r. �urlZrsp�infor ZtmpfdZtmpnameZtmpfiler r r r"