以编程方式获取App Engine的版本列表

4 投票
3 回答
583 浏览
提问于 2025-04-17 06:03

我想从appengine获取一个已部署版本的列表,可以通过远程API或者appcfg.py来实现。但是我找不到任何方法,特别是没有找到官方文档说明的方式。有没有人知道怎么做这个(即使没有文档说明)?

3 个回答

0

看起来谷歌最近在 google.appengine.api.modules 这个包里发布了一个新的 get_versions() 函数。我建议你使用这个新函数,而不是我之前回答中提到的那个小技巧。

想了解更多,可以去这里看看: https://developers.google.com/appengine/docs/python/modules/functions

1

我通过把一些RPC代码从appcfg.py复制到我的应用程序里,成功实现了这个功能。我在这个链接上详细说明了怎么做,但我在这里也会重复一遍,以备后用。

  1. 安装Python API客户端。这样你就能获得与Google的RPC服务器互动所需的OAuth2和httplib2库。
  2. 从你开发机器上安装的GAE SDK中复制这个文件:google/appengine/tools/appengine_rpc_httplib2.py到你的GAE网页应用里。
  3. 通过在本地机器上执行appcfg.py list_versions . --oauth2来获取一个刷新令牌。这会打开一个浏览器,让你登录你的Google账户。然后,你可以在~/.appcfg_oauth2_tokens中找到refresh_token
  4. 在一个网页处理程序中修改并运行以下代码:

祝你好运。

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
1

你可以在管理控制台的“管理员日志”里查看已部署的版本。除了手动抓取这个页面的数据,没办法通过程序直接获取这些信息。

你可以把这个作为一个改进建议提交到问题跟踪器

撰写回答