MCPcopy Create free account
hub / github.com/Keeper-Security/Commander / execute

Method execute

keepercommander/commands/aram.py:2182–2511  ·  view source on GitHub ↗
(self, params, **kwargs)

Source from the content-addressed store, hash-verified

2180 return action_report_parser
2181
2182 def execute(self, params, **kwargs):
2183 def get_excluded(candidate_usernames, query_filter, username_field='username'):
2184 # type: (Set[str], Dict[str, Any], Optional[str]) -> Set[str]
2185 """
2186 Get usernames that should be excluded (users who HAVE performed the action).
2187
2188 """
2189 if not candidate_usernames:
2190 return set()
2191
2192 cols = [username_field]
2193
2194 # Use the fetch_audit_events function with pagination support
2195 events = fetch_audit_events(
2196 params,
2197 audit_filter=query_filter,
2198 columns=cols,
2199 aggregate=['last_created'],
2200 report_type='span',
2201 limit=None, # Get all matching events
2202 cmd='action-report'
2203 )
2204
2205 # Extract usernames from events that match the candidate usernames
2206 to_exclude = {event.get(username_field, '').lower() for event in events}
2207 excluded = to_exclude.intersection(candidate_usernames)
2208
2209 return excluded
2210
2211 def get_no_action_users(candidate_users, days_since, event_types, name_key='username'):
2212 # type: (List[Dict[str, Any]], int, List[str], Optional[str]) -> List[Dict[str, Any]]
2213 days_since = 30 if not isinstance(days_since, int) else days_since
2214 now_dt = datetime.datetime.now()
2215 min_dt = now_dt - datetime.timedelta(days=days_since)
2216 start = int(min_dt.timestamp())
2217 end = int(now_dt.timestamp())
2218
2219 if 'accept_transfer' in event_types:
2220 get_expiration_ts = lambda u: u.get('account_share_expiration', 0) / 1000
2221 return [user for user in candidate_users if get_expiration_ts(user) < start]
2222
2223 period = {'min': start, 'max': end}
2224 included = {candidate.get('username') for candidate in candidate_users}
2225 query_filter = {
2226 'audit_event_type': ['login'] if event_types is None else event_types,
2227 'created': period
2228 }
2229 excluded = get_excluded(included, query_filter, name_key)
2230 return [user for user in candidate_users if user.get('username') not in excluded]
2231
2232 def chunk_list(items, chunk_size):
2233 for i in range(0, len(items), chunk_size):
2234 yield items[i:i + chunk_size]
2235
2236 def get_latest_lock_times(usernames):
2237 # type: (Set[str]) -> Dict[str, int]
2238 if not usernames:
2239 return {}

Callers

nothing calls this directly

Calls 8

executeMethod · 0.95
executeMethod · 0.95
dump_report_dataFunction · 0.85
warningMethod · 0.80
resolve_nodesMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected