Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
gjl2004yn
jumpserver
提交
ce6b9de0
J
jumpserver
项目概览
gjl2004yn
/
jumpserver
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
jumpserver
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
ce6b9de0
编写于
4月 13, 2021
作者:
X
xinwen
提交者:
baltery
4月 13, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: ES 自动创建索引
上级
b9775968
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
36 addition
and
1 deletion
+36
-1
apps/terminal/api/command.py
apps/terminal/api/command.py
+16
-1
apps/terminal/backends/command/es.py
apps/terminal/backends/command/es.py
+11
-0
apps/terminal/models/storage.py
apps/terminal/models/storage.py
+9
-0
未找到文件。
apps/terminal/api/command.py
浏览文件 @
ce6b9de0
...
...
@@ -11,6 +11,7 @@ from rest_framework.response import Response
from
rest_framework.decorators
import
action
from
django.template
import
loader
from
common.http
import
is_true
from
terminal.models
import
CommandStorage
,
Command
from
terminal.filters
import
CommandFilter
from
orgs.utils
import
current_org
...
...
@@ -140,7 +141,21 @@ class CommandViewSet(viewsets.ModelViewSet):
if
session_id
and
not
command_storage_id
:
# 会话里的命令列表肯定会提供 session_id,这里防止 merge 的时候取全量的数据
return
self
.
merge_all_storage_list
(
request
,
*
args
,
**
kwargs
)
return
super
().
list
(
request
,
*
args
,
**
kwargs
)
queryset
=
self
.
filter_queryset
(
self
.
get_queryset
())
page
=
self
.
paginate_queryset
(
queryset
)
if
page
is
not
None
:
serializer
=
self
.
get_serializer
(
page
,
many
=
True
)
return
self
.
get_paginated_response
(
serializer
.
data
)
query_all
=
self
.
request
.
query_params
.
get
(
'all'
,
False
)
if
is_true
(
query_all
):
# 适配像 ES 这种没有指定分页只返回少量数据的情况
queryset
=
queryset
[:]
serializer
=
self
.
get_serializer
(
queryset
,
many
=
True
)
return
Response
(
serializer
.
data
)
def
get_queryset
(
self
):
command_storage_id
=
self
.
request
.
query_params
.
get
(
'command_storage_id'
)
...
...
apps/terminal/backends/command/es.py
浏览文件 @
ce6b9de0
...
...
@@ -10,6 +10,7 @@ import inspect
from
django.db.models
import
QuerySet
as
DJQuerySet
from
elasticsearch
import
Elasticsearch
from
elasticsearch.helpers
import
bulk
from
elasticsearch.exceptions
import
RequestError
from
common.utils.common
import
lazyproperty
from
common.utils
import
get_logger
...
...
@@ -31,6 +32,15 @@ class CommandStore():
kwargs
[
'verify_certs'
]
=
None
self
.
es
=
Elasticsearch
(
hosts
=
hosts
,
max_retries
=
0
,
**
kwargs
)
def
pre_use_check
(
self
):
self
.
_ensure_index_exists
()
def
_ensure_index_exists
(
self
):
try
:
self
.
es
.
indices
.
create
(
self
.
index
)
except
RequestError
:
pass
@
staticmethod
def
make_data
(
command
):
data
=
dict
(
...
...
@@ -234,6 +244,7 @@ class QuerySet(DJQuerySet):
uqs
=
QuerySet
(
self
.
_command_store_config
)
uqs
.
_method_calls
=
self
.
_method_calls
.
copy
()
uqs
.
_slice
=
self
.
_slice
uqs
.
model
=
self
.
model
return
uqs
def
count
(
self
,
limit_to_max_result_window
=
True
):
...
...
apps/terminal/models/storage.py
浏览文件 @
ce6b9de0
...
...
@@ -76,6 +76,15 @@ class CommandStorage(CommonModelMixin):
qs
.
model
=
Command
return
qs
def
save
(
self
,
force_insert
=
False
,
force_update
=
False
,
using
=
None
,
update_fields
=
None
):
super
().
save
()
if
self
.
type
in
TYPE_ENGINE_MAPPING
:
engine_mod
=
import_module
(
TYPE_ENGINE_MAPPING
[
self
.
type
])
backend
=
engine_mod
.
CommandStore
(
self
.
config
)
backend
.
pre_use_check
()
class
ReplayStorage
(
CommonModelMixin
):
name
=
models
.
CharField
(
max_length
=
128
,
verbose_name
=
_
(
"Name"
),
unique
=
True
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录