-
Notifications
You must be signed in to change notification settings - Fork 0
/
validator_service.go
710 lines (635 loc) · 20.9 KB
/
validator_service.go
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
// Package validator provides functions for interacting with the validator and its plugins.
package validator
import (
"fmt"
"path/filepath"
"slices"
"strconv"
"strings"
"emperror.dev/errors"
vtypes "github.com/validator-labs/validator/pkg/types"
"k8s.io/client-go/kubernetes"
"github.com/spectrocloud-labs/prompts-tui/prompts"
awsconsts "github.com/validator-labs/validator-plugin-aws/pkg/constants"
azureconsts "github.com/validator-labs/validator-plugin-azure/pkg/constants"
maasconsts "github.com/validator-labs/validator-plugin-maas/pkg/constants"
netconsts "github.com/validator-labs/validator-plugin-network/pkg/constants"
ociconsts "github.com/validator-labs/validator-plugin-oci/pkg/constants"
vsphereconsts "github.com/validator-labs/validator-plugin-vsphere/pkg/constants"
"github.com/validator-labs/validatorctl/pkg/components"
cfg "github.com/validator-labs/validatorctl/pkg/config"
log "github.com/validator-labs/validatorctl/pkg/logging"
"github.com/validator-labs/validatorctl/pkg/services"
"github.com/validator-labs/validatorctl/pkg/utils/exec"
"github.com/validator-labs/validatorctl/pkg/utils/kind"
"github.com/validator-labs/validatorctl/pkg/utils/kube"
string_utils "github.com/validator-labs/validatorctl/pkg/utils/string"
)
type pluginFuncMap map[string]func(*components.ValidatorConfig, *cfg.TaskConfig, kubernetes.Interface) error
var (
pluginInstallFuncs = pluginFuncMap{
awsconsts.PluginCode: readAwsPlugin,
azureconsts.PluginCode: readAzurePlugin,
maasconsts.PluginCode: readMaasPlugin,
netconsts.PluginCode: readNetworkPlugin,
ociconsts.PluginCode: readOciPlugin,
vsphereconsts.PluginCode: readVspherePlugin,
}
pluginRuleFuncs = pluginFuncMap{
awsconsts.PluginCode: readAwsPluginRules,
azureconsts.PluginCode: readAzurePluginRules,
maasconsts.PluginCode: readMaasPluginRules,
netconsts.PluginCode: readNetworkPluginRules,
ociconsts.PluginCode: readOciPluginRules,
vsphereconsts.PluginCode: readVspherePluginRules,
}
plugins = make([]string, 0, len(pluginInstallFuncs))
)
func init() {
for k := range pluginInstallFuncs {
plugins = append(plugins, k)
}
slices.Sort(plugins)
}
// ReadValidatorConfig prompts the user to configure installation settings for validator and its plugins.
// nolint:gocyclo
func ReadValidatorConfig(c *cfg.Config, tc *cfg.TaskConfig, vc *components.ValidatorConfig) error {
log.Header("Enter Validator Configuration")
log.InfoCLI(`
You will be prompted for the following configuration:
- Kubernetes cluster configuration
- Proxy configuration
- Artifact registry configuration
- Sink configuration
- Validator plugin(s) to install
If you make a mistake at any point you will have to option
to revisit any configuration step at the end.
`)
var err error
var kClient kubernetes.Interface
log.Header("Kind Configuration")
vc.KindConfig.UseKindCluster, err = prompts.ReadBool("Provision & use kind cluster", true)
if err != nil {
return err
}
if vc.KindConfig.UseKindCluster {
if err := exec.CheckBinaries([]exec.Binary{exec.DockerBin, exec.KindBin}); err != nil {
return err
}
if err := kind.ValidateClusters("Validator installation"); err != nil {
return err
}
// only set kubeconfig if a kind cluster will be created
if !tc.CreateConfigOnly {
vc.Kubeconfig = filepath.Join(c.RunLoc, "kind-cluster.kubeconfig")
}
} else {
kClient, vc.Kubeconfig, err = services.ReadKubeconfig()
if err != nil {
return err
}
}
log.Header("Proxy Configuration")
if err := readProxyConfig(vc); err != nil {
return err
}
log.Header("Artifact Registry Configuration")
if err := readRegistryConfig(vc); err != nil {
return err
}
log.Header("Helm Configuration")
if err := readHelmConfig(cfg.Validator, kClient, vc, vc.ReleaseSecret); err != nil {
return err
}
log.Header("Sink Configuration")
log.InfoCLI(`
If sink configuration is provided, validator will upload all plugin validation
results to either Slack or Alertmanager. Results are hashed so that new events
are emitted only when the validation result changes.
`)
if err := readSinkConfig(vc, kClient); err != nil {
return err
}
// Configure validator HelmRelease
if err := readHelmRelease(cfg.Validator, vc, vc.Release); err != nil {
return err
}
log.Header("Validator Plugin Configuration")
log.InfoCLI(`
Validator plugins provide informative, actionable validation results pertaining
to infrastructure, networking, kubernetes cluster internals, and more.
Pick and choose from them to craft a validation profile that meets your
organization's requirements.
`)
// Enable plugin(s) & read install config
if err := handlePlugins(vc, tc, kClient, "Install", true, pluginInstallFuncs); err != nil {
return err
}
log.Header("Finalize Installation Configuration")
restart, err := prompts.ReadBool("Restart configuration", false)
if err != nil {
return err
}
if restart {
return ReadValidatorConfig(c, tc, vc)
}
for {
revisit, err := prompts.ReadBool("Reconfigure plugin(s)", false)
if err != nil {
return err
}
if revisit {
pluginCode, err := prompts.Select("Plugin", plugins)
if err != nil {
return err
}
if err := pluginInstallFuncs[pluginCode](vc, tc, kClient); err != nil {
return err
}
continue
}
break
}
return nil
}
// handlePlugins supports three distinct logical flows:
// 1. validator install
// - prompt to enable plugins
// - verb is Install & tc.Direct will never be true, so readXYZPlugin calls are never hit
//
// 2. validator check (without --direct)
// - no prompt to enable plugins as they're already enabled in the validator config file
// - verb is Enable & tc.Direct is false, so readXYZPlugin are never called, but readXYZPluginRules are
//
// 3. validator check --direct
// - prompt to enable plugins (since we don't have a validator config file)
// - verb is Enable & tc.Direct is true, so readXYZPlugin and readXYZPluginRules are called
//
// nolint:gocyclo
func handlePlugins(vc *components.ValidatorConfig, tc *cfg.TaskConfig, kClient kubernetes.Interface, verb string, enablePlugins bool, funcMap pluginFuncMap) error {
var err error
if enablePlugins {
log.Header("AWS Plugin")
log.InfoCLI(`
The AWS validator plugin reconciles AwsValidator custom resources to perform the
following validations against your AWS environment:
- Ensure that one or more EC2 AMI(s) exist in a particular region.
- Compare the IAM permissions associated with an IAM user / group / role / policy
against an expected permission set.
- Compare the usage for a particular service quota against the active quota to
avoid unexpectedly hitting quota limits.
- Compare the tags associated with a subnet against an expected tag set.
`)
vc.AWSPlugin.Enabled, err = prompts.ReadBool(fmt.Sprintf("%s AWS plugin", verb), true)
if err != nil {
return err
}
}
if vc.AWSPlugin.Enabled {
if tc.Direct {
if err = readAwsPlugin(vc, tc, kClient); err != nil {
return err
}
}
if err := funcMap[awsconsts.PluginCode](vc, tc, kClient); err != nil {
return err
}
}
// TODO: support image gallery rules
// - Verify that images in community image galleries exist.
if enablePlugins {
log.Header("Azure Plugin")
log.InfoCLI(`
The Azure validator plugin reconciles AzureValidator custom resources to perform
the following validations against your Azure environment:
- Compare the Azure RBAC permissions associated with a security principal against
an expected permission set.
`)
vc.AzurePlugin.Enabled, err = prompts.ReadBool(fmt.Sprintf("%s Azure plugin", verb), true)
if err != nil {
return err
}
}
if vc.AzurePlugin.Enabled {
if tc.Direct {
if err = readAzurePlugin(vc, tc, kClient); err != nil {
return err
}
}
if err := funcMap[azureconsts.PluginCode](vc, tc, kClient); err != nil {
return err
}
}
if enablePlugins {
log.Header("MAAS Plugin")
log.InfoCLI(`
The MAAS validator plugin reconciles MaasValidator custom resources to perform
the following validation against your MAAS cluster:
- Check that a certain number of Upstream DNS servers are configured.
- Check that the expected Internal DNS settings are present.
- Check that the expected number of Machines matching a certain spec are "Ready" for use in each Availability Zone.
- Check that all required OS Images are "Synced" to the cluster.
`)
vc.MaasPlugin.Enabled, err = prompts.ReadBool(fmt.Sprintf("%s MAAS plugin", verb), true)
if err != nil {
return err
}
}
if vc.MaasPlugin.Enabled {
if tc.Direct {
if err = readMaasPlugin(vc, tc, kClient); err != nil {
return err
}
}
if err := funcMap[maasconsts.PluginCode](vc, tc, kClient); err != nil {
return err
}
}
if enablePlugins {
log.Header("Network Plugin")
log.InfoCLI(`
The Network validator plugin reconciles NetworkValidator custom resources to perform
the following validations against your network:
- Execute DNS lookups.
- Execute ICMP pings.
- Validate TCP connections to arbitrary host + port(s).
- Check each IP in an IP range to ensure that they're all unallocated.
- Check that the default NIC has an MTU greater than or equal to a specified value.
- Check that each file in a list of URLs is available and publicly accessible
via an HTTP HEAD request, with optional basic auth.
`)
vc.NetworkPlugin.Enabled, err = prompts.ReadBool(fmt.Sprintf("%s Network plugin", verb), true)
if err != nil {
return err
}
}
if vc.NetworkPlugin.Enabled {
if tc.Direct {
if err := exec.CheckBinaries([]exec.Binary{exec.NslookupBin, exec.PingBin}); err != nil {
return err
}
if err = readNetworkPlugin(vc, tc, kClient); err != nil {
return err
}
}
if err := funcMap[netconsts.PluginCode](vc, tc, kClient); err != nil {
return err
}
}
if enablePlugins {
log.Header("OCI Plugin")
log.InfoCLI(`
The OCI validator plugin reconciles OciValidator custom resources to perform the
following validations against your OCI registry:
- Validate OCI registry authentication.
- Validate the existence of arbitrary OCI artifacts, with optional signature
verification.
- Validate downloading arbitrary OCI artifacts.
`)
vc.OCIPlugin.Enabled, err = prompts.ReadBool(fmt.Sprintf("%s OCI plugin", verb), true)
if err != nil {
return err
}
}
if vc.OCIPlugin.Enabled {
if tc.Direct {
if err = readOciPlugin(vc, tc, kClient); err != nil {
return err
}
}
if err := funcMap[ociconsts.PluginCode](vc, tc, kClient); err != nil {
return err
}
}
if enablePlugins {
log.Header("vSphere Plugin")
log.InfoCLI(`
The vSphere validator plugin reconciles VsphereValidator custom resources to perform
the following validations against your vSphere environment:
- Compare the privileges associated with a user against an expected privileges set.
- Compare the privileges associated with a user against an expected privileges set
on a particular entity (cluster, resourcepool, folder, vapp, host).
- Verify availability of compute resources on an ESXi host, resourcepool, or cluster.
- Compare the tags associated with a datacenter, cluster, host, vm, resourcepool or vm
against an expected tag set.
- Verify that a set of ESXi hosts have valid NTP configuration.
`)
vc.VspherePlugin.Enabled, err = prompts.ReadBool(fmt.Sprintf("%s vSphere plugin", verb), true)
if err != nil {
return err
}
}
if vc.VspherePlugin.Enabled {
if tc.Direct {
if err = readVspherePlugin(vc, tc, kClient); err != nil {
return err
}
}
if err := funcMap[vsphereconsts.PluginCode](vc, tc, kClient); err != nil {
return err
}
}
return nil
}
// ReadValidatorPluginConfig prompts the user to configure validator plugins rule(s).
func ReadValidatorPluginConfig(c *cfg.Config, tc *cfg.TaskConfig, vc *components.ValidatorConfig) error {
var err error
var enablePlugins bool
var kClient kubernetes.Interface
if tc.Direct {
enablePlugins = true
} else if !tc.CreateConfigOnly {
if vc.Kubeconfig == "" {
if vc.KindConfig.UseKindCluster {
return errors.New(`config file has kindConfig.useKindCluster set to true, but no kubeconfig path was provided. Have you run "validator install" yet?`)
}
kClient, vc.Kubeconfig, err = services.ReadKubeconfig()
if err != nil {
return err
}
} else {
kClient, err = kube.GetKubeClientset(vc.Kubeconfig)
if err != nil {
return err
}
}
log.InfoCLI("")
}
log.Header("Validator Plugin Configuration")
if tc.Direct {
log.InfoCLI(`
You will be prompted to enable validator plugins and
configure rules for each enabled plugin. The rules will be
evaluated directly, in-process. Results will be saved to
disk and printed to the console.
If you make a mistake at any point you will have to option
to revisit any configuration step at the end.
`)
} else {
log.InfoCLI(`
You will be prompted to configure validator plugin rules
for each enabled plugin in your validator configuration file.
Custom Resouces containing plugin rules will be applied to the
Kubernetes cluster specified by the KUBECONFIG environment variable.
If you make a mistake at any point you will have to option
to revisit any configuration step at the end.
`)
}
// If direct, enable plugin(s) & read partial install config & rule config.
// If not direct, read rule config for enabled plugin(s).
if err := handlePlugins(vc, tc, kClient, "Enable", enablePlugins, pluginRuleFuncs); err != nil {
return err
}
log.Header("Finalize Plugin Rule Configuration")
restart, err := prompts.ReadBool("Restart configuration", false)
if err != nil {
return err
}
if restart {
return ReadValidatorPluginConfig(c, tc, vc)
}
for {
revisit, err := prompts.ReadBool("Reconfigure plugin(s)", false)
if err != nil {
return err
}
if revisit {
pluginCode, err := prompts.Select("Plugin", plugins)
if err != nil {
return err
}
if err := pluginRuleFuncs[pluginCode](vc, tc, kClient); err != nil {
return err
}
continue
}
break
}
return nil
}
// UpdateValidatorCredentials updates validator credentials
func UpdateValidatorCredentials(c *components.ValidatorConfig) error {
if c.RegistryConfig.Enabled {
if err := readRegistryConfig(c); err != nil {
return fmt.Errorf("failed to update registry config: %w", err)
}
}
k8sClient, err := k8sClientFromConfig(c)
if err != nil {
return err
}
if err := readHelmConfig(cfg.Validator, k8sClient, c, c.ReleaseSecret); err != nil {
return fmt.Errorf("failed to update Helm configuration: %w", err)
}
return nil
}
// UpdateValidatorPluginCredentials updates validator plugin credentials
func UpdateValidatorPluginCredentials(c *components.ValidatorConfig, tc *cfg.TaskConfig) error {
var err error
var kClient kubernetes.Interface
if !tc.Direct {
kClient, err = k8sClientFromConfig(c)
if err != nil {
return err
}
}
if c.AWSPlugin != nil && c.AWSPlugin.Enabled {
if err := readAwsCredentials(c.AWSPlugin, tc, kClient); err != nil {
return fmt.Errorf("failed to update AWS credentials: %w", err)
}
}
if c.AzurePlugin != nil && c.AzurePlugin.Enabled {
if err := readAzureCredentials(c.AzurePlugin, tc, kClient); err != nil {
return fmt.Errorf("failed to update Azure credentials: %w", err)
}
}
if c.MaasPlugin != nil && c.MaasPlugin.Enabled {
if err := readMaasCredentials(c.MaasPlugin, tc, kClient); err != nil {
return fmt.Errorf("failed to update MAAS credentials: %w", err)
}
}
if c.OCIPlugin != nil && c.OCIPlugin.Enabled {
for _, secret := range c.OCIPlugin.Secrets {
if err := readOciSecret(secret); err != nil {
return fmt.Errorf("failed to update OCI secret: %w", err)
}
}
}
if c.VspherePlugin != nil && c.VspherePlugin.Enabled {
if err := readVsphereCredentials(c.VspherePlugin, tc, kClient); err != nil {
return fmt.Errorf("failed to update vSphere credentials: %w", err)
}
}
return nil
}
func k8sClientFromConfig(c *components.ValidatorConfig) (kubernetes.Interface, error) {
var err error
var k8sClient kubernetes.Interface
if !c.KindConfig.UseKindCluster {
k8sClient, c.Kubeconfig, err = services.ReadKubeconfig()
if err != nil {
return nil, err
}
}
return k8sClient, nil
}
func readRegistryConfig(vc *components.ValidatorConfig) (err error) {
airgapped, err := prompts.ReadBool("Configure Hauler for air-gapped installation", false)
if err != nil {
return err
}
if airgapped {
vc.RegistryConfig.Enabled = true
vc.RegistryConfig.Registry.IsAirgapped = true
vc.UseFixedVersions = true
if err = services.ReadHaulerProps(vc.RegistryConfig.Registry, vc.ProxyConfig.Env); err != nil {
return err
}
vc.ImageRegistry = vc.RegistryConfig.Registry.ImageEndpoint()
return nil
}
privateRegistry, err := prompts.ReadBool("Configure private OCI registry", false)
if err != nil {
return err
}
if privateRegistry {
vc.RegistryConfig.Enabled = true
if err := services.ReadRegistryProps(vc.RegistryConfig.Registry, vc.ProxyConfig.Env); err != nil {
return err
}
vc.ImageRegistry = vc.RegistryConfig.Registry.ImageEndpoint()
return nil
}
// public registry configuration
imageRegistry := cfg.ValidatorImagePath()
if vc.ImageRegistry != "" {
imageRegistry = vc.ImageRegistry
}
vc.ImageRegistry, err = prompts.ReadText("Validator image registry", imageRegistry, false, -1)
if err != nil {
return err
}
return nil
}
func readProxyConfig(vc *components.ValidatorConfig) error {
vc.ProxyConfig.Env.PodCIDR = &cfg.DefaultPodCIDR
vc.ProxyConfig.Env.ServiceIPRange = &cfg.DefaultServiceIPRange
configureProxy, err := prompts.ReadBool("Configure an HTTP proxy", false)
if err != nil {
return err
}
if !configureProxy {
vc.ProxyConfig.Enabled = false
return nil
}
if err := services.ReadProxyProps(vc.ProxyConfig.Env); err != nil {
return err
}
vc.ProxyConfig.Enabled = vc.ProxyConfig.Env.ProxyCACert.Path != ""
return nil
}
func readSinkConfig(vc *components.ValidatorConfig, k8sClient kubernetes.Interface) error {
var err error
vc.SinkConfig.Enabled, err = prompts.ReadBool("Configure a sink", false)
if err != nil {
return err
}
if !vc.SinkConfig.Enabled {
return nil
}
sinkType, err := prompts.Select("Sink Type", sinkTypes())
if err != nil {
return err
}
vc.SinkConfig.Type = strings.ToLower(sinkType)
// always create sink credential secret if creating a new kind cluster
vc.SinkConfig.CreateSecret = true
if k8sClient != nil {
keys := cfg.ValidatorSinkKeys[vtypes.SinkType(vc.SinkConfig.Type)]
log.InfoCLI(`
Either specify sink credentials or provide the name of a secret in the target K8s cluster's %s namespace.
If using an existing secret, it must contain the following keys: %+v.
`, cfg.Validator, keys,
)
vc.SinkConfig.CreateSecret, err = prompts.ReadBool("Create sink credential secret", true)
if err != nil {
return err
}
if !vc.SinkConfig.CreateSecret {
secret, err := services.ReadSecret(k8sClient, cfg.Validator, false, keys)
if err != nil {
return err
}
vc.SinkConfig.SecretName = secret.Name
return nil
}
}
vc.SinkConfig.SecretName, err = prompts.ReadText("Sink credentials secret name", "sink-creds", false, -1)
if err != nil {
return err
}
switch vc.SinkConfig.Type {
case string(vtypes.SinkTypeAlertmanager):
if vc.SinkConfig.Values == nil {
vc.SinkConfig.Values = map[string]string{
"endpoint": "",
"caCert": "",
"username": "",
"password": "",
}
}
endpoint, err := prompts.ReadURL(
"Alertmanager endpoint", vc.SinkConfig.Values["endpoint"], "Alertmanager endpoint must be a valid URL", false,
)
if err != nil {
return err
}
vc.SinkConfig.Values["endpoint"] = endpoint
insecure, err := prompts.ReadBool("Allow Insecure Connection (Bypass x509 Verification)", true)
if err != nil {
return err
}
vc.SinkConfig.Values["insecureSkipVerify"] = strconv.FormatBool(insecure)
if !insecure {
var caCertData []byte
_, _, caCertData, err = prompts.ReadCACert("Alertmanager CA certificate filepath", vc.SinkConfig.Values["caCert"], "")
if err != nil {
return err
}
vc.SinkConfig.Values["caCert"] = string(caCertData)
}
username, password, err := prompts.ReadBasicCreds(
"Alertmanager Username", "Alertmanager Password",
vc.SinkConfig.Values["username"], vc.SinkConfig.Values["password"], true, false,
)
if err != nil {
return err
}
vc.SinkConfig.Values["username"] = username
vc.SinkConfig.Values["password"] = password
case string(vtypes.SinkTypeSlack):
if vc.SinkConfig.Values == nil {
vc.SinkConfig.Values = map[string]string{
"apiToken": "",
"channelID": "",
}
}
botToken, err := prompts.ReadPassword("Bot token", vc.SinkConfig.Values["apiToken"], false, -1)
if err != nil {
return err
}
vc.SinkConfig.Values["apiToken"] = botToken
channelID, err := prompts.ReadText("Channel ID", vc.SinkConfig.Values["channelID"], false, -1)
if err != nil {
return err
}
vc.SinkConfig.Values["channelID"] = channelID
}
return nil
}
func sinkTypes() []string {
return []string{
string_utils.Capitalize(string(vtypes.SinkTypeAlertmanager)),
string_utils.Capitalize(string(vtypes.SinkTypeSlack)),
}
}