File manager - Edit - /opt/saltstack/salt/lib/python3.10/site-packages/libcloud/common/__pycache__/google.cpython-310.pyc
Back
o ;j� � @ sx d Z ddlZddlZddlZddlZddlZddlZddlZddlZ ddl mZ ddlm Z mZ ddlmZmZmZmZ ddlmZmZmZmZ ddlmZmZ ddlmZ zddlZW n e yi ddlZY nw z dd l!m"Z" dd l#m$Z$ ddl%m&Z& ddl'm(Z( dd l)m*Z* W n e y� dZ(Y nw dZ+e�,e-�Z.dd� Z/dd� Z0dd� Z1d;dee2 fdd�Z3G dd� de�Z4G dd� de�Z5G dd� de5�Z6G dd � d e5�Z7G d!d"� d"e5�Z8G d#d$� d$e5�Z9G d%d&� d&e5�Z:G d'd(� d(e5�Z;G d)d*� d*e�Z<G d+d,� d,e�Z=G d-d.� d.e�Z>G d/d0� d0e>�Z?G d1d2� d2e>�Z@G d3d4� d4e>�ZAG d5d6� d6�ZBG d7d8� d8�ZCG d9d:� d:ee�ZDdS )<a� Module for Google Connection and Authentication classes. Information about setting up your Google OAUTH2 credentials: For libcloud, there are two basic methods for authenticating to Google using OAUTH2: Service Accounts and Client IDs for Installed Applications. Both are initially set up from the Cloud Console Console - https://cloud.google.com/console Setting up Service Account authentication (note that you need the cryptography package installed to use this): - Go to the Console - Go to your project and then to "APIs & auth" on the left - Click on "Credentials" - Click on "Create New Client ID..." - Select "Service account" and click on "Create Client ID" - Download the Private Key (should happen automatically). The key you download is in JSON format. - Move the .json file to a safe location. - Optionally, you may choose to Generate a PKCS12 key from the Console. It needs to be converted to the PEM format. Please note, the PKCS12 format is deprecated and may be removed in a future release. - Convert the key using OpenSSL (the default password is 'notasecret'). - Move the .pem file to a safe location. - To Authenticate, you will need to pass the Service Account's "Email address" in as the user_id and the path to the .pem file as the key. Setting up Installed Application authentication: - Go to the Console - Go to your project and then to "APIs & auth" on the left - Click on "Credentials" - Select "Installed application" and "Other" then click on "Create Client ID" - To Authenticate, pass in the "Client ID" as the user_id and the "Client secret" as the key - The first time that you do this, the libcloud will give you a URL to visit. Copy and paste the URL into a browser. - When you go to the URL it will ask you to log in (if you aren't already) and ask you if you want to allow the project access to your account. - Click on Accept and you will be given a code. - Paste that code at the prompt given to you by the Google libcloud connection. - At that point, a token & refresh token will be stored in your home directory and will be used for authentication. Please remember to secure your keys and access tokens. � N)�Optional)� HTTPServer�BaseHTTPRequestHandler)�b�httplib�urlparse� urlencode)� BaseDriver�JsonResponse�PollingConnection�ConnectionUserAndKey)� LibcloudError� ProviderError)�get_response_object)� exceptions)�default_backend)� serialization)�SHA256)�PKCS1v15z%Y-%m-%dT%H:%M:%SZc C s t j �� S )z? Mocked in libcloud.test.common.google.GoogleTestCase. )�datetime�utcnow� r r �J/opt/saltstack/salt/lib/python3.10/site-packages/libcloud/common/google.py�_utcnowi � r c C s | � t�S )zC Return string of datetime_obj in the UTC Timestamp Format )�strftime�UTC_TIMESTAMP_FORMAT)Zdatetime_objr r r �_utc_timestampp r r c C s t j �| t�S )zS Return datetime obj where date and time are pulled from timestamp string. )r �strptimer )� timestampr r r �_from_utc_timestampw � r � �retry_failedc C sh zd| � d� }ddi}t|||d�}|jd|jfW S ty3 } z dt|�d fW Y d }~S d }~ww )Nz3http://metadata.google.internal/computeMetadata/v1/�/zMetadata-FlavorZGoogle)�headersr# r"