Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2472)

Unified Diff: appengine/findit/common/pubsub_util.py

Issue 1852383002: [Findit] Integrate with Fracas through Pub/Sub. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Just rebase. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « appengine/findit/common/constants.py ('k') | appengine/findit/crash-backend-fracas.yaml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: appengine/findit/common/pubsub_util.py
diff --git a/appengine/findit/common/pubsub_util.py b/appengine/findit/common/pubsub_util.py
new file mode 100644
index 0000000000000000000000000000000000000000..1bc9ead351b12fb2e0ffc71e966be7e670f9a4c3
--- /dev/null
+++ b/appengine/findit/common/pubsub_util.py
@@ -0,0 +1,31 @@
+# Copyright 2016 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import base64
+
+import httplib2
+from googleapiclient import discovery
+from oauth2client import client as oauth2client
+
+
+PUBSUB_SCOPES = [
+ 'https://www.googleapis.com/auth/pubsub',
+]
+
+
+def CreatePubSubClient(): # pragma: no cover.
+ credentials = oauth2client.GoogleCredentials.get_application_default()
+ if credentials.create_scoped_required():
+ credentials = credentials.create_scoped(PUBSUB_SCOPES)
+ http = httplib2.Http()
+ credentials.authorize(http)
+ return discovery.build('pubsub', 'v1', http=http)
+
+
+def PublishMessagesToTopic(messages_data, topic): # pragma: no cover.
+ messages = []
+ for message_data in messages_data:
+ messages.append({'data': base64.b64encode(message_data)})
+ return CreatePubSubClient().projects().topics().publish(
+ topic=topic, body={'messages': messages}).execute()
« no previous file with comments | « appengine/findit/common/constants.py ('k') | appengine/findit/crash-backend-fracas.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698