Deployment: Wrap argument parsing in function
This commit is contained in:
parent
7bcfc6d27a
commit
38f50641a5
|
@ -2,11 +2,13 @@ import argparse
|
||||||
|
|
||||||
import pymongo
|
import pymongo
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description="Export attack mitigations from a database")
|
|
||||||
parser.add_argument(
|
def parse_args():
|
||||||
|
parser = argparse.ArgumentParser(description="Export attack mitigations from a database")
|
||||||
|
parser.add_argument(
|
||||||
"-host", "--mongo_host", default="localhost", help="URL for mongo database.", required=False
|
"-host", "--mongo_host", default="localhost", help="URL for mongo database.", required=False
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-port",
|
"-port",
|
||||||
"--mongo_port",
|
"--mongo_port",
|
||||||
action="store",
|
action="store",
|
||||||
|
@ -14,24 +16,24 @@ parser.add_argument(
|
||||||
type=int,
|
type=int,
|
||||||
help="Port for mongo database. Default 27017",
|
help="Port for mongo database. Default 27017",
|
||||||
required=False,
|
required=False,
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-db",
|
"-db",
|
||||||
"--database_name",
|
"--database_name",
|
||||||
action="store",
|
action="store",
|
||||||
default="monkeyisland",
|
default="monkeyisland",
|
||||||
help="Database name inside of mongo.",
|
help="Database name inside of mongo.",
|
||||||
required=False,
|
required=False,
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-cn",
|
"-cn",
|
||||||
"--collection_name",
|
"--collection_name",
|
||||||
action="store",
|
action="store",
|
||||||
default="attack_mitigations",
|
default="attack_mitigations",
|
||||||
help="Which collection are we going to export",
|
help="Which collection are we going to export",
|
||||||
required=False,
|
required=False,
|
||||||
)
|
)
|
||||||
args = parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
def connect_to_mongo(mongo_host: str, mongo_port: int, database_name: str) -> pymongo.MongoClient:
|
def connect_to_mongo(mongo_host: str, mongo_port: int, database_name: str) -> pymongo.MongoClient:
|
||||||
|
@ -51,6 +53,7 @@ def clean_collection(mongodb: pymongo.MongoClient, collection_name: str):
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
args = parse_args()
|
||||||
mongodb = connect_to_mongo(args.mongo_host, args.mongo_port, args.database_name)
|
mongodb = connect_to_mongo(args.mongo_host, args.mongo_port, args.database_name)
|
||||||
|
|
||||||
clean_collection(mongodb, args.collection_name)
|
clean_collection(mongodb, args.collection_name)
|
||||||
|
|
Loading…
Reference in New Issue