Refactor various names.
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
#!/usr/bin/env python3
|
||||
import argparse
|
||||
|
||||
from kydcap.subcommands.sniff import setup_sniff_parser
|
||||
from kydcap.subcommands.initialize_device_root_dir import setup_init_root_dir_parser
|
||||
from iottb.subcommands.capture import setup_capture_parser
|
||||
from iottb.subcommands.init import setup_init_iottb_root_parser
|
||||
|
||||
CAP_DIR_PREFIX = ...
|
||||
|
||||
@@ -12,11 +12,11 @@ CAP_DIR_PREFIX = ...
|
||||
######################
|
||||
def setup_argparse():
|
||||
# create top level parser
|
||||
root_parser = argparse.ArgumentParser(prog="kydcap")
|
||||
root_parser = argparse.ArgumentParser(prog="iottb")
|
||||
subparsers = root_parser.add_subparsers(title="subcommands", required=True, dest="command")
|
||||
|
||||
setup_sniff_parser(subparsers)
|
||||
setup_init_root_dir_parser(subparsers)
|
||||
setup_capture_parser(subparsers)
|
||||
setup_init_iottb_root_parser(subparsers)
|
||||
|
||||
return root_parser
|
||||
|
||||
2
code/iottb/cli.py
Normal file
2
code/iottb/cli.py
Normal file
@@ -0,0 +1,2 @@
|
||||
import argparse
|
||||
from .subcommands.capture import handle_sniff
|
||||
@@ -4,7 +4,7 @@ from enum import Flag, unique, global_enum
|
||||
|
||||
DEVICE_METADATA_FILE = "device-metadata.json"
|
||||
CAPTURE_METADATA_FILE = "capture-metadata.json"
|
||||
TODAY_DATE_STRING = datetime.now().strftime("%d%b%Y").lower()
|
||||
TODAY_DATE_STRING = datetime.now().strftime("%d%b%Y").lower() # TODO convert to function in utils or so
|
||||
|
||||
|
||||
@unique
|
||||
@@ -6,7 +6,7 @@ from typing import Optional, Any
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from kydcap.config import ReturnCodes
|
||||
from iottb.definitions import ReturnCodes
|
||||
|
||||
|
||||
class KydcapCaptureMetadata(BaseModel):
|
||||
@@ -19,6 +19,7 @@ class KydcapCaptureMetadata(BaseModel):
|
||||
start_time: str
|
||||
stop_time: str
|
||||
packet_count: Optional[int]
|
||||
pcap_filter: str = ""
|
||||
|
||||
# Optional Fields
|
||||
device_ip_address: Optional[str] = None
|
||||
@@ -4,8 +4,8 @@ from datetime import datetime
|
||||
from pathlib import Path
|
||||
from typing import Optional, List, Any
|
||||
|
||||
# kydcap modules
|
||||
from kydcap.config import ReturnCodes
|
||||
# iottb modules
|
||||
from iottb.definitions import ReturnCodes
|
||||
|
||||
# 3rd party libs
|
||||
from pydantic import BaseModel, Field
|
||||
@@ -1,17 +1,17 @@
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
from kydcap.config import *
|
||||
from kydcap.models.device_metadata_model import DeviceMetadata
|
||||
from iottb.definitions import *
|
||||
from iottb.models.device_metadata_model import DeviceMetadata
|
||||
|
||||
|
||||
def setup_sniff_parser(subparsers):
|
||||
def setup_capture_parser(subparsers):
|
||||
parser = subparsers.add_parser('sniff', help='Sniff packets with tcpdump')
|
||||
# metadata args
|
||||
parser.add_argument("-a", "--ip-address=", help="IP address of the device to sniff", dest="device_ip")
|
||||
parser.add_argument("-a", "--ip-address", help="IP address of the device to sniff", dest="device_ip")
|
||||
# tcpdump args
|
||||
parser_sniff_tcpdump = parser.add_argument_group('tcpdump arguments')
|
||||
parser_sniff_tcpdump.add_argument("-i", "--interface=", help="Interface to capture on.", dest="capture_interface",
|
||||
parser_sniff_tcpdump.add_argument("-i", "--interface", help="Interface to capture on.", dest="capture_interface",
|
||||
default="any")
|
||||
parser_sniff_tcpdump.add_argument("-I", "--monitor-mode", help="Put interface into monitor mode",
|
||||
action="store_true")
|
||||
@@ -30,7 +30,7 @@ def setup_sniff_parser(subparsers):
|
||||
cap_size_group = parser.add_mutually_exclusive_group(required=False)
|
||||
cap_size_group.add_argument("-c", "--count", type=int, help="Number of packets to capture.", default=0)
|
||||
cap_size_group.add_argument("--mins", type=int, help="Time in minutes to capture.", default=60)
|
||||
parser.set_defaults(func=handle_sniff)
|
||||
parser.set_defaults(func=handle_capture)
|
||||
# return parser
|
||||
# parser.add_default(func=handle_sniff(args=sniff_args))
|
||||
|
||||
@@ -40,6 +40,9 @@ def cwd_is_device_root_dir() -> bool:
|
||||
return device_metadata_file.exists()
|
||||
|
||||
|
||||
def get_user_capture_config():
|
||||
pass
|
||||
|
||||
def start_guided_device_root_dir_setup():
|
||||
assert False, "Not implemented"
|
||||
|
||||
@@ -52,7 +55,7 @@ def handle_metadata():
|
||||
if response.lower() == "y":
|
||||
start_guided_device_root_dir_setup()
|
||||
else:
|
||||
print("'kydcap init-device-root --help' for more information.")
|
||||
print("'iottb init-device-root --help' for more information.")
|
||||
exit(ReturnCodes.ABORTED)
|
||||
# device_id = handle_capture_metadata()
|
||||
return ReturnCodes.SUCCESS
|
||||
@@ -68,9 +71,12 @@ def handle_capture_metadata():
|
||||
def handle_date_dir():
|
||||
pass
|
||||
|
||||
|
||||
def run_tcpdum(cmd):
|
||||
subprocess.run(cmd)
|
||||
def handle_sniff(args):
|
||||
|
||||
|
||||
def handle_capture(args):
|
||||
if cwd_is_device_root_dir():
|
||||
handle_date_dir()
|
||||
cmd = ['sudo tcpdump', '-i', args.capture_interface]
|
||||
@@ -1,11 +1,11 @@
|
||||
import pathlib
|
||||
|
||||
from kydcap.config import DEVICE_METADATA_FILE
|
||||
from kydcap.models.device_metadata_model import DeviceMetadata
|
||||
from iottb.definitions import DEVICE_METADATA_FILE
|
||||
from iottb.models.device_metadata_model import DeviceMetadata
|
||||
|
||||
|
||||
def setup_init_root_dir_parser(subparsers):
|
||||
parser = subparsers.add_parser("init-device-root", aliases=["idr"])
|
||||
def setup_init_iottb_root_parser(subparsers):
|
||||
parser = subparsers.add_parser("init", aliases=["idr"])
|
||||
parser.add_argument("--root_dir", type=pathlib.Path, default=pathlib.Path.cwd())
|
||||
group = parser.add_mutually_exclusive_group()
|
||||
group.add_argument("--dynamic", action="store_true", help="enable guided setup", default=False)
|
||||
@@ -14,7 +14,7 @@ def setup_init_root_dir_parser(subparsers):
|
||||
|
||||
|
||||
def handle_idr(args):
|
||||
print("Entered kydcap initialize-device-root")
|
||||
print("Entered iottb initialize-device-root")
|
||||
root_dir = args.root_dir
|
||||
device_name = None
|
||||
if args.dynamic:
|
||||
0
code/iottb/utils/__init__.py
Normal file
0
code/iottb/utils/__init__.py
Normal file
@@ -1,7 +1,7 @@
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
from kydcap.config import ReturnCodes
|
||||
from iottb.definitions import ReturnCodes
|
||||
|
||||
|
||||
def set_device_ip_address(ip_addr: str, file_path: Path):
|
||||
@@ -2,7 +2,7 @@ import json
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
|
||||
from kydcap.config import ReturnCodes
|
||||
from iottb.definitions import ReturnCodes
|
||||
|
||||
|
||||
def update_firmware_version(version: str, file_path: Path):
|
||||
@@ -3,4 +3,4 @@ from pathlib import Path
|
||||
from unittest.mock import mock_open, patch
|
||||
import pytest
|
||||
|
||||
from kydcap.utils.capture_metadata_utils import set_device_ip_address
|
||||
from iottb.utils.capture_metadata_utils import set_device_ip_address
|
||||
Reference in New Issue
Block a user