summaryrefslogtreecommitdiff
path: root/internal/config/client.go
blob: 60c7bc565a605e7cf4ebfdac81e1d158b41ccd0d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
package config

import (
	"os"

	"github.com/mimecast/dtail/internal/color"
)

type remoteTermColors struct {
	DelimiterAttr color.Attribute
	DelimiterBg   color.BgColor
	DelimiterFg   color.FgColor
	RemoteAttr    color.Attribute
	RemoteBg      color.BgColor
	RemoteFg      color.FgColor
	CountAttr     color.Attribute
	CountBg       color.BgColor
	CountFg       color.FgColor
	HostnameAttr  color.Attribute
	HostnameBg    color.BgColor
	HostnameFg    color.FgColor
	IDAttr        color.Attribute
	IDBg          color.BgColor
	IDFg          color.FgColor
	StatsOkAttr   color.Attribute
	StatsOkBg     color.BgColor
	StatsOkFg     color.FgColor
	StatsWarnAttr color.Attribute
	StatsWarnBg   color.BgColor
	StatsWarnFg   color.FgColor
	TextAttr      color.Attribute
	TextBg        color.BgColor
	TextFg        color.FgColor
}

type clientTermColors struct {
	DelimiterAttr color.Attribute
	DelimiterBg   color.BgColor
	DelimiterFg   color.FgColor
	ClientAttr    color.Attribute
	ClientBg      color.BgColor
	ClientFg      color.FgColor
	HostnameAttr  color.Attribute
	HostnameBg    color.BgColor
	HostnameFg    color.FgColor
	TextAttr      color.Attribute
	TextBg        color.BgColor
	TextFg        color.FgColor
}

type serverTermColors struct {
	DelimiterAttr color.Attribute
	DelimiterBg   color.BgColor
	DelimiterFg   color.FgColor
	ServerAttr    color.Attribute
	ServerBg      color.BgColor
	ServerFg      color.FgColor
	HostnameAttr  color.Attribute
	HostnameBg    color.BgColor
	HostnameFg    color.FgColor
	TextAttr      color.Attribute
	TextBg        color.BgColor
	TextFg        color.FgColor
}

type commonTermColors struct {
	SeverityErrorAttr color.Attribute
	SeverityErrorBg   color.BgColor
	SeverityErrorFg   color.FgColor
	SeverityFatalAttr color.Attribute
	SeverityFatalBg   color.BgColor
	SeverityFatalFg   color.FgColor
	SeverityWarnAttr  color.Attribute
	SeverityWarnBg    color.BgColor
	SeverityWarnFg    color.FgColor
}

type maprTableTermColors struct {
	DataAttr            color.Attribute
	DataBg              color.BgColor
	DataFg              color.FgColor
	DelimiterAttr       color.Attribute
	DelimiterBg         color.BgColor
	DelimiterFg         color.FgColor
	HeaderAttr          color.Attribute
	HeaderBg            color.BgColor
	HeaderDelimiterAttr color.Attribute
	HeaderDelimiterBg   color.BgColor
	HeaderDelimiterFg   color.FgColor
	HeaderFg            color.FgColor
	HeaderGroupKeyAttr  color.Attribute
	HeaderSortKeyAttr   color.Attribute
	RawQueryAttr        color.Attribute
	RawQueryBg          color.BgColor
	RawQueryFg          color.FgColor
}

type termColors struct {
	Remote    remoteTermColors
	Client    clientTermColors
	Server    serverTermColors
	Common    commonTermColors
	MaprTable maprTableTermColors
}

// ClientConfig represents a DTail client configuration (empty as of now as there
// are no available config options yet, but that may changes in the future).
type ClientConfig struct {
	TermColorsEnable bool       `json:",omitempty"`
	TermColors       termColors `json:",omitempty"`
	AuthKeyPath      string     `json:",omitempty"`
	AuthKeyDisable   bool       `json:",omitempty"`
}

// Create a new default client configuration.
func newDefaultClientConfig() *ClientConfig {
	return &ClientConfig{
		TermColorsEnable: true,
		AuthKeyPath:      defaultAuthKeyPath(),
		AuthKeyDisable:   false,
		TermColors: termColors{
			Remote: remoteTermColors{
				DelimiterAttr: color.AttrDim,
				DelimiterBg:   color.BgBlue,
				DelimiterFg:   color.FgCyan,
				RemoteAttr:    color.AttrDim,
				RemoteBg:      color.BgBlue,
				RemoteFg:      color.FgWhite,
				CountAttr:     color.AttrDim,
				CountBg:       color.BgBlue,
				CountFg:       color.FgWhite,
				HostnameAttr:  color.AttrBold,
				HostnameBg:    color.BgBlue,
				HostnameFg:    color.FgWhite,
				IDAttr:        color.AttrDim,
				IDBg:          color.BgBlue,
				IDFg:          color.FgWhite,
				StatsOkAttr:   color.AttrNone,
				StatsOkBg:     color.BgGreen,
				StatsOkFg:     color.FgBlack,
				StatsWarnAttr: color.AttrNone,
				StatsWarnBg:   color.BgRed,
				StatsWarnFg:   color.FgWhite,
				TextAttr:      color.AttrNone,
				TextBg:        color.BgBlack,
				TextFg:        color.FgWhite,
			},
			Client: clientTermColors{
				DelimiterAttr: color.AttrDim,
				DelimiterBg:   color.BgYellow,
				DelimiterFg:   color.FgBlack,
				ClientAttr:    color.AttrDim,
				ClientBg:      color.BgYellow,
				ClientFg:      color.FgBlack,
				HostnameAttr:  color.AttrDim,
				HostnameBg:    color.BgYellow,
				HostnameFg:    color.FgBlack,
				TextAttr:      color.AttrNone,
				TextBg:        color.BgBlack,
				TextFg:        color.FgWhite,
			},
			Server: serverTermColors{
				DelimiterAttr: color.AttrDim,
				DelimiterBg:   color.BgCyan,
				DelimiterFg:   color.FgBlack,
				ServerAttr:    color.AttrDim,
				ServerBg:      color.BgCyan,
				ServerFg:      color.FgBlack,
				HostnameAttr:  color.AttrBold,
				HostnameBg:    color.BgCyan,
				HostnameFg:    color.FgBlack,
				TextAttr:      color.AttrNone,
				TextBg:        color.BgBlack,
				TextFg:        color.FgWhite,
			},
			Common: commonTermColors{
				SeverityErrorAttr: color.AttrBold,
				SeverityErrorBg:   color.BgRed,
				SeverityErrorFg:   color.FgWhite,
				SeverityFatalAttr: color.AttrBold,
				SeverityFatalBg:   color.BgMagenta,
				SeverityFatalFg:   color.FgWhite,
				SeverityWarnAttr:  color.AttrBold,
				SeverityWarnBg:    color.BgBlack,
				SeverityWarnFg:    color.FgWhite,
			},
			MaprTable: maprTableTermColors{
				DataAttr:            color.AttrNone,
				DataBg:              color.BgBlue,
				DataFg:              color.FgWhite,
				DelimiterAttr:       color.AttrDim,
				DelimiterBg:         color.BgBlue,
				DelimiterFg:         color.FgWhite,
				HeaderAttr:          color.AttrBold,
				HeaderBg:            color.BgBlue,
				HeaderFg:            color.FgWhite,
				HeaderDelimiterAttr: color.AttrDim,
				HeaderDelimiterBg:   color.BgBlue,
				HeaderDelimiterFg:   color.FgWhite,
				HeaderSortKeyAttr:   color.AttrUnderline,
				HeaderGroupKeyAttr:  color.AttrReverse,
				RawQueryAttr:        color.AttrDim,
				RawQueryBg:          color.BgBlack,
				RawQueryFg:          color.FgCyan,
			},
		},
	}
}

func defaultAuthKeyPath() string {
	homeDir, err := os.UserHomeDir()
	if err != nil || homeDir == "" {
		homeDir = os.Getenv("HOME")
	}
	if homeDir == "" {
		return "~/.ssh/id_rsa"
	}

	return homeDir + "/.ssh/id_rsa"
}