Skip to content

Commit

Permalink
Merge pull request #396 from jumpserver/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
LeeEirc authored Aug 20, 2020
2 parents 3feed0a + d53cb7c commit 1e57e49
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 55 deletions.
24 changes: 12 additions & 12 deletions cmd/locale/en_US/LC_MESSAGES/koko.po
Original file line number Diff line number Diff line change
Expand Up @@ -237,28 +237,28 @@ msgid "Command `%s` is forbidden"
msgstr ""

#. i18n.T
#: pkg/proxy/dbproxy.go:117
#: pkg/proxy/dbproxy.go:119
msgid "Connecting to Database %s %.1f"
msgstr ""

#. i18n.T
#: pkg/proxy/dbproxy.go:136
#: pkg/proxy/dbproxy.go:138
msgid "System user <%s> and database <%s> protocol are inconsistent."
msgstr ""

#. i18n.T
#: pkg/proxy/dbproxy.go:144
#: pkg/proxy/dbproxy.go:146
msgid "Database %s protocol client not installed."
msgstr ""

#. i18n.T
#: pkg/proxy/dbproxy.go:203
#: pkg/proxy/dbproxy.go:205
msgid "Create database session failed"
msgstr ""

#. i18n.T
#. i18n.T
#: pkg/proxy/dbproxy.go:241 pkg/proxy/dbswitch.go:183
#: pkg/proxy/dbproxy.go:243 pkg/proxy/dbswitch.go:183
msgid "Database connect idle more than %d minutes, disconnect"
msgstr ""

Expand All @@ -268,39 +268,39 @@ msgid "Database connection terminated by administrator"
msgstr ""

#. i18n.T
#: pkg/proxy/k8sproxy.go:69
#: pkg/proxy/k8sproxy.go:71
msgid "Connecting to Kubernetes %s %.1f"
msgstr ""

#. i18n.T
#: pkg/proxy/k8sproxy.go:88
#: pkg/proxy/k8sproxy.go:90
msgid "System user <%s> and kubernetes <%s> protocol are inconsistent."
msgstr ""

#. i18n.T
#: pkg/proxy/k8sproxy.go:96
#: pkg/proxy/k8sproxy.go:98
msgid "%s protocol client not installed."
msgstr ""

#. i18n.T
#: pkg/proxy/k8sproxy.go:104
#: pkg/proxy/k8sproxy.go:106
msgid "You don't have permission login %s"
msgstr ""

#. i18n.T
#: pkg/proxy/k8sproxy.go:112
#: pkg/proxy/k8sproxy.go:114
msgid "You get auth token failed"
msgstr ""

#. i18n.T
#: pkg/proxy/k8sproxy.go:157
#: pkg/proxy/k8sproxy.go:159
msgid "Create k8s session failed"
msgstr ""

#. i18n.T
#. i18n.T
#. i18n.T
#: pkg/proxy/k8sproxy.go:195 pkg/proxy/parser.go:150 pkg/proxy/proxy.go:184
#: pkg/proxy/k8sproxy.go:197 pkg/proxy/parser.go:150 pkg/proxy/proxy.go:184
msgid "Reuse SSH connections (%s@%s) [Number of connections: %d]"
msgstr ""

Expand Down
30 changes: 14 additions & 16 deletions cmd/locale/zh_CN/LC_MESSAGES/koko.po
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ msgstr ""
#: pkg/handler/app_database.go:102
#, fuzzy
msgid "Search: %s"
msgstr "搜索: %s"
msgstr "搜索%s"

#. i18n.T
#: pkg/handler/app_database.go:104
Expand Down Expand Up @@ -224,9 +224,7 @@ msgstr "用户名"
#: pkg/handler/session.go:196
#, fuzzy
msgid "Tips: Enter system user ID and directly login"
msgstr ""
"\n"
"提示:输入系统用户ID,登录资产[ %s(%s) ]\n"
msgstr "提示:输入系统用户ID直接登录"

#. i18n.T
#: pkg/handler/session.go:197
Expand Down Expand Up @@ -254,30 +252,30 @@ msgid "Command `%s` is forbidden"
msgstr "命令 `%s` 是被禁止的 ..."

#. i18n.T
#: pkg/proxy/dbproxy.go:117
#: pkg/proxy/dbproxy.go:119
#, fuzzy
msgid "Connecting to Database %s %.1f"
msgstr "开始连接数据库%s %.1f"

#. i18n.T
#: pkg/proxy/dbproxy.go:136
#: pkg/proxy/dbproxy.go:138
#, fuzzy
msgid "System user <%s> and database <%s> protocol are inconsistent."
msgstr "系统用户<%s>和资产<%s>协议不一致"

#. i18n.T
#: pkg/proxy/dbproxy.go:144
#: pkg/proxy/dbproxy.go:146
msgid "Database %s protocol client not installed."
msgstr "%s 协议的数据库客户端未安装"

#. i18n.T
#: pkg/proxy/dbproxy.go:203
#: pkg/proxy/dbproxy.go:205
msgid "Create database session failed"
msgstr "创建数据库会话失败"

#. i18n.T
#. i18n.T
#: pkg/proxy/dbproxy.go:241 pkg/proxy/dbswitch.go:183
#: pkg/proxy/dbproxy.go:243 pkg/proxy/dbswitch.go:183
#, fuzzy
msgid "Database connect idle more than %d minutes, disconnect"
msgstr "数据库连接空闲时间超过 %d 分钟,断开连接"
Expand All @@ -289,43 +287,43 @@ msgid "Database connection terminated by administrator"
msgstr "管理员中断数据库连接"

#. i18n.T
#: pkg/proxy/k8sproxy.go:69
#: pkg/proxy/k8sproxy.go:71
#, fuzzy
msgid "Connecting to Kubernetes %s %.1f"
msgstr "开始连接Kubernetes %s %.1f"

#. i18n.T
#: pkg/proxy/k8sproxy.go:88
#: pkg/proxy/k8sproxy.go:90
#, fuzzy
msgid "System user <%s> and kubernetes <%s> protocol are inconsistent."
msgstr "系统用户<%s>和kubernetes<%s>协议不一致"

#. i18n.T
#: pkg/proxy/k8sproxy.go:96
#: pkg/proxy/k8sproxy.go:98
#, fuzzy
msgid "%s protocol client not installed."
msgstr "%s 协议的数据库客户端未安装"

#. i18n.T
#: pkg/proxy/k8sproxy.go:104
#: pkg/proxy/k8sproxy.go:106
msgid "You don't have permission login %s"
msgstr "你无权限登陆%s"

#. i18n.T
#: pkg/proxy/k8sproxy.go:112
#: pkg/proxy/k8sproxy.go:114
msgid "You get auth token failed"
msgstr "你获取认证令牌失败"

#. i18n.T
#: pkg/proxy/k8sproxy.go:157
#: pkg/proxy/k8sproxy.go:159
#, fuzzy
msgid "Create k8s session failed"
msgstr "创建Kubernetes会话失败"

#. i18n.T
#. i18n.T
#. i18n.T
#: pkg/proxy/k8sproxy.go:195 pkg/proxy/parser.go:150 pkg/proxy/proxy.go:184
#: pkg/proxy/k8sproxy.go:197 pkg/proxy/parser.go:150 pkg/proxy/proxy.go:184
msgid "Reuse SSH connections (%s@%s) [Number of connections: %d]"
msgstr "复用SSH连接(%s@%s)[连接数量: %d]"

Expand Down
2 changes: 1 addition & 1 deletion pkg/handler/app_k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func (k *K8sApplication) DisplayCurrentResult() {

func (k *K8sApplication) ProxyK8s(dbSelect model.K8sCluster) {
systemUsers := service.GetUserK8sSystemUsers(k.h.user.ID, dbSelect.ID)
defer k.h.term.SetPrompt("[k8s]> ")
defer k.h.term.SetPrompt("[K8S]> ")
systemUserSelect, ok := k.h.chooseSystemUser(systemUsers)
if !ok {
return
Expand Down
4 changes: 2 additions & 2 deletions pkg/handler/dispatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (h *interactiveHandler) Dispatch() {
searchWord := strings.TrimSpace(strings.TrimPrefix(line, "g"))
if num, err := strconv.Atoi(searchWord); err == nil {
<-h.firstLoadDone
if num >= 0 && num <= len(h.nodes) {
if num > 0 && num <= len(h.nodes) {
currentApp = h.getNodeAssetApp(h.nodes[num-1])
currentApp.Search("")
continue
Expand Down Expand Up @@ -188,7 +188,7 @@ func (h *interactiveHandler) getK8sApp() Application {
engine: eng,
searchKeys: make([]string, 0),
}
h.term.SetPrompt("[k8s]> ")
h.term.SetPrompt("[K8S]> ")
return &app
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/handler/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,9 @@ func (h *interactiveHandler) chooseSystemUser(systemUsers []model.SystemUser) (s
backTip := i18n.T("Back: B/b")
for {
utils.IgnoreErrWriteString(h.term, table.Display())
utils.IgnoreErrWriteString(h.term, selectTip)
utils.IgnoreErrWriteString(h.term, utils.WrapperString(selectTip, utils.Green))
utils.IgnoreErrWriteString(h.term, utils.CharNewLine)
utils.IgnoreErrWriteString(h.term, backTip)
utils.IgnoreErrWriteString(h.term, utils.WrapperString(backTip, utils.Green))
utils.IgnoreErrWriteString(h.term, utils.CharNewLine)
line, err := h.term.ReadLine()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/proxy/dbproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ func IsInstalledMysqlClient() bool {
cmd := exec.Command("bash", "-c", checkLine)
out, err := cmd.CombinedOutput()
if err != nil && len(out) == 0 {
logger.Errorf("Check mysql client installed failed: %s", err, out)
logger.Errorf("Check mysql client installed failed: %s", err)
return false
}
if bytes.HasPrefix(out, []byte("mysql")) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/proxy/dbswitch.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func (s *DBSwitchSession) Bridge(userConn UserConnection, srvConn srvconn.Server
return
}
_ = srvConn.SetWinSize(win.Width, win.Height)
logger.Infof("DB Session[%s] Window server change: %d*%d", win.Height, win.Width)
logger.Infof("DB Session[%s] Window server change: %d*%d", s.ID, win.Height, win.Width)
p, _ := json.Marshal(win)
msg := model.RoomMessage{
Event: model.WindowsEvent,
Expand Down
2 changes: 1 addition & 1 deletion pkg/proxy/k8sproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ func IsInstalledKubectlClient() bool {
cmd := exec.Command("bash", "-c", checkLine)
out, err := cmd.CombinedOutput()
if err != nil && len(out) == 0 {
logger.Errorf("Check kubectl client failed %s", err, out)
logger.Errorf("Check kubectl client failed %s", err)
return false
}
var result map[string]interface{}
Expand Down
4 changes: 2 additions & 2 deletions pkg/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (p *ProxyServer) getSystemUserBasicInfo() {
var info model.SystemUserAuthInfo
if p.SystemUser.UsernameSameWithUser {
p.SystemUser.Username = p.User.Username
logger.Infof("Conn[%s] SystemUser username same with user: %s", p.User.Username)
logger.Infof("Conn[%s] SystemUser username same with user: %s", p.UserConn.ID(), p.User.Username)
info = service.GetUserAssetAuthInfo(p.SystemUser.ID, p.Asset.ID, p.User.ID, p.User.Username)
} else {
info = service.GetSystemUserAssetAuthInfo(p.SystemUser.ID, p.Asset.ID)
Expand Down Expand Up @@ -358,7 +358,7 @@ func (p *ProxyServer) Proxy() {
}
msg = utils.WrapperWarn(msg)
utils.IgnoreErrWriteString(p.UserConn, msg)
logger.Errorf("Conn[%s] submit session %s to core server err: %s", p.UserConn.ID(), msg)
logger.Errorf("Conn[%s] submit session %s to core server err: %s", p.UserConn.ID(), sw.ID, msg)
return
}
logger.Infof("Conn[%s] create session %s success", p.UserConn.ID(), sw.ID)
Expand Down
12 changes: 8 additions & 4 deletions pkg/proxy/recorderstorage/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (a AzureReplayStorage) Upload(gZipFilePath, target string) (err error) {
if err != nil {
return
}

defer file.Close()
credential, err := azblob.NewSharedKeyCredential(a.AccountName, a.AccountKey)
if err != nil {
logger.Error("Invalid credentials with error: " + err.Error())
Expand All @@ -34,15 +34,19 @@ func (a AzureReplayStorage) Upload(gZipFilePath, target string) (err error) {
containerURL := azblob.NewContainerURL(*URL, p)
blobURL := containerURL.NewBlockBlobURL(target)

_, err = azblob.UploadFileToBlockBlob(context.TODO(), file, blobURL, azblob.UploadToBlockBlobOptions{
commonResp, err := azblob.UploadFileToBlockBlob(context.TODO(), file, blobURL, azblob.UploadToBlockBlobOptions{
BlockSize: 4 * 1024 * 1024,
Parallelism: 16})
if err != nil {
logger.Error(err.Error())
logger.Errorf("Azure upload file %s failed: %s", gZipFilePath, err)
return err
}
if httpResp := commonResp.Response(); httpResp != nil {
defer httpResp.Body.Close()
}
return
}

func (o AzureReplayStorage) TypeName() string {
func (a AzureReplayStorage) TypeName() string {
return "azure"
}
20 changes: 12 additions & 8 deletions pkg/proxy/recorderstorage/es.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,36 @@ type ESCommandStorage struct {

func (es ESCommandStorage) BulkSave(commands []*model.Command) (err error) {
var buf bytes.Buffer
esClinet, err := elasticsearch.NewClient(elasticsearch.Config{
esClient, err := elasticsearch.NewClient(elasticsearch.Config{
Addresses: es.Hosts,
})
if err != nil {
logger.Error(err.Error())
return
logger.Errorf("ES new client err: %s", err)
return err
}
for _, item := range commands {
meta := []byte(fmt.Sprintf(`{ "index" : { } }%s`, "\n"))
data, err := json.Marshal(item)
if err != nil {
logger.Errorf("ES marshal data to json err: %s", err)
return err
}
data = append(data, "\n"...)
buf.Write(meta)
buf.Write(data)
}

_, err = esClinet.Bulk(bytes.NewReader(buf.Bytes()),
esClinet.Bulk.WithIndex(es.Index), esClinet.Bulk.WithDocumentType(es.DocType))
response, err := esClient.Bulk(bytes.NewReader(buf.Bytes()),
esClient.Bulk.WithIndex(es.Index), esClient.Bulk.WithDocumentType(es.DocType))
if err != nil {
logger.Error(err.Error())
logger.Errorf("ES client bulk save err: %s", err)
return err
}
defer response.Body.Close()
logger.Debugf("ES client bulk save %d commands", len(commands))
return
}

func (f ESCommandStorage) TypeName() string {
func (es ESCommandStorage) TypeName() string {
return "es"
}
}
15 changes: 10 additions & 5 deletions pkg/proxy/recorderstorage/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ func (s S3ReplayStorage) Upload(gZipFilePath, target string) (err error) {

file, err := os.Open(gZipFilePath)
if err != nil {
logger.Debug("Failed to open file", err)
return
logger.Errorf("Open %s file failed: %s", gZipFilePath, err)
return err
}
defer file.Close()
s3Config := &aws.Config{
Expand All @@ -34,7 +34,12 @@ func (s S3ReplayStorage) Upload(gZipFilePath, target string) (err error) {
S3ForcePathStyle: aws.Bool(true),
}

sess := session.Must(session.NewSession(s3Config))
sess, err := session.NewSession(s3Config)
if err != nil {
logger.Errorf("S3 new session failed: %s", err)
return err
}

uploader := s3manager.NewUploader(sess, func(u *s3manager.Uploader) {
u.PartSize = 64 * 1024 * 1024 // 64MB per part
})
Expand All @@ -44,13 +49,13 @@ func (s S3ReplayStorage) Upload(gZipFilePath, target string) (err error) {
Body: file,
})
if err != nil {
logger.Error(err.Error())
logger.Errorf("S3 upload file %s failed: %s", gZipFilePath, err)
return err
}

return
}


func (s S3ReplayStorage) TypeName() string {
return "s3"
}

0 comments on commit 1e57e49

Please sign in to comment.