
                         n    S r SSKJr  SSKJr  SSKJr  SSKJr  SSKJ	r	  SSKJ
r
  SrS	r " S
 S\5      rg)zCrash Reporting for Cloud SDK.    )absolute_import)division)unicode_literals)apis)
properties)	resourcesv1beta1clouderrorreportingc                   J    \ rS rSrSrS
S jr  SS jr  SS jrS rS r	S	r
g)ErrorReporting   z Report errors to errorreporting.Nc                     Xl         U R                   c$  [        R                  " [        [        5      U l         U R                   R
                  U l        g 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__ErrorReporting.__init__"   s7     O!33HkJdo77D    c                 l    U R                   R                  R                  U R                  XX4XVS95        g)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   ReportEventErrorReporting.ReportEvent(   s7     	OO##**4+E+E ,F ,, -r   c                    U R                   R                  X#S9nU R                   R                  XqS9nU(       d  U(       aR  U R                   R                  5       n	U(       a  U R                   R	                  US9U	l        U(       a  Xil        Xl        Uc  U R                  5       nU R                  U5      n
U R                   R                  XS9$ )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#   $ErrorReporting.GenerateReportRequest8   s     ''66 7 *O ##66& 7 ?K d''446m	$($5$5$H$H %I %!	!)&&(g((1LKK  L B Br   c                 d    [         R                  R                  R                  R	                  SS9$ )z5Gets the current project if project is not specified.T)required)r   VALUEScorer   Get)r   s    r   r4    ErrorReporting._GetGcloudProject]   s(    !!))--t-<<r   c                 l    [         R                  R                  [        S-   US9nUR	                  5       $ )Nz	.projects)	projectId)r   REGISTRYCreater   RelativeName)r   r   project_refs      r   r5   ErrorReporting._MakeProjectNamea   s6    $$++H{,B6= , ?K##%%r   )r   r   r   )NNNN)__name__
__module____qualname____firstlineno____doc__r   r&   r#   r4   r5   __static_attributes__ r   r   r   r      s2    (8 9=7;-  CGAE#BJ=&r   r   N)rM   
__future__r   r   r   googlecloudsdk.api_lib.utilr   r   googlecloudsdk.corer   r   r   r   objectr   rO   r   r   <module>rT      s6     % &  ' 9 * )  E&V E&r   