Debian Codegraph @

core/config.go

raw
1 package core
2
3 import "sort"
4
5 type ConfigLogStreams map[string]ConfigLogStream
6
7 type ConfigLogStream struct {
8 // HostAddr is the actual host to connect to.
9 //
10 // If empty, we'll resort to the ssh config, and if there's no info for that
11 // host either, we'll try to get host addr from the key in
12 // ConfigLogStreams.LogStreams.
13 Hostname string `yaml:"hostname"`
14
15 // Port is the actual port to connect to. If empty, the same overriding rules
16 // apply.
17 Port string `yaml:"port"`
18
19 // User is the user to authenticate as. If empty, same overriding rules
20 // apply.
21 User string `yaml:"user"`
22
23 // TODO: optional Jumphost configuration, also with addr and user.
24
25 // LogFiles contains a list of files which are part of the logstream, like
26 // ["/var/log/syslog", "/var/log/syslog.1"]. The [0]th item is the latest log
27 // file [1]st is the previous one, etc.
28 //
29 // During the final usage (after resolving everything), it must contain at
30 // least a single item, otherwise LogStream is invalid. However in the configs,
31 // it's optional (and eventually, if empty, will be set to default values by
32 // the LStreamsResolver).
33 LogFiles []string `yaml:"log_files"`
34
35 Options ConfigLogStreamOptions `yaml:"options"`
36 }
37
38 // ConfigLogStreamOptions contains additional options for a particular logstream.
39 type ConfigLogStreamOptions struct {
40 // Sudo is a shortcut for SudoMode: if Sudo is true, it's an equivalent of
41 // setting SudoMode to SudoModeFull.
42 Sudo bool `yaml:"sudo,omitempty"`
43
44 // SudoMode can be used to configure nerdlog to read log files with "sudo -n".
45 // See constants for the SudoMode type for more details.
46 SudoMode SudoMode `yaml:"sudo_mode,omitempty"`
47
48 // ShellInit can contain arbitrary shell commands which will be executed
49 // right after connecting to the host. A common use case is setting
50 // custom env vars for tests, like: "export TZ=America/New_York", but
51 // might be useful outside of tests as well.
52 ShellInit []string `yaml:"shell_init,omitempty"`
53 }
54
55 func (lss ConfigLogStreams) Keys() []string {
56 keys := make([]string, 0, len(lss))
57 for k := range lss {
58 keys = append(keys, k)
59 }
60
61 sort.Strings(keys)
62
63 return keys
64 }
65
66 // EffectiveSudoMode returns the SudoMode considering all fields that can
67 // affect it: Sudo and SudoMode.
68 func (opts ConfigLogStreamOptions) EffectiveSudoMode() SudoMode {
69 if opts.SudoMode != "" {
70 return opts.SudoMode
71 }
72
73 if opts.Sudo {
74 return SudoModeFull
75 }
76
77 return ""
78 }