From de20ff4a93435ba010c4cc110e28808d707eb842 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Fri, 15 Nov 2024 12:44:05 -0800 Subject: [PATCH 1/4] feat: update apikey sample for client option support --- auth/src/auth_cloud_apikey.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/auth/src/auth_cloud_apikey.php b/auth/src/auth_cloud_apikey.php index 02fe09ca35..356d0d624f 100644 --- a/auth/src/auth_cloud_apikey.php +++ b/auth/src/auth_cloud_apikey.php @@ -44,8 +44,7 @@ function auth_cloud_apikey(string $projectId, string $location, string $apiKey): // Create a client. $productSearchClient = new ProductSearchClient([ - // STEP 1: Use an insecure credentials wrapper to bypass the application default credentials. - 'credentials' => new InsecureCredentialsWrapper(), + 'apiKey' => $apiKey, ]); // Prepare the request message. @@ -55,10 +54,7 @@ function auth_cloud_apikey(string $projectId, string $location, string $apiKey): // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $productSearchClient->listProducts($request, [ - // STEP 2: Pass in the API key with each RPC call as a "Call Option" - 'headers' => ['x-goog-api-key' => [$apiKey]], - ]); + $response = $productSearchClient->listProducts($request); /** @var Product $element */ foreach ($response as $element) { From 59a905968cee99947b957d09ad190c2ef11a22e8 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Fri, 15 Nov 2024 12:49:56 -0800 Subject: [PATCH 2/4] Update auth_cloud_apikey.php --- auth/src/auth_cloud_apikey.php | 1 - 1 file changed, 1 deletion(-) diff --git a/auth/src/auth_cloud_apikey.php b/auth/src/auth_cloud_apikey.php index 356d0d624f..cc941502c4 100644 --- a/auth/src/auth_cloud_apikey.php +++ b/auth/src/auth_cloud_apikey.php @@ -24,7 +24,6 @@ namespace Google\Cloud\Samples\Auth; use Google\ApiCore\ApiException; -use Google\ApiCore\InsecureCredentialsWrapper; use Google\ApiCore\PagedListResponse; use Google\Cloud\Vision\V1\Client\ProductSearchClient; use Google\Cloud\Vision\V1\ListProductsRequest; From 72dfee7eccbdec13ca8d6ecec3bfd6998f1d1263 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Fri, 15 Nov 2024 12:51:08 -0800 Subject: [PATCH 3/4] chore: fix cs in compute sample --- compute/firewall/src/print_firewall_rule.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compute/firewall/src/print_firewall_rule.php b/compute/firewall/src/print_firewall_rule.php index 65ee07f757..bab5a7bc5e 100644 --- a/compute/firewall/src/print_firewall_rule.php +++ b/compute/firewall/src/print_firewall_rule.php @@ -54,7 +54,7 @@ function print_firewall_rule(string $projectId, string $firewallRuleName) printf('Self Link: %s' . PHP_EOL, $response->getSelfLink()); printf('Logging Enabled: %s' . PHP_EOL, var_export($response->getLogConfig()->getEnable(), true)); print('--Allowed--' . PHP_EOL); - foreach ($response->getAllowed()as $item) { + foreach ($response->getAllowed() as $item) { printf('Protocol: %s' . PHP_EOL, $item->getIPProtocol()); foreach ($item->getPorts() as $ports) { printf(' - Ports: %s' . PHP_EOL, $ports); From da5c5fae2b44a57ff1ee6d2986cf534c8b140ca9 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Fri, 15 Nov 2024 13:13:48 -0800 Subject: [PATCH 4/4] update region tag --- auth/src/auth_cloud_apikey.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/auth/src/auth_cloud_apikey.php b/auth/src/auth_cloud_apikey.php index 356d0d624f..12a5df3558 100644 --- a/auth/src/auth_cloud_apikey.php +++ b/auth/src/auth_cloud_apikey.php @@ -20,7 +20,7 @@ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/auth/README.md */ -# [START auth_cloud_apikey] +# [START apikeys_authenticate_api_key] namespace Google\Cloud\Samples\Auth; use Google\ApiCore\ApiException; @@ -64,7 +64,7 @@ function auth_cloud_apikey(string $projectId, string $location, string $apiKey): printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); } } -# [END auth_cloud_apikey] +# [END apikeys_authenticate_api_key] // The following 2 lines are only needed to run the samples require_once __DIR__ . '/../../testing/sample_helpers.php';