Skip to content
Merged
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
74 changes: 40 additions & 34 deletions servicedirectory/src/create_endpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,43 +16,49 @@
* limitations under the License.
*/

// Include Google Cloud dependendencies using Composer
require_once __DIR__ . '/../vendor/autoload.php';

if ($argc < 6 || $argc > 8) {
return printf("Usage: php %s PROJECT_ID LOCATION_ID NAMESPACE_ID SERVICE_ID ENDPOINT_ID [IP] [PORT]\n", basename(__FILE__));
}
list($_, $projectId, $locationId, $namespaceId, $serviceId, $endpointId) = $argv;
$ip = isset($argv[6]) ? $argv[6] : '';
$port = isset($argv[7]) ? (int) $argv[7] : 0;
namespace Google\Cloud\Samples\ServiceDirectory;

// [START servicedirectory_create_endpoint]
use Google\Cloud\ServiceDirectory\V1beta1\RegistrationServiceClient;
use Google\Cloud\ServiceDirectory\V1beta1\Endpoint;

/** Uncomment and populate these variables in your code */
// $projectId = '[YOUR_PROJECT_ID]';
// $locationId = '[YOUR_GCP_REGION]';
// $namespaceId = '[YOUR_NAMESPACE_NAME]';
// $serviceId = '[YOUR_SERVICE_NAME]';
// $endpointId = '[YOUR_ENDPOINT_NAME]';
// $ip = '[IP_ADDRESS]'; // (Optional) Defaults to ''
// $port = [PORT]; // (Optional) Defaults to 0

// Instantiate a client.
$client = new RegistrationServiceClient();

// Construct Endpoint object.
$endpointObject = (new Endpoint())
->setAddress($ip)
->setPort($port);

// Run request.
$serviceName = RegistrationServiceClient::serviceName($projectId, $locationId, $namespaceId, $serviceId);
$endpoint = $client->createEndpoint($serviceName, $endpointId, $endpointObject);

// Print results.
printf('Created Endpoint: %s' . PHP_EOL, $endpoint->getName());
printf(' IP: %s' . PHP_EOL, $endpoint->getAddress());
printf(' Port: %d' . PHP_EOL, $endpoint->getPort());
/**
* @param string $projectId Your Cloud project ID
* @param string $locationId Your GCP region
* @param string $namespaceId Your namespace name
* @param string $serviceId Your service name
* @param string $endpointId Your endpoint name
* @param string $ip (Optional) Defaults to ''
* @param int $port (Optional) Defaults to 0
*/
function create_endpoint(
string $projectId,
string $locationId,
string $namespaceId,
string $serviceId,
string $endpointId,
string $ip = '',
int $port = 0
): void {
// Instantiate a client.
$client = new RegistrationServiceClient();

// Construct Endpoint object.
$endpointObject = (new Endpoint())
->setAddress($ip)
->setPort($port);

// Run request.
$serviceName = RegistrationServiceClient::serviceName($projectId, $locationId, $namespaceId, $serviceId);
$endpoint = $client->createEndpoint($serviceName, $endpointId, $endpointObject);

// Print results.
printf('Created Endpoint: %s' . PHP_EOL, $endpoint->getName());
printf(' IP: %s' . PHP_EOL, $endpoint->getAddress());
printf(' Port: %d' . PHP_EOL, $endpoint->getPort());
}
// [END servicedirectory_create_endpoint]

// The following 2 lines are only needed to execute the samples on the CLI
require_once __DIR__ . '/../../testing/sample_helpers.php';
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
46 changes: 25 additions & 21 deletions servicedirectory/src/create_namespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,34 @@
* limitations under the License.
*/

// Include Google Cloud dependendencies using Composer
require_once __DIR__ . '/../vendor/autoload.php';

if ($argc != 4) {
return printf("Usage: php %s PROJECT_ID LOCATION_ID NAMESPACE_ID\n", basename(__FILE__));
}
list($_, $projectId, $locationId, $namespaceId) = $argv;
namespace Google\Cloud\Samples\ServiceDirectory;

// [START servicedirectory_create_namespace]
use Google\Cloud\ServiceDirectory\V1beta1\RegistrationServiceClient;
use Google\Cloud\ServiceDirectory\V1beta1\PBNamespace;

/** Uncomment and populate these variables in your code */
// $projectId = '[YOUR_PROJECT_ID]';
// $locationId = '[YOUR_GCP_REGION]';
// $namespaceId = '[YOUR_NAMESPACE_NAME]';

// Instantiate a client.
$client = new RegistrationServiceClient();

// Run request.
$locationName = RegistrationServiceClient::locationName($projectId, $locationId);
$namespace = $client->createNamespace($locationName, $namespaceId, new PBNamespace());

// Print results.
printf('Created Namespace: %s' . PHP_EOL, $namespace->getName());
/**
* @param string $projectId Your Cloud project ID
* @param string $locationId Your GCP region
* @param string $namespaceId Your namespace name
*/
function create_namespace(
string $projectId,
string $locationId,
string $namespaceId
): void {
// Instantiate a client.
$client = new RegistrationServiceClient();

// Run request.
$locationName = RegistrationServiceClient::locationName($projectId, $locationId);
$namespace = $client->createNamespace($locationName, $namespaceId, new PBNamespace());

// Print results.
printf('Created Namespace: %s' . PHP_EOL, $namespace->getName());
}
// [END servicedirectory_create_namespace]

// The following 2 lines are only needed to execute the samples on the CLI
require_once __DIR__ . '/../../testing/sample_helpers.php';
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
49 changes: 27 additions & 22 deletions servicedirectory/src/create_service.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,36 @@
* limitations under the License.
*/

// Include Google Cloud dependendencies using Composer
require_once __DIR__ . '/../vendor/autoload.php';

if ($argc != 5) {
return printf("Usage: php %s PROJECT_ID LOCATION_ID NAMESPACE_ID SERVICE_ID\n", basename(__FILE__));
}
list($_, $projectId, $locationId, $namespaceId, $serviceId) = $argv;
namespace Google\Cloud\Samples\ServiceDirectory;

// [START servicedirectory_create_service]
use Google\Cloud\ServiceDirectory\V1beta1\RegistrationServiceClient;
use Google\Cloud\ServiceDirectory\V1beta1\Service;

/** Uncomment and populate these variables in your code */
// $projectId = '[YOUR_PROJECT_ID]';
// $locationId = '[YOUR_GCP_REGION]';
// $namespaceId = '[YOUR_NAMESPACE_NAME]';
// $serviceId = '[YOUR_SERVICE_NAME]';

// Instantiate a client.
$client = new RegistrationServiceClient();

// Run request.
$namespaceName = RegistrationServiceClient::namespaceName($projectId, $locationId, $namespaceId);
$service = $client->createService($namespaceName, $serviceId, new Service());

// Print results.
printf('Created Service: %s' . PHP_EOL, $service->getName());
/**
* @param string $projectId Your Cloud project ID
* @param string $locationId Your GCP region
* @param string $namespaceId Your namespace name
* @param string $serviceId Your service name
*/
function create_service(
string $projectId,
string $locationId,
string $namespaceId,
string $serviceId
): void {
// Instantiate a client.
$client = new RegistrationServiceClient();

// Run request.
$namespaceName = RegistrationServiceClient::namespaceName($projectId, $locationId, $namespaceId);
$service = $client->createService($namespaceName, $serviceId, new Service());

// Print results.
printf('Created Service: %s' . PHP_EOL, $service->getName());
}
// [END servicedirectory_create_service]

// The following 2 lines are only needed to execute the samples on the CLI
require_once __DIR__ . '/../../testing/sample_helpers.php';
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
52 changes: 29 additions & 23 deletions servicedirectory/src/delete_endpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,37 @@
* limitations under the License.
*/

// Include Google Cloud dependendencies using Composer
require_once __DIR__ . '/../vendor/autoload.php';

if ($argc != 6) {
return printf("Usage: php %s PROJECT_ID LOCATION_ID NAMESPACE_ID SERVICE_ID ENDPOINT_ID\n", basename(__FILE__));
}
list($_, $projectId, $locationId, $namespaceId, $serviceId, $endpointId) = $argv;
namespace Google\Cloud\Samples\ServiceDirectory;

// [START servicedirectory_delete_endpoint]
use Google\Cloud\ServiceDirectory\V1beta1\RegistrationServiceClient;

/** Uncomment and populate these variables in your code */
// $projectId = '[YOUR_PROJECT_ID]';
// $locationId = '[YOUR_GCP_REGION]';
// $namespaceId = '[YOUR_NAMESPACE_NAME]';
// $serviceId = '[YOUR_SERVICE_NAME]';
// $endpointId = '[YOUR_ENDPOINT_NAME]';

// Instantiate a client.
$client = new RegistrationServiceClient();

// Run request.
$endpointName = RegistrationServiceClient::endpointName($projectId, $locationId, $namespaceId, $serviceId, $endpointId);
$endpoint = $client->deleteEndpoint($endpointName);

// Print results.
printf('Deleted Endpoint: %s' . PHP_EOL, $endpointName);
/**
* @param string $projectId Your Cloud project ID
* @param string $locationId Your GCP region
* @param string $namespaceId Your namespace name
* @param string $serviceId Your service name
* @param string $endpointId Your endpoint name
*/
function delete_endpoint(
string $projectId,
string $locationId,
string $namespaceId,
string $serviceId,
string $endpointId
): void {
// Instantiate a client.
$client = new RegistrationServiceClient();

// Run request.
$endpointName = RegistrationServiceClient::endpointName($projectId, $locationId, $namespaceId, $serviceId, $endpointId);
$endpoint = $client->deleteEndpoint($endpointName);

// Print results.
printf('Deleted Endpoint: %s' . PHP_EOL, $endpointName);
}
// [END servicedirectory_delete_endpoint]

// The following 2 lines are only needed to execute the samples on the CLI
require_once __DIR__ . '/../../testing/sample_helpers.php';
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
46 changes: 25 additions & 21 deletions servicedirectory/src/delete_namespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,33 @@
* limitations under the License.
*/

// Include Google Cloud dependendencies using Composer
require_once __DIR__ . '/../vendor/autoload.php';

if ($argc != 4) {
return printf("Usage: php %s PROJECT_ID LOCATION_ID NAMESPACE_ID\n", basename(__FILE__));
}
list($_, $projectId, $locationId, $namespaceId) = $argv;
namespace Google\Cloud\Samples\ServiceDirectory;

// [START servicedirectory_delete_namespace]
use Google\Cloud\ServiceDirectory\V1beta1\RegistrationServiceClient;

/** Uncomment and populate these variables in your code */
// $projectId = '[YOUR_PROJECT_ID]';
// $locationId = '[YOUR_GCP_REGION]';
// $namespaceId = '[YOUR_NAMESPACE_NAME]';

// Instantiate a client.
$client = new RegistrationServiceClient();

// Run request.
$namespaceName = RegistrationServiceClient::namespaceName($projectId, $locationId, $namespaceId);
$client->deleteNamespace($namespaceName);

// Print results.
printf('Deleted Namespace: %s' . PHP_EOL, $namespaceName);
/**
* @param string $projectId Your Cloud project ID
* @param string $locationId Your GCP region
* @param string $namespaceId Your namespace name
*/
function delete_namespace(
string $projectId,
string $locationId,
string $namespaceId
): void {
// Instantiate a client.
$client = new RegistrationServiceClient();

// Run request.
$namespaceName = RegistrationServiceClient::namespaceName($projectId, $locationId, $namespaceId);
$client->deleteNamespace($namespaceName);

// Print results.
printf('Deleted Namespace: %s' . PHP_EOL, $namespaceName);
}
// [END servicedirectory_delete_namespace]

// The following 2 lines are only needed to execute the samples on the CLI
require_once __DIR__ . '/../../testing/sample_helpers.php';
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
49 changes: 27 additions & 22 deletions servicedirectory/src/delete_service.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,35 @@
* limitations under the License.
*/

// Include Google Cloud dependendencies using Composer
require_once __DIR__ . '/../vendor/autoload.php';

if ($argc != 5) {
return printf("Usage: php %s PROJECT_ID LOCATION_ID NAMESPACE_ID SERVICE_ID\n", basename(__FILE__));
}
list($_, $projectId, $locationId, $namespaceId, $serviceId) = $argv;
namespace Google\Cloud\Samples\ServiceDirectory;

// [START servicedirectory_delete_service]
use Google\Cloud\ServiceDirectory\V1beta1\RegistrationServiceClient;

/** Uncomment and populate these variables in your code */
// $projectId = '[YOUR_PROJECT_ID]';
// $locationId = '[YOUR_GCP_REGION]';
// $namespaceId = '[YOUR_NAMESPACE_NAME]';
// $serviceId = '[YOUR_SERVICE_NAME]';

// Instantiate a client.
$client = new RegistrationServiceClient();

// Run request.
$serviceName = RegistrationServiceClient::serviceName($projectId, $locationId, $namespaceId, $serviceId);
$client->deleteService($serviceName);

// Print results.
printf('Deleted Service: %s' . PHP_EOL, $serviceName);
/**
* @param string $projectId Your Cloud project ID
* @param string $locationId Your GCP region
* @param string $namespaceId Your namespace name
* @param string $serviceId Your service name
*/
function delete_service(
string $projectId,
string $locationId,
string $namespaceId,
string $serviceId
): void {
// Instantiate a client.
$client = new RegistrationServiceClient();

// Run request.
$serviceName = RegistrationServiceClient::serviceName($projectId, $locationId, $namespaceId, $serviceId);
$client->deleteService($serviceName);

// Print results.
printf('Deleted Service: %s' . PHP_EOL, $serviceName);
}
// [END servicedirectory_delete_service]

// The following 2 lines are only needed to execute the samples on the CLI
require_once __DIR__ . '/../../testing/sample_helpers.php';
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
Loading