Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def serve_swagger_ui():
return chalice.Response(status_code=200,
headers={"Content-Type": "text/html"},
body=swagger_ui_html)
"query_params": msg_query_params,
"started_at": msg_started_at,
"content-length": res_headers.get('Content-Length', ''),
"content-type": res_headers.get('Content-Type', '')}
}
app.log.info(json.dumps(msg, indent=4))
# API Gateway/Cloudfront adds a duplicate Content-Length with a different value (not sure why)
res_headers.pop("Content-Length", None)
res_headers["Strict-Transport-Security"] = "max-age=31536000; includeSubDomains; preload"
res_headers["X-AWS-REQUEST-ID"] = app.lambda_context.aws_request_id
if include_retry_after_header(return_code=status_code, method=app.current_request.method, uri=path):
res_headers['Retry-After'] = '10'
return chalice.Response(status_code=status_code,
headers=res_headers,
body="".join([c.decode() if isinstance(c, bytes) else c for c in flask_res.response]))
def redirect(url):
return Response(
status_code=301,
headers={'Location': url},
body='',
)
'client_secret': auth0_secret,
'code': auth0_code,
'redirect_uri': ''.join(['https://', domain, '/api/callback/'])
}
json_payload = json.dumps(payload)
headers = { 'content-type': "application/json" }
res = requests.post("https://hms-dbmi.auth0.com/oauth/token", data=json_payload, headers=headers)
id_token = res.json().get('id_token', None)
if id_token:
cookie_str = ''.join(['jwtToken=', id_token, '; Domain=', domain, '; Path=/;'])
expires_in = res.json().get('expires_in', None)
if expires_in:
expires = datetime.datetime.utcnow() + datetime.timedelta(seconds=expires_in)
cookie_str += (' Expires=' + expires.strftime("%a, %d %b %Y %H:%M:%S GMT") + ';')
resp_headers['Set-Cookie'] = cookie_str
return Response(
status_code=302,
body=json.dumps(resp_headers),
headers=resp_headers)
def error_response(msg):
return Response(body='Error: %s' % msg,
status_code=500,
headers={'Content-Type': 'text/plain'})
def health_check(*args, **kwargs):
health_status = health.l2_health_checks()
health_res = {k: v for k, v in health_status.items() if k == "Healthy"}
return chalice.Response(status_code=200,
headers={"Content-Type": "application/json"},
body=json.dumps(health_res, indent=4, sort_keys=True, default=str))
def run_get_environment(environ):
"""
Return config information about a given environment, or throw an error
if it is not valid.
"""
environments = init_environments()
if environ in environments:
response = Response(
body = {
'status': 'success',
'details': environments[environ],
'environment': environ
},
status_code = 200
)
else:
response = Response(
body = {
'status': 'error',
'description': 'Invalid environment provided. Should be one of: %s' % (str(list(environments.keys()))),
'environment': environ
},
status_code = 400
)
def view_foursight_history(environ, check, start=0, limit=25, is_admin=False,
domain="", context="/"):
"""
View a tabular format of the history of a given check or action (str name
as the 'check' parameter) for the given environment. Results look like:
status, kwargs.
start controls where the first result is and limit controls how many
results are retrieved (see get_foursight_history()).
Returns html.
"""
html_resp = Response('Foursight history view')
html_resp.headers = {'Content-Type': 'text/html'}
server = None
try:
connection = init_connection(environ)
except Exception:
connection = None
if connection:
server = connection.ff_server
history = get_foursight_history(connection, check, start, limit)
history_kwargs = list(set(chain.from_iterable([l[2] for l in history])))
else:
history, history_kwargs = [], []
template = jin_env.get_template('history.html')
check_title = get_check_title_from_setup(check)
page_title = ''.join(['History for ', check_title, ' (', environ, ')'])
queue_attr = get_sqs_attributes(get_sqs_queue().url)
def view_foursight_check(environ, check, uuid, is_admin=False, domain="", context="/"):
"""
View a formatted html response for a single check (environ, check, uuid)
"""
html_resp = Response('Foursight viewing suite')
html_resp.headers = {'Content-Type': 'text/html'}
total_envs = []
servers = []
try:
connection = init_connection(environ)
except Exception:
connection = None
if connection:
servers.append(connection.ff_server)
res_check = CheckResult(connection, check)
if res_check:
data = res_check.get_result_by_uuid(uuid)
if data is None:
# the check hasn't run. Return a placeholder view
data = {
'name': check,