@@ -184,9 +184,9 @@ if __name__ == "__main__":
184184 parser .add_argument ("--list-configuration" , dest = "list_configuration" ,
185185 help = "Get a configuration loaded for given type and config id" , metavar = "CONFIG_ID" )
186186 parser .add_argument ("--load-configuration" , dest = "load_configuration" ,
187- action = 'store_true' , help = "Load an configuration using paramemeters provided by --params" )
187+ action = 'store_true' , help = "Load an configuration using paramemeters provided by --params or --json-file " )
188188 parser .add_argument ("--update-configuration" , dest = "update_configuration" ,
189- action = 'store_true' , help = "Update an configuration using paramemeters provided by --params" )
189+ action = 'store_true' , help = "Update an configuration using paramemeters provided by --params or --json-file " )
190190 parser .add_argument ("--delete-configuration" , dest = "delete_configuration" ,
191191 help = "Delete a configuration" , metavar = "CONFIGURATION_ID" )
192192 parser .add_argument ("--type-id" , dest = "type_id" , help = "id of configuration source type" )
@@ -519,53 +519,67 @@ if __name__ == "__main__":
519519
520520
521521 if options .load_configuration :
522- if options .type_id is not None :
523- if options .params is not None :
524- params = __parse_params (options .params )
525- if (params is not None ):
526- response = tsp_client .post_configuration (options .type_id , params )
527- if response .status_code == 200 :
528- print ('Successfully loaded configuration' )
529- print ('---------------------------------' )
530- print (response .model .to_json ())
531- sys .exit (0 )
532- else :
533- sys .exit (1 )
534- else :
535- print ("Invalid params provided" )
536- sys .exit (1 )
537- else :
538- print ("No params provided" )
539- sys .exit (1 )
522+ if not options .type_id :
523+ print ("No type-id for loading of configuration provided" )
524+ sys .exit (1 )
525+
526+ if not options .params and not options .json_file :
527+ print ("No parameters provided with --params or --json-file" )
528+ sys .exit (1 )
529+
530+ params = {}
531+ if options .params is not None :
532+ params = __parse_params (options .params )
533+
534+ if options .json_file is not None :
535+ with open (options .json_file , 'r' ) as file :
536+ params = json .loads (file .read ())
537+
538+ if not params :
539+ print ("Invalid params provided" )
540+ sys .exit (1 )
541+
542+ response = tsp_client .post_configuration (options .type_id , params )
543+ if response .status_code == 200 :
544+ print ('Successfully loaded configuration' )
545+ print ('---------------------------------' )
546+ print (response .model .to_json ())
547+ sys .exit (0 )
540548 else :
541- print ("No type id of configuration provided" )
542549 sys .exit (1 )
543550
544551 if options .update_configuration :
545- if options .type_id is not None :
546- if (options .config_id is not None ):
547- if options .params is not None :
548- params = __parse_params (options .params );
549- if (params is not None ):
550- response = tsp_client .put_configuration (options .type_id , options .config_id , params )
551- if response .status_code == 200 :
552- print ('Successfully updated configuration' )
553- print ('---------------------------------' )
554- print (response .model .to_json ())
555- sys .exit (0 )
556- else :
557- sys .exit (1 )
558- else :
559- print ("Invalid params provided" )
560- sys .exit (1 )
561- else :
562- print ("No params provided" )
563- sys .exit (1 )
564- else :
565- print ("No config id if configuration provided" )
566- sys .exit (1 )
552+ if not options .type_id :
553+ print ("No type-id for updating of configuration provided" )
554+ sys .exit (1 )
555+
556+ if not options .config_id :
557+ print ("No config-id of configuration provided" )
558+ sys .exit (1 )
559+
560+ if not options .params and not options .json_file :
561+ print ("No parameters provided with --params or --json-file" )
562+ sys .exit (1 )
563+
564+ params = {}
565+ if options .params is not None :
566+ params = __parse_params (options .params )
567+
568+ if options .json_file is not None :
569+ with open (options .json_file , 'r' ) as file :
570+ params = json .loads (file .read ())
571+
572+ if not params :
573+ print ("Invalid params provided" )
574+ sys .exit (1 )
575+
576+ response = tsp_client .put_configuration (options .type_id , options .config_id , params )
577+ if response .status_code == 200 :
578+ print ('Successfully updated configuration' )
579+ print ('---------------------------------' )
580+ print (response .model .to_json ())
581+ sys .exit (0 )
567582 else :
568- print ("No type id of configuration provided" )
569583 sys .exit (1 )
570584
571585 if options .delete_configuration :
@@ -627,7 +641,7 @@ if __name__ == "__main__":
627641 sys .exit (1 )
628642
629643 if not options .params and not options .json_file :
630- print ("No parameters provided with --param or --json-file" )
644+ print ("No parameters provided with --params or --json-file" )
631645 sys .exit (1 )
632646
633647 params = {}
0 commit comments