MCPcopy
hub / github.com/jtesta/ssh-audit / process_commandline

Function process_commandline

src/ssh_audit/ssh_audit.py:826–1015  ·  view source on GitHub ↗
(out: OutputBuffer, args: List[str], usage_cb: Callable[..., None])

Source from the content-addressed store, hash-verified

824
825
826def process_commandline(out: OutputBuffer, args: List[str], usage_cb: Callable[..., None]) -> 'AuditConf': # pylint: disable=too-many-statements
827 # pylint: disable=too-many-branches
828 aconf = AuditConf()
829
830 enable_colors = not any(i in args for i in ['--no-colors', '-n'])
831
832 # Disable colors if the NO_COLOR environment variable is set.
833 if "NO_COLOR" in os.environ:
834 enable_colors = False
835
836 aconf.colors = enable_colors
837 out.use_colors = enable_colors
838
839 try:
840 sopts = 'h1246M:p:P:jbcnvl:t:T:Lmdg:'
841 lopts = ['help', 'ssh1', 'ssh2', 'ipv4', 'ipv6', 'make-policy=', 'port=', 'policy=', 'json', 'batch', 'client-audit', 'no-colors', 'verbose', 'level=', 'timeout=', 'targets=', 'list-policies', 'lookup=', 'threads=', 'manual', 'debug', 'gex-test=', 'dheat=', 'skip-rate-test', 'conn-rate-test=']
842 opts, args = getopt.gnu_getopt(args, sopts, lopts)
843 except getopt.GetoptError as err:
844 usage_cb(out, str(err))
845 aconf.ssh1, aconf.ssh2 = False, False
846 host: str = ''
847 oport: Optional[str] = None
848 port: int = 0
849 for o, a in opts:
850 if o in ('-h', '--help'):
851 usage_cb(out)
852 elif o in ('-1', '--ssh1'):
853 aconf.ssh1 = True
854 elif o in ('-2', '--ssh2'):
855 aconf.ssh2 = True
856 elif o in ('-4', '--ipv4'):
857 aconf.ipv4 = True
858 elif o in ('-6', '--ipv6'):
859 aconf.ipv6 = True
860 elif o in ('-p', '--port'):
861 oport = a
862 elif o in ('-b', '--batch'):
863 aconf.batch = True
864 aconf.verbose = True
865 elif o in ('-c', '--client-audit'):
866 aconf.client_audit = True
867 elif o in ('-j', '--json'):
868 if aconf.json: # If specified twice, enable indent printing.
869 aconf.json_print_indent = True
870 else:
871 aconf.json = True
872 elif o in ('-v', '--verbose'):
873 aconf.verbose = True
874 out.verbose = True
875 elif o in ('-l', '--level'):
876 if a not in ('info', 'warn', 'fail'):
877 usage_cb(out, 'level {} is not valid'.format(a))
878 aconf.level = a
879 elif o in ('-t', '--timeout'):
880 aconf.timeout = float(a)
881 aconf.timeout_set = True
882 elif o in ('-M', '--make-policy'):
883 aconf.make_policy = True

Callers 1

mainFunction · 0.85

Calls 11

AuditConfClass · 0.90
PolicyClass · 0.90
list_policiesFunction · 0.85
valuesMethod · 0.80
parse_host_and_portMethod · 0.80
parse_intMethod · 0.80
load_builtin_policyMethod · 0.80
failMethod · 0.80
is_server_policyMethod · 0.80
writeMethod · 0.45

Tested by

no test coverage detected