
    P9                        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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 S\	R$                  5      r " S S\	R$                  5      r " S S\	R$                  5      r " S S\	R$                  5      r " S S\	R.                  5      r " S S\	R$                  5      r " S S\	R$                  5      r " S S\	R.                  5      r " S S\	R.                  5      r " S S\5      r\R>                  " S / S!Q5      r  " S" S#\	R.                  5      r! " S$ S%\	RD                  5      r# " S& S'\RH                  5      r%g)(z.Python wrappers around Apigee Management APIs.    )absolute_import)division)unicode_literalsN)base)waiter)errors)request)resource_args)logc                   >    \ rS rSrSrS/r\S 5       r\S 5       rSr	g)OrganizationsClient!   z%REST client for Apigee Organizations.organizationc                      [         R                  " SU R                  SS U R                  S   SS9$ ! [        R                   a  nUR                  SS5      eSnAff = f)z:Returns a list of Apigee organizations on global endpoint.Nglobal)identifiersentity_pathentity_collectionlocationr   listr	   ResponseToApiRequest_entity_pathr   RequestErrorRewrittenError)clserrors     -lib/googlecloudsdk/api_lib/apigee/__init__.pyListOrganizationsGlobal+OrganizationsClient.ListOrganizationsGlobal%   si    9))&&s+,,R0	 
  9  889   03 AAAc                     [         R                  " UU R                  SSSS9$ ! [        R                  [        R
                  4 a  nUR                  SS5      eSnAf[        R                   a  nUR                  SS5      eSnAff = f)z9Returns a mapping of GCP projects to Apigee organization.z:getProjectMappingGETr   )methodmethod_overrider   zproject mappinggetN)r	   r   r   r   UnauthorizedRequestErrorEntityNotFoundErrorr   r   r   r   r   s      r   ProjectMapping"OrganizationsClient.ProjectMapping2   s    ;))



%  	''"" ;
   !2E:: ;  !2E::;s!   !$ $BAB1BB N)
__name__
__module____qualname____firstlineno____doc__r   classmethodr    r+   __static_attributes__r-       r   r   r   !   s3    - !,
9 
9 ; ;r5   r   c                   D    \ rS rSrSrSS/r\S	S j5       r\S 5       rSr	g)

APIsClientI   z#REST client for Apigee API Proxies.r   apic                     / SQnU(       a  SS0O0 n [         R                  " UUSSUS9$ ! [        R                   a  nUR	                  SS5      eS nAff = f)	Nr   environmentr9   revisionoverridetrue
deploymentPOST)r%   query_paramsz	API proxydeployr	   r   r   r   r   )r   r   r>   deployment_pathrB   r   s         r   DeployAPIsClient.DeployM   sg    HO+3J'L
8))


#% %  8  h778s   + AAAc                      [         R                  " U/ SQSSS9$ ! [        R                   a  nUR	                  SS5      eS nAff = f)Nr;   r@   DELETE)r%   undeployrD   r*   s      r   UndeployAPIsClient.Undeploy]   sQ    ;))
I
   ;  z::;s    AAAr-   N)F)
r.   r/   r0   r1   r2   r   r3   rF   rK   r4   r-   r5   r   r7   r7   I   s5    + %(,8 8 ; ;r5   r7   c                       \ rS rSrSS/rSrg)EnvironmentsClienti   r   r<   r-   Nr.   r/   r0   r1   r   r4   r-   r5   r   rN   rN   i   s     -0,r5   rN   c                       \ rS rSr/ SQrSrg)RevisionsClientm   )r   r9   r=   r-   NrP   r-   r5   r   rR   rR   m   s    4,r5   rR   c                   $    \ rS rSr/ SQrSrSrSrg)_DeveloperApplicationsClientq   )r   	developerapprX   namer-   Nr.   r/   r0   r1   r   _list_container_page_fieldr4   r-   r5   r   rU   rU   q   s    5,/+r5   rU   c                   d   ^  \ rS rSrSrSS/r\S 5       r\U 4S j5       r\U 4S j5       r	Sr
U =r$ )	OperationsClientw   z/REST client for Apigee long running operations.r   	operationc                     [         R                  " SUS   5      nU(       d  U$ UR                  S5      US'   UR                  S5      US'   U$ )Nzlorganizations/([a-z][-a-z0-9]{0,30}[a-z0-9])/operations/([0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12})rY      r      uuid)rematchgroup)r   operation_info
name_partss      r   	SplitNameOperationsClient.SplitName{   sY    	@v J %/%5%5a%8N>"'--a0N6r5   c              #      >#    [         [        U ]  U5      nU(       d  g US    H  nU R                  U5      v   M     g 7f)N
operations)superr^   Listrj   )r   r   responseitem	__class__s       r   ro   OperationsClient.List   s<     %s0=H&MM$ 's   <?c                 H   > U R                  [        [        U ]  U5      5      $ N)rj   rn   r^   Describe)r   r   rr   s     r   rv   OperationsClient.Describe   s    ==/>{KLLr5   r-   )r.   r/   r0   r1   r2   r   r3   rj   ro   rv   r4   __classcell__rr   s   @r   r^   r^   w   sL    7 +.,	 	     M Mr5   r^   c                   2    \ rS rSrSrS/r\SS j5       rSrg)ProjectsClient   z4REST client for Apigee APIs related to GCP projects.projectNc                 `    [         R                  " SU0S/S[        R                  " U5      US9$ )N
projectsIdr}   z:provisionOrganization)r%   bodyr   )r	   r   jsondumps)r   
project_idorg_infor   s       r   ProvisionOrganization$ProjectsClient.ProvisionOrganization   s2    ''z(BYK/G-1ZZ-A19; ;r5   r-   ru   )	r.   r/   r0   r1   r2   r   r3   r   r4   r-   r5   r   r{   r{      s    <,; ;r5   r{   c                   J   ^  \ rS rSrSrSS/rSrSrSr\	U 4S j5       r
SrU =r$ )	ApplicationsClient   z$REST client for Apigee applications.r   rX   appIdrowsc              #      >#    SU;   a  US   (       a  [         R                  nSnO[        [        U ]  nSnU" XS0S9nU H  nUS   US   S.v   M     g 7f)	NdevelopersIdshallowExpandexpandr?   )extra_paramsr   rY   )r   rY   )rU   ro   rn   r   )r   r   list_implementationexpand_flagitemsrq   rr   s         r   ro   ApplicationsClient.List   se     $^)D8==#k!"4c?k:OPE7mT&\:: s   AAr-   )r.   r/   r0   r1   r2   r   r[   r\   _limit_paramr3   ro   r4   rx   ry   s   @r   r   r      s1    , %(,/+,	; 	;r5   r   c                   $    \ rS rSrSS/rSrSrSrg)DevelopersClient   r   rW   emailr-   NrZ   r-   r5   r   r   r      s     +.,/+r5   r   c                   (    \ rS rSrSr\S 5       rSrg)DeploymentsClient   z#REST client for Apigee deployments.c                    / SQnU Vs/ s H  n[         R                  U   PM     nn/ nU H;  nUR                  S-   nXq;   d  M  X   c  M   UR                  UR                  5        M=     SU;   a  SU;  a  UR                  S5         [        R                  " XS5      nSU;   a  U/$ SU;   a  US   $ U(       d  / $ U$ s  snf ! [        R                   a    / n N<f = f)a  Returns a list of deployments, filtered by `identifiers`.

The deployment-listing API, unlike most GCP APIs, is very flexible as to
what kinds of objects are provided as the deployments' parents. An
organization is required, but any combination of environment, proxy or
shared flow, and API revision can be given in addition to that.

Args:
  identifiers: dictionary with fields that describe which deployments to
    list. `organizationsId` is required. `environmentsId`, `apisId`, and
    `revisionsId` can be optionally provided to further filter the list.
    Shared flows are not yet supported.

Returns:
  A list of Apigee deployments, each represented by a parsed JSON object.
r;   Idr=   r9   r@   apiProxydeployments)
r
   ENTITIESpluralappendsingularremover	   r   r   r)   )	r   r   identifier_namesrY   entitiesr   entitykeyrp   s	            r   ro   DeploymentsClient.List   s    & J9IJ9I&&t,9IHJKMMD c		 0 <6??+ 
 [ U+%= $--k.:<h XZ m$$iO9 K  %% hs   B?	C CCr-   N)r.   r/   r0   r1   r2   r3   ro   r4   r-   r5   r   r   r      s    +/ /r5   r   ProductsInfo)rY   displayNameapprovalType
attributesdescriptionapiResourcesenvironmentsproxiesquotaquotaIntervalquotaTimeUnitscopesc                   H    \ rS rSrSrSS/rSrSr\S 5       r	\S 5       r
S	rg
)ProductsClient   z$REST client for Apigee API products.r   product
apiProductrY   c           	          UR                  5       nU Vs0 s H  nX4   c  M
  XCU   _M     nn[        R                  " US/SS[        R                  " U5      S9$ s  snf )Nr   r   rA   r%   r   _asdictr	   r   r   r   r   r   product_infoproduct_dictr   s        r   CreateProductsClient.Create   sv    '')L  C 	#   ''n%ZZ%	' '
   	A	Ac                     UR                  5       nU Vs0 s H  nX4   c  M
  XCU   _M     nn[        R                  " USS/S[        R                  " U5      S9$ s  snf )Nr   r   PUTr   r   r   s        r   UpdateProductsClient.Update  su    '')L  C 	#   ''ni0ZZ%' 'r   r-   N)r.   r/   r0   r1   r2   r   r[   r\   r3   r   r   r4   r-   r5   r   r   r      s?    , ),, /+' ' ' 'r5   r   c                   r   ^  \ rS rSrSr/ SQrSr\S 5       r\U 4S j5       r	\S 5       r
\S 5       rS	rU =r$ )
ArchivesClienti  z-Client for the Apigee archiveDeployments API.)r   r<   archive_deploymentarchiveDeploymentsc                      [         R                  " UU R                  S[        R                  " U5      S9$ ! [
        R                   a  nUR                  SS5      eSnAff = f)a  Calls the 'update' API for archive deployments.

Args:
  identifiers: Dict of identifiers for the request entity path, which must
    include "organizationsId", "environmentsId" and "archiveDeploymentsId".
  labels: Dict of the labels proto to update, in the form of:
    {"labels": {"key1": "value1", "key2": "value2", ... "keyN": "valueN"}}

Returns:
  A dict of the updated archive deployment.

Raises:
  command_lib.apigee.errors.RequestError if there is an error with the API
    request.
PATCH)r   r%   r   archive deploymentupdateNr	   r   r   r   r   r   r   r   )r   r   labelsr   s       r   r   ArchivesClient.Update#  sd    "A))
&&zz&!	# #
  A  !5x@@As   47 A"AA"c                    >  [         [        U ]  U5      $ ! [        R                   a  nUR                  SS5      eSnAff = f)aE  Calls the 'list' API for archive deployments.

Args:
  identifiers: Dict of identifiers for the request entity path, which must
    include "organizationsId" and "environmentsId".

Returns:
  An iterable of archive deployments.

Raises:
  command_lib.apigee.errors.RequestError if there is an error with the API
    request.
r   r   N)rn   r   ro   r   r   r   )r   r   r   rr   s      r   ro   ArchivesClient.List=  sD    ?>3,[99 ?  !5v>>?s    A<Ac                      [         R                  " UU R                  SS U R                  S   SS9$ ! [        R                   a  nUR                  SS5      eSnAff = f)a  Apigee API for generating a signed URL for uploading archives.

This API uses the custom method:
organizations/*/environments/*/archiveDeployments:generateUploadUrl

Args:
  identifiers: Dict of identifiers for the request entity path, which must
    include "organizationsId" and "environmentsId".

Returns:
  A dict of the API response in the form of:
    {"uploadUri": "https://storage.googleapis.com/ ... (full URI)"}

Raises:
  command_lib.apigee.errors.RequestError if there is an error with the API
    request.
Nr   z:generateUploadUrl)r   r   r%   r   zget upload url forr   r*   s      r   GetUploadUrlArchivesClient.GetUploadUrlQ  sp    &
M ))
&&s+,,R0%	' '
  M  !57KLLMr"   c           	           [         R                  " UU R                  SS U R                  S   S[        R                  " U5      S9$ ! [
        R                   a  nUR                  SS5      eSnAff = f)a  Apigee API for creating a new archive deployment.

Args:
  identifiers: A dict of identifiers for the request entity path, which must
    include "organizationsId" and "environmentsId".
  post_data: A dict of the request body to include in the
    CreateArchiveDeployment API call.

Returns:
  A dict of the API response. The API call starts a long-running operation,
    so the response dict will contain info about the operation id.

Raises:
  command_lib.apigee.errors.RequestError if there is an error with the API
    request.
Nr   rA   r   r   creater   )r   r   	post_datar   s       r   CreateArchiveDeployment&ArchivesClient.CreateArchiveDeploymentp  s{    $A ))



3B



2
zz)$& &  A  !5x@@As   AA A3A..A3r-   )r.   r/   r0   r1   r2   r   r[   r3   r   ro   r   r   r4   rx   ry   s   @r   r   r     sd    5F,(/A A2 ? ?& M M< A Ar5   r   c                   >   ^  \ rS rSrSrU 4S jrS rS rS rSr	U =r
$ )	LROPolleri  z8Polls on completion of an Apigee long running operation.c                 6   > [         [        U ]  5         Xl        g ru   )rn   r   __init__r   )selfr   rr   s     r   r   LROPoller.__init__  s    	)T#%$r5   c                     Sn US   S   S:H  nU(       a6  SU;   a0  [        R                  " SS	US	   0S
[
        R                  " U5      S9eU$ ! [          a#  n[        R                  " SU< SU< 35      eS nAff = f)NFmetadatastateFINISHEDzMalformed operation; 
r   r`   rY   await)r   )KeyErrorr   OperationErrorr   r   r   r   )r   r`   finishederrs       r   IsDoneLROPoller.IsDone  s    H4J'0J>h Gy(
	& 12
zz)$& & O  4!!#&	#3 4 44s   A 
A;A66A;c                 F    [         R                  U R                  US.5      $ )N)organizationsIdoperationsId)r^   rv   r   )r   operation_uuids     r   PollLROPoller.Poll  s&    $$,,&&  r5   c                     SU;   a  US   $ g )Nrp   r-   )r   r`   s     r   	GetResultLROPoller.GetResult  s    Yz""r5   )r   )r.   r/   r0   r1   r2   r   r   r   r   r4   rx   ry   s   @r   r   r     s    @% r5   r   )&r2   
__future__r   r   r   collectionsr   re   googlecloudsdk.api_lib.apigeer   googlecloudsdk.api_lib.utilr   !googlecloudsdk.command_lib.apigeer   r	   r
   googlecloudsdk.corer   
BaseClientr   r7   rN   rR   FieldPagedListClientrU   r^   r{   r   r   objectr   
namedtupler   r   TokenPagedListClientr   OperationPollerr   r-   r5   r   <module>r     s*   5 &  '   	 . . 4 5 ; #%;$// %;P; ;@1 15doo 54#<#< Mt M:	;T__ 	;;22 ;(t00 3 3l %%n 7 #'T.. #'LpAT.. pAf&& r5   