#!/usr/bin/env python

import sys, os
import json

from boto.s3.connection import S3Connection
from boto.exception import S3ResponseError

input = json.loads(sys.stdin.read())

access_key_id = input['source']['access_key_id']
secret_access_key = input['source']['secret_access_key']
bucket_name = input['source']['bucket']
key_name = input['source']['key']

conn = S3Connection(access_key_id, secret_access_key)
bucket = conn.get_bucket(bucket_name)

try:
  key = bucket.get_key(key_name)
  key_value = key.get_contents_as_string().decode('utf-8')
except:
  key_value = "{\"versions\": [\"0.0.0\"]}"

output = []

for value in json.loads(key_value)['versions']:
  output.append({"number": value})

print(json.dumps(output))
