randyvdh
randyvdh

Reputation: 41

Programmatically get the list of versions from appengine

I'd like to get a list of deployed versions from appengine, either from the remote API or via appcfg.py. I can't seem to find any way to do it, certainly not a documented way. Does anyone know of any way to do this (even undocumented)?

Upvotes: 4

Views: 594

Answers (3)

Matt Faus
Matt Faus

Reputation: 6671

Looks like Google has recently released a get_versions() function in the google.appengine.api.modules package. I recommend using that over the hack I implemented in my other answer.

Read more at: https://developers.google.com/appengine/docs/python/modules/functions

Upvotes: 0

Matt Faus
Matt Faus

Reputation: 6671

I was able to do this by copying some of the RPC code from appcfg.py into my application. I posted up this gist that goes into detail on how to do this, but I will repeat them here for posterity.

  1. Install the python API client. This will give you the OAuth2 and httplib2 libraries you need to interact with Google's RPC servers from within your application.
  2. Copy this file from the GAE SDK installed on your development machine: google/appengine/tools/appengine_rpc_httplib2.py into your GAE webapp.
  3. Obtain a refresh token by executing appcfg.py list_versions . --oauth2 from your local machine. This will open a browser so you can login to your Google Account. Then, you can find the refresh_token in ~/.appcfg_oauth2_tokens
  4. Modify and run the following code inside of a web handler:

Enjoy.

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

Upvotes: 1

Drew Sears
Drew Sears

Reputation: 12838

You can list deployed versions in the admin console under "Admin Logs". Short of screen-scraping this page, there's no way to access this data programmatically.

You can submit this as an enhancement request to the issue tracker.

Upvotes: 1

Related Questions