Skip to content

Commit 3e20545

Browse files
authored
feat(Compute): string enums with constants for library Ga (GoogleCloudPlatform#1576)
1 parent 35a3231 commit 3e20545

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"require": {
3-
"google/cloud-compute": "^0.5.0",
4-
"google/cloud-storage": "^1.23"
3+
"google/cloud-compute": "^1.0.0",
4+
"google/cloud-storage": "^1.26"
55
}
66
}

compute/cloud-client/instances/src/create_firewall_rule.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,15 @@
2727
use Google\Cloud\Compute\V1\FirewallsClient;
2828
use Google\Cloud\Compute\V1\Allowed;
2929
use Google\Cloud\Compute\V1\Firewall;
30-
use Google\Cloud\Compute\V1\Firewall\Direction;
3130

3231
/**
33-
* Creates a simple firewall rule allowing for incoming HTTP and HTTPS access from the entire Internet.
32+
* To correctly handle string enums in Cloud Compute library
33+
* use constants defined in the Enums subfolder.
34+
*/
35+
use Google\Cloud\Compute\V1\Enums\Firewall\Direction;
36+
37+
/**
38+
* Creates a simple firewall rule allowing incoming HTTP and HTTPS access from the entire internet.
3439
*
3540
* Example:
3641
* ```
@@ -56,7 +61,7 @@ function create_firewall_rule(string $projectId, string $firewallRuleName, strin
5661
->setPorts(['80', '443']);
5762
$firewallResource = (new Firewall())
5863
->setName($firewallRuleName)
59-
->setDirection(Direction::name(Direction::INGRESS))
64+
->setDirection(Direction::INGRESS)
6065
->setAllowed([$allowedPorts])
6166
->setSourceRanges(['0.0.0.0/0'])
6267
->setTargetTags(['web'])

compute/cloud-client/instances/src/create_instance.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,15 @@
2929
use Google\Cloud\Compute\V1\AttachedDiskInitializeParams;
3030
use Google\Cloud\Compute\V1\Instance;
3131
use Google\Cloud\Compute\V1\NetworkInterface;
32-
use Google\Cloud\Compute\V1\Operation;
3332

3433
/**
35-
* Create an instance in the specified project and zone.
34+
* To correctly handle string enums in Cloud Compute library
35+
* use constants defined in the Enums subfolder.
36+
*/
37+
use Google\Cloud\Compute\V1\Enums\AttachedDisk\Type;
38+
39+
/**
40+
* Creates an instance in the specified project and zone.
3641
* Example:
3742
* ```
3843
* create_instance($projectId, $zone, $instanceName);
@@ -65,6 +70,7 @@ function create_instance(
6570
$disk = (new AttachedDisk())
6671
->setBoot(true)
6772
->setAutoDelete(true)
73+
->setType(Type::PERSISTENT)
6874
->setInitializeParams($diskInitializeParams);
6975

7076
// Use the network interface provided in the $networkName argument.

0 commit comments

Comments
 (0)