{"action":"created","comment":{"url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/pulls/comments/66672026","id":66672026,"diff_hunk":"@@ -0,0 +1,108 @@\n+#!/usr/bin/env python\n+# Copyright 2016 Google Inc. All Rights Reserved.\n+#\n+# Licensed under the Apache License, Version 2.0 (the \"License\");\n+# you may not use this file except in compliance with the License.\n+# You may obtain a copy of the License at\n+#\n+#     http://www.apache.org/licenses/LICENSE-2.0\n+#\n+# Unless required by applicable law or agreed to in writing, software\n+# distributed under the License is distributed on an \"AS IS\" BASIS,\n+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+# See the License for the specific language governing permissions and\n+# limitations under the License.\n+\n+import argparse\n+\n+from gcloud import logging\n+from oauth2client.client import GoogleCredentials\n+\n+SINK_NAME = 'mysink'\n+\n+\n+def create_sink_if_not_exists(client, project_id, destination_bucket,\n+                              sink_name):\n+    \"\"\"Creates a logging sink\"\"\"\n+    # [START create]\n+    sink = client.sink(sink_name,\n+                       'logName=\"projects/{}/logs/syslog\" '\n+                       'AND severity>=ERROR'\n+                       .format(project_id),\n+                       'storage.googleapis.com/{}'.format(destination_bucket))\n+    if not sink.exists():\n+        sink.create()\n+        print(\"Created sink {}\".format(sink.name))\n+    # [END create]\n+    return sink\n+\n+\n+def list_sinks(client):\n+    \"\"\"Lists all sinks for a project\"\"\"\n+    print(\"Listing sinks available\")\n+\n+    # [START list]\n+    sinks = []\n+    while True:\n+        new_sinks, token = client.list_sinks()\n+        sinks += new_sinks\n+        if token is None:\n+            break\n+\n+    for sink in sinks:\n+        print('{}: {}'.format(sink.name, sink.destination))\n+    # [END list]\n+\n+    return sinks\n+\n+\n+def update_sink(sink):\n+    \"\"\"Changes the filter of a sink\"\"\"\n+    # Removes the robot in textPayload part of filter\n+    # [START update]\n+    sink.filter = ('logName=\"projects/{}/logs/syslog\" '\n+                   'AND severity>= INFO'.format(sink.project))\n+    print(\"Updated sink {}\".format(sink.name))\n+    sink.update()\n+    # [END update]\n+\n+\n+def delete_sink(sink):\n+    \"\"\"Deletes a sink\"\"\"\n+    # [START delete]\n+    sink.delete()\n+    # [END delete]\n+    print(\"Deleted sink {}\".format(sink.name))\n+\n+\n+def get_client(project_id):\n+    \"\"\"Builds an http client authenticated with the service account\n+    credentials.\"\"\"\n+    credentials = GoogleCredentials.get_application_default()\n+    return logging.Client(project=project_id, credentials=credentials)\n+    # [END auth]\n+\n+\n+def main(project_id, destination_bucket):","path":"logging/api/export.py","position":86,"original_position":86,"commit_id":"d28decc3c16be118d737c099d325b5f6056b4fc4","original_commit_id":"d28decc3c16be118d737c099d325b5f6056b4fc4","user":{"login":"jonparrott","id":250995,"avatar_url":"https://avatars.githubusercontent.com/u/250995?v=3","gravatar_id":"","url":"https://api.github.com/users/jonparrott","html_url":"https://github.com/jonparrott","followers_url":"https://api.github.com/users/jonparrott/followers","following_url":"https://api.github.com/users/jonparrott/following{/other_user}","gists_url":"https://api.github.com/users/jonparrott/gists{/gist_id}","starred_url":"https://api.github.com/users/jonparrott/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jonparrott/subscriptions","organizations_url":"https://api.github.com/users/jonparrott/orgs","repos_url":"https://api.github.com/users/jonparrott/repos","events_url":"https://api.github.com/users/jonparrott/events{/privacy}","received_events_url":"https://api.github.com/users/jonparrott/received_events","type":"User","site_admin":false},"body":"There's another sample in here somewhere that exposes subcommands for each of these CRUD actions, WDYT about doing that?","created_at":"2016-06-10T19:56:17Z","updated_at":"2016-06-10T19:56:17Z","html_url":"https://github.com/GoogleCloudPlatform/python-docs-samples/pull/373#discussion_r66672026","pull_request_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/pulls/373","_links":{"self":{"href":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/pulls/comments/66672026"},"html":{"href":"https://github.com/GoogleCloudPlatform/python-docs-samples/pull/373#discussion_r66672026"},"pull_request":{"href":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/pulls/373"}}},"pull_request":{"url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/pulls/373","id":73419215,"html_url":"https://github.com/GoogleCloudPlatform/python-docs-samples/pull/373","diff_url":"https://github.com/GoogleCloudPlatform/python-docs-samples/pull/373.diff","patch_url":"https://github.com/GoogleCloudPlatform/python-docs-samples/pull/373.patch","issue_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/issues/373","number":373,"state":"open","locked":false,"title":"Add Logging API Samples","user":{"login":"waprin","id":1075173,"avatar_url":"https://avatars.githubusercontent.com/u/1075173?v=3","gravatar_id":"","url":"https://api.github.com/users/waprin","html_url":"https://github.com/waprin","followers_url":"https://api.github.com/users/waprin/followers","following_url":"https://api.github.com/users/waprin/following{/other_user}","gists_url":"https://api.github.com/users/waprin/gists{/gist_id}","starred_url":"https://api.github.com/users/waprin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/waprin/subscriptions","organizations_url":"https://api.github.com/users/waprin/orgs","repos_url":"https://api.github.com/users/waprin/repos","events_url":"https://api.github.com/users/waprin/events{/privacy}","received_events_url":"https://api.github.com/users/waprin/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-06-10T18:53:47Z","updated_at":"2016-06-10T19:56:17Z","closed_at":null,"merged_at":null,"merge_commit_sha":"090fd5b6060b2b599ac4529ecaed4f4f7e418c79","assignee":{"login":"jonparrott","id":250995,"avatar_url":"https://avatars.githubusercontent.com/u/250995?v=3","gravatar_id":"","url":"https://api.github.com/users/jonparrott","html_url":"https://github.com/jonparrott","followers_url":"https://api.github.com/users/jonparrott/followers","following_url":"https://api.github.com/users/jonparrott/following{/other_user}","gists_url":"https://api.github.com/users/jonparrott/gists{/gist_id}","starred_url":"https://api.github.com/users/jonparrott/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jonparrott/subscriptions","organizations_url":"https://api.github.com/users/jonparrott/orgs","repos_url":"https://api.github.com/users/jonparrott/repos","events_url":"https://api.github.com/users/jonparrott/events{/privacy}","received_events_url":"https://api.github.com/users/jonparrott/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/pulls/373/commits","review_comments_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/pulls/373/comments","review_comment_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/pulls/comments{/number}","comments_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/issues/373/comments","statuses_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/statuses/d28decc3c16be118d737c099d325b5f6056b4fc4","head":{"label":"GoogleCloudPlatform:logging","ref":"logging","sha":"d28decc3c16be118d737c099d325b5f6056b4fc4","user":{"login":"GoogleCloudPlatform","id":2810941,"avatar_url":"https://avatars.githubusercontent.com/u/2810941?v=3","gravatar_id":"","url":"https://api.github.com/users/GoogleCloudPlatform","html_url":"https://github.com/GoogleCloudPlatform","followers_url":"https://api.github.com/users/GoogleCloudPlatform/followers","following_url":"https://api.github.com/users/GoogleCloudPlatform/following{/other_user}","gists_url":"https://api.github.com/users/GoogleCloudPlatform/gists{/gist_id}","starred_url":"https://api.github.com/users/GoogleCloudPlatform/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GoogleCloudPlatform/subscriptions","organizations_url":"https://api.github.com/users/GoogleCloudPlatform/orgs","repos_url":"https://api.github.com/users/GoogleCloudPlatform/repos","events_url":"https://api.github.com/users/GoogleCloudPlatform/events{/privacy}","received_events_url":"https://api.github.com/users/GoogleCloudPlatform/received_events","type":"Organization","site_admin":false},"repo":{"id":35065876,"name":"python-docs-samples","full_name":"GoogleCloudPlatform/python-docs-samples","owner":{"login":"GoogleCloudPlatform","id":2810941,"avatar_url":"https://avatars.githubusercontent.com/u/2810941?v=3","gravatar_id":"","url":"https://api.github.com/users/GoogleCloudPlatform","html_url":"https://github.com/GoogleCloudPlatform","followers_url":"https://api.github.com/users/GoogleCloudPlatform/followers","following_url":"https://api.github.com/users/GoogleCloudPlatform/following{/other_user}","gists_url":"https://api.github.com/users/GoogleCloudPlatform/gists{/gist_id}","starred_url":"https://api.github.com/users/GoogleCloudPlatform/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GoogleCloudPlatform/subscriptions","organizations_url":"https://api.github.com/users/GoogleCloudPlatform/orgs","repos_url":"https://api.github.com/users/GoogleCloudPlatform/repos","events_url":"https://api.github.com/users/GoogleCloudPlatform/events{/privacy}","received_events_url":"https://api.github.com/users/GoogleCloudPlatform/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/GoogleCloudPlatform/python-docs-samples","description":"Code samples used on cloud.google.com","fork":false,"url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples","forks_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/forks","keys_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/keys{/key_id}","collaborators_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/teams","hooks_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/hooks","issue_events_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/issues/events{/number}","events_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/events","assignees_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/assignees{/user}","branches_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/branches{/branch}","tags_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/tags","blobs_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/git/refs{/sha}","trees_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/git/trees{/sha}","statuses_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/statuses/{sha}","languages_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/languages","stargazers_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/stargazers","contributors_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/contributors","subscribers_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/subscribers","subscription_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/subscription","commits_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/commits{/sha}","git_commits_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/git/commits{/sha}","comments_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/comments{/number}","issue_comment_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/issues/comments{/number}","contents_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/contents/{+path}","compare_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/compare/{base}...{head}","merges_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/merges","archive_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/downloads","issues_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/issues{/number}","pulls_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/pulls{/number}","milestones_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/milestones{/number}","notifications_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/labels{/name}","releases_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/releases{/id}","deployments_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/deployments","created_at":"2015-05-04T23:26:13Z","updated_at":"2016-06-10T15:39:33Z","pushed_at":"2016-06-10T18:53:48Z","git_url":"git://github.com/GoogleCloudPlatform/python-docs-samples.git","ssh_url":"git@github.com:GoogleCloudPlatform/python-docs-samples.git","clone_url":"https://github.com/GoogleCloudPlatform/python-docs-samples.git","svn_url":"https://github.com/GoogleCloudPlatform/python-docs-samples","homepage":"","size":1722,"stargazers_count":131,"watchers_count":131,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":169,"mirror_url":null,"open_issues_count":15,"forks":169,"open_issues":15,"watchers":131,"default_branch":"master"}},"base":{"label":"GoogleCloudPlatform:master","ref":"master","sha":"63896b13fc87e27a6110dee1596652506fdd9353","user":{"login":"GoogleCloudPlatform","id":2810941,"avatar_url":"https://avatars.githubusercontent.com/u/2810941?v=3","gravatar_id":"","url":"https://api.github.com/users/GoogleCloudPlatform","html_url":"https://github.com/GoogleCloudPlatform","followers_url":"https://api.github.com/users/GoogleCloudPlatform/followers","following_url":"https://api.github.com/users/GoogleCloudPlatform/following{/other_user}","gists_url":"https://api.github.com/users/GoogleCloudPlatform/gists{/gist_id}","starred_url":"https://api.github.com/users/GoogleCloudPlatform/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GoogleCloudPlatform/subscriptions","organizations_url":"https://api.github.com/users/GoogleCloudPlatform/orgs","repos_url":"https://api.github.com/users/GoogleCloudPlatform/repos","events_url":"https://api.github.com/users/GoogleCloudPlatform/events{/privacy}","received_events_url":"https://api.github.com/users/GoogleCloudPlatform/received_events","type":"Organization","site_admin":false},"repo":{"id":35065876,"name":"python-docs-samples","full_name":"GoogleCloudPlatform/python-docs-samples","owner":{"login":"GoogleCloudPlatform","id":2810941,"avatar_url":"https://avatars.githubusercontent.com/u/2810941?v=3","gravatar_id":"","url":"https://api.github.com/users/GoogleCloudPlatform","html_url":"https://github.com/GoogleCloudPlatform","followers_url":"https://api.github.com/users/GoogleCloudPlatform/followers","following_url":"https://api.github.com/users/GoogleCloudPlatform/following{/other_user}","gists_url":"https://api.github.com/users/GoogleCloudPlatform/gists{/gist_id}","starred_url":"https://api.github.com/users/GoogleCloudPlatform/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GoogleCloudPlatform/subscriptions","organizations_url":"https://api.github.com/users/GoogleCloudPlatform/orgs","repos_url":"https://api.github.com/users/GoogleCloudPlatform/repos","events_url":"https://api.github.com/users/GoogleCloudPlatform/events{/privacy}","received_events_url":"https://api.github.com/users/GoogleCloudPlatform/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/GoogleCloudPlatform/python-docs-samples","description":"Code samples used on cloud.google.com","fork":false,"url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples","forks_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/forks","keys_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/keys{/key_id}","collaborators_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/teams","hooks_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/hooks","issue_events_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/issues/events{/number}","events_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/events","assignees_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/assignees{/user}","branches_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/branches{/branch}","tags_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/tags","blobs_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/git/refs{/sha}","trees_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/git/trees{/sha}","statuses_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/statuses/{sha}","languages_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/languages","stargazers_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/stargazers","contributors_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/contributors","subscribers_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/subscribers","subscription_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/subscription","commits_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/commits{/sha}","git_commits_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/git/commits{/sha}","comments_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/comments{/number}","issue_comment_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/issues/comments{/number}","contents_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/contents/{+path}","compare_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/compare/{base}...{head}","merges_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/merges","archive_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/downloads","issues_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/issues{/number}","pulls_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/pulls{/number}","milestones_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/milestones{/number}","notifications_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/labels{/name}","releases_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/releases{/id}","deployments_url":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/deployments","created_at":"2015-05-04T23:26:13Z","updated_at":"2016-06-10T15:39:33Z","pushed_at":"2016-06-10T18:53:48Z","git_url":"git://github.com/GoogleCloudPlatform/python-docs-samples.git","ssh_url":"git@github.com:GoogleCloudPlatform/python-docs-samples.git","clone_url":"https://github.com/GoogleCloudPlatform/python-docs-samples.git","svn_url":"https://github.com/GoogleCloudPlatform/python-docs-samples","homepage":"","size":1722,"stargazers_count":131,"watchers_count":131,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":169,"mirror_url":null,"open_issues_count":15,"forks":169,"open_issues":15,"watchers":131,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/pulls/373"},"html":{"href":"https://github.com/GoogleCloudPlatform/python-docs-samples/pull/373"},"issue":{"href":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/issues/373"},"comments":{"href":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/issues/373/comments"},"review_comments":{"href":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/pulls/373/comments"},"review_comment":{"href":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/pulls/373/commits"},"statuses":{"href":"https://api.github.com/repos/GoogleCloudPlatform/python-docs-samples/statuses/d28decc3c16be118d737c099d325b5f6056b4fc4"}}}}
{"actor":{"display_login":"jonparrott"}}