以编程方式从appengine获取版本列表

时间:2011-11-10 15:40:27

标签: python google-app-engine

我想从远程API或appcfg.py获取appengine的已部署版本列表。我似乎无法找到任何办法,当然不是一种记录的方式。有谁知道这样做的任何方法(甚至没有记录)?

3 个答案:

答案 0 :(得分:1)

您可以在“管理员日志”下的管理控制台中列出已部署的版本。如果没有屏幕抓取此页面,则无法以编程方式访问此数据。

您可以将此作为增强请求提交给issue tracker

答案 1 :(得分:1)

我能够通过将appcfg.py中的一些RPC代码复制到我的应用程序中来实现这一点。我发布了this gist详细说明了如何做到这一点,但我会在这里重复这些内容以供后代使用。

  1. Install the python API client。这将为您提供从应用程序内与Google的RPC服务器进行交互所需的OAuth2和httplib2库。
  2. 将此文件从开发计算机上安装的GAE SDK google/appengine/tools/appengine_rpc_httplib2.py复制到您的GAE Web应用程序中。
  3. 通过从本地计算机执行appcfg.py list_versions . --oauth2来获取刷新令牌。这将打开浏览器,以便您登录Google帐户。然后,您可以在〜/ .appcfg_oauth2_tokens
  4. 中找到refresh_token
  5. 在Web处理程序中修改并运行以下代码:
  6. 享受。

    from third_party.google_api_python_client import appengine_rpc_httplib2
    
    # Not-so-secret IDs cribbed from appcfg.py
    # https://code.google.com/p/googleappengine/source/browse/trunk/python/google/appengine/tools/appcfg.py#144
    APPCFG_CLIENT_ID = '550516889912.apps.googleusercontent.com'
    APPCFG_CLIENT_NOTSOSECRET = 'ykPq-0UYfKNprLRjVx1hBBar'
    APPCFG_SCOPES = ['https://www.googleapis.com/auth/appengine.admin']
    
    source = (APPCFG_CLIENT_ID,
                APPCFG_CLIENT_NOTSOSECRET,
                APPCFG_SCOPES,
                None)
    
    rpc_server = appengine_rpc_httplib2.HttpRpcServerOauth2(
        'appengine.google.com',
        # NOTE: Here's there the refresh token is used
        "your OAuth2 refresh token goes here",
        "appcfg_py/1.8.3 Darwin/12.5.0 Python/2.7.2.final.0",
        source,
        host_override=None,
        save_cookies=False,
        auth_tries=1,
        account_type='HOSTED_OR_GOOGLE',
        secure=True,
        ignore_certs=False)
    
    # NOTE: You must insert the correct app_id here, too
    response = rpc_server.Send('/api/versions/list', app_id="khan-academy")
    
    # The response is in YAML format
    parsed_response = yaml.safe_load(response)
    if not parsed_response:
        return None
    else:
        return parsed_response
    

答案 2 :(得分:0)

Google似乎最近在get_versions()包中发布了google.appengine.api.modules功能。我建议在我的其他答案中实现的黑客攻击。

了解详情: https://developers.google.com/appengine/docs/python/modules/functions

相关问题