-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
74 lines (44 loc) · 1.86 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python
import boto3
from flask import Flask, jsonify, send_from_directory
import logging
app = Flask(__name__, static_url_path='/')
client = boto3.client('ecr')
@app.route('/api/v1.0/<string:registry_id>/repositories', methods=['GET'])
def get_tasks(registry_id):
app.logger.info('Listing repositories under registry_id={0}'.format(registry_id))
return get_repositories(registry_id)
@app.route('/api/v1.0/<string:registry_id>/repository/<path:repository_name>', methods=['GET'])
def get_task(registry_id, repository_name):
return list_repository(registry_id, repository_name)
@app.route('/static/<path:path>')
def send_template(path):
return send_from_directory('static/', path)
@app.route('/')
def root():
return app.send_static_file('index.html')
@app.route('/favicon.ico')
def favicon():
return app.send_static_file('assets/favicon.ico')
def get_repositories(registry_id):
paginator = client.get_paginator('describe_repositories')
page_iterator = paginator.paginate(registryId=registry_id)
response = {'repositories': []}
for page in page_iterator:
response['repositories'].extend(page['repositories'])
return jsonify(response)
def list_repository(registry_id, repository_name):
paginator = client.get_paginator('describe_images')
page_iterator = paginator.paginate(
registryId=registry_id, repositoryName=repository_name)
response = {'imageDetails': []}
for page in page_iterator:
response['imageDetails'].extend(page['imageDetails'])
return jsonify(response)
if __name__ == '__main__':
app.run(debug=True)
# If we are running under gunicorn wire up the flask and gunicorn loggers
if __name__ != '__main__':
gunicorn_logger = logging.getLogger('gunicorn.error')
app.logger.handlers = gunicorn_logger.handlers
app.logger.setLevel(gunicorn_logger.level)