Skip to content

Commit

Permalink
Issue #467 - Remove eval from bsc bin script and fix arg parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
MJJoyce committed Sep 4, 2019
1 parent a5ef1e9 commit 574148a
Showing 1 changed file with 23 additions and 38 deletions.
61 changes: 23 additions & 38 deletions bliss/core/bin/bliss_bsc_create_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@
Usage:
bliss-bsc-create-handler [options] <name> <loc> <port> <conn_type>
--service-host=<host> The host for the BSC REST service connection
[default: localhost]
--service-port=<port> The port for the BSC REST service connection
[default: 8080]
--rotate=<rl> Flag saying whether the log should be rotated
automatically [default: True]
--rotate-index=<rli> If log rotation is enabled, this determines the
frequency of a rotation. One of 'year', 'month',
'day', 'hour', 'minutes', 'second' [default: day]
--rotate-delta=<rld> If log rotation is enabled, this determines the
delta between log creation and current time
rotate-index value needed to trigger a log
rotation [default: 1]
--file-pattern=<fnp> The file pattern for the log file name. This can
include handler metadata values as well as strftime
format characters [default: %Y-%m-%d-%H-%M-%S-{name}.pcap]
--service-host=<host> The host for the BSC REST service connection
[default: localhost]
--service-port=<port> The port for the BSC REST service connection
[default: 8080]
--rotate-log=<rl> Flag saying whether the log should be rotated
automatically [default: True]
--rotate-log-index=<rli> If log rotation is enabled, this determines the
frequency of a rotation. One of 'year', 'month',
'day', 'hour', 'minutes', 'second' [default: day]
--rotate-log-delta=<rld> If log rotation is enabled, this determines the
delta between log creation and current time
rotate-index value needed to trigger a log
rotation [default: 1]
--file-name-pattern=<fnp> The file pattern for the log file name. This can
include handler metadata values as well as strftime
format characters [default: %Y-%m-%d-%H-%M-%S-{name}.pcap]
'''

import argparse
Expand All @@ -53,36 +53,21 @@ def main():
# Add optional command line arguments
parser.add_argument('--service-host', default='localhost')
parser.add_argument('--service-port', type=int, default=8080)
parser.add_argument('--rotate', type=int, default=1)
parser.add_argument('--rotate-index', choices=['year','month','day','hour','minutes','second'], default='day')
parser.add_argument('--rotate-delta', type=int, default=1)
parser.add_argument('--file-pattern', default='\%Y-\%m-\%d-\%H-\%M-\%S-{name}.pcap')
parser.add_argument('--rotate-log', type=lambda x: x in ['True', 'true'], default=True)
parser.add_argument('--rotate-log-index', choices=['year','month','day','hour','minutes','second'], default='day')
parser.add_argument('--rotate-log-delta', type=int, default=1)
parser.add_argument('--file-name-pattern', default='\%Y-\%m-\%d-\%H-\%M-\%S-{name}.pcap')

# Get command line arguments
args = vars(parser.parse_args())

host = args['service-host']
port = args['service-port']

host = args['service_host']
port = args['service_port']
handler_name = args['name']

handler_port = args['port']
arguments['port'] = handler_port

handler_conn_type = args['conn_type']
arguments['conn_type'] = handler_conn_type

handler_loc = args['loc']
arguments['loc'] = handler_loc

arguments['rotate_log'] = eval(args['rotate'])
arguments['rotate_log_index'] = args['rotate-index']
arguments['rotate_log_delta'] = args['rotate-delta']
arguments['file_name_pattern'] = args['file-pattern']

requests.post(
'http://{}:{}/{}/start'.format(host, port, handler_name),
data=arguments
data=args
)

if __name__ == '__main__':
Expand Down

0 comments on commit 574148a

Please sign in to comment.