
    ]jF                        d dl Z d dlmZ ddlmZ ddlmZmZ ddlm	Z	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 j6                  e j8                  d      Z G d d      Z G d d      Zy)    N)JSONDecodeError   )ApiError)AsyncClientWrapperSyncClientWrapper)AsyncHttpResponseHttpResponse)RequestOptions)construct_type)BadRequestError)NotFoundError)LseapiTokenCreate)LseapiTokenList)TokenRefreshResponse)TokenRotateResponse.c            
          e Zd ZdefdZddddej                  e   dej                  e   de	ej                  e      fdZdd	dej                  e   de	e   fd
Zdd	dedej                  e   de	ej                  eej                   f      fdZdd	dedej                  e   de	e   fdZdd	dedej                  e   de	e   fdZy)RawTokensClientclient_wrapperc                    || _         y N_client_wrapperselfr   s     L/root/env/lib/python3.12/site-packages/label_studio_sdk/tokens/raw_client.py__init__zRawTokensClient.__init__   
    -    Norderingrequest_optionsr    r!   returnc                P   | j                   j                  j                  ddd|i|      }	 d|j                  cxk  rdk  rin nft	        j
                  t        j                  t           t        t        j                  t           |j                                     }t        ||      S |j                         }t        |j                  t        |j                        |	      # t        $ r6 t        |j                  t        |j                        |j                  	      w xY w)
a  
        List all API tokens for the current user.

        Parameters
        ----------
        ordering : typing.Optional[str]
            Which field to use when ordering the results.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[typing.List[LseapiTokenList]]

        
api/token/GETr    methodparamsr!      ,  type_object_responsedatastatus_codeheadersbody)r   httpx_clientrequestr2   typingcastListr   r   jsonr	   r   r   dictr3   textr   r    r!   	_response_data_response_jsons         r   listzRawTokensClient.list   s   & ((55==H , > 
		ti++1c1KK0"$kk/: ) 0 $YUCC&^^-N 9#8#8$yGXGXBY`noo  	ty'<'<d9K\K\F]dmdrdrss	ts   A=C& +C& &?D%r!   c                   | j                   j                  j                  dd|      }	 d|j                  cxk  rdk  rGn nDt	        j
                  t        t        t        |j                                     }t        ||      S |j                         }t        |j                  t        |j                        |      # t        $ r6 t        |j                  t        |j                        |j                        w xY w)	a  
        Create a new API token for the current user.

        Parameters
        ----------
        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[LseapiTokenCreate]

        r$   POSTr'   r!   r)   r*   r+   r.   r1   )r   r5   r6   r2   r7   r8   r   r   r:   r	   r   r   r;   r3   r<   r   r!   r>   r?   r@   s        r   createzRawTokensClient.createD   s     ((55==+ > 
	
	ti++1c1%"/ ) 0 $YUCC&^^-N 9#8#8$yGXGXBY`noo  	ty'<'<d9K\K\F]dmdrdrss	ts   AC C ?D refreshc                   | j                   j                  j                  ddd|iddi|t              }	 d|j                  cxk  rdk  rn nt        j                  t
        j                  t        t
        j                  f   t        t
        j                  t        t
        j                  f   |j                         	            }t        ||
      S |j                  dk(  rit        t        |j                        t        j                  t
        j                  t        t
        j                  |j                         	                  |j                         }t#        |j                  t        |j                        |      # t         $ r6 t#        |j                  t        |j                        |j$                        w xY w)ap  
        Adds a JWT refresh token to the blacklist, preventing it from being used to obtain new access tokens.

        Parameters
        ----------
        refresh : str

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[typing.Dict[str, typing.Any]]

        api/token/blacklist/rD   rH   content-typeapplication/jsonr'   r:   r3   r!   omitr)   r*   r+   r.     r3   r4   r1   )r   r5   r6   OMITr2   r7   r8   DictstrAnyr   r:   r	   r   r;   r3   r   r   r<   r   rH   r!   r>   r?   r@   s         r   	blacklistzRawTokensClient.blacklistf   sz   $ ((55=="7  2 , > 
		ti++1c1KKVZZ0"$kk#vzz/: ) 0 $YUCC$$+# !2!23

&"(**$-NN$4	 	 '^^-N 9#8#8$yGXGXBY`noo  	ty'<'<d9K\K\F]dmdrdrss	ts   BF BF ?Gc                   | j                   j                  j                  ddd|iddi|t              }	 d|j                  cxk  rdk  rGn nDt        j                  t        t        t        |j                         	            }t        ||
      S |j                         }t        |j                  t        |j                        |      # t        $ r6 t        |j                  t        |j                        |j                        w xY w)a1  
        Get a new access token, using a refresh token.

        Parameters
        ----------
        refresh : str

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[TokenRefreshResponse]

        api/token/refresh/rD   rH   rK   rL   rM   r)   r*   r+   r.   r1   )r   r5   r6   rQ   r2   r7   r8   r   r   r:   r	   r   r   r;   r3   r<   rU   s         r   rH   zRawTokensClient.refresh   s   $ ((55== 7  2 , > 
		ti++1c1("2 ) 0 $YUCC&^^-N 9#8#8$yGXGXBY`noo  	ty'<'<d9K\K\F]dmdrdrss	ts   AC C ?Dc                   | j                   j                  j                  ddd|iddi|t              }	 d|j                  cxk  rdk  rGn nDt        j                  t        t        t        |j                         	            }t        ||
      S |j                  dk(  rit        t        |j                        t        j                  t
        j                  t        t
        j                  |j                         	                  |j                         }t!        |j                  t        |j                        |      # t        $ r6 t!        |j                  t        |j                        |j"                        w xY w)aA  
        Creates a new JWT refresh token and blacklists the current one.

        Parameters
        ----------
        refresh : str

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[TokenRotateResponse]

        api/token/rotate/rD   rH   rK   rL   rM   r)   r*   r+   r.     rP   r1   )r   r5   r6   rQ   r2   r7   r8   r   r   r:   r	   r   r;   r3   rT   r   r   r<   rU   s         r   rotatezRawTokensClient.rotate   sX   $ ((55==7  2 , > 
		ti++1c1'"1 ) 0 $YUCC$$+% !2!23

&"(**$-NN$4	 	 '^^-N 9#8#8$yGXGXBY`noo  	ty'<'<d9K\K\F]dmdrdrss	ts   AE BE ?F)__name__
__module____qualname__r   r   r7   OptionalrS   r
   r	   r9   r   rA   r   rG   rR   rT   rV   r   rH   r   r\    r   r   r   r      s?   .*; . 37ko(p!??3/(pIOYgIh(p	fkk/2	3(pT LP  p)H  pT`arTs  pF SW6p6p060O6p	fkk#vzz/2	36pr SW+p+p060O+p	*	++p\ SW6p6p060O6p	)	*6pr   r   c            
          e Zd ZdefdZddddej                  e   dej                  e   de	ej                  e      fdZdd	dej                  e   de	e   fd
Zdd	dedej                  e   de	ej                  eej                   f      fdZdd	dedej                  e   de	e   fdZdd	dedej                  e   de	e   fdZy)AsyncRawTokensClientr   c                    || _         y r   r   r   s     r   r   zAsyncRawTokensClient.__init__  r   r   Nr   r    r!   r"   c                l  K   | j                   j                  j                  ddd|i|       d{   }	 d|j                  cxk  rdk  rin nft	        j
                  t        j                  t           t        t        j                  t           |j                                     }t        ||	      S |j                         }t        |j                  t        |j                        |
      7 # t        $ r6 t        |j                  t        |j                        |j                  
      w xY ww)a  
        List all API tokens for the current user.

        Parameters
        ----------
        ordering : typing.Optional[str]
            Which field to use when ordering the results.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[typing.List[LseapiTokenList]]

        r$   r%   r    r&   Nr)   r*   r+   r.   r1   )r   r5   r6   r2   r7   r8   r9   r   r   r:   r   r   r   r;   r3   r<   r=   s         r   rA   zAsyncRawTokensClient.list  s    & ..;;CCH , D 
 
		ti++1c1KK0"$kk/: ) 0 ))%HH&^^-N 9#8#8$yGXGXBY`noo+
&  	ty'<'<d9K\K\F]dmdrdrss	ts3   /D4C0D4A=C2 4D45C2 ,D42?D11D4rB   c                "  K   | j                   j                  j                  dd|       d{   }	 d|j                  cxk  rdk  rGn nDt	        j
                  t        t        t        |j                                     }t        ||      S |j                         }t        |j                  t        |j                        |	      7 # t        $ r6 t        |j                  t        |j                        |j                  	      w xY ww)
a  
        Create a new API token for the current user.

        Parameters
        ----------
        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[LseapiTokenCreate]

        r$   rD   rE   Nr)   r*   r+   r.   r1   )r   r5   r6   r2   r7   r8   r   r   r:   r   r   r   r;   r3   r<   rF   s        r   rG   zAsyncRawTokensClient.create2  s       ..;;CC+ D 
 
	
	ti++1c1%"/ ) 0 ))%HH&^^-N 9#8#8$yGXGXBY`noo%
   	ty'<'<d9K\K\F]dmdrdrss	ts3   ,DCDAC DC  ,D?DDrH   c                  K   | j                   j                  j                  ddd|iddi|t               d{   }	 d|j                  cxk  rd	k  rn nt        j                  t
        j                  t        t
        j                  f   t        t
        j                  t        t
        j                  f   |j                         
            }t        ||      S |j                  dk(  rit        t        |j                        t        j                  t
        j                  t        t
        j                  |j                         
                  |j                         }t#        |j                  t        |j                        |      7 W# t         $ r6 t#        |j                  t        |j                        |j$                        w xY ww)au  
        Adds a JWT refresh token to the blacklist, preventing it from being used to obtain new access tokens.

        Parameters
        ----------
        refresh : str

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[typing.Dict[str, typing.Any]]

        rJ   rD   rH   rK   rL   rM   Nr)   r*   r+   r.   rO   rP   r1   )r   r5   r6   rQ   r2   r7   r8   rR   rS   rT   r   r:   r   r   r;   r3   r   r   r<   rU   s         r   rV   zAsyncRawTokensClient.blacklistV  s    $ ..;;CC"7  2 , D 
 
		ti++1c1KKVZZ0"$kk#vzz/: ) 0 ))%HH$$+# !2!23

&"(**$-NN$4	 	 '^^-N 9#8#8$yGXGXBY`nooI
D  	ty'<'<d9K\K\F]dmdrdrss	ts4   7GFGBF GBF %,G?GGc                8  K   | j                   j                  j                  ddd|iddi|t               d{   }	 d|j                  cxk  rd	k  rGn nDt        j                  t        t        t        |j                         
            }t        ||      S |j                         }t        |j                  t        |j                        |      7 # t        $ r6 t        |j                  t        |j                        |j                        w xY ww)a6  
        Get a new access token, using a refresh token.

        Parameters
        ----------
        refresh : str

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[TokenRefreshResponse]

        rX   rD   rH   rK   rL   rM   Nr)   r*   r+   r.   r1   )r   r5   r6   rQ   r2   r7   r8   r   r   r:   r   r   r   r;   r3   r<   rU   s         r   rH   zAsyncRawTokensClient.refresh  s    $ ..;;CC 7  2 , D 
 
		ti++1c1("2 ) 0 ))%HH&^^-N 9#8#8$yGXGXBY`noo3
.  	ty'<'<d9K\K\F]dmdrdrss	ts3   7DCDAC DC +,D?DDc                *  K   | j                   j                  j                  ddd|iddi|t               d{   }	 d|j                  cxk  rd	k  rGn nDt        j                  t        t        t        |j                         
            }t        ||      S |j                  dk(  rit        t        |j                        t        j                  t
        j                  t        t
        j                  |j                         
                  |j                         }t!        |j                  t        |j                        |      7 # t        $ r6 t!        |j                  t        |j                        |j"                        w xY ww)aF  
        Creates a new JWT refresh token and blacklists the current one.

        Parameters
        ----------
        refresh : str

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[TokenRotateResponse]

        rZ   rD   rH   rK   rL   rM   Nr)   r*   r+   r.   r[   rP   r1   )r   r5   r6   rQ   r2   r7   r8   r   r   r:   r   r   r;   r3   rT   r   r   r<   rU   s         r   r\   zAsyncRawTokensClient.rotate  sh    $ ..;;CC7  2 , D 
 
		ti++1c1'"1 ) 0 ))%HH$$+% !2!23

&"(**$-NN$4	 	 '^^-N 9#8#8$yGXGXBY`nooI
D  	ty'<'<d9K\K\F]dmdrdrss	ts4   7FEFAE FBE #,F?FF)r]   r^   r_   r   r   r7   r`   rS   r
   r   r9   r   rA   r   rG   rR   rT   rV   r   rH   r   r\   ra   r   r   rc   rc     s@   .*< . 37ko(p!??3/(pIOYgIh(p	6;;7	8(pV EI"p"(//."A"p	,	-"pJ SW6p6p060O6p	6;;sFJJ7	86pr SW+p+p060O+p	/	0+p\ SW6p6p060O6p	.	/6pr   rc   ) r7   json.decoderr   core.api_errorr   core.client_wrapperr   r   core.http_responser   r	   core.request_optionsr
   core.unchecked_base_modelr   errors.bad_request_errorr   errors.not_found_errorr   types.lseapi_token_creater   types.lseapi_token_listr   types.token_refresh_responser   types.token_rotate_responser   r8   rT   rQ   r   rc   ra   r   r   <module>rv      sc     ( % G @ 1 6 6 2 9 5 ? = v{{6::s#kp kp\mp mpr   