Google Cloud Assured Workloads V1beta1 Client - Class AssuredWorkloadsServiceClient (0.8.3)

Reference documentation and code samples for the Google Cloud Assured Workloads V1beta1 Client class AssuredWorkloadsServiceClient.

Service Description: Service to manage AssuredWorkloads.

This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started:

$assuredWorkloadsServiceClient = new AssuredWorkloadsServiceClient();
try {
    $target = 'target';
    $response = $assuredWorkloadsServiceClient->analyzeWorkloadMove($target);
} finally {
    $assuredWorkloadsServiceClient->close();
}

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.

Methods

locationName

Formats a string containing the fully-qualified path to represent a location resource.

Parameters
NameDescription
organization string
location string
Returns
TypeDescription
stringThe formatted location resource.

workloadName

Formats a string containing the fully-qualified path to represent a workload resource.

Parameters
NameDescription
organization string
location string
workload string
Returns
TypeDescription
stringThe formatted workload resource.

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

  • location: organizations/{organization}/locations/{location}
  • workload: organizations/{organization}/locations/{location}/workloads/{workload}

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
NameDescription
formattedName string

The formatted name string

template string

Optional name of template to match

Returns
TypeDescription
arrayAn associative array from name component IDs to component values.

getOperationsClient

Return an OperationsClient object with the same endpoint as $this.

Returns
TypeDescription
Google\ApiCore\LongRunning\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
NameDescription
operationName string

The name of the long running operation

methodName string

The name of the method used to start the operation

Returns
TypeDescription
Google\ApiCore\OperationResponse

__construct

Constructor.

Parameters
NameDescription
options array

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 string|array|FetchAuthTokenInterface|CredentialsWrapper

The credentials to be used by the client to authorize API calls. This option accepts either a path to a credentials file, or a decoded credentials file as a PHP array. Advanced usage: In addition, this option can also accept a pre-constructed Google\Auth\FetchAuthTokenInterface object or Google\ApiCore\CredentialsWrapper object. Note that when one of these objects are provided, any settings in $credentialsConfig will be ignored.

↳ 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 false.

↳ 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|TransportInterface

The transport used for executing network requests. May be either the string rest or grpc. Defaults to grpc if gRPC support is detected on the system. Advanced usage: Additionally, it is possible to pass in an already instantiated Google\ApiCore\Transport\TransportInterface object. Note that when this object is provided, any settings in $transportConfig, and any $apiEndpoint setting, will be ignored.

↳ 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.

analyzeWorkloadMove

Analyze if the source Assured Workloads can be moved to the target Assured Workload

Parameters
NameDescription
target string

Required. The resource ID of the folder-based destination workload. This workload is where the source project will hypothetically be moved to. Specify the workload's relative resource name, formatted as: "organizations/{ORGANIZATION_ID}/locations/{LOCATION_ID}/workloads/{WORKLOAD_ID}" For example: "organizations/123/locations/us-east1/workloads/assured-workload-2"

optionalArgs array

Optional.

↳ source string

The source type is a project-based workload. Specify the workloads's relative resource name, formatted as: "organizations/{ORGANIZATION_ID}/locations/{LOCATION_ID}/workloads/{WORKLOAD_ID}" For example: "organizations/123/locations/us-east1/workloads/assured-workload-1"

↳ project string

The source type is a project. Specify the project's relative resource name, formatted as either a project number or a project ID: "projects/{PROJECT_NUMBER}" or "projects/{PROJECT_ID}" For example: "projects/951040570662" when specifying a project number, or "projects/my-project-123" when specifying a project ID.

↳ retrySettings 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
TypeDescription
Google\Cloud\AssuredWorkloads\V1beta1\AnalyzeWorkloadMoveResponse
Example
use Google\ApiCore\ApiException;
use Google\Cloud\AssuredWorkloads\V1beta1\AnalyzeWorkloadMoveResponse;
use Google\Cloud\AssuredWorkloads\V1beta1\AssuredWorkloadsServiceClient;

/**
 * @param string $target The resource ID of the folder-based destination workload. This workload is
 *                       where the source project will hypothetically be moved to. Specify the
 *                       workload's relative resource name, formatted as:
 *                       "organizations/{ORGANIZATION_ID}/locations/{LOCATION_ID}/workloads/{WORKLOAD_ID}"
 *                       For example:
 *                       "organizations/123/locations/us-east1/workloads/assured-workload-2"
 */
function analyze_workload_move_sample(string $target): void
{
    // Create a client.
    $assuredWorkloadsServiceClient = new AssuredWorkloadsServiceClient();

    // Call the API and handle any network failures.
    try {
        /** @var AnalyzeWorkloadMoveResponse $response */
        $response = $assuredWorkloadsServiceClient->analyzeWorkloadMove($target);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * 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
{
    $target = '[TARGET]';

    analyze_workload_move_sample($target);
}

createWorkload

Creates Assured Workload.

Parameters
NameDescription
parent string

Required. The resource name of the new Workload's parent. Must be of the form organizations/{org_id}/locations/{location_id}.

workload Google\Cloud\AssuredWorkloads\V1beta1\Workload

Required. Assured Workload to create

optionalArgs array

Optional.

↳ externalId string

Optional. A identifier associated with the workload and underlying projects which allows for the break down of billing costs for a workload. The value provided for the identifier will add a label to the workload and contained projects with the identifier as the value.

↳ retrySettings 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
TypeDescription
Google\ApiCore\OperationResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\AssuredWorkloads\V1beta1\AssuredWorkloadsServiceClient;
use Google\Cloud\AssuredWorkloads\V1beta1\Workload;
use Google\Cloud\AssuredWorkloads\V1beta1\Workload\ComplianceRegime;
use Google\Rpc\Status;

/**
 * @param string $formattedParent          The resource name of the new Workload's parent.
 *                                         Must be of the form `organizations/{org_id}/locations/{location_id}`. Please see
 *                                         {@see AssuredWorkloadsServiceClient::locationName()} for help formatting this field.
 * @param string $workloadDisplayName      The user-assigned display name of the Workload.
 *                                         When present it must be between 4 to 30 characters.
 *                                         Allowed characters are: lowercase and uppercase letters, numbers,
 *                                         hyphen, and spaces.
 *
 *                                         Example: My Workload
 * @param int    $workloadComplianceRegime Immutable. Compliance Regime associated with this workload.
 */
function create_workload_sample(
    string $formattedParent,
    string $workloadDisplayName,
    int $workloadComplianceRegime
): void {
    // Create a client.
    $assuredWorkloadsServiceClient = new AssuredWorkloadsServiceClient();

    // Prepare any non-scalar elements to be passed along with the request.
    $workload = (new Workload())
        ->setDisplayName($workloadDisplayName)
        ->setComplianceRegime($workloadComplianceRegime);

    // Call the API and handle any network failures.
    try {
        /** @var OperationResponse $response */
        $response = $assuredWorkloadsServiceClient->createWorkload($formattedParent, $workload);
        $response->pollUntilComplete();

        if ($response->operationSucceeded()) {
            /** @var Workload $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());
    }
}

/**
 * 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 = AssuredWorkloadsServiceClient::locationName('[ORGANIZATION]', '[LOCATION]');
    $workloadDisplayName = '[DISPLAY_NAME]';
    $workloadComplianceRegime = ComplianceRegime::COMPLIANCE_REGIME_UNSPECIFIED;

    create_workload_sample($formattedParent, $workloadDisplayName, $workloadComplianceRegime);
}

deleteWorkload

Deletes the workload. Make sure that workload's direct children are already in a deleted state, otherwise the request will fail with a FAILED_PRECONDITION error.

In addition to assuredworkloads.workload.delete permission, the user should also have orgpolicy.policy.set permission on the deleted folder to remove Assured Workloads OrgPolicies.

Parameters
NameDescription
name string

Required. The name field is used to identify the workload. Format: organizations/{org_id}/locations/{location_id}/workloads/{workload_id}

optionalArgs array

Optional.

↳ etag string

Optional. The etag of the workload. If this is provided, it must match the server's etag.

↳ retrySettings 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.

Example
use Google\ApiCore\ApiException;
use Google\Cloud\AssuredWorkloads\V1beta1\AssuredWorkloadsServiceClient;

/**
 * @param string $formattedName The `name` field is used to identify the workload.
 *                              Format:
 *                              organizations/{org_id}/locations/{location_id}/workloads/{workload_id}
 *                              Please see {@see AssuredWorkloadsServiceClient::workloadName()} for help formatting this field.
 */
function delete_workload_sample(string $formattedName): void
{
    // Create a client.
    $assuredWorkloadsServiceClient = new AssuredWorkloadsServiceClient();

    // Call the API and handle any network failures.
    try {
        $assuredWorkloadsServiceClient->deleteWorkload($formattedName);
        printf('Call completed successfully.' . PHP_EOL);
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * 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 = AssuredWorkloadsServiceClient::workloadName(
        '[ORGANIZATION]',
        '[LOCATION]',
        '[WORKLOAD]'
    );

    delete_workload_sample($formattedName);
}

getWorkload

Gets Assured Workload associated with a CRM Node

Parameters
NameDescription
name string

Required. The resource name of the Workload to fetch. This is the workloads's relative path in the API, formatted as "organizations/{organization_id}/locations/{location_id}/workloads/{workload_id}". For example, "organizations/123/locations/us-east1/workloads/assured-workload-1".

optionalArgs array

Optional.

↳ retrySettings 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
TypeDescription
Google\Cloud\AssuredWorkloads\V1beta1\Workload
Example
use Google\ApiCore\ApiException;
use Google\Cloud\AssuredWorkloads\V1beta1\AssuredWorkloadsServiceClient;
use Google\Cloud\AssuredWorkloads\V1beta1\Workload;

/**
 * @param string $formattedName The resource name of the Workload to fetch. This is the workloads's
 *                              relative path in the API, formatted as
 *                              "organizations/{organization_id}/locations/{location_id}/workloads/{workload_id}".
 *                              For example,
 *                              "organizations/123/locations/us-east1/workloads/assured-workload-1". Please see
 *                              {@see AssuredWorkloadsServiceClient::workloadName()} for help formatting this field.
 */
function get_workload_sample(string $formattedName): void
{
    // Create a client.
    $assuredWorkloadsServiceClient = new AssuredWorkloadsServiceClient();

    // Call the API and handle any network failures.
    try {
        /** @var Workload $response */
        $response = $assuredWorkloadsServiceClient->getWorkload($formattedName);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * 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 = AssuredWorkloadsServiceClient::workloadName(
        '[ORGANIZATION]',
        '[LOCATION]',
        '[WORKLOAD]'
    );

    get_workload_sample($formattedName);
}

listWorkloads

Lists Assured Workloads under a CRM Node.

Parameters
NameDescription
parent string

Required. Parent Resource to list workloads from. Must be of the form organizations/{org_id}/locations/{location}.

optionalArgs array

Optional.

↳ pageSize int

The maximum number of resources contained in the underlying API response. The API may return fewer values in a page, even if there are additional values to be retrieved.

↳ pageToken string

A page token is used to specify a page of values to be returned. If no page token is specified (the default), the first page of values will be returned. Any page token used here must have been generated by a previous call to the API.

↳ filter string

A custom filter for filtering by properties of a workload. At this time, only filtering by labels is supported.

↳ retrySettings 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
TypeDescription
Google\ApiCore\PagedListResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\AssuredWorkloads\V1beta1\AssuredWorkloadsServiceClient;
use Google\Cloud\AssuredWorkloads\V1beta1\Workload;

/**
 * @param string $formattedParent Parent Resource to list workloads from.
 *                                Must be of the form `organizations/{org_id}/locations/{location}`. Please see
 *                                {@see AssuredWorkloadsServiceClient::locationName()} for help formatting this field.
 */
function list_workloads_sample(string $formattedParent): void
{
    // Create a client.
    $assuredWorkloadsServiceClient = new AssuredWorkloadsServiceClient();

    // Call the API and handle any network failures.
    try {
        /** @var PagedListResponse $response */
        $response = $assuredWorkloadsServiceClient->listWorkloads($formattedParent);

        /** @var Workload $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());
    }
}

/**
 * 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 = AssuredWorkloadsServiceClient::locationName('[ORGANIZATION]', '[LOCATION]');

    list_workloads_sample($formattedParent);
}

restrictAllowedResources

Restrict the list of resources allowed in the Workload environment.

The current list of allowed products can be found at https://cloud.google.com/assured-workloads/docs/supported-products In addition to assuredworkloads.workload.update permission, the user should also have orgpolicy.policy.set permission on the folder resource to use this functionality.

Parameters
NameDescription
name string

Required. The resource name of the Workload. This is the workloads's relative path in the API, formatted as "organizations/{organization_id}/locations/{location_id}/workloads/{workload_id}". For example, "organizations/123/locations/us-east1/workloads/assured-workload-1".

restrictionType int

Required. The type of restriction for using gcp products in the Workload environment. For allowed values, use constants defined on {@see \Google\Cloud\AssuredWorkloads\V1beta1\RestrictAllowedResourcesRequest\RestrictionType}

optionalArgs array

Optional.

↳ retrySettings 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
TypeDescription
Google\Cloud\AssuredWorkloads\V1beta1\RestrictAllowedResourcesResponse
Example
use Google\ApiCore\ApiException;
use Google\Cloud\AssuredWorkloads\V1beta1\AssuredWorkloadsServiceClient;
use Google\Cloud\AssuredWorkloads\V1beta1\RestrictAllowedResourcesRequest\RestrictionType;
use Google\Cloud\AssuredWorkloads\V1beta1\RestrictAllowedResourcesResponse;

/**
 * @param string $name            The resource name of the Workload. This is the workloads's
 *                                relative path in the API, formatted as
 *                                "organizations/{organization_id}/locations/{location_id}/workloads/{workload_id}".
 *                                For example,
 *                                "organizations/123/locations/us-east1/workloads/assured-workload-1".
 * @param int    $restrictionType The type of restriction for using gcp products in the Workload environment.
 */
function restrict_allowed_resources_sample(string $name, int $restrictionType): void
{
    // Create a client.
    $assuredWorkloadsServiceClient = new AssuredWorkloadsServiceClient();

    // Call the API and handle any network failures.
    try {
        /** @var RestrictAllowedResourcesResponse $response */
        $response = $assuredWorkloadsServiceClient->restrictAllowedResources($name, $restrictionType);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * 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
{
    $name = '[NAME]';
    $restrictionType = RestrictionType::RESTRICTION_TYPE_UNSPECIFIED;

    restrict_allowed_resources_sample($name, $restrictionType);
}

updateWorkload

Updates an existing workload.

Currently allows updating of workload display_name and labels. For force updates don't set etag field in the Workload. Only one update operation per workload can be in progress.

Parameters
NameDescription
workload Google\Cloud\AssuredWorkloads\V1beta1\Workload

Required. The workload to update. The workload's name field is used to identify the workload to be updated. Format: organizations/{org_id}/locations/{location_id}/workloads/{workload_id}

updateMask Google\Protobuf\FieldMask

Required. The list of fields to be updated.

optionalArgs array

Optional.

↳ retrySettings 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
TypeDescription
Google\Cloud\AssuredWorkloads\V1beta1\Workload
Example
use Google\ApiCore\ApiException;
use Google\Cloud\AssuredWorkloads\V1beta1\AssuredWorkloadsServiceClient;
use Google\Cloud\AssuredWorkloads\V1beta1\Workload;
use Google\Cloud\AssuredWorkloads\V1beta1\Workload\ComplianceRegime;
use Google\Protobuf\FieldMask;

/**
 * @param string $workloadDisplayName      The user-assigned display name of the Workload.
 *                                         When present it must be between 4 to 30 characters.
 *                                         Allowed characters are: lowercase and uppercase letters, numbers,
 *                                         hyphen, and spaces.
 *
 *                                         Example: My Workload
 * @param int    $workloadComplianceRegime Immutable. Compliance Regime associated with this workload.
 */
function update_workload_sample(string $workloadDisplayName, int $workloadComplianceRegime): void
{
    // Create a client.
    $assuredWorkloadsServiceClient = new AssuredWorkloadsServiceClient();

    // Prepare any non-scalar elements to be passed along with the request.
    $workload = (new Workload())
        ->setDisplayName($workloadDisplayName)
        ->setComplianceRegime($workloadComplianceRegime);
    $updateMask = new FieldMask();

    // Call the API and handle any network failures.
    try {
        /** @var Workload $response */
        $response = $assuredWorkloadsServiceClient->updateWorkload($workload, $updateMask);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * 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
{
    $workloadDisplayName = '[DISPLAY_NAME]';
    $workloadComplianceRegime = ComplianceRegime::COMPLIANCE_REGIME_UNSPECIFIED;

    update_workload_sample($workloadDisplayName, $workloadComplianceRegime);
}

Constants

SERVICE_NAME

Value: 'google.cloud.assuredworkloads.v1beta1.AssuredWorkloadsService'

The name of the service.

SERVICE_ADDRESS

Value: 'assuredworkloads.googleapis.com'

The default address of the service.

DEFAULT_SERVICE_PORT

Value: 443

The default port of the service.

CODEGEN_NAME

Value: 'gapic'

The name of the code generator, to be included in the agent header.