-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #226 from patrikspiess/Add-CLI-commands-to-get-con…
…figuration-from-FortiGate-#225 Add cli commands to get configuration from FortiGate #225
- Loading branch information
Showing
48 changed files
with
1,093 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,16 @@ | ||
### Added | ||
|
||
- Add generic api_get() method in tools/fgt/get | ||
- Add CLI command fgt get cmdb firewall address | ||
- Add CLI command fgt get cmdb firewall addrgrp | ||
- Add CLI command fgt get cmdb firewall service-custom | ||
- Add CLI command fgt get cmdb firewall service-group | ||
- Add the layers of fotoobo into the architecture documentation | ||
|
||
|
||
### Changed | ||
|
||
- Optimize imports in CLI module | ||
|
||
### Removed | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
""" | ||
__init__.py | ||
""" | ||
|
||
from . import ems, get, monitor | ||
|
||
__all__ = ["ems", "get", "monitor"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
""" | ||
__init__.py | ||
""" | ||
|
||
from . import faz | ||
|
||
__all__ = ["faz"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
""" | ||
__init__.py | ||
""" | ||
|
||
from . import fgt | ||
|
||
__all__ = ["fgt"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
""" | ||
__init__.py | ||
""" | ||
|
||
from . import get | ||
|
||
__all__ = ["get"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
""" | ||
__init__.py | ||
""" | ||
|
||
from . import cmdb | ||
|
||
__all__ = ["cmdb"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
""" | ||
The FortiGate commands | ||
""" | ||
|
||
import logging | ||
|
||
import typer | ||
|
||
from fotoobo.helpers import cli_path | ||
|
||
from .firewall import firewall | ||
|
||
app = typer.Typer(no_args_is_help=True, rich_markup_mode="rich") | ||
log = logging.getLogger("fotoobo") | ||
|
||
|
||
app.add_typer(firewall.app, name="firewall", help="FortiGate get cmdb firewall commands.") | ||
|
||
|
||
@app.callback() | ||
def callback(context: typer.Context) -> None: | ||
""" | ||
The fgt get cmdb subcommand callback | ||
Args: | ||
context: The context object of the typer app | ||
""" | ||
cli_path.append(str(context.invoked_subcommand)) | ||
log.debug("About to execute command: '%s'", context.invoked_subcommand) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
""" | ||
__init__.py | ||
""" | ||
|
||
from . import firewall | ||
|
||
__all__ = ["firewall"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,187 @@ | ||
""" | ||
The FortiGate commands | ||
""" | ||
|
||
# pylint: disable=anomalous-backslash-in-string | ||
import logging | ||
|
||
import typer | ||
|
||
from fotoobo.exceptions import GeneralError | ||
from fotoobo.helpers import cli_path | ||
from fotoobo.tools.fgt.cmdb.firewall import * # pylint: disable=wildcard-import | ||
|
||
app = typer.Typer(no_args_is_help=True, rich_markup_mode="rich") | ||
log = logging.getLogger("fotoobo") | ||
|
||
|
||
@app.callback() | ||
def callback(context: typer.Context) -> None: | ||
""" | ||
The fgt get cmdb get firewall subcommand callback | ||
Args: | ||
context: The context object of the typer app | ||
""" | ||
cli_path.append(str(context.invoked_subcommand)) | ||
log.debug("About to execute command: '%s'", context.invoked_subcommand) | ||
|
||
|
||
@app.command() | ||
def address( | ||
host: str = typer.Argument( | ||
"", | ||
help="The FortiGate hostname to access (must be defined in the inventory). " | ||
"\[default: <all>]", | ||
show_default=False, | ||
metavar="[host]", | ||
), | ||
name: str = typer.Argument( | ||
"", | ||
help="The firewall address object to get \[default: <all>]", | ||
show_default=False, | ||
metavar="[name]", | ||
), | ||
vdom: str = typer.Option( | ||
"*", | ||
"--vdom", | ||
help="The vdom to query ('vdom1' or 'vdom1,vdom2') \[default: <all>]", | ||
show_default=False, | ||
metavar="[vdom]", | ||
), | ||
output_file: str = typer.Option( | ||
None, | ||
"--output", | ||
"-o", | ||
help="Output file (format is specified by extension)", | ||
metavar="[file]", | ||
show_default=False, | ||
), | ||
) -> None: | ||
"""Get FortiGate cmdb firewall address.""" | ||
if name and ("*" in vdom or "," in vdom): | ||
raise GeneralError("With name argument you have to specify one single VDOM (with --vdom)") | ||
|
||
result = get_cmdb_firewall_address(host, name, vdom, output_file) | ||
if not output_file: | ||
result.print_table_raw(result.results[host], auto_header=True, title=host) | ||
|
||
|
||
@app.command() | ||
def addrgrp( | ||
host: str = typer.Argument( | ||
"", | ||
help="The FortiGate hostname to access (must be defined in the inventory). " | ||
"\[default: <all>]", | ||
show_default=False, | ||
metavar="[host]", | ||
), | ||
name: str = typer.Argument( | ||
"", | ||
help="The firewall address group object to get \[default: <all>]", | ||
show_default=False, | ||
metavar="[name]", | ||
), | ||
vdom: str = typer.Option( | ||
"*", | ||
"--vdom", | ||
help="The vdom to query ('vdom1' or 'vdom1,vdom2') \[default: <all>]", | ||
show_default=False, | ||
metavar="[vdom]", | ||
), | ||
output_file: str = typer.Option( | ||
None, | ||
"--output", | ||
"-o", | ||
help="Output file (format is specified by extension)", | ||
metavar="[file]", | ||
show_default=False, | ||
), | ||
) -> None: | ||
"""Get FortiGate cmdb firewall address group.""" | ||
if name and ("*" in vdom or "," in vdom): | ||
raise GeneralError("With name argument you have to specify one single VDOM (with --vdom)") | ||
|
||
result = get_cmdb_firewall_addrgrp(host, name, vdom, output_file) | ||
if not output_file: | ||
result.print_table_raw(result.results[host], auto_header=True, title=host) | ||
|
||
|
||
@app.command() | ||
def service_custom( | ||
host: str = typer.Argument( | ||
"", | ||
help="The FortiGate hostname to access (must be defined in the inventory). " | ||
"\[default: <all>]", | ||
show_default=False, | ||
metavar="[host]", | ||
), | ||
name: str = typer.Argument( | ||
"", | ||
help="The firewall service object to get \[default: <all>]", | ||
show_default=False, | ||
metavar="[name]", | ||
), | ||
vdom: str = typer.Option( | ||
"*", | ||
"--vdom", | ||
help="The vdom to query ('vdom1' or 'vdom1,vdom2') \[default: <all>]", | ||
show_default=False, | ||
metavar="[vdom]", | ||
), | ||
output_file: str = typer.Option( | ||
None, | ||
"--output", | ||
"-o", | ||
help="Output file (format is specified by extension)", | ||
metavar="[file]", | ||
show_default=False, | ||
), | ||
) -> None: | ||
"""Get FortiGate cmdb firewall service custom.""" | ||
if name and ("*" in vdom or "," in vdom): | ||
raise GeneralError("With name argument you have to specify one single VDOM (with --vdom)") | ||
|
||
result = get_cmdb_firewall_service_custom(host, name, vdom, output_file) | ||
if not output_file: | ||
result.print_table_raw(result.results[host], auto_header=True, title=host) | ||
|
||
|
||
@app.command() | ||
def service_group( | ||
host: str = typer.Argument( | ||
"", | ||
help="The FortiGate hostname to access (must be defined in the inventory). " | ||
"\[default: <all>]", | ||
show_default=False, | ||
metavar="[host]", | ||
), | ||
name: str = typer.Argument( | ||
"", | ||
help="The firewall service group to get \[default: <all>]", | ||
show_default=False, | ||
metavar="[name]", | ||
), | ||
vdom: str = typer.Option( | ||
"*", | ||
"--vdom", | ||
help="The vdom to query ('vdom1' or 'vdom1,vdom2') \[default: <all>]", | ||
show_default=False, | ||
metavar="[vdom]", | ||
), | ||
output_file: str = typer.Option( | ||
None, | ||
"--output", | ||
"-o", | ||
help="Output file (format is specified by extension)", | ||
metavar="[file]", | ||
show_default=False, | ||
), | ||
) -> None: | ||
"""Get FortiGate cmdb firewall service group.""" | ||
if name and ("*" in vdom or "," in vdom): | ||
raise GeneralError("With name argument you have to specify one single VDOM (with --vdom)") | ||
|
||
result = get_cmdb_firewall_service_group(host, name, vdom, output_file) | ||
if not output_file: | ||
result.print_table_raw(result.results[host], auto_header=True, title=host) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.