Ur, d Z ddlZddlZddlZddlZddlZddlZddlm Z ddl mZ ddlm Z mZmZmZmZmZmZ ddlmZmZ ddlmZmZ ej e ZdZd ed edefdZ e!h d Z" e!h d Z#d ed e$de$fdZ% e dd Z& e dd Z' e dd Z( e%dd Z)dZ*dedefdZ+ G d de 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_sorted$plain_text_payload_for_enabled_flags$serialize_feature_flags_file_payload!sync_checksum_hex_from_flags_filesync_response_file_bytes)IAIDTokenErrorIndependentAgentIDAPI)Scopeatomic_rewritez/api/sync/v1/feature-flagsnamedefaultreturnc t j | }|s|S t | S # t $ r" t d| || |cY S w xY w)u Read 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)r r raws Z/opt/imunify360/venv/lib/python3.11/site-packages/defence360agent/plugins/feature_flags.py_env_intr + s| *.. C 3xx B s 4 )A A > 1onyestrue> 0noofffalsec t j | }|s|S | }|t v rdS |t v rdS t d| || |S )NTFz4feature-flags: %s=%r is not a bool, using default %s) r r r striplower_TRUE_VALUES _FALSE_VALUESr r )r r r normalizeds r _env_boolr, E s *.. C ""$$J\!!t]""u NN> N I360_FEATURE_FLAGS_SYNC_INTERVALi I360_FEATURE_FLAGS_INIT_DELAY I360_FEATURE_FLAGS_UNREG_DELAY #I360_FEATURE_FLAGS_USE_SERVER_DELAYTserver_delayc . t r| dk r| S t S )Nr )_USE_SERVER_DELAY_SYNC_INTERVAL)r4 s r _next_delayr8 ^ s \A--r- c e Zd Zej Zd Zd ZdefdZ d Z defdZe dej j defd Ze ddd Zd S ) FeatureFlagsSyncc ~ K || _ || _ | | | _ d S N)_loop_sinkcreate_task _sync_loop_task)selfloopsinks r create_sourcezFeatureFlagsSync.create_sourceg s7 %%doo&7&788 r- c K | j ?| j | j d {V d S # t j $ r Y d S w xY wd S r<