
    H                         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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KJr  \	R(                   " S S\	R*                  5      5       rg)z(Command to create an Apigee API product.    )absolute_import)division)unicode_literals)apigee)arg_parsers)base)
exceptions)argument_groups)defaults)prompts)resource_args)
properties)
console_ioc                   8    \ rS rSrSrSSS.r\S 5       rS rSr	g	)
Deploy!   zCreate an Apigee API product.a  
          Create an Apigee API product.

          `{command}` publishes a collection of API proxy resources as an API
          product.

          API products combine their underlying API proxies with quota settings
          and metadata, to deliver customized and productized API bundles to
          the developer community.

          API products enable the repackaging of APIs on-the-fly, without having
          to do any additional coding or configuration. Apigee recommends
          starting with a simple API product including only required elements,
          and then provisioning credentials to apps to enable them to start
          testing those APIs.

          At minimum, a new API product requires an internal name, access
          policy, and declaration of what environments and API proxies to
          include in the product. If these aren't provided, interactive calls
          will prompt for the missing values, and non-interactive calls will
          fail.
          a 	  
          To create a basic API product in the active Cloud Platform project by
          answering interactive prompts, run:

              $ {command}

          To create an API product that publicly exposes all API proxies
          deployed to the ``prod'' environment, run:

              $ {command} kitchen-sink --environments=prod --all-proxies --public-access

          To require manual approval of developers before they can access the
          new API product, run:

              $ {command} kitchen-sink --environments=prod --all-proxies --public-access --manual-approval

          To hide the new API product while still making it accessible to
          developers, run:

              $ {command} kitchen-sink --environments=prod --all-proxies --private-access

          To restrict the new API product to internal users only, run:

              $ {command} kitchen-sink --environments=prod --all-proxies --internal-access

          To expose all API proxies that are deployed to a URI fragment
          beginning with ``/v1'' or ``/v0'', run:

              $ {command} legacy --all-environments --resources="/v0/**#/v1/**" --public-access

          To expose a few specific API proxies on all URI paths where they're
          deployed, run:

              $ {command} consumer --environments=prod --apis=menu,cart,delivery-tracker --public-access

          To expose only those API calls that match both a set of API proxies
          and a set of API resources, run:

              $ {command} legacy-consumer --environments=prod --apis=menu,cart,delivery-tracker --resources="/v0/**#/v1/**" --public-access

          To impose a quota of 50 calls per half-hour on a new all-inclusive API
          product, and output the new API product as a JSON object, run:

              $ {command} kitchen-sink --environments=prod --all-proxies --public-access --quota=50 --quota-interval=30 --quota-unit=minute --format=json

          To specify a human-friendly display name and description for the
          product, run:

              $ {command} consumer --environments=prod --apis=menu,cart,delivery-tracker --public-access --display-name="Consumer APIs" --description="APIs for the consumer side of the delivery network: ordering food and tracking deliveries."
          )DESCRIPTIONEXAMPLESc           	         [         R                  " U SSSSSS9  U R                  5       nUR                  SS[        R
                  " S	S
9SS9  UR                  SSS/ SS9  U R                  SSS9  U R                  5       nUR                  SSSSSS9  UR                  SSSSSS9  UR                  SSSSSS9  U R                  S5      nUR                  S S!S"S#9  UR                  S$5      nUR                  S%S&[        R
                  " 5       S'S9  UR                  S(S)[        R                  " S	S
9S*S9  U R                  S+5      nUR                  S,[        S-S.9  UR                  S/[        S0S.9  UR                  S1/ S2QS3S49  U R                  S5S6S9  U R                  S7S!S8S#9  U R                  S9S:[        R
                  " 5       S;S9  U R                  S<S=[        R                  " S>S?9S@S9  g )ANzorganization.productzlAPI product to be created. Characters in a product's internal name are restricted to: ```A-Za-z0-9._-$ %```.TINTERNAL_NAMEF)validateargument_namerequired--environmentsENVIRONMENT   )
min_lengtha  Environments to which the API product is bound. Requests to environments that are not listed are rejected, preventing developers from accessing those resources through API Proxies deployed in another environment.

For example, this can prevent resources associated with API proxies in a ``prod'' environment from also granting access to matching API proxies deployed in a ``test'' environment.

To get a list of available environments, run:

    $ {grandparent_command} environments list)metavartypehelp--all-environmentsenvironmentsstore_constz:Make all environments accessible through this API product.)destactionconstr    z--display-namez\Name to be displayed in the UI or developer portal to developers registering for API access.)r    --public-accessaccesspubliczKMake this API product visible to developers in the Apigee developer portal.--private-accessprivatez\Hide this API product in the developer portal but make it accessible by external developers.--internal-accessinternalz,Prevent external access to this API product.z?Arguments specifying which API proxies and resources to expose.--all-proxies
store_truezExpose all available API proxies and their resources. Must be explicitly specified if neither `--apis` nor `--resources` is provided.)r%   r    zmArguments that restrict exposed API proxies. One or both of these may be specified if `--all-proxies` is not:--apisAPIa  Comma-separated names of API proxies to which this API product is bound. Only
those API proxies will be accessible through the new API product.

If not provided, all deployed API proxies will be included in the product, so
long as they match the other parameters.

The API proxy names must already be deployed to the bound environments, or
creation of the API product will fail. To get a list of deployed API proxies,
run:

    $ {grandparent_command} deployments list

To deploy an API proxy, run:

    $ {grandparent_command} apis deploy--resourcesRESOURCEa  API resources to be bundled in the API product, separated by `#` signs.

By default, the resource paths are mapped from the `proxy.pathsuffix` variable.

The proxy path suffix is defined as the URI fragment following the
ProxyEndpoint base path. For example, if ``/forecastrss'' is given as an element
of this list, and the base path defined for the API proxy is `/weather`, then
only requests to `/weather/forecastrss` are permitted by the API product.

Proxy paths can use asterisks as wildcards; `/**` indicates that all sub-URIs
are included, whereas a single asterisk indicates that only URIs one level
down are included.

By default, `/` supports the same resources as `/**` as well as the base path
defined by the API proxy.

For example, if the base path of the API proxy is `/v1/weatherapikey`, then
the API product supports requests to `/v1/weatherapikey` and to any sub-URIs,
such as `/v1/weatherapikey/forecastrss`, `/v1/weatherapikey/region/CA`, and so
on.

If not provided, all deployed API resources will be included in the product, so
long as they match the other parameters.

The API proxy resources must already be deployed to the bound environments, or
creation of the API product will fail.zRTo impose a quota limit on calls to the API product, specify all of the following:z--quotaa  Number of request messages permitted per app by this API product
for the specified `--quota-interval` and `--quota-unit`.

For example, to create an API product that allows 50 requests every twelve hours
to every deployed API proxy, run:

    $ {command} PRODUCT --all-environments --all-proxies --public-access --quota=50 --quota-interval=12 --quota-unit=hour

If specified, `--quota-interval` and `--quota-unit` must be specified too.)r   r    z--quota-intervalzTime interval over which the number of request messages is calculated.

If specified, `--quota` and `--quota-unit` must be specified too.z--quota-unit)minutehourdaymonthzhTime unit for `--quota-interval`.

If specified, `--quota` and `--quota-interval` must be specified too.)choicesr    z--descriptionzpOverview of the API product. Include key information about the API product that is not captured by other fields.z--manual-approvalzRequire manual approval of developer requests to access this API product before their consumer keys can be used. If unset, the consumer key is generated in an "approved" state and can be used immediately.z--oauth-scopesSCOPEzComma-separated list of OAuth scopes that are validated at runtime. Apigee validates that the scopes in any access token presented match the scopes defined in the OAuth policy assoicated with the API product.z--attributesz
NAME=VALUE   )
max_lengthzKey-value attribute pairs that may be used to extend the default API product profile with customer-specific metadata. Up to 17 attributes can be specified.)r   AddSingleResourceArgumentadd_mutually_exclusive_groupadd_argumentr   ArgListadd_argument_groupr
   HashDelimitedArgListintArgDict)parserenvironment_groupaccess_groupproxies_mutex_groupproxies_groupquota_groups         %lib/surface/apigee/products/create.pyArgsDeploy.Argsr   s    ++	4% ;;=""  A.>	 # @ ""I # K 7  9
 668L"  $ 3  5 ;  = !==IK $$ %  (::	23M   "+	  ,2 11Q?*	  +@ ++
K N  O    2  ! B  D
 %  '   "1	  3   B/3	  5    c                 	  ^^ UR                   c  [        R                  " 5       Ul         [        R                  " 5       (       Ga  UR                   c   S n[
        R                  " SSU5      Ul         UR                  c9  [        R                  " S5      mU4S jn[        R                  " USS5      Ul        S	UR                   0mUR                  cG  U4S
 jn[        R                  " SS/SS9nUS:X  a  / Ul        O[
        R                  " SU5      Ul        UR                  (       d  UR                  (       d  UR                   (       d  [        R                  " SS/SS9nUS:X  a  SUl        OU4S jn[
        R                  " SUS5      Ul        SS/n[        R                  " U5      S:X  a  [
        R"                  " SSS5      Ul        O/ Ul        UR                  (       d  UR                  (       d  SUl        UR$                  c#  [        R                  " / SQSS9n/ SQU   Ul        UR                  c  [&        R(                  " S S!/S"5      eUR$                  c  [&        R(                  " / S#QS$5      eUR                  (       d;  UR                  (       d*  UR                   (       d  [&        R(                  " / S%QS&5      e[+        U5       V	s/ s H  n	S'U	;   d  M  [+        U5      U	   b  M  U	PM      n
n	U
(       a=  [-        U
5      S(:  a-  [&        R.                  " S)U
S   R1                  S*S+5      -   S,5      eO(S-UR2                  -  Ul        S-UR4                  -  Ul        S.UR$                  S/./nUR6                  (       a3  UR6                   H#  nUR9                  XR6                  U   S/.5        M%     UR:                  R<                  R?                  5       RA                  5       nURB                  c
  US0   Ul!        [D        RF                  " US0   URB                  URH                  (       a  S1OS2UURJ                  UR                  (       a  UR                  OSUR                  (       a  UR                  OSUR                  (       a  UR                  OSUR2                  UR4                  URL                  URN                  S39n[D        RP                  RS                  X5      $ s  sn	f )4zRun the deploy command.Nc                  4   [         R                  R                  R                  R	                  5       (       a  [        R
                  R                  5       n O[        R
                  R                  5       n SU ;   a  U S    Vs/ s H  oS   PM	     sn$ / $ s  snf )Norganizationsorganization)r   VALUESapi_endpoint_overridesr   GetOrganizationsClientListListOrganizationsGlobal)responseitems     rJ   	_ListOrgsDeploy.Run.<locals>._ListOrgs<  s}    55<<@@BB11668H11IIKH(5=o5NO5NT(5NOOI Ps   BrQ   z3the organization in which to create the API productproductc                 *   > TR                  U 5      S L$ N)search)nameproduct_matchers    rJ   <lambda>Deploy.Run.<locals>.<lambda>L  s    _%;%;D%A%MrM   z"Empty or invalid API product name.z0Enter an internal name for the new API product: organizationsIdc                  B   > [         R                  R                  T 5      $ r^   )r   EnvironmentsClientrV   )org_identifiers   rJ   rb   rc   S  s    F55::>JrM   zInclude all environmentszChoose environments to includez:What environments should be accessible in the API product?)prompt_stringr   environmentzInclude all API proxiesz.Choose API proxies and/or basepaths to includez9What API proxies should be accessible in the API product?Tc                     > [         R                  R                  T5      n [        [	        [        S U  5       5      5      5      $ )Nc              3   *   #    U  H	  oS    v   M     g7f)apiProxyN ).0rY   s     rJ   	<genexpr>;Deploy.Run.<locals>._ListDeployedProxies.<locals>.<genexpr>l  s     "I
#3s   )r   DeploymentsClientrV   sortedlistset)rX   rg   s    rJ   _ListDeployedProxies(Deploy.Run.<locals>._ListDeployedProxiesj  s4    //44^DH$s"I"IIJKKrM   apiz Include all deployed API proxiesz&Restrict proxy access by resource pathz7Include all resource paths of the product's API proxiesz/Enter a resource path that should be included: zInclude another resource path)z/Public - visible in the Apigee developer portalzXPrivate - callable by external developers but not visible in the Apigee developer portalz.Internal - not callable by external developerszChoose an access policy.)message)r)   r+   r-   r   r!   z7All API products must include at least one environment.)r'   r*   r,   zDAll API products must specify whether they can be publicly accessed.)r0   r2   r.   zAAll API products must include at least one API proxy or resource.quota   z--_-z/Must specify all quota arguments to use quotas.z%dr(   )r`   valueapiproductsIdmanualauto)r`   displayNameapprovalType
attributesdescriptionapiResourcesr"   proxiesry   quotaIntervalquotaTimeUnitscopes)*rQ   r   OrganizationFromGCPProjectr   	CanPromptr   ResourceFromFreeformPromptr   r   ValidPatternForEntityPromptWithValidatorr"   PromptChoiceResourceListFromPromptapis	resourcesall_proxiesListFromFreeformPromptr(   r	   OneOfArgumentsRequiredExceptionvarslenRequiredArgumentExceptionreplacery   quota_intervalr   appendCONCEPTSinternal_nameParseAsDictdisplay_namer   ProductsInfomanual_approvalr   
quota_unitoauth_scopesProductsClientCreate)selfargsrZ   valid_product	list_envschoiceru   resource_optionsoptionargquota_args_missingr   keyidentifiersr\   rg   ra   s                  @@rJ   Run
Deploy.Run4  sX    "==?d				"	 $>>A9N 
			#'==iHM';;?>@ *4+<+<=n				"J	((')IJ&( Q; $
%<<Y($
 YYt~~d6F6F(()@&( Q;!$
L 44)+MO$) 7G
 $$%56!;$;;A/IKDN
  DN		#D		(( *
 2LM 8? 661
2
CE E {{66 8	OQ Q 99T^^D4D4D66
4
MO O
 Dz!W^T
3z   		 1	$22%a(00c::=? 	? 
%
 $**$dj 4#6#66d#dkk:;J#31EFG ! ----335<<>K %o6d!!)%%!%!5!5X6$$'+~~T^^4*.*;*;T&&!YY		Djj))oo  "G   ''==Gs   
S-$S-5S-rm   N)
__name__
__module____qualname____firstlineno____doc__detailed_helpstaticmethodrK   r   __static_attributes__rm   rM   rJ   r   r   !   s5    %.13K-Z 5 5BI>rM   r   N)r   
__future__r   r   r   googlecloudsdk.api_libr   googlecloudsdk.callioper   r   r	   !googlecloudsdk.command_lib.apigeer
   r   r   r   googlecloudsdk.corer   googlecloudsdk.core.consoler   DefaultUniverseOnlyDescribeCommandr   rm   rM   rJ   <module>r      s[    / &  ' ) / ( . = 6 5 ; * 2 [>T!! [> [>rM   