22 lines
1.8 KiB
Python
22 lines
1.8 KiB
Python
"""Identity-only actual kubectl JSONPath parser proof, for coordinator execution."""
|
|
import hashlib,json,subprocess
|
|
from pathlib import Path
|
|
P=Path(__file__).parent
|
|
source=(P/'preflight.py').read_text().split("if __name__=='__main__':")[0]
|
|
source+='''
|
|
try:
|
|
nodes=query('nodes',['metadata.name','status.addresses','status.conditions[*].type','status.conditions[*].status','status.conditions[*].reason'])
|
|
cluster=query('namespace',['metadata.name','metadata.uid'],name='kube-system')
|
|
rows=nodes.get('rows',[]);clusters=cluster.get('rows',[])
|
|
result={'node_query_ok':nodes.get('ok'),'cluster_query_ok':cluster.get('ok'),'array_object_format_valid':bool(rows) and all(type(x.get('status.addresses')) is list for x in rows),'exact_target_address':any(a.get('address')=='92.205.62.239' and a.get('type') in {'InternalIP','ExternalIP'} for row in rows for a in (row.get('status.addresses') if type(row.get('status.addresses')) is list else []) if type(a) is dict),'cluster_identity':len(clusters)==1 and clusters[0].get('metadata.uid')=='a553c742-0115-43d4-99a4-a5ca56fe0786','stdout_sanitized':True}
|
|
except Exception:result={'refused':'sanitized-formatter-probe-failure'}
|
|
print(json.dumps(result))
|
|
'''
|
|
try:
|
|
r=subprocess.run(['ssh','-o','BatchMode=yes','-o','ConnectTimeout=12','railiance01','python3','-'],input=source,capture_output=True,text=True,timeout=100)
|
|
try:result=json.loads(r.stdout) if r.returncode==0 else {'refused':'sanitized-ssh-failure'}
|
|
except ValueError:result={'refused':'sanitized-output-shape'}
|
|
result['transport']={'exit_code':r.returncode,'stderr_present':bool(r.stderr)}
|
|
except (OSError,subprocess.TimeoutExpired):result={'refused':'sanitized-probe-unconfirmed'}
|
|
result['probe_sha256']=hashlib.sha256(Path(__file__).read_bytes()).hexdigest()
|
|
(P/'formatter-probe.json').write_text(json.dumps(result,indent=2)+'\n');print(json.dumps(result))
|