Skip to content

Commit

Permalink
feature: 审计事件支出输出 scope_type/scope_id #2685
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyu096 committed Jan 4, 2024
1 parent 85946fd commit 1278398
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ ext {
set('bkjobVersion', "1.0.0")
println "bkjobVersion:" + bkjobVersion
}
set('bkAuditJavaSdkVersion', "1.0.7-SNAPSHOT")
set('bkAuditJavaSdkVersion', "1.0.8")
set('mockitoVersion', "4.0.0")
set('embeddedRedisVersion', "0.6")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* 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.audit;

import com.tencent.bk.audit.filter.AuditPostFilter;
import com.tencent.bk.audit.model.AuditEvent;
import com.tencent.bk.job.common.model.dto.AppResourceScope;
import com.tencent.bk.job.common.util.JobContextUtil;
import lombok.extern.slf4j.Slf4j;

/**
* 审计事件增加 scopeType, scopeId
*/
@Slf4j
public class AddResourceScopeAuditPostFilter implements AuditPostFilter {

@Override
public AuditEvent map(AuditEvent auditEvent) {
if (auditEvent == null) {
return null;
}
AppResourceScope appResourceScope = JobContextUtil.getAppResourceScope();
if (appResourceScope != null) {
if (log.isDebugEnabled()) {
log.debug("Add resource scope for audit event, resourceScope: {}", appResourceScope);
}
auditEvent.setScopeType(appResourceScope.getType().getValue());
auditEvent.setScopeId(appResourceScope.getId());
}
return auditEvent;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.tencent.bk.audit.AuditRequestProvider;
import com.tencent.bk.audit.config.AuditAutoConfiguration;
import com.tencent.bk.audit.config.AuditProperties;
import com.tencent.bk.job.common.audit.AddResourceScopeAuditPostFilter;
import com.tencent.bk.job.common.audit.JobAuditExceptionResolver;
import com.tencent.bk.job.common.audit.JobAuditRequestProvider;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -56,4 +57,9 @@ public JobAuditExceptionResolver auditExceptionResolver() {
log.info("Init JobAuditExceptionResolver");
return new JobAuditExceptionResolver();
}

@Bean
public AddResourceScopeAuditPostFilter addResourceScopeAuditPostFilter() {
return new AddResourceScopeAuditPostFilter();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import java.util.Map;

/**
* @since 6/11/2019 10:26
* Job http 请求上下文
*/
@Data
public class JobContext {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
package com.tencent.bk.job.common.context;

/**
* @since 6/11/2019 10:26
* Job http 请求上下文托管(ThreadLocal方式)
*/
public class JobContextThreadLocal {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import java.util.Map;

/**
* @since 6/11/2019 10:27
* Job http 请求上下文工具类
*/
@Slf4j
public class JobContextUtil {
Expand Down

0 comments on commit 1278398

Please sign in to comment.