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

Function execute_command_direct

keepercommander/service/api/command.py:91–122  ·  view source on GitHub ↗

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

(**kwargs)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected