_metadata.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:SurfaceWaterTool 作者: Servir-Mekong 项目源码 文件源码
def get_token(http_request, service_account='default'):
    """Fetch an oauth token for the

    Args:
        service_account: An email specifying the service account this token
            should represent. Default will be a token for the "default" service
            account of the current compute engine instance.
        http_request: A callable that matches the method
            signature of httplib2.Http.request. Used to make the request to the
            metadataserver.

    Returns:
         A tuple of (access token, token expiration), where access token is the
         access token as a string and token expiration is a datetime object
         that indicates when the access token will expire.
    """
    token_json = get(
        http_request,
        'instance/service-accounts/{0}/token'.format(service_account))
    token_expiry = _UTCNOW() + datetime.timedelta(
        seconds=token_json['expires_in'])
    return token_json['access_token'], token_expiry
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号