Skip to content

Commit 68f960b

Browse files
committed
move to reflect
1 parent 880a4ba commit 68f960b

File tree

5 files changed

+203
-154
lines changed

5 files changed

+203
-154
lines changed

cli/deployment/config.go

Lines changed: 65 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,244 +20,296 @@ import (
2020
func newConfig() codersdk.DeploymentConfig {
2121
return codersdk.DeploymentConfig{
2222
AccessURL: codersdk.DeploymentConfigField[string]{
23+
Key: "access_url",
2324
Usage: "External URL to access your deployment. This must be accessible by all provisioned workspaces.",
2425
Flag: "access-url",
2526
},
2627
WildcardAccessURL: codersdk.DeploymentConfigField[string]{
28+
Key: "wildcard_access_url",
2729
Usage: "Specifies the wildcard hostname to use for workspace applications in the form \"*.example.com\".",
2830
Flag: "wildcard-access-url",
2931
},
3032
Address: codersdk.DeploymentConfigField[string]{
33+
Key: "address",
3134
Usage: "Bind address of the server.",
3235
Flag: "address",
3336
Shorthand: "a",
3437
Value: "127.0.0.1:3000",
3538
},
3639
AutobuildPollInterval: codersdk.DeploymentConfigField[time.Duration]{
40+
Key: "autobuild_poll_interval",
3741
Usage: "Interval to poll for scheduled workspace builds.",
3842
Flag: "autobuild-poll-interval",
3943
Hidden: true,
4044
Value: time.Minute,
4145
},
4246
DERPServerEnable: codersdk.DeploymentConfigField[bool]{
47+
Key: "derp.server.enable",
4348
Usage: "Whether to enable or disable the embedded DERP relay server.",
4449
Flag: "derp-server-enable",
4550
Value: true,
4651
},
4752
DERPServerRegionID: codersdk.DeploymentConfigField[int]{
53+
Key: "derp.server.region_id",
4854
Usage: "Region ID to use for the embedded DERP server.",
4955
Flag: "derp-server-region-id",
5056
Value: 999,
5157
},
5258
DERPServerRegionCode: codersdk.DeploymentConfigField[string]{
59+
Key: "derp.server.region_code",
5360
Usage: "Region code to use for the embedded DERP server.",
5461
Flag: "derp-server-region-code",
5562
Value: "coder",
5663
},
5764
DERPServerRegionName: codersdk.DeploymentConfigField[string]{
65+
Key: "derp.server.region_name",
5866
Usage: "Region name that for the embedded DERP server.",
5967
Flag: "derp-server-region-name",
6068
Value: "Coder Embedded Relay",
6169
},
6270
DERPServerSTUNAddresses: codersdk.DeploymentConfigField[[]string]{
71+
Key: "derp.server.stun_addresses",
6372
Usage: "Addresses for STUN servers to establish P2P connections. Set empty to disable P2P connections.",
6473
Flag: "derp-server-stun-addresses",
6574
Value: []string{"stun.l.google.com:19302"},
6675
},
6776
DERPServerRelayAddress: codersdk.DeploymentConfigField[string]{
77+
Key: "derp.server.relay_address",
6878
Usage: "An HTTP address that is accessible by other replicas to relay DERP traffic. Required for high availability.",
6979
Flag: "derp-server-relay-address",
7080
Enterprise: true,
7181
},
7282
DERPConfigURL: codersdk.DeploymentConfigField[string]{
83+
Key: "derp.config.url",
7384
Usage: "URL to fetch a DERP mapping on startup. See: https://tailscale.com/kb/1118/custom-derp-servers/",
7485
Flag: "derp-config-url",
7586
},
7687
DERPConfigPath: codersdk.DeploymentConfigField[string]{
88+
Key: "derp.config.path",
7789
Usage: "Path to read a DERP mapping from. See: https://tailscale.com/kb/1118/custom-derp-servers/",
7890
Flag: "derp-config-path",
7991
},
8092
PrometheusEnable: codersdk.DeploymentConfigField[bool]{
93+
Key: "prometheus.enable",
8194
Usage: "Serve prometheus metrics on the address defined by prometheus address.",
8295
Flag: "prometheus-enable",
8396
},
8497
PrometheusAddress: codersdk.DeploymentConfigField[string]{
98+
Key: "prometheus.address",
8599
Usage: "The bind address to serve prometheus metrics.",
86100
Flag: "prometheus-address",
87101
Value: "127.0.0.1:2112",
88102
},
89103
PprofEnable: codersdk.DeploymentConfigField[bool]{
104+
Key: "pprof.enable",
90105
Usage: "Serve pprof metrics on the address defined by pprof address.",
91106
Flag: "pprof-enable",
92107
},
93108
PprofAddress: codersdk.DeploymentConfigField[string]{
109+
Key: "pprof.address",
94110
Usage: "The bind address to serve pprof.",
95111
Flag: "pprof-address",
96112
Value: "127.0.0.1:6060",
97113
},
98114
CacheDir: codersdk.DeploymentConfigField[string]{
115+
Key: "cache_dir",
99116
Usage: "The directory to cache temporary files. If unspecified and $CACHE_DIRECTORY is set, it will be used for compatibility with systemd.",
100117
Flag: "cache-dir",
101118
Value: defaultCacheDir(),
102119
},
103120
InMemoryDatabase: codersdk.DeploymentConfigField[bool]{
121+
Key: "in_memory_database",
104122
Usage: "Controls whether data will be stored in an in-memory database.",
105123
Flag: "in-memory",
106124
Hidden: true,
107125
},
108126
ProvisionerDaemonCount: codersdk.DeploymentConfigField[int]{
127+
Key: "provisioner.daemon_count",
109128
Usage: "Number of provisioner daemons to create on start. If builds are stuck in queued state for a long time, consider increasing this.",
110129
Flag: "provisioner-daemons",
111130
Value: 3,
112131
},
113132
PostgresURL: codersdk.DeploymentConfigField[string]{
133+
Key: "postgres_url",
114134
Usage: "URL of a PostgreSQL database. If empty, PostgreSQL binaries will be downloaded from Maven (https://repo1.maven.org/maven2) and store all data in the config root. Access the built-in database with \"coder server postgres-builtin-url\".",
115135
Flag: "postgres-url",
116136
},
117137
OAuth2GithubClientID: codersdk.DeploymentConfigField[string]{
138+
Key: "oauth2github.client_id",
118139
Usage: "Client ID for Login with GitHub.",
119140
Flag: "oauth2-github-client-id",
120141
},
121142
OAuth2GithubClientSecret: codersdk.DeploymentConfigField[string]{
143+
Key: "oauth2github.client_secret",
122144
Usage: "Client secret for Login with GitHub.",
123145
Flag: "oauth2-github-client-secret",
124146
},
125147
OAuth2GithubAllowedOrganizations: codersdk.DeploymentConfigField[[]string]{
148+
Key: "oauth2github.allowed_organizations",
126149
Usage: "Organizations the user must be a member of to Login with GitHub.",
127150
Flag: "oauth2-github-allowed-orgs",
128151
},
129152
OAuth2GithubAllowedTeams: codersdk.DeploymentConfigField[[]string]{
153+
Key: "oauth2github.allowed_teams",
130154
Usage: "Teams inside organizations the user must be a member of to Login with GitHub. Structured as: <organization-name>/<team-slug>.",
131155
Flag: "oauth2-github-allowed-teams",
132156
},
133157
OAuth2GithubAllowSignups: codersdk.DeploymentConfigField[bool]{
158+
Key: "oauth2github.allow_signups",
134159
Usage: "Whether new users can sign up with GitHub.",
135160
Flag: "oauth2-github-allow-signups",
136161
},
137162
OAuth2GithubEnterpriseBaseURL: codersdk.DeploymentConfigField[string]{
163+
Key: "oauth2github.enterprise_base_url",
138164
Usage: "Base URL of a GitHub Enterprise deployment to use for Login with GitHub.",
139165
Flag: "oauth2-github-enterprise-base-url",
140166
},
141167
OIDCAllowSignups: codersdk.DeploymentConfigField[bool]{
168+
Key: "oidc.allow_signups",
142169
Usage: "Whether new users can sign up with OIDC.",
143170
Flag: "oidc-allow-signups",
144171
Value: true,
145172
},
146173
OIDCClientID: codersdk.DeploymentConfigField[string]{
174+
Key: "oidc.client_id",
147175
Usage: "Client ID to use for Login with OIDC.",
148176
Flag: "oidc-client-id",
149177
},
150178
OIDCClientSecret: codersdk.DeploymentConfigField[string]{
179+
Key: "oidc.client_secret",
151180
Usage: "Client secret to use for Login with OIDC.",
152181
Flag: "oidc-client-secret",
153182
},
154183
OIDCEmailDomain: codersdk.DeploymentConfigField[string]{
184+
Key: "oidc.email_domain",
155185
Usage: "Email domain that clients logging in with OIDC must match.",
156186
Flag: "oidc-email-domain",
157187
},
158188
OIDCIssuerURL: codersdk.DeploymentConfigField[string]{
189+
Key: "oidc.issuer_url",
159190
Usage: "Issuer URL to use for Login with OIDC.",
160191
Flag: "oidc-issuer-url",
161192
},
162193
OIDCScopes: codersdk.DeploymentConfigField[[]string]{
194+
Key: "oidc.scopes",
163195
Usage: "Scopes to grant when authenticating with OIDC.",
164196
Flag: "oidc-scopes",
165197
Value: []string{oidc.ScopeOpenID, "profile", "email"},
166198
},
167199
TelemetryEnable: codersdk.DeploymentConfigField[bool]{
200+
Key: "telemetry.enable",
168201
Usage: "Whether telemetry is enabled or not. Coder collects anonymized usage data to help improve our product.",
169202
Flag: "telemetry",
170203
Value: flag.Lookup("test.v") == nil,
171204
},
172205
TelemetryTraceEnable: codersdk.DeploymentConfigField[bool]{
206+
Key: "telemetry.trace.enable",
173207
Usage: "Whether Opentelemetry traces are sent to Coder. Coder collects anonymized application tracing to help improve our product. Disabling telemetry also disables this option.",
174208
Flag: "telemetry-trace",
175209
Value: flag.Lookup("test.v") == nil,
176210
},
177211
TelemetryURL: codersdk.DeploymentConfigField[string]{
212+
Key: "telemetry.url",
178213
Usage: "URL to send telemetry.",
179214
Flag: "telemetry-url",
180215
Hidden: true,
181216
Value: "https://telemetry.coder.com",
182217
},
183218
TLSEnable: codersdk.DeploymentConfigField[bool]{
219+
Key: "tls.enable",
184220
Usage: "Whether TLS will be enabled.",
185221
Flag: "tls-enable",
186222
},
187223
TLSCertFiles: codersdk.DeploymentConfigField[[]string]{
224+
Key: "tls.cert_files",
188225
Usage: "Path to each certificate for TLS. It requires a PEM-encoded file. To configure the listener to use a CA certificate, concatenate the primary certificate and the CA certificate together. The primary certificate should appear first in the combined file.",
189226
Flag: "tls-cert-file",
190227
},
191228
TLSClientCAFile: codersdk.DeploymentConfigField[string]{
229+
Key: "tls.client_ca_file",
192230
Usage: "PEM-encoded Certificate Authority file used for checking the authenticity of client",
193231
Flag: "tls-client-ca-file",
194232
},
195233
TLSClientAuth: codersdk.DeploymentConfigField[string]{
234+
Key: "tls.client_auth",
196235
Usage: "Policy the server will follow for TLS Client Authentication. Accepted values are \"none\", \"request\", \"require-any\", \"verify-if-given\", or \"require-and-verify\".",
197236
Flag: "tls-client-auth",
198237
Value: "request",
199238
},
200239
TLSKeyFiles: codersdk.DeploymentConfigField[[]string]{
240+
Key: "tls.key_files",
201241
Usage: "Paths to the private keys for each of the certificates. It requires a PEM-encoded file.",
202242
Flag: "tls-key-file",
203243
},
204244
TLSMinVersion: codersdk.DeploymentConfigField[string]{
245+
Key: "tls.min_version",
205246
Usage: "Minimum supported version of TLS. Accepted values are \"tls10\", \"tls11\", \"tls12\" or \"tls13\"",
206247
Flag: "tls-min-version",
207248
Value: "tls12",
208249
},
209250
TraceEnable: codersdk.DeploymentConfigField[bool]{
251+
Key: "trace",
210252
Usage: "Whether application tracing data is collected.",
211253
Flag: "trace",
212254
},
213255
SecureAuthCookie: codersdk.DeploymentConfigField[bool]{
256+
Key: "secure_auth_cookie",
214257
Usage: "Controls if the 'Secure' property is set on browser session cookies.",
215258
Flag: "secure-auth-cookie",
216259
},
217260
SSHKeygenAlgorithm: codersdk.DeploymentConfigField[string]{
261+
Key: "ssh_keygen_algorithm",
218262
Usage: "The algorithm to use for generating ssh keys. Accepted values are \"ed25519\", \"ecdsa\", or \"rsa4096\".",
219263
Flag: "ssh-keygen-algorithm",
220264
Value: "ed25519",
221265
},
222266
AutoImportTemplates: codersdk.DeploymentConfigField[[]string]{
267+
Key: "auto_import_templates",
223268
Usage: "Templates to auto-import. Available auto-importable templates are: kubernetes",
224269
Flag: "auto-import-template",
225270
Hidden: true,
226271
},
227272
MetricsCacheRefreshInterval: codersdk.DeploymentConfigField[time.Duration]{
273+
Key: "metrics_cache_refresh_interval",
228274
Usage: "How frequently metrics are refreshed",
229275
Flag: "metrics-cache-refresh-interval",
230276
Hidden: true,
231277
Value: time.Hour,
232278
},
233279
AgentStatRefreshInterval: codersdk.DeploymentConfigField[time.Duration]{
280+
Key: "agent_stat_refresh_interval",
234281
Usage: "How frequently agent stats are recorded",
235282
Flag: "agent-stats-refresh-interval",
236283
Hidden: true,
237284
Value: 10 * time.Minute,
238285
},
239286
Verbose: codersdk.DeploymentConfigField[bool]{
287+
Key: "verbose",
240288
Usage: "Enables verbose logging.",
241289
Flag: "verbose",
242290
Shorthand: "v",
243291
},
244292
AuditLogging: codersdk.DeploymentConfigField[bool]{
293+
Key: "audit_logging",
245294
Usage: "Specifies whether audit logging is enabled.",
246295
Flag: "audit-logging",
247296
Value: true,
248297
Enterprise: true,
249298
},
250299
BrowserOnly: codersdk.DeploymentConfigField[bool]{
300+
Key: "browser_only",
251301
Usage: "Whether Coder only allows connections to workspaces via the browser.",
252302
Flag: "browser-only",
253303
Enterprise: true,
254304
},
255305
SCIMAuthHeader: codersdk.DeploymentConfigField[string]{
306+
Key: "scim_auth_header",
256307
Usage: "Enables SCIM and sets the authentication header for the built-in SCIM server. New users are automatically created with OIDC authentication.",
257308
Flag: "scim-auth-header",
258309
Enterprise: true,
259310
},
260311
UserWorkspaceQuota: codersdk.DeploymentConfigField[int]{
312+
Key: "user_workspace_quota",
261313
Usage: "Enables and sets a limit on how many workspaces each user can create.",
262314
Flag: "user-workspace-quota",
263315
Enterprise: true,
@@ -267,11 +319,10 @@ func newConfig() codersdk.DeploymentConfig {
267319

268320
func Config(vip *viper.Viper) codersdk.DeploymentConfig {
269321
dc := newConfig()
270-
dcv := reflect.ValueOf(dc).Elem()
322+
dcv := reflect.ValueOf(&dc).Elem()
271323
t := dcv.Type()
272324
for i := 0; i < t.NumField(); i++ {
273-
fv := dcv.Field(i)
274-
fve := fv.Elem()
325+
fve := dcv.Field(i)
275326
key := fve.FieldByName("Key").String()
276327
value := fve.FieldByName("Value").Interface()
277328

@@ -298,13 +349,12 @@ func NewViper() *viper.Viper {
298349
v.SetEnvPrefix("coder")
299350
v.AutomaticEnv()
300351

301-
dcv := reflect.ValueOf(dc).Elem()
352+
dcv := reflect.ValueOf(dc)
302353
t := dcv.Type()
303354
for i := 0; i < t.NumField(); i++ {
304355
fv := dcv.Field(i)
305-
fve := fv.Elem()
306-
key := fve.FieldByName("Key").String()
307-
value := fve.FieldByName("Value").Interface()
356+
key := fv.FieldByName("Key").String()
357+
value := fv.FieldByName("Value").Interface()
308358
v.SetDefault(key, value)
309359
}
310360

@@ -314,25 +364,24 @@ func NewViper() *viper.Viper {
314364
//nolint:revive
315365
func AttachFlags(flagset *pflag.FlagSet, vip *viper.Viper, enterprise bool) {
316366
dc := newConfig()
317-
dcv := reflect.ValueOf(dc).Elem()
367+
dcv := reflect.ValueOf(dc)
318368
t := dcv.Type()
319369
for i := 0; i < t.NumField(); i++ {
320370
fv := dcv.Field(i)
321-
fve := fv.Elem()
322-
isEnt := fve.FieldByName("Enterprise").Bool()
371+
isEnt := fv.FieldByName("Enterprise").Bool()
323372
if enterprise != isEnt {
324373
continue
325374
}
326-
key := fve.FieldByName("Key").String()
327-
flg := fve.FieldByName("Flag").String()
375+
key := fv.FieldByName("Key").String()
376+
flg := fv.FieldByName("Flag").String()
328377
if flg == "" {
329378
continue
330379
}
331-
usage := fve.FieldByName("Usage").String()
380+
usage := fv.FieldByName("Usage").String()
332381
usage = fmt.Sprintf("%s\n%s", usage, cliui.Styles.Placeholder.Render("Consumes $"+formatEnv(key)))
333-
shorthand := fve.FieldByName("Shorthand").String()
334-
hidden := fve.FieldByName("Hidden").Bool()
335-
value := fve.FieldByName("Value").Interface()
382+
shorthand := fv.FieldByName("Shorthand").String()
383+
hidden := fv.FieldByName("Hidden").Bool()
384+
value := fv.FieldByName("Value").Interface()
336385

337386
switch value.(type) {
338387
case string:

0 commit comments

Comments
 (0)