%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3.9/site-packages/ansible/modules/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3.9/site-packages/ansible/modules/__pycache__/rpm_key.cpython-39.opt-1.pyc

a

�)g�!�@s�ddlmZmZmZeZdZdZdZddl	Z	ddl
ZddlZddl
mZddlmZddlmZd	d
�ZGdd�de�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_nativecCs d}tt�|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[src@s\eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�ZdS)�RpmKeyc	Cs�d}d}||_|j�dd�|_|jd}|jd}|jd}|rP|�dd���}|j�d	�|_|jsv|jjd
dd�|_d|vr�|�|�}|�|�}d}n>|�	|�r�|}n.t
j�|�r�|}|�|�}n|jj
d
|d�|�|�}|dk�rr|�|��r|jdd�nl|�s|jj
dd�|�rH|�|�}||k�rH|jj
d||fd�|�|�|�rd|j�|�|jdd�n0|�|��r�|�|�|jdd�n|jdd�dS)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')�moduleZget_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_keyfilerrr�keyidZhas_fingerprintrrr�__init__csT










�

zRpmKey.__init__cCs�t|j|�\}}|ddkr6|jjd||dfd�|��}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: %srrzNot a public key: %szw+b)rrr(�readr�tempfileZmkstempZadd_cleanup_filer%�fdopen�write�close)r.�urlZrsp�inforZtmpfdZtmpnameZtmpfilerrrr"�s
zRpmKey.fetch_keycCs@|����}|�d�r"|dd�S|�d�r8|dd�S|SdS)zhEnsure a keyid doesn't have a leading 0x, has leading or trailing whitespace, and make sure is uppercase�0x�NZ0X)�stripr!�
startswith)r.r0�retrrrr)�s

zRpmKey.normalize_keyidcCs`|�|jdddd|g�\}}|��D](}|��}|�d�r$|�d�dSq$|jjdd	�dS)
N�--no-tty�--batch�
--with-colons�--fixed-list-modezpub:�:��Unexpected gpg outputr��execute_commandr�
splitlinesr=r>�splitrr(�r.r/�stdout�stderr�linerrrr#�s
zRpmKey.getkeyidc	Csb|�|jddddd|g�\}}|��D](}|��}|�d�r&|�d�dSq&|jjd	d
�dS)Nr@rArBrCz--with-fingerprintzfpr:rD�	rFrrGrKrrrr+�s
�

	zRpmKey.getfingerprintcCstjd|tjd�S)z5Verifies if a key, as provided by the user is a keyidz(0x)?[0-9a-f]{8})�flags)rr�
IGNORECASE)r.Zkeystrrrrr$�szRpmKey.is_keyidcCs4|jj|dd�\}}}|dkr,|jj|d�||fS)NT)Zuse_unsafe_shellrr)r�run_commandr()r.�cmd�rcrLrMrrrrH�szRpmKey.execute_commandcCsr|jd}|j�|�\}}}|dkr(dS|d|jd7}|�|�\}}|��D]}||�d�dvrPdSqPdS)	Nz -q  gpg-pubkeyrFz --qf "%{description}" | z3 --no-tty --batch --with-colons --fixed-list-mode -rDrET)rrrRrrHrIrJ)r.r0rSrTrLrMrNrrrr*�s
zRpmKey.is_key_importedcCs|jjs|�|jd|g�dS)Nz--import)r�
check_moderHr)r.r/rrrr,�szRpmKey.import_keyc	Cs0|jjs,|�|jddd|dd���g�dS)Nz--erasez--allmatchesz
gpg-pubkey-%si����)rrUrHr�lower)r.r0rrrr-�szRpmKey.drop_keyN)
�__name__�
__module__�__qualname__r1r"r)r#r+r$rHr*r,r-rrrrras5
	rc	CsJtttddddgd�tdddd�tdd�td	dd
�d�dd�}t|�dS)
N�strrZabsent)�type�default�choicesTF)r[rZno_log)r[r
)r[r\)rrrZvalidate_certs)Z
argument_specZsupports_check_mode)r�dictr)rrrr�main�s
��
r_�__main__)Z
__future__rrrr[Z
__metaclass__Z
DOCUMENTATIONZEXAMPLESZRETURNrZos.pathr%r5Zansible.module_utils.basicrZansible.module_utils.urlsrZansible.module_utils._textrr�objectrr_rWrrrr�<module>s -

Zerion Mini Shell 1.0