forked from mtusi2026/mtusi2026lab7
lab7: безопасность, mTLS, OpenBao и PKI lifecycle
This commit is contained in:
@@ -9,28 +9,29 @@ import urllib.parse
|
||||
import urllib.request
|
||||
from pathlib import Path
|
||||
|
||||
from lab7_environment import Environment
|
||||
from lab7_http import BASE_URL, open_url
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
for key in ('HTTP_PROXY','HTTPS_PROXY','ALL_PROXY','http_proxy','https_proxy','all_proxy'):
|
||||
os.environ.pop(key, None)
|
||||
OPENER = urllib.request.build_opener(urllib.request.ProxyHandler({}))
|
||||
|
||||
|
||||
def prom(expr):
|
||||
url = 'http://localhost:9090/api/v1/query?' + urllib.parse.urlencode({'query': expr})
|
||||
with OPENER.open(url, timeout=10) as response:
|
||||
url = 'https://localhost:9090/api/v1/query?' + urllib.parse.urlencode({'query': expr})
|
||||
with open_url(url, timeout=10, operator=True) as response:
|
||||
result = json.loads(response.read()).get('data', {}).get('result', [])
|
||||
return result[0]['value'][1] if result else 'MISSING'
|
||||
|
||||
|
||||
def alerts():
|
||||
with OPENER.open('http://localhost:9090/api/v1/alerts', timeout=10) as response:
|
||||
with open_url('https://localhost:9090/api/v1/alerts', timeout=10, operator=True) as response:
|
||||
data = json.loads(response.read()).get('data', {}).get('alerts', [])
|
||||
return [(a['labels'].get('alertname', ''), a['state']) for a in data]
|
||||
|
||||
|
||||
def compose(*args, check=True):
|
||||
return subprocess.run(['docker','compose','--env-file','.env',*args], cwd=ROOT,
|
||||
capture_output=True, text=True, check=check)
|
||||
return Environment().compose(*args, check=check)
|
||||
|
||||
|
||||
def main():
|
||||
@@ -42,7 +43,7 @@ def main():
|
||||
print('UTC', time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime()), flush=True)
|
||||
print('HEAD', subprocess.run(['git','rev-parse','HEAD'], cwd=ROOT, capture_output=True, text=True, check=True).stdout.strip(), flush=True)
|
||||
print('$ /api/v1/rules (contains or vector(0))', flush=True)
|
||||
with OPENER.open('http://localhost:9090/api/v1/rules', timeout=10) as response:
|
||||
with open_url('https://localhost:9090/api/v1/rules', timeout=10, operator=True) as response:
|
||||
rules = response.read().decode()
|
||||
print('or_vector_0=', 'or vector(0)' in rules, flush=True)
|
||||
print('json_len=', len(rules), flush=True)
|
||||
@@ -53,7 +54,7 @@ def main():
|
||||
def start_load():
|
||||
index = len(loads)
|
||||
loads.append(subprocess.Popen([
|
||||
'python3', str(ROOT/'scripts/lab6_load.py'), '--base-url', 'http://localhost:8080',
|
||||
'python3', str(ROOT/'scripts/lab6_load.py'), '--base-url', BASE_URL,
|
||||
'--rate', '0.2', '--duration', '1000', '--upload-ratio', '1',
|
||||
'--deadline', '60', '--output', '/tmp/lab6-ttr-worker-load-%d.json' % index,
|
||||
], cwd=ROOT, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL))
|
||||
|
||||
Reference in New Issue
Block a user