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

Function execute_command_direct

keepercommander/service/api/command.py:87–118  ·  view source on GitHub ↗

Execute a command immediately, optionally via the v2 request queue.

(**kwargs)

Source from the content-addressed store, hash-verified

85 @bp.route("/executecommand", methods=["POST"])
86 @unified_api_decorator()
87 def execute_command_direct(**kwargs) -> Tuple[Union[Response, bytes], int]:
88 """Execute a command immediately, optionally via the v2 request queue."""
89 temp_files = []
90 queued_request_submitted = False
91 try:
92 processed_command, temp_files, request_error = _prepare_command_request()
93 if request_error:
94 return request_error
95
96 if use_queue:
97 response_data, queued_request_submitted = _submit_queue_request(
98 processed_command, temp_files, wait_for_completion=True
99 )
100 return response_data
101
102 response, status_code = CommandExecutor.execute(processed_command)
103
104 # If we get a busy response, add v1-specific message
105 if (isinstance(response, dict) and
106 "temporarily busy" in str(response.get("error", "")).lower()):
107 response["message"] = "Note: api/v1/executecommand only supports a single request at a time."
108 status_code = 503
109
110 return response if isinstance(response, bytes) else jsonify(response), status_code
111
112 except Exception as e:
113 logger.error(f"Error executing command: {e}")
114 return jsonify({"status": "error", "error": f"Error: {str(e)}"}), 500
115 finally:
116 # Queue-backed compatibility requests clean up files in the worker after submission.
117 if not use_queue or not queued_request_submitted:
118 RequestValidator.cleanup_temp_files(temp_files)
119
120 return bp
121

Callers

nothing calls this directly

Calls 6

_prepare_command_requestFunction · 0.85
_submit_queue_requestFunction · 0.85
getMethod · 0.80
cleanup_temp_filesMethod · 0.80
executeMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected