
    ,Of4                        d dl mZ d dlZd dlZd dlmZ d dlZd dlZd dlm	Z	 d dl
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  G d d      Zy)    )annotationsN)Any)Retry)Consts)AppAuth)	GithubApp)GithubException)Installation)InstallationAuthorization)PaginatedList)	Requesterc                  8   e Zd ZU dZded<   ded<   ded<   ddej                  fej                  ej                  ej                  d	ddej                  ej                  ej                  ej                  ej                  dd
	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZddZddZd dZ	 d!	 	 	 	 	 d"dZd#dZd$dZ ej,                  d      d!d%d       Z	 d!	 	 	 	 	 d&dZ ej,                  d      d'd       Zd(dZd)dZd'dZd*dZd+dZd,dZy)-GithubIntegrationz?
    Main class to obtain tokens for a GitHub integration.
    r   authstrbase_urlr   _GithubIntegration__requesterNT)timeout
user_agentper_pageverifyretry	pool_sizeseconds_between_requestsseconds_between_writes
jwt_expiryjwt_issued_atjwt_algorithmr   c               r   |t        |t        t        f      sJ |       |t        |t              sJ d       t        |t              sJ |       t        |t              sJ |       |t        |t              sJ |       t        |t              sJ |       t        |t        t        f      sJ |       |;t        |t              s+t        |t        j
                  j                        sJ |       |	t        |	t              sJ |	       |
|
dk\  sJ ||dk\  sJ t        |t              sJ |       t        j                  |cxk  rt        j                  k  sJ |        J |       t        |t              sJ || _
        |;|9|t        j                  k7  s&|t        j                  k7  s|t        j                  k7  r+t        j                  dt                t#        |||||      }t        |t"              sJ dt%        |              || _        t)        || j                  ||||||	|
|
      | _        y)	aM  
        :param integration_id: int deprecated, use auth=github.Auth.AppAuth(...) instead
        :param private_key: string deprecated, use auth=github.Auth.AppAuth(...) instead
        :param base_url: string
        :param timeout: integer
        :param user_agent: string
        :param per_page: int
        :param verify: boolean or string
        :param retry: int or urllib3.util.retry.Retry object
        :param pool_size: int
        :param seconds_between_requests: float
        :param seconds_between_writes: float
        :param jwt_expiry: int deprecated, use auth=github.Auth.AppAuth(...) instead
        :param jwt_issued_at: int deprecated, use auth=github.Auth.AppAuth(...) instead
        :param jwt_algorithm: string deprecated, use auth=github.Auth.AppAuth(...) instead
        :param auth: authentication method
        Nz'supplied private key should be a stringr   zArguments integration_id, private_key, jwt_expiry, jwt_issued_at and jwt_algorithm are deprecated, please use auth=github.Auth.AppAuth(...) instead)category)r   r   r   zCGithubIntegration requires github.Auth.AppAuth authentication, not )
r   r   r   r   r   r   r   r   r   r   )
isinstanceintr   boolurllib3utilr   r   MIN_JWT_EXPIRYMAX_JWT_EXPIRYr   DEFAULT_JWT_EXPIRYDEFAULT_JWT_ISSUED_ATDEFAULT_JWT_ALGORITHMwarningswarnDeprecationWarningr   typer   r   r   )selfintegration_idprivate_keyr   r   r   r   r   r   r   r   r   r   r   r   r   s                   8lib/python3.12/site-packages/github/GithubIntegration.py__init__zGithubIntegration.__init__C   sN   H %nsCj9I>I9"k3/Z1ZZ/(C(2(2('3'00'!Z
C%@L*L@(C(2(2(&4+.66.}
5# 6*UGLLL^L^:_faff_ Jy#$>I	I>'/3Kq3PPP%-1G11LLL*c*6J6*$$
Kf6K6KKWZWKWZWK----  &&V666 < << < <<MMC+
 %++D '
 	^PQUVZQ[P\]	^ 
 	$]]!%=#9
    c                8    | j                   j                          y)zClose connections to the server. Alternatively, use the
        GithubIntegration object as a context manager:

        .. code-block:: python

          with github.GithubIntegration(...) as gi:
            # do something
        N)r   closer/   s    r2   r6   zGithubIntegration.close   s     	 r4   c                    | S N r7   s    r2   	__enter__zGithubIntegration.__enter__   s    r4   c                $    | j                          y r9   )r6   )r/   exc_typeexc_valexc_tbs       r2   __exit__zGithubIntegration.__exit__   s    

r4   c                    | j                   j                  ||| j                        }t        j                  di | j                  j                  |      j                  S )Nr:   )r   get_installation_authr   githubGithubwithAuthkwargs)r/   installation_idtoken_permissionsr   s       r2   get_github_for_installationz-GithubIntegration.get_github_for_installation   sM     yy..@QSWScScd}}Ft//88>EEFFr4   c                &    dt         j                  iS )z/
        Get headers for the requests.
        Accept)r   mediaTypeIntegrationPreviewr7   s    r2   _get_headerszGithubIntegration._get_headers   s    
 f88
 	
r4   c                    | j                   j                  d|| j                               \  }}t        | j                   ||d      S )z5
        Get installation for the given URL.
        GETheadersT	requesterrQ   
attributes	completed)r   requestJsonAndCheckrM   r
   )r/   urlrQ   responses       r2   _get_installed_appz$GithubIntegration._get_installed_app   sO     !,,@@UYUfUfUh@i&&	
 	
r4   z|Use github.Github(auth=github.Auth.AppAuth), github.Auth.AppAuth.token or github.Auth.AppAuth.create_jwt(expiration) insteadc                8    | j                   j                  |      S )z
        Create a signed JWT
        https://docs.github.com/en/developers/apps/building-github-apps/authenticating-with-github-apps#authenticating-as-a-github-app
        )r   
create_jwt)r/   
expirations     r2   r[   zGithubIntegration.create_jwt   s     yy##J//r4   c                    |i }t        |t              st        dddid      d|i}| j                  j	                  dd| d	| j                         |
      \  }}t        | j                  ||d      S )z
        :calls: `POST /app/installations/{installation_id}/access_tokens <https://docs.github.com/en/rest/apps/apps#create-an-installation-access-token-for-an-app>`
        Ni  messagezInvalid permissions)statusdatarQ   permissionsPOST/app/installations/z/access_tokens)rQ   inputTrR   )r!   dictr	   r   rV   rM   r   )r/   rG   ra   bodyrQ   rX   s         r2   get_access_tokenz"GithubIntegration.get_access_token   s     K+t,!I?T3U_cdd{+ ,,@@!/!2.A%%'	 A 
 )&&	
 	
r4   zUse get_repo_installationc                    t         j                  j                  |      }t         j                  j                  |      }| j                  d| d| d      S )z
        Deprecated by get_repo_installation.

        :calls: `GET /repos/{owner}/{repo}/installation
        <https://docs.github.com/en/rest/reference/apps#get-a-repository-installation-for-the-authenticated-app>`

        /repos///installationrW   urllibparsequoterY   r/   ownerrepos      r2   get_installationz"GithubIntegration.get_installation   sO     ""5)||!!$'&&WUG1TF-+P&QQr4   c                \    t        t        | j                  dd| j                         d      S )z
        :calls: GET /app/installations <https://docs.github.com/en/rest/reference/apps#list-installations-for-the-authenticated-app>
        z/app/installationsNinstallations)contentClassrS   firstUrlfirstParamsrQ   	list_item)r   r
   r   rM   r7   s    r2   get_installationsz#GithubIntegration.get_installations   s2     %&&)%%'%
 	
r4   c                l    t         j                  j                  |      }| j                  d| d      S )z
        :calls: `GET /orgs/{org}/installation <https://docs.github.com/en/rest/apps/apps#get-an-organization-installation-for-the-authenticated-app>`
        z/orgs/rk   rl   rm   )r/   orgs     r2   get_org_installationz&GithubIntegration.get_org_installation  s5     ll  %&&VC5+F&GGr4   c                    t         j                  j                  |      }t         j                  j                  |      }| j                  d| d| d      S )z
        :calls: `GET /repos/{owner}/{repo}/installation <https://docs.github.com/en/rest/reference/apps#get-a-repository-installation-for-the-authenticated-app>`
        ri   rj   rk   rl   rm   rq   s      r2   get_repo_installationz'GithubIntegration.get_repo_installation  sO     ""5)||!!$'&&WUG1TF-+P&QQr4   c                l    t         j                  j                  |      }| j                  d| d      S )z
        :calls: `GET /users/{username}/installation <https://docs.github.com/en/rest/apps/apps#get-a-user-installation-for-the-authenticated-app>`
        z/users/rk   rl   rm   )r/   usernames     r2   get_user_installationz'GithubIntegration.get_user_installation  s5     <<%%h/&&WXJm+L&MMr4   c                ,    | j                  d|       S )z
        :calls: `GET /app/installations/{installation_id} <https://docs.github.com/en/rest/apps/apps#get-an-installation-for-the-authenticated-app>`
        rc   rl   )rY   )r/   rG   s     r2   get_app_installationz&GithubIntegration.get_app_installation#  s!     &&-@@Q+R&SSr4   c                    | j                   j                  dd| j                               \  }}t        | j                   ||d      S )zp
        :calls: `GET /app <https://docs.github.com/en/rest/reference/apps#get-the-authenticated-app>`_
        rO   z/apprP   TrR   )r   rV   rM   r   )r/   rQ   r`   s      r2   get_appzGithubIntegration.get_app)  sH    
 ((<<UFTXTeTeTg<h4#3#3WQUaeffr4   ) r0   zint | str | Noner1   z
str | Noner   r   r   r"   r   r   r   r"   r   z
bool | strr   zint | Retry | Noner   
int | Noner   float | Noner   r   r   r"   r   r"   r   r   r   zAppAuth | NonereturnNone)r   r   )r   r   )r=   r   r>   r   r?   r   r   r   r9   )rG   r"   rH   dict[str, str] | Noner   zgithub.Github)r   zdict[str, str])rW   r   r   r
   )r\   r   r   r   )rG   r"   ra   r   r   r   )rr   r   rs   r   r   r
   )r   zPaginatedList[Installation])r}   r   r   r
   )r   r   r   r
   )rG   r"   r   r
   )r   r   ) __name__
__module____qualname____doc____annotations__r   DEFAULT_BASE_URLDEFAULT_TIMEOUTDEFAULT_USER_AGENTDEFAULT_PER_PAGE DEFAULT_SECONDS_BETWEEN_REQUESTSDEFAULT_SECONDS_BETWEEN_WRITESr(   r)   r*   r3   r6   r;   r@   rI   rM   rY   
deprecatedr[   rg   rt   r{   r~   r   r   r   r   r:   r4   r2   r   r   4   s    MM ,0"&//	\
 -- 33//!$( $171X1X/5/T/T 33#99#99##\
(\
  \
 	\
 \
 \
 \
 \
 "\
 \
 #/\
 !-\
 \
 \
  !\
" #\
$ 
%\
|	! PTG"G7LG	G

 Z 	G00 JN
"
1F
	"
6 Z67
R 8
R
HRNTgr4   r   )
__future__r   urllib.parsern   r+   typingr   r   r$   r   rC   r   github.Authr   github.GithubAppr   github.GithubExceptionr	   github.Installationr
    github.InstallationAuthorizationr   github.PaginatedListr   github.Requesterr   r   r:   r4   r2   <module>r      sE   > #          & 2 , F . &{g {gr4   