Skip to content

Commit

Permalink
feat: add support for Universe Domain via service address template (#658
Browse files Browse the repository at this point in the history
)
  • Loading branch information
bshaffer committed Dec 14, 2023
1 parent e45bf0e commit 26661dd
Show file tree
Hide file tree
Showing 36 changed files with 318 additions and 36 deletions.
24 changes: 23 additions & 1 deletion src/Generation/GapicClientGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ private function generateClass(): PhpClass
->withTrait($this->ctx->type(Type::fromName(\Google\ApiCore\GapicClientTrait::class)))
->withMember($this->serviceName())
->withMember($this->serviceAddress())
->withMember($this->hasServiceAddressTemplate() ? $this->serviceAddressTemplate() : null)
->withMember($this->servicePort())
->withMember($this->codegenName())
->withMember($this->serviceScopes())
Expand All @@ -155,10 +156,31 @@ private function serviceName(): PhpClassMember
private function serviceAddress(): PhpClassMember
{
return AST::constant('SERVICE_ADDRESS')
->withPhpDocText('The default address of the service.')
->withPhpDoc(PhpDoc::block(
PhpDoc::text("The default address of the service."),
$this->hasServiceAddressTemplate()
? PhpDoc::deprecated('SERVICE_ADDRESS_TEMPLATE should be used instead.')
: null
))
->withValue($this->serviceDetails->defaultHost);
}

private function hasServiceAddressTemplate(): bool
{
return str_contains($this->serviceDetails->defaultHost, '.googleapis.com');
}

private function serviceAddressTemplate(): PhpClassMember
{
// Replace ".googleapis.com" with .UNIVERSE_DOMAIN to create a template
// in the client libraries (e.x. "storage.googleapis.com" becomes "storage.UNIVERSE_DOMAIN")
$template = str_replace('.googleapis.com', '.UNIVERSE_DOMAIN', $this->serviceDetails->defaultHost);
return AST::constant('SERVICE_ADDRESS_TEMPLATE')
->withPhpDocText('The address template of the service.')
->withAccess(Access::PRIVATE)
->withValue($template);
}

private function servicePort(): PhpClassMember
{
return AST::constant('DEFAULT_SERVICE_PORT')
Expand Down
24 changes: 23 additions & 1 deletion src/Generation/GapicClientV2Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ private function generateClass(): PhpClass
$this->serviceDetails->hasResources ? $this->ctx->type(Type::fromName(\Google\ApiCore\ResourceHelperTrait::class)): null)
->withMember($this->serviceName())
->withMember($this->serviceAddress())
->withMember($this->hasServiceAddressTemplate() ? $this->serviceAddressTemplate() : null)
->withMember($this->servicePort())
->withMember($this->codegenName())
->withMember($this->serviceScopes())
Expand All @@ -161,11 +162,32 @@ private function serviceName(): PhpClassMember
private function serviceAddress(): PhpClassMember
{
return AST::constant('SERVICE_ADDRESS')
->withPhpDocText('The default address of the service.')
->withPhpDoc(PhpDoc::block(
PhpDoc::text("The default address of the service."),
$this->hasServiceAddressTemplate()
? PhpDoc::deprecated('SERVICE_ADDRESS_TEMPLATE should be used instead.')
: null
))
->withAccess(Access::PRIVATE)
->withValue($this->serviceDetails->defaultHost);
}

private function hasServiceAddressTemplate(): bool
{
return str_contains($this->serviceDetails->defaultHost, '.googleapis.com');
}

private function serviceAddressTemplate(): PhpClassMember
{
// Replace ".googleapis.com" with .UNIVERSE_DOMAIN to create a template
// in the client libraries (e.x. "storage.googleapis.com" becomes "storage.UNIVERSE_DOMAIN")
$template = str_replace('.googleapis.com', '.UNIVERSE_DOMAIN', $this->serviceDetails->defaultHost);
return AST::constant('SERVICE_ADDRESS_TEMPLATE')
->withPhpDocText('The address template of the service.')
->withAccess(Access::PRIVATE)
->withValue($template);
}

private function servicePort(): PhpClassMember
{
return AST::constant('DEFAULT_SERVICE_PORT')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,16 @@ class AssetServiceGapicClient
/** The name of the service. */
const SERVICE_NAME = 'google.cloud.asset.v1.AssetService';

/** The default address of the service. */
/**
* The default address of the service.
*
* @deprecated SERVICE_ADDRESS_TEMPLATE should be used instead.
*/
const SERVICE_ADDRESS = 'cloudasset.googleapis.com';

/** The address template of the service. */
private const SERVICE_ADDRESS_TEMPLATE = 'cloudasset.UNIVERSE_DOMAIN';

/** The default port of the service. */
const DEFAULT_SERVICE_PORT = 443;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,16 @@ class AddressesGapicClient
/** The name of the service. */
const SERVICE_NAME = 'google.cloud.compute.v1.Addresses';

/** The default address of the service. */
/**
* The default address of the service.
*
* @deprecated SERVICE_ADDRESS_TEMPLATE should be used instead.
*/
const SERVICE_ADDRESS = 'compute.googleapis.com';

/** The address template of the service. */
private const SERVICE_ADDRESS_TEMPLATE = 'compute.UNIVERSE_DOMAIN';

/** The default port of the service. */
const DEFAULT_SERVICE_PORT = 443;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,16 @@ class RegionOperationsGapicClient
/** The name of the service. */
const SERVICE_NAME = 'google.cloud.compute.v1.RegionOperations';

/** The default address of the service. */
/**
* The default address of the service.
*
* @deprecated SERVICE_ADDRESS_TEMPLATE should be used instead.
*/
const SERVICE_ADDRESS = 'compute.googleapis.com';

/** The address template of the service. */
private const SERVICE_ADDRESS_TEMPLATE = 'compute.UNIVERSE_DOMAIN';

/** The default port of the service. */
const DEFAULT_SERVICE_PORT = 443;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,16 @@ class ClusterManagerGapicClient
/** The name of the service. */
const SERVICE_NAME = 'google.container.v1.ClusterManager';

/** The default address of the service. */
/**
* The default address of the service.
*
* @deprecated SERVICE_ADDRESS_TEMPLATE should be used instead.
*/
const SERVICE_ADDRESS = 'container.googleapis.com';

/** The address template of the service. */
private const SERVICE_ADDRESS_TEMPLATE = 'container.UNIVERSE_DOMAIN';

/** The default port of the service. */
const DEFAULT_SERVICE_PORT = 443;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,16 @@ class AutoscalingPolicyServiceGapicClient
/** The name of the service. */
const SERVICE_NAME = 'google.cloud.dataproc.v1.AutoscalingPolicyService';

/** The default address of the service. */
/**
* The default address of the service.
*
* @deprecated SERVICE_ADDRESS_TEMPLATE should be used instead.
*/
const SERVICE_ADDRESS = 'dataproc.googleapis.com';

/** The address template of the service. */
private const SERVICE_ADDRESS_TEMPLATE = 'dataproc.UNIVERSE_DOMAIN';

/** The default port of the service. */
const DEFAULT_SERVICE_PORT = 443;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,16 @@ class ClusterControllerGapicClient
/** The name of the service. */
const SERVICE_NAME = 'google.cloud.dataproc.v1.ClusterController';

/** The default address of the service. */
/**
* The default address of the service.
*
* @deprecated SERVICE_ADDRESS_TEMPLATE should be used instead.
*/
const SERVICE_ADDRESS = 'dataproc.googleapis.com';

/** The address template of the service. */
private const SERVICE_ADDRESS_TEMPLATE = 'dataproc.UNIVERSE_DOMAIN';

/** The default port of the service. */
const DEFAULT_SERVICE_PORT = 443;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,16 @@ class JobControllerGapicClient
/** The name of the service. */
const SERVICE_NAME = 'google.cloud.dataproc.v1.JobController';

/** The default address of the service. */
/**
* The default address of the service.
*
* @deprecated SERVICE_ADDRESS_TEMPLATE should be used instead.
*/
const SERVICE_ADDRESS = 'dataproc.googleapis.com';

/** The address template of the service. */
private const SERVICE_ADDRESS_TEMPLATE = 'dataproc.UNIVERSE_DOMAIN';

/** The default port of the service. */
const DEFAULT_SERVICE_PORT = 443;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,16 @@ class WorkflowTemplateServiceGapicClient
/** The name of the service. */
const SERVICE_NAME = 'google.cloud.dataproc.v1.WorkflowTemplateService';

/** The default address of the service. */
/**
* The default address of the service.
*
* @deprecated SERVICE_ADDRESS_TEMPLATE should be used instead.
*/
const SERVICE_ADDRESS = 'dataproc.googleapis.com';

/** The address template of the service. */
private const SERVICE_ADDRESS_TEMPLATE = 'dataproc.UNIVERSE_DOMAIN';

/** The default port of the service. */
const DEFAULT_SERVICE_PORT = 443;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,16 @@ final class CloudFunctionsServiceClient
/** The name of the service. */
private const SERVICE_NAME = 'google.cloud.functions.v1.CloudFunctionsService';

/** The default address of the service. */
/**
* The default address of the service.
*
* @deprecated SERVICE_ADDRESS_TEMPLATE should be used instead.
*/
private const SERVICE_ADDRESS = 'cloudfunctions.googleapis.com';

/** The address template of the service. */
private const SERVICE_ADDRESS_TEMPLATE = 'cloudfunctions.UNIVERSE_DOMAIN';

/** The default port of the service. */
private const DEFAULT_SERVICE_PORT = 443;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,16 @@ class IAMPolicyGapicClient
/** The name of the service. */
const SERVICE_NAME = 'google.iam.v1.IAMPolicy';

/** The default address of the service. */
/**
* The default address of the service.
*
* @deprecated SERVICE_ADDRESS_TEMPLATE should be used instead.
*/
const SERVICE_ADDRESS = 'iam-meta-api.googleapis.com';

/** The address template of the service. */
private const SERVICE_ADDRESS_TEMPLATE = 'iam-meta-api.UNIVERSE_DOMAIN';

/** The default port of the service. */
const DEFAULT_SERVICE_PORT = 443;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,16 @@ class KeyManagementServiceGapicClient
/** The name of the service. */
const SERVICE_NAME = 'google.cloud.kms.v1.KeyManagementService';

/** The default address of the service. */
/**
* The default address of the service.
*
* @deprecated SERVICE_ADDRESS_TEMPLATE should be used instead.
*/
const SERVICE_ADDRESS = 'cloudkms.googleapis.com';

/** The address template of the service. */
private const SERVICE_ADDRESS_TEMPLATE = 'cloudkms.UNIVERSE_DOMAIN';

/** The default port of the service. */
const DEFAULT_SERVICE_PORT = 443;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,16 @@ class ConfigServiceV2GapicClient
/** The name of the service. */
const SERVICE_NAME = 'google.logging.v2.ConfigServiceV2';

/** The default address of the service. */
/**
* The default address of the service.
*
* @deprecated SERVICE_ADDRESS_TEMPLATE should be used instead.
*/
const SERVICE_ADDRESS = 'logging.googleapis.com';

/** The address template of the service. */
private const SERVICE_ADDRESS_TEMPLATE = 'logging.UNIVERSE_DOMAIN';

/** The default port of the service. */
const DEFAULT_SERVICE_PORT = 443;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,16 @@ class LoggingServiceV2GapicClient
/** The name of the service. */
const SERVICE_NAME = 'google.logging.v2.LoggingServiceV2';

/** The default address of the service. */
/**
* The default address of the service.
*
* @deprecated SERVICE_ADDRESS_TEMPLATE should be used instead.
*/
const SERVICE_ADDRESS = 'logging.googleapis.com';

/** The address template of the service. */
private const SERVICE_ADDRESS_TEMPLATE = 'logging.UNIVERSE_DOMAIN';

/** The default port of the service. */
const DEFAULT_SERVICE_PORT = 443;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,16 @@ class MetricsServiceV2GapicClient
/** The name of the service. */
const SERVICE_NAME = 'google.logging.v2.MetricsServiceV2';

/** The default address of the service. */
/**
* The default address of the service.
*
* @deprecated SERVICE_ADDRESS_TEMPLATE should be used instead.
*/
const SERVICE_ADDRESS = 'logging.googleapis.com';

/** The address template of the service. */
private const SERVICE_ADDRESS_TEMPLATE = 'logging.UNIVERSE_DOMAIN';

/** The default port of the service. */
const DEFAULT_SERVICE_PORT = 443;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,16 @@ final class CloudRedisClient
/** The name of the service. */
private const SERVICE_NAME = 'google.cloud.redis.v1.CloudRedis';

/** The default address of the service. */
/**
* The default address of the service.
*
* @deprecated SERVICE_ADDRESS_TEMPLATE should be used instead.
*/
private const SERVICE_ADDRESS = 'redis.googleapis.com';

/** The address template of the service. */
private const SERVICE_ADDRESS_TEMPLATE = 'redis.UNIVERSE_DOMAIN';

/** The default port of the service. */
private const DEFAULT_SERVICE_PORT = 443;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,16 @@ class CloudRedisGapicClient
/** The name of the service. */
const SERVICE_NAME = 'google.cloud.redis.v1.CloudRedis';

/** The default address of the service. */
/**
* The default address of the service.
*
* @deprecated SERVICE_ADDRESS_TEMPLATE should be used instead.
*/
const SERVICE_ADDRESS = 'redis.googleapis.com';

/** The address template of the service. */
private const SERVICE_ADDRESS_TEMPLATE = 'redis.UNIVERSE_DOMAIN';

/** The default port of the service. */
const DEFAULT_SERVICE_PORT = 443;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,16 @@ class CatalogServiceGapicClient
/** The name of the service. */
const SERVICE_NAME = 'google.cloud.retail.v2alpha.CatalogService';

/** The default address of the service. */
/**
* The default address of the service.
*
* @deprecated SERVICE_ADDRESS_TEMPLATE should be used instead.
*/
const SERVICE_ADDRESS = 'retail.googleapis.com';

/** The address template of the service. */
private const SERVICE_ADDRESS_TEMPLATE = 'retail.UNIVERSE_DOMAIN';

/** The default port of the service. */
const DEFAULT_SERVICE_PORT = 443;

Expand Down

0 comments on commit 26661dd

Please sign in to comment.