本文整理匯總了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()