Skip to content

Commit e54cdf0

Browse files
author
Ace Nassri
authored
Merge branch 'master' into ace-n-patch-2
2 parents a3bf75a + 5d08768 commit e54cdf0

File tree

212 files changed

+7705
-2911
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

212 files changed

+7705
-2911
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ credentials.*
88
**/vendor/
99
**/build/
1010
.php_cs.cache
11+
.php-cs-fixer.cache
1112
.vscode/
1213
.kokoro/secrets.sh
1314
.phpunit.result.cache
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
22

3-
return PhpCsFixer\Config::create()
3+
// php-cs-fixer 3.0 distributed config file
4+
5+
$config = new PhpCsFixer\Config();
6+
$config
47
->setRules([
58
'@PSR2' => true,
69
'concat_space' => ['spacing' => 'one'],
710
'no_unused_imports' => true,
8-
'method_argument_space' => false,
911
'whitespace_after_comma_in_array' => true,
1012
'method_argument_space' => [
11-
'keep_multiple_spaces_after_comma' => true
13+
'keep_multiple_spaces_after_comma' => true,
14+
'on_multiline' => 'ignore'
1215
],
1316
'return_type_declaration' => [
1417
'space_before' => 'none'
@@ -19,3 +22,5 @@
1922
->in(__DIR__)
2023
)
2124
;
25+
26+
return $config;

CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
/firestore/**/*.php @GoogleCloudPlatform/cloud-native-db-dpes @GoogleCloudPlatform/php-admins
2222
/iot/ @gcseh @GoogleCloudPlatform/api-iot @GoogleCloudPlatform/php-admins
2323
/storage/ @GoogleCloudPlatform/storage-dpe @GoogleCloudPlatform/php-admins
24+
/spanner/ @GoogleCloudPlatform/api-spanner @GoogleCloudPlatform/php-admins
2425

2526
# Functions samples owned by the Firebase team
2627
/functions/firebase_analytics @schandel @samtstern

CODE_OF_CONDUCT.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Contributor Code of Conduct
2+
3+
As contributors and maintainers of this project,
4+
and in the interest of fostering an open and welcoming community,
5+
we pledge to respect all people who contribute through reporting issues,
6+
posting feature requests, updating documentation,
7+
submitting pull requests or patches, and other activities.
8+
9+
We are committed to making participation in this project
10+
a harassment-free experience for everyone,
11+
regardless of level of experience, gender, gender identity and expression,
12+
sexual orientation, disability, personal appearance,
13+
body size, race, ethnicity, age, religion, or nationality.
14+
15+
Examples of unacceptable behavior by participants include:
16+
17+
* The use of sexualized language or imagery
18+
* Personal attacks
19+
* Trolling or insulting/derogatory comments
20+
* Public or private harassment
21+
* Publishing other's private information,
22+
such as physical or electronic
23+
addresses, without explicit permission
24+
* Other unethical or unprofessional conduct.
25+
26+
Project maintainers have the right and responsibility to remove, edit, or reject
27+
comments, commits, code, wiki edits, issues, and other contributions
28+
that are not aligned to this Code of Conduct.
29+
By adopting this Code of Conduct,
30+
project maintainers commit themselves to fairly and consistently
31+
applying these principles to every aspect of managing this project.
32+
Project maintainers who do not follow or enforce the Code of Conduct
33+
may be permanently removed from the project team.
34+
35+
This code of conduct applies both within project spaces and in public spaces
36+
when an individual is representing the project or its community.
37+
38+
Instances of abusive, harassing, or otherwise unacceptable behavior
39+
may be reported by opening an issue
40+
or contacting one or more of the project maintainers.
41+
42+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.2.0,
43+
available at [http://contributor-covenant.org/version/1/2/0/](http://contributor-covenant.org/version/1/2/0/)

SECURITY.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Security Policy
2+
3+
To report a security issue, please use [g.co/vulnz](https://g.co/vulnz).
4+
5+
The Google Security Team will respond within 5 working days of your report on g.co/vulnz.
6+
7+
We use g.co/vulnz for our intake, and do coordination and disclosure here using GitHub Security Advisory to privately discuss and fix the issue.

bigtable/src/create_app_profile.php

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
2+
3+
namespace Google\Cloud\Samples\Bigtable;
4+
5+
/**
6+
* Copyright 2019 Google LLC.
7+
*
8+
* Licensed under the Apache License, Version 2.0 (the "License");
9+
* you may not use this file except in compliance with the License.
10+
* You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
21+
/**
22+
* For instructions on how to run the full sample:
23+
*
24+
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
25+
*/
26+
27+
// [START bigtable_create_app_profile]
28+
use Google\Cloud\Bigtable\Admin\V2\BigtableInstanceAdminClient;
29+
use Google\Cloud\Bigtable\Admin\V2\AppProfile;
30+
use Google\Cloud\Bigtable\Admin\V2\AppProfile\SingleClusterRouting;
31+
use Google\ApiCore\ApiException;
32+
33+
/**
34+
* Create an App Profile
35+
* @param string $projectId The Google Cloud project ID
36+
* @param string $instanceId The ID of the Bigtable instance
37+
* @param string $clusterId The ID of the cluster where the new App Profile will route it's requests(in case of single cluster routing)
38+
* @param string $appProfileId The ID of the App Profile to create
39+
*/
40+
function create_app_profile(
41+
string $projectId,
42+
string $instanceId,
43+
string $clusterId,
44+
string $appProfileId
45+
): void {
46+
$instanceAdminClient = new BigtableInstanceAdminClient();
47+
$instanceName = $instanceAdminClient->instanceName($projectId, $instanceId);
48+
49+
$appProfile = new AppProfile([
50+
'name' => $appProfileId,
51+
'description' => 'Description for this newly created AppProfile'
52+
]);
53+
54+
// create a new routing policy
55+
// allow_transactional_writes refers to Single-Row-Transactions(https://cloud.google.com/bigtable/docs/app-profiles#single-row-transactions)
56+
$routingPolicy = new SingleClusterRouting([
57+
'cluster_id' => $clusterId,
58+
'allow_transactional_writes' => false
59+
]);
60+
61+
// set the newly created routing policy to our app profile
62+
$appProfile->setSingleClusterRouting($routingPolicy);
63+
64+
// we could also create a multi cluster routing policy like so:
65+
// $routingPolicy = new \Google\Cloud\Bigtable\Admin\V2\AppProfile\MultiClusterRoutingUseAny();
66+
// $appProfile->setMultiClusterRoutingUseAny($routingPolicy);
67+
68+
printf('Creating a new AppProfile %s' . PHP_EOL, $appProfileId);
69+
70+
try {
71+
$newAppProfile = $instanceAdminClient->createAppProfile($instanceName, $appProfileId, $appProfile);
72+
} catch (ApiException $e) {
73+
if ($e->getStatus() === 'ALREADY_EXISTS') {
74+
printf('AppProfile %s already exists.', $appProfileId);
75+
return;
76+
}
77+
throw $e;
78+
}
79+
80+
printf('AppProfile created: %s', $newAppProfile->getName());
81+
}
82+
// [END bigtable_create_app_profile]
83+
84+
// The following 2 lines are only needed to run the samples
85+
require_once __DIR__ . '/../../testing/sample_helpers.php';
86+
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);

bigtable/src/create_cluster.php

Lines changed: 64 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
22

3+
namespace Google\Cloud\Samples\Bigtable;
4+
35
/**
46
* Copyright 2019 Google LLC.
57
*
@@ -22,82 +24,83 @@
2224
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
2325
*/
2426

25-
// Include Google Cloud dependencies using Composer
26-
require_once __DIR__ . '/../vendor/autoload.php';
27-
28-
if (count($argv) < 3 || count($argv) > 5) {
29-
return printf("Usage: php %s PROJECT_ID INSTANCE_ID CLUSTER_ID [LOCATION_ID]" . PHP_EOL, __FILE__);
30-
}
31-
list($_, $projectId, $instanceId, $clusterId) = $argv;
32-
$locationId = isset($argv[4]) ? $argv[4] : 'us-east1-b';
33-
3427
// [START bigtable_create_cluster]
35-
3628
use Google\Cloud\Bigtable\Admin\V2\BigtableInstanceAdminClient;
3729
use Google\Cloud\Bigtable\Admin\V2\Cluster;
3830
use Google\Cloud\Bigtable\Admin\V2\StorageType;
3931
use Google\ApiCore\ApiException;
4032

41-
/** Uncomment and populate these variables in your code */
42-
// $projectId = 'The Google project ID';
43-
// $instanceId = 'The Bigtable instance ID';
44-
// $clusterId = 'The Bigtable cluster ID';
45-
// $locationId = 'The Bigtable region ID';
46-
47-
48-
$instanceAdminClient = new BigtableInstanceAdminClient();
33+
/**
34+
* Create a cluster in an existing Bigtable instance
35+
* @param string $projectId The Google Cloud project ID
36+
* @param string $instanceId The ID of the parent Bigtable instance
37+
* @param string $clusterId The ID of the cluster to be generated
38+
* @param string $locationId The Bigtable region ID where you want your cluster to reside
39+
*/
40+
function create_cluster(
41+
string $projectId,
42+
string $instanceId,
43+
string $clusterId,
44+
string $locationId = 'us-east1-b'
45+
): void {
46+
$instanceAdminClient = new BigtableInstanceAdminClient();
4947

50-
$instanceName = $instanceAdminClient->instanceName($projectId, $instanceId);
51-
$clusterName = $instanceAdminClient->clusterName($projectId, $instanceId, $clusterId);
48+
$instanceName = $instanceAdminClient->instanceName($projectId, $instanceId);
49+
$clusterName = $instanceAdminClient->clusterName($projectId, $instanceId, $clusterId);
5250

53-
printf("Adding Cluster to Instance %s" . PHP_EOL, $instanceId);
54-
try {
55-
$instanceAdminClient->getInstance($instanceName);
56-
} catch (ApiException $e) {
57-
if ($e->getStatus() === 'NOT_FOUND') {
58-
printf("Instance %s does not exists." . PHP_EOL, $instanceId);
59-
return;
60-
} else {
61-
throw $e;
51+
printf("Adding Cluster to Instance %s" . PHP_EOL, $instanceId);
52+
try {
53+
$instanceAdminClient->getInstance($instanceName);
54+
} catch (ApiException $e) {
55+
if ($e->getStatus() === 'NOT_FOUND') {
56+
printf("Instance %s does not exists." . PHP_EOL, $instanceId);
57+
return;
58+
} else {
59+
throw $e;
60+
}
6261
}
63-
}
64-
printf("Listing Clusters:" . PHP_EOL);
62+
printf("Listing Clusters:" . PHP_EOL);
6563

66-
$storage_type = StorageType::SSD;
67-
$serve_nodes = 3;
64+
$storage_type = StorageType::SSD;
65+
$serve_nodes = 3;
6866

69-
$clustersBefore = $instanceAdminClient->listClusters($instanceName)->getClusters();
70-
$clusters = $clustersBefore->getIterator();
71-
foreach ($clusters as $cluster) {
72-
print($cluster->getName() . PHP_EOL);
73-
}
67+
$clustersBefore = $instanceAdminClient->listClusters($instanceName)->getClusters();
68+
$clusters = $clustersBefore->getIterator();
69+
foreach ($clusters as $cluster) {
70+
print($cluster->getName() . PHP_EOL);
71+
}
7472

75-
$cluster = new Cluster();
76-
$cluster->setServeNodes($serve_nodes);
77-
$cluster->setDefaultStorageType($storage_type);
78-
$cluster->setLocation(
79-
$instanceAdminClient->locationName(
80-
$projectId,
81-
$locationId
82-
)
83-
);
84-
try {
85-
$instanceAdminClient->getCluster($clusterName);
86-
printf("Cluster %s already exists, aborting...", $clusterId);
87-
} catch (ApiException $e) {
88-
if ($e->getStatus() === 'NOT_FOUND') {
89-
$operationResponse = $instanceAdminClient->createCluster($instanceName, $clusterId, $cluster);
73+
$cluster = new Cluster();
74+
$cluster->setServeNodes($serve_nodes);
75+
$cluster->setDefaultStorageType($storage_type);
76+
$cluster->setLocation(
77+
$instanceAdminClient->locationName(
78+
$projectId,
79+
$locationId
80+
)
81+
);
82+
try {
83+
$instanceAdminClient->getCluster($clusterName);
84+
printf("Cluster %s already exists, aborting...", $clusterId);
85+
} catch (ApiException $e) {
86+
if ($e->getStatus() === 'NOT_FOUND') {
87+
$operationResponse = $instanceAdminClient->createCluster($instanceName, $clusterId, $cluster);
9088

91-
$operationResponse->pollUntilComplete();
92-
if ($operationResponse->operationSucceeded()) {
93-
$result = $operationResponse->getResult();
94-
printf("Cluster created: %s", $clusterId);
89+
$operationResponse->pollUntilComplete();
90+
if ($operationResponse->operationSucceeded()) {
91+
$result = $operationResponse->getResult();
92+
printf("Cluster created: %s", $clusterId);
93+
} else {
94+
$error = $operationResponse->getError();
95+
printf("Cluster not created: %s", $error);
96+
}
9597
} else {
96-
$error = $operationResponse->getError();
97-
printf("Cluster not created: %s", $error);
98+
throw $e;
9899
}
99-
} else {
100-
throw $e;
101100
}
102101
}
103102
// [END bigtable_create_cluster]
103+
104+
// The following 2 lines are only needed to run the samples
105+
require_once __DIR__ . '/../../testing/sample_helpers.php';
106+
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);

0 commit comments

Comments
 (0)