
    Vha                         d dl mZmZmZ eZddgddZdZdZdZ	d d	l
mZ d
dlmZmZmZ d Zd Zd Zd Zd Zd Zedk(  r e        yy)    )absolute_importdivisionprint_functionz1.1stableinterface	certified)metadata_versionstatussupported_bya  
module: asset
author:
  - Cameron Hurst (@wakemaster39)
  - Aljaz Kosir (@aljazkosir)
  - Manca Bizjak (@mancabizjak)
  - Miha Plesko (@miha-plesko)
  - Tadej Borovsak (@tadeboro)
short_description: Manage Sensu assets
description:
  - Create, update or delete Sensu Go asset.
  - For more information, refer to the Sensu documentation at
    U(https://docs.sensu.io/sensu-go/latest/reference/assets/).
version_added: 1.0.0
extends_documentation_fragment:
  - sensu.sensu_go.requirements
  - sensu.sensu_go.auth
  - sensu.sensu_go.name
  - sensu.sensu_go.namespace
  - sensu.sensu_go.state
  - sensu.sensu_go.labels
  - sensu.sensu_go.annotations
seealso:
  - module: sensu.sensu_go.asset_info
  - module: sensu.sensu_go.bonsai_asset
options:
  builds:
    description:
      - A list of asset builds used to define multiple artefacts which
        provide the named asset.
      - Required if I(state) is C(present).
    type: list
    elements: dict
    suboptions:
      url:
        description:
          - The URL location of the asset.
        type: str
        required: yes
      sha512:
        description:
          - The checksum of the asset.
        type: str
        required: yes
      filters:
        description:
          - A set of Sensu query expressions used to determine if the asset
            should be installed.
        type: list
        elements: str
      headers:
        description:
          - Additional headers to send when retrieving the asset, e.g. for
            authorization.
        type: dict
a3  
- name: Create a multiple-build asset
  sensu.sensu_go.asset:
    name: sensu-plugins-cpu-checks
    builds:
      - url: https://assets.bonsai.sensu.io/68546e739d96fd695655b77b35b5aabfbabeb056/sensu-plugins-cpu-checks_4.0.0_centos_linux_amd64.tar.gz
        sha512: 518e7c17cf670393045bff4af318e1d35955bfde166e9ceec2b469109252f79043ed133241c4dc96501b6636a1ec5e008ea9ce055d1609865635d4f004d7187b
        filters:
          - entity.system.os == 'linux'
          - entity.system.arch == 'amd64'
          - entity.system.platform == 'rhel'
      - url: https://assets.bonsai.sensu.io/68546e739d96fd695655b77b35b5aabfbabeb056/sensu-plugins-cpu-checks_4.0.0_alpine_linux_amd64.tar.gz
        sha512: b2da25ecd7642e6de41fde37d674fe19dcb6ee3d680e145e32289f7cfc352e6b5f9413ee9b701d61faeaa47b399aa30b25885dbc1ca432c4061c8823774c28f3
        filters:
          - entity.system.os == 'linux'
          - entity.system.arch == 'amd64'
          - entity.system.platform == 'alpine'

- name: Delete an asset
  sensu.sensu_go.asset:
    name: sensu-plugins-cpu-check
    state: absent
a!  
object:
  description: Object representing Sensu asset.
  returned: success
  type: dict
  sample:
    metadata:
      name: check_script
      namespace: default
    builds:
      - sha512: 4f926bf4328f...2c58ad9ab40c9e2edc31b288d066b195b21b
        url: http://example.com/asset.tar.gz
)AnsibleModule   )	argumentserrorsutilsc                      | d   dk(  r| d   syy )Nstatepresentbuildsz(builds must include at least one element )paramss    h/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/sensu/sensu_go/plugins/modules/asset.pyvalidate_module_paramsr   u   s    g)#h=    c                 &    t        d | D              S )Nc           
   3      K   | ]p  }|j                  d       |j                  d      t        |j                  di       xs i j                               t        |j                  dg       xs g       f r yw)sha512urlheadersfiltersN)get	frozensetitems).0bs     r   	<genexpr>z_build_set.<locals>.<genexpr>}   sk      
 	 	
h	e155B'-24467!%%	2&,"-	 s   A6A8)setr   s    r   
_build_setr'   |   s     
   r   c                 f    | yt        |       t        |      k7  ryt        |       t        |      k7  S )NT)lenr'   currentdesireds     r   _do_builds_differr-      s4     
7|s7|#g*W"555r   c                 V    t        | d   |d         ryt        j                  | |d      S )Nr   T)r-   r   	do_differr*   s     r   r/   r/      s,    *GH,=>??7GX66r   c                     t        j                  |       }| d   dk(  r9| d   D cg c]&  }t        j                  |g|j                          ( }}||d<   |S c c}w )Nr   r   r   )r   get_mutation_payloadget_spec_payloadkeys)r   payloadr#   r   s       r   build_api_payloadr5      sa    ,,V4Gg)#DJ8DTUq),,Q::UU"N Vs   +Ac                  (   dddgfg} t        | dt        t        j                  dddddd	      t        d
dt        t        d      t        d      t        d
d      t        d                              }t	        |j
                        }|r|j                  |       t        j                  |j
                  d         }t        j                  |j
                  d   d|j
                  d         }t        |j
                        }	 t        j                  |j
                  d   ||||j                  t              \  }}|j                  ||       y # t        j                   $ r%}|j                  t#        |             Y d }~y d }~ww xY w)Nr   r   r   Tauthname	namespacelabelsannotationslistdict)requiredstr)typeelements)r@   )r   r   r   r   )r@   rA   optionsr&   )required_ifsupports_check_modeargument_spec)msgassets)changedobject)r   r=   r   get_specr   r   	fail_jsonget_sensu_clientr   build_core_v2_pathr5   sync
check_moder/   	exit_jsonr   Errorr?   )	rC   modulerF   clientpathr4   rH   assetes	            r   mainrW      s   	)hZ(K  Wh !%  !% !#!& !#	
F: !
/C
S!''f(=>F##k"HfmmF.CD  .G%MM'"FD'6;L;Li
 	7<< %SV$$%s   AE F,FF__main__N)
__future__r   r   r   r@   __metaclass__ANSIBLE_METADATADOCUMENTATIONEXAMPLESRETURNansible.module_utils.basicr   module_utilsr   r   r   r   r'   r-   r/   r5   rW   __name__r   r   r   <module>rb      s}    A @  ! 7r0
 5 3 3	671%h zF r   