Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
ttktatakai committed Mar 4, 2024
1 parent 08e955f commit 4084216
Show file tree
Hide file tree
Showing 15 changed files with 534 additions and 463 deletions.
4 changes: 2 additions & 2 deletions backend/cmd/api/app/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

"github.com/veops/oneterm/pkg/conf"
"github.com/veops/oneterm/pkg/logger"
"github.com/veops/oneterm/pkg/server/controller"
gsession "github.com/veops/oneterm/pkg/server/global/session"
"github.com/veops/oneterm/pkg/server/router"
"github.com/veops/oneterm/pkg/server/schedule/cmdb"
"github.com/veops/oneterm/pkg/server/schedule/connectable"
Expand Down Expand Up @@ -80,7 +80,7 @@ func Run() {
os.Exit(1)
}

if err := controller.Init(); err != nil {
if err := gsession.Init(); err != nil {
logger.L.Error("local init failed: " + err.Error())
os.Exit(1)
}
Expand Down
40 changes: 28 additions & 12 deletions backend/pkg/i18n/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ var (
One: "\n----------Session {{.sessionId}} has been ended----------\n",
Other: "\n----------Session {{.sessionId}} has been ended----------\n",
}
MsgLoginError = &goi18n.Message{
ID: "MsgLoginError",
One: "Bad Request: Invalid account",
Other: "Bad Request: Invalid account",
}
MsgAccessTime = &goi18n.Message{
ID: "MsgAccessTime",
One: "Bad Request: current time is not allowed to access",
Other: "Bad Request: current time is not allowed to access",
}
//
MsgInternalError = &goi18n.Message{
ID: "MsgInternalError",
Expand Down Expand Up @@ -119,38 +129,39 @@ var (
MsgSshShowAssetResults = &goi18n.Message{
ID: "MsgSshShowAssetResults",
One: "Total host count is:\033[0;32m {{.Count}} \033[0m \r\n{{.Msg}}\r\n",
Other: "ShowAssetResultsOther",
Other: "Total host count is:\033[0;32m {{.Count}} \033[0m \r\n{{.Msg}}\r\n",
}
MsgSshAccountLoginError = &goi18n.Message{
ID: "MsgSshAccountLoginError",
One: "\x1b[1;30;32m failed login \x1b[0m \x1b[1;30;3m {{.User}}\x1b[0m\n" +
"\x1b[0;33m you need to choose asset again \u001B[0m\n",
Other: "AccountLoginErrorOther",
Other: "\x1b[1;30;32m failed login \x1b[0m \x1b[1;30;3m {{.User}}\x1b[0m\n" +
"\x1b[0;33m you need to choose asset again \u001B[0m\n",
}
MsgSshNoAssetPermission = &goi18n.Message{
ID: "MsgSshNoAssetPermission",
One: "\r\n\u001B[0;33mNo permission for[0m:\033[0;31m {{.Host}} \033[0m\r\n",
Other: "NoAssetPermissionOther",
Other: "\r\n\u001B[0;33mNo permission for[0m:\033[0;31m {{.Host}} \033[0m\r\n",
}
MsgSshNoMatchingAsset = &goi18n.Message{
ID: "MsgSshNoMatchingAsset",
One: "\x1b[0;33mNo matching asset for :\x1b[0m \x1b[0;94m{{.Host}} \x1b[0m\r\n",
Other: "MsgSshNoMatchingAsset",
Other: "\x1b[0;33mNo matching asset for :\x1b[0m \x1b[0;94m{{.Host}} \x1b[0m\r\n",
}
MsgSshNoSshAccessMethod = &goi18n.Message{
ID: "MsgSshNoSshAccessMethod",
One: "No ssh access method for :\033[0;31m {{.Host}} \033[0m\r\n",
Other: "NoSshAccessMethodOther",
Other: "No ssh access method for :\033[0;31m {{.Host}} \033[0m\r\n",
}
MsgSshNoSshAccountForAsset = &goi18n.Message{
ID: "MsgSshNoSshAccountForAsset",
One: "No ssh account for :\033[0;31m {{.Host}} \033[0m\r\n",
Other: "NoSshAccountForAssetOther",
Other: "No ssh account for :\033[0;31m {{.Host}} \033[0m\r\n",
}
MsgSshMultiSshAccountForAsset = &goi18n.Message{
ID: "MsgSshMultiSshAccountForAsset",
One: "choose account: \n\033[0;31m {{.Accounts}} \033[0m\n",
Other: "MultiSshAccountForAssetOther",
Other: "choose account: \n\033[0;31m {{.Accounts}} \033[0m\n",
}
MsgSshWelcome = &goi18n.Message{
ID: "MsgSshWelcomeMsg",
Expand All @@ -160,28 +171,33 @@ var (
"\x1b[1;30;32m IP/hostname \x1b[0m to search and login if only one, eg. 192\r\n" +
"\x1b[1;30;32m /q \x1b[0m to exit\r\n" +
"\x1b[1;30;32m /? \x1b[0m for help\r\n",
Other: "WelcomeMsgOther",
Other: "\x1b[0;47m Welcome: {{.User}} \x1b[0m\r\n" +
" \x1b[1;30;32m /s \x1b[0m to switch language between english and 中文\r\n" +
"\x1b[1;30;32m /* \x1b[0m to list all host which you have permission\r\n" +
"\x1b[1;30;32m IP/hostname \x1b[0m to search and login if only one, eg. 192\r\n" +
"\x1b[1;30;32m /q \x1b[0m to exit\r\n" +
"\x1b[1;30;32m /? \x1b[0m for help\r\n",
}
MsgSshCommandRefused = &goi18n.Message{
ID: "MsgSshCommandRefused",
One: "\x1b[0;31m you have no permission to execute command: \x1b[0m \x1b[0;33m{{.Command}} \x1b[0m\r\n",
Other: "MsgSshCommandRefusedOther",
Other: "\x1b[0;31m you have no permission to execute command: \x1b[0m \x1b[0;33m{{.Command}} \x1b[0m\r\n",
}
MsgSShHostIdleTimeout = &goi18n.Message{
ID: "MsgSShHostIdleTimeout",
One: "\r\n\x1b[0;31m disconnect since idle more than\x1b[0m \x1b[0;33m {{.Idle}} \x1b[0m\r\n",
Other: "MsgSShHostIdleTimeoutOther",
Other: "\r\n\x1b[0;31m disconnect since idle more than\x1b[0m \x1b[0;33m {{.Idle}} \x1b[0m\r\n",
}

MsgSshAccessRefusedInTimespan = &goi18n.Message{
ID: "MsgSshAccessRefusedInTimespan",
One: "\r\n\x1b[0;31m disconnect since current time is not allowed \x1b[0m\r\n",
Other: "MsgSshAccessRefusedInTimespanOther",
Other: "\r\n\x1b[0;31m disconnect since current time is not allowed \x1b[0m\r\n",
}

MsgSShWelcomeForHelp = &goi18n.Message{
ID: "MsgSShWelcomeForHelp",
One: "\x1b[31;47m Welcome: {{.User}}",
Other: "MsgSShWelcomeForHelp",
Other: "\x1b[31;47m Welcome: {{.User}}",
}
)
104 changes: 38 additions & 66 deletions backend/pkg/i18n/translate/active.en.toml
Original file line number Diff line number Diff line change
@@ -1,122 +1,110 @@
[MsgAccessTime]
one = "Bad Request: current time is not allowed to access"
other = "Bad Request: current time is not allowed to access"

[MsgArgumentError]
hash = "sha1-362dc86add63740c0adfc87b90fa6d1a76b0af2d"
many = "Bad Request: Argument is invalid, {{.err}}"
one = "Bad Request: Argument is invalid, {{.err}}"
other = "Bad Request: Argument is invalid, {{.err}}"

[MsgBadRequest]
hash = "sha1-ce2a43b7dbe690adefef142f93b5f37e29ceb5f9"
many = "Bad Request: {{.err}}"
one = "Bad Request: {{.err}}"
other = "Bad Request: {{.err}}"

[MsgConnectServer]
hash = "sha1-3d9e42d4d82b873203fef24cf7865de8c64d9dc4"
many = "Connect Server Error"
one = "Connect Server Error"
other = "Connect Server Error"

[MsgDupName]
hash = "sha1-e170045255d10872b5cbcf32f29c0fdbcebb8d6c"
many = "Bad Request: {{.name}} is duplicate"
one = "Bad Request: {{.name}} is duplicate"
other = "Bad Request: {{.name}} is duplicate"

[MsgHasChild]
hash = "sha1-657547f2a971f07890ee54e5a5b3d15801efef9d"
many = "Bad Request: This folder has sub folder or assert, cannot be deleted"
one = "Bad Request: This folder has sub folder or assert, cannot be deleted"
other = "Bad Request: This folder has sub folder or assert, cannot be deleted"

[MsgHasDepdency]
hash = "sha1-742d552bba52b9dedec287d46b70f6bc810dc759"
many = "Bad Request: Asset {{.name}} dependens on this, cannot be deleted"
one = "Bad Request: Asset {{.name}} dependens on this, cannot be deleted"
other = "Bad Request: Asset {{.name}} dependens on this, cannot be deleted"

[MsgInternalError]
hash = "sha1-a52fb3157738021674255481e2e949e83064dd2b"
many = "Server Error: {{.err}}"
one = "Server Error: {{.err}}"
other = "Server Error: {{.err}}"

[MsgInvalidSessionId]
hash = "sha1-cde5615d9fe5010a47a5572c5bbdd379d5d9bf41"
many = "Bad Request: Invalid session id {{.sessionId}}"
one = "Bad Request: Invalid session id {{.sessionId}}"
other = "Bad Request: Invalid session id {{.sessionId}}"

[MsgLoadSession]
hash = "sha1-58aa1fb9d4e3648849877723a19dc64634e1da3d"
many = "Load Session Faild"
one = "Load Session Faild"
other = "Load Session Faild"

[MsgLoginError]
one = "Bad Request: Invalid account"
other = "Bad Request: Invalid account"

[MsgNoPerm]
hash = "sha1-086946e776d00a6f09fbae8f3df244cd2160f433"
many = "Bad Request: You do not have {{.perm}} permission"
one = "Bad Request: You do not have {{.perm}} permission"
other = "Bad Request: You do not have {{.perm}} permission"

[MsgRemote]
hash = "sha1-0c6217c9a4b713d7ab02d8422a8ae7f3339e31ec"
many = "Bad Request: {{.message}}"
one = "Bad Request: {{.message}}"
other = "Bad Request: {{.message}}"

[MsgRemoteServer]
hash = "sha1-1b419a55cf846d5f9779b2e883cc9f4c5c89aa9d"
many = "Server Error: {{.message}}"
one = "Server Error: {{.message}}"
other = "Server Error: {{.message}}"

[MsgSShHostIdleTimeout]
one = "\r\n\u001b[0;31m disconnect since idle more than\u001b[0m \u001b[0;33m {{.Idle}} \u001b[0m\r\n"
other = "\r\n\u001b[0;31m disconnect since idle more than\u001b[0m \u001b[0;33m {{.Idle}} \u001b[0m\r\n"

[MsgSShWelcomeForHelp]
one = "\u001b[31;47m Welcome: {{.User}}"
other = "\u001b[31;47m Welcome: {{.User}}"

[MsgSessionEnd]
hash = "sha1-1dec3e3125610522edc06e644f321d1a9c166508"
many = "\n----------Session {{.sessionId}} has been ended----------\n"
one = "\n----------Session {{.sessionId}} has been ended----------\n"
other = "\n----------Session {{.sessionId}} has been ended----------\n"

[MsgSshAccessRefusedInTimespan]
one = "\r\n\u001b[0;31m disconnect since current time is not allowed \u001b[0m\r\n"
other = "\r\n\u001b[0;31m disconnect since current time is not allowed \u001b[0m\r\n"

[MsgSshAccountLoginError]
hash = "sha1-56b115cbab2672d62913f0be2533b286213f5697"
many = "AccountLoginErrorOther"
one = "\u001b[1;30;32m failed login \u001b[0m \u001b[4;30;3m {{.User}}\u001b[0m\n\u001b[0;33m you need to choose asset again \u001b[0m\n"
other = "AccountLoginErrorOther"
one = "\u001b[1;30;32m failed login \u001b[0m \u001b[1;30;3m {{.User}}\u001b[0m\n\u001b[0;33m you need to choose asset again \u001b[0m\n"
other = "\u001b[1;30;32m failed login \u001b[0m \u001b[1;30;3m {{.User}}\u001b[0m\n\u001b[0;33m you need to choose asset again \u001b[0m\n"

[MsgSshCommandRefused]
one = "\u001b[0;31m you have no permission to execute command: \u001b[0m \u001b[0;33m{{.Command}} \u001b[0m\r\n"
other = "\u001b[0;31m you have no permission to execute command: \u001b[0m \u001b[0;33m{{.Command}} \u001b[0m\r\n"

[MsgSshMultiSshAccountForAsset]
hash = "sha1-610e0729478a3bcf0dbd20ba8d2ac99285ef1203"
many = "MultiSshAccountForAssetOther"
one = "choose account: \n\u001b[0;31m {{.Accounts}} \u001b[0m\n"
other = "MultiSshAccountForAssetOther"
other = "choose account: \n\u001b[0;31m {{.Accounts}} \u001b[0m\n"

[MsgSshNoAssetPermission]
hash = "sha1-c2e665e88c6439ed5be62508c90171fbe6dc5124"
many = "NoAssetPermissionOther"
one = "No permission for :\u001b[0;31m {{.Host}} \u001b[0m\r\n"
other = "NoAssetPermissionOther"
one = "\r\n\u001b[0;33mNo permission for[0m:\u001b[0;31m {{.Host}} \u001b[0m\r\n"
other = "\r\n\u001b[0;33mNo permission for[0m:\u001b[0;31m {{.Host}} \u001b[0m\r\n"

[MsgSshNoMatchingAsset]
one = "\u001b[0;33mNo matching asset for :\u001b[0m \u001b[0;94m{{.Host}} \u001b[0m\r\n"
other = "\u001b[0;33mNo matching asset for :\u001b[0m \u001b[0;94m{{.Host}} \u001b[0m\r\n"

[MsgSshNoSshAccessMethod]
hash = "sha1-c6687b9f627968f6a94050ea5651ba8198ff022f"
many = "NoSshAccessMethodOther"
one = "No ssh access method for :\u001b[0;31m {{.Host}} \u001b[0m\r\n"
other = "NoSshAccessMethodOther"
other = "No ssh access method for :\u001b[0;31m {{.Host}} \u001b[0m\r\n"

[MsgSshNoSshAccountForAsset]
hash = "sha1-361247824ccc685fc82ef91ed0d67dbeab9e01cb"
many = "NoSshAccountForAssetOther"
one = "No ssh account for :\u001b[0;31m {{.Host}} \u001b[0m\r\n"
other = "NoSshAccountForAssetOther"
other = "No ssh account for :\u001b[0;31m {{.Host}} \u001b[0m\r\n"

[MsgSshShowAssetResults]
hash = "sha1-2911e21b4a1a6c46cc67c8212c6918c8f4ce8d32"
many = "ShowAssetResultsOther"
one = "Total host count is:\u001b[0;32m {{.Count}} \u001b[0m \r\n{{.Msg}}\r\n"
other = "ShowAssetResultsOther"
other = "Total host count is:\u001b[0;32m {{.Count}} \u001b[0m \r\n{{.Msg}}\r\n"

[MsgSshWelcomeMsg]
hash = "sha1-764a3cb5c081536d5f574875ab5758d9b26942e8"
many = "WelcomeMsgOther"
one = "\u001b[0;33m Current User: {{.User}} \u001b[0m\r\n\u001b[1;30;32m IP/hostname \u001b[0m to search and login if only one, eg. 192\r\n\u001b[1;30;32m /s \u001b[0m to switch language between english and 中文\r\n\u001b[1;30;32m /* \u001b[0m to list all host which you have permission\r\n\u001b[1;30;32m /q \u001b[0m to exit\r\n\u001b[1;30;32m ? \u001b[0m for help\r\n"
other = "\u001b[0;33m Current User: {{.User}} \u001b[0m\r\n\u001b[1;30;32m IP/hostname \u001b[0m to search and login if only one, eg. 192\r\n\u001b[1;30;32m /s \u001b[0m to switch language between english and 中文\r\n\u001b[1;30;32m /* \u001b[0m to list all host which you have permission\r\n\u001b[1;30;32m /q \u001b[0m to exit\r\n\u001b[1;30;32m ? \u001b[0m for help\r\n"
one = "\u001b[0;47m Welcome: {{.User}} \u001b[0m\r\n \u001b[1;30;32m /s \u001b[0m to switch language between english and 中文\r\n\u001b[1;30;32m /* \u001b[0m to list all host which you have permission\r\n\u001b[1;30;32m IP/hostname \u001b[0m to search and login if only one, eg. 192\r\n\u001b[1;30;32m /q \u001b[0m to exit\r\n\u001b[1;30;32m /? \u001b[0m for help\r\n"
other = "\u001b[0;47m Welcome: {{.User}} \u001b[0m\r\n \u001b[1;30;32m /s \u001b[0m to switch language between english and 中文\r\n\u001b[1;30;32m /* \u001b[0m to list all host which you have permission\r\n\u001b[1;30;32m IP/hostname \u001b[0m to search and login if only one, eg. 192\r\n\u001b[1;30;32m /q \u001b[0m to exit\r\n\u001b[1;30;32m /? \u001b[0m for help\r\n"

[MsgTypeMappingAccount]
one = "Account"
Expand Down Expand Up @@ -149,19 +137,3 @@ other = "Bad Request: Invalid Mac address"
[MsgWrongPk]
one = "Bad Request: Invalid SSH public key"
other = "Bad Request: Invalid SSH public key"

[MsgSshCommandRefused]
one = "\u001b[0;31m you have no permission to execute command: \u001b[0m \u001b[0;33m{{.Command}} \u001b[0m\r\n"
other= "\u001b[0;31m you have no permission to execute command: \u001b[0m \u001b[0;33m{{.Command}} \u001b[0m\r\n"

[MsgSshNoMatchingAsset]
one = "\u001b[0;33mNo matching asset for :\u001b[0m \u001b[4;94m{{.Host}} \u001b[0m\r\n"
other = "MsgSshNoMatchingAsset"

[MsgSShHostIdleTimeout]
one = "\r\n\u001b[0;31m disconnect since idle more than\u001b[0m \u001b[0;33m {{.Idle}} \u001b[0m\r\n"
other = "\r\n\u001b[0;31m disconnect since idle more than\u001b[0m \u001b[0;33m {{.Idle}} \u001b[0m\r\n"

[MsgSshAccessRefusedInTimespan]
one = "\r\n\u001b[0;31m disconnect since current time is not allowed \u001b[0m\r\n"
other = "\r\n\u001b[0;31m disconnect since current time is not allowed \u001b[0m\r\n"
Loading

0 comments on commit 4084216

Please sign in to comment.