Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade dependencies #232

Merged
merged 4 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions WHATSNEW.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@

### Changed

- Fix some typing issues for Python3.8
- Optimize imports in CLI module
- Upgrade requests, jinja and pygount due to security issues and bugs

### Removed

6 changes: 3 additions & 3 deletions fotoobo/fortinet/fortigate.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""

import logging
from typing import Any, Dict, Optional
from typing import Any, Dict, List, Optional

import requests

Expand Down Expand Up @@ -70,7 +70,7 @@ def api( # pylint: disable=too-many-arguments
method, url, payload=payload, params=params, timeout=timeout, headers=headers
)

def api_get(self, url: str, vdom: str = "*", timeout: Optional[float] = None) -> list[Any]:
def api_get(self, url: str, vdom: str = "*", timeout: Optional[float] = None) -> List[Any]:
"""Low level GET request to a FortiGate.

This gets the response from a single API request to a FortiGate and returns it as a fotoobo
Expand All @@ -86,7 +86,7 @@ def api_get(self, url: str, vdom: str = "*", timeout: Optional[float] = None) ->
"""
params = {"vdom": vdom}
response = self.api(method="get", url=url, params=params, timeout=timeout)
data: list[Any] = (
data: List[Any] = (
[response.json()] if isinstance(response.json(), dict) else response.json()
) # this is to listify the data from the response

Expand Down
70 changes: 35 additions & 35 deletions fotoobo/fortinet/fortimanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def api_delete(self, url: str) -> requests.models.Response:
return self.api("post", payload=payload)

def api_get(
self, url: str, params: Optional[dict[str, Any]] = None, timeout: Optional[float] = None
self, url: str, params: Optional[Dict[str, Any]] = None, timeout: Optional[float] = None
) -> requests.models.Response:
"""GET method for API requests

Expand Down Expand Up @@ -193,7 +193,7 @@ def assign_all_objects(self, adoms: str, policy: str) -> int:

return task_id

def delete_adom_address(self, adom: str, address: str, dry: bool = False) -> dict[str, Any]:
def delete_adom_address(self, adom: str, address: str, dry: bool = False) -> Dict[str, Any]:
"""
Delete an address from an ADOM in FortiManager

Expand All @@ -205,7 +205,7 @@ def delete_adom_address(self, adom: str, address: str, dry: bool = False) -> dic
Returns:
FortiManager result item
"""
result: dict[str, Any] = {}
result: Dict[str, Any] = {}
if not dry:
url: str = f"/pm/config/adom/{adom}/obj/firewall/address/{address}"
result = self.api_delete(url).json()["result"][0]
Expand All @@ -215,7 +215,7 @@ def delete_adom_address(self, adom: str, address: str, dry: bool = False) -> dic

return result

def delete_adom_address_group(self, adom: str, group: str, dry: bool = False) -> dict[str, Any]:
def delete_adom_address_group(self, adom: str, group: str, dry: bool = False) -> Dict[str, Any]:
"""
Delete an address group from an ADOM in FortiManager

Expand All @@ -227,7 +227,7 @@ def delete_adom_address_group(self, adom: str, group: str, dry: bool = False) ->
Returns:
FortiManager result item
"""
result: dict[str, Any] = {}
result: Dict[str, Any] = {}
if not dry:
url: str = f"/pm/config/adom/{adom}/obj/firewall/addrgrp/{group}"
result = self.api_delete(url).json()["result"][0]
Expand All @@ -237,7 +237,7 @@ def delete_adom_address_group(self, adom: str, group: str, dry: bool = False) ->

return result

def delete_adom_service(self, adom: str, service: str, dry: bool = False) -> dict[str, Any]:
def delete_adom_service(self, adom: str, service: str, dry: bool = False) -> Dict[str, Any]:
"""
Delete a service from an ADOM in FortiManager

Expand All @@ -249,7 +249,7 @@ def delete_adom_service(self, adom: str, service: str, dry: bool = False) -> dic
Returns:
FortiManager result item
"""
result: dict[str, Any] = {}
result: Dict[str, Any] = {}
if not dry:
url: str = f"/pm/config/adom/{adom}/obj/firewall/service/custom/{service}"
result = self.api_delete(url).json()["result"][0]
Expand All @@ -259,7 +259,7 @@ def delete_adom_service(self, adom: str, service: str, dry: bool = False) -> dic

return result

def delete_adom_service_group(self, adom: str, group: str, dry: bool = False) -> dict[str, Any]:
def delete_adom_service_group(self, adom: str, group: str, dry: bool = False) -> Dict[str, Any]:
"""
Delete a service group from an ADOM in FortiManager

Expand All @@ -271,7 +271,7 @@ def delete_adom_service_group(self, adom: str, group: str, dry: bool = False) ->
Returns:
FortiManager result item
"""
result: dict[str, Any] = {}
result: Dict[str, Any] = {}
if not dry:
url: str = f"/pm/config/adom/{adom}/obj/firewall/service/group/{group}"
result = self.api_delete(url).json()["result"][0]
Expand All @@ -281,7 +281,7 @@ def delete_adom_service_group(self, adom: str, group: str, dry: bool = False) ->

return result

def delete_global_address(self, address: str, dry: bool = False) -> dict[str, Any]:
def delete_global_address(self, address: str, dry: bool = False) -> Dict[str, Any]:
"""
Delete a global address from FortiManager

Expand All @@ -306,7 +306,7 @@ def delete_global_address(self, address: str, dry: bool = False) -> dict[str, An
Returns:
FortiManager result item
"""
result: dict[str, Any] = {}
result: Dict[str, Any] = {}

# Get the address object with 'scope member' information
address_object = self.get_global_address(address, scope_member=True)
Expand Down Expand Up @@ -353,7 +353,7 @@ def delete_global_address(self, address: str, dry: bool = False) -> dict[str, An

return result

def delete_global_address_group(self, group: str, dry: bool = False) -> dict[str, Any]:
def delete_global_address_group(self, group: str, dry: bool = False) -> Dict[str, Any]:
"""
Delete a global address group from FortiManager

Expand All @@ -378,7 +378,7 @@ def delete_global_address_group(self, group: str, dry: bool = False) -> dict[str
Returns:
FortiManager result item
"""
result: dict[str, Any] = {}
result: Dict[str, Any] = {}

# Get the address group object with 'scope member' information
address_group_object = self.get_global_address_group(group, scope_member=True)
Expand Down Expand Up @@ -423,7 +423,7 @@ def delete_global_address_group(self, group: str, dry: bool = False) -> dict[str

return result

def delete_global_service(self, service: str, dry: bool = False) -> dict[str, Any]:
def delete_global_service(self, service: str, dry: bool = False) -> Dict[str, Any]:
"""
Delete a global service from FortiManager

Expand All @@ -448,7 +448,7 @@ def delete_global_service(self, service: str, dry: bool = False) -> dict[str, An
Returns:
FortiManager result item
"""
result: dict[str, Any] = {}
result: Dict[str, Any] = {}

# Get the service object with 'scope member' information
service_object = self.get_global_service(service, scope_member=True)
Expand Down Expand Up @@ -493,7 +493,7 @@ def delete_global_service(self, service: str, dry: bool = False) -> dict[str, An

return result

def delete_global_service_group(self, group: str, dry: bool = False) -> dict[str, Any]:
def delete_global_service_group(self, group: str, dry: bool = False) -> Dict[str, Any]:
"""
Delete a global service group from FortiManager

Expand All @@ -518,7 +518,7 @@ def delete_global_service_group(self, group: str, dry: bool = False) -> dict[str
Returns:
FortiManager result item
"""
result: dict[str, Any] = {}
result: Dict[str, Any] = {}

# Get the service group object with 'scope member' information
service_group_object = self.get_global_service_group(group, scope_member=True)
Expand Down Expand Up @@ -563,7 +563,7 @@ def delete_global_service_group(self, group: str, dry: bool = False) -> dict[str

return result

def get_adoms(self, ignored_adoms: Optional[List[str]] = None) -> list[Any]:
def get_adoms(self, ignored_adoms: Optional[List[str]] = None) -> List[Any]:
"""
Get FortiManager ADOM list

Expand All @@ -585,7 +585,7 @@ def get_adoms(self, ignored_adoms: Optional[List[str]] = None) -> list[Any]:

return fmg_adoms

def get_global_address(self, address: str, scope_member: bool = False) -> dict[str, Any]:
def get_global_address(self, address: str, scope_member: bool = False) -> Dict[str, Any]:
"""
Get an address object from global ADOM

Expand All @@ -596,7 +596,7 @@ def get_global_address(self, address: str, scope_member: bool = False) -> dict[s
Returns:
FortiManager result item
"""
result: dict[str, Any] = {}
result: Dict[str, Any] = {}
url: str = f"/pm/config/global/obj/firewall/address/{address}"

if scope_member:
Expand All @@ -610,21 +610,21 @@ def get_global_address(self, address: str, scope_member: bool = False) -> dict[s

return result

def get_global_addresses(self) -> dict[str, Any]:
def get_global_addresses(self) -> Dict[str, Any]:
"""
Get the global address database

Returns:
FortiManager result item
"""
result: dict[str, Any] = self.api_get(
result: Dict[str, Any] = self.api_get(
"/pm/config/global/obj/firewall/address",
timeout=10,
).json()["result"][0]

return result

def get_global_address_group(self, group: str, scope_member: bool = False) -> dict[str, Any]:
def get_global_address_group(self, group: str, scope_member: bool = False) -> Dict[str, Any]:
"""
Get an address group object from the global ADOM

Expand All @@ -635,7 +635,7 @@ def get_global_address_group(self, group: str, scope_member: bool = False) -> di
Returns:
FortiManager result item
"""
result: dict[str, Any] = {}
result: Dict[str, Any] = {}
url: str = f"/pm/config/global/obj/firewall/addrgrp/{group}"

if scope_member:
Expand All @@ -649,21 +649,21 @@ def get_global_address_group(self, group: str, scope_member: bool = False) -> di

return result

def get_global_address_groups(self) -> dict[str, Any]:
def get_global_address_groups(self) -> Dict[str, Any]:
"""
Get the global address group database

Returns:
FortiManager result item
"""
result: dict[str, Any] = self.api_get(
result: Dict[str, Any] = self.api_get(
"/pm/config/global/obj/firewall/addrgrp",
timeout=10,
).json()["result"][0]

return result

def get_global_service(self, service: str, scope_member: bool = False) -> dict[str, Any]:
def get_global_service(self, service: str, scope_member: bool = False) -> Dict[str, Any]:
"""
Get a service object from global ADOM

Expand All @@ -674,7 +674,7 @@ def get_global_service(self, service: str, scope_member: bool = False) -> dict[s
Returns:
FortiManager result item
"""
result: dict[str, Any] = {}
result: Dict[str, Any] = {}
url: str = f"/pm/config/global/obj/firewall/service/custom/{service}"

if scope_member:
Expand All @@ -688,21 +688,21 @@ def get_global_service(self, service: str, scope_member: bool = False) -> dict[s

return result

def get_global_services(self) -> dict[str, Any]:
def get_global_services(self) -> Dict[str, Any]:
"""
Get the global services database

Returns:
FortiManager result item
"""
result: dict[str, Any] = self.api_get(
result: Dict[str, Any] = self.api_get(
"/pm/config/global/obj/firewall/service/custom",
timeout=10,
).json()["result"][0]

return result

def get_global_service_group(self, group: str, scope_member: bool = False) -> dict[str, Any]:
def get_global_service_group(self, group: str, scope_member: bool = False) -> Dict[str, Any]:
"""
Get a service group object from the global ADOM

Expand All @@ -713,7 +713,7 @@ def get_global_service_group(self, group: str, scope_member: bool = False) -> di
Returns:
FortiManager result item
"""
result: dict[str, Any] = {}
result: Dict[str, Any] = {}
url: str = f"/pm/config/global/obj/firewall/service/group/{group}"

if scope_member:
Expand All @@ -727,14 +727,14 @@ def get_global_service_group(self, group: str, scope_member: bool = False) -> di

return result

def get_global_service_groups(self) -> dict[str, Any]:
def get_global_service_groups(self) -> Dict[str, Any]:
"""
Get the global network service group database

Returns:
FortiManager result item
"""
result: dict[str, Any] = self.api_get(
result: Dict[str, Any] = self.api_get(
"/pm/config/global/obj/firewall/service/group",
timeout=10,
).json()["result"][0]
Expand Down Expand Up @@ -859,7 +859,7 @@ def post(self, adom: str, payloads: Any) -> List[str]:
payloads: One payload (Dict) or a list of payloads (List of Dict)

Returns:
Amount of errors ocurred during the set command
Amount of errors occurred during the set command
"""
# if payload is a dict convert it to a list with one dict in it.
if isinstance(payloads, dict):
Expand Down
8 changes: 4 additions & 4 deletions fotoobo/tools/fgt/cmdb/firewall/address.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""FortiGate CMDB firewall address module"""

from pathlib import Path
from typing import Any
from typing import Any, Dict, List

from fotoobo.fortinet.fortigate import FortiGate
from fotoobo.helpers.config import config
Expand All @@ -11,14 +11,14 @@

def get_cmdb_firewall_address(
host: str, name: str, vdom: str, output_file: str
) -> Result[list[Any]]:
) -> Result[List[Any]]:
"""Get the firewall address object(s)

The FortiGate api endpoint is: /cmdb/firewall/address
"""
inventory = Inventory(config.inventory_file)
fgt: FortiGate = inventory.get_item(host, "fortigate")
result = Result[list[Any]]()
result = Result[List[Any]]()

address_list = fgt.api_get(url=f"/cmdb/firewall/address/{name}", vdom=vdom)
result.push_result(key=host, data=address_list)
Expand All @@ -32,7 +32,7 @@ def get_cmdb_firewall_address(
for vd in address_list:
for asset in vd["results"]:

data: dict[str, str] = {
data: Dict[str, str] = {
"name": asset["name"],
"vdom": vd["vdom"],
"type": asset["type"],
Expand Down
Loading
Loading