
    g7-                     r    d Z ddlZddlZddlZddlmZ ddlmZ ddlmZ ddZddZ	ddZ
d	 Zdd
ZddZy)zgApplication default credentials.

Implements application default credentials and project ID detection.
    N)_default)environment_vars)
exceptionsc                    t         j                  j                  |       s$t        j                  dj                  |             t        j                  | d      5 }	 t        j                  |      }	 ddd       j                  d      }|t        j                  k(  r\ddlm} 	 |j                   j#                  ||      }|r|j%                  |      }|j&                  st        j(                  |       |dfS |t        j*                  k(  rFdd
lm}
 	 |
j                   j/                  ||      j%                  |      }||j                  d      fS t        j                  dj                  | |t        j0                              # t        $ r-}t        j                  dj                  |       |      }||d}~ww xY w# 1 sw Y   QxY w# t        $ r/}d	j                  |       }	t        j                  |	|      }||d}~ww xY w# t        $ r/}dj                  |       }	t        j                  |	|      }||d}~ww xY w)aF  Loads Google credentials from a file.

    The credentials file must be a service account key or stored authorized
    user credentials.

    Args:
        filename (str): The full path to the credentials file.
        scopes (Optional[Sequence[str]]): The list of scopes for the credentials. If
            specified, the credentials will automatically be scoped if
            necessary
        quota_project_id (Optional[str]):  The project ID used for
                quota and billing.

    Returns:
        Tuple[google.auth.credentials.Credentials, Optional[str]]: Loaded
            credentials and the project ID. Authorized user credentials do not
            have the project ID information.

    Raises:
        google.auth.exceptions.DefaultCredentialsError: if the file is in the
            wrong format or is missing.
    zFile {} was not found.rz!File {} is not a valid json file.Ntyper   )_credentials_async)scopesz2Failed to load authorized user credentials from {})_service_account_asyncz2Failed to load service account credentials from {}
project_idzZThe file {file} does not have a valid type. Type is {type}, expected one of {valid_types}.)filer   valid_types)ospathexistsr   DefaultCredentialsErrorformatioopenjsonload
ValueErrorgetr   _AUTHORIZED_USER_TYPEgoogle.oauth2r	   Credentialsfrom_authorized_user_infowith_quota_projectquota_project_id#_warn_about_problematic_credentials_SERVICE_ACCOUNT_TYPEr   from_service_account_info_VALID_TYPES)filenamer
   r   file_objinfo
caught_excnew_exccredential_typecredentialsmsgservice_accounts              w/var/www/html/FastMealFinder_FlaskServer-InitialRelease/venv/lib/python3.12/site-packages/google/auth/_default_async.pyload_credentials_from_filer.      s4   . 77>>(#00$++H5
 	
 
3	 *8	*99X&D* hhv&O(888C	*%11KKV L K %889IJK++88ED  	H::	:K	*)55OOV P   !12  DHH\222 00==CVOAVAV >D >
 	
S  	* 883::8DjG z)		** *(  	*FMMhWC 88jIGz)	*"  	*FMMhWC 88jIGz)	*sZ   GF%G ,H	 	F>(F99F>>GG	H*HH		I*H<<Ic                     ddl m} |j                         }t        j                  j                  |      syt        ||       \  }}|s|j                         }||fS )z7Gets the credentials and project ID from the Cloud SDK.r   
_cloud_sdkNNr   )google.authr1   (get_application_default_credentials_pathr   r   isfiler.   get_project_id)r   r1   credentials_filenamer*   r   s        r-   _get_gcloud_sdk_credentialsr9   m   s]    & &NNP77>>./8/?K ..0

""    c                    ddl m} |j                         }t        j                  j                  t        j                        }|||k(  rt        |       S |3t        t        j                  t        j                     |       \  }}||fS y)zRGets credentials from the GOOGLE_APPLICATION_CREDENTIALS environment
    variable.r   r0   r3   r2   )
r4   r1   r5   r   environr   r   CREDENTIALSr9   r.   )r   r1   cloud_sdk_adc_pathexplicit_filer*   r   s         r-   !_get_explicit_environ_credentialsr@      s     '#LLNJJNN#3#?#?@M ]6H%H +<LMM "<JJ'334GW#
Z J&& r:   c                  *    t        j                         S )z?Gets Google App Engine App Identity credentials and project ID.)r   _get_gae_credentials r:   r-   rB   rB      s    
 ((**r:   c                 ,    t        j                  |       S )z>Gets credentials and project ID from the GCE Metadata Service.)r   _get_gce_credentialsrequests    r-   rE   rE      s     ((11r:   c                 *   ddl m} ddlm} t        j
                  j                  t        j                  t        j
                  j                  t        j                              }fdfdt        fdf}|D ]r  } |       \  }}	| |||       }rt        ||      r|j                        }|xs |	}
|
s.t        j                  j                  dt        j                         ||
fc S  t!        j"                  t        j$                        )ah  Gets the default credentials for the current environment.

    `Application Default Credentials`_ provides an easy way to obtain
    credentials to call Google APIs for server-to-server or local applications.
    This function acquires credentials from the environment in the following
    order:

    1. If the environment variable ``GOOGLE_APPLICATION_CREDENTIALS`` is set
       to the path of a valid service account JSON private key file, then it is
       loaded and returned. The project ID returned is the project ID defined
       in the service account file if available (some older files do not
       contain project ID information).
    2. If the `Google Cloud SDK`_ is installed and has application default
       credentials set they are loaded and returned.

       To enable application default credentials with the Cloud SDK run::

            gcloud auth application-default login

       If the Cloud SDK has an active project, the project ID is returned. The
       active project can be set using::

            gcloud config set project

    3. If the application is running in the `App Engine standard environment`_
       (first generation) then the credentials and project ID from the
       `App Identity Service`_ are used.
    4. If the application is running in `Compute Engine`_ or `Cloud Run`_ or
       the `App Engine flexible environment`_ or the `App Engine standard
       environment`_ (second generation) then the credentials and project ID
       are obtained from the `Metadata Service`_.
    5. If no credentials are found,
       :class:`~google.auth.exceptions.DefaultCredentialsError` will be raised.

    .. _Application Default Credentials: https://developers.google.com            /identity/protocols/application-default-credentials
    .. _Google Cloud SDK: https://cloud.google.com/sdk
    .. _App Engine standard environment: https://cloud.google.com/appengine
    .. _App Identity Service: https://cloud.google.com/appengine/docs/python            /appidentity/
    .. _Compute Engine: https://cloud.google.com/compute
    .. _App Engine flexible environment: https://cloud.google.com            /appengine/flexible
    .. _Metadata Service: https://cloud.google.com/compute/docs            /storing-retrieving-metadata
    .. _Cloud Run: https://cloud.google.com/run

    Example::

        import google.auth

        credentials, project_id = google.auth.default()

    Args:
        scopes (Sequence[str]): The list of scopes for the credentials. If
            specified, the credentials will automatically be scoped if
            necessary.
        request (google.auth.transport.Request): An object used to make
            HTTP requests. This is used to detect whether the application
            is running on Compute Engine. If not specified, then it will
            use the standard library http client to make requests.
        quota_project_id (Optional[str]):  The project ID used for
            quota and billing.
    Returns:
        Tuple[~google.auth.credentials.Credentials, Optional[str]]:
            the current environment's credentials and project ID. Project ID
            may be None, which indicates that the Project ID could not be
            ascertained from the environment.

    Raises:
        ~google.auth.exceptions.DefaultCredentialsError:
            If no credentials were found, or if the credentials found were
            invalid.
    r   )with_scopes_if_required)CredentialsWithQuotaProjectc                      t               S Nr3   )r@   r3   s   r-   <lambda>zdefault_async.<locals>.<lambda>  s    1CST r:   c                      t               S rL   )r9   r3   s   r-   rM   zdefault_async.<locals>.<lambda>  s    +=MN r:   c                      t               S N)rE   rF   s   r-   rM   zdefault_async.<locals>.<lambda>  s    $W- r:   zvNo project ID could be determined. Consider running `gcloud config set project` or setting the %s environment variable)google.auth._credentials_asyncrI   google.auth.credentialsrJ   r   r<   r   r   PROJECTLEGACY_PROJECTrB   
isinstancer   r   _LOGGERwarningr   r   _CLOUD_SDK_MISSING_CREDENTIALS)r
   rG   r   rI   rJ   explicit_project_idcheckerscheckerr*   r   effective_project_ids    ``        r-   default_asyncr]      s    V GC**..  "**..1A1P1P"Q
 	UN-	H  5"))Z"1+vFKJ8% *<<=MN#6#D* '  ((+ %,,	  444!5$ 
,
,X-T-T
UUr:   r2   rP   )NNN)__doc__r   r   r   r4   r   r   r   r.   r9   r@   rB   rE   r]   rC   r:   r-   <module>r_      s@   
 
  	   ( "M
`#(2+
2kVr:   