o
    i                     @   s\   d dl Z d dlZd dlZd dlmZ d dlmZmZ d dlm	Z	 G dd de
Zdd ZdS )	    N)api)report_errorsreport_warnings)pretty_jsonc                   @   sH   e Zd Zedd Zedd Zedd Zedd Zed	d
 ZdS )DashboardClientc                 C   s  |j ddd}|jddd}d|_|j dd	d}|jd
dd |jdddd |jdddgdd |jddd |jdddd |jdtdd |jdtdd |j| jd  |j d!d"d}|jd#d$d |jd
d%d |jdd&dd |jdddgdd |jddd |jdddd |jdtdd |jdtdd |j| jd  |j d'd(d}|jd#d)d |j| jd  |j d*d+d}|jd#d,d |j| j	d  d S )-N	dashboardz#Create, edit, and delete dashboards)helpVerbsverb)titledestTpostzCreate dashboardsr   ztitle for the new dashboardwidgetsz@widget definitions as a JSON string. If unset, reads from stdin.?)r   nargslayout_typeorderedfreezLayout type of the dashboard.)choicesr   z--descriptionz"Short description of the dashboardz--read_onlyz`Whether this dashboard is read-only. If True, only the author and admins can make changes to it.
store_true)r   actionz--notify_listzLA json list of user handles, e.g. '["user1@domain.com", "user2@domain.com"]')typer   z--template_variablesziA json list of template variable dicts, e.g. '[{"name": "host", "prefix": "host", "default": "my-host"}]')funcupdatezUpdate existing dashboardsdashboard_idz,Dashboard to replace with the new definitionzNew title for the dashboardz?Widget definitions as a JSON string. If unset, reads from stdinshowzShow a dashboard definitionzDashboard to showdeletezDelete dashboardszDashboard to delete)

add_parseradd_subparsersrequiredadd_argument_json_stringset_defaults_post_update_show_delete)cls
subparsersparserverb_parserspost_parserupdate_parsershow_parserdelete_parser r/   N/home/ubuntu/.local/lib/python3.10/site-packages/datadog/dogshell/dashboard.pysetup_parser   sp   zDashboardClient.setup_parserc                 C   s   |j t_|j}|j}|jd u rtj }t	|}|j
||jd}|jr)|j|d< |jr1|j|d< |jr9|j|d< |jrA|j|d< tjjdi |}t| t| |dkr^tt| d S tt| d S )Nr   r   r   descriptionis_read_onlynotify_listtemplate_variablesprettyr/   )timeoutr   _timeoutformatr   sysstdinreadjsonloadsr   r   r3   	read_onlyr5   r6   	Dashboardcreater   r   printr   dumpsr'   argsr:   r   payloadresr/   r/   r0   r#   Z   s*   






zDashboardClient._postc                 C   s   |j t_|j}|j}|jd u rtj }t	|}|j
||jd}|jr)|j|d< |jr1|j|d< |jr9|j|d< |jrA|j|d< tjj|jfi |}t| t| |dkr`tt| d S tt| d S )Nr2   r3   r4   r5   r6   r7   )r8   r   r9   r:   r   r;   r<   r=   r>   r?   r   r   r3   r@   r5   r6   rA   r   r   r   r   rC   r   rD   rE   r/   r/   r0   r$   w   s*   






zDashboardClient._updatec                 C   sV   |j t_|j}tj|j}t| t| |dkr"t	t
| d S t	t| d S )Nr7   )r8   r   r9   r:   rA   getr   r   r   rC   r   r>   rD   )r'   rF   r:   rH   r/   r/   r0   r%      s   zDashboardClient._showc                 C   s6   |j t_tj|j}|d urt| t| d S d S )N)r8   r   r9   rA   r   r   r   r   )r'   rF   rH   r/   r/   r0   r&      s   zDashboardClient._deleteN)	__name__
__module____qualname__classmethodr1   r#   r$   r%   r&   r/   r/   r/   r0   r      s    
G


r   c                 C   s&   zt | W S  ty   tdw )Nzbad json parameter)r>   r?   	ExceptionargparseArgumentTypeError)strr/   r/   r0   r!      s
   
r!   )r>   r;   rO   datadogr   datadog.dogshell.commonr   r   datadog.util.formatr   objectr   r!   r/   r/   r/   r0   <module>   s    