def _build_path_matchers(path_matcher_list, project_id):
    """
    Reformat services in path matchers list.

    Specifically, builds out URLs.

    :param path_matcher_list: The GCP project ID.
    :type path_matcher_list: ``list`` of ``dict``

    :param project_id: The GCP project ID.
    :type project_id:  ``str``

    :return: list suitable for submission to GCP
             UrlMap API Path Matchers list.
    :rtype ``list`` of ``dict``
    """
    url = ''
    if project_id:
        url = GCPUtils.build_googleapi_url(project_id)
    for pm in path_matcher_list:
        if 'defaultService' in pm:
            pm['defaultService'] = '%s/global/backendServices/%s' % (url,
                                                                     pm['defaultService'])
        if 'pathRules' in pm:
            for rule in pm['pathRules']:
                if 'service' in rule:
                    rule['service'] = '%s/global/backendServices/%s' % (url,
                                                                        rule['service'])
    return path_matcher_list
def _build_global_forwarding_rule_dict(params, project_id=None):
    """
    Reformat services in Ansible Params.

    :param params: Params from AnsibleModule object
    :type params: ``dict``

    :param project_id: The GCP project ID.
    :type project_id:  ``str``

    :return: dictionary suitable for submission to GCP API.
    :rtype ``dict``
    """
    url = ''
    if project_id:
        url = GCPUtils.build_googleapi_url(project_id)
    gcp_dict = GCPUtils.params_to_gcp_dict(params, 'forwarding_rule_name')
    if 'target' in gcp_dict:
        gcp_dict['target'] = '%s/global/targetHttpProxies/%s' % (
            url, gcp_dict['target'])
    if 'address' in gcp_dict:
        gcp_dict['IPAddress'] = '%s/global/addresses/%s' % (
            url, gcp_dict['address'])
        del gcp_dict['address']
    if 'protocol' in gcp_dict:
        gcp_dict['IPProtocol'] = gcp_dict['protocol']
        del gcp_dict['protocol']
    return gcp_dict
def _build_url_map_dict(params, project_id=None):
    """
    Reformat services in Ansible Params.

    :param params: Params from AnsibleModule object
    :type params: ``dict``

    :param project_id: The GCP project ID.
    :type project_id:  ``str``

    :return: dictionary suitable for submission to GCP UrlMap API.
    :rtype ``dict``
    """
    url = ''
    if project_id:
        url = GCPUtils.build_googleapi_url(project_id)
    gcp_dict = GCPUtils.params_to_gcp_dict(params, 'url_map_name')
    if 'defaultService' in gcp_dict:
        gcp_dict['defaultService'] = '%s/global/backendServices/%s' % (url,
                                                                       gcp_dict['defaultService'])
    if 'pathMatchers' in gcp_dict:
        gcp_dict['pathMatchers'] = _build_path_matchers(gcp_dict['pathMatchers'], project_id)

    return gcp_dict