
    O                     t    S r SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSK	J
r  \R                  rS rS	 rg
)z The BigQuery CLI update command.    )absolute_import)division)print_function)flags)client_data_transfer)utilsc                    Sn[         R                  (       af  U S-   [         R                  -   S-   U-   nUR                  5       R                  5       R	                  5       R                  U0 S9R                  5       nU$ U S-   U-   nUR                  5       R	                  5       R                  U0 S9R                  5       nU$ )as  Checks valid credentials.

Checks if Data Transfer Service valid credentials exist for the given data
source and requesting user. Some data sources don't support service account,
so we need to talk to them on behalf of the end user. This method just checks
whether we have OAuth token for the particular user, which is a pre-requisite
before a user can create a transfer config.

Args:
  reference: The project reference.
  data_source: The data source of the transfer config.
  transfer_client: The transfer api client.

Returns:
  credentials: It contains an instance of CheckValidCredsResponse if valid
  credentials exist.
Nz/locations//dataSources/)namebody)FLAGSlocationprojects	locationsdataSourcescheckValidCredsexecute)	referencedata_sourcetransfer_clientcredentialsdata_source_references        +platform/bq/frontend/utils_data_transfer.pyCheckValidCredsr      s    $ +
^^
	
..	 	 		  	  "			3"	=	  
 &7+E  "		3"	=		  
    c                 R   U S-   U-   nUR                  5       R                  5       R                  US9R                  5       nSUS   -   S-   SR	                  US   5      -   S-   n[        S	U-   5        0 n[        S
5        [        R                  " S5      U[        R                  '   U$ )a7  Retrieves the authorization code.

An authorization code is needed if the Data Transfer Service does not
have credentials for the requesting user and data source. The Data
Transfer Service will convert this authorization code into a refresh
token to perform transfer runs on the user's behalf.

Args:
  reference: The project reference.
  data_source: The data source of the transfer config.
  transfer_client: The transfer api client.

Returns:
  auth_info: A dict which contains authorization info from user. It is either
  an authorization_code or a version_info.
r
   )r   zEhttps://bigquery.cloud.google.com/datatransfer/oauthz/auth?client_id=clientIdz&scope=z%20scopeszB&redirect_uri=urn:ietf:wg:oauth:2.0:oob&response_type=consent_user
zqPlease copy and paste the above URL into your web browser and follow the instructions to retrieve a version_info.zEnter your version_info here: )
r   r   getr   joinprintfrontend_utilsRawInputr   VERSION_INFO)r   r   r   data_source_retrievaldata_source_infoauth_uri	auth_infos          r   RetrieveAuthorizationInfor*   =   s    " $o5C {}
s%s&wy	  N$% 	

#H-./ 	M	M  x)A 2@1H1H&2) --. 
r   N)__doc__
__future__r   r   r   abslr   clientsr   frontendr   r#   r   r   r*    r   r   <module>r1      s.    & &  %  ( ,*Z*r   