Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 102 additions & 2 deletions asset/asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
// Create Bucket ACL command
$application->add(new Command('export'))
->setDescription('Export assets for given projec to specified path.')
->setHelp(<<<EOF
->setHelp(
<<<EOF
The <info>%command.name%</info> command exports assets for given project to specified path.

<info>php %command.full_name% --help</info>
Expand All @@ -46,7 +47,8 @@
// Create Bucket Default ACL command
$application->add(new Command('batch-get-history'))
->setDescription('Batch get the history of assets.')
->setHelp(<<<EOF
->setHelp(
<<<EOF
The <info>%command.name%</info> command batch gets history of assets.

<info>php %command.full_name% --help</info>
Expand All @@ -62,6 +64,104 @@
batch_get_assets_history($projectId, $assetNames);
});

// Create Feed Default ACL command
$application->add(new Command('create-feed'))
->setDescription('Create real time feed.')
->setHelp(
<<<EOF
The <info>%command.name%</info> command create real time feed.

<info>php %command.full_name% --help</info>

EOF
)
->addArgument('parent', InputArgument::REQUIRED, 'The parent of the feed')
->addArgument('feedId', InputArgument::REQUIRED, 'The Id of the feed')
->addArgument('topic', InputArgument::REQUIRED, 'The topic of the feed')
->addArgument('assetNames', InputArgument::IS_ARRAY | InputArgument::REQUIRED, 'The assets of which the feed will listen to')

->setCode(function ($input, $output) {
$parent = $input->getArgument('parent');
$feedId = $input->getArgument('feedId');
$topic = $input->getArgument('topic');
$assetNames = $input->getArgument('assetNames');
create_feed($parent, $feedId, $topic, $assetNames);
});

// Get Feed Default ACL command
$application->add(new Command('get-feed'))
->setDescription('Get real time feed.')
->setHelp(
<<<EOF
The <info>%command.name%</info> command get real time feed.

<info>php %command.full_name% --help</info>

EOF
)
->addArgument('feedName', InputArgument::REQUIRED, 'The Name of the feed will be got')

->setCode(function ($input, $output) {
$feedName = $input->getArgument('feedName');
get_feed($feedName);
});

// List Feeds Default ACL command
$application->add(new Command('list-feeds'))
->setDescription('List real time feed under a resource.')
->setHelp(
<<<EOF
The <info>%command.name%</info> command list real time feeds.

<info>php %command.full_name% --help</info>

EOF
)
->addArgument('parent', InputArgument::REQUIRED, 'The resource parent of the feeds will be got')

->setCode(function ($input, $output) {
$parent = $input->getArgument('parent');
list_feeds($parent);
});

// Update Feed Default ACL command
$application->add(new Command('update-feed'))
->setDescription('Update real time feed.')
->setHelp(
<<<EOF
The <info>%command.name%</info> command update assetNames of a real time feed.

<info>php %command.full_name% --help</info>

EOF
)
->addArgument('feedName', InputArgument::REQUIRED, 'The Id of the feed')
->addArgument('assetNames', InputArgument::IS_ARRAY | InputArgument::REQUIRED, 'The assets of which the feed will listen to')

->setCode(function ($input, $output) {
$feedName = $input->getArgument('feedName');
$assetNames = $input->getArgument('assetNames');
update_feed($feedName, $assetNames);
});

// Delete Feed Default ACL command
$application->add(new Command('delete-feed'))
->setDescription('Delete real time feed.')
->setHelp(
<<<EOF
The <info>%command.name%</info> command delete real time feed.

<info>php %command.full_name% --help</info>

EOF
)
->addArgument('feedName', InputArgument::REQUIRED, 'The Name of the feed to be deleted')

->setCode(function ($input, $output) {
$feedName = $input->getArgument('feedName');
delete_feed($feedName);
});

// for testing
if (getenv('PHPUNIT_TESTS') === '1') {
return $application;
Expand Down
10 changes: 8 additions & 2 deletions asset/composer.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
{
"require": {
"google/cloud-storage": "^1.9",
"google/cloud-asset": "^0.4.0",
"google/cloud-pubsub": "^1.11.1",
"google/cloud-asset": "^0.5.0",
"symfony/console": " ^3.0"
},
"autoload": {
"files": [
"src/export_assets.php",
"src/batch_get_assets_history.php"
"src/batch_get_assets_history.php",
"src/create_feed.php",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: whitespace here

"src/get_feed.php",
"src/list_feeds.php",
"src/delete_feed.php",
"src/update_feed.php"
]
}
}
45 changes: 45 additions & 0 deletions asset/src/create_feed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
/**
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace Google\Cloud\Samples\Asset;

# [START asset_quickstart_create_feed]
use Google\Cloud\Asset\V1\AssetServiceClient;
use Google\Cloud\Asset\V1\Feed;
use Google\Cloud\Asset\V1\FeedOutputConfig;
use Google\Cloud\Asset\V1\PubsubDestination;

/**
* Create a real time feed.
*/
function create_feed($parent, $feedId, $topic, $assetNames)
{
$client = new AssetServiceClient();

$feed = new Feed();
$feedOutputConfig = new FeedOutputConfig();
$pubsubDestination = new PubsubDestination();
$pubsubDestination->setTopic($topic);
$feedOutputConfig->setPubsubDestination($pubsubDestination);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, but let's have this ordered better, like this:

    $pubsubDestination = (new PubsubDestination())
        ->setTopic($topic);

    $feedOutputConfig = (new FeedOutputConfig())
        ->setPubsubDestination($pubsubDestination);

    $feed = (new Feed())
        ->setAssetNames($assetNames)
        ->setFeedOutputConfig($feedOutputConfig);

$feed->setAssetNames($assetNames);
$feed->setFeedOutputConfig($feedOutputConfig);

$createdFeed = $client->CreateFeed($parent, $feedId, $feed);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

casing should be createFeed


echo $createdFeed->getName();
}
# [END asset_quickstart_create_feed]
34 changes: 34 additions & 0 deletions asset/src/delete_feed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/**
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace Google\Cloud\Samples\Asset;

# [START asset_quickstart_delete_feed]
use Google\Cloud\Asset\V1\AssetServiceClient;

/**
* Get real time feed given its name.
*/
function delete_feed($feedName)
{
$client = new AssetServiceClient();

$client->DeleteFeed($feedName);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

casing should be deleteFeed


echo 'Feed deleted';
}
# [END asset_quickstart_delete_feed]
34 changes: 34 additions & 0 deletions asset/src/get_feed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/**
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace Google\Cloud\Samples\Asset;

# [START asset_quickstart_create_feed]
use Google\Cloud\Asset\V1\AssetServiceClient;

/**
* Get real time feed given its name.
*/
function get_feed($feedName)
{
$client = new AssetServiceClient();

$feed = $client->GetFeed($feedName);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

casing should be getFeed


echo 'Feed ' . $feed->getName() . ' got.';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not read well. Should be:

printf('Got feed "%s".', $feed->getName());

}
# [END asset_quickstart_get_feed]
34 changes: 34 additions & 0 deletions asset/src/list_feeds.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/**
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace Google\Cloud\Samples\Asset;

# [START asset_quickstart_list_feeds]
use Google\Cloud\Asset\V1\AssetServiceClient;

/**
* List real time feeds sgiven their parents.
*/
function list_feeds($parent)
{
$client = new AssetServiceClient();

$feed = $client->ListFeeds($parent);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

casing should be listFeeds


echo 'Feeds listed';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No feeds were actually listed, would probably make more sense like this:

$feeds = $client->listFeeds($parent);

printf('Feeds for %s:' . PHP_EOL, $parent);
foreach ($feeds as $feed) {
    print($feed->getName() . PHP_EOL);
}

}
# [END asset_quickstart_list_feeds]
42 changes: 42 additions & 0 deletions asset/src/update_feed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
/**
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace Google\Cloud\Samples\Asset;

# [START asset_quickstart_create_feed]
use Google\Cloud\Asset\V1\AssetServiceClient;
use Google\Cloud\Asset\V1\Feed;
use Google\Protobuf\FieldMask;

/**
* Create a real time feed.
*/
function update_feed($feedName, $assetNames)
{
$client = new AssetServiceClient();

$new_feed = new Feed();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's be consistent with our casing and make this variable $newFeed

$new_feed->setName($feedName);
$new_feed->setAssetNames($assetNames);
$updateMask = new FieldMask();
$updateMask->setPaths(['asset_names']);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar issue here, let's format these like follows:

    $newFeed = (new Feed())
        ->setName($feedName)
        ->setAssetNames($assetNames);

    $updateMask = (new FieldMask())
        ->setPaths(['asset_names']);


$updated_feed = $client->UpdateFeed($new_feed, $updateMask);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

casing should be updateFeed for the method call and $updatedFeed for the variable


echo 'Feed Updated ' . $updated_feed;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make this 'Feed Updated: ' . $updatedFeed . PHP_EOL;. All echo/print statements should have an appended new line.

}
# [END asset_quickstart_create_feed]
Loading