
                         n    d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z	 ddlm
Z
 dZd	Z G d
 de      Zy)zCrash Reporting for Cloud SDK.    )absolute_import)division)unicode_literals)apis)
properties)	resourcesv1beta1clouderrorreportingc                   <    e Zd ZdZddZ	 	 d	dZ	 	 d	dZd Zd Zy)
ErrorReportingz Report errors to errorreporting.Nc                     || _         | j                   #t        j                  t        t              | _         | j                   j
                  | _        y N)
api_client	core_apisGetClientInstanceAPI_NAMEAPI_VERSIONMESSAGES_MODULEapi_messages)selfr   s     2lib/googlecloudsdk/api_lib/error_reporting/util.py__init__zErrorReporting.__init__"   s9     DO!33HkJdo77D    c           
      x    | j                   j                  j                  | j                  ||||||             y)a  Creates a new error event and sends to StackDriver Reporting API.

    Args:
      error_message: str, Crash details including stacktrace
      service: str, Name of service
      version: str, Service version, defaults to None
      project: str, Project to report errors to, defaults to current
      request_url: str, The request url that led to the error
      user: str, The user affected by the error
    )versionprojectrequest_urluserN)r   projects_eventsReportGenerateReportRequest)r   error_messageservicer   r   r   r   s          r   ReportEventzErrorReporting.ReportEvent(   s=     	OO##**4+E+Ewd ,F ,, -r   c                    | j                   j                  ||      }| j                   j                  ||      }|s|rM| j                   j                         }	|r!| j                   j	                  |      |	_        |r||	_        |	|_        || j                         }| j                  |      }
| j                   j                  |
|      S )a  Creates a new error event request.

    Args:
      error_message: str, Crash details including stacktrace
      service: str, Name of service
      version: str, Service version, defaults to None
      project: str, Project to report errors to, defaults to current
      request_url: str, The request url that led to the error
      user: str, The user affected by the error

    Returns:
      The request to send.
    )r#   r   )serviceContextmessage)url)projectNamereportedErrorEvent)r   ServiceContextReportedErrorEventErrorContextHttpRequestContexthttpRequestr   context_GetGcloudProject_MakeProjectName.ClouderrorreportingProjectsEventsReportRequest)r   r"   r#   r   r   r   r   service_contexterror_eventerror_contextproject_names              r   r!   z$ErrorReporting.GenerateReportRequest8   s     ''66 7 *O ##66& 7 ?K d''446m	$($5$5$H$H %I %!	!)k&&(g((1LKK [ L B Br   c                 j    t         j                  j                  j                  j	                  d      S )z5Gets the current project if project is not specified.T)required)r   VALUEScorer   Get)r   s    r   r1   z ErrorReporting._GetGcloudProject]   s(    !!))--t-<<r   c                 r    t         j                  j                  t        dz   |      }|j	                         S )Nz	.projects)	projectId)r   REGISTRYCreater   RelativeName)r   r   project_refs      r   r2   zErrorReporting._MakeProjectNamea   s6    $$++H{,B6= , ?K##%%r   r   )NNNN)	__name__
__module____qualname____doc__r   r$   r!   r1   r2    r   r   r   r      s2    (8 9=7;-  CGAE#BJ=&r   r   N)rF   
__future__r   r   r   googlecloudsdk.api_lib.utilr   r   googlecloudsdk.corer   r   r   r   objectr   rG   r   r   <module>rL      s6     % &  ' 9 * )  E&V E&r   