github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/pkg/lorry/engines/nebula/commands.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 nebula 21 22 import ( 23 "fmt" 24 "strings" 25 26 corev1 "k8s.io/api/core/v1" 27 28 "github.com/1aal/kubeblocks/pkg/lorry/engines" 29 "github.com/1aal/kubeblocks/pkg/lorry/engines/models" 30 ) 31 32 var _ engines.ClusterCommands = &Commands{} 33 34 type Commands struct { 35 info engines.EngineInfo 36 examples map[models.ClientType]engines.BuildConnectExample 37 } 38 39 func NewCommands() engines.ClusterCommands { 40 return &Commands{ 41 info: engines.EngineInfo{ 42 Client: "nebula-console", 43 Container: "nebula-console", 44 }, 45 examples: map[models.ClientType]engines.BuildConnectExample{ 46 models.CLI: func(info *engines.ConnectionInfo) string { 47 return fmt.Sprintf(`# nebula client connection example 48 nebula --addr %s --port %s --user %s -port%s 49 `, info.Host, info.Port, info.User, info.Password) 50 }, 51 }, 52 } 53 } 54 55 func (r *Commands) ConnectCommand(connectInfo *engines.AuthInfo) []string { 56 userName := "root" 57 userPass := "nebula" 58 59 if connectInfo != nil { 60 userName = connectInfo.UserName 61 userPass = connectInfo.UserPasswd 62 } 63 64 nebulaCmd := []string{fmt.Sprintf("%s --addr $GRAPHD_SVC_NAME --port $GRAPHD_SVC_PORT --user %s --password %s", r.info.Client, userName, userPass)} 65 66 return []string{"sh", "-c", strings.Join(nebulaCmd, " ")} 67 } 68 69 func (r *Commands) Container() string { 70 return r.info.Container 71 } 72 73 func (r *Commands) ConnectExample(info *engines.ConnectionInfo, client string) string { 74 return engines.BuildExample(info, client, r.examples) 75 } 76 77 func (r *Commands) ExecuteCommand([]string) ([]string, []corev1.EnvVar, error) { 78 return nil, nil, fmt.Errorf("%s not implemented", r.info.Client) 79 }