h"甧 d Z ddlZddlZddlZddlZddlZddlZddlm Z ddl
mZ ddlm
Z
mZmZmZmZmZmZ ddlmZmZ ddlmZmZ ej e ZdZd ed
edefdZ e d
d Z!dZ"dZ#dZ$ 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_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-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 $I360_FEATURE_FLAGS_SYNC_INTERVAL_SECi
c e Zd Zej Zd Zd ZdefdZ d Z
defdZe
dej j defd Ze
dd
Zd S )FeatureFlagsSyncc ~ K || _ || _ | | | _ d S N)_loop_sinkcreate_task
_sync_loop_task)selfloopsinks r
create_sourcezFeatureFlagsSync.create_sourceJ s7
%%doo&7&788
c K | j ?| j | j d {V d S # t j $ r Y d S w xY wd S r$ )r) cancelasyncioCancelledErrorr* s r shutdownzFeatureFlagsSync.shutdownO st :!J
j )
"!s
3 AAr c * t t S r$ )r r r3 s r _local_checksumz FeatureFlagsSync._local_checksumW s 0<<