Skip to content

Commit 58ee191

Browse files
author
Patrick Glinsman
committed
Addressed first comments
1 parent 97db2e8 commit 58ee191

File tree

8 files changed

+53
-56
lines changed

8 files changed

+53
-56
lines changed

securitycenter/composer.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
{
2-
32
"require": {
43
"google/cloud-security-center": "^0.5.0",
54
"google/cloud-pubsub": "^1.21"
65
},
76
"require-dev": {
8-
"phpunit/phpunit": "^8"
97
}
108
}

securitycenter/src/create_notification.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,15 @@
1717

1818
// Include Google Cloud dependendencies using Composer
1919
require_once __DIR__ . '/../vendor/autoload.php';
20-
if (count($argv) < 1) {
21-
return printf("Usage: php %s PROJECT_ID STRING\n", __FILE__);
20+
if (count($argv) < 4) {
21+
return printf("Usage: php %s ORGANIZATION_ID NOTIFICATION_ID PROJECT_ID TOPIC_NAME\n", basename(__FILE__));
2222
}
2323
list($_, $organizationId, $notificationConfigId, $projectId, $topicName) = $argv;
2424

2525
// [START scc_create_notification_config]
26-
2726
use \Google\Cloud\SecurityCenter\V1\SecurityCenterClient;
2827
use \Google\Cloud\SecurityCenter\V1\NotificationConfig;
2928

30-
3129
/** Uncomment and populate these variables in your code */
3230
// $organizationId = "{your-org-id}";
3331
// $notificationConfigId = {"your-unique-id"};

securitycenter/src/delete_notification.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@
1717

1818
// Include Google Cloud dependendencies using Composer
1919
require_once __DIR__ . '/../vendor/autoload.php';
20-
if (count($argv) < 1) {
21-
return printf("Usage: php %s PROJECT_ID STRING\n", __FILE__);
20+
if (count($argv) < 2) {
21+
return printf("Usage: php %s ORGANIZATION_ID NOTIFICATION_ID\n", basename(__FILE__));
2222
}
2323
list($_, $organizationId, $notificationConfigId) = $argv;
2424

2525
// [START scc_delete_notification_config]
26-
2726
use \Google\Cloud\SecurityCenter\V1\SecurityCenterClient;
2827

2928
/** Uncomment and populate these variables in your code */

securitycenter/src/get_notification.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@
1717

1818
// Include Google Cloud dependendencies using Composer
1919
require_once __DIR__ . '/../vendor/autoload.php';
20-
if (count($argv) < 1) {
21-
return printf("Usage: php %s PROJECT_ID STRING\n", __FILE__);
20+
if (count($argv) < 2) {
21+
return printf("Usage: php %s ORGANIZATION_ID NOTIFICATION_ID\n", basename(__FILE__));
2222
}
2323
list($_, $organizationId, $notificationConfigId) = $argv;
2424

2525
// [START scc_get_notification_config]
26-
2726
use \Google\Cloud\SecurityCenter\V1\SecurityCenterClient;
2827

2928
/** Uncomment and populate these variables in your code */

securitycenter/src/list_notification.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,11 @@
1818
// Include Google Cloud dependendencies using Composer
1919
require_once __DIR__ . '/../vendor/autoload.php';
2020
if (count($argv) < 1) {
21-
return printf("Usage: php %s PROJECT_ID STRING\n", __FILE__);
21+
return printf("Usage: php %s ORGANIZATION_ID\n", basename(__FILE__));
2222
}
2323
list($_, $organizationId) = $argv;
2424

2525
// [START scc_list_notification_configs]
26-
2726
use \Google\Cloud\SecurityCenter\V1\SecurityCenterClient;
2827

2928
/** Uncomment and populate these variables in your code */

securitycenter/src/receive_notification.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@
1717

1818
// Include Google Cloud dependendencies using Composer
1919
require_once __DIR__ . '/../vendor/autoload.php';
20-
if (count($argv) < 1) {
21-
return printf("Usage: php %s PROJECT_ID STRING\n", __FILE__);
20+
if (count($argv) < 2) {
21+
return printf("Usage: php %s PROJECT_ID SUSBSCRIPTION_ID\n", basename(__FILE__));
2222
}
2323
list($_, $projectId, $subscriptionId) = $argv;
2424

2525
// [START scc_receive_notifications]
26-
2726
use Google\Cloud\PubSub\PubSubClient;
2827

2928
/** Uncomment and populate these variables in your code */

securitycenter/src/update_notification.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@
1717

1818
// Include Google Cloud dependendencies using Composer
1919
require_once __DIR__ . '/../vendor/autoload.php';
20-
if (count($argv) < 1) {
21-
return printf("Usage: php %s PROJECT_ID STRING\n", __FILE__);
20+
if (count($argv) < 4) {
21+
return printf("Usage: php %s ORGANIZATION_ID NOTIFICATION_ID PROJECT_ID TOPIC_NAME\n", basename(__FILE__));
2222
}
2323
list($_, $organizationId, $notificationConfigId, $projectId, $topicName) = $argv;
2424

2525
// [START scc_update_notification_config]
26-
2726
use \Google\Cloud\SecurityCenter\V1\SecurityCenterClient;
2827
use \Google\Cloud\SecurityCenter\V1\NotificationConfig;
2928
use \Google\Protobuf\FieldMask;

securitycenter/test/securitycenterTest.php

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -22,79 +22,83 @@ class securitycenterTest extends TestCase
2222
{
2323
use TestTrait;
2424

25+
private static $testNotificationCreate;
26+
private static $testNotificationGet;
27+
private static $testNotificationUpdate;
28+
29+
public static function setUpBeforeClass()
30+
{
31+
self::$testNotificationCreate = self::randomNotificationId();
32+
self::$testNotificationGet = self::randomNotificationId();
33+
self::$testNotificationUpdate = self::randomNotificationId();
34+
}
35+
36+
private function deleteConfig(string $configId)
37+
{
38+
$deleteOutput = $this->runSnippet('delete_notification', [
39+
self::getOrganizationId(),
40+
$configId,
41+
]);
42+
43+
$this->assertContains('Notification config was deleted', $deleteOutput);
44+
}
45+
2546
public function testCreateNotification()
2647
{
2748
$createOutput = $this->runSnippet('create_notification', [
2849
self::getOrganizationId(),
29-
"php-notification-config-create",
30-
self::getProject(),
50+
self::$testNotificationCreate,
51+
self::$projectId,
3152
self::getTopicName()
3253
]);
3354

3455
$this->assertContains('Notification config was created', $createOutput);
3556

36-
$deleteOutput = $this->runSnippet('delete_notification', [
37-
self::getOrganizationId(),
38-
"php-notification-config-create",
39-
]);
40-
41-
$this->assertContains('Notification config was deleted', $deleteOutput);
57+
self::deleteConfig(self::$testNotificationCreate);
4258
}
4359

4460
public function testGetNotificationConfig()
4561
{
4662
$createOutput = $this->runSnippet('create_notification', [
4763
self::getOrganizationId(),
48-
"php-notification-config-get",
49-
self::getProject(),
64+
self::$testNotificationGet,
65+
self::$projectId,
5066
self::getTopicName()
5167
]);
5268

5369
$this->assertContains('Notification config was created', $createOutput);
5470

5571
$getOutput = $this->runSnippet('get_notification', [
5672
self::getOrganizationId(),
57-
"php-notification-config-get",
73+
self::$testNotificationGet
5874
]);
5975

6076
$this->assertContains('Notification config was retrieved', $getOutput);
6177

62-
$deleteOutput = $this->runSnippet('delete_notification', [
63-
self::getOrganizationId(),
64-
"php-notification-config-get",
65-
]);
66-
67-
$this->assertContains('Notification config was deleted', $deleteOutput);
68-
78+
self::deleteConfig(self::$testNotificationGet);
6979
}
7080

7181
public function testUpdateNotificationConfig()
7282
{
7383
$createOutput = $this->runSnippet('create_notification', [
7484
self::getOrganizationId(),
75-
"php-notification-config-update",
76-
self::getProject(),
85+
self::$testNotificationUpdate,
86+
self::$projectId,
7787
self::getTopicName()
7888
]);
7989

8090
$this->assertContains('Notification config was created', $createOutput);
8191

8292
$getOutput = $this->runSnippet('update_notification', [
8393
self::getOrganizationId(),
84-
"php-notification-config-update",
85-
self::getProject(),
94+
self::$testNotificationUpdate,
95+
self::$projectId,
8696
self::getTopicName()
8797
]);
8898

8999
$this->assertContains('Notification config was updated', $getOutput);
90100

91-
$deleteOutput = $this->runSnippet('delete_notification', [
92-
self::getOrganizationId(),
93-
"php-notification-config-update",
94-
]);
95-
96-
$this->assertContains('Notification config was deleted', $deleteOutput);
97-
101+
self::deleteConfig(self::$testNotificationUpdate);
98102
}
99103

100104
public function testListNotificationConfig()
@@ -104,18 +108,20 @@ public function testListNotificationConfig()
104108
]);
105109

106110
$this->assertContains('Notification configs were listed', $listOutput);
107-
108111
}
109112

110-
private static function getOrganizationId() {
111-
return "1081635000895";
113+
private static function getOrganizationId()
114+
{
115+
return self::requireEnv('GOOGLE_ORGANIZATION_ID');
112116
}
113117

114-
private static function getProject() {
115-
return "project-a-id";
118+
private static function getTopicName()
119+
{
120+
return self::requireEnv('GOOGLE_TOPIC_ID');
116121
}
117122

118-
private static function getTopicName() {
119-
return "notifications-sample-topic";
123+
private static function randomNotificationId()
124+
{
125+
return uniqid('php-notification-config-');
120126
}
121127
}

0 commit comments

Comments
 (0)