Skip to content
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
3 changes: 3 additions & 0 deletions WHATSNEW.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
### Added

- Add more examples on how to use imported fotoobo
- Add typing information for fotoobo so that mypy is able to check types when importing fotoobo

### Changed

### Removed
Expand Down
2 changes: 1 addition & 1 deletion docs/source/usage/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Logging

NOTE: The settings here apply the same to normal logging and audit logging.

If you configure a logging setting it is automatically enabled. Otherwise defaut logging will be
If you configure a logging setting it is automatically enabled. Otherwise default logging will be
used. Default logging is set to log to **console** with log-level **WARNING**.

.. _logging_level:
Expand Down
64 changes: 64 additions & 0 deletions docs/source/usage/import_fotoobo.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,67 @@ FortiClient EMS
print(ems.get_version())
ems.logout()

Using an inventory file
^^^^^^^^^^^^^^^^^^^^^^^

You can maintain an :ref:`inventory file<usage_inventory>` to load the assets from. This helps not having API tokens or username/passwords directly in the source code.

Imagine you created the inventory file ``~/.config/inventory.yaml``:

.. code-block:: yaml

fmg-test:
hostname: myfortimanager.local
username: the_fortimanager_username
password: the_fortimanager_password
type: fortimanager

With this inventory file you can use the asset ```fmg-test`` in your code:

.. code-block:: python

from fotoobo.inventory import Inventory
inventory = Inventory(Path("~/.config/inventory.yaml"))
fmg = inventory.get_item("fmg-test")
print(fmg.get_version())


Using a configuration file
^^^^^^^^^^^^^^^^^^^^^^^^^^

You can read your fotoobo :ref:`configuration file<usage_configuration>`. This is useful if you wish to load and change settings like :ref:`inventory file<usage_inventory>`, :ref:`logging options<logging>` or a :ref:`vault configuration<vault_service>`.

Use the inventory file ``~/.config/inventory.yaml`` with the string ``VAULT`` as the token or password for your assets.

.. code-block:: yaml

fmg-test:
hostname: myfortimanager.local
username: the_fortimanager_username
password: VAULT
type: fortimanager

Then you have to specify this inventory file and the vault configuration in the fotoobo configuration file ``~/.config/fotoobo.yaml``.

.. code-block:: yaml

inventory: ~/.config/inventory.yaml
vault:
url: https://vault.local
namespace: vault_namespace
data_path: /v1/kv/data/fotoobo
role_id: ...
secret_id: ...
token_file: ~/.cache/token.key

With these preparations you can use the fotoobo configuration to access your assets.

.. code-block:: python

from fotoobo.helpers.config import config
from fotoobo.inventory import Inventory
config.load_configuration()
config.vault["ssl_verify"] = False
inventory = Inventory(config.inventory_file)
fmg = inventory.get_item("fmg-test")
print(fmg.get_version())
2 changes: 1 addition & 1 deletion fotoobo/fortinet/forticlientems.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def api( # pylint: disable=too-many-arguments, too-many-positional-arguments
params: dict[str, str] | None = None,
payload: dict[str, Any] | None = None,
timeout: float | None = None,
) -> requests.models.Response:
) -> requests.Response:
"""
API request to a FortiClientEMS device.

Expand Down
2 changes: 1 addition & 1 deletion fotoobo/fortinet/forticloudasset.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def api( # pylint: disable=too-many-arguments, too-many-positional-arguments
params: dict[str, str] | None = None,
payload: dict[str, Any] | None = None,
timeout: float | None = None,
) -> requests.models.Response:
) -> requests.Response:
"""
API request to a FortiManager device.

Expand Down
2 changes: 1 addition & 1 deletion fotoobo/fortinet/fortigate.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def api( # pylint: disable=too-many-arguments, too-many-positional-arguments
params: dict[str, str] | None = None,
payload: dict[str, Any] | None = None,
timeout: float | None = None,
) -> requests.models.Response:
) -> requests.Response:
"""Native API request to a FortiGate.

It uses the super.api method but it has to enrich the payload in post requests with the
Expand Down
7 changes: 3 additions & 4 deletions fotoobo/fortinet/fortimanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def __init__(self, hostname: str, username: str, password: str, **kwargs: Any) -
"rootp",
]

def api_delete(self, url: str) -> requests.models.Response:
def api_delete(self, url: str) -> requests.Response:
"""DELETE method for API requests

Args:
Expand All @@ -85,7 +85,7 @@ def api_delete(self, url: str) -> requests.models.Response:

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

Args:
Expand Down Expand Up @@ -114,7 +114,7 @@ def api( # pylint: disable=too-many-arguments, too-many-positional-arguments
params: dict[str, str] | None = None,
payload: dict[str, Any] | None = None,
timeout: float | None = None,
) -> requests.models.Response:
) -> requests.Response:
"""
API request to a FortiManager device.

Expand Down Expand Up @@ -818,7 +818,6 @@ def login(self) -> int:
response = super().api("post", payload=payload)
if response.status_code == 200:
if "session" in response.json():
log.debug("Storing session key")
self.session_key = response.json()["session"]

if self.session_path:
Expand Down
2 changes: 1 addition & 1 deletion fotoobo/fortinet/fortinet.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def api( # pylint: disable=too-many-arguments, too-many-positional-arguments
params: dict[str, str] | None = None,
payload: dict[str, Any] | None = None,
timeout: float | None = None,
) -> requests.models.Response:
) -> requests.Response:
"""
API request to a Fortinet device.

Expand Down
Empty file added fotoobo/py.typed
Empty file.
8 changes: 4 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ disallow_untyped_decorators=false
[tool.pytest.ini_options]
addopts = "--basetemp=tests/temp/"


# here we define the tox settings
# we do it inline because we don't want to have another tox.ini in the project root
# package management is done as described in option 3 on the following FAQ
Expand Down