Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
J
jumpserver
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
jumpserver
Commits
2d0be8f9
Commit
2d0be8f9
authored
Dec 15, 2017
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[git status
parent
b97d5b09
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
31 additions
and
25 deletions
+31
-25
const.py
apps/assets/const.py
+2
-2
user.py
apps/assets/models/user.py
+10
-12
tasks.py
apps/assets/tasks.py
+7
-3
common_tags.py
apps/common/templatetags/common_tags.py
+1
-1
models.py
apps/ops/models.py
+7
-6
session.py
apps/terminal/views/session.py
+4
-1
No files found.
apps/assets/const.py
View file @
2d0be8f9
...
...
@@ -39,7 +39,7 @@ TEST_ASSET_CONN_TASK_NAME = "ASSET_CONN_TEST_MANUAL"
TEST_SYSTEM_USER_CONN_PERIOD_LOCK_KEY
=
"TEST_SYSTEM_USER_CONN_PERIOD_KEY"
TEST_SYSTEM_USER_CONN_PERIOD_TASK_NAME
=
"TEST-SYSTEM-USER-CONN-PERIOD-TASK"
TEST_SYSTEM_USER_CONN_CACHE_KEY_PREFIX
=
"SYSTEM_USER_CONN_"
TEST_SYSTEM_USER_CONN_TASK_NAME
=
"TEST-
ADMIN
-USER-CONN-{}"
TEST_SYSTEM_USER_CONN_TASK_NAME
=
"TEST-
SYSTEM
-USER-CONN-{}"
TEST_SYSTEM_USER_CONN_LOCK_KEY
=
"TEST_SYSTEM_USER_CONN_{}"
SYSTEM_USER_CONN_CACHE_KEY
=
"SYSTEM_USER_CONN_{}"
TEST_SYSTEM_USER_CONN_TASKS
=
[
...
...
@@ -52,6 +52,6 @@ TEST_SYSTEM_USER_CONN_TASKS = [
]
TASK_OPTIONS
=
{
'timeout'
:
6
0
,
'timeout'
:
1
0
,
'forks'
:
10
,
}
apps/assets/models/user.py
View file @
2d0be8f9
...
...
@@ -114,6 +114,16 @@ class AssetUser(models.Model):
private_key
=
private_key
,
public_key
=
public_key
)
def
_to_secret_json
(
self
):
"""Push system user use it"""
return
{
'name'
:
self
.
name
,
'username'
:
self
.
username
,
'password'
:
self
.
password
,
'public_key'
:
self
.
public_key
,
'private_key'
:
self
.
private_key_file
,
}
class
Meta
:
abstract
=
True
...
...
@@ -195,18 +205,6 @@ class SystemUser(AssetUser):
def
__str__
(
self
):
return
self
.
name
def
_to_secret_json
(
self
):
"""Push system user use it"""
return
{
'name'
:
self
.
name
,
'username'
:
self
.
username
,
'shell'
:
self
.
shell
,
'sudo'
:
self
.
sudo
,
'password'
:
self
.
password
,
'public_key'
:
self
.
public_key
,
'private_key_file'
:
self
.
private_key_file
,
}
def
get_clusters_assets
(
self
):
from
.asset
import
Asset
clusters
=
self
.
cluster
.
all
()
...
...
apps/assets/tasks.py
View file @
2d0be8f9
...
...
@@ -173,7 +173,10 @@ def test_admin_user_connectability_manual(asset, task_name=None):
task_name
=
const
.
TEST_ASSET_CONN_TASK_NAME
hosts
=
[
asset
.
hostname
]
tasks
=
const
.
TEST_ADMIN_USER_CONN_TASKS
task
=
create_or_update_task
(
task_name
,
tasks
=
tasks
,
hosts
=
hosts
)
task
=
create_or_update_task
(
task_name
,
tasks
=
tasks
,
hosts
=
hosts
,
run_as_admin
=
True
,
created_by
=
'System'
,
options
=
const
.
TASK_OPTIONS
,
pattern
=
'all'
,
)
result
=
task
.
run
()
if
result
.
results_summary
[
'dark'
]:
...
...
@@ -194,7 +197,7 @@ def test_system_user_connectability(system_user, force=False):
"""
from
ops.utils
import
create_or_update_task
lock_key
=
const
.
TEST_SYSTEM_USER_CONN_LOCK_KEY
.
format
(
system_user
.
name
)
task_name
=
const
.
TEST_SYSTEM_USER_CONN_TASK_NAME
task_name
=
const
.
TEST_SYSTEM_USER_CONN_TASK_NAME
.
format
(
system_user
.
name
)
if
cache
.
get
(
lock_key
,
0
)
==
1
and
not
force
:
logger
.
debug
(
"Task {} is running or before long, passed this time"
.
format
(
task_name
))
return
{}
...
...
@@ -202,7 +205,8 @@ def test_system_user_connectability(system_user, force=False):
hosts
=
[
asset
.
hostname
for
asset
in
assets
]
tasks
=
const
.
TEST_SYSTEM_USER_CONN_TASKS
task
=
create_or_update_task
(
task_name
,
hosts
=
hosts
,
tasks
=
tasks
,
options
=
const
.
TASK_OPTIONS
,
task_name
,
hosts
=
hosts
,
tasks
=
tasks
,
pattern
=
'all'
,
options
=
const
.
TASK_OPTIONS
,
run_as
=
system_user
.
name
,
created_by
=
"System"
,
)
cache
.
set
(
lock_key
,
1
,
CACHE_MAX_TIME
)
...
...
apps/common/templatetags/common_tags.py
View file @
2d0be8f9
...
...
@@ -57,7 +57,7 @@ def int_to_str(value):
def
ts_to_date
(
ts
):
try
:
ts
=
float
(
ts
)
except
Typ
eError
:
except
Valu
eError
:
ts
=
0
dt
=
timezone
.
datetime
.
fromtimestamp
(
ts
)
.
\
replace
(
tzinfo
=
timezone
.
get_current_timezone
())
...
...
apps/ops/models.py
View file @
2d0be8f9
...
...
@@ -23,7 +23,7 @@ class Task(models.Model):
id
=
models
.
UUIDField
(
default
=
uuid
.
uuid4
,
primary_key
=
True
)
name
=
models
.
CharField
(
max_length
=
128
,
unique
=
True
,
verbose_name
=
_
(
'Name'
))
is_deleted
=
models
.
BooleanField
(
default
=
False
)
created_by
=
models
.
CharField
(
max_length
=
128
,
blank
=
True
,
default
=
''
)
created_by
=
models
.
CharField
(
max_length
=
128
,
blank
=
True
,
null
=
True
,
default
=
''
)
date_created
=
models
.
DateTimeField
(
auto_now_add
=
True
)
__latest_adhoc
=
None
...
...
@@ -93,13 +93,13 @@ class AdHoc(models.Model):
id
=
models
.
UUIDField
(
default
=
uuid
.
uuid4
,
primary_key
=
True
)
task
=
models
.
ForeignKey
(
Task
,
related_name
=
'adhoc'
,
on_delete
=
models
.
CASCADE
)
_tasks
=
models
.
TextField
(
verbose_name
=
_
(
'Tasks'
))
pattern
=
models
.
CharField
(
max_length
=
64
,
default
=
''
,
verbose_name
=
_
(
'Pattern'
))
pattern
=
models
.
CharField
(
max_length
=
64
,
default
=
'
{}
'
,
verbose_name
=
_
(
'Pattern'
))
_options
=
models
.
CharField
(
max_length
=
1024
,
default
=
''
,
verbose_name
=
_
(
'Options'
))
_hosts
=
models
.
TextField
(
blank
=
True
,
verbose_name
=
_
(
'Hosts'
))
# ['hostname1', 'hostname2']
run_as_admin
=
models
.
BooleanField
(
default
=
False
,
verbose_name
=
_
(
'Run as admin'
))
run_as
=
models
.
CharField
(
max_length
=
128
,
default
=
''
,
verbose_name
=
_
(
"Run as"
))
_become
=
models
.
CharField
(
max_length
=
1024
,
default
=
''
,
verbose_name
=
_
(
"Become"
))
created_by
=
models
.
CharField
(
max_length
=
64
,
default
=
''
,
verbose_name
=
_
(
'Create by'
))
created_by
=
models
.
CharField
(
max_length
=
64
,
default
=
''
,
null
=
True
,
verbose_name
=
_
(
'Create by'
))
date_created
=
models
.
DateTimeField
(
auto_now_add
=
True
)
@property
...
...
@@ -147,9 +147,10 @@ class AdHoc(models.Model):
@property
def
options
(
self
):
if
self
.
_options
:
return
json
.
loads
(
self
.
_options
)
else
:
return
{}
_options
=
json
.
loads
(
self
.
_options
)
if
isinstance
(
_options
,
dict
):
return
_options
return
{}
@options.setter
def
options
(
self
,
item
):
...
...
apps/terminal/views/session.py
View file @
2d0be8f9
...
...
@@ -124,8 +124,11 @@ class SessionDetailView(SingleObjectMixin, ListView):
model
=
Session
object
=
None
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
self
.
object
=
self
.
get_object
(
queryset
=
self
.
model
.
objects
.
all
())
return
super
()
.
get
(
request
,
*
args
,
**
kwargs
)
def
get_queryset
(
self
):
self
.
object
=
self
.
get_object
()
return
command_store
.
filter
(
session
=
self
.
object
.
id
)
def
get_context_data
(
self
,
**
kwargs
):
...
...
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