
    Vh5                         d dl mZmZmZ eZdZdZdZd dl	m
Z
mZ d dlmZ d dlmZmZ d dlmZ  G d	 d
e      Z G d de      Z G d de      Zy)    )absolute_importdivisionprint_functiona  
name: lastpass
author:
  - Andrew Zenk (!UNKNOWN) <azenk@umn.edu>
requirements:
  - lpass (command line utility)
  - must have already logged into LastPass
short_description: fetch data from LastPass
description:
  - Use the lpass command line utility to fetch specific fields from LastPass.
options:
  _terms:
    description: Key from which you want to retrieve the field.
    required: true
    type: list
    elements: str
  field:
    description: Field to return from LastPass.
    default: 'password'
    type: str
z
- name: get 'custom_field' from LastPass entry 'entry-name'
  ansible.builtin.debug:
    msg: "{{ lookup('community.general.lastpass', 'entry-name', field='custom_field') }}"
zC
_raw:
  description: Secrets stored.
  type: list
  elements: str
)PopenPIPE)AnsibleError)to_bytesto_text)
LookupBasec                       e Zd Zy)LPassExceptionN)__name__
__module____qualname__     m/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/lookup/lastpass.pyr   r   3   s    r   r   c                   J    e Zd ZddZed        Zed        Zd	dZd
dZd Z	y)LPassc                     || _         y N	_cli_path)selfpaths     r   __init__zLPass.__init__9   s	    r   c                     | j                   S r   r   )r   s    r   cli_pathzLPass.cli_path<   s    ~~r   c                 p    | j                  | j                  d      dd      \  }}|j                  d      S )Nlogoutzn
   )stdinexpected_rcz'Are you sure you would like to log out?)_run_build_args
startswith)r   outerrs      r   	logged_inzLPass.logged_in@   s6    99T--h7uRS9TS~~GHHr   Nc                    t        | j                  g|z   t        t        t              }|j                  t	        |            \  }}|j                         }||k7  rt        |      t        |d      t        |d      fS )N)stdoutstderrr"   surrogate_or_strict)errors)r   r   r   communicater	   waitr   r
   )r   argsr"   r#   pr'   r(   rcs           r   r$   z
LPass._runE   sl    4==/D(d$O==%1SVVX %%s#8973Od;eeer   c                 &    |g }|g|z   }|dgz  }|S )Nz--color=neverr   )r   commandr1   s      r   r%   zLPass._build_argsM   s*    <Dy4!!r   c                     |dv r9| j                  | j                  dd| |g            \  }}|j                         S | j                  | j                  dd| |g            \  }}|j                         S )N)usernamepasswordurlnotesidnameshowz--z--field=)r$   r%   strip)r   keyfieldr'   r(   s        r   	get_fieldzLPass.get_fieldT   s|    JJyy!1!1&Rw<:M!NOHC yy{ yy!1!1&XeW;Ms:S!TUHCyy{r   )lpass)Nr   r   )
r   r   r   r   propertyr   r)   r$   r%   rA   r   r   r   r   r   7   sA       I Ifr   r   c                       e Zd ZddZy)LookupModuleNc                     | j                  ||       | j                  d      }t               }|j                  st	        d      g }|D ]#  }|j                  |j                  ||             % |S )N)var_optionsdirectr@   z8Not logged into LastPass: please run 'lpass login' first)set_options
get_optionr   r)   r   appendrA   )r   terms	variableskwargsr@   lpvaluesterms           r   runzLookupModule.run^   sm    Yv>(W||YZZ 	5DMM",,tU34	5r   r   )r   r   r   rR   r   r   r   rE   rE   \   s    r   rE   N)
__future__r   r   r   type__metaclass__DOCUMENTATIONEXAMPLESRETURN
subprocessr   r   ansible.errorsr   +ansible.module_utils.common.text.convertersr	   r
   ansible.plugins.lookupr   r   objectr   rE   r   r   r   <module>r^      s[    C B,
 # ' I -	\ 	"F "J: r   