github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/pkg/lorry/engines/foxlake/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 foxlake 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: "usql", 43 Container: "foxlake", 44 UserEnv: "$FOXLAKE_ROOT_USER", 45 PasswordEnv: "$FOXLAKE_ROOT_PASSWORD", 46 }, 47 examples: map[models.ClientType]engines.BuildConnectExample{ 48 models.CLI: func(info *engines.ConnectionInfo) string { 49 return fmt.Sprintf(`# foxlake client connection example 50 mysql -h%s -P%s -u%s -p%s 51 `, info.Host, info.Port, info.User, info.Password) 52 }, 53 }, 54 } 55 } 56 57 func (r *Commands) ConnectCommand(connectInfo *engines.AuthInfo) []string { 58 userName := r.info.UserEnv 59 userPass := r.info.PasswordEnv 60 61 if connectInfo != nil { 62 userName = connectInfo.UserName 63 userPass = connectInfo.UserPasswd 64 } 65 66 foxlakeCmd := []string{fmt.Sprintf("%s mysql://%s:%s@:${serverPort}", r.info.Client, userName, userPass)} 67 68 return []string{"sh", "-c", strings.Join(foxlakeCmd, " ")} 69 } 70 71 func (r *Commands) Container() string { 72 return r.info.Container 73 } 74 75 func (r *Commands) ConnectExample(info *engines.ConnectionInfo, client string) string { 76 return engines.BuildExample(info, client, r.examples) 77 } 78 79 func (r *Commands) ExecuteCommand([]string) ([]string, []corev1.EnvVar, error) { 80 return nil, nil, fmt.Errorf("%s not implemented", r.info.Client) 81 }