You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// PIMO is free software: you can redistribute it and/or modify
6
+
// it under the terms of the GNU General Public License as published by
7
+
// the Free Software Foundation, either version 3 of the License, or
8
+
// (at your option) any later version.
9
+
//
10
+
// PIMO is distributed in the hope that it will be useful,
11
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+
// GNU General Public License for more details.
14
+
//
15
+
// You should have received a copy of the GNU General Public License
16
+
// along with PIMO. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+
package main
19
+
20
+
import (
21
+
"os"
22
+
23
+
"github.com/spf13/cobra"
24
+
)
25
+
26
+
typeflag[Tany] struct {
27
+
namestring// Name of the flag
28
+
shorthandstring// Optional short name
29
+
variable*T// Pointer to the variable
30
+
usagestring// Description of the flag
31
+
}
32
+
33
+
// flags with default values
34
+
//
35
+
//nolint:gochecknoglobals
36
+
var (
37
+
maxBufferCapacity=64
38
+
catchErrors=""
39
+
maskingFile="masking.yml"
40
+
mockConfigFile="routes.yaml"
41
+
cachesToDump=map[string]string{}
42
+
cachesToLoad=map[string]string{}
43
+
emptyInput=false
44
+
maskingOneLiner= []string{}
45
+
profiling=""
46
+
iteration=1
47
+
repeatUntil=""
48
+
repeatWhile=""
49
+
seedValue=int64(0)
50
+
serve=""
51
+
skipLineOnError=false
52
+
skipFieldOnError=false
53
+
skipLogFile=""
54
+
statisticsDestination=os.Getenv("PIMO_STATS_URL")
55
+
statsTemplate=os.Getenv("PIMO_STATS_TEMPLATE")
56
+
xmlSubscriberName=map[string]string{}
57
+
)
58
+
59
+
//nolint:gochecknoglobals
60
+
var (
61
+
flagBufferSize=flag[int]{name: "buffer-size", variable: &maxBufferCapacity, usage: "buffer size in kB to load data from uri for each line"}
62
+
flagCatchErrors=flag[string]{name: "catch-errors", shorthand: "e", variable: &catchErrors, usage: "catch errors and write line in file, same as using skip-field-on-error + skip-log-file"}
63
+
flagConfigMasking=flag[string]{name: "config", shorthand: "c", variable: &maskingFile, usage: "name and location of the masking config file"}
64
+
flagConfigRoute=flag[string]{name: "config", shorthand: "c", variable: &mockConfigFile, usage: "name and location of the routes config file"}
65
+
flagCachesToDump=flag[map[string]string]{name: "dump-cache", variable: &cachesToDump, usage: "path for dumping cache into file"}
66
+
flagCachesToLoad=flag[map[string]string]{name: "load-cache", variable: &cachesToLoad, usage: "path for loading cache from file"}
67
+
flagEmptyInput=flag[bool]{name: "empty-input", variable: &emptyInput, usage: "generate data without any input, to use with repeat flag"}
flagProfiling=flag[string]{name: "pprof", variable: &profiling, usage: "create a pprof file - use 'cpu' to create a CPU pprof file or 'mem' to create an memory pprof file"}
70
+
flagRepeat=flag[int]{name: "repeat", shorthand: "r", variable: &iteration, usage: "number of iteration to mask each input"}
71
+
flagRepeatUntil=flag[string]{name: "repeat-until", variable: &repeatUntil, usage: "mask each input repeatedly until the given condition is met"}
72
+
flagRepeatWhile=flag[string]{name: "repeat-while", variable: &repeatWhile, usage: "mask each input repeatedly while the given condition is met"}
73
+
flagSeed=flag[int64]{name: "seed", shorthand: "s", variable: &seedValue, usage: "set global seed"}
74
+
flagServe=flag[string]{name: "serve", variable: &serve, usage: "listen/respond to HTTP interface and port instead of stdin/stdout, <ip>:<port> or :<port> to listen to all local networks"}
75
+
flagSkipLineOnError=flag[bool]{name: "skip-line-on-error", variable: &skipLineOnError, usage: "skip a line if an error occurs while masking a field"}
76
+
flagSkipFieldOnError=flag[bool]{name: "skip-field-on-error", variable: &skipFieldOnError, usage: "remove a field if an error occurs while masking this field"}
77
+
flagSkipLogFile=flag[string]{name: "skip-log-file", variable: &skipLogFile, usage: "skipped lines will be written to this log file"}
78
+
flagStatsDestination=flag[string]{name: "stats", variable: &statisticsDestination, usage: "generate execution statistics in the specified dump file"}
79
+
flagStatsTemplate=flag[string]{name: "statsTemplate", variable: &statsTemplate, usage: "template string to format stats (to include them you have to specify them as `{{ .Stats }}` like `{\"software\":\"PIMO\",\"stats\":{{ .Stats }}}`)"}
80
+
flagXMLSubscriberName=flag[map[string]string]{name: "subscriber", variable: &xmlSubscriberName, usage: "name of element to mask"}
Copy file name to clipboardExpand all lines: cmd/pimo/main.go
+73-55Lines changed: 73 additions & 55 deletions
Original file line number
Diff line number
Diff line change
@@ -42,40 +42,21 @@ import (
42
42
)
43
43
44
44
// Provisioned by ldflags
45
-
// nolint: gochecknoglobals
45
+
//
46
+
//nolint:gochecknoglobals
46
47
var (
47
48
versionstring
48
49
commitstring
49
50
buildDatestring
50
51
builtBystring
51
52
52
-
verbositystring
53
-
debugbool
54
-
jsonlogbool
55
-
colormodestring
56
-
iterationint
57
-
emptyInputbool
58
-
maskingFilestring
59
-
cachesToDumpmap[string]string
60
-
cachesToLoadmap[string]string
61
-
skipLineOnErrorbool
62
-
skipFieldOnErrorbool
63
-
skipLogFilestring
64
-
catchErrorsstring
65
-
seedValueint64
66
-
maskingOneLiner []string
67
-
repeatUntilstring
68
-
repeatWhilestring
69
-
statisticsDestinationstring
70
-
statsTemplatestring
71
-
statsDestinationEnv=os.Getenv("PIMO_STATS_URL")
72
-
statsTemplateEnv=os.Getenv("PIMO_STATS_TEMPLATE")
73
-
xmlSubscriberNamemap[string]string
74
-
servestring
75
-
maxBufferCapacityint
76
-
profilingstring
77
-
parquetInputstring
78
-
parquetOutputstring
53
+
verbositystring
54
+
debugbool
55
+
jsonlogbool
56
+
colormodestring
57
+
58
+
parquetInputstring
59
+
parquetOutputstring
79
60
)
80
61
81
62
funcmain() {
@@ -102,28 +83,31 @@ There is NO WARRANTY, to the extent permitted by law.`, version, commit, buildDa
102
83
rootCmd.PersistentFlags().BoolVar(&debug, "debug", false, "add debug information to logs (very slow)")
103
84
rootCmd.PersistentFlags().BoolVar(&jsonlog, "log-json", false, "output logs in JSON format")
104
85
rootCmd.PersistentFlags().StringVar(&colormode, "color", "auto", "use colors in log outputs : yes, no or auto")
105
-
rootCmd.PersistentFlags().IntVarP(&iteration, "repeat", "r", 1, "number of iteration to mask each input")
106
-
rootCmd.PersistentFlags().BoolVar(&emptyInput, "empty-input", false, "generate data without any input, to use with repeat flag")
107
-
rootCmd.PersistentFlags().StringVarP(&maskingFile, "config", "c", "masking.yml", "name and location of the masking-config file")
108
-
rootCmd.PersistentFlags().StringToStringVar(&cachesToDump, "dump-cache", map[string]string{}, "path for dumping cache into file")
109
-
rootCmd.PersistentFlags().StringToStringVar(&cachesToLoad, "load-cache", map[string]string{}, "path for loading cache from file")
110
-
rootCmd.PersistentFlags().BoolVar(&skipLineOnError, "skip-line-on-error", false, "skip a line if an error occurs while masking a field")
111
-
rootCmd.PersistentFlags().BoolVar(&skipFieldOnError, "skip-field-on-error", false, "remove a field if an error occurs while masking this field")
112
-
rootCmd.PersistentFlags().StringVar(&skipLogFile, "skip-log-file", "", "skipped lines will be written to this log file")
113
-
rootCmd.PersistentFlags().StringVarP(&catchErrors, "catch-errors", "e", "", "catch errors and write line in file, same as using skip-field-on-error + skip-log-file")
rootCmd.PersistentFlags().StringVar(&repeatUntil, "repeat-until", "", "mask each input repeatedly until the given condition is met")
117
-
rootCmd.PersistentFlags().StringVar(&repeatWhile, "repeat-while", "", "mask each input repeatedly while the given condition is met")
118
-
rootCmd.PersistentFlags().StringVar(&statisticsDestination, "stats", statsDestinationEnv, "generate execution statistics in the specified dump file")
119
-
rootCmd.PersistentFlags().StringVar(&statsTemplate, "statsTemplate", statsTemplateEnv, "template string to format stats (to include them you have to specify them as `{{ .Stats }}` like `{\"software\":\"PIMO\",\"stats\":{{ .Stats }}}`)")
120
-
rootCmd.Flags().StringVar(&serve, "serve", "", "listen/respond to HTTP interface and port instead of stdin/stdout, <ip>:<port> or :<port> to listen to all local networks")
121
-
rootCmd.Flags().IntVar(&maxBufferCapacity, "buffer-size", 64, "buffer size in kB to load data from uri for each line")
122
-
rootCmd.Flags().StringVar(&profiling, "pprof", "", "create a pprof file - use 'cpu' to create a CPU pprof file or 'mem' to create an memory pprof file")
86
+
87
+
addFlag(rootCmd, flagBufferSize)
88
+
addFlag(rootCmd, flagCatchErrors)
89
+
addFlag(rootCmd, flagConfigMasking)
90
+
addFlag(rootCmd, flagCachesToDump)
91
+
addFlag(rootCmd, flagCachesToLoad)
92
+
addFlag(rootCmd, flagEmptyInput)
93
+
addFlag(rootCmd, flagMaskOneLiner)
94
+
addFlag(rootCmd, flagProfiling)
95
+
addFlag(rootCmd, flagRepeat)
96
+
addFlag(rootCmd, flagRepeatUntil)
97
+
addFlag(rootCmd, flagRepeatWhile)
98
+
addFlag(rootCmd, flagSeed)
99
+
addFlag(rootCmd, flagServe)
100
+
addFlag(rootCmd, flagSkipFieldOnError)
101
+
addFlag(rootCmd, flagSkipLineOnError)
102
+
addFlag(rootCmd, flagSkipLogFile)
103
+
addFlag(rootCmd, flagStatsDestination)
104
+
addFlag(rootCmd, flagStatsTemplate)
123
105
124
106
rootCmd.AddCommand(&cobra.Command{
125
-
Use: "jsonschema",
107
+
Use: "jsonschema",
108
+
Short: "Export schema of masking configuration",
126
109
Run: func(cmd*cobra.Command, args []string) {
110
+
initLog()
127
111
jsonschema, err:=pimo.GetJsonSchema()
128
112
iferr!=nil {
129
113
os.Exit(8)
@@ -135,8 +119,11 @@ There is NO WARRANTY, to the extent permitted by law.`, version, commit, buildDa
135
119
xmlCmd:=&cobra.Command{
136
120
Use: "xml",
137
121
Short: "Parsing and masking XML file",
138
-
Run: func(cmd*cobra.Command, args []string) {
122
+
Run: func(cmd*cobra.Command, _ []string) {
139
123
initLog()
124
+
ifmaxBufferCapacity>0 {
125
+
uri.MaxCapacityForEachLine=maxBufferCapacity*1024
126
+
}
140
127
iflen(catchErrors) >0 {
141
128
skipLineOnError=true
142
129
skipLogFile=catchErrors
@@ -185,8 +172,18 @@ There is NO WARRANTY, to the extent permitted by law.`, version, commit, buildDa
185
172
}
186
173
},
187
174
}
188
-
xmlCmd.Flags().StringToStringVar(&xmlSubscriberName, "subscriber", map[string]string{}, "name of element to mask")
0 commit comments