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



我想从appengine获得部署版本的列表,无论是从远程API还是通过appfg .py。我似乎找不到任何方法来做这件事,当然不是一个记录在案的方法。有人知道有什么方法可以做到这一点吗(甚至没有记录)?

可以在管理控制台中" admin Logs"下列出已部署的版本。除非对这个页面进行屏幕抓取,否则无法通过编程方式访问这些数据。

您可以将此作为增强请求提交给问题跟踪器。

我可以通过将appfg .py中的一些RPC代码复制到我的应用程序中来做到这一点。我张贴了这个要点,详细介绍了如何做到这一点,但我将在这里重复它们,以供子孙后代使用。

  1. 安装python API客户端这将为您提供OAuth2和httplib2库,您需要从应用程序中与Google的RPC服务器进行交互。
  2. 将安装在您的开发机器:google/appengine/tools/appengine_rpc_httplib2.py上的GAE SDK文件复制到您的GAE web应用程序中。
  3. 通过在本地机器上执行appcfg.py list_versions . --oauth2获得刷新令牌。这将打开一个浏览器,以便您可以登录到您的谷歌帐户。然后,您可以在~/. apppcfg_oauth2_tokens
  4. 中找到refresh_token
  5. 在web处理程序中修改并运行以下代码:

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

看起来Google最近在google.appengine.api.modules包中发布了一个get_versions()函数。我建议使用这个hack,而不是我在另一个答案中实现的hack。

阅读更多:https://developers.google.com/appengine/docs/python/modules/functions

最新更新