本文整理汇总了Python中google_auth_httplib2.AuthorizedHttp方法的典型用法代码示例。如果您正苦于以下问题:Python google_auth_httplib2.AuthorizedHttp方法的具体用法?Python google_auth_httplib2.AuthorizedHttp怎么用?Python google_auth_httplib2.AuthorizedHttp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类google_auth_httplib2
的用法示例。
在下文中一共展示了google_auth_httplib2.AuthorizedHttp方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_api_client
# 需要导入模块: import google_auth_httplib2 [as 别名]
# 或者: from google_auth_httplib2 import AuthorizedHttp [as 别名]
def get_api_client(self, service, version, scopes):
"""Gets an authenticated api connection to the provided service and version.
Args:
service: str, the name of the service to connect to.
version: str, the version of the service to connect to.
scopes: List[str], a list of the required scopes for this api call.
Returns:
An authenticated api client connection.
"""
if not self._credentials.has_scopes(scopes):
scopes.extend(self._credentials.scopes)
self._credentials = self.get_credentials(scopes)
return build(
serviceName=service, version=version,
http=google_auth_httplib2.AuthorizedHttp(credentials=self._credentials))
示例2: http
# 需要导入模块: import google_auth_httplib2 [as 别名]
# 或者: from google_auth_httplib2 import AuthorizedHttp [as 别名]
def http(self):
"""A thread local instance of httplib2.Http.
Returns:
google_auth_httplib2.AuthorizedHttp: An Http instance authorized by
the credentials.
"""
if self._use_cached_http and hasattr(self._local, 'http'):
return self._local.http
authorized_http = google_auth_httplib2.AuthorizedHttp(
self._credentials, http=http_helpers.build_http())
if self._use_cached_http:
self._local.http = authorized_http
return authorized_http
示例3: _create_directory_service
# 需要导入模块: import google_auth_httplib2 [as 别名]
# 或者: from google_auth_httplib2 import AuthorizedHttp [as 别名]
def _create_directory_service(self, user_email=None):
"""Build and return a Google Admin SDK Directory API service object.
Args:
user_email: String, The email address of the user that needs permission to
access the admin APIs.
Returns:
Google Admin SDK Directory API service object.
Raises:
UnauthorizedUserError: If a user email is not provided.
"""
if user_email and user_email.split('@')[1] in constants.APP_DOMAINS:
credentials = service_account.Credentials.from_service_account_file(
filename=constants.SECRETS_FILE,
scopes=constants.DIRECTORY_SCOPES,
subject=constants.ADMIN_EMAIL)
logging.info('Created delegated credentials for %s.', user_email)
else:
raise UnauthorizedUserError('User Email not provided.')
return build(
serviceName='admin',
version='directory_v1',
http=google_auth_httplib2.AuthorizedHttp(credentials=credentials))
示例4: __init__
# 需要导入模块: import google_auth_httplib2 [as 别名]
# 或者: from google_auth_httplib2 import AuthorizedHttp [as 别名]
def __init__(self, oauth_client_secrets_path):
flow = InstalledAppFlow.from_client_secrets_file(
oauth_client_secrets_path,
scopes=['https://www.googleapis.com/auth/siteverification'])
credentials = flow.run_console()
http = google_auth_httplib2.AuthorizedHttp(
credentials, http=httplib2.Http())
self.api = discovery.build('siteVerification', 'v1', http=http)
示例5: __init__
# 需要导入模块: import google_auth_httplib2 [as 别名]
# 或者: from google_auth_httplib2 import AuthorizedHttp [as 别名]
def __init__(self, project_id, zone):
self.project_id = project_id
self.zone = zone
creds = credentials.get_default(scopes=_SCOPES)[0]
http = google_auth_httplib2.AuthorizedHttp(
creds, http=httplib2.Http(timeout=REQUEST_TIMEOUT))
self.compute = build('compute', 'v1', http=http, cache_discovery=False)
示例6: _authorize
# 需要导入模块: import google_auth_httplib2 [as 别名]
# 或者: from google_auth_httplib2 import AuthorizedHttp [as 别名]
def _authorize(self) -> google_auth_httplib2.AuthorizedHttp:
"""
Returns an authorized HTTP object to be used to build a Google cloud
service hook connection.
"""
credentials = self._get_credentials()
http = build_http()
http = set_user_agent(http, "airflow/" + version.version)
authed_http = google_auth_httplib2.AuthorizedHttp(credentials, http=http)
return authed_http
示例7: from_credentials
# 需要导入模块: import google_auth_httplib2 [as 别名]
# 或者: from google_auth_httplib2 import AuthorizedHttp [as 别名]
def from_credentials(cls, credentials: credentials.Credentials):
auth_http = google_auth_httplib2.AuthorizedHttp(credentials)
user_agent = '/'.join(['django-cloud-deploy', __version__.__version__])
http.set_user_agent(auth_http, user_agent)
return cls(
discovery.build('cloudresourcemanager',
'v1',
http=auth_http,
cache_discovery=False))
示例8: _authenticate
# 需要导入模块: import google_auth_httplib2 [as 别名]
# 或者: from google_auth_httplib2 import AuthorizedHttp [as 别名]
def _authenticate(self, cache_discovery):
import google_auth_httplib2
import googleapiclient.discovery
scope = ['https://www.googleapis.com/auth/cloud-platform']
if self.credentials_path:
try:
from google.oauth2 import service_account
credentials = service_account.Credentials.from_service_account_file(
self.credentials_path)
scoped_credentials = credentials.with_scopes(scope)
except ImportError:
logging.error('Failed to load google.oauth2.service_account module. '
'If you are running this script in Google App Engine '
'environment, you can initialize the segmenter with '
'default credentials.')
else:
import google.auth
scoped_credentials, _ = google.auth.default(scope)
authed_http = google_auth_httplib2.AuthorizedHttp(scoped_credentials)
service = googleapiclient.discovery.build(
'language', 'v1beta2', http=authed_http,
cache_discovery=cache_discovery)
return service
示例9: authorized_http
# 需要导入模块: import google_auth_httplib2 [as 别名]
# 或者: from google_auth_httplib2 import AuthorizedHttp [as 别名]
def authorized_http(credentials):
"""Returns an http client that is authorized with the given credentials.
Args:
credentials (Union[
google.auth.credentials.Credentials,
oauth2client.client.Credentials]): The credentials to use.
Returns:
Union[httplib2.Http, google_auth_httplib2.AuthorizedHttp]: An
authorized http client.
"""
from googleapiclient.http import build_http
if HAS_GOOGLE_AUTH and isinstance(
credentials, google.auth.credentials.Credentials):
if google_auth_httplib2 is None:
raise ValueError(
'Credentials from google.auth specified, but '
'google-api-python-client is unable to use these credentials '
'unless google-auth-httplib2 is installed. Please install '
'google-auth-httplib2.')
return google_auth_httplib2.AuthorizedHttp(credentials,
http=build_http())
else:
return credentials.authorize(build_http())
示例10: refresh_credentials
# 需要导入模块: import google_auth_httplib2 [as 别名]
# 或者: from google_auth_httplib2 import AuthorizedHttp [as 别名]
def refresh_credentials(credentials):
# Refresh must use a new http instance, as the one associated with the
# credentials could be a AuthorizedHttp or an oauth2client-decorated
# Http instance which would cause a weird recursive loop of refreshing
# and likely tear a hole in spacetime.
refresh_http = httplib2.Http()
if HAS_GOOGLE_AUTH and isinstance(
credentials, google.auth.credentials.Credentials):
request = google_auth_httplib2.Request(refresh_http)
return credentials.refresh(request)
else:
return credentials.refresh(refresh_http)
示例11: init
# 需要导入模块: import google_auth_httplib2 [as 别名]
# 或者: from google_auth_httplib2 import AuthorizedHttp [as 别名]
def init(self, conf):
# type: (ConfigTree) -> None
# should use key_path, or cred_key if the former doesn't exist
self.key_path = conf.get_string(BaseBigQueryExtractor.KEY_PATH_KEY, None)
self.cred_key = conf.get_string(BaseBigQueryExtractor.CRED_KEY, None)
self.project_id = conf.get_string(BaseBigQueryExtractor.PROJECT_ID_KEY)
self.pagesize = conf.get_int(
BaseBigQueryExtractor.PAGE_SIZE_KEY,
BaseBigQueryExtractor.DEFAULT_PAGE_SIZE)
self.filter = conf.get_string(BaseBigQueryExtractor.FILTER_KEY, '')
if self.key_path:
credentials = (
google.oauth2.service_account.Credentials.from_service_account_file(
self.key_path, scopes=self._DEFAULT_SCOPES))
else:
if self.cred_key:
service_account_info = json.loads(self.cred_key)
credentials = (
google.oauth2.service_account.Credentials.from_service_account_info(
service_account_info, scopes=self._DEFAULT_SCOPES))
else:
credentials, _ = google.auth.default(scopes=self._DEFAULT_SCOPES)
http = httplib2.Http()
authed_http = google_auth_httplib2.AuthorizedHttp(credentials, http=http)
self.bigquery_service = build('bigquery', 'v2', http=authed_http, cache_discovery=False)
self.logging_service = build('logging', 'v2', http=authed_http, cache_discovery=False)
self.iter = iter(self._iterate_over_tables())
示例12: _BuildService
# 需要导入模块: import google_auth_httplib2 [as 别名]
# 或者: from google_auth_httplib2 import AuthorizedHttp [as 别名]
def _BuildService(self):
http = httplib2.Http(timeout=_HTTP_TIMEOUT_SECONDS)
http = google_auth_httplib2.AuthorizedHttp(self._credentials, http)
api = googleapiclient.discovery.build(
'clouddebugger', 'v2', http=http, cache_discovery=False)
return api.controller()