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 query(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 sample(label):
|
||||
@@ -54,7 +55,7 @@ def main():
|
||||
load_path.unlink(missing_ok=True)
|
||||
load_duration = args.duration + 300 + 60
|
||||
load = 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', str(load_duration), '--upload-ratio', '0.2',
|
||||
'--deadline', '60', '--output', str(load_path),
|
||||
], cwd=ROOT, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
@@ -62,7 +63,7 @@ def main():
|
||||
print('$ docker compose ps -a', flush=True)
|
||||
print(compose('ps','-a').stdout, flush=True)
|
||||
print('$ docker compose stop otel-collector', flush=True)
|
||||
print(compose('stop','otel-collector').stdout.strip(), flush=True)
|
||||
print(compose('stop','collector-tls','otel-collector').stdout.strip(), flush=True)
|
||||
started = time.monotonic()
|
||||
while time.monotonic() - started < args.duration:
|
||||
time.sleep(30)
|
||||
@@ -70,7 +71,7 @@ def main():
|
||||
print('$ docker compose ps -a (down)', flush=True)
|
||||
print(compose('ps','-a').stdout, flush=True)
|
||||
print('$ docker compose start otel-collector', flush=True)
|
||||
print(compose('start','otel-collector').stdout.strip(), flush=True)
|
||||
print(compose('start','otel-collector','collector-tls').stdout.strip(), flush=True)
|
||||
started = time.monotonic()
|
||||
while time.monotonic() - started < 300:
|
||||
time.sleep(30)
|
||||
|
||||
Reference in New Issue
Block a user