admin管理员组文章数量:1391943
@pubsub_bp.route("/api/pubsub/events", methods=["POST"])
def handle_pubsub_event():
try:
print("Received Pub/Sub event")
envelope = request.get_json()
if not envelope or 'message' not in envelope:
return "Invalid Pub/Sub message format", 400
pubsub_message = envelope['message']
data = pubsub_message.get('data')
if data:
# Decode base64 message
decoded_data = base64.b64decode(data).decode("utf-8")
message_json = json.loads(decoded_data)
# Extract account_id and entitlements
account_id = message_json.get("account_id")
entitlements = message_json.get("entitlements", [])
print(f"Received Pub/Sub message: account_id={account_id}, entitlements={entitlements}")
# ⚡ Approve the account in your system (Firebase example)
if account_id:
db.collection("accounts").document(account_id).set({
"status": "approved",
"entitlements": entitlements
}, merge=True)
print(f"Account {account_id} marked as approved in Firebase.")
return "OK", 200
return "No data in Pub/Sub message", 400
except Exception as e:
print(f"Error processing Pub/Sub event: {str(e)}")
return f"Error: {str(e)}", 500
This is how I am listening to pub sub push url. Not sure how I can approve users and entitlements. Some code snippet will be helpful
本文标签:
版权声明:本文标题:google cloud pubsub - How to handle GCP marketplace pub sub events for subscription for Saas integration? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744691873a2620043.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论