Skip to content

Commit 7cb5c4c

Browse files
committed
Update documentation for Datastore options
1 parent 6fc1479 commit 7cb5c4c

1 file changed

Lines changed: 96 additions & 28 deletions

File tree

Datastore/src/DatastoreClient.php

Lines changed: 96 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
namespace Google\Cloud\Datastore;
1919

2020
use DomainException;
21+
use Google\ApiCore\Options\ClientOptions;
2122
use Google\Auth\FetchAuthTokenInterface;
23+
use Google\Cloud\Core\ApiHelperTrait;
2224
use Google\Cloud\Core\ArrayTrait;
2325
use Google\Cloud\Core\ClientTrait;
2426
use Google\Cloud\Core\Int64;
@@ -87,10 +89,10 @@
8789
*/
8890
class DatastoreClient
8991
{
90-
use ArrayTrait;
9192
use ClientTrait;
9293
use DatastoreTrait;
9394
use TimestampTrait;
95+
use ApiHelperTrait;
9496

9597
const VERSION = '1.34.0';
9698

@@ -116,20 +118,76 @@ class DatastoreClient
116118
*
117119
* @param array $config [optional] {
118120
* Configuration Options.
121+
* Some of this options details on {@see ClientOptions}.
119122
*
120-
* @type string $apiEndpoint A hostname with optional port to use in
121-
* place of the service's default endpoint.
122123
* @type string $projectId The project ID from the Google Developer's
123124
* Console.
124-
* @type CacheItemPoolInterface $authCache A cache for storing access
125-
* tokens. **Defaults to** a simple in memory implementation.
126-
* @type array $authCacheOptions Cache configuration options.
127-
* @type callable $authHttpHandler A handler used to deliver Psr7
128-
* requests specifically for authentication.
129-
* @type FetchAuthTokenInterface $credentialsFetcher A credentials
130-
* fetcher instance.
131-
* @type callable $httpHandler A handler used to deliver Psr7 requests.
132-
* Only valid for requests sent over REST.
125+
* @type string $namespaceId Partitions data under a namespace. Useful for
126+
* [Multitenant Projects](https://cloud.google.com/datastore/docs/concepts/multitenancy).
127+
* @type string $databaseId ID of the database to which the entities belong.
128+
* @type bool $returnInt64AsObject If true, 64 bit integers will be
129+
* returned as a {@see \Google\Cloud\Core\Int64} object for 32 bit
130+
* platform compatibility. **Defaults to** false.
131+
* @type GapicDatastoreClient $datastoreClient A client that is of
132+
* type {@see GapicDatastoreClient}
133+
* @type string $apiEndpoint
134+
* The address of the API remote host. May optionally include the port, formatted
135+
* as "<uri>:<port>". Default 'datastore.googleapis.com:443'.
136+
* @type FetchAuthTokenInterface|CredentialsWrapper $credentials
137+
* This option should only be used with a pre-constructed
138+
* {@see FetchAuthTokenInterface} or {@see CredentialsWrapper} object. Note that
139+
* when one of these objects are provided, any settings in $credentialsConfig will
140+
* be ignored.
141+
* **Important**: If you are providing a path to a credentials file, or a decoded
142+
* credentials file as a PHP array, this usage is now DEPRECATED. Providing an
143+
* unvalidated credential configuration to Google APIs can compromise the security
144+
* of your systems and data. It is recommended to create the credentials explicitly
145+
* ```
146+
* use Google\Auth\Credentials\ServiceAccountCredentials;
147+
* use Google\Cloud\Datastore\V1\DatastoreClient;
148+
* $creds = new ServiceAccountCredentials($scopes, $json);
149+
* $options = new DatastoreClient(['credentials' => $creds]);
150+
* ```
151+
* {@see
152+
* https://cloud.google.com/docs/authentication/external/externally-sourced-credentials}
153+
* @type array $credentialsConfig
154+
* Options used to configure credentials, including auth token caching, for the
155+
* client. For a full list of supporting configuration options, see
156+
* {@see \Google\ApiCore\CredentialsWrapper::build()} .
157+
* @type bool $disableRetries
158+
* Determines whether or not retries defined by the client configuration should be
159+
* disabled. Defaults to `false`.
160+
* @type string|array $clientConfig
161+
* Client method configuration, including retry settings. This option can be either
162+
* a path to a JSON file, or a PHP array containing the decoded JSON data. By
163+
* default this settings points to the default client config file, which is
164+
* provided in the resources folder.
165+
* @type string|TransportInterface $transport
166+
* The transport used for executing network requests. May be either the string
167+
* `rest` or `grpc`. Defaults to `grpc` if gRPC support is detected on the system.
168+
* *Advanced usage*: Additionally, it is possible to pass in an already
169+
* instantiated {@see \Google\ApiCore\Transport\TransportInterface} object. Note
170+
* that when this object is provided, any settings in $transportConfig, and any
171+
* $apiEndpoint setting, will be ignored.
172+
* @type array $transportConfig
173+
* Configuration options that will be used to construct the transport. Options for
174+
* each supported transport type should be passed in a key for that transport. For
175+
* example:
176+
* $transportConfig = [
177+
* 'grpc' => [...],
178+
* 'rest' => [...],
179+
* ];
180+
* See the {@see \Google\ApiCore\Transport\GrpcTransport::build()} and
181+
* {@see \Google\ApiCore\Transport\RestTransport::build()} methods for the
182+
* supported options.
183+
* @type callable $clientCertSource
184+
* A callable which returns the client cert as a string. This can be used to
185+
* provide a certificate and private key to the transport layer for mTLS.
186+
* @type false|LoggerInterface $logger
187+
* A PSR-3 compliant logger. If set to false, logging is disabled, ignoring the
188+
* 'GOOGLE_SDK_PHP_LOGGING' environment flag
189+
* @type string $universeDomain
190+
* The service domain for the client. Defaults to 'googleapis.com'.
133191
* @type array $keyFile [DEPRECATED]
134192
* @deprecated This option is being deprecated because of a potential security risk.
135193
* This option does not validate the credential configuration. The security
@@ -174,28 +232,13 @@ class DatastoreClient
174232
* Regardless of the method used, it is always your responsibility to validate
175233
* configurations received from external sources.
176234
* @see https://cloud.google.com/docs/authentication/external/externally-sourced-credentials
177-
* @type float $requestTimeout Seconds to wait before timing out the
178-
* request. **Defaults to** `0` with REST and `60` with gRPC.
179-
* @type int $retries Number of retries for a failed request. **Defaults
180-
* to** `3`.
181-
* @type array $scopes Scopes to be used for the request.
182-
* @type string $quotaProject Specifies a user project to bill for
183-
* access charges associated with the request.
184-
* @type string $namespaceId Partitions data under a namespace. Useful for
185-
* [Multitenant Projects](https://cloud.google.com/datastore/docs/concepts/multitenancy).
186-
* @type string $databaseId ID of the database to which the entities belong.
187-
* @type bool $returnInt64AsObject If true, 64 bit integers will be
188-
* returned as a {@see \Google\Cloud\Core\Int64} object for 32 bit
189-
* platform compatibility. **Defaults to** false.
190-
* @type GapicDatastoreClient $datastoreClient A client that is of
191-
* type {@see GapicDatastoreClient}
192235
* }
193236
* @throws \InvalidArgumentException
194237
*/
195238
public function __construct(array $config = [])
196239
{
197240
$emulatorHost = getenv('DATASTORE_EMULATOR_HOST');
198-
241+
$this->validateConfigurationOptions($config);
199242
$connectionType = $this->getConnectionType($config);
200243

201244
$config += [
@@ -1305,4 +1348,29 @@ private function getGapicClient(array $config): GapicDatastoreClient
13051348

13061349
return $config['datastoreClient'] ?? new GapicDatastoreClient($config);
13071350
}
1351+
1352+
private function validateConfigurationOptions(array $config): void
1353+
{
1354+
$availableOptions = [
1355+
'projectId',
1356+
'namespaceId',
1357+
'databaseId',
1358+
'returnInt64AsObject',
1359+
'datastoreClient',
1360+
'apiEndpoint',
1361+
'credentials',
1362+
'credentialsConfig',
1363+
'disableRetries',
1364+
'clientConfig',
1365+
'transport',
1366+
'transportConfig',
1367+
'clientCertSource',
1368+
'logger',
1369+
'universeDomain',
1370+
'keyFile',
1371+
'keyFilePath',
1372+
];
1373+
1374+
$this->validateOptions($config, $availableOptions);
1375+
}
13081376
}

0 commit comments

Comments
 (0)