@@ -376,20 +376,15 @@ def get_policy_events_range(self, from_sec, to_sec, sampling=None, aggregations=
376376 `examples/get_secure_policy_events.py <https://github.com/draios/python-sdc-client/blob/master/examples/get_secure_policy_events.py>`_
377377
378378 '''
379- ctx = {"from" : int (from_sec ) * 1000000 ,
380- "to" : int (to_sec ) * 1000000 ,
381- "offset" : 0 ,
382- "limit" : 1000 }
383-
384- if sampling is not None :
385- ctx ["sampling" ] = sampling
386- if aggregations is not None :
387- ctx ["aggregations" ] = aggregations
388- if scope_filter is not None :
389- ctx ["scopeFilter" ] = scope_filter
390- if event_filter is not None :
391- ctx ["eventFilter" ] = event_filter
392-
379+ options = {"from" : int (from_sec ) * 1000000 ,
380+ "to" : int (to_sec ) * 1000000 ,
381+ "offset" : 0 ,
382+ "limit" : 1000 ,
383+ "sampling" : sampling ,
384+ "aggregations" : aggregations ,
385+ "scopeFilter" : scope_filter ,
386+ "eventFilter" : event_filter }
387+ ctx = {k : v for k , v in options .items () if v is not None }
393388 return self ._get_policy_events_int (ctx )
394389
395390 def get_policy_events_duration (self , duration_sec , sampling = None , aggregations = None , scope_filter = None , event_filter = None ):
@@ -415,23 +410,18 @@ def get_policy_events_duration(self, duration_sec, sampling=None, aggregations=N
415410
416411 '''
417412 epoch = datetime .datetime .utcfromtimestamp (0 )
418-
419413 to_ts = (datetime .datetime .utcnow () - epoch ).total_seconds () * 1000 * 1000
420414 from_ts = to_ts - (int (duration_sec ) * 1000 * 1000 )
421- ctx = {"to" : to_ts ,
422- "from" : from_ts ,
423- "offset" : 0 ,
424- "limit" : 1000 }
425-
426- if sampling is not None :
427- ctx ["sampling" ] = sampling
428- if aggregations is not None :
429- ctx ["aggregations" ] = aggregations
430- if scope_filter is not None :
431- ctx ["scopeFilter" ] = scope_filter
432- if event_filter is not None :
433- ctx ["eventFilter" ] = event_filter
434415
416+ options = {"to" : to_ts ,
417+ "from" : from_ts ,
418+ "offset" : 0 ,
419+ "limit" : 1000 ,
420+ "sampling" : sampling ,
421+ "aggregations" : aggregations ,
422+ "scopeFilter" : scope_filter ,
423+ "eventFilter" : event_filter }
424+ ctx = {k : v for k , v in options .items () if v is not None }
435425 return self ._get_policy_events_int (ctx )
436426
437427 def get_policy_events_id_range (self , id , from_sec , to_sec , sampling = None , aggregations = None , scope_filter = None , event_filter = None ):
@@ -458,21 +448,16 @@ def get_policy_events_id_range(self, id, from_sec, to_sec, sampling=None, aggreg
458448 `examples/get_secure_policy_events.py <https://github.com/draios/python-sdc-client/blob/master/examples/get_secure_policy_events.py>`_
459449
460450 '''
461- ctx = {"id" : id ,
462- "from" : int (from_sec ) * 1000000 ,
463- "to" : int (to_sec ) * 1000000 ,
464- "offset" : 0 ,
465- "limit" : 1000 }
466-
467- if sampling is not None :
468- ctx ["sampling" ] = sampling
469- if aggregations is not None :
470- ctx ["aggregations" ] = aggregations
471- if scope_filter is not None :
472- ctx ["scopeFilter" ] = scope_filter
473- if event_filter is not None :
474- ctx ["eventFilter" ] = event_filter
475-
451+ options = {"id" : id ,
452+ "from" : int (from_sec ) * 1000000 ,
453+ "to" : int (to_sec ) * 1000000 ,
454+ "offset" : 0 ,
455+ "limit" : 1000 ,
456+ "sampling" : sampling ,
457+ "aggregations" : aggregations ,
458+ "scopeFilter" : scope_filter ,
459+ "eventFilter" : event_filter }
460+ ctx = {k : v for k , v in options .items () if v is not None }
476461 return self ._get_policy_events_int (ctx )
477462
478463 def get_policy_events_id_duration (self , id , duration_sec , sampling = None , aggregations = None , scope_filter = None , event_filter = None ):
@@ -499,24 +484,19 @@ def get_policy_events_id_duration(self, id, duration_sec, sampling=None, aggrega
499484
500485 '''
501486 epoch = datetime .datetime .utcfromtimestamp (0 )
502-
503487 to_ts = (datetime .datetime .utcnow () - epoch ).total_seconds () * 1000 * 1000
504488 from_ts = to_ts - (int (duration_sec ) * 1000 * 1000 )
489+
505490 ctx = {"id" : id ,
506491 "to" : to_ts ,
507492 "from" : from_ts ,
508493 "offset" : 0 ,
509- "limit" : 1000 }
510-
511- if sampling is not None :
512- ctx ["sampling" ] = sampling
513- if aggregations is not None :
514- ctx ["aggregations" ] = aggregations
515- if scope_filter is not None :
516- ctx ["scopeFilter" ] = scope_filter
517- if event_filter is not None :
518- ctx ["eventFilter" ] = event_filter
519-
494+ "limit" : 1000 ,
495+ "sampling" : sampling ,
496+ "aggregations" : aggregations ,
497+ "scopeFilter" : scope_filter ,
498+ "eventFilter" : event_filter }
499+ ctx = {k : v for k , v in options .items () if v is not None }
520500 return self ._get_policy_events_int (ctx )
521501
522502 def get_more_policy_events (self , ctx ):
@@ -841,16 +821,14 @@ def update_compliance_task(self, id, name=None, module_name=None, schedule=None,
841821 return ok , res
842822
843823 task = res
844- if name is not None :
845- task ["name" ] = name
846- if module_name is not None :
847- task ["moduleName" ] = module_name
848- if schedule is not None :
849- task ["schedule" ] = schedule
850- if scope is not None :
851- task ["scope" ] = scope
852- if enabled is not None :
853- task ["enabled" ] = enabled
824+ options = {
825+ 'name' : name ,
826+ 'moduleName' : module_name ,
827+ 'schedule' : schedule ,
828+ 'scope' : scope ,
829+ 'enabled' : enabled
830+ }
831+ task .update ({k : v for k , v in options .items () if v is not None })
854832 res = requests .put (self .url + '/api/complianceTasks/{}' .format (id ), data = json .dumps (task ), headers = self .hdrs , verify = self .ssl_verify )
855833 return self ._request_result (res )
856834
0 commit comments