h" 甧dZddlZddlZddlZddlZddlZddlZddlm Z ddl m Z ddl m Z mZmZmZmZmZmZddlmZmZddlmZmZejeZdZd ed ed efd Z e d dZ!dZ"dZ#dZ$Gdde Z%dS)u3 Feature flags synchronisation plugin (AV mode only). In IM360 mode the Go resident-agent handles feature-flag sync. In AV mode there is no resident-agent, so this plugin takes over. Periodically POSTs the local file checksum to the API and writes back any updated flags to ``/var/imunify360/feature_flags.json`` (legacy map ``{flag: true}`` on disk) and ``/var/imunify360/feature_flags`` (plain names, one per line). The POSTed checksum is over the canonical JSON **array** of enabled names, matching the correlation sync API—not over the on-disk map bytes. N)Core) MessageSource) FLAGS_PATHFLAGS_PLAIN_PATHenabled_flag_names_sortedlegacy_feature_flags_map_bytes$plain_text_payload_for_enabled_flags$serialize_feature_flags_file_payload!sync_checksum_hex_from_flags_file)IAIDTokenErrorIndependentAgentIDAPI)Scopeatomic_rewritez/api/sync/v1/feature-flagsnamedefaultreturnctj|}|s|S t|S#t$r"t d||||cYSwxYw)uRead an int env var tolerantly. A non-numeric value (empty string, typo, etc.) must NOT raise at import time — the plugin lives in the AV agent entry point and a bad env var would otherwise kill the whole agent. z4feature-flags: %s=%r is not an int, using default %d)osenvirongetint ValueErrorloggerwarning)rrraws Z/opt/imunify360/venv/lib/python3.11/site-packages/defence360agent/plugins/feature_flags.py_env_intr+s| *..  C  3xx  B       s4)A A $I360_FEATURE_FLAGS_SYNC_INTERVAL_SECi ceZdZejZdZdZdefdZ dZ de fdZ e dejjdefdZe d d Zd S) FeatureFlagsSyncc~K||_||_|||_dSN)_loop_sink create_task _sync_loop_task)selfloopsinks r create_sourcezFeatureFlagsSync.create_sourceJs7  %%doo&7&788 cK|j?|j |jd{VdS#tj$rYdSwxYwdSr$)r)cancelasyncioCancelledErrorr*s rshutdownzFeatureFlagsSync.shutdownOst : ! J      j         )     " !s 3AArc*ttSr$)r rr3s r_local_checksumz FeatureFlagsSync._local_checksumWs0<<FF F F F F F F FsL$AA3"DH*A&FH-!G*HHH)IIrdctj|t5}|cdddS#1swxYwYdS)N)timeout)rTrUurlopen _HTTP_TIMEOUTread)rdresps rrWz"FeatureFlagsSync._blocking_requests ^ # #C # ? ? 499;;                  sAA A Nc t|trt|}nt|}n>#t$r1t dt|jYdSwxYwtt|} tj tj tdt!t|dt#|}t!t$|dt d|dS#t($r t dd YdSwxYw) zHPersist flags: map on disk; checksum for next sync uses canonical array.zrlr"rr.rrs    111111;;;;;;87777777  8 $ $ ( 3,@$GG PFPFPFPFPF}PFPFPFPFPFr.