|
| 1 | +#!/usr/bin/env python |
| 2 | + |
| 3 | +# Copyright 2019 Google LLC. |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | + |
| 18 | +import argparse |
| 19 | + |
| 20 | + |
| 21 | +def create_feed(project_id, feed_id, asset_names, topic): |
| 22 | + # [START asset_quickstart_create_feed] |
| 23 | + from google.cloud import asset_v1p2beta1 |
| 24 | + from google.cloud.asset_v1p2beta1.proto import asset_service_pb2 |
| 25 | + |
| 26 | + # TODO project_id = 'Your Google Cloud Project ID' |
| 27 | + # TODO feed_id = 'Feed ID you want to create' |
| 28 | + # TODO asset_names = 'List of asset names the feed listen to' |
| 29 | + # TODO topic = "Topic name of the feed" |
| 30 | + |
| 31 | + client = asset_v1p2beta1.AssetServiceClient() |
| 32 | + parent = "projects/{}".format(project_id) |
| 33 | + feed = asset_service_pb2.Feed() |
| 34 | + feed.asset_names.extend(asset_names) |
| 35 | + feed.feed_output_config.pubsub_destination.topic = topic |
| 36 | + response = client.create_feed(parent, feed_id, feed) |
| 37 | + print('feed: {}'.format(response)) |
| 38 | + # [END asset_quickstart_create_feed] |
| 39 | + |
| 40 | + |
| 41 | +if __name__ == '__main__': |
| 42 | + parser = argparse.ArgumentParser( |
| 43 | + description=__doc__, |
| 44 | + formatter_class=argparse.RawDescriptionHelpFormatter) |
| 45 | + parser.add_argument('project_id', help='Your Google Cloud project ID') |
| 46 | + parser.add_argument('feed_id', help='Feed ID you want to create') |
| 47 | + parser.add_argument('asset_names', |
| 48 | + help='List of asset names the feed listen to') |
| 49 | + parser.add_argument('topic', help='Topic name of the feed') |
| 50 | + args = parser.parse_args() |
| 51 | + create_feed(args.project_id, args.feed_id, args.asset_names, args.topic) |
0 commit comments