1+ <?php
2+ /**
3+ * Copyright 2020 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+ // Include Google Cloud dependendencies using Composer
19+ require_once __DIR__ . '/../vendor/autoload.php ' ;
20+ if (count ($ argv ) < 1 ) {
21+ return printf ("Usage: php %s PROJECT_ID STRING \n" , __FILE__ );
22+ }
23+ list ($ _ , $ organizationId , $ notificationConfigId , $ projectId , $ topicName ) = $ argv ;
24+
25+ // [START scc_update_notification_config]
26+
27+ use \Google \Cloud \SecurityCenter \V1 \SecurityCenterClient ;
28+ use \Google \Cloud \SecurityCenter \V1 \NotificationConfig ;
29+ use \Google \Protobuf \FieldMask ;
30+
31+ /** Uncomment and populate these variables in your code */
32+ // $organizationId = "{your-org-id}";
33+ // $notificationConfigId = {"your-unique-id"};
34+ // $projectId = "{your-project}"";
35+ // $topicName = "{your-topic}";
36+
37+ $ securityCenterClient = new SecurityCenterClient ();
38+ $ organizationName = "organizations/ " . $ organizationId ;
39+
40+ // Ensure this ServiceAccount has the "pubsub.topics.setIamPolicy" permission on the topic.
41+ $ pubsubTopic = "projects/ " . $ projectId . "/topics/ " . $ topicName ;
42+ $ notificationConfigName = $ organizationName . "/notificationConfigs/ " . $ notificationConfigId ;
43+
44+ try {
45+ $ streamingConfig = new NotificationConfig \StreamingConfig ();
46+ $ streamingConfig ->setFilter ("state = \"ACTIVE \"" );
47+ $ notificationConfig = new NotificationConfig ();
48+ $ notificationConfig ->setName ($ notificationConfigName );
49+ $ notificationConfig ->setDescription ("Updated description. " );
50+ $ notificationConfig ->setPubsubTopic ($ pubsubTopic );
51+ $ fieldMask = new FieldMask ();
52+ $ fieldMask ->setPaths (array ("description " , "pubsub_topic " ));
53+
54+ $ response = $ securityCenterClient ->updateNotificationConfig ($ notificationConfig , array ($ fieldMask ));
55+ printf ("Notification config was updated: %s " , $ response ->getName ());
56+
57+ } finally {
58+ $ securityCenterClient ->close ();
59+ }
60+
61+ // [END scc_update_notification_config]
0 commit comments