
    Vh                     v    d dl mZmZmZ eZdZdZd dlm	Z	 d dl
mZ d dlmZ d dlZd Zd	 Zed
k(  r e        yy)    )absolute_importdivisionprint_functiona  
module: newrelic_deployment
author: "Matt Coddington (@mcodd)"
short_description: Notify New Relic about app deployments
description:
  - Notify New Relic about app deployments (see U(https://docs.newrelic.com/docs/apm/new-relic-apm/maintenance/record-monitor-deployments/)).
extends_documentation_fragment:
  - community.general.attributes
attributes:
  check_mode:
    support: full
  diff_mode:
    support: none
options:
  token:
    type: str
    description:
      - API token to place in the Api-Key header.
    required: true
  app_name:
    type: str
    description:
      - The value of C(app_name) in the C(newrelic.yml) file used by the application.
      - One of O(app_name) or O(application_id) is required.
    required: false
  application_id:
    type: str
    description:
      - The application ID found in the metadata of the application in APM.
      - One of O(app_name) or O(application_id) is required.
    required: false
  changelog:
    type: str
    description:
      - A list of changes for this deployment.
    required: false
  description:
    type: str
    description:
      - Text annotation for the deployment - notes for you.
    required: false
  revision:
    type: str
    description:
      - A revision number (for example, git commit SHA).
    required: true
  user:
    type: str
    description:
      - The name of the user/process that triggered this deployment.
    required: false
  validate_certs:
    description:
      - If V(false), SSL certificates will not be validated. This should only be used on personally controlled sites using
        self-signed certificates.
    required: false
    default: true
    type: bool
  app_name_exact_match:
    type: bool
    description:
      - If this flag is set to V(true) then the application ID lookup by name would only work for an exact match. If set to
        V(false) it returns the first result.
    required: false
    default: false
    version_added: 7.5.0
requirements: []
z
- name: Notify New Relic about an app deployment
  community.general.newrelic_deployment:
    token: AAAAAA
    app_name: myapp
    user: ansible deployment
    revision: '1.0'
)AnsibleModule)	fetch_url)quoteNc                     t        t        t        dd      t        d      t        d      t        d      t        d      t        d      t        d      t        dd      t        ddd      	      d	d
ggddd	gfgd      } i }| j                  d	   r!| j                  d
   r| j                  d       d }| j                  d	   rt	        |       }n1| j                  d
   r| j                  d
   }n| j                  d       |"| j                  d| j                  d	   z         dD ]$  }| j                  |   s| j                  |   ||<   & | j
                  r| j                  d       dt        t        |      d      z  }d|i}| j                  d   dd}t        | || j                  |      |d      \  }}|d   dv r| j                  d       y | j                  d|d   z         y ) NT)requiredno_logF)r
   bool)defaulttype)r
   r   r   )	tokenapp_nameapplication_id	changelogdescriptionrevisionuservalidate_certsapp_name_exact_matchr   r   r   )argument_specrequired_one_ofrequired_ifsupports_check_modez5only one of 'app_name' or 'application_id' can be setmsgz2you must set one of 'app_name' or 'application_id'z0No application with name %s is found in NewRelic)r   r   r   r   )changedz<https://api.newrelic.com/v2/applications/%s/deployments.json )safe
deploymentr   zapplication/json)Api-KeyzContent-TypePOST)dataheadersmethodstatus      z&Unable to insert deployment marker: %sr   )r   dictparams	fail_jsonget_application_id
check_mode	exit_jsonr   strr   jsonify)	moduler,   app_iditemurlr$   r%   responseinfos	            y/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/newrelic_deployment.pymainr:   d   s
   T25)/E*e,4(u%6:!%u65!Q

 %&678,dZLAB F$ F}}Z V]]3C%DTUF}}Z #F+	'	(/0QR~ORXR_R_`jRkkl@ /==!==.F4L/
 & I5QTU[Q\ceKf
fCfD ==)*G vs1Ew_efNHdH~#&EUST    c                 L   d}d| j                   d   z  }d }d| j                   d   i}t        | |||      \  }}|d   dvr| j                  d	|d
   z         t        j                  |j                               }|t        |j                  dd            dk(  r"| j                  d| j                   d   z         | j                   d   rL|d   D ]  }|d   | j                   d   k(  s|d   } n |"| j                  d| j                   d   z         |S |d   d   d   }|S )Nz-https://api.newrelic.com/v2/applications.jsonzfilter[name]=%sr   r"   r   )r$   r%   r'   r(   zUnable to get application: %sr   r   applicationsr   r   z#No application found with name "%s"r   nameidz)No application found with exact name "%s")r,   r   r-   jsonloadsreadlenget)	r3   r6   r$   r   r%   r7   r8   resultr5   s	            r9   r.   r.      sQ   
9Cv}}Z88DN6==)G vswGNHdH~Z'<tE{JKZZ(F~VZZ;<ABV]]S]E^^_}}+,>* 	DF|v}}Z88!%d	 !!Lv}}]gOh!hi   /248r;   __main__)
__future__r   r   r   r   __metaclass__DOCUMENTATIONEXAMPLESansible.module_utils.basicr   ansible.module_utils.urlsr   +ansible.module_utils.six.moves.urllib.parser   r@   r:   r.   __name__ r;   r9   <module>rP      sQ    A @CJ 5 / = 7Ut8 zF r;   