Skip to content

Commit

Permalink
Update cluster/module_domains and raise module-domain-changed event
Browse files Browse the repository at this point in the history
  • Loading branch information
stephdl committed Jan 11, 2024
1 parent b885885 commit 23e080b
Showing 1 changed file with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,35 @@ with agent.redis_connect(privileged=True) as rdb:
rdb.delete(f"cluster/counters_cache/users/{kdom}", f"cluster/counters_cache/groups/{kdom}")

# TODO: remove HASH items matching kdom from cluster/module_domains
# TODO: raise module-domain-changed for matching modules and domain
with agent.redis_connect(privileged=True) as rdb:
# Iterate over the hash and find the matching value, remove the key from the hash or update the value to '' if no more domains
for key, value in rdb.hscan_iter("cluster/module_domains"):
print(f"Checking {key} {value}", file=sys.stderr)
values = value.split()
if kdom in values:
values.remove(kdom)
new_value = ' '.join(values)
# we could remove the key if no more domains are left, but we need to keep the key to raise the event
# what to do @davidep ?
#if new_value == '':
# # no more domains, remove the key
# print(f"Removing {key} from cluster/module_domains", file=sys.stderr)
# rdb.hdel("cluster/module_domains", key)
#else:
# # update the value with the new list of domains
# print(f"Updating {key} to {new_value} in cluster/module_domains", file=sys.stderr)
# rdb.hset("cluster/module_domains", key, new_value)
if new_value == None:
new_value = ''
print(f"Updating {key} to {new_value} in cluster/module_domains", file=sys.stderr)
rdb.hset("cluster/module_domains", key, new_value)

# TODO: raise module-domain-changed for matching modules and domains
agent_id = os.environ['AGENT_ID']
values = {"modules": key, "domains": new_value}
trx = rdb.pipeline()
trx.hset(agent_id + '/module-domain-changed', mapping=values)
trx.publish(agent_id + '/event/module-domain-changed', json.dumps({
'key': agent_id + '/event/module-domain-changed',
}))
trx.execute()

0 comments on commit 23e080b

Please sign in to comment.