-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e5ea279
commit a470130
Showing
8 changed files
with
213 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
auth_enabled: false | ||
|
||
server: | ||
http_listen_port: 3100 | ||
|
||
ingester: | ||
lifecycler: | ||
address: 127.0.0.1 | ||
ring: | ||
kvstore: | ||
store: inmemory | ||
replication_factor: 1 | ||
final_sleep: 0s | ||
chunk_idle_period: 5m | ||
chunk_retain_period: 30s | ||
|
||
schema_config: | ||
configs: | ||
- from: 2020-01-01 | ||
store: boltdb | ||
object_store: filesystem | ||
schema: v9 | ||
index: | ||
prefix: index_ | ||
period: 168h # 每张表的时间范围6天 | ||
|
||
storage_config: | ||
boltdb: | ||
directory: /data/loki/index # 索引文件存储地址 | ||
|
||
filesystem: | ||
directory: /data/loki/chunks # 块存储地址 | ||
|
||
limits_config: | ||
enforce_metric_name: false | ||
reject_old_samples: true | ||
reject_old_samples_max_age: 168h | ||
|
||
chunk_store_config: | ||
max_look_back_period: 0s | ||
|
||
table_manager: | ||
retention_deletes_enabled: false | ||
retention_period: 0s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
server: | ||
http_listen_port: 9080 | ||
grpc_listen_port: 0 | ||
|
||
# Positions | ||
positions: | ||
filename: /data/loki/positions.yaml | ||
|
||
# Loki服务器的地址 | ||
clients: | ||
- url: http://127.0.0.1:3100/loki/api/v1/push | ||
|
||
scrape_configs: | ||
- job_name: go-gin-api | ||
static_configs: | ||
- targets: | ||
- localhost | ||
labels: | ||
job: accesslog | ||
__path__: /data/logs/*.log # 日志目录 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
## DDM | ||
|
||
动态数据掩码(Dynamic Data Masking,简称为DDM)能够防止把敏感数据暴露给未经授权的用户。 | ||
|
||
| 类型 | 要求 | 示例 | 说明 | ||
| ---- | ---- | ---- | ---- | ||
| 手机号 | 前 3 后 4 | 132****7986 | 定长 11 位数字 | ||
| 邮箱地址 | 前 1 后 1 | l**[email protected] | 仅对 @ 之前的邮箱名称进行掩码 | ||
| 姓名 | 隐姓 | *鸿章 | 将姓氏隐藏 | ||
| 密码 | 不输出 | ****** | | ||
| 银行卡卡号 | 前 6 后 4 | 622888******5676 | 银行卡卡号最多 19 位数字 | ||
| 身份证号 | 前 1 后 1 | 1******7 | 定长 18 位 | ||
|
||
#### 代码示例 | ||
|
||
``` | ||
// 返回值 | ||
type message struct { | ||
Email ddm.Email `json:"email"` | ||
} | ||
msg := new(message) | ||
msg.Email = ddm.Email("[email protected]") | ||
... | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package ddm | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
func (m Mobile) MarshalJSON() ([]byte, error) { | ||
if len(m) != 11 { | ||
return []byte(`"` + m + `"`), nil | ||
} | ||
|
||
v := fmt.Sprintf("%s****%s", m[:3], m[len(m)-4:]) | ||
return []byte(`"` + v + `"`), nil | ||
} | ||
|
||
func (bc BankCard) MarshalJSON() ([]byte, error) { | ||
if len(bc) > 19 || len(bc) < 16 { | ||
return []byte(`"` + bc + `"`), nil | ||
} | ||
|
||
v := fmt.Sprintf("%s******%s", bc[:6], bc[len(bc)-4:]) | ||
return []byte(`"` + v + `"`), nil | ||
} | ||
|
||
func (card IDCard) MarshalJSON() ([]byte, error) { | ||
if len(card) != 18 { | ||
return []byte(`"` + card + `"`), nil | ||
} | ||
|
||
v := fmt.Sprintf("%s******%s", card[:1], card[len(card)-1:]) | ||
return []byte(`"` + v + `"`), nil | ||
} | ||
|
||
func (name IDName) MarshalJSON() ([]byte, error) { | ||
if len(name) < 1 { | ||
return []byte(`""`), nil | ||
} | ||
|
||
nameRune := []rune(name) | ||
v := fmt.Sprintf("*%s", string(nameRune[1:])) | ||
return []byte(`"` + v + `"`), nil | ||
} | ||
|
||
func (pw PassWord) MarshalJSON() ([]byte, error) { | ||
v := "******" | ||
return []byte(`"` + v + `"`), nil | ||
} | ||
|
||
func (e Email) MarshalJSON() ([]byte, error) { | ||
if !strings.Contains(string(e), "@") { | ||
return []byte(`"` + e + `"`), nil | ||
} | ||
|
||
split := strings.Split(string(e), "@") | ||
if len(split[0]) < 1 || len(split[1]) < 1 { | ||
return []byte(`"` + e + `"`), nil | ||
} | ||
|
||
v := fmt.Sprintf("%s***%s", split[0][:1], split[0][len(split[0])-1:]) | ||
return []byte(`"` + v + "@" + split[1] + `"`), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package ddm | ||
|
||
// 手机号 132****7986 | ||
type Mobile string | ||
|
||
// 银行卡号 622888******5676 | ||
type BankCard string | ||
|
||
// 身份证号 1******7 | ||
type IDCard string | ||
|
||
// 姓名 *鸿章 | ||
// TODO:参考 https://blog.thinkeridea.com/201910/go/efficient_string_truncation.html | ||
// Deprecated:有更好的性能选择 | ||
type IDName string | ||
|
||
// 密码 ****** | ||
type PassWord string | ||
|
||
// 邮箱 l***[email protected] | ||
type Email string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package ddm | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
) | ||
|
||
type message struct { | ||
Name IDName `json:"name"` | ||
Mobile Mobile `json:"mobile"` | ||
IDCard IDCard `json:"id_card"` | ||
PassWord PassWord `json:"password"` | ||
Email Email `json:"email"` | ||
BankCard1 BankCard `json:"bank_card_1"` | ||
BankCard2 BankCard `json:"bank_card_2"` | ||
BankCard3 BankCard `json:"bank_card_3"` | ||
} | ||
|
||
func TestMarshalJSON(t *testing.T) { | ||
msg := new(message) | ||
msg.Name = IDName("李鸿章") | ||
msg.Mobile = Mobile("13288887986") | ||
msg.IDCard = IDCard("125252525252525252") | ||
msg.PassWord = PassWord("123456") | ||
msg.Email = Email("[email protected]") | ||
msg.BankCard1 = BankCard("6545654565456545") | ||
msg.BankCard2 = BankCard("65485269874569852") | ||
msg.BankCard3 = BankCard("6548526987456985298") | ||
|
||
marshal, _ := json.Marshal(msg) | ||
t.Log(string(marshal)) | ||
} |