
    9                     L    d Z ddlmZ dZdZdZdZdeded	efd
Z	 G d d      Z
y)z+Client for interacting with Management Hub.    )apiszedition_config,filterfoldersorganizationsprojectsresource_typeresource_idreturnc                     |  d| dS )z$Returns the full id of the resource./z/locations/global/managementHub r   r   s     8lib/googlecloudsdk/api_lib/storage/management_hub_api.py_get_full_id_stringr      s    ?!K=(G	HH    c                        e Zd ZdZ fdZ	 	 	 ddZd Z	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 	 	 	 	 ddZd Z	d Z
d	 Zd
 Zd Zd Z	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 	 ddZ xZS )ManagementHubApizClient for Management Hub API.c                     t         t        |           t        j                  dd      | _        t        j                  dd      | _        y )Nstoragev2)superr   __init__	core_apisGetClientInstanceclientGetMessagesModulemessages)self	__class__s    r   r   zManagementHubApi.__init__"   s9    	
D*,--i>DK//	4@DMr   c                     | j                   j                         }| j                   j                  j                  j                  |_        ||_         ||t        |      } ||      S )z3Disables the management hub for the given resource.managementHub
updateMaskname)r   ManagementHubEditionConfigValueValuesEnumDISABLEDeditionConfigr#   _FULL_UPDATE_MASK)r   full_idrequest_message_classpatch_methodmanagement_hubrequests         r   _disable_management_hubz(ManagementHubApi._disable_management_hub'   sa     ]]002N##@@II   "N#$$G   r   c                 >   g }|9|j                  |D cg c]  }| j                  j                  |        c}       |9|j                  |D cg c]  }| j                  j                  |        c}       | j                  j                  |      S c c}w c c}w )a  Returns the cloud storage buckets filter for the given args.

    Args:
      bucket_ids: List of bucket ids to be included in the filter.
      bucket_id_regexes: List of bucket id regexes to be included in the filter.

    Returns:
      The cloud storage buckets filter message.
    )bucketId)bucketIdRegex)cloudStorageBuckets)extendr   CloudStorageBucket&ManagementHubFilterCloudStorageBuckets)r   
bucket_idsbucket_id_regexesbuckets_filter	bucket_idbucket_id_regexs         r   !_get_cloud_storage_buckets_filterz2ManagementHubApi._get_cloud_storage_buckets_filter<   s     N%%i --
*
*I
*
>% 	
 $!2!2o --
*
*
*
I!2 	
 ==??* @  s   #B#Bc	                    | j                   j                         |_        d}	|r4| j                   j                  j                  j
                  |_        |	dz   S | j                   j                  j                  j                  |_        |0| j                   j                  |      |j                  _	        |	dz  }	|0| j                   j                  |      |j                  _
        |	dz  }	||&| j                  ||      |j                  _        |	dz  }	||&| j                  ||      |j                  _        |	dz  }	|	S )a  Updates the management hub filter and returns update_mask.

    Args:
      management_hub: The management hub object to be updated.
      inherit_from_parent: Whether to inherit config from the parent.
      include_locations: List of locations to be included in the filter.
      exclude_locations: List of locations to be excluded in the filter.
      include_bucket_ids: List of bucket ids to be included in the filter.
      exclude_bucket_ids: List of bucket ids to be excluded in the filter.
      include_bucket_id_regexes: List of bucket id regexes to be included in the
        filter.
      exclude_bucket_id_regexes: List of bucket id regexes to be excluded in the
        filter.

    Returns:
      The update mask to be used for the request.
    edition_configz,filter)	locationsz(,filter.included_cloud_storage_locationsz(,filter.excluded_cloud_storage_locationsz&,filter.included_cloud_storage_bucketsz&,filter.excluded_cloud_storage_buckets)r   ManagementHubFilterfilterr$   r%   INHERITr'   STANDARD(ManagementHubFilterCloudStorageLocationsincludedCloudStorageLocationsexcludedCloudStorageLocationsr;   includedCloudStorageBucketsexcludedCloudStorageBuckets)
r   r,   inherit_from_parentinclude_locationsexclude_locationsinclude_bucket_idsexclude_bucket_idsinclude_bucket_id_regexesexclude_bucket_id_regexesupdate_masks
             r   _set_management_hub_filterz+ManagementHubApi._set_management_hub_filterX   sl   : !MM==?N"K 
--
%
%
B
B
J
J " "" 	##@@II  
 $
--
@
@) A  9
 ??k$
--
@
@) A  9
 ??k %)B)N

0
0 "; 7
 ==k%)B)N

0
0 "; 7
 ==kr   c           
          | j                   j                         }||_        | j                  ||||||||      } |
 |	|||            S )z2Updates the management hub for the given resource.r    )r   r$   r#   rP   )r   r)   rH   rI   rJ   rK   rL   rM   rN   r*   r+   r,   rO   s                r   _update_management_hubz'ManagementHubApi._update_management_hub   sd     ]]002N!N11!!	K ([w	
 r   c                     t        t        |      }| j                  j                  |      }| j                  j
                  j                  |      S )zGets the management hub for the given sub folder.

    Args:
      folder_id: Id of the GCP hierarchy folder.

    Returns:
      The management hub object for the given sub folder.
    r   r#   )r   _FOLDER_RESOURCE_TYPEr   .StorageFoldersLocationsGetManagementHubRequestr   folders_locationsGetManagementHub)r   	folder_id	full_namer-   s       r   get_sub_folder_management_hubz.ManagementHubApi.get_sub_folder_management_hub   sO     $+I mmJJ K G ;;((99'BBr   c                     t        t        |      }| j                  j                  |      }| j                  j
                  j                  |      S )zGets the management hub for the given project.

    Args:
      project_name: Name of the GCP project.

    Returns:
      The management hub object for the given project.
    r   rT   )r   _PROJECT_RESOURCE_TYPEr   /StorageProjectsLocationsGetManagementHubRequestr   projects_locationsrX   )r   project_namerZ   r-   s       r   get_project_management_hubz+ManagementHubApi.get_project_management_hub   sO     $,,I mmKK L G ;;))::7CCr   c                     t        t        |      }| j                  j                  |      }| j                  j
                  j                  |      S )zGets the management hub for the given organization.

    Args:
      organization_id: Id of the GCP organization.

    Returns:
      The management hub object for the given organization.
    r   rT   )r   _ORGANIZATION_RESOURCE_TYPEr   4StorageOrganizationsLocationsGetManagementHubRequestr   organizations_locationsrX   )r   organization_idrZ   r-   s       r   get_organization_management_hubz0ManagementHubApi.get_organization_management_hub   sR     $1I
 	JJ 	K 	
 
 ;;..??HHr   c                     t        t        |      }| j                  || j                  j                  | j
                  j                  j                        S )zDisables the management hub for the given project.

    Args:
      project_name: Name of the GCP project.

    Returns:
      The management hub object for the given project.
    r   r)   r*   r+   )r   r]   r.   r   2StorageProjectsLocationsUpdateManagementHubRequestr   r_   UpdateManagementHub)r   r`   rZ   s      r   disable_project_management_hubz/ManagementHubApi.disable_project_management_hub   sP     $,,I ''"mm^^[[33GG (  r   c                     t        t        |      }| j                  || j                  j                  | j
                  j                  j                        S )zDisables the management hub for the given organization.

    Args:
      organization_id: Id of the GCP organization.

    Returns:
      The management hub object for the given organization.
    r   ri   )r   rc   r.   r   7StorageOrganizationsLocationsUpdateManagementHubRequestr   re   rk   )r   rf   rZ   s      r   #disable_organization_management_hubz4ManagementHubApi.disable_organization_management_hub  sP     $1I ''"mmcc[[88LL (  r   c                     t        t        |      }| j                  || j                  j                  | j
                  j                  j                        S )zDisables the management hub for the given sub folder.

    Args:
      sub_folder_id: Id of the GCP hierarchy folder.

    Returns:
      The management hub object for the given sub folder.
    r   ri   )r   rU   r.   r   1StorageFoldersLocationsUpdateManagementHubRequestr   rW   rk   )r   sub_folder_idrZ   s      r   !disable_sub_folder_management_hubz2ManagementHubApi.disable_sub_folder_management_hub%  sP     $+I ''"mm]][[22FF (  r   c	                     t        d|      }	| j                  |	|||||||| j                  j                  | j                  j
                  j                  
      S )a  Updates the management hub for the given GCP project.

    Args:

      project: Name of the GCP project.
      inherit_from_parent: Whether to inherit config from the parent.
      include_locations: List of locations to be included in the filter.
      exclude_locations: List of locations to be excluded in the filter.
      include_bucket_ids: List of bucket ids to be included in the filter.
      exclude_bucket_ids: List of bucket ids to be excluded in the filter.
      include_bucket_id_regexes: List of bucket id regexes to be included in the
        filter.
      exclude_bucket_id_regexes: List of bucket id regexes to be excluded in the
        filter.

    Returns:
      The management hub object.
    r   r   )r   rR   r   rj   r   r_   rk   )
r   projectrH   rI   rJ   rK   rL   rM   rN   rZ   s
             r   update_project_management_hubz.ManagementHubApi.update_project_management_hub8  s`    < $ gI &&!!HH&&:: r   c	                     t        d|      }	| j                  |	|||||||| j                  j                  | j                  j
                  j                  
      S )a  Updates the management hub for the given GCP sub folder.

    Args:

      sub_folder: The GCP sub folder name.
      inherit_from_parent: Whether to inherit config from the parent.
      include_locations: List of locations to be included in the filter.
      exclude_locations: List of locations to be excluded in the filter.
      include_bucket_ids: List of bucket ids to be included in the filter.
      exclude_bucket_ids: List of bucket ids to be excluded in the filter.
      include_bucket_id_regexes: List of bucket id regexes to be included in the
        filter.
      exclude_bucket_id_regexes: List of bucket id regexes to be excluded in the
        filter.

    Returns:
      The management hub object.
    r   r   )r   rR   r   rq   r   rW   rk   )
r   
sub_folderrH   rI   rJ   rK   rL   rM   rN   rZ   s
             r    update_sub_folder_management_hubz1ManagementHubApi.update_sub_folder_management_hubg  s`    : $ZI &&!!GG%%99 r   c	                     t        d|      }	| j                  |	|||||||| j                  j                  | j                  j
                  j                  
      S )a  Updates the management hub for the given GCP organization.

    Args:

      organization: The GCP organization name.
      inherit_from_parent: Whether to inherit config from the parent.
      include_locations: List of locations to be included in the filter.
      exclude_locations: List of locations to be excluded in the filter.
      include_bucket_ids: List of bucket ids to be included in the filter.
      exclude_bucket_ids: List of bucket ids to be excluded in the filter.
      include_bucket_id_regexes: List of bucket id regexes to be included in the
        filter.
      exclude_bucket_id_regexes: List of bucket id regexes to be excluded in the
        filter.

    Returns:
      The management hub object.
    r   r   )r   rR   r   rn   r   re   rk   )
r   organizationrH   rI   rJ   rK   rL   rM   rN   rZ   s
             r   "update_organization_management_hubz3ManagementHubApi.update_organization_management_hub  s`    : $%<I &&!!MM++?? r   )NNN)FNNNNNN)
NNNNNNNNNN)NNNNNNN)__name__
__module____qualname____doc__r   r.   r;   rP   rR   r[   ra   rg   rl   ro   rs   rv   ry   r|   __classcell__)r   s   @r   r   r      s    &A  	!*>   $ $K^  $ $  DC$D$I(&&,  $ $-d  $ $,b  $ $,r   r   N)r   googlecloudsdk.api_lib.utilr   r   r(   rU   rc   r]   strr   r   r   r   r   <module>r      sQ    2 9 , ! - # Is I I I
b br   