350-201 Question 241
Select 4You are tasked with analyzing a Python script used to automate the addition of IP addresses to a firewall rule using the Cisco Firepower Management Center (FMC) API. Below is a snippet of the script:
import requests
def add_ip_to_firewall(ip_address, api_url, token):
headers = {
'Content-Type': 'application/json',
'Authorization': f'Bearer {token}'
}
payload = {
'ip': ip_address
}
response = requests.post(f'{api_url}/add_ip', headers=headers, json=payload)
if response.status_code == 200:
return "Success"
else:
return f"Error: {response.status_code}"
ip = "192.168.1.100"
api_endpoint = "https://fmc-server/api"
api_token = "abcd1234"
result = add_ip_to_firewall(ip, api_endpoint, api_token)
print(result)
After reviewing the script, which of the following statements are correct about its functionality?
- A
The script uses an HTTP POST request to add an IP address to the firewall.
- B
The 'Authorization' header is dynamically generated using the provided API token.
- C
The script will fail if the API token is invalid or expired.
- D
The script uses the GET method to retrieve the list of IP addresses from the firewall.
- E
The API endpoint in the script is hardcoded and not dynamically derived.
Show answer and explanation
Correct answers: A, B, C, E
Explanation
The script demonstrates the use of Python and the requests library to interact with the Cisco FMC API. It uses an HTTP POST request to add an IP address to the firewall. The 'Authorization' header and the payload are dynamically generated based on the provided arguments, but the API endpoint is hardcoded. If the token is invalid or expired, the operation will fail, which aligns with how most APIs handle authentication.
- A. Correct.
Correct. The
requests.postmethod is used, indicating an HTTP POST request is being made to the API. - B. Correct.
Correct. The 'Authorization' header is constructed dynamically using the token provided as a function argument.
- C. Correct.
Correct. If the API token is invalid or expired, the request will fail, likely returning an error status code other than 200.
- D. Incorrect.
Incorrect. The script does not use the GET method; it explicitly uses POST to add an IP address.
- E. Correct.
Correct. The API endpoint is hardcoded in the variable
api_endpointand is not dynamically derived.