Reference documentation and code samples for the Google Cloud PHP shared dependency, providing functionality useful to all components. Client class Iam.
IAM Manager
This class is not meant to be used directly. It should be accessed through other objects which support IAM.
Policies can be created using the PolicyBuilder to help ensure their validity.
Example:
// IAM policies are obtained via resources which implement IAM.
// In this example, we'll use PubSub topics to demonstrate
// how IAM policies are managed.
use Google\Cloud\Spanner\SpannerClient;
$spanner = new SpannerClient();
$instance = $spanner->instance('my-new-instance');
$iam = $instance->iam();
Namespace
Google \ Cloud \ Core \ IamMethods
__construct
Parameters | |
---|---|
Name | Description |
connection |
IamConnectionInterface
|
resource |
string
|
options |
array
Configuration Options |
↳ parent |
string|null
The parent request parameter for the policy. If set, policy data will be sent as |
↳ args |
array
Arbitrary data to be sent with the request. |
policy
Get the existing IAM policy for this resource.
If a policy has already been retrieved from the API, it will be returned. To fetch a fresh copy of the policy, use Iam::reload().
Example:
$policy = $iam->policy();
Parameter | |
---|---|
Name | Description |
options |
int
['requestedPolicyVersion'] Specify the policy version to request from the server. Please see policy versioning for more information. |
Returns | |
---|---|
Type | Description |
array |
An array of policy data |
setPolicy
Set the IAM policy for this resource.
Bindings with invalid roles, or non-existent members will raise a server error.
Example:
$oldPolicy = $iam->policy();
$oldPolicy['bindings'][0]['members'] = 'user:test@example.com';
$policy = $iam->setPolicy($oldPolicy);
Parameters | |
---|---|
Name | Description |
policy |
array|PolicyBuilder
The new policy, as an array or an instance of PolicyBuilder. |
options |
array
Configuration Options |
Returns | |
---|---|
Type | Description |
array |
An array of policy data |
testPermissions
Test if the current user has the given permissions on this resource.
Invalid permissions will raise a BadRequestException.
Example:
$allowedPermissions = $iam->testPermissions([
'pubsub.topics.publish',
'pubsub.topics.attachSubscription'
]);
Parameters | |
---|---|
Name | Description |
permissions |
array
A list of permissions to test |
options |
array
Configuration Options |
Returns | |
---|---|
Type | Description |
array |
A subset of $permissions, with only those allowed included. |
reload
Refresh the IAM policy for this resource.
Example:
$policy = $iam->reload();
Parameter | |
---|---|
Name | Description |
options |
array
Configuration Options |
Returns | |
---|---|
Type | Description |
array |
An array of policy data |