github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/pkg/cli/cmd/alert/list_smtpserver.go (about) 1 /* 2 Copyright (C) 2022-2023 ApeCloud Co., Ltd 3 4 This file is part of KubeBlocks project 5 6 This program is free software: you can redistribute it and/or modify 7 it under the terms of the GNU Affero General Public License as published by 8 the Free Software Foundation, either version 3 of the License, or 9 (at your option) any later version. 10 11 This program is distributed in the hope that it will be useful 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU Affero General Public License for more details. 15 16 You should have received a copy of the GNU Affero General Public License 17 along with this program. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 package alert 21 22 import ( 23 "github.com/spf13/cobra" 24 "k8s.io/cli-runtime/pkg/genericiooptions" 25 cmdutil "k8s.io/kubectl/pkg/cmd/util" 26 "k8s.io/kubectl/pkg/util/templates" 27 28 "github.com/1aal/kubeblocks/pkg/cli/printer" 29 "github.com/1aal/kubeblocks/pkg/cli/util" 30 ) 31 32 var ( 33 listSMTPServerExample = templates.Examples(` 34 # list alert smtp servers config 35 kbcli alert list-smtpserver`) 36 ) 37 38 type listSMTPServerOptions struct { 39 baseOptions 40 } 41 42 func newListSMTPServerCmd(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Command { 43 o := &listSMTPServerOptions{baseOptions: baseOptions{IOStreams: streams}} 44 cmd := &cobra.Command{ 45 Use: "list-smtpserver", 46 Short: "List alert smtp servers config.", 47 Example: listSMTPServerExample, 48 Run: func(cmd *cobra.Command, args []string) { 49 util.CheckErr(o.complete(f)) 50 util.CheckErr(o.run()) 51 }, 52 } 53 return cmd 54 } 55 56 func (o *listSMTPServerOptions) run() error { 57 data, err := getConfigData(o.alertConfigMap, alertConfigFileName) 58 if err != nil { 59 return err 60 } 61 62 // get global 63 global := getGlobalFromData(data) 64 65 tbl := printer.NewTablePrinter(o.Out) 66 tbl.SetHeader("IDENTITY", "PASSWORD", "USERNAME", "FROM", "SMARTHOST") 67 tbl.AddRow(global["smtp_auth_identity"], global["smtp_auth_password"], global["smtp_auth_username"], global["smtp_from"], global["smtp_smarthost"]) 68 tbl.Print() 69 return nil 70 }