
                             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Z G d dej                        Zd Zd Z G d de      Zy
)zSourceRepo APIs layer.

Parse methods accepts strings from command-line arguments, and it can accept
more formats like "https://...". Get methods are strict about the arguments.
    )absolute_import)division)unicode_literals)
list_pager)apis)
exceptions)
properties)	resourcesNc                       e Zd ZdZy)RepoResourceErrorz'Raised when a repo could not be parsed.N)__name__
__module____qualname____doc__     /lib/googlecloudsdk/api_lib/source/sourcerepo.pyr   r   !   s    /r   r   c                    	 t         j                  j                  | dt        j                  j
                  j                  j                  id      S # t        j                  $ r#}t        t        j                  |            d}~ww xY w)z7Parse a string as a sourcerepo.projects.repos resource.
projectsIdzsourcerepo.projects.repos)params
collectionN)r
   REGISTRYParser	   VALUEScoreproject	GetOrFailcore_exceptionsErrorr   six	text_type)repoes     r   	ParseRepor$   %   sw    .##j//44<<FFG. $ 0 0 
		 .
CMM!,
--.s   AA B%BBc                      t         j                  j                  dt        j                  j
                  j                  j                               S )z=Create a sourcerepo.projects resource of the default project.sourcerepo.projectsr   )r
   r   Creater	   r   r   r   r   r   r   r   GetDefaultProjectr)   0   sA    				"	"""''//99; 
# 
= =r   c                   F    e Zd ZdZddZd Zd ZddZd Zd Z	d	 Z
dd
Zy)Sourcez'Base class for sourcerepo api wrappers.Nc                 x    |t        j                  dd      }|| _        t        j                  dd      | _        y )N
sourcerepov1)r   GetClientInstance_clientGetMessagesModulemessages)selfclients     r   __init__zSource.__init__:   s4    ~%%lD9fDL**<>DMr   c                     | j                   j                  |j                               }| j                  j                  j                  |      S )zGets IAM policy for a repo.

    Args:
      repo_resource:  The repo resource with collection type
        sourcerepo.projects.repos
    Returns:
      (messages.Policy) The IAM policy.
    )resource)r2   *SourcerepoProjectsReposGetIamPolicyRequestRelativeNamer0   projects_reposGetIamPolicyr3   repo_resourcerequests      r   r;   zSource.GetIamPolicy@   sE     mmFF++- G /G<<&&33G<<r   c                     | j                   j                  |      }| j                   j                  |j                         |      }| j                  j
                  j                  |      S )a  Sets the IAM policy from a policy string.

    Args:
      repo_resource: The repo as a resource with colleciton type
        sourcerepo.projects.repos
      policy: (string) The file containing the new IAM policy.
    Returns:
      (messages.Policy) The IAM policy.
    )policy)r7   setIamPolicyRequest)r2   SetIamPolicyRequest*SourcerepoProjectsReposSetIamPolicyRequestr9   r0   r:   SetIamPolicy)r3   r=   r@   reqr>   s        r   rD   zSource.SetIamPolicyM   s_     --
+
+6
+
:CmmFF++-3 G HG<<&&33G<<r   c                     t        j                  | j                  j                  | j                  j                  |j                               |d|d      S )zReturns list of repos.namepageSizerepos)limitbatch_size_attribute
batch_sizefield)r   YieldFromListr0   r:   r2   "SourcerepoProjectsReposListRequestr9   )r3   project_resourcerK   	page_sizes       r   	ListReposzSource.ListRepos\   sQ    ####88!..0 	9 	2' r   c                     | j                   j                  |j                               }| j                  j                  j                  |      S )a$  Finds details on the named repo, if it exists.

    Args:
      repo_resource: (Resource) A resource representing the repo to create.
    Returns:
      (messages.Repo) The full definition of the new repo, as reported by
        the server.
      Returns None if the repo does not exist.
    rG   )r2   !SourcerepoProjectsReposGetRequestr9   r0   r:   Getr<   s      r   GetRepozSource.GetRepog   sD     mm=='') > +G<<&&**733r   c                 H   t         j                  j                  d|j                        }| j                  j                  |j                         | j                  j                  |j                                     }| j                  j                  j                  |      S )zCreates a repo.

    Args:
      repo_resource: (Resource) A resource representing the repo to create.
    Returns:
      (messages.Repo) The full definition of the new repo, as reported by
        the server.
    r&   r'   rG   )parentr"   )
r
   r   r(   r   r2   $SourcerepoProjectsReposCreateRequestr9   Repor0   r:   )r3   r=   rY   r>   s       r   
CreateRepozSource.CreateRepou   s     &&-*B*B ' DFmm@@""$]]]%?%?%AB A DG <<&&--g66r   c                     | j                   j                  |j                               }| j                  j                  j                  |       y)zkDeletes a repo.

    Args:
      repo_resource: (Resource) A resource representing the repo to create.
    rG   N)r2   $SourcerepoProjectsReposDeleteRequestr9   r0   r:   Deleter<   s      r   
DeleteRepozSource.DeleteRepo   sB     mm@@'') A +GLL&&w/r   c                     | j                   j                  |j                  | j                   j                  ||            }| j                  j
                  j                  |      S )zUpdates a repo's configuration.)r"   
updateMask)rH   updateRepoRequest)r2   #SourcerepoProjectsReposPatchRequestrH   UpdateRepoRequestr0   r:   Patch)r3   r"   update_maskrE   s       r   	PatchRepozSource.PatchRepo   s[    
--
;
;YY--99+ : / < 0C <<&&,,S11r   )N)NN)pubsubConfigs)r   r   r   r   r5   r;   rD   rS   rW   r\   r`   rh   r   r   r   r+   r+   7   s-    /?==	47 02r   r+   )r   
__future__r   r   r   apitools.base.pyr   googlecloudsdk.api_lib.utilr   googlecloudsdk.corer   r   r	   r
   r    r   r   r$   r)   objectr+   r   r   r   <module>ro      sQ    '  ' ' , = * ) 
0-- 0.=^2V ^2r   