-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflan_scan_api.py
38 lines (33 loc) · 1.1 KB
/
flan_scan_api.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
from flask import Flask, escape, request, redirect
import sys
import json
import urllib.request as urllib
import os
import glob
import xmltodict
import boto3
from datetime import datetime as DT
from datetime import timedelta as TD
import hashlib
app = Flask(__name__)
context_root = "/flan_api"
@app.route(context_root + '/<location>/<env>/<content>')
def get_s3_object(location, env, content):
try:
client = boto3.client('s3')
response = client.get_object(
Bucket='flan-scans',
Key='flan_api/' + location + '/' + env + '/' + content)['Body'].read()
return response
except ClientError as e:
print(e)
return json.dumps(e)
@app.route(context_root + '/list_s3_objects')
def list_objects():
environment_prefix = os.environ.get('ENV_PREFIX', '')
client = boto3.client('s3')
response = client.list_objects_v2(
Bucket='flan-scans',
Prefix=environment_prefix)['Contents']
get_last_modified = lambda obj: int(obj['LastModified'].strftime('%s'))
return sorted(response, key=get_last_modified, reverse=True)[0]