No flags found
Use flags to group coverage reports by test type, project and/or folders.
Then setup custom commit statuses and notifications for each flag.
e.g., #unittest #integration
#production #enterprise
#frontend #backend
db80781
... +249 ...
0ecaa86
Use flags to group coverage reports by test type, project and/or folders.
Then setup custom commit statuses and notifications for each flag.
e.g., #unittest #integration
#production #enterprise
#frontend #backend
1 | + | package command |
|
2 | + | ||
3 | + | import ( |
|
4 | + | "fmt" |
|
5 | + | "os" |
|
6 | + | "strings" |
|
7 | + | "time" |
|
8 | + | ) |
|
9 | + | ||
10 | + | const ( |
|
11 | + | minTimeout = 1 |
|
12 | + | maxTimeout = 300 |
|
13 | + | defaultTimeout = 30 |
|
14 | + | ) |
|
15 | + | ||
16 | + | var ( |
|
17 | + | config Config |
|
18 | + | ) |
|
19 | + | ||
20 | + | // Command define the configuration for a specific commands |
|
21 | + | type Command struct { |
|
22 | + | // Path is the command path as defined in the hook configuration |
|
23 | + | Path string `json:"path" mapstructure:"path"` |
|
24 | + | // Timeout specifies a time limit, in seconds, for the command execution. |
|
25 | + | // This value overrides the global timeout if set. |
|
26 | + | // Do not use variables with the SFTPGO_ prefix to avoid conflicts with env |
|
27 | + | // vars that SFTPGo sets |
|
28 | + | Timeout int `json:"timeout" mapstructure:"timeout"` |
|
29 | + | // Env defines additional environment variable for the commands. |
|
30 | + | // Each entry is of the form "key=value". |
|
31 | + | // These values are added to the global environment variables if any |
|
32 | + | Env []string `json:"env" mapstructure:"env"` |
|
33 | + | } |
|
34 | + | ||
35 | + | // Config defines the configuration for external commands such as |
|
36 | + | // program based hooks |
|
37 | + | type Config struct { |
|
38 | + | // Timeout specifies a global time limit, in seconds, for the external commands execution |
|
39 | + | Timeout int `json:"timeout" mapstructure:"timeout"` |
|
40 | + | // Env defines additional environment variable for the commands. |
|
41 | + | // Each entry is of the form "key=value". |
|
42 | + | // Do not use variables with the SFTPGO_ prefix to avoid conflicts with env |
|
43 | + | // vars that SFTPGo sets |
|
44 | + | Env []string `json:"env" mapstructure:"env"` |
|
45 | + | // Commands defines configuration for specific commands |
|
46 | + | Commands []Command `json:"commands" mapstructure:"commands"` |
|
47 | + | } |
|
48 | + | ||
49 | + | func init() { |
|
50 | + | config = Config{ |
|
51 | + | Timeout: defaultTimeout, |
|
52 | + | } |
|
53 | + | } |
|
54 | + | ||
55 | + | // Initialize configures commands |
|
56 | + | func (c Config) Initialize() error { |
|
57 | + | if c.Timeout < minTimeout || c.Timeout > maxTimeout { |
|
58 | + | return fmt.Errorf("invalid timeout %v", c.Timeout) |
|
59 | + | } |
|
60 | + | for _, env := range c.Env { |
|
61 | + | if len(strings.Split(env, "=")) != 2 { |
|
62 | + | return fmt.Errorf("invalid env var %#v", env) |
|
63 | + | } |
|
64 | + | } |
|
65 | + | for idx, cmd := range c.Commands { |
|
66 | + | if cmd.Path == "" { |
|
67 | + | return fmt.Errorf("invalid path %#v", cmd.Path) |
|
68 | + | } |
|
69 | + | if cmd.Timeout == 0 { |
|
70 | + | c.Commands[idx].Timeout = c.Timeout |
|
71 | + | } else { |
|
72 | + | if cmd.Timeout < minTimeout || cmd.Timeout > maxTimeout { |
|
73 | + | return fmt.Errorf("invalid timeout %v for command %#v", cmd.Timeout, cmd.Path) |
|
74 | + | } |
|
75 | + | } |
|
76 | + | for _, env := range cmd.Env { |
|
77 | + | if len(strings.Split(env, "=")) != 2 { |
|
78 | + | return fmt.Errorf("invalid env var %#v for command %#v", env, cmd.Path) |
|
79 | + | } |
|
80 | + | } |
|
81 | + | } |
|
82 | + | config = c |
|
83 | + | return nil |
|
84 | + | } |
|
85 | + | ||
86 | + | // GetConfig returns the configuration for the specified command |
|
87 | + | func GetConfig(command string) (time.Duration, []string) { |
|
88 | + | env := os.Environ() |
|
89 | + | timeout := time.Duration(config.Timeout) * time.Second |
|
90 | + | env = append(env, config.Env...) |
|
91 | + | for _, cmd := range config.Commands { |
|
92 | + | if cmd.Path == command { |
|
93 | + | timeout = time.Duration(cmd.Timeout) * time.Second |
|
94 | + | env = append(env, cmd.Env...) |
|
95 | + | break |
|
96 | + | } |
|
97 | + | } |
|
98 | + | ||
99 | + | return timeout, env |
|
100 | + | } |
Learn more Showing 68 files with coverage changes found.
sftpd/handler.go
sftpd/server.go
telemetry/telemetry.go
common/connection.go
config/config_linux.go
sftpd/sftpd.go
httpd/api_maintenance.go
httpd/auth_utils.go
httpd/httpd.go
httpd/api_user.go
httpd/api_folder.go
ftpd/server.go
config/config.go
httpd/server.go
webdavd/handler.go
webdavd/webdavd.go
sftpd/ssh_cmd.go
webdavd/server.go
httpd/api_admin.go
httpd/web.go
sftpd/transfer.go
httpd/middleware.go
common/tlsutils.go
ftpd/ftpd.go
common/httpauth.go
sftpd/lister.go
httpd/api_utils.go
webdavd/file.go
httpd/api_quota.go
telemetry/router.go
httpd/api_defender.go
ftpd/transfer.go
webdavd/mimecache.go
common/transfer.go
sftpd/cmd_unix.go
common/actions.go
common/common.go
ftpd/handler.go
common/defender.go
sftpd/subsystem.go
httpd/handler.go
config/config_nolinux.go
command/command.go
httpd/file.go
httpd/oidcmanager.go
httpd/api_retention.go
httpd/api_mfa.go
common/dataretention.go
sftpd/middleware.go
common/ratelimiter.go
httpd/api_shares.go
httpd/flash.go
httpd/api_group.go
common/clientsmap.go
mfa/totp.go
common/defendermem.go
common/defenderdb.go
httpd/api_keys.go
mfa/mfa.go
common/transferschecker.go
httpd/api_events.go
httpd/oidc.go
httpd/api_http_user.go
httpd/webadmin.go
httpd/webclient.go
httpd/resetcode.go
httpd/api_metadata.go
sftpd/scp.go
0ecaa86
751946f
796ea1d
a87aa9b
9abd186
18d0bf9
c9bd08c
d2f4edc
67abf03
5d7f696
4bea9ed
4995cf1
a5d0cbb
7b1a0d3
1e0b3a2
e72bb1e
1646212
737109b
8b8e27b
4b09964
80da2dc
61947e6
9a37e3d
14fb6c4
dd9c5b2
ecd488a
4a44a7d
16a44a1
97f8142
504cd3e
857b6cc
002a066
5bc0f4f
cacfffc
87d7854
aa34388
a3f5002
f9d8b83
7c8bb5b
254b2ae
5a40f99
77f3400
3521bac
55f8171
a7b159a
5c114b2
e079444
3cb23ac
8fb256a
ca32cd5
e0defaf
5cccb87
aaf940e
853086b
81bdba6
d955ddc
4bbb195
a193089
9bfdc10
b062b38
a31a9dc
fa43791
93b9c16
4c710d7
d9f30e7
03da7f6
883a3dc
7b86e2a
8502d7b
6f8b71b
7e7f662
0bec1c6
5582f5c
48ed3da
d8de0fa
df828b6
056daad
5c2fd8d
4519bff
1ea7429
816c174
79857a8
dcc3292
7f674a7
b64d3c2
7fc5cb8
92460f8
e18ad55
4e9dae6
f5a0559
670018f
8bbf54d
d31cccf
c19b03a
c6b8644
f1a255a
876bf8a
900e519
f1832d4
ebbbf81
1fccd05
66945c0
fa0ca8f
c478c7d
9382db7
7e2a8e7
cd35636
d51adb0
02db00d
fb2d59e
1df1225
aca71bf
9709aed
d2a4178
d73be7a
ffe7f7f
a6ed6fc
c3831de
9b6b9cc
64d1ea2
1c51239
51c15de
b8efb1b
ec1d20f
1f619d5
6d3d94a
0a3d94f
7c68b03
2912b2e
a6fe802
ad483b7
df86955
00ec426
222db53
4d85dc1
6d582a8
794afbf
e3f3997
f78090e
4d7a4aa
c36217c
59bb578
7d88233
8174349
00a02dc
ced73ed
cc73bb8
a587228
1472a0f
0bb1419
c153330
5b4ef0e
9632b6e
78eb1c1
a7c0b07
dc1cc88
3f5451e
30d9832
bedc8e2
6092b66
6ee51c5
4df0ae8
5db31f0
0f8170c
3c24cb7
bec54ac
c330ac8
3e478f4
18ab757
b6bcf0c
015aa36
f2480ce
f828c58
dc19921
3f3591b
fc04872
aeb4675
4652f9e
531cb5b
9fb43b2
8a8298a
3d6b09e
fb8f013
c41319b
46157eb
200b1d0
24b0352
52f3a98
e29a3ef
ca730e7
0833b46
ee5c5e0
78233ff
b331dc5
dfcfcee
094ee15
3bc58f5
f6938e7
570964d
31984ff
74fc3aa
97d0a48
3bbe675
f131ef1
4a6a4ce
a80ac80
4aa9686
64e87d6
9ca0b46
6eb154b
ea01c3a
1b4a1fb