forked from nginxinc/kic-reference-architectures
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathverify.py
executable file
·31 lines (25 loc) · 872 Bytes
/
verify.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
#!/usr/bin/env python3
import requests
import sys
import json
import urllib3
stdin_json = json.load(sys.stdin)
if 'application_url' not in stdin_json:
raise ValueError(
"Missing expected key 'application_url' in STDIN json data")
url = f"{stdin_json['application_url']}/login"
payload = 'username=testuser&password=password'
headers = {
'Content-Type': 'application/x-www-form-urlencoded'
}
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
response = requests.request(
"POST", url, headers=headers, data=payload, verify=False)
response_code = response.status_code
if response_code != 200:
print(
f'Application failed health check [url={url},response_code={response_code}', file=sys.stderr)
sys.exit(1)
else:
print('Application passed health check', file=sys.stderr)
print(stdin_json['application_url'])