Skip to content

Commit 3b5d11e

Browse files
authored
feat: add universe domain support to core, bigquery, storage, and pubsub (#6850)
1 parent 705ab23 commit 3b5d11e

File tree

5 files changed

+67
-12
lines changed

5 files changed

+67
-12
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"minimum-stability": "stable",
66
"require": {
77
"php": ">=7.4",
8-
"google/cloud-core": "^1.52.7",
8+
"google/cloud-core": "^1.53",
99
"google/gax": "^1.26.0"
1010
},
1111
"require-dev": {

src/Connection/Grpc.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ class Grpc implements ConnectionInterface
5656
use EmulatorTrait;
5757
use GrpcTrait;
5858

59+
/**
60+
* @deprecated
61+
*/
5962
const BASE_URI = 'https://pubsub.googleapis.com/';
6063

6164
const COMPRESSION_HEADER_KEY = 'grpc-internal-encoding-request';
@@ -112,7 +115,8 @@ public function __construct(array $config = [])
112115
PubSubClient::VERSION,
113116
isset($config['authHttpHandler'])
114117
? $config['authHttpHandler']
115-
: null
118+
: null,
119+
$config['universeDomain'] ?? null
116120
);
117121

118122
$config += ['emulatorHost' => null];
@@ -127,6 +131,10 @@ public function __construct(array $config = [])
127131
$this->emulatorGapicConfig($config['emulatorHost'])
128132
);
129133
}
134+
135+
if (isset($config['universeDomain'])) {
136+
$grpcConfig['universeDomain'] = $config['universeDomain'];
137+
}
130138
//@codeCoverageIgnoreEnd
131139

132140
$this->clientConfig = $grpcConfig;

src/Connection/Rest.php

+12-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
namespace Google\Cloud\PubSub\Connection;
1919

20+
use Google\Auth\GetUniverseDomainInterface;
2021
use Google\Cloud\Core\EmulatorTrait;
2122
use Google\Cloud\Core\RequestBuilder;
2223
use Google\Cloud\Core\RequestWrapper;
@@ -39,19 +40,28 @@ class Rest implements ConnectionInterface
3940
use RestTrait;
4041
use UriTrait;
4142

43+
/**
44+
* @deprecated
45+
*/
4246
const BASE_URI = 'https://pubsub.googleapis.com/';
4347

48+
private const BASE_URI_TEMPLATE = 'https://pubsub.UNIVERSE_DOMAIN';
49+
4450
/**
4551
* @param array $config
4652
*/
4753
public function __construct(array $config = [])
4854
{
49-
$config += ['emulatorHost' => null];
55+
$config += [
56+
'emulatorHost' => null,
57+
'universeDomain' => GetUniverseDomainInterface::DEFAULT_UNIVERSE_DOMAIN,
58+
];
5059

51-
$baseUri = $this->getApiEndpoint(self::BASE_URI, $config);
5260
if ((bool) $config['emulatorHost']) {
5361
$baseUri = $this->emulatorBaseUri($config['emulatorHost']);
5462
$config['shouldSignRequest'] = false;
63+
} else {
64+
$baseUri = $this->getApiEndpoint(null, $config, self::BASE_URI_TEMPLATE);
5565
}
5666

5767
$config += [

tests/Unit/Connection/GrpcTest.php

+24
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,30 @@ public function testApiEndpoint()
7777
$this->assertEquals($expected, $grpc->config['apiEndpoint']);
7878
}
7979

80+
81+
/**
82+
* @dataProvider clientUniverseDomainConfigProvider
83+
*/
84+
public function testUniverseDomain($config, $expectedUniverseDomain, $domainConfigExists = true)
85+
{
86+
$grpc = new GrpcStub($config);
87+
88+
if ($domainConfigExists) {
89+
$this->assertEquals($expectedUniverseDomain, $grpc->config['universeDomain']);
90+
} else {
91+
$this->assertArrayNotHasKey('universeDomain', $grpc->config);
92+
}
93+
}
94+
95+
public function clientUniverseDomainConfigProvider()
96+
{
97+
return [
98+
[[], 'googleapis.com', false],
99+
[['universeDomain' => 'googleapis.com'], 'googleapis.com'],
100+
[['universeDomain' => 'abc.def.ghi'], 'abc.def.ghi'],
101+
];
102+
}
103+
80104
public function testUpdateTopic()
81105
{
82106
$topic = new Topic();

tests/Unit/Connection/RestTest.php

+21-8
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use Prophecy\Argument;
2828
use Prophecy\PhpUnit\ProphecyTrait;
2929
use Psr\Http\Message\RequestInterface;
30+
use UnexpectedValueException;
3031

3132
/**
3233
* @group pubsub
@@ -46,21 +47,33 @@ public function setUp(): void
4647
$this->successBody = '{"canI":"kickIt"}';
4748
}
4849

49-
public function testApiEndpoint()
50+
/**
51+
* @dataProvider clientUniverseDomainConfigProvider
52+
*/
53+
public function testApiEndpointForUniverseDomain($config, $expectedEndpoint, $expectException = false)
5054
{
51-
$endpoint = 'https://foobar.com/';
52-
$rest = TestHelpers::stub(Rest::class, [
53-
[
54-
'apiEndpoint' => $endpoint
55-
]
56-
], ['requestBuilder']);
55+
if ($expectException) {
56+
$this->expectException(UnexpectedValueException::class);
57+
}
58+
$rest = TestHelpers::stub(Rest::class, [$config], ['requestBuilder']);
5759

5860
$rb = $rest->___getProperty('requestBuilder');
5961
$r = new \ReflectionObject($rb);
6062
$p = $r->getProperty('baseUri');
6163
$p->setAccessible(true);
6264

63-
$this->assertEquals($endpoint, $p->getValue($rb));
65+
$this->assertEquals($expectedEndpoint, $p->getValue($rb));
66+
}
67+
68+
public function clientUniverseDomainConfigProvider()
69+
{
70+
return [
71+
[[], 'https://pubsub.googleapis.com/'], // default
72+
[['apiEndpoint' => 'https://foobar.com'], 'https://foobar.com/'],
73+
[['universeDomain' => 'googleapis.com'], 'https://pubsub.googleapis.com/'],
74+
[['universeDomain' => 'abc.def.ghi'], 'https://pubsub.abc.def.ghi/'],
75+
[['universeDomain' => null], '', true],
76+
];
6477
}
6578

6679
/**

0 commit comments

Comments
 (0)