google cloud pubsub - How to handle GCP marketplace pub sub events for subscription for Saas integration? - Stack Overflow

@pubsub_bp.route("apipubsubevents", methods=["POST"])def handle_pubsub_event():

@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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744691873a4588257.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信
['keyword'] : $thread['subject']; $header['description'] = $thread['description'] ? $thread['description'] : $thread['brief']; $_SESSION['fid'] = $fid; if ($ajax) { empty($conf['api_on']) and message(0, lang('closed')); $apilist['header'] = $header; $apilist['extra'] = $extra; $apilist['access'] = $access; $apilist['thread'] = well_thread_safe_info($thread); $apilist['thread_data'] = $data; $apilist['forum'] = $forum; $apilist['imagelist'] = $imagelist; $apilist['filelist'] = $thread['filelist']; $apilist['threadlist'] = $threadlist; message(0, $apilist); } else { include _include(theme_load('single_page', $fid)); } break; default: message(-1, lang('data_malformation')); break; } ?>