
                         p    S r SSKJr  SSKJr  SSKJr  SSKrSSKJr  SSK	J
r
  SSK	Jr  S	 rS
 rS rS rg)z"Utils for GKE cluster memberships.    )absolute_import)division)unicode_literalsN)apis)
exceptions)
propertiesc                    SnSnSn[         R                  " X5      nUb2  UR                  S5      UR                  S5      UR                  S5      4$ [         R                  " X 5      nUb2  UR                  S5      UR                  S5      UR                  S5      4$ [         R                  " X05      nUb2  UR                  S5      UR                  S5      UR                  S5      4$ [        R                  " SR                  U 5      5      e)a*  The GKE resource URI can be of following types: zonal, regional or generic.

zonal - */projects/{project_id}/zones/{zone}/clusters/{cluster_name}
regional - */projects/{project_id}/regions/{zone}/clusters/{cluster_name}
generic - */projects/{project_id}/locations/{zone}/clusters/{cluster_name}

The expected patterns are matched to extract the cluster location and name.
Args:
 gke_uri: GKE resource URI, e.g., https://container.googleapis.com/v1/
   projects/my-project/zones/us-west2-c/clusters/test1

Returns:
  cluster's project, location, and name
z/.*\/projects\/(.*)\/zones\/(.*)\/clusters\/(.*)z1.*\/projects\/(.*)\/regions\/(.*)\/clusters\/(.*)z3.*\/projects\/(.*)\/locations\/(.*)\/clusters\/(.*)         a  argument --gke-uri: {} is invalid. --gke-uri must be of format: `https://container.googleapis.com/v1/projects/my-project/locations/us-central1-a/clusters/my-cluster`. You can use command: `gcloud container clusters list --uri` to view the current GKE clusters in your project.researchgroupr   Errorformat)gke_urizonal_uri_patternregional_uri_patternlocation_uri_patternzone_matcherregion_matcherlocation_matchers          Flib/googlecloudsdk/command_lib/container/fleet/memberships/gke_util.pyParseGKEURIr      s    IMO,6,a ,"4"4Q"79K9KA9NNN991;.QQQ  YY3=!q!q!q!  	. /5fWo	     c                     Sn[         R                  " X5      nUb"  UR                  S5      UR                  S5      4$ [        R                  " SR                  U 5      5      e)zParse GKE cluster's location and name.

Args:
 gke_cluster: GKE cluster sepecified in format {location}/{cluster_name}

Returns:
  cluster's location, and name
z
(.*)\/(.*)r
   r   znargument --gke-cluster: {} is invalid. --gke-cluster must be of format: `{{REGION OR ZONE}}/{{CLUSTER_NAME`}}`r   )gke_clusterrgxcluster_matchers      r   ParseGKEClusterr!   K   s`     	#IIc//   #_%:%:1%===//5vk/B	 r   c                     [         R                  " SS5      nUR                  S5      (       a  USS nSR                  UR	                  SSS	5      R	                  S
SS	5      U UU5      nSR                  X0X5      nXE4$ )a  Constructs GKE URI and resource name from args and container endpoint.

Args:
  project_id: the project identifier to which the cluster to be registered
    belongs.
  cluster_location: zone or region of the cluster.
  cluster_name: name of the cluster to be registered.

Returns:
  GKE resource link: full resource name as per go/resource-names
    (including preceding slashes).
  GKE cluster URI: URI string looks in the format of
  https://container.googleapis.com/v1/
    projects/{projectID}/locations/{location}/clusters/{clusterName}.
	containerv1/Nz)//{}/projects/{}/locations/{}/clusters/{}zhttps:// r
   zhttp://z*{}/v1/projects/{}/locations/{}/clusters/{})	core_apisGetEffectiveApiEndpointendswithr   replace)
project_idcluster_locationcluster_namecontainer_endpointgke_resource_linkgke_cluster_uris         r   %ConstructGKEClusterResourceLinkAndURIr2   ^   s    $ !88dK  %%+CR0AHH  R3;;Ir1M	 AGG&6/ 
	++r   c                     U c  Uc  gSnU (       a  [        U 5      u  p#nO?[        R                  R                  R                  R                  5       n[        U5      u  p4[        X#U5      $ )z5Get GKE cluster's full resource name and cluster URI.N)NN)r   r   VALUEScoreproject	GetOrFailr!   r2   )r   r   cluster_projectlocationnames        r   GetGKEClusterResoureLinkAndURIr;      s_    _,/&1'&:#Ot '',,44>>@O$[1NH	.$	OOr   )__doc__
__future__r   r   r   r   googlecloudsdk.api_lib.utilr   r(   googlecloudsdk.corer   r   r   r!   r2   r;    r   r   <module>rA      s6    ) &  ' 	 9 * *-`&,BPr   