Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
coco
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ops
coco
Commits
01635fad
Unverified
Commit
01635fad
authored
Jul 18, 2019
by
BaiJiangJie
Committed by
GitHub
Jul 18, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #246 from jumpserver/dev
Dev
parents
55841ed2
ff28d9a3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
7 deletions
+26
-7
interactive.py
coco/interactive.py
+15
-4
sftp.py
coco/sftp.py
+11
-3
No files found.
coco/interactive.py
View file @
01635fad
...
...
@@ -47,6 +47,7 @@ class InteractiveServer:
self
.
node_tree
=
None
# 授权节点树
self
.
load_user_assets_from_cache
()
self
.
get_user_assets_and_update_async
()
self
.
load_user_nodes_from_cache
()
self
.
get_user_nodes_async
()
@property
...
...
@@ -344,6 +345,11 @@ class InteractiveServer:
# Nodes
#
def
load_user_nodes_from_cache
(
self
):
nodes
=
self
.
__class__
.
_user_nodes_cached
.
get
(
self
.
client
.
user
.
id
)
self
.
nodes
=
nodes
self
.
_construct_node_tree
()
def
get_user_nodes_async
(
self
):
thread
=
threading
.
Thread
(
target
=
self
.
get_user_nodes
,
kwargs
=
{
"cache_policy"
:
1
})
thread
.
start
()
...
...
@@ -359,11 +365,11 @@ class InteractiveServer:
logger
.
debug
(
"Get user nodes: not modify"
)
return
nodes
=
sorted
(
nodes
,
key
=
lambda
node
:
node
.
key
)
self
.
nodes
=
self
.
filter_system_users_of_assets_under_nodes
(
nodes
)
self
.
__class__
.
_user_nodes_cached
[
self
.
client
.
user
.
id
]
=
self
.
nodes
nodes
=
self
.
filter_system_users_of_assets_under_nodes
(
nodes
)
self
.
__class__
.
_user_nodes_cached
[
self
.
client
.
user
.
id
]
=
nodes
if
new_etag
:
self
.
__class__
.
_user_assets_cached_etag
[
self
.
client
.
user
.
id
]
=
new_etag
self
.
_construct_node_tre
e
()
self
.
load_user_nodes_from_cach
e
()
def
filter_system_users_of_assets_under_nodes
(
self
,
nodes
):
for
node
in
nodes
:
...
...
@@ -371,6 +377,8 @@ class InteractiveServer:
return
nodes
def
_construct_node_tree
(
self
):
if
not
self
.
nodes
:
return
self
.
node_tree
=
Tree
()
root
=
'ROOT_ALL_ORG_NODE'
self
.
node_tree
.
create_node
(
tag
=
''
,
identifier
=
root
,
parent
=
None
)
...
...
@@ -390,7 +398,10 @@ class InteractiveServer:
self
.
node_tree
.
show
(
key
=
lambda
node
:
node
.
identifier
)
self
.
client
.
send_unicode
(
wr
(
title
(
_
(
"Node: [ ID.Name(Asset amount) ]"
)),
before
=
0
))
self
.
client
.
send_unicode
(
wr
(
self
.
node_tree
.
_reader
.
replace
(
'
\n
'
,
'
\r\n
'
),
before
=
0
))
for
line
in
self
.
node_tree
.
_reader
.
splitlines
():
self
.
client
.
send_unicode
(
wr
(
line
))
prompt
=
_
(
"Tips: Enter g+NodeID to display the host under the node, such as g1"
)
self
.
client
.
send_unicode
(
wr
(
title
(
prompt
),
before
=
1
))
...
...
coco/sftp.py
View file @
01635fad
...
...
@@ -11,6 +11,7 @@ from coco.utils import get_logger
from
.conf
import
config
from
.service
import
app_service
from
.connection
import
SSHConnection
from
.interactive
import
InteractiveServer
from
.const
import
(
PERMS_ACTION_NAME_DOWNLOAD_FILE
,
PERMS_ACTION_NAME_UPLOAD_FILE
,
)
...
...
@@ -73,11 +74,18 @@ class SFTPServer(paramiko.SFTPServerInterface):
self
.
hosts
=
self
.
get_permed_hosts
()
self
.
is_finished
=
False
def
get_user_assets
(
self
):
user_id
=
self
.
server
.
connection
.
user
.
id
assets
=
InteractiveServer
.
_user_assets_cached
.
get
(
user_id
)
if
assets
is
None
:
assets
,
new_etag
=
app_service
.
get_user_assets
(
self
.
server
.
connection
.
user
,
cache_policy
=
'1'
)
return
assets
def
get_permed_hosts
(
self
):
hosts
=
{}
assets
=
app_service
.
get_user_assets
(
self
.
server
.
connection
.
user
,
cache_policy
=
'1'
,
)
assets
=
self
.
get_user_assets
()
for
asset
in
assets
:
if
not
asset
.
has_protocol
(
'ssh'
):
continue
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment