forked from mtusi2026/mtusi2026lab7
lab7: безопасность, mTLS, OpenBao и PKI lifecycle
This commit is contained in:
@@ -18,13 +18,15 @@ import urllib.parse
|
||||
import urllib.request
|
||||
from pathlib import Path
|
||||
|
||||
from lab7_environment import Environment
|
||||
from lab7_http import BASE_URL, open_url
|
||||
|
||||
for _key in ('HTTP_PROXY', 'HTTPS_PROXY', 'ALL_PROXY', 'http_proxy', 'https_proxy', 'all_proxy'):
|
||||
os.environ.pop(_key, None)
|
||||
os.environ['NO_PROXY'] = 'localhost,127.0.0.1,::1'
|
||||
os.environ['no_proxy'] = 'localhost,127.0.0.1,::1'
|
||||
# tests/client.py builds its own opener; make it ignore macOS system proxies too.
|
||||
urllib.request.getproxies = lambda: {}
|
||||
OPENER = urllib.request.build_opener(urllib.request.ProxyHandler({}))
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
ACTIVE_LOAD = [None]
|
||||
@@ -35,24 +37,21 @@ def utc(ts=None):
|
||||
|
||||
|
||||
def http_json(url, timeout=15):
|
||||
with OPENER.open(url, timeout=timeout) as response:
|
||||
with open_url(url, timeout=timeout, operator=True) as response:
|
||||
return json.loads(response.read())
|
||||
|
||||
|
||||
def prom(expr):
|
||||
url = 'http://localhost:9090/api/v1/query?' + urllib.parse.urlencode({'query': expr})
|
||||
url = 'https://localhost:9090/api/v1/query?' + urllib.parse.urlencode({'query': expr})
|
||||
return http_json(url).get('data', {}).get('result', [])
|
||||
|
||||
|
||||
def alerts():
|
||||
return http_json('http://localhost:9090/api/v1/alerts').get('data', {}).get('alerts', [])
|
||||
return http_json('https://localhost:9090/api/v1/alerts').get('data', {}).get('alerts', [])
|
||||
|
||||
|
||||
def compose(*args, check=True):
|
||||
result = subprocess.run(
|
||||
['docker', 'compose', '--env-file', '.env', '-f', 'compose.yaml', *args],
|
||||
cwd=ROOT, capture_output=True, text=True, check=False,
|
||||
)
|
||||
result = Environment().compose(*args, check=False)
|
||||
(ROOT / 'evidence/lab6/track2').mkdir(parents=True, exist_ok=True)
|
||||
with (ROOT / 'evidence/lab6/track2/full-compose.log').open('a') as log:
|
||||
log.write(utc() + ' docker compose ' + ' '.join(args) + ' rc=' + str(result.returncode) + '\n')
|
||||
@@ -67,7 +66,7 @@ def wait_ready(timeout=120):
|
||||
deadline = time.time() + timeout
|
||||
while time.time() < deadline:
|
||||
try:
|
||||
with OPENER.open('http://localhost:8080/health/ready', timeout=5) as response:
|
||||
with open_url(BASE_URL + '/health/ready', timeout=5) as response:
|
||||
if response.status == 200:
|
||||
return True
|
||||
except Exception:
|
||||
@@ -168,7 +167,7 @@ def run_load(out, label, duration, ratio=0.2, rate=0.2):
|
||||
log_path = out / (label + '-load.log')
|
||||
output_path = out / (label + '-load.json')
|
||||
cmd = [sys.executable, str(ROOT / 'scripts/lab6_load.py'),
|
||||
'--base-url', 'http://localhost:8080', '--rate', str(rate),
|
||||
'--base-url', BASE_URL, '--rate', str(rate),
|
||||
'--duration', str(duration), '--upload-ratio', str(ratio),
|
||||
'--deadline', '60', '--output', str(output_path)]
|
||||
log = log_path.open('w')
|
||||
|
||||
Reference in New Issue
Block a user