Reference documentation and code samples for the Google Cloud Iam V3 Client class AccessPoliciesClient.
Service Description: Manages Identity and Access Management (IAM) access policies.
This class provides the ability to make remote calls to the backing service through method calls that map to API methods.
Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parseName method to extract the individual identifiers contained within formatted names that are returned by the API.
Namespace
Google \ Cloud \ Iam \ V3 \ ClientMethods
__construct
Constructor.
| Parameters | |
|---|---|
| Name | Description |
options |
array|Google\ApiCore\Options\ClientOptions
Optional. Options for configuring the service API wrapper. |
↳ apiEndpoint |
string
The address of the API remote host. May optionally include the port, formatted as "
|
↳ credentials |
Google\Auth\FetchAuthTokenInterface|Google\ApiCore\CredentialsWrapper
This option should only be used with a pre-constructed Google\Auth\FetchAuthTokenInterface or Google\ApiCore\CredentialsWrapper object. Note that when one of these objects are provided, any settings in $credentialsConfig will be ignored. Important: If you are providing a path to a credentials file, or a decoded credentials file as a PHP array, this usage is now DEPRECATED. Providing an unvalidated credential configuration to Google APIs can compromise the security of your systems and data. It is recommended to create the credentials explicitly |
↳ credentialsConfig |
array
Options used to configure credentials, including auth token caching, for the client. For a full list of supporting configuration options, see Google\ApiCore\CredentialsWrapper::build() . |
↳ disableRetries |
bool
Determines whether or not retries defined by the client configuration should be disabled. Defaults to |
↳ clientConfig |
string|array
Client method configuration, including retry settings. This option can be either a path to a JSON file, or a PHP array containing the decoded JSON data. By default this settings points to the default client config file, which is provided in the resources folder. |
↳ transport |
string|Google\ApiCore\Transport\TransportInterface
The transport used for executing network requests. May be either the string |
↳ transportConfig |
array
Configuration options that will be used to construct the transport. Options for each supported transport type should be passed in a key for that transport. For example: $transportConfig = [ 'grpc' => [...], 'rest' => [...], ]; See the Google\ApiCore\Transport\GrpcTransport::build() and Google\ApiCore\Transport\RestTransport::build() methods for the supported options. |
↳ clientCertSource |
callable
A callable which returns the client cert as a string. This can be used to provide a certificate and private key to the transport layer for mTLS. |
↳ logger |
false|Psr\Log\LoggerInterface
A PSR-3 compliant logger. If set to false, logging is disabled, ignoring the 'GOOGLE_SDK_PHP_LOGGING' environment flag |
↳ universeDomain |
string
The service domain for the client. Defaults to 'googleapis.com'. |
createAccessPolicy
Creates an access policy, and returns a long running operation.
The async variant is AccessPoliciesClient::createAccessPolicyAsync() .
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Iam\V3\CreateAccessPolicyRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
Google\ApiCore\RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
| Returns | |
|---|---|
| Type | Description |
Google\ApiCore\OperationResponse<Google\Cloud\Iam\V3\AccessPolicy> |
|
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Iam\V3\AccessPolicy;
use Google\Cloud\Iam\V3\Client\AccessPoliciesClient;
use Google\Cloud\Iam\V3\CreateAccessPolicyRequest;
use Google\Rpc\Status;
/**
* @param string $formattedParent The parent resource where this access policy will be created.
*
* Format:
* `projects/{project_id}/locations/{location}`
* `projects/{project_number}/locations/{location}`
* `folders/{folder_id}/locations/{location}`
* `organizations/{organization_id}/locations/{location}`
* Please see {@see AccessPoliciesClient::organizationLocationName()} for help formatting this field.
* @param string $accessPolicyId The ID to use for the access policy, which
* will become the final component of the access policy's
* resource name.
*
* This value must start with a lowercase letter followed by up to 62
* lowercase letters, numbers, hyphens, or dots. Pattern,
* /[a-z][a-z0-9-\.]{2,62}/.
*
* This value must be unique among all access policies with the same parent.
*/
function create_access_policy_sample(string $formattedParent, string $accessPolicyId): void
{
// Create a client.
$accessPoliciesClient = new AccessPoliciesClient();
// Prepare the request message.
$accessPolicy = new AccessPolicy();
$request = (new CreateAccessPolicyRequest())
->setParent($formattedParent)
->setAccessPolicyId($accessPolicyId)
->setAccessPolicy($accessPolicy);
// Call the API and handle any network failures.
try {
/** @var OperationResponse $response */
$response = $accessPoliciesClient->createAccessPolicy($request);
$response->pollUntilComplete();
if ($response->operationSucceeded()) {
/** @var AccessPolicy $result */
$result = $response->getResult();
printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
} else {
/** @var Status $error */
$error = $response->getError();
printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedParent = AccessPoliciesClient::organizationLocationName('[ORGANIZATION]', '[LOCATION]');
$accessPolicyId = '[ACCESS_POLICY_ID]';
create_access_policy_sample($formattedParent, $accessPolicyId);
}
deleteAccessPolicy
Deletes an access policy.
The async variant is AccessPoliciesClient::deleteAccessPolicyAsync() .
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Iam\V3\DeleteAccessPolicyRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
Google\ApiCore\RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
| Returns | |
|---|---|
| Type | Description |
Google\ApiCore\OperationResponse<null> |
|
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Iam\V3\Client\AccessPoliciesClient;
use Google\Cloud\Iam\V3\DeleteAccessPolicyRequest;
use Google\Rpc\Status;
/**
* @param string $formattedName The name of the access policy to delete.
*
* Format:
* `projects/{project_id}/locations/{location}/accessPolicies/{access_policy_id}`
* `projects/{project_number}/locations/{location}/accessPolicies/{access_policy_id}`
* `folders/{folder_id}/locations/{location}/accessPolicies/{access_policy_id}`
* `organizations/{organization_id}/locations/{location}/accessPolicies/{access_policy_id}`
* Please see {@see AccessPoliciesClient::accessPolicyName()} for help formatting this field.
*/
function delete_access_policy_sample(string $formattedName): void
{
// Create a client.
$accessPoliciesClient = new AccessPoliciesClient();
// Prepare the request message.
$request = (new DeleteAccessPolicyRequest())
->setName($formattedName);
// Call the API and handle any network failures.
try {
/** @var OperationResponse $response */
$response = $accessPoliciesClient->deleteAccessPolicy($request);
$response->pollUntilComplete();
if ($response->operationSucceeded()) {
printf('Operation completed successfully.' . PHP_EOL);
} else {
/** @var Status $error */
$error = $response->getError();
printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedName = AccessPoliciesClient::accessPolicyName(
'[ORGANIZATION]',
'[LOCATION]',
'[ACCESS_POLICY]'
);
delete_access_policy_sample($formattedName);
}
getAccessPolicy
Gets an access policy.
The async variant is AccessPoliciesClient::getAccessPolicyAsync() .
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Iam\V3\GetAccessPolicyRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
Google\ApiCore\RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
| Returns | |
|---|---|
| Type | Description |
Google\Cloud\Iam\V3\AccessPolicy |
|
use Google\ApiCore\ApiException;
use Google\Cloud\Iam\V3\AccessPolicy;
use Google\Cloud\Iam\V3\Client\AccessPoliciesClient;
use Google\Cloud\Iam\V3\GetAccessPolicyRequest;
/**
* @param string $formattedName The name of the access policy to retrieve.
*
* Format:
* `projects/{project_id}/locations/{location}/accessPolicies/{access_policy_id}`
* `projects/{project_number}/locations/{location}/accessPolicies/{access_policy_id}`
* `folders/{folder_id}/locations/{location}/accessPolicies/{access_policy_id}`
* `organizations/{organization_id}/locations/{location}/accessPolicies/{access_policy_id}`
* Please see {@see AccessPoliciesClient::accessPolicyName()} for help formatting this field.
*/
function get_access_policy_sample(string $formattedName): void
{
// Create a client.
$accessPoliciesClient = new AccessPoliciesClient();
// Prepare the request message.
$request = (new GetAccessPolicyRequest())
->setName($formattedName);
// Call the API and handle any network failures.
try {
/** @var AccessPolicy $response */
$response = $accessPoliciesClient->getAccessPolicy($request);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedName = AccessPoliciesClient::accessPolicyName(
'[ORGANIZATION]',
'[LOCATION]',
'[ACCESS_POLICY]'
);
get_access_policy_sample($formattedName);
}
listAccessPolicies
Lists access policies.
The async variant is AccessPoliciesClient::listAccessPoliciesAsync() .
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Iam\V3\ListAccessPoliciesRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
Google\ApiCore\RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
| Returns | |
|---|---|
| Type | Description |
Google\ApiCore\PagedListResponse |
|
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\Iam\V3\AccessPolicy;
use Google\Cloud\Iam\V3\Client\AccessPoliciesClient;
use Google\Cloud\Iam\V3\ListAccessPoliciesRequest;
/**
* @param string $formattedParent The parent resource, which owns the collection of access policy
* resources.
*
* Format:
* `projects/{project_id}/locations/{location}`
* `projects/{project_number}/locations/{location}`
* `folders/{folder_id}/locations/{location}`
* `organizations/{organization_id}/locations/{location}`
* Please see {@see AccessPoliciesClient::organizationLocationName()} for help formatting this field.
*/
function list_access_policies_sample(string $formattedParent): void
{
// Create a client.
$accessPoliciesClient = new AccessPoliciesClient();
// Prepare the request message.
$request = (new ListAccessPoliciesRequest())
->setParent($formattedParent);
// Call the API and handle any network failures.
try {
/** @var PagedListResponse $response */
$response = $accessPoliciesClient->listAccessPolicies($request);
/** @var AccessPolicy $element */
foreach ($response as $element) {
printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedParent = AccessPoliciesClient::organizationLocationName('[ORGANIZATION]', '[LOCATION]');
list_access_policies_sample($formattedParent);
}
searchAccessPolicyBindings
Returns all policy bindings that bind a specific policy if a user has searchPolicyBindings permission on that policy.
The async variant is AccessPoliciesClient::searchAccessPolicyBindingsAsync() .
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Iam\V3\SearchAccessPolicyBindingsRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
Google\ApiCore\RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
| Returns | |
|---|---|
| Type | Description |
Google\ApiCore\PagedListResponse |
|
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\Iam\V3\Client\AccessPoliciesClient;
use Google\Cloud\Iam\V3\PolicyBinding;
use Google\Cloud\Iam\V3\SearchAccessPolicyBindingsRequest;
/**
* @param string $formattedName The name of the access policy.
* Format:
* `organizations/{organization_id}/locations/{location}/accessPolicies/{access_policy_id}`
* `folders/{folder_id}/locations/{location}/accessPolicies/{access_policy_id}`
* `projects/{project_id}/locations/{location}/accessPolicies/{access_policy_id}`
* `projects/{project_number}/locations/{location}/accessPolicies/{access_policy_id}`
* Please see {@see AccessPoliciesClient::accessPolicyName()} for help formatting this field.
*/
function search_access_policy_bindings_sample(string $formattedName): void
{
// Create a client.
$accessPoliciesClient = new AccessPoliciesClient();
// Prepare the request message.
$request = (new SearchAccessPolicyBindingsRequest())
->setName($formattedName);
// Call the API and handle any network failures.
try {
/** @var PagedListResponse $response */
$response = $accessPoliciesClient->searchAccessPolicyBindings($request);
/** @var PolicyBinding $element */
foreach ($response as $element) {
printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedName = AccessPoliciesClient::accessPolicyName(
'[ORGANIZATION]',
'[LOCATION]',
'[ACCESS_POLICY]'
);
search_access_policy_bindings_sample($formattedName);
}
updateAccessPolicy
Updates an access policy.
The async variant is AccessPoliciesClient::updateAccessPolicyAsync() .
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Iam\V3\UpdateAccessPolicyRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
Google\ApiCore\RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
| Returns | |
|---|---|
| Type | Description |
Google\ApiCore\OperationResponse<Google\Cloud\Iam\V3\AccessPolicy> |
|
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Iam\V3\AccessPolicy;
use Google\Cloud\Iam\V3\Client\AccessPoliciesClient;
use Google\Cloud\Iam\V3\UpdateAccessPolicyRequest;
use Google\Rpc\Status;
/**
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function update_access_policy_sample(): void
{
// Create a client.
$accessPoliciesClient = new AccessPoliciesClient();
// Prepare the request message.
$accessPolicy = new AccessPolicy();
$request = (new UpdateAccessPolicyRequest())
->setAccessPolicy($accessPolicy);
// Call the API and handle any network failures.
try {
/** @var OperationResponse $response */
$response = $accessPoliciesClient->updateAccessPolicy($request);
$response->pollUntilComplete();
if ($response->operationSucceeded()) {
/** @var AccessPolicy $result */
$result = $response->getResult();
printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
} else {
/** @var Status $error */
$error = $response->getError();
printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
createAccessPolicyAsync
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Iam\V3\CreateAccessPolicyRequest
|
optionalArgs |
array
|
| Returns | |
|---|---|
| Type | Description |
GuzzleHttp\Promise\PromiseInterface<Google\ApiCore\OperationResponse> |
|
deleteAccessPolicyAsync
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Iam\V3\DeleteAccessPolicyRequest
|
optionalArgs |
array
|
| Returns | |
|---|---|
| Type | Description |
GuzzleHttp\Promise\PromiseInterface<Google\ApiCore\OperationResponse> |
|
getAccessPolicyAsync
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Iam\V3\GetAccessPolicyRequest
|
optionalArgs |
array
|
| Returns | |
|---|---|
| Type | Description |
GuzzleHttp\Promise\PromiseInterface<Google\Cloud\Iam\V3\AccessPolicy> |
|
listAccessPoliciesAsync
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Iam\V3\ListAccessPoliciesRequest
|
optionalArgs |
array
|
| Returns | |
|---|---|
| Type | Description |
GuzzleHttp\Promise\PromiseInterface<Google\ApiCore\PagedListResponse> |
|
searchAccessPolicyBindingsAsync
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Iam\V3\SearchAccessPolicyBindingsRequest
|
optionalArgs |
array
|
| Returns | |
|---|---|
| Type | Description |
GuzzleHttp\Promise\PromiseInterface<Google\ApiCore\PagedListResponse> |
|
updateAccessPolicyAsync
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Iam\V3\UpdateAccessPolicyRequest
|
optionalArgs |
array
|
| Returns | |
|---|---|
| Type | Description |
GuzzleHttp\Promise\PromiseInterface<Google\ApiCore\OperationResponse> |
|
getOperationsClient
Return an OperationsClient object with the same endpoint as $this.
| Returns | |
|---|---|
| Type | Description |
Google\LongRunning\Client\OperationsClient |
|
resumeOperation
Resume an existing long running operation that was previously started by a long running API method. If $methodName is not provided, or does not match a long running API method, then the operation can still be resumed, but the OperationResponse object will not deserialize the final response.
| Parameters | |
|---|---|
| Name | Description |
operationName |
string
The name of the long running operation |
methodName |
string
The name of the method used to start the operation |
| Returns | |
|---|---|
| Type | Description |
Google\ApiCore\OperationResponse |
|
static::accessPolicyName
Formats a string containing the fully-qualified path to represent a access_policy resource.
| Parameters | |
|---|---|
| Name | Description |
organization |
string
|
location |
string
|
accessPolicy |
string
|
| Returns | |
|---|---|
| Type | Description |
string |
The formatted access_policy resource. |
static::folderLocationName
Formats a string containing the fully-qualified path to represent a folder_location resource.
| Parameters | |
|---|---|
| Name | Description |
folder |
string
|
location |
string
|
| Returns | |
|---|---|
| Type | Description |
string |
The formatted folder_location resource. |
static::folderLocationAccessPolicyName
Formats a string containing the fully-qualified path to represent a folder_location_access_policy resource.
| Parameters | |
|---|---|
| Name | Description |
folder |
string
|
location |
string
|
accessPolicy |
string
|
| Returns | |
|---|---|
| Type | Description |
string |
The formatted folder_location_access_policy resource. |
static::locationName
Formats a string containing the fully-qualified path to represent a location resource.
| Parameters | |
|---|---|
| Name | Description |
project |
string
|
location |
string
|
| Returns | |
|---|---|
| Type | Description |
string |
The formatted location resource. |
static::organizationLocationName
Formats a string containing the fully-qualified path to represent a organization_location resource.
| Parameters | |
|---|---|
| Name | Description |
organization |
string
|
location |
string
|
| Returns | |
|---|---|
| Type | Description |
string |
The formatted organization_location resource. |
static::organizationLocationAccessPolicyName
Formats a string containing the fully-qualified path to represent a organization_location_access_policy resource.
| Parameters | |
|---|---|
| Name | Description |
organization |
string
|
location |
string
|
accessPolicy |
string
|
| Returns | |
|---|---|
| Type | Description |
string |
The formatted organization_location_access_policy resource. |
static::projectLocationAccessPolicyName
Formats a string containing the fully-qualified path to represent a project_location_access_policy resource.
| Parameters | |
|---|---|
| Name | Description |
project |
string
|
location |
string
|
accessPolicy |
string
|
| Returns | |
|---|---|
| Type | Description |
string |
The formatted project_location_access_policy resource. |
static::parseName
Parses a formatted name string and returns an associative array of the components in the name.
The following name formats are supported: Template: Pattern
- accessPolicy: organizations/{organization}/locations/{location}/accessPolicies/{access_policy}
- folderLocation: folders/{folder}/locations/{location}
- folderLocationAccessPolicy: folders/{folder}/locations/{location}/accessPolicies/{access_policy}
- location: projects/{project}/locations/{location}
- organizationLocation: organizations/{organization}/locations/{location}
- organizationLocationAccessPolicy: organizations/{organization}/locations/{location}/accessPolicies/{access_policy}
- projectLocationAccessPolicy: projects/{project}/locations/{location}/accessPolicies/{access_policy}
The optional $template argument can be supplied to specify a particular pattern, and must match one of the templates listed above. If no $template argument is provided, or if the $template argument does not match one of the templates listed, then parseName will check each of the supported templates, and return the first match.
| Parameters | |
|---|---|
| Name | Description |
formattedName |
string
The formatted name string |
template |
?string
Optional name of template to match |
| Returns | |
|---|---|
| Type | Description |
array |
An associative array from name component IDs to component values. |