Skip to content

Commit

Permalink
feat: Add support to generate client certificate and get connection i…
Browse files Browse the repository at this point in the history
…nfo for auth proxy in AlloyDB v1 (#6663)

PiperOrigin-RevId: 568860878
Source-Link: googleapis/googleapis@5601ad3
Source-Link: googleapis/googleapis-gen@a1f1322
Copy-Tag: eyJwIjoiQWxsb3lEYi8uT3dsQm90LnlhbWwiLCJoIjoiYTFmMTMyMjYwYWYyOGEzMzZmNDNkNWE3YTUzYmYzZTY2YTRiNzVlOCJ9
  • Loading branch information
gcf-owl-bot[bot] authored Sep 28, 2023
1 parent a42e6c0 commit 15da635
Show file tree
Hide file tree
Showing 16 changed files with 1,375 additions and 0 deletions.
Binary file modified AlloyDb/metadata/V1/Resources.php
Binary file not shown.
Binary file modified AlloyDb/metadata/V1/Service.php
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php
/*
* Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* GENERATED CODE WARNING
* This file was automatically generated - do not edit!
*/

require_once __DIR__ . '/../../../vendor/autoload.php';

// [START alloydb_v1_generated_AlloyDBAdmin_GenerateClientCertificate_sync]
use Google\ApiCore\ApiException;
use Google\Cloud\AlloyDb\V1\Client\AlloyDBAdminClient;
use Google\Cloud\AlloyDb\V1\GenerateClientCertificateRequest;
use Google\Cloud\AlloyDb\V1\GenerateClientCertificateResponse;

/**
* Generate a client certificate signed by a Cluster CA.
* The sole purpose of this endpoint is to support AlloyDB connectors and the
* Auth Proxy client. The endpoint's behavior is subject to change without
* notice, so do not rely on its behavior remaining constant. Future changes
* will not break AlloyDB connectors or the Auth Proxy client.
*
* @param string $formattedParent The name of the parent resource. The required format is:
* * projects/{project}/locations/{location}/clusters/{cluster}
* Please see {@see AlloyDBAdminClient::clusterName()} for help formatting this field.
*/
function generate_client_certificate_sample(string $formattedParent): void
{
// Create a client.
$alloyDBAdminClient = new AlloyDBAdminClient();

// Prepare the request message.
$request = (new GenerateClientCertificateRequest())
->setParent($formattedParent);

// Call the API and handle any network failures.
try {
/** @var GenerateClientCertificateResponse $response */
$response = $alloyDBAdminClient->generateClientCertificate($request);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}

/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedParent = AlloyDBAdminClient::clusterName('[PROJECT]', '[LOCATION]', '[CLUSTER]');

generate_client_certificate_sample($formattedParent);
}
// [END alloydb_v1_generated_AlloyDBAdmin_GenerateClientCertificate_sync]
77 changes: 77 additions & 0 deletions AlloyDb/samples/V1/AlloyDBAdminClient/get_connection_info.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php
/*
* Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* GENERATED CODE WARNING
* This file was automatically generated - do not edit!
*/

require_once __DIR__ . '/../../../vendor/autoload.php';

// [START alloydb_v1_generated_AlloyDBAdmin_GetConnectionInfo_sync]
use Google\ApiCore\ApiException;
use Google\Cloud\AlloyDb\V1\Client\AlloyDBAdminClient;
use Google\Cloud\AlloyDb\V1\ConnectionInfo;
use Google\Cloud\AlloyDb\V1\GetConnectionInfoRequest;

/**
* Get instance metadata used for a connection.
*
* @param string $formattedParent The name of the parent resource. The required format is:
* projects/{project}/locations/{location}/clusters/{cluster}/instances/{instance}
* Please see {@see AlloyDBAdminClient::instanceName()} for help formatting this field.
*/
function get_connection_info_sample(string $formattedParent): void
{
// Create a client.
$alloyDBAdminClient = new AlloyDBAdminClient();

// Prepare the request message.
$request = (new GetConnectionInfoRequest())
->setParent($formattedParent);

// Call the API and handle any network failures.
try {
/** @var ConnectionInfo $response */
$response = $alloyDBAdminClient->getConnectionInfo($request);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}

/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedParent = AlloyDBAdminClient::instanceName(
'[PROJECT]',
'[LOCATION]',
'[CLUSTER]',
'[INSTANCE]'
);

get_connection_info_sample($formattedParent);
}
// [END alloydb_v1_generated_AlloyDBAdmin_GetConnectionInfo_sync]
62 changes: 62 additions & 0 deletions AlloyDb/src/V1/Client/BaseClient/AlloyDBAdminBaseClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
use Google\Cloud\AlloyDb\V1\Backup;
use Google\Cloud\AlloyDb\V1\BatchCreateInstancesRequest;
use Google\Cloud\AlloyDb\V1\Cluster;
use Google\Cloud\AlloyDb\V1\ConnectionInfo;
use Google\Cloud\AlloyDb\V1\CreateBackupRequest;
use Google\Cloud\AlloyDb\V1\CreateClusterRequest;
use Google\Cloud\AlloyDb\V1\CreateInstanceRequest;
Expand All @@ -49,8 +50,11 @@
use Google\Cloud\AlloyDb\V1\DeleteInstanceRequest;
use Google\Cloud\AlloyDb\V1\DeleteUserRequest;
use Google\Cloud\AlloyDb\V1\FailoverInstanceRequest;
use Google\Cloud\AlloyDb\V1\GenerateClientCertificateRequest;
use Google\Cloud\AlloyDb\V1\GenerateClientCertificateResponse;
use Google\Cloud\AlloyDb\V1\GetBackupRequest;
use Google\Cloud\AlloyDb\V1\GetClusterRequest;
use Google\Cloud\AlloyDb\V1\GetConnectionInfoRequest;
use Google\Cloud\AlloyDb\V1\GetInstanceRequest;
use Google\Cloud\AlloyDb\V1\GetUserRequest;
use Google\Cloud\AlloyDb\V1\InjectFaultRequest;
Expand Down Expand Up @@ -104,8 +108,10 @@
* @method PromiseInterface deleteInstanceAsync(DeleteInstanceRequest $request, array $optionalArgs = [])
* @method PromiseInterface deleteUserAsync(DeleteUserRequest $request, array $optionalArgs = [])
* @method PromiseInterface failoverInstanceAsync(FailoverInstanceRequest $request, array $optionalArgs = [])
* @method PromiseInterface generateClientCertificateAsync(GenerateClientCertificateRequest $request, array $optionalArgs = [])
* @method PromiseInterface getBackupAsync(GetBackupRequest $request, array $optionalArgs = [])
* @method PromiseInterface getClusterAsync(GetClusterRequest $request, array $optionalArgs = [])
* @method PromiseInterface getConnectionInfoAsync(GetConnectionInfoRequest $request, array $optionalArgs = [])
* @method PromiseInterface getInstanceAsync(GetInstanceRequest $request, array $optionalArgs = [])
* @method PromiseInterface getUserAsync(GetUserRequest $request, array $optionalArgs = [])
* @method PromiseInterface injectFaultAsync(InjectFaultRequest $request, array $optionalArgs = [])
Expand Down Expand Up @@ -757,6 +763,36 @@ public function failoverInstance(FailoverInstanceRequest $request, array $callOp
return $this->startApiCall('FailoverInstance', $request, $callOptions)->wait();
}

/**
* Generate a client certificate signed by a Cluster CA.
* The sole purpose of this endpoint is to support AlloyDB connectors and the
* Auth Proxy client. The endpoint's behavior is subject to change without
* notice, so do not rely on its behavior remaining constant. Future changes
* will not break AlloyDB connectors or the Auth Proxy client.
*
* The async variant is {@see self::generateClientCertificateAsync()} .
*
* @example samples/V1/AlloyDBAdminClient/generate_client_certificate.php
*
* @param GenerateClientCertificateRequest $request A request to house fields associated with the call.
* @param array $callOptions {
* Optional.
*
* @type RetrySettings|array $retrySettings
* Retry settings to use for this call. Can be a {@see RetrySettings} object, or an
* associative array of retry settings parameters. See the documentation on
* {@see RetrySettings} for example usage.
* }
*
* @return GenerateClientCertificateResponse
*
* @throws ApiException Thrown if the API call fails.
*/
public function generateClientCertificate(GenerateClientCertificateRequest $request, array $callOptions = []): GenerateClientCertificateResponse
{
return $this->startApiCall('GenerateClientCertificate', $request, $callOptions)->wait();
}

/**
* Gets details of a single Backup.
*
Expand Down Expand Up @@ -809,6 +845,32 @@ public function getCluster(GetClusterRequest $request, array $callOptions = []):
return $this->startApiCall('GetCluster', $request, $callOptions)->wait();
}

/**
* Get instance metadata used for a connection.
*
* The async variant is {@see self::getConnectionInfoAsync()} .
*
* @example samples/V1/AlloyDBAdminClient/get_connection_info.php
*
* @param GetConnectionInfoRequest $request A request to house fields associated with the call.
* @param array $callOptions {
* Optional.
*
* @type RetrySettings|array $retrySettings
* Retry settings to use for this call. Can be a {@see RetrySettings} object, or an
* associative array of retry settings parameters. See the documentation on
* {@see RetrySettings} for example usage.
* }
*
* @return ConnectionInfo
*
* @throws ApiException Thrown if the API call fails.
*/
public function getConnectionInfo(GetConnectionInfoRequest $request, array $callOptions = []): ConnectionInfo
{
return $this->startApiCall('GetConnectionInfo', $request, $callOptions)->wait();
}

/**
* Gets details of a single Instance.
*
Expand Down
Loading

0 comments on commit 15da635

Please sign in to comment.