From 156148527ebcbc4c7f1beaccf2d4831afd2bdd81 Mon Sep 17 00:00:00 2001 From: wangyu096 Date: Tue, 7 Nov 2023 10:20:43 +0800 Subject: [PATCH] =?UTF-8?q?feature:=20ESB=20=E7=BD=91=E5=85=B3=E8=AE=A4?= =?UTF-8?q?=E8=AF=81=E5=8F=82=E6=95=B0=E6=A0=87=E5=87=86=E5=8C=96=20#2590?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WebInterceptorAutoConfiguration.java | 6 -- .../web/interceptor/EsbApiLogInterceptor.java | 55 +++++----- .../interceptor/EsbReqRewriteInterceptor.java | 101 ------------------ .../bk/job/common/esb/model/EsbReq.java | 28 +++-- .../api/esb/v2/EsbExecuteTaskResource.java | 4 + .../api/esb/v2/EsbFastExecuteSQLResource.java | 4 + .../esb/v2/EsbFastExecuteScriptResource.java | 4 + .../v3/EsbGetJobInstanceListV3Resource.java | 2 + .../v2/impl/EsbExecuteTaskResourceImpl.java | 10 +- .../impl/EsbFastExecuteSQLResourceImpl.java | 29 ++--- .../EsbFastExecuteScriptResourceImpl.java | 22 ++-- .../EsbGetJobInstanceListV3ResourceImpl.java | 6 +- 12 files changed, 91 insertions(+), 180 deletions(-) delete mode 100644 src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/interceptor/EsbReqRewriteInterceptor.java diff --git a/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/config/WebInterceptorAutoConfiguration.java b/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/config/WebInterceptorAutoConfiguration.java index a56b77aab9..66c1d06967 100644 --- a/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/config/WebInterceptorAutoConfiguration.java +++ b/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/config/WebInterceptorAutoConfiguration.java @@ -27,7 +27,6 @@ import com.tencent.bk.job.common.jwt.JwtManager; import com.tencent.bk.job.common.service.SpringProfile; import com.tencent.bk.job.common.web.interceptor.EsbApiLogInterceptor; -import com.tencent.bk.job.common.web.interceptor.EsbReqRewriteInterceptor; import com.tencent.bk.job.common.web.interceptor.JobCommonInterceptor; import com.tencent.bk.job.common.web.interceptor.ServiceSecurityInterceptor; import org.springframework.cloud.sleuth.Tracer; @@ -50,11 +49,6 @@ public EsbApiLogInterceptor esbApiLogInterceptor() { return new EsbApiLogInterceptor(); } - @Bean - public EsbReqRewriteInterceptor esbReqRewriteInterceptor() { - return new EsbReqRewriteInterceptor(); - } - @Bean public ServiceSecurityInterceptor serviceSecurityInterceptor(JwtManager jwtManager, SpringProfile springProfile) { return new ServiceSecurityInterceptor(jwtManager, springProfile); diff --git a/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/interceptor/EsbApiLogInterceptor.java b/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/interceptor/EsbApiLogInterceptor.java index 129d38c701..a933217376 100644 --- a/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/interceptor/EsbApiLogInterceptor.java +++ b/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/interceptor/EsbApiLogInterceptor.java @@ -25,7 +25,6 @@ package com.tencent.bk.job.common.web.interceptor; import com.fasterxml.jackson.databind.node.ObjectNode; -import com.fasterxml.jackson.databind.node.TextNode; import com.tencent.bk.job.common.annotation.JobInterceptor; import com.tencent.bk.job.common.constant.InterceptorOrder; import com.tencent.bk.job.common.constant.JobCommonHeaders; @@ -48,8 +47,6 @@ public class EsbApiLogInterceptor extends HandlerInterceptorAdapter { private static final String ATTR_REQUEST_START = "request-start"; private static final String ATTR_API_NAME = "api-name"; - private static final String ATTR_USERNAME = "username"; - private static final String ATTR_APP_CODE = "app-code"; @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) { @@ -59,8 +56,8 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons RepeatableReadWriteHttpServletRequest wrapperRequest = (RepeatableReadWriteHttpServletRequest) request; String desensitizedBody = ""; String desensitizedQueryParams = ""; - String username = ""; - String appCode = ""; + String username = request.getHeader(JobCommonHeaders.USERNAME); + String appCode = request.getHeader(JobCommonHeaders.APP_CODE); String apiName = ""; String lang = request.getHeader(JobCommonHeaders.BK_GATEWAY_LANG); String requestId = request.getHeader(JobCommonHeaders.BK_GATEWAY_REQUEST_ID); @@ -70,28 +67,9 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons apiName = getAPIName(wrapperRequest.getRequestURI()); request.setAttribute(ATTR_API_NAME, apiName); desensitizedQueryParams = desensitizeQueryParams(request.getQueryString()); - if (request.getMethod().equals(HttpMethod.POST.name()) - || request.getMethod().equals(HttpMethod.PUT.name())) { - if (StringUtils.isNotBlank(wrapperRequest.getBody())) { - ObjectNode jsonBody = (ObjectNode) JsonUtils.toJsonNode(wrapperRequest.getBody()); - if (jsonBody == null) { - return true; - } - username = jsonBody.get("bk_username") == null ? null : jsonBody.get("bk_username").asText(); - appCode = jsonBody.get("bk_app_code") == null ? null : jsonBody.get("bk_app_code").asText(); - - // hidden sensitive data - jsonBody.set("bk_app_secret", TextNode.valueOf("***")); - desensitizedBody = jsonBody.toString(); - } - } else if (request.getMethod().equals(HttpMethod.GET.name())) { - username = request.getParameter("bk_username"); - appCode = request.getParameter("bk_app_code"); - request.setAttribute(ATTR_USERNAME, username); - request.setAttribute(ATTR_APP_CODE, appCode); - } - } catch (Throwable e) { - return true; + desensitizedBody = desensitizeRequestBody(wrapperRequest); + } catch (Throwable ignore) { + // do nothing } finally { log.info("request-id: {}|lang: {}|API: {}|uri: {}|appCode: {}|username: {}|body: {}|queryParams: {}", requestId, lang, apiName, request.getRequestURI(), appCode, username, desensitizedBody, @@ -100,6 +78,25 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons return true; } + private String desensitizeRequestBody(RepeatableReadWriteHttpServletRequest request) { + if (request.getMethod().equals(HttpMethod.POST.name()) + || request.getMethod().equals(HttpMethod.PUT.name())) { + if (StringUtils.isNotBlank(request.getBody())) { + ObjectNode jsonBody = (ObjectNode) JsonUtils.toJsonNode(request.getBody()); + if (jsonBody == null) { + return null; + } + + // 由于历史原因,ESB API 的调用方会在 Body 中直接传入 bk_app_secret 这个敏感参数,需要在日志记录的时候脱敏 + if (jsonBody.get("bk_app_secret") != null) { + jsonBody.remove("bk_app_secret"); + } + return jsonBody.toString(); + } + } + return null; + } + private String desensitizeQueryParams(String queryParams) { String desensitizedQueryParams = queryParams; if (StringUtils.isNotEmpty(queryParams)) { @@ -138,8 +135,8 @@ public void afterCompletion(HttpServletRequest request, HttpServletResponse resp try { Long startTimeInMills = (Long) request.getAttribute(ATTR_REQUEST_START); String apiName = (String) request.getAttribute(ATTR_API_NAME); - String appCode = (String) request.getAttribute(ATTR_APP_CODE); - String username = (String) request.getAttribute(ATTR_USERNAME); + String username = request.getHeader(JobCommonHeaders.USERNAME); + String appCode = request.getHeader(JobCommonHeaders.APP_CODE); String requestId = request.getHeader(JobCommonHeaders.BK_GATEWAY_REQUEST_ID); int respStatus = response.getStatus(); long cost = System.currentTimeMillis() - startTimeInMills; diff --git a/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/interceptor/EsbReqRewriteInterceptor.java b/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/interceptor/EsbReqRewriteInterceptor.java deleted file mode 100644 index cf3fa06cf6..0000000000 --- a/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/interceptor/EsbReqRewriteInterceptor.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. - * - * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. - * - * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. - * - * License for BK-JOB蓝鲸智云作业平台: - * -------------------------------------------------------------------- - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated - * documentation files (the "Software"), to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and - * to permit persons to whom the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of - * the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO - * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF - * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. - */ - -package com.tencent.bk.job.common.web.interceptor; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.node.ObjectNode; -import com.fasterxml.jackson.databind.node.TextNode; -import com.tencent.bk.job.common.annotation.JobInterceptor; -import com.tencent.bk.job.common.constant.InterceptorOrder; -import com.tencent.bk.job.common.constant.JobCommonHeaders; -import com.tencent.bk.job.common.util.json.JsonUtils; -import com.tencent.bk.job.common.web.model.RepeatableReadWriteHttpServletRequest; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; -import org.springframework.http.HttpMethod; -import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -@Slf4j -@JobInterceptor(order = InterceptorOrder.Init.REWRITE_REQUEST, pathPatterns = "/esb/api/**") -public class EsbReqRewriteInterceptor extends HandlerInterceptorAdapter { - - @Override - public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) { - if (!(request instanceof RepeatableReadWriteHttpServletRequest)) { - return true; - } - RepeatableReadWriteHttpServletRequest wrapperRequest = (RepeatableReadWriteHttpServletRequest) request; - - String appCode = request.getHeader(JobCommonHeaders.APP_CODE); - String username = request.getHeader(JobCommonHeaders.USERNAME); - - try { - if (request.getMethod().equals(HttpMethod.POST.name()) - || request.getMethod().equals(HttpMethod.PUT.name())) { - if (StringUtils.isNotBlank(wrapperRequest.getBody())) { - ObjectNode jsonBody = (ObjectNode) JsonUtils.toJsonNode(wrapperRequest.getBody()); - if (jsonBody == null) { - return true; - } - // reset username and appCode - if (StringUtils.isNotBlank(username)) { - JsonNode bkUserNameNode = jsonBody.get("bk_username"); - if (bkUserNameNode != null && StringUtils.isNotBlank(bkUserNameNode.asText()) - && !bkUserNameNode.asText().equals(username)) { - log.error("Invalid username, usernameInBody: {}, username: {}", bkUserNameNode.asText(), - username); - } - jsonBody.set("bk_username", new TextNode(username)); - } else { - log.error("Header {} is missing", JobCommonHeaders.USERNAME); - } - - if (StringUtils.isNotBlank(appCode)) { - JsonNode bkAppCodeNode = jsonBody.get("bk_app_code"); - if (bkAppCodeNode != null && StringUtils.isNotBlank(bkAppCodeNode.asText()) - && !bkAppCodeNode.asText().equals(appCode)) { - log.error("Invalid appCode, appCodeInBody: {}, appCode: {}", bkAppCodeNode.asText(), - appCode); - } - jsonBody.set("bk_app_code", new TextNode(appCode)); - } else { - log.error("Header {} is missing", JobCommonHeaders.APP_CODE); - } - - // hidden sensitive data - jsonBody.set("bk_app_secret", TextNode.valueOf("***")); - wrapperRequest.setBody(jsonBody.toString()); - } - } - } catch (Throwable e) { - log.warn("Rewrite EsbReq error", e); - return true; - } - return true; - } -} diff --git a/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/model/EsbReq.java b/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/model/EsbReq.java index 64d0db846b..3d7d62253d 100644 --- a/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/model/EsbReq.java +++ b/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/model/EsbReq.java @@ -27,7 +27,6 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.tencent.bk.job.common.util.http.BasicHttpReq; -import com.tencent.bk.job.common.util.json.SkipLogFields; import lombok.Getter; import lombok.Setter; @@ -37,20 +36,19 @@ @Setter @Getter public class EsbReq extends BasicHttpReq { - @JsonProperty("bk_app_code") - private String appCode; - - @SkipLogFields("bk_app_secret") - @JsonProperty("bk_app_secret") - private String appSecret; - - @JsonProperty("bk_username") - private String userName; - - @JsonProperty("bk_token") - @JsonInclude(JsonInclude.Include.NON_EMPTY) - private String bkToken; - +// @JsonProperty("bk_app_code") +// private String appCode; +// +// @SkipLogFields("bk_app_secret") +// @JsonProperty("bk_app_secret") +// private String appSecret; +// +// @JsonProperty("bk_username") +// private String userName; + + /** + * 租户账号 - 除了 cmdb 之外,其他平台暂未使用 + */ @JsonProperty("bk_supplier_account") @JsonInclude(JsonInclude.Include.NON_EMPTY) private String bkSupplierAccount; diff --git a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/EsbExecuteTaskResource.java b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/EsbExecuteTaskResource.java index 3d7edb6f89..ed15b808c3 100644 --- a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/EsbExecuteTaskResource.java +++ b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/EsbExecuteTaskResource.java @@ -25,12 +25,14 @@ package com.tencent.bk.job.execute.api.esb.v2; import com.tencent.bk.job.common.annotation.EsbAPI; +import com.tencent.bk.job.common.constant.JobCommonHeaders; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.execute.model.esb.v2.EsbJobExecuteDTO; import com.tencent.bk.job.execute.model.esb.v2.request.EsbExecuteJobRequest; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -44,6 +46,8 @@ public interface EsbExecuteTaskResource { @PostMapping("/execute_job") EsbResp executeJob( + @RequestHeader(value = JobCommonHeaders.USERNAME) String username, + @RequestHeader(value = JobCommonHeaders.APP_CODE) String appCode, @RequestBody @Validated EsbExecuteJobRequest request diff --git a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/EsbFastExecuteSQLResource.java b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/EsbFastExecuteSQLResource.java index 6ab20737fc..21086cc18f 100644 --- a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/EsbFastExecuteSQLResource.java +++ b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/EsbFastExecuteSQLResource.java @@ -25,12 +25,14 @@ package com.tencent.bk.job.execute.api.esb.v2; import com.tencent.bk.job.common.annotation.EsbAPI; +import com.tencent.bk.job.common.constant.JobCommonHeaders; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.execute.model.esb.v2.EsbJobExecuteDTO; import com.tencent.bk.job.execute.model.esb.v2.request.EsbFastExecuteSQLRequest; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -44,6 +46,8 @@ public interface EsbFastExecuteSQLResource { @PostMapping("/fast_execute_sql") EsbResp fastExecuteSQL( + @RequestHeader(value = JobCommonHeaders.USERNAME) String username, + @RequestHeader(value = JobCommonHeaders.APP_CODE) String appCode, @RequestBody @Validated EsbFastExecuteSQLRequest request diff --git a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/EsbFastExecuteScriptResource.java b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/EsbFastExecuteScriptResource.java index 5070f10884..6d6e896733 100644 --- a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/EsbFastExecuteScriptResource.java +++ b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/EsbFastExecuteScriptResource.java @@ -25,12 +25,14 @@ package com.tencent.bk.job.execute.api.esb.v2; import com.tencent.bk.job.common.annotation.EsbAPI; +import com.tencent.bk.job.common.constant.JobCommonHeaders; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.execute.model.esb.v2.EsbJobExecuteDTO; import com.tencent.bk.job.execute.model.esb.v2.request.EsbFastExecuteScriptRequest; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -44,6 +46,8 @@ public interface EsbFastExecuteScriptResource { @PostMapping("/fast_execute_script") EsbResp fastExecuteScript( + @RequestHeader(value = JobCommonHeaders.USERNAME) String username, + @RequestHeader(value = JobCommonHeaders.APP_CODE) String appCode, @RequestBody @Validated EsbFastExecuteScriptRequest request diff --git a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbGetJobInstanceListV3Resource.java b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbGetJobInstanceListV3Resource.java index 113095f895..ee03aab1c5 100644 --- a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbGetJobInstanceListV3Resource.java +++ b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbGetJobInstanceListV3Resource.java @@ -49,6 +49,8 @@ public interface EsbGetJobInstanceListV3Resource { @PostMapping("/get_job_instance_list") EsbResp> getJobInstanceListUsingPost( + @RequestHeader(value = JobCommonHeaders.USERNAME) String username, + @RequestHeader(value = JobCommonHeaders.APP_CODE) String appCode, @RequestBody @Validated EsbGetJobInstanceListV3Request request diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbExecuteTaskResourceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbExecuteTaskResourceImpl.java index 59b13d3551..065befe96c 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbExecuteTaskResourceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbExecuteTaskResourceImpl.java @@ -78,7 +78,11 @@ public EsbExecuteTaskResourceImpl(TaskExecuteService taskExecuteService) { ExecuteMetricsConstants.TAG_KEY_TASK_TYPE, ExecuteMetricsConstants.TAG_VALUE_TASK_TYPE_EXECUTE_PLAN }) @AuditEntry(actionId = ActionId.LAUNCH_JOB_PLAN) - public EsbResp executeJob(@AuditRequestBody EsbExecuteJobRequest request) { + public EsbResp executeJob( + String username, + String appCode, + @AuditRequestBody EsbExecuteJobRequest request) { + log.info("Execute task, request={}", JsonUtils.toJson(request)); ValidateResult checkResult = checkExecuteTaskRequest(request); if (!checkResult.isPass()) { @@ -110,11 +114,11 @@ public EsbResp executeJob(@AuditRequestBody EsbExecuteJobReque .builder() .appId(request.getAppId()) .planId(request.getTaskId()) - .operator(request.getUserName()) + .operator(username) .executeVariableValues(executeVariableValues) .startupMode(TaskStartupModeEnum.API) .callbackUrl(request.getCallbackUrl()) - .appCode(request.getAppCode()) + .appCode(appCode) .build()); EsbJobExecuteDTO result = new EsbJobExecuteDTO(); diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbFastExecuteSQLResourceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbFastExecuteSQLResourceImpl.java index 78a61591b5..345b08b089 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbFastExecuteSQLResourceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbFastExecuteSQLResourceImpl.java @@ -54,7 +54,6 @@ import com.tencent.bk.job.execute.model.esb.v2.EsbJobExecuteDTO; import com.tencent.bk.job.execute.model.esb.v2.request.EsbFastExecuteSQLRequest; import com.tencent.bk.job.execute.service.AccountService; -import com.tencent.bk.job.execute.service.ScriptService; import com.tencent.bk.job.execute.service.TaskExecuteService; import com.tencent.bk.job.manage.common.consts.script.ScriptTypeEnum; import lombok.extern.slf4j.Slf4j; @@ -74,17 +73,13 @@ public class EsbFastExecuteSQLResourceImpl extends JobExecuteCommonProcessor imp private final MessageI18nService i18nService; - private final ScriptService scriptService; - @Autowired public EsbFastExecuteSQLResourceImpl(TaskExecuteService taskExecuteService, AccountService accountService, - MessageI18nService i18nService, - ScriptService scriptService) { + MessageI18nService i18nService) { this.taskExecuteService = taskExecuteService; this.accountService = accountService; this.i18nService = i18nService; - this.scriptService = scriptService; } @Override @@ -95,7 +90,11 @@ public EsbFastExecuteSQLResourceImpl(TaskExecuteService taskExecuteService, ExecuteMetricsConstants.TAG_KEY_TASK_TYPE, ExecuteMetricsConstants.TAG_VALUE_TASK_TYPE_FAST_SQL }) @AuditEntry - public EsbResp fastExecuteSQL(@AuditRequestBody EsbFastExecuteSQLRequest request) { + public EsbResp fastExecuteSQL(String username, + String appCode, + @AuditRequestBody EsbFastExecuteSQLRequest request) { + + ValidateResult validateResult = checkFastExecuteSQLRequest(request); if (!validateResult.isPass()) { log.warn("Fast execute SQL request is illegal!"); @@ -104,8 +103,8 @@ public EsbResp fastExecuteSQL(@AuditRequestBody EsbFastExecute request.trimIps(); - TaskInstanceDTO taskInstance = buildFastSQLTaskInstance(request); - StepInstanceDTO stepInstance = buildFastSQLStepInstance(request); + TaskInstanceDTO taskInstance = buildFastSQLTaskInstance(username, appCode, request); + StepInstanceDTO stepInstance = buildFastSQLStepInstance(username, request); TaskInstanceDTO executeTaskInstance = taskExecuteService.executeFastTask( FastTaskDTO.builder().taskInstance(taskInstance).stepInstance(stepInstance).build() ); @@ -149,7 +148,9 @@ private ValidateResult checkFastExecuteSQLRequest(EsbFastExecuteSQLRequest reque } - private TaskInstanceDTO buildFastSQLTaskInstance(EsbFastExecuteSQLRequest request) { + private TaskInstanceDTO buildFastSQLTaskInstance(String username, + String appCode, + EsbFastExecuteSQLRequest request) { TaskInstanceDTO taskInstance = new TaskInstanceDTO(); if (StringUtils.isNotBlank(request.getName())) { taskInstance.setName(request.getName()); @@ -158,7 +159,7 @@ private TaskInstanceDTO buildFastSQLTaskInstance(EsbFastExecuteSQLRequest reques } taskInstance.setCronTaskId(-1L); taskInstance.setAppId(request.getAppId()); - taskInstance.setOperator(request.getUserName()); + taskInstance.setOperator(username); taskInstance.setPlanId(-1L); taskInstance.setTaskTemplateId(-1L); taskInstance.setDebugTask(false); @@ -167,13 +168,13 @@ private TaskInstanceDTO buildFastSQLTaskInstance(EsbFastExecuteSQLRequest reques taskInstance.setCurrentStepInstanceId(0L); taskInstance.setCreateTime(DateUtils.currentTimeMillis()); taskInstance.setType(TaskTypeEnum.SCRIPT.getValue()); - taskInstance.setAppCode(request.getAppCode()); + taskInstance.setAppCode(appCode); taskInstance.setCallbackUrl(request.getCallbackUrl()); return taskInstance; } - private StepInstanceDTO buildFastSQLStepInstance(EsbFastExecuteSQLRequest request) + private StepInstanceDTO buildFastSQLStepInstance(String username, EsbFastExecuteSQLRequest request) throws ServiceException { StepInstanceDTO stepInstance = new StepInstanceDTO(); stepInstance.setAppId(request.getAppId()); @@ -211,7 +212,7 @@ private StepInstanceDTO buildFastSQLStepInstance(EsbFastExecuteSQLRequest reques } stepInstance.setAccountId(account.getDbSystemAccountId()); stepInstance.setDbAccountId(account.getId()); - stepInstance.setOperator(request.getUserName()); + stepInstance.setOperator(username); stepInstance.setCreateTime(DateUtils.currentTimeMillis()); return stepInstance; } diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbFastExecuteScriptResourceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbFastExecuteScriptResourceImpl.java index 965e6af87b..5d0c028eb5 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbFastExecuteScriptResourceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbFastExecuteScriptResourceImpl.java @@ -92,7 +92,10 @@ public EsbFastExecuteScriptResourceImpl(TaskExecuteService taskExecuteService, ExecuteMetricsConstants.TAG_KEY_TASK_TYPE, ExecuteMetricsConstants.TAG_VALUE_TASK_TYPE_FAST_SCRIPT }) @AuditEntry - public EsbResp fastExecuteScript(@AuditRequestBody EsbFastExecuteScriptRequest request) { + public EsbResp fastExecuteScript(String username, + String appCode, + @AuditRequestBody EsbFastExecuteScriptRequest request) { + ValidateResult checkResult = checkFastExecuteScriptRequest(request); if (!checkResult.isPass()) { log.warn("Fast execute script request is illegal!"); @@ -101,8 +104,8 @@ public EsbResp fastExecuteScript(@AuditRequestBody EsbFastExec request.trimIps(); - TaskInstanceDTO taskInstance = buildFastScriptTaskInstance(request); - StepInstanceDTO stepInstance = buildFastScriptStepInstance(request); + TaskInstanceDTO taskInstance = buildFastScriptTaskInstance(username, appCode, request); + StepInstanceDTO stepInstance = buildFastScriptStepInstance(username, request); TaskInstanceDTO executeTaskInstance = taskExecuteService.executeFastTask( FastTaskDTO.builder().taskInstance(taskInstance).stepInstance(stepInstance).build() ); @@ -115,7 +118,6 @@ public EsbResp fastExecuteScript(@AuditRequestBody EsbFastExec } - private String generateDefaultFastTaskName() { return i18nService.getI18n("task.type.name.fast_execute_script") + "_" + DateUtils.formatLocalDateTime(LocalDateTime.now(), "yyyyMMddHHmmssSSS"); @@ -153,7 +155,9 @@ private ValidateResult checkFastExecuteScriptRequest(EsbFastExecuteScriptRequest } - private TaskInstanceDTO buildFastScriptTaskInstance(EsbFastExecuteScriptRequest request) { + private TaskInstanceDTO buildFastScriptTaskInstance(String username, + String appCode, + EsbFastExecuteScriptRequest request) { TaskInstanceDTO taskInstance = new TaskInstanceDTO(); if (StringUtils.isNotBlank(request.getName())) { taskInstance.setName(request.getName()); @@ -167,17 +171,17 @@ private TaskInstanceDTO buildFastScriptTaskInstance(EsbFastExecuteScriptRequest taskInstance.setAppId(request.getAppId()); taskInstance.setStartupMode(TaskStartupModeEnum.API.getValue()); taskInstance.setStatus(RunStatusEnum.BLANK); - taskInstance.setOperator(request.getUserName()); + taskInstance.setOperator(username); taskInstance.setCreateTime(DateUtils.currentTimeMillis()); taskInstance.setType(TaskTypeEnum.SCRIPT.getValue()); taskInstance.setCurrentStepInstanceId(0L); taskInstance.setCallbackUrl(request.getCallbackUrl()); - taskInstance.setAppCode(request.getAppCode()); + taskInstance.setAppCode(appCode); return taskInstance; } - private StepInstanceDTO buildFastScriptStepInstance(EsbFastExecuteScriptRequest request) + private StepInstanceDTO buildFastScriptStepInstance(String username, EsbFastExecuteScriptRequest request) throws ServiceException { StepInstanceDTO stepInstance = new StepInstanceDTO(); stepInstance.setAppId(request.getAppId()); @@ -219,7 +223,7 @@ private StepInstanceDTO buildFastScriptStepInstance(EsbFastExecuteScriptRequest throw new NotFoundException(ErrorCode.ACCOUNT_NOT_EXIST, ArrayUtil.toArray(request.getAccount())); } stepInstance.setAccountId(account.getId()); - stepInstance.setOperator(request.getUserName()); + stepInstance.setOperator(username); stepInstance.setCreateTime(DateUtils.currentTimeMillis()); // ESB接口默认为手工录入的本地脚本 stepInstance.setScriptSource(1); diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbGetJobInstanceListV3ResourceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbGetJobInstanceListV3ResourceImpl.java index b01e5e6aaf..6dc598fa64 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbGetJobInstanceListV3ResourceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbGetJobInstanceListV3ResourceImpl.java @@ -64,6 +64,8 @@ public EsbGetJobInstanceListV3ResourceImpl(TaskResultService taskResultService) @Override @EsbApiTimed(value = CommonMetricNames.ESB_API, extraTags = {"api_name", "v3_get_job_instance_list"}) public EsbResp> getJobInstanceListUsingPost( + String username, + String appCode, EsbGetJobInstanceListV3Request request) { ValidateResult checkResult = checkRequest(request); if (!checkResult.isPass()) { @@ -174,8 +176,6 @@ public EsbResp> getJobInstanceList(String us Integer start, Integer length) { EsbGetJobInstanceListV3Request request = new EsbGetJobInstanceListV3Request(); - request.setUserName(username); - request.setAppCode(appCode); request.setBizId(bizId); request.setScopeType(scopeType); request.setScopeId(scopeId); @@ -190,6 +190,6 @@ public EsbResp> getJobInstanceList(String us request.setIp(ip); request.setStart(start); request.setLength(length); - return getJobInstanceListUsingPost(request); + return getJobInstanceListUsingPost(username, appCode, request); } }