|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * Copyright 2020 Google Inc. |
| 5 | + * |
| 6 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | + * you may not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | + |
| 19 | +// Include Google Cloud dependendencies using Composer |
| 20 | +require_once __DIR__ . '/../vendor/autoload.php'; |
| 21 | + |
| 22 | +if ($argc < 6 || $argc > 8) { |
| 23 | + return printf("Usage: php %s PROJECT_ID LOCATION_ID NAMESPACE_ID SERVICE_ID ENDPOINT_ID [IP] [PORT]\n", basename(__FILE__)); |
| 24 | +} |
| 25 | +list($_, $projectId, $locationId, $namespaceId, $serviceId, $endpointId) = $argv; |
| 26 | +$ip = isset($argv[6]) ? $argv[6] : ''; |
| 27 | +$port = isset($argv[7]) ? (int) $argv[7] : 0; |
| 28 | + |
| 29 | +// [START servicedirectory_create_endpoint] |
| 30 | +use Google\Cloud\ServiceDirectory\V1beta1\RegistrationServiceClient; |
| 31 | +use Google\Cloud\ServiceDirectory\V1beta1\Endpoint; |
| 32 | + |
| 33 | +/** Uncomment and populate these variables in your code */ |
| 34 | +// $projectId = '[YOUR_PROJECT_ID]'; |
| 35 | +// $locationId = '[YOUR_GCP_REGION]'; |
| 36 | +// $namespaceId = '[YOUR_NAMESPACE_NAME]'; |
| 37 | +// $serviceId = '[YOUR_SERVICE_NAME]'; |
| 38 | +// $endpointId = '[YOUR_ENDPOINT_NAME]'; |
| 39 | +// $ip = '[IP_ADDRESS]'; // (Optional) Defaults to '' |
| 40 | +// $port = [PORT]; // (Optional) Defaults to 0 |
| 41 | + |
| 42 | +// Instantiate a client. |
| 43 | +$client = new RegistrationServiceClient(); |
| 44 | + |
| 45 | +// Construct Endpoint object. |
| 46 | +$endpointObject = (new Endpoint()) |
| 47 | + ->setAddress($ip) |
| 48 | + ->setPort($port); |
| 49 | + |
| 50 | +// Run request. |
| 51 | +$serviceName = RegistrationServiceClient::serviceName($projectId, $locationId, $namespaceId, $serviceId); |
| 52 | +$endpoint = $client->createEndpoint($serviceName, $endpointId, $endpointObject); |
| 53 | + |
| 54 | +// Print results. |
| 55 | +printf('Created Endpoint: %s' . PHP_EOL, $endpoint->getName()); |
| 56 | +printf(' IP: %s' . PHP_EOL, $endpoint->getAddress()); |
| 57 | +printf(' Port: %d' . PHP_EOL, $endpoint->getPort()); |
| 58 | +// [END servicedirectory_create_endpoint] |
0 commit comments