Exemple #1
0
def get_request_network(value):
    """Return parsed data from API of object type 'service'"""
    network_data = []
    base_urls = gen_network_urls()
    
    for url in base_urls:
        network_url = '{}/{}'.format(url, value)
        result = common_bits.get_request(network_url, common_bits.headers, common_bits.payload)

        if result.status_code == 200:
            network = result.json()
            network_type = network['_type']

            data = {
                    "type":network_type,
                    "data":network
            }
            network_data.append(data)
            break

    result = parser(network_data)

    final_result = []
    common_bits.removeNestedLists(result, final_result)

    return final_result
Exemple #2
0
def get_nat_rules():
    """Returns list object of all nat rules via REST API."""
    url = '{}/packetfilter/nat'.format(common_bits.base_url)
    result = common_bits.get_request(url, common_bits.headers,
                                     common_bits.payload)

    return result.json()
def service_group(sg):
    """Return data from /service/group object."""
    service_type = sg['type']
    members = sg['data']['members']
    service_urls = gen_service_urls()
    service_data = []
    for member in members:
        for url in service_urls:
            service_url = '{}/{}'.format(url, member)
            result = common_bits.get_request(service_url, common_bits.headers,
                                             common_bits.payload)
            if result.status_code == 200:
                service = result.json()
                service_type = service['_type']
                data = {"type": service_type, "data": service}
                service_data.append(data)
    result = parser(service_data)
    return result
Exemple #4
0
def network_group(ng):
    """Return data from /network/group object."""
    network_type = ng['type']
    members = ng['data']['members']
    network_urls = gen_network_urls()
    network_data = []
    for member in members:
        for url in network_urls:
            network_url = '{}/{}'.format(url,member)
            result = common_bits.get_request(network_url, common_bits.headers, common_bits.payload)
            if result.status_code == 200:
                network = result.json()
                network_type = network['_type']
                data = {
                        "type":network_type,
                        "data":network
                }
                network_data.append(data)
    result = parser(network_data)
    return result