本文整理汇总了Python中oauth2client.client.GoogleCredentials.from_stream方法的典型用法代码示例。如果您正苦于以下问题:Python GoogleCredentials.from_stream方法的具体用法?Python GoogleCredentials.from_stream怎么用?Python GoogleCredentials.from_stream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oauth2client.client.GoogleCredentials
的用法示例。
在下文中一共展示了GoogleCredentials.from_stream方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from oauth2client.client import GoogleCredentials [as 别名]
# 或者: from oauth2client.client.GoogleCredentials import from_stream [as 别名]
def __init__(self, access_token, client_id, client_secret, refresh_token,
token_expiry, token_uri, user_agent,
revoke_uri=GOOGLE_REVOKE_URI):
"""Create an instance of GoogleCredentials.
This constructor is not usually called by the user, instead
GoogleCredentials objects are instantiated by
GoogleCredentials.from_stream() or
GoogleCredentials.get_application_default().
Args:
access_token: string, access token.
client_id: string, client identifier.
client_secret: string, client secret.
refresh_token: string, refresh token.
token_expiry: datetime, when the access_token expires.
token_uri: string, URI of token endpoint.
user_agent: string, The HTTP User-Agent to provide for this application.
revoke_uri: string, URI for revoke endpoint.
Defaults to GOOGLE_REVOKE_URI; a token can't be revoked if this is None.
"""
super(GoogleCredentials, self).__init__(
access_token, client_id, client_secret, refresh_token, token_expiry,
token_uri, user_agent, revoke_uri=revoke_uri)
示例2: get_credentials
# 需要导入模块: from oauth2client.client import GoogleCredentials [as 别名]
# 或者: from oauth2client.client.GoogleCredentials import from_stream [as 别名]
def get_credentials(credential_file=None, credentials=None):
if credential_file:
return GoogleCredentials.from_stream(credential_file)
if credentials and credentials["type"] == "service_account":
return ServiceAccountCredentials_from_dict(credentials)
if credentials and credentials["type"] == "authorized_user":
return GoogleCredentials(
access_token=None,
client_id=credentials["client_id"],
client_secret=credentials["client_secret"],
refresh_token=credentials["refresh_token"],
token_expiry=None,
token_uri=GOOGLE_TOKEN_URI,
user_agent="pghoard")
return GoogleCredentials.get_application_default()
示例3: from_stream
# 需要导入模块: from oauth2client.client import GoogleCredentials [as 别名]
# 或者: from oauth2client.client.GoogleCredentials import from_stream [as 别名]
def from_stream(credential_filename):
"""Create a Credentials object by reading the information from a given file.
It returns an object of type GoogleCredentials.
Args:
credential_filename: the path to the file from where the credentials
are to be read
Exceptions:
ApplicationDefaultCredentialsError: raised when the credentials fail
to be retrieved.
"""
if credential_filename and os.path.isfile(credential_filename):
try:
return _get_application_default_credential_from_file(
credential_filename)
except (ApplicationDefaultCredentialsError, ValueError) as error:
extra_help = ' (provided as parameter to the from_stream() method)'
_raise_exception_for_reading_json(credential_filename,
extra_help,
error)
else:
raise ApplicationDefaultCredentialsError(
'The parameter passed to the from_stream() '
'method should point to a file.')
示例4: start_gsuite_ingestion
# 需要导入模块: from oauth2client.client import GoogleCredentials [as 别名]
# 或者: from oauth2client.client.GoogleCredentials import from_stream [as 别名]
def start_gsuite_ingestion(session, config):
"""
Starts the GSuite ingestion process by initializing
:param session: The Neo4j session
:param config: A `cartography.config` object
:return: Nothing
"""
common_job_parameters = {
"UPDATE_TAG": config.update_tag,
}
try:
credentials = GoogleCredentials.from_stream(GSUITE_CREDS)
credentials = credentials.create_scoped(OAUTH_SCOPE)
credentials = credentials.create_delegated(GSUITE_DELEGATED_ADMIN)
except ApplicationDefaultCredentialsError as e:
logger.debug('Error occurred calling GoogleCredentials.get_application_default().', exc_info=True)
logger.error(
(
"Unable to initialize GSuite creds. If you don't have GSuite data or don't want to load "
'Gsuite data then you can ignore this message. Otherwise, the error code is: %s '
'Make sure your GSuite credentials are configured correctly, your credentials file (if any) is valid. '
'For more details see README'
),
e,
)
return
resources = _initialize_resources(credentials)
api.sync_gsuite_users(session, resources.admin, config.update_tag, common_job_parameters)
api.sync_gsuite_groups(session, resources.admin, config.update_tag, common_job_parameters)
示例5: __init__
# 需要导入模块: from oauth2client.client import GoogleCredentials [as 别名]
# 或者: from oauth2client.client.GoogleCredentials import from_stream [as 别名]
def __init__(self, access_token, client_id, client_secret, refresh_token,
token_expiry, token_uri, user_agent,
revoke_uri=GOOGLE_REVOKE_URI):
"""Create an instance of GoogleCredentials.
This constructor is not usually called by the user, instead
GoogleCredentials objects are instantiated by
GoogleCredentials.from_stream() or
GoogleCredentials.get_application_default().
Args:
access_token: string, access token.
client_id: string, client identifier.
client_secret: string, client secret.
refresh_token: string, refresh token.
token_expiry: datetime, when the access_token expires.
token_uri: string, URI of token endpoint.
user_agent: string, The HTTP User-Agent to provide for this
application.
revoke_uri: string, URI for revoke endpoint. Defaults to
GOOGLE_REVOKE_URI; a token can't be revoked if this
is None.
"""
super(GoogleCredentials, self).__init__(
access_token, client_id, client_secret, refresh_token,
token_expiry, token_uri, user_agent, revoke_uri=revoke_uri)
示例6: from_stream
# 需要导入模块: from oauth2client.client import GoogleCredentials [as 别名]
# 或者: from oauth2client.client.GoogleCredentials import from_stream [as 别名]
def from_stream(credential_filename):
"""Create a Credentials object by reading information from a file.
It returns an object of type GoogleCredentials.
Args:
credential_filename: the path to the file from where the
credentials are to be read
Raises:
ApplicationDefaultCredentialsError: raised when the credentials
fail to be retrieved.
"""
if credential_filename and os.path.isfile(credential_filename):
try:
return _get_application_default_credential_from_file(
credential_filename)
except (ApplicationDefaultCredentialsError, ValueError) as error:
extra_help = (' (provided as parameter to the '
'from_stream() method)')
_raise_exception_for_reading_json(credential_filename,
extra_help,
error)
else:
raise ApplicationDefaultCredentialsError(
'The parameter passed to the from_stream() '
'method should point to a file.')
示例7: __init__
# 需要导入模块: from oauth2client.client import GoogleCredentials [as 别名]
# 或者: from oauth2client.client.GoogleCredentials import from_stream [as 别名]
def __init__(self, access_token, client_id, client_secret, refresh_token,
token_expiry, token_uri, user_agent,
revoke_uri=oauth2client.GOOGLE_REVOKE_URI):
"""Create an instance of GoogleCredentials.
This constructor is not usually called by the user, instead
GoogleCredentials objects are instantiated by
GoogleCredentials.from_stream() or
GoogleCredentials.get_application_default().
Args:
access_token: string, access token.
client_id: string, client identifier.
client_secret: string, client secret.
refresh_token: string, refresh token.
token_expiry: datetime, when the access_token expires.
token_uri: string, URI of token endpoint.
user_agent: string, The HTTP User-Agent to provide for this
application.
revoke_uri: string, URI for revoke endpoint. Defaults to
oauth2client.GOOGLE_REVOKE_URI; a token can't be
revoked if this is None.
"""
super(GoogleCredentials, self).__init__(
access_token, client_id, client_secret, refresh_token,
token_expiry, token_uri, user_agent, revoke_uri=revoke_uri)
示例8: create
# 需要导入模块: from oauth2client.client import GoogleCredentials [as 别名]
# 或者: from oauth2client.client.GoogleCredentials import from_stream [as 别名]
def create(self, scopes):
with open(self.path, 'r') as fh:
data = json.load(fh)
if data.get('type', None):
credentials = GoogleCredentials.from_stream(self.path)
credentials = credentials.create_scoped(scopes)
return credentials
return Storage(self.path).get()