Google Cloud PHP shared dependency, providing functionality useful to all components. Client - Class Iam (1.49.3)

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 Google\Cloud\Core\Iam\Google\Cloud\Core\Iam\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\PubSub\PubSubClient;

$pubsub = new PubSubClient();
$topic = $pubsub->topic('my-new-topic');

$iam = $topic->iam();

Methods

__construct

Parameters
NameDescription
connection Google\Cloud\Core\Iam\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 request.{$parent}. Otherwise, policy will be sent in request root. Defaults to policy.

↳ 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 Google\Cloud\Core\Iam\Google\Cloud\Core\Iam\Iam::reload().

Example:

$policy = $iam->policy();
Parameter
NameDescription
options array

Configuration Options

Returns
TypeDescription
arrayAn 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
NameDescription
policy array|Google\Cloud\Core\Iam\PolicyBuilder

The new policy, as an array or an instance of {@see \Google\Cloud\Core\Iam\Google\Cloud\Core\Iam\PolicyBuilder}.

options array

Configuration Options

Returns
TypeDescription
arrayAn 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
NameDescription
permissions array

A list of permissions to test

options array

Configuration Options

Returns
TypeDescription
arrayA subset of $permissions, with only those allowed included.

reload

Refresh the IAM policy for this resource.

Example:

$policy = $iam->reload();
Parameter
NameDescription
options array

Configuration Options

Returns
TypeDescription
arrayAn array of policy data