diff --git a/backend/moonstream/routes/dashboards.py b/backend/moonstream/routes/dashboards.py index e2e48022..4e54047c 100644 --- a/backend/moonstream/routes/dashboards.py +++ b/backend/moonstream/routes/dashboards.py @@ -110,7 +110,7 @@ async def add_dashboard_handler( detail=f"We can't access the abi for subscription with id:{dashboard_subscription.subscription_id}.", ) - abi = response["Body"].read().decode("utf-8") + abi = data.DashboardMeta(**response["Body"].read().decode("utf-8")) actions.dashboards_abi_validation( dashboard_subscription, abi, s3_path=s3_path @@ -279,8 +279,46 @@ async def update_dashboard_handler( for dashboard_subscription in dashboard_subscriptions: if dashboard_subscription.subscription_id in available_subscriptions: + # TODO(Andrey): Add some dedublication for get object from s3 for repeated subscription_id + + bucket = available_subscriptions[dashboard_subscription.subscription_id][ + "bucket" + ] + abi_path = available_subscriptions[dashboard_subscription.subscription_id][ + "abi_path" + ] + + if bucket is None or abi_path is None: + logger.error( + f"Error on dashboard resource {dashboard_subscription.subscription_id} does not have an abi" + ) + raise MoonstreamHTTPException( + status_code=404, + detail=f"Error on dashboard resource {dashboard_subscription.subscription_id} does not have an abi", + ) + s3_path = f"s3://{bucket}/{abi_path}" + + try: + + response = s3_client.get_object( + Bucket=bucket, + Key=abi_path, + ) + + except s3_client.exceptions.NoSuchKey as e: + logger.error( + f"Error getting Abi for subscription {dashboard_subscription.subscription_id} S3 {s3_path} does not exist : {str(e)}" + ) + raise MoonstreamHTTPException( + status_code=500, + internal_error=e, + detail=f"We can't access the abi for subscription with id:{dashboard_subscription.subscription_id}.", + ) + + abi = data.DashboardMeta(**response["Body"].read().decode("utf-8")) + actions.dashboards_abi_validation( - dashboard_subscription, available_subscriptions, s3_client + dashboard_subscription, abi, s3_path=s3_path ) else: