google.cloud.forseti.common.gcp_api.api_helpers module

Helper functions for API clients.

flatten_aggregated_list_results(paged_results, item_key)[source]

Flatten a split-up list as returned by GCE “aggregatedList” API.

The compute API’s aggregatedList methods return a structure in the form:

{
items: {
$group_value_1: {
$item_key: [$items]

}, $group_value_2: {

$item_key: [$items]

}, $group_value_3: {

“warning”: {
message: “There are no results for …”

}

}, …, $group_value_n, {

$item_key: [$items]

},

}

}

where each “$group_value_n” is a particular element in the aggregation, e.g. a particular zone or group or whatever, and “$item_key” is some type-specific resource name, e.g. “backendServices” for an aggregated list of backend services.

This method takes such a structure and yields a simple list of all $items across all of the groups.

Parameters:
  • paged_results (list) – A list of paged API response objects. [{page 1 results}, {page 2 results}, {page 3 results}, …]
  • item_key (str) – The name of the key within the inner “items” lists containing the objects of interest.
Returns:

A list of items.

Return type:

list

flatten_list_results(paged_results, item_key)[source]

Flatten a split-up list as returned by list_next() API.

GCE ‘list’ APIs return results in the form:
{item_key: […]}

with one dictionary for each “page” of results. This method flattens that to a simple list of items.

Parameters:
  • paged_results (list) – A list of paged API response objects. [{page 1 results}, {page 2 results}, {page 3 results}, …]
  • item_key (str) – The name of the key within the inner “items” lists containing the objects of interest.
Returns:

A list of items.

Return type:

list

get_delegated_credential(delegated_account, scopes)[source]

Build delegated credentials required for accessing the gsuite APIs.

Parameters:
  • delegated_account (str) – The account to delegate the service account to use.
  • scopes (list) – The list of required scopes for the service account.
Returns:

Credentials as built by google.oauth2.service_account.

Return type:

service_account.Credentials

get_ratelimiter_config(global_configs, api_name)[source]

Get rate limiter configuration.

Parameters:
  • global_configs (dict) – Global configurations.
  • api_name (String) – The name of the api.
Returns:

Max calls float: quota period)

Return type:

float