def _parse_submit_run_body(db_session: Session, auth_info: mlrun.api.schemas.AuthInfo, data): task = data.get("task") function_dict = data.get("function") function_url = data.get("functionUrl") if not function_url and task: function_url = get_in(task, "spec.function") if not (function_dict or function_url) or not task: log_and_raise( HTTPStatus.BAD_REQUEST.value, reason="bad JSON, need to include function/url and task objects", ) # TODO: block exec for function["kind"] in ["", "local] (must be a # remote/container runtime) if function_dict and not function_url: function = new_function(runtime=function_dict) else: if "://" in function_url: function = import_function(url=function_url, project=task.get("metadata", {}).get("project")) else: project, name, tag, hash_key = parse_versioned_object_uri( function_url) function_record = get_db().get_function(db_session, name, project, tag, hash_key) if not function_record: log_and_raise( HTTPStatus.NOT_FOUND.value, reason=f"runtime error: function {function_url} not found", ) function = new_function(runtime=function_record) if function_dict: # The purpose of the function dict is to enable the user to override configurations of the existing function # without modifying it - to do that we're creating a function object from the request function dict and # assign values from it to the main function object function = enrich_function_from_dict(function, function_dict) # if auth given in request ensure the function pod will have these auth env vars set, otherwise the job won't # be able to communicate with the api ensure_function_has_auth_set(function, auth_info) return function, task
def _generate_function_and_task_from_submit_run_body( db_session: Session, auth_info: mlrun.api.schemas.AuthInfo, data): function_dict, function_url, task = parse_submit_run_body(data) # TODO: block exec for function["kind"] in ["", "local] (must be a # remote/container runtime) if function_dict and not function_url: function = new_function(runtime=function_dict) else: if "://" in function_url: function = import_function(url=function_url, project=task.get("metadata", {}).get("project")) else: project, name, tag, hash_key = parse_versioned_object_uri( function_url) function_record = get_db().get_function(db_session, name, project, tag, hash_key) if not function_record: log_and_raise( HTTPStatus.NOT_FOUND.value, reason=f"runtime error: function {function_url} not found", ) function = new_function(runtime=function_record) if function_dict: # The purpose of the function dict is to enable the user to override configurations of the existing function # without modifying it - to do that we're creating a function object from the request function dict and # assign values from it to the main function object function = enrich_function_from_dict(function, function_dict) # if auth given in request ensure the function pod will have these auth env vars set, otherwise the job won't # be able to communicate with the api ensure_function_has_auth_set(function, auth_info) # if this was triggered by the UI, we will need to attempt auto-mount based on auto-mount config and params passed # in the auth_info. If this was triggered by the SDK, then auto-mount was already attempted and will be skipped. try_perform_auto_mount(function, auth_info) # Validate function's service-account, based on allowed SAs for the project, if existing in a project-secret. process_function_service_account(function) return function, task