MCPcopy Index your code
hub / github.com/bugy/script-server / post

Method post

src/web/server.py:380–451  ·  view source on GitHub ↗
(self, user)

Source from the content-addressed store, hash-verified

378
379 @inject_user
380 def post(self, user):
381 script_name = None
382
383 audit_name = user.get_audit_name()
384
385 try:
386 arguments = self.form_reader.values
387 execution_info = external_model.to_execution_info(arguments)
388
389 script_name = execution_info.script
390
391 config_model = self.application.config_service.load_config_model(script_name, user)
392
393 if not config_model:
394 message = 'Script with name "' + str(script_name) + '" not found'
395 LOGGER.error(message)
396 respond_error(self, 400, message)
397 return
398
399 parameter_values = execution_info.param_values
400
401 if self.form_reader.files:
402 for key, value in self.form_reader.files.items():
403 parameter_values[key] = value.path
404
405 all_audit_names = user.audit_names
406 LOGGER.info('Calling script %s. User %s', script_name, all_audit_names)
407
408 config_model.set_all_param_values(parameter_values)
409
410 execution_id = self.application.execution_service.start_script(config_model, user)
411
412 self.write(str(execution_id))
413
414 except InvalidValueException as e:
415 message = 'Invalid parameter %s value: %s' % (e.param_name, str(e))
416 LOGGER.error(message)
417 respond_error(self, 422, message)
418 return
419
420 except ConfigNotAllowedException:
421 LOGGER.warning('Access to the script "' + script_name + '" is denied for ' + audit_name)
422 respond_error(self, 403, 'Access to the script is denied')
423 return
424
425 except CorruptConfigFileException as e:
426 respond_error(self, CorruptConfigFileException.HTTP_CODE, str(e))
427 return None
428
429 except Exception as e:
430 LOGGER.exception("Error while calling the script")
431
432 if hasattr(e, "strerror") and e.strerror:
433 error_output = e.strerror
434 else:
435 error_output = "Unknown error occurred, contact the administrator"
436
437 result = " --- ERRORS --- \n"

Callers

nothing calls this directly

Calls 7

respond_errorFunction · 0.90
load_config_modelMethod · 0.80
set_all_param_valuesMethod · 0.80
start_scriptMethod · 0.80
get_audit_nameMethod · 0.45
writeMethod · 0.45
send_alertMethod · 0.45

Tested by

no test coverage detected