Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
transactionLogMask
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
王海鹰
transactionLogMask
Commits
7582bbaa
Commit
7582bbaa
authored
Oct 21, 2020
by
王海鹰
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
<dev> 设置从配置文件中读取参数
parent
1e097d43
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
104 additions
and
25 deletions
+104
-25
src/main/java/com/zorkdata/datamask/TransactionLogMask.java
src/main/java/com/zorkdata/datamask/TransactionLogMask.java
+16
-9
src/main/java/com/zorkdata/datamask/constants/Constants.java
src/main/java/com/zorkdata/datamask/constants/Constants.java
+8
-2
src/main/java/com/zorkdata/datamask/util/AvroTest.java
src/main/java/com/zorkdata/datamask/util/AvroTest.java
+20
-1
src/main/java/com/zorkdata/datamask/util/MaskUtil.java
src/main/java/com/zorkdata/datamask/util/MaskUtil.java
+1
-1
src/main/java/com/zorkdata/datamask/util/ZorkParameterUtil.java
...in/java/com/zorkdata/datamask/util/ZorkParameterUtil.java
+1
-1
src/main/resources/application.properties
src/main/resources/application.properties
+23
-0
src/main/resources/application.yml
src/main/resources/application.yml
+35
-11
No files found.
src/main/java/com/zorkdata/datamask/TransactionLogMask.java
View file @
7582bbaa
...
@@ -63,6 +63,14 @@ public class TransactionLogMask {
...
@@ -63,6 +63,14 @@ public class TransactionLogMask {
private
static
Long
startTime
;
private
static
Long
startTime
;
private
static
Long
endTime
;
private
static
Long
endTime
;
private
static
String
namePattern
=
""
;
private
static
String
mobilePattern
=
""
;
private
static
String
phonePattern
=
""
;
private
static
String
emailPattern
=
""
;
public
static
void
main
(
String
[]
args
)
throws
Exception
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
if
(
"hdfs"
.
equals
(
source
))
{
if
(
"hdfs"
.
equals
(
source
))
{
maskHdfsLog
(
args
);
maskHdfsLog
(
args
);
...
@@ -126,15 +134,14 @@ public class TransactionLogMask {
...
@@ -126,15 +134,14 @@ public class TransactionLogMask {
LogData
logData
=
JSON
.
parseObject
(
value
.
getField
(
0
).
toString
(),
new
TypeReference
<
LogData
>()
{
LogData
logData
=
JSON
.
parseObject
(
value
.
getField
(
0
).
toString
(),
new
TypeReference
<
LogData
>()
{
});
});
//根据日志事件的核心信息做过滤
//根据日志事件的核心信息做过滤
if
(
null
!=
core
&&
logData
.
getDimensions
().
get
(
"hostname"
).
indexOf
(
"c9"
)
==
-
1
)
{
if
(
null
!=
core
&&
logData
.
getDimensions
().
get
(
"hostname"
).
indexOf
(
"c9"
)
>
-
1
)
{
return
;
//根据日志事件的timestamp做过滤
}
Long
timestamp
=
utc2timestamp
(
logData
.
getTimestamp
());
//根据日志事件的timestamp做过滤
if
(
null
!=
timestamp
&&
timestamp
>
startTime
&&
timestamp
<
endTime
||
Boolean
.
TRUE
)
{
Long
timestamp
=
utc2timestamp
(
logData
.
getTimestamp
());
Map
maskResult
=
MaskUtil
.
mask
(
logData
.
getNormalFields
());
if
(
null
!=
timestamp
&&
timestamp
>
startTime
&&
timestamp
<
endTime
||
Boolean
.
TRUE
)
{
logData
.
setNormalFields
(
maskResult
);
Map
maskResult
=
MaskUtil
.
mask
(
logData
.
getNormalFields
());
collector
.
collect
(
logData
);
logData
.
setNormalFields
(
maskResult
);
}
collector
.
collect
(
logData
);
}
}
}
}
});
});
...
...
src/main/java/com/zorkdata/datamask/constants/Constants.java
View file @
7582bbaa
...
@@ -12,6 +12,12 @@ public interface Constants {
...
@@ -12,6 +12,12 @@ public interface Constants {
String
HDFS_DEST
=
"hdfs_dest"
;
String
HDFS_DEST
=
"hdfs_dest"
;
String
CORE
=
"core"
;
String
CORE
=
"core"
;
String
DATE
=
"date"
;
String
DATE
=
"date"
;
String
START_TIME
=
"startTime"
;
String
START_TIME
=
"start_time"
;
String
END_TIME
=
"endTime"
;
String
END_TIME
=
"end_time"
;
String
NAME_REG_EXP
=
"name_reg_exp"
;
String
MOBILE_REG_EXP
=
"mobile_reg_exp"
;
String
PHONE_REG_EXP
=
"phone_reg_exp"
;
String
EMAIL_REG_EXP
=
"email_reg_exp"
;
}
}
src/main/java/com/zorkdata/datamask/util/AvroTest.java
View file @
7582bbaa
...
@@ -18,7 +18,11 @@ import org.apache.avro.specific.SpecificDatumReader;
...
@@ -18,7 +18,11 @@ import org.apache.avro.specific.SpecificDatumReader;
import
org.apache.avro.specific.SpecificDatumWriter
;
import
org.apache.avro.specific.SpecificDatumWriter
;
import
java.io.*
;
import
java.io.*
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.TimeZone
;
/**
/**
* Description :
* Description :
...
@@ -146,7 +150,7 @@ public class AvroTest {
...
@@ -146,7 +150,7 @@ public class AvroTest {
Schema
schema
=
new
Schema
.
Parser
().
parse
(
new
File
(
"d:\\log.avro"
));
Schema
schema
=
new
Schema
.
Parser
().
parse
(
new
File
(
"d:\\log.avro"
));
GenericRecord
emp
=
new
GenericData
.
Record
(
schema
);
GenericRecord
emp
=
new
GenericData
.
Record
(
schema
);
File
file
=
new
File
(
"d:\\
part-0-0
.avro"
);
File
file
=
new
File
(
"d:\\
1 (1)
.avro"
);
DatumReader
<
GenericRecord
>
datumReader
=
new
GenericDatumReader
<
GenericRecord
>(
schema
);
DatumReader
<
GenericRecord
>
datumReader
=
new
GenericDatumReader
<
GenericRecord
>(
schema
);
DataFileReader
<
GenericRecord
>
dataFileReader
=
new
DataFileReader
<
GenericRecord
>(
file
,
datumReader
);
DataFileReader
<
GenericRecord
>
dataFileReader
=
new
DataFileReader
<
GenericRecord
>(
file
,
datumReader
);
...
@@ -156,5 +160,20 @@ public class AvroTest {
...
@@ -156,5 +160,20 @@ public class AvroTest {
emp
=
dataFileReader
.
next
();
emp
=
dataFileReader
.
next
();
System
.
out
.
println
(
emp
);
System
.
out
.
println
(
emp
);
}
}
// Long aLong = utc2Local("2020-09-29T09:36:20.626+08:00");
// System.out.println(aLong);
}
public
static
Long
utc2Local
(
String
utcTime
)
{
SimpleDateFormat
utcFormater
=
new
SimpleDateFormat
(
"yyyy-MM-dd'T'HH:mm:ss.SSS+08:00"
);
utcFormater
.
setTimeZone
(
TimeZone
.
getTimeZone
(
"UTC"
));
//时区定义并进行时间获取
Date
gpsUTCDate
=
null
;
try
{
gpsUTCDate
=
utcFormater
.
parse
(
utcTime
);
}
catch
(
ParseException
e
)
{
System
.
out
.
println
(
"时间戳格式转换异常:"
+
utcTime
+
e
.
getMessage
());
}
return
gpsUTCDate
.
getTime
();
}
}
}
}
src/main/java/com/zorkdata/datamask/util/MaskUtil.java
View file @
7582bbaa
...
@@ -20,7 +20,7 @@ public class MaskUtil {
...
@@ -20,7 +20,7 @@ public class MaskUtil {
/**
/**
* 姓名正则
* 姓名正则
*/
*/
static
Pattern
namePattern
=
Pattern
.
compile
(
"([\\u4e00-\u9fa5]{1,20}|[a-zA-Z\\.\\s]{1,20})"
);
static
Pattern
namePattern
=
Pattern
.
compile
(
"([\\u4e00-\
\
u9fa5]{1,20}|[a-zA-Z\\.\\s]{1,20})"
);
// Pattern namePattern = Pattern.compile(maskRegexConfig.getNameRegExp());
// Pattern namePattern = Pattern.compile(maskRegexConfig.getNameRegExp());
/**
/**
* 手机号正则
* 手机号正则
...
...
src/main/java/com/zorkdata/datamask/util/ZorkParameterUtil.java
View file @
7582bbaa
...
@@ -34,7 +34,7 @@ public class ZorkParameterUtil {
...
@@ -34,7 +34,7 @@ public class ZorkParameterUtil {
logger
.
info
(
"read config path is "
+
configPath
);
logger
.
info
(
"read config path is "
+
configPath
);
if
(!
configPath
.
endsWith
(
"y
a
ml"
))
{
if
(!
configPath
.
endsWith
(
"yml"
))
{
System
.
err
.
println
(
"Please input correct configuration file and flink run mode!"
);
System
.
err
.
println
(
"Please input correct configuration file and flink run mode!"
);
System
.
exit
(-
1
);
System
.
exit
(-
1
);
}
else
{
}
else
{
...
...
src/main/resources/application.properties
0 → 100644
View file @
7582bbaa
# 不做脱敏的字段白名单
fieldsWhiteList
=
fundid,custid,orgid,brhid,secuid,bankcode,market,ordersno,ordergroup,count,poststr,stkcode,bsflag,
\
orderamt,price,qty,bankcode,tacode,ofcode,transacc,taacc
# 脱敏用的正则表达式
# 姓名正则
nameRegExp
=
"[
\一
-龥]{1,20}|[a-zA-Z
\\
.
\\
s]{1,20}"
# 手机号正则
mobileRegExp
=
"(13[0-9])|(14[5,7])|(15[0-3,5-9])|(17[0,3,5-8])|(18[0-9])|(147))
\\
d{8}"
# 电话号码正则
phoneRegExp
=
"(
\\
d{3,4}-)?
\\
d{6,8}"
# 邮箱正则
emailRegExp
=
"
\\
w+([-+.]
\\
w+)*@
\\
w+([-.]
\\
w+)*
\\
.
\\
w+([-.]
\\
w+)*"
# 身份证号码(15位)正则
idRegExp15
=
"[1-9]
\\
d{7}((0
\\
d)|(1[0-2]))(([0|1|2]
\\
d)|3[0-1])
\\
d{3}"
#身份证号码(18位)正则
idRegExp18
=
"[1-9]
\\
d{5}[1-9]
\\
d{3}((0
\\
d)|(1[0-2]))(([0|1|2]
\\
d)|3[0-1])
\\
d{3}([0-9Xx])"
# 家庭住址正则
addressRegExp
=
"([
\一
-
\龥
A-Za-z0-9_]+(省|市|区|县|道|路|街|号|弄|条|室)){2,}"
# ip地址正则
ipRegExp
=
"((2[0-4]
\\
d|25[0-5]|[01]?
\\
d
\\
d?)
\\
.){3}(2[0-4]
\\
d|25[0-5]|[01]?
\\
d
\\
d?)"
# mac地址正则
macRegExp
=
"([A-Fa-f0-9]{2}-){5}[A-Fa-f0-9]{2}"
\ No newline at end of file
src/main/resources/application.yml
View file @
7582bbaa
# 日志来源,支持hdfs和kafka,必传
source
:
"
hdfs"
# hdfs日志源文件地址,若source为hdfs,则该地址必传
hdfs_src
:
"
hdfs://cdh-2:8020/tmp/datawarehouse4/jzjy/kcbp_biz_log"
# hdfs日志写入地址,非必传,默认写到hdfs-src目录下的output目录下
hdfs_dest
:
"
hdfs://cdh-2:8020/tmp/datawarehouse/jzjy/kcbp_biz_log/output2/"
# 脱敏结果下载到的本地路径
download_path
:
"
/tmp"
# 交易日志的“核心”信息,值以c开头、后面是数字序号,非必传
core
:
"
c9"
# 查询日志日期(默认为当天),非必传
date
:
20200929
# 查询日志起始时间戳,非必传
start_time
:
1601348849900
# 查询日志结束时间戳,非必传
end_time
:
1601348850000
# 不做脱敏的字段白名单
# 不做脱敏的字段白名单
fieldsWhiteList
=
fundid,custid,orgid,brhid,secuid,bankcode,market,ordersno,ordergroup,count,poststr,stkcode,bsflag,\
fieldsWhiteList
:
"
fundid,custid,orgid,brhid,secuid,bankcode,market,ordersno,ordergroup,count,poststr,stkcode,bsflag,
\
orderamt,price,qty,bankcode,tacode,ofcode,transacc,taacc
orderamt,price,qty,bankcode,tacode,ofcode,transacc,taacc
"
# 脱敏用的正则表达式
# 脱敏用的正则表达式
# 姓名正则
# 姓名正则
nameRegExp
= "[\一-龥
]{1,20}|[a-zA-Z\\.\\s]{1,20}"
nameRegExp
:
"
[
\u4e00
-
\u9fa5
]{1,20}|[a-zA-Z
\\
.
\\
s]{1,20}"
# 手机号正则
# 手机号正则
mobileRegExp
=
"(13[0-9])|(14[5,7])|(15[0-3,5-9])|(17[0,3,5-8])|(18[0-9])|(147))\\d{8}"
mobileRegExp
:
"
(13[0-9])|(14[5,7])|(15[0-3,5-9])|(17[0,3,5-8])|(18[0-9])|(147))
\\
d{8}"
# 电话号码正则
# 电话号码正则
phoneRegExp
=
"(\\d{3,4}-)?\\d{6,8}"
phoneRegExp
:
"
(
\\
d{3,4}-)?
\\
d{6,8}"
# 邮箱正则
# 邮箱正则
emailRegExp
=
"\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*"
emailRegExp
:
"
\\
w+([-+.]
\\
w+)*@
\\
w+([-.]
\\
w+)*
\\
.
\\
w+([-.]
\\
w+)*"
# 身份证号码(15位)正则
# 身份证号码(15位)正则
idRegExp15
=
"[1-9]\\d{7}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}"
idRegExp15
:
"
[1-9]
\\
d{7}((0
\\
d)|(1[0-2]))(([0|1|2]
\\
d)|3[0-1])
\\
d{3}"
#身份证号码(18位)正则
#身份证号码(18位)正则
idRegExp18
=
"[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}([0-9Xx])"
idRegExp18
:
"
[1-9]
\\
d{5}[1-9]
\\
d{3}((0
\\
d)|(1[0-2]))(([0|1|2]
\\
d)|3[0-1])
\\
d{3}([0-9Xx])"
# 家庭住址正则
# 家庭住址正则
addressRegExp
= "([\一-\龥
A-Za-z0-9_]+(省|市|区|县|道|路|街|号|弄|条|室)){2,}"
addressRegExp
:
"
([
\u4E00
-
\u9FA5
A-Za-z0-9_]+(省|市|区|县|道|路|街|号|弄|条|室)){2,}"
# ip地址正则
# ip地址正则
ipRegExp
=
"((2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.){3}(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)"
ipRegExp
:
"
((2[0-4]
\\
d|25[0-5]|[01]?
\\
d
\\
d?)
\\
.){3}(2[0-4]
\\
d|25[0-5]|[01]?
\\
d
\\
d?)"
# mac地址正则
# mac地址正则
macRegExp = "([A-Fa-f0-9]{2}-){5}[A-Fa-f0-9]{2}"
macRegExp
:
"
([A-Fa-f0-9]{2}-){5}[A-Fa-f0-9]{2}"
\ No newline at end of file
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment