def fdm_create_network(
        network_object,
        access_token,
        host=FDM.get("host"),
        port=FDM.get("port"),
        api_version=FDM.get("api_version"),
):
    """Create a new network in FDM."""
    print(blue("\n==> Creating a new network in FDM"))

    headers = {
        "Content-Type": "application/json",
        "Accept": "application/json",
        "Authorization": f"Bearer {access_token}",
    }

    payload = network_object

    response = requests.post(
        f"https://{host}:{port}/api/fdm/v{api_version}/object/networks",
        headers=headers,
        json=payload,
        verify=False,
    )
    response.raise_for_status()

    print(green("Successfully created the new network!"))
    return response.json()
Exemple #2
0
def get_spec_json(host=FDM.get("host"),
    port=FDM.get("port"),
    username=FDM.get("username"),
    password=FDM.get("password"),):
    http_client = RequestsClient()
    http_client.session.verify = False
    http_client.session.headers = headers
    url = f"https://{host}:{port}/apispec/ngfw.json"
    client = SwaggerClient.from_url(url, http_client=http_client, config={'validate_responses':False})
    return client
Exemple #3
0
def fdm_login(
    host=FDM.get("host"),
    port=FDM.get("port"),
    username=FDM.get("username"),
    password=FDM.get("password"),
    api_version=FDM.get("api_version"),
):
    """Login to FDM and return an access token that may be used for API calls.

    This login will give you an access token that is valid for ~30 minutes
    with no refresh. Using this token should be fine for short running scripts.

    Do not use for services that need to last longer than 30 minutes.
    """
    print(blue("\n==> Logging into FDM and requesting an access token"))

    headers = {
        "Content-Type": "application/json",
        "Accept": "application/json",
    }

    payload = {
        "grant_type": "password",
        "username": username,
        "password": password,
    }

    response = requests.post(
        f"https://{host}:{port}/api/fdm/v{api_version}/fdm/token",
        headers=headers,
        json=payload,
        verify=False,
    )

    try:
        response.raise_for_status()
        access_token = response.json()["access_token"]

    except HTTPError:
        if response.status_code == 400:
            raise HTTPError(f"Error logging in to FDM: {response.text}")
        else:
            raise

    except ValueError:
        raise ValueError("Error parsing the response from FDM")

    print(
        green("Login was successful!"),
        f"Access Token: {access_token}",
        sep="\n"
    )

    return access_token
Exemple #4
0
def login(host=FDM.get("host"),
    port=FDM.get("port"),
    username=FDM.get("username"),
    password=FDM.get("password"), ):

    payload = {
        "grant_type": "password",
        "username": username,
        "password": password,
    }
    #mission TODO: Complete the URL to get FDM oAuth token Here is starting string "https://{host}:{port}/api/fdm/v{api_version}"
    env_lab.print_missing_mission_warn(env_lab.get_line())

    r = requests.post(url, json=payload, verify=False, headers=headers)
    access_token = "Bearer %s" % r.json()['access_token']
    headers['Authorization'] = access_token
Exemple #5
0
def login(
        host=FDM.get("host"),
        port=FDM.get("port"),
        username=FDM.get("username"),
        password=FDM.get("password"),
):

    payload = {
        "grant_type": "password",
        "username": username,
        "password": password,
    }
    url = f"https://{host}:{port}/api/fdm/v{api_version}/fdm/token"
    print(url)
    print(payload)
    r = requests.post(url, json=payload, verify=False, headers=headers)
    print(r)
    access_token = "Bearer %s" % r.json()['access_token']
    headers['Authorization'] = access_token
Exemple #6
0
def fdm_login(
    host=FDM.get("host"),
    port=FDM.get("port"),
    username=FDM.get("username"),
    password=FDM.get("password"),
    api_version=FDM.get("api_version")
):
    """Login to FDM and return an access token that may be used for API calls.
    """
    print("\n==> Logging into FDM and requesting an access token")

    headers = {
        "Content-Type": "application/json",
        "Accept": "application/json",
    }

    payload = {
        "grant_type": "password",
        "username": username,
        "password": password,
    }

    response = requests.post(
        f"https://{host}:{port}/api/fdm/v{api_version}/fdm/token",
        headers=headers,
        json=payload,
        verify=False,
    )

    try:
        response.raise_for_status()
        access_token = response.json()["access_token"]

    except HTTPError:
        if response.status_code == 400:
            raise HTTPError(f"Error logging in to FDM: {response.text}")
        else:
            raise

    except ValueError:
        raise ValueError("Error parsing the response from FDM")

    return access_token
Exemple #7
0
def fdm_get_networks(
        access_token,
        host=FDM.get("host"),
        port=FDM.get("port"),
        api_version=FDM.get("api_version"),
):
    """Get the list of all Networks in FDM."""
    print(blue("\n==> Getting a list of all Networks in FDM"))

    headers = {
        "Content-Type": "application/json",
        "Accept": "application/json",
        "Authorization": f"Bearer {access_token}",
    }

    response = requests.get(
        f"https://{host}:{port}/api/fdm/v{api_version}/object/networks",
        headers=headers,
        verify=False,
    )
    response.raise_for_status()

    print(green("Successfully retrieved the list of Networks"))
    return response.json()
Exemple #8
0
from env_lab import FDM
from env_user import WEBEX_TEAMS_ACCESS_TOKEN
from env_user import WEBEX_TEAMS_ROOM_ID
pathf = Path(__file__).parent.absolute()
fdmfolder = (pathf / ".." / "fdm").resolve()

# Disable insecure request warnings
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

headers = {
    "Content-Type": "application/json",
    "Accept": "application/json",
    "Authorization": "Bearer "
}

api_version = FDM.get("api_version")

#mission TODO: Enter the FTD hostname/ip here... (TIP: dont't forget to use HTTPS + the IP)


def login(
        host=FDM.get("host"),
        port=FDM.get("port"),
        username=FDM.get("username"),
        password=FDM.get("password"),
):

    payload = {
        "grant_type": "password",
        "username": username,
        "password": password,