[Agent][Bastion] - Bastion mode - 2
This commit is contained in:
@@ -6,7 +6,9 @@ import (
|
||||
"os"
|
||||
"strings"
|
||||
"wdd.io/agent-go/a_agent"
|
||||
"wdd.io/agent-go/a_executor"
|
||||
"wdd.io/agent-go/a_init/bastion_init"
|
||||
"wdd.io/agent-go/a_status"
|
||||
)
|
||||
|
||||
/*
|
||||
@@ -25,11 +27,22 @@ import (
|
||||
3.5 安装kubernetes
|
||||
*/
|
||||
|
||||
var AllFunctionCache = &bastion_init.Trie{}
|
||||
|
||||
const (
|
||||
InstallDocker = "docker"
|
||||
InstallDockerCompose = "dockercompose"
|
||||
InstallMinio = "minio"
|
||||
InstallRabbitmq = "rabbitmq"
|
||||
Exit = "exit"
|
||||
Help = "help"
|
||||
)
|
||||
|
||||
// BastionModeInit 堡垒机模式 完全离线模式
|
||||
func BastionModeInit() {
|
||||
|
||||
// Build For Operator
|
||||
_ = &a_agent.AgentServerInfo{
|
||||
bastionAgentServerInfo := &a_agent.AgentServerInfo{
|
||||
ServerName: "BastionSingle",
|
||||
ServerIPPbV4: "127.0.0.1",
|
||||
ServerIPInV4: "127.0.0.1",
|
||||
@@ -59,53 +72,78 @@ func BastionModeInit() {
|
||||
TopicName: "BastionNode",
|
||||
}
|
||||
|
||||
// build for bastion mode operator
|
||||
// re-get agentInfo from status module
|
||||
//agentInfo := a_status.ReportAgentInfo()
|
||||
//refreshAgentInfoByStatusInfo(agentInfo, agentServerInfo)
|
||||
//buildAgentOsOperator(agentInfo, agentServerInfo)
|
||||
agentInfo := a_status.ReportAgentInfo()
|
||||
refreshAgentInfoByStatusInfo(agentInfo, bastionAgentServerInfo)
|
||||
|
||||
// install docker
|
||||
//agentOsOperator := a_executor.AgentOsOperatorCache
|
||||
// boot up minio & rabbitmq
|
||||
//agentOsOperator.InstallDockerFromLocalExec(nil)
|
||||
//agentOsOperator.InstallDockerComposeFromLocalExec()
|
||||
// build operator cache
|
||||
buildAgentOsOperator(agentInfo, bastionAgentServerInfo)
|
||||
|
||||
// build for socks server
|
||||
// 缓存此内容
|
||||
a_agent.AgentServerInfoCache = bastionAgentServerInfo
|
||||
agentOperator := a_executor.AgentOsOperatorCache
|
||||
|
||||
words := []string{"apple", "apricot", "apprentice", "application"}
|
||||
t := bastion_init.NewTrie()
|
||||
t.InsertAll(words)
|
||||
// build for all functions
|
||||
buildBastionModeFunction()
|
||||
|
||||
prefix := "ap"
|
||||
closest, err := bastion_init.FindClosestWord(t, prefix)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
} else {
|
||||
fmt.Printf("The closest word to '%s' is '%s'\n", prefix, closest)
|
||||
}
|
||||
// build for function arguments list
|
||||
//var funcArgsList []string
|
||||
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
bastion_init.PrintBastionHelp()
|
||||
|
||||
for {
|
||||
bastion_init.PrintBastionHelp()
|
||||
|
||||
fmt.Println()
|
||||
fmt.Print("enter ==> ")
|
||||
|
||||
text, _ := reader.ReadString('\n')
|
||||
text = strings.TrimSpace(text)
|
||||
inputCommand := uniformInputCommand(text)
|
||||
fmt.Println("inputCommand: ", inputCommand)
|
||||
|
||||
if text == "quit" {
|
||||
break
|
||||
} else if text == "help" {
|
||||
// execute the function
|
||||
switch inputCommand {
|
||||
case InstallDocker:
|
||||
agentOperator.InstallDockerBastion()
|
||||
case InstallDockerCompose:
|
||||
agentOperator.InstallDockerComposeBastion()
|
||||
case InstallMinio:
|
||||
agentOperator.InstallMinioBastion()
|
||||
case Exit:
|
||||
os.Exit(0)
|
||||
case Help:
|
||||
bastion_init.PrintBastionHelp()
|
||||
} else {
|
||||
// Execute the command
|
||||
fmt.Println("Executing command:", text)
|
||||
default:
|
||||
fmt.Println("inputCommand is not exist ! Please input again")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// uniformInputCommand 归一化输入的命令
|
||||
func uniformInputCommand(inputString string) {
|
||||
func buildBastionModeFunction() {
|
||||
// build the tree search node
|
||||
log.Info("build the tree search node")
|
||||
|
||||
tcc := bastion_init.NewTrie()
|
||||
tcc.Insert(InstallDocker)
|
||||
tcc.Insert(InstallDockerCompose)
|
||||
tcc.Insert(InstallMinio)
|
||||
tcc.Insert(InstallRabbitmq)
|
||||
tcc.Insert(Help)
|
||||
tcc.Insert(Exit)
|
||||
|
||||
AllFunctionCache = tcc
|
||||
}
|
||||
|
||||
// uniformInputCommand 归一化输入的命令
|
||||
func uniformInputCommand(inputString string) string {
|
||||
|
||||
findClosestWord, err := bastion_init.FindClosestWord(AllFunctionCache, inputString)
|
||||
if err != nil {
|
||||
log.ErrorF("inputString error: %s", err.Error())
|
||||
}
|
||||
|
||||
return findClosestWord
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user