From f19b26590455c8b8196625a6763d7b76628c50e8 Mon Sep 17 00:00:00 2001 From: daveads Date: Tue, 29 Oct 2024 10:02:30 +0100 Subject: [PATCH] support for .yaml policy file --- packages/opal-client/opal_client/policy/updater.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/opal-client/opal_client/policy/updater.py b/packages/opal-client/opal_client/policy/updater.py index 8a3a44db6..2eb8ec2c7 100644 --- a/packages/opal-client/opal_client/policy/updater.py +++ b/packages/opal-client/opal_client/policy/updater.py @@ -1,6 +1,7 @@ import asyncio from typing import List, Optional import json +import yaml import pydantic from fastapi_websocket_pubsub import PubSubClient from fastapi_websocket_rpc.rpc_channel import RpcChannel @@ -343,6 +344,12 @@ async def update_policy( await store_transaction.set_policy(policy_module.path, json.dumps(policy_data)) except json.JSONDecodeError: logger.error(f"Invalid JSON in OpenFGA policy file: {policy_module.path}") + + elif policy_module.path.endswith('.yaml'): + policy_data = yaml.safe_load(policy_module.rego) + await store_transaction.set_policy(policy_module.path, json.dumps(policy_data)) + #logger.error(f"yaml file") + else: logger.warning(f"Skipping non-JSON file for OpenFGA: {policy_module.path}") else: