
    Vh                         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Z	 d dlmZmZ d d	lmZ d d
lmZ  e       Z G d de      Zy# e$ r dZY (w xY w)    )absolute_importdivisionprint_functiona  
name: dsv
author: Adam Migus (@amigus) <adam@migus.org>
short_description: Get secrets from Thycotic DevOps Secrets Vault
version_added: 1.0.0
description:
  - Uses the Thycotic DevOps Secrets Vault Python SDK to get Secrets from a DSV O(tenant) using a O(client_id) and O(client_secret).
requirements:
  - python-dsv-sdk - https://pypi.org/project/python-dsv-sdk/
options:
  _terms:
    description: The path to the secret, for example V(/staging/servers/web1).
    required: true
  tenant:
    description: The first format parameter in the default O(url_template).
    type: string
    env:
      - name: DSV_TENANT
    ini:
      - section: dsv_lookup
        key: tenant
    required: true
  tld:
    default: com
    description: The top-level domain of the tenant; the second format parameter in the default O(url_template).
    type: string
    env:
      - name: DSV_TLD
    ini:
      - section: dsv_lookup
        key: tld
    required: false
  client_id:
    description: The client_id with which to request the Access Grant.
    type: string
    env:
      - name: DSV_CLIENT_ID
    ini:
      - section: dsv_lookup
        key: client_id
    required: true
  client_secret:
    description: The client secret associated with the specific O(client_id).
    type: string
    env:
      - name: DSV_CLIENT_SECRET
    ini:
      - section: dsv_lookup
        key: client_secret
    required: true
  url_template:
    default: https://{}.secretsvaultcloud.{}/v1
    description: The path to prepend to the base URL to form a valid REST API request.
    type: string
    env:
      - name: DSV_URL_TEMPLATE
    ini:
      - section: dsv_lookup
        key: url_template
    required: false
z
_list:
  description:
    - One or more JSON responses to C(GET /secrets/{path}).
    - See U(https://dsv.thycotic.com/api/index.html#operation/getSecret).
  type: list
  elements: dict
z
- hosts: localhost
  vars:
    secret: "{{ lookup('community.general.dsv', '/test/secret') }}"
  tasks:
    - ansible.builtin.debug:
        msg: 'the password is {{ secret["data"]["password"] }}'
)AnsibleErrorAnsibleOptionsErrorF)SecretsVaultSecretsVaultErrorT)Display)
LookupBasec                   "    e Zd Zed        Zd Zy)LookupModulec                 N    	 t        di | }|S # t        $ r t        d      w xY w)N:python-dsv-sdk==0.0.1 must be installed to use this plugin )r   	TypeErrorr   )vault_parametersvaults     h/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/lookup/dsv.pyClientzLookupModule.Clientm   s8    	] 4#34EL 	][\\	]s    $c           	      h   t         rt        d      | j                  ||       t        j	                  | j                  d      | j                  d      | j                  d      | j                  d      | j                  d      d      }g }|D ]w  }t        j                  d	|        	 |j                  d
      }|dk(  rt        d|       t        j                  d|        |j                  |j                  |             y |S # t        $ r}t        d|j                         d }~ww xY w)Nr   )var_optionsdirecttenant	client_idclient_secrettldurl_template)r   r   r   r   r   zdsv_lookup term: z[/:] zInvalid secret path: z"DevOps Secrets Vault GET /secrets/z%DevOps Secrets Vault lookup failure: )sdk_is_missingr   set_optionsr   r   
get_optiondisplaydebuglstripr   vvvappendget_secret_jsonr	   message)	selfterms	variableskwargsr   resulttermpatherrors	            r   runzLookupModule.runu   s+   [\\Yv>##//(3!__[9!%!Au- $ ?
  	DMM-dV45{{6*2:-0EdV.LMM@GHe33D9:	 	 % ";EMM?K s   +AD	D1D,,D1N)__name__
__module____qualname__staticmethodr   r1   r       r   r   r   l   s    ] ]r6   r   N)
__future__r   r   r   type__metaclass__DOCUMENTATIONRETURNEXAMPLESansible.errorsr   r   r   thycotic.secrets.vaultr   r	   ImportErroransible.utils.displayr
   ansible.plugins.lookupr   r"   r   r   r6   r   <module>rB      sp   
 A @<|
 = * - )(: (  Ns   A AA