
    s*                        S r SSKJr  SSKJr  SSKJr  SSKrSSKrSSKJr  SSKJ	r	  SSK
r
S rS	 r " S
 S\R                  5      r " S S\R                  5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\R                  5      r " S S\R                  5      r " S S\R                  5      r " S S\R                  5      rg)z)Error classes for gcloud Apigee commands.    )absolute_import)division)unicode_literalsN)
exceptions)yamlc           	         U R                  S5       Vs/ s H  o"S   R                  5       USS -   PM     nnSR                  U5      n[        R                  " UUR                  5       5      n[        U" S0 [        U5      D65      $ s  snf )a  Returns a human readable string representation of a resource identifier.

Args:
  resource_type: the type of resource identified by `resource_identifier`.
  resource_identifier: an ordered mapping representing a fully qualified
    identifier for an Apigee Management API resource.
 r      N  )splitupperjoincollections
namedtuplekeysreprdict)resource_typeresource_identifierword
name_wordscapitalized_type
tuple_types         /lib/googlecloudsdk/command_lib/apigee/errors.py_GetResourceIdentifierStringr      s     8E7J7J37OP7OtQ$qr(*7O*PWWZ( %%&6&9&>&>&@B* 
j54 345	66 Qs   "Bc                 >    SU ;   ad  / nU S    H  nSnUS   U;   d  M  SU;   d  M  XS   -  nM!     U Vs/ s H  oDS   PM	     nnU(       a  U S   S-   [         R                  " U5      -   $ U S   $ s  snf ! [         a    S[         R                  " U 5      -   s $ f = f)a  Returns a string summarizing `error_info`.

Attempts to interpret error_info as an error JSON returned by the Apigee
management API. If successful, the returned string will be an error message
from that data structure - either its top-level error message, or a list of
precondition violations.

If `error_info` can't be parsed, or has no known error message, returns a YAML
formatted copy of `error_info` instead.

Args:
  error_info: a dictionary containing the error data structure returned by the
    Apigee Management API.
details)z+type.googleapis.com/google.rpc.QuotaFailurez2type.googleapis.com/google.rpc.PreconditionFailurez5type.googleapis.com/edge.configstore.bundle.BadBundlez@type
violationsdescriptionmessage
)r   dumpKeyError)
error_infor   itemdetail_types	violationdescriptionss         r   _GetErrorDetailsSummaryr*   /   s    (J jY'$

 =L(\T-A
\*
** ( AKK
9.
lK	)$t+dii.EEE i   L 
 ( $))J'''(s2   A6 A6 A6 A1'A6 ,A6 1A6 6#BBc                       \ rS rSrSrSrg)AmbiguousRequestErrorY   a  Raised when the user makes a request for an ambiguously defined resource.

Sometimes arguments are optional in the general case because their correct
values can generally be inferred, but required for cases when that inferrence
isn't possible. This error covers that scenario.
r   N)__name__
__module____qualname____firstlineno____doc____static_attributes__r       r   r,   r,   Y   s     r4   r,   c                   D   ^  \ rS rSrSr       SU 4S jjrS rSrU =r$ )RequestErrorc   z>Raised when a request to the Apigee Management API has failed.c                   > S U l         U(       av   [        U[        5      (       d!  [        US5      (       a  UR	                  5       n[
        R                  " U5      U l         SU R                   ;   a  U R                   S   U l         X@l        Xl	        X l
        Xpl        U(       d  U(       d  SnU(       d  SnSU< SU< 3nU(       a  Xd(       a  SU-  OS-  nU(       a  US	[        UU5      -   -  nU R                   (       a  US
[        U R                   5      -   -  nU(       a  USU-   -  n[        [        U ]C  U5        g ! [         a     Nf = f)Ndecodeerroraccessresourcez
Failed to r	   z (%s)r   z:
z

Details: r"   )r   
isinstancestrhasattrr9   jsonloads
ValueErrorreasonr   r   	user_helpr   r*   superr6   __init__	selfr   r   methodrC   bodyr!   rD   	__class__s	           r   rF   RequestError.__init__f   s+    DL	 $$$x)@)@$zz$'dll"g.$, K&2N"%+];g	7f%R7	578KM M 	M	=#:4<<#HHH	4)##	,&w//  s   A5E   
EEc           	          U R                   (       a   [        R                  " U R                   5      OSn[        U 5      " UU R                  UU R
                  UU R                  S9$ )z@Returns a copy of the error with a new resource type and method.N)rI   rC   rJ   rD   )r   r@   dumpstyper   rC   rD   rH   r   rI   rJ   s       r   RewrittenErrorRequestError.RewrittenError   sM    '+||4::dll#D:  {{.." "r4   )r   rC   r   r   rD   NNNNNNN	r.   r/   r0   r1   r2   rF   rQ   r3   __classcell__rK   s   @r   r6   r6   c   s-    F "#')0V	" 	"r4   r6   c                   >   ^  \ rS rSrSr    SU 4S jjrS rSrU =r$ )ResponseNotJSONError   zERaised when a request to the Apigee API returns a malformed response.c           
        >^ [        U4S jS 5       5      (       a'  STR                  TR                  TR                  4-  nO[        R
                  " T5      n[        [        U ]#  UUSU[        R                  " SU05      US9  TU l        g )Nc              3   <   >#    U  H  n[        TU5      v   M     g 7f)N)r?   ).0attrr:   s     r   	<genexpr>0ResponseNotJSONError.__init__.<locals>.<genexpr>   s     
G,FD75$,Fs   )msglinenocolnoz%s at %d:%dparseresponse)rD   )allr`   ra   rb   six	text_typerE   rX   rF   r@   rN   
base_error)rH   r:   r   r   rJ   rD   rC   rK   s    `     r   rF   ResponseNotJSONError.__init__   s     
G,F
GGG		5<<EEf}}U#f	
.

J%& /  DOr4   c                     U R                   (       a  U R                   S   OSn[        U 5      " U R                  UU R                  UU R                  S9$ )z5Returns a copy of the error with a new resource type.rd   N)rJ   rD   )r   rO   rh   r   rD   rP   s       r   rQ   #ResponseNotJSONError.RewrittenError   sF    '+||4<<
#D:  .." "r4   )rh   )NNNNrT   rV   s   @r   rX   rX      s#    M "#'&" "r4   rX   c                   >   ^  \ rS rSrSr       SU 4S jjrSrU =r$ )UnauthorizedRequestError   zDRaised when a request to the Apigee API had insufficient privileges.c           	         > U=(       d    SnU=(       d    SnU(       d@  SU< SU< 3nU(       a  USU-   -  nU(       a  US[        X5      -   -  nU(       a  USU-   -  n[        [        U ]  XX4XVU5        g )Nr<   r;   zInsufficient privileges to z the requested z; z
Requested: r"   )r   rE   rm   rF   rG   s	           r   rF   !UnauthorizedRequestError.__init__   s     "/ZMxF
-!g	4&= 	?%A&0 0 	0	4)##	
"
&V	3r4   r   rS   r.   r/   r0   r1   r2   rF   r3   rU   rV   s   @r   rm   rm      s'    L "#'3 3r4   rm   c                   >   ^  \ rS rSrSr       SU 4S jjrSrU =r$ )EntityNotFoundError   zHRaised when a request to the Apigee API mentions a nonexistant resource.c           	         > U=(       d    SnU(       d-  SU-  nU(       a  US[        UU5      -   -  nU(       a  USU-   -  n[        [        U ]  XX4XVU5        g )Nr<   zRequested %s does not existz: r"   )r   rE   rs   rF   rG   s	           r   rF   EntityNotFoundError.__init__   so     "/ZM-?g	46}7JL L 	L	4)##	

&V	3r4   r   rS   rq   rV   s   @r   rs   rs      s'    P "#'3 3r4   rs   c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )HttpRequestError   zrRaised for generic HTTP errors.

Used for HTTP requests sent to an endpoint other than the Apigee Management
API.
c                 n   > SnUR                  XU5      U l        [        [        U ]  U R                  S9  g )Nz]- HTTP status: {}
- Reason: {}
- Message: {}
Use the --log-http flag to see more information.r!   )formatr!   rE   rx   rF   )rH   status_coderC   contenterr_tmplrK   s        r   rF   HttpRequestError.__init__   s4    CH??;@DL	
D*4<<*@r4   r{   rq   rV   s   @r   rx   rx      s    A Ar4   rx   c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )MissingIdentifierError   zRaised when a request to the Apigee API is missing an expected identifier.

Normally this situation should be caught by a required argument being missing
or similar; this error is a fallback in case a corner case slips past those
higher level checks.
c                 B   > SU< SU< S3n[         [        U ]  U5        g )NzCommand requires a z but no z was provided.)rE   r   rF   )rH   namer!   rK   s      r   rF   MissingIdentifierError.__init__  s    AEtLG	
 $09r4   r   rq   rV   s   @r   r   r      s    : :r4   r   c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )SourcePathIsNotDirectoryErrori  zRaised when the source path is not a directory.

The deploy command validates that the file path provided by the --source
command line flag is a directory, and if not, raises this exception.
c                 N   > SR                  U5      n[        [        U ]  U5        g )Nz"Source path is not a directory: {})r|   rE   r   rF   )rH   src_pathr`   rK   s      r   rF   &SourcePathIsNotDirectoryError.__init__  s#    
.
5
5h
?C	
'7<r4   r   rq   rV   s   @r   r   r     s    = =r4   r   c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )BundleFileNotValidErrori  zRaised when a bundle file is not valid.

The deploy command validates that the bundle file provided by the
--bundle-file command line flag is a valid zip archive, and if not, raises
this exception.
c                 N   > SR                  U5      n[        [        U ]  U5        g )Nz*Bundle file is not a valid zip archive: {})r|   rE   r   rF   )rH   bundle_filer`   rK   s      r   rF    BundleFileNotValidError.__init__!  s#    
6
=
=k
JC	
!41#6r4   r   rq   rV   s   @r   r   r         7 7r4   r   c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )LocationResolutionErrori&  a  Raised when the unable to resolve the location of the Apigee organization.

All the commands in the apigee surface require a valid location to execute.
This error is raised when the gcloud command is unable to determine the
location of the Apigee organization.
c                 0   > Sn[         [        U ]  U5        g )Nz:Failed to resolve the location of the Apigee organization.)rE   r   rF   )rH   r`   rK   s     r   rF    LocationResolutionError.__init__.  s    
FC	
!41#6r4   r   rq   rV   s   @r   r   r   &  r   r4   r   )r2   
__future__r   r   r   r   r@   googlecloudsdk.corer   r   rf   r   r*   Errorr,   r6   rX   rm   rs   rx   r   r   r   r   r   r4   r   <module>r      s    0 &  '   * $ 
7&'(TJ,, 7":## 7"t"< "B3| 383, 30A| A
:Z-- 
:	=J$4$4 	=
7j.. 
7
7j.. 
7r4   