
                         P   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dlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ  ej$                  ej&                  j(                  ej&                  j*                        ej,                   G d dej.                                      Zy)zICommand for creating or replacing an application from YAML specification.    )absolute_import)division)unicode_literals)types_utils)base)pretty_print)deprecation_util)flags)messages_util)run_apps_operations)
exceptionsc                   6    e Zd ZdZdddZed        Zd Zd Zy)	CreatezCreate a Cloud Run Integration.z"          {description}
          a-            To create and attach a redis instance to a Cloud Run service

              $ {command} --type=redis --service=myservice

          To attach a custom domain to a Cloud Run service

              $ {command} --type=custom-domains --parameters='set-mapping=example.com/*:myservice'

         )DESCRIPTIONEXAMPLESc                     t        j                  |       t        j                  |       t        j                  |       t        j                  |       t        j
                  |       y)z\Set up arguments for this command.

    Args:
      parser: An argparse.ArgumentParser.
    N)r
   
AddTypeArg
AddNameArgAddServiceCreateArgAddParametersArgAddServiceAccountArg)clsparsers     &lib/surface/run/integrations/create.pyArgszCreate.Args4   sJ     
V	V	f%	6"	v&    c                    t        j                          t        j                          |j                  }|j                  }|j
                  }t        j                  |      }t        j                  |||       t        j                  |       | j                         }t        j                  ||      5 }|j                          | j                  ||||       |j                  ||||      }ddd       j!                        }	|j#                  |	j$                        }
t'        j(                  |      }t+        j,                  d       t+        j.                  t1        j2                  ||d             t1        j4                  ||	|
      }|rTt+        j,                  d       t+        j,                  |       t+        j,                  t1        j6                  ||             yy# 1 sw Y   xY w)z Creates a Cloud Run Integration.)integration_typeserviceintegration_name)r   
parametersr   nameN created)r   r    action)r	   CheckIfEndOfSaleAppliesDeprecationNoticetyper   r"   r
   GetParametersValidateCreateParametersValidateEnabledGcpApisReleaseTrackr   ConnectVerifyLocation'_validateServiceNameAgainstIntegrationsCreateIntegrationGetIntegrationGenericGetIntegrationStatusidr   GetTypeMetadatar   InfoSuccessr   GetSuccessMessageGetCallToActionCheckStatusMessage)selfargsr   r   
input_namer!   release_trackclientr    resourceresource_statusmetadatacall_to_actions                r   Runz
Create.RunA   s   ,,.&&(yyllGJ$$T*J	""#3ZI	  !12%%'M		$	$T=	9V
22
+%	 3   11+	 2  
: ++,<=H11(++>O**+;<Hb''--	
 #22(ON '

*
*=:J
K = 
:	9s   4;G&&G/c                     |syt        j                  d      }||k(  r||j                  |d      }|D ]  }|j                  |k(  s| y)z7Checks if the service name matches an integration name.Nz`Service name cannot be the same as the provided integration name or an existing integration name)r   ArgumentErrorListIntegrationsr    )r:   r>   r   r    r   errorintegrationsintegrations           r   r/   z.Create._validateServiceNameAgainstIntegrationsr   s_     $$	&E
 ""k**+;TBL#		%	%	0 $r   N)	__name__
__module____qualname____doc__detailed_helpclassmethodr   rC   r/    r   r   r   r      s7     (		-  
' 
'/br   r   N)rM   
__future__r   r   r   'googlecloudsdk.api_lib.run.integrationsr   googlecloudsdk.callioper   googlecloudsdk.command_lib.runr   +googlecloudsdk.command_lib.run.integrationsr	   r
   r   r   "googlecloudsdk.command_lib.runappsr   ReleaseTracksr,   ALPHABETADefaultUniverseOnlyCommandr   rP   r   r   <module>r\      s    P &  ' ? ( 7 H = E K 9 D%%++T->->-C-CDaT\\ a  Ear   