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
841a1ce8
Commit
841a1ce8
authored
Jul 24, 2019
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 修改api
parent
c0a15003
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
39 additions
and
27 deletions
+39
-27
system_user.py
apps/assets/api/system_user.py
+7
-5
user.py
apps/assets/models/user.py
+1
-1
api_urls.py
apps/assets/urls/api_urls.py
+1
-1
serializers.py
apps/common/serializers.py
+6
-1
settings.py
apps/jumpserver/settings.py
+6
-3
swagger.py
apps/jumpserver/swagger.py
+1
-1
adhoc.py
apps/ops/api/adhoc.py
+2
-1
adhoc.py
apps/ops/models/adhoc.py
+3
-3
api_urls.py
apps/orgs/urls/api_urls.py
+9
-9
user.py
apps/users/models/user.py
+1
-1
v1.py
apps/users/serializers/v1.py
+2
-1
No files found.
apps/assets/api/system_user.py
View file @
841a1ce8
...
@@ -16,18 +16,18 @@
...
@@ -16,18 +16,18 @@
from
django.shortcuts
import
get_object_or_404
from
django.shortcuts
import
get_object_or_404
from
rest_framework
import
generics
from
rest_framework
import
generics
from
rest_framework.response
import
Response
from
rest_framework.response
import
Response
from
rest_framework_bulk
import
BulkModelViewSet
from
rest_framework.pagination
import
LimitOffsetPagination
from
rest_framework.pagination
import
LimitOffsetPagination
from
common.utils
import
get_logger
from
common.utils
import
get_logger
from
common.permissions
import
IsOrgAdmin
,
IsOrgAdminOrAppUser
from
common.permissions
import
IsOrgAdmin
,
IsOrgAdminOrAppUser
from
common.
mixins
import
IDInCacheFilterMixin
from
common.
serializers
import
CeleryTaskSerializer
from
orgs.mixins
import
OrgBulkModelViewSet
from
orgs.mixins
import
OrgBulkModelViewSet
from
..models
import
SystemUser
,
Asset
from
..models
import
SystemUser
,
Asset
from
..
import
serializers
from
..
import
serializers
from
..tasks
import
push_system_user_to_assets_manual
,
\
from
..tasks
import
(
test_system_user_connectivity_manual
,
push_system_user_a_asset_manual
,
\
push_system_user_to_assets_manual
,
test_system_user_connectivity_manual
,
test_system_user_connectivity_a_asset
push_system_user_a_asset_manual
,
test_system_user_connectivity_a_asset
,
)
logger
=
get_logger
(
__file__
)
logger
=
get_logger
(
__file__
)
...
@@ -92,6 +92,7 @@ class SystemUserPushApi(generics.RetrieveAPIView):
...
@@ -92,6 +92,7 @@ class SystemUserPushApi(generics.RetrieveAPIView):
"""
"""
queryset
=
SystemUser
.
objects
.
all
()
queryset
=
SystemUser
.
objects
.
all
()
permission_classes
=
(
IsOrgAdmin
,)
permission_classes
=
(
IsOrgAdmin
,)
serializer_class
=
CeleryTaskSerializer
def
retrieve
(
self
,
request
,
*
args
,
**
kwargs
):
def
retrieve
(
self
,
request
,
*
args
,
**
kwargs
):
system_user
=
self
.
get_object
()
system_user
=
self
.
get_object
()
...
@@ -108,6 +109,7 @@ class SystemUserTestConnectiveApi(generics.RetrieveAPIView):
...
@@ -108,6 +109,7 @@ class SystemUserTestConnectiveApi(generics.RetrieveAPIView):
"""
"""
queryset
=
SystemUser
.
objects
.
all
()
queryset
=
SystemUser
.
objects
.
all
()
permission_classes
=
(
IsOrgAdmin
,)
permission_classes
=
(
IsOrgAdmin
,)
serializer_class
=
CeleryTaskSerializer
def
retrieve
(
self
,
request
,
*
args
,
**
kwargs
):
def
retrieve
(
self
,
request
,
*
args
,
**
kwargs
):
system_user
=
self
.
get_object
()
system_user
=
self
.
get_object
()
...
...
apps/assets/models/user.py
View file @
841a1ce8
...
@@ -28,7 +28,7 @@ class AdminUser(AssetUser):
...
@@ -28,7 +28,7 @@ class AdminUser(AssetUser):
become
=
models
.
BooleanField
(
default
=
True
)
become
=
models
.
BooleanField
(
default
=
True
)
become_method
=
models
.
CharField
(
choices
=
BECOME_METHOD_CHOICES
,
default
=
'sudo'
,
max_length
=
4
)
become_method
=
models
.
CharField
(
choices
=
BECOME_METHOD_CHOICES
,
default
=
'sudo'
,
max_length
=
4
)
become_user
=
models
.
CharField
(
default
=
'root'
,
max_length
=
64
)
become_user
=
models
.
CharField
(
default
=
'root'
,
max_length
=
64
)
_become_pass
=
models
.
CharField
(
default
=
''
,
max_length
=
128
)
_become_pass
=
models
.
CharField
(
default
=
''
,
blank
=
True
,
max_length
=
128
)
CONNECTIVITY_CACHE_KEY
=
'_ADMIN_USER_CONNECTIVE_{}'
CONNECTIVITY_CACHE_KEY
=
'_ADMIN_USER_CONNECTIVE_{}'
_prefer
=
"admin_user"
_prefer
=
"admin_user"
...
...
apps/assets/urls/api_urls.py
View file @
841a1ce8
...
@@ -20,7 +20,7 @@ router.register(r'domains', api.DomainViewSet, 'domain')
...
@@ -20,7 +20,7 @@ router.register(r'domains', api.DomainViewSet, 'domain')
router
.
register
(
r'gateways'
,
api
.
GatewayViewSet
,
'gateway'
)
router
.
register
(
r'gateways'
,
api
.
GatewayViewSet
,
'gateway'
)
router
.
register
(
r'cmd-filters'
,
api
.
CommandFilterViewSet
,
'cmd-filter'
)
router
.
register
(
r'cmd-filters'
,
api
.
CommandFilterViewSet
,
'cmd-filter'
)
router
.
register
(
r'asset-users'
,
api
.
AssetUserViewSet
,
'asset-user'
)
router
.
register
(
r'asset-users'
,
api
.
AssetUserViewSet
,
'asset-user'
)
router
.
register
(
r'asset-user-info'
,
api
.
AssetUserExportViewSet
,
'asset-user-info'
)
router
.
register
(
r'asset-user
s
-info'
,
api
.
AssetUserExportViewSet
,
'asset-user-info'
)
cmd_filter_router
=
routers
.
NestedDefaultRouter
(
router
,
r'cmd-filters'
,
lookup
=
'filter'
)
cmd_filter_router
=
routers
.
NestedDefaultRouter
(
router
,
r'cmd-filters'
,
lookup
=
'filter'
)
cmd_filter_router
.
register
(
r'rules'
,
api
.
CommandFilterRuleViewSet
,
'cmd-filter-rule'
)
cmd_filter_router
.
register
(
r'rules'
,
api
.
CommandFilterRuleViewSet
,
'cmd-filter-rule'
)
...
...
apps/common/serializers.py
View file @
841a1ce8
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
#
#
from
.mixins
import
BulkListSerializerMixin
from
rest_framework_bulk.serializers
import
BulkListSerializer
from
rest_framework_bulk.serializers
import
BulkListSerializer
from
rest_framework
import
serializers
from
.mixins
import
BulkListSerializerMixin
class
AdaptedBulkListSerializer
(
BulkListSerializerMixin
,
BulkListSerializer
):
class
AdaptedBulkListSerializer
(
BulkListSerializerMixin
,
BulkListSerializer
):
pass
pass
class
CeleryTaskSerializer
(
serializers
.
Serializer
):
task
=
serializers
.
CharField
(
read_only
=
True
)
apps/jumpserver/settings.py
View file @
841a1ce8
...
@@ -384,7 +384,7 @@ REST_FRAMEWORK = {
...
@@ -384,7 +384,7 @@ REST_FRAMEWORK = {
'rest_framework.parsers.FileUploadParser'
,
'rest_framework.parsers.FileUploadParser'
,
),
),
'DEFAULT_AUTHENTICATION_CLASSES'
:
(
'DEFAULT_AUTHENTICATION_CLASSES'
:
(
#
'rest_framework.authentication.BasicAuthentication',
'rest_framework.authentication.BasicAuthentication'
,
'authentication.backends.api.AccessKeyAuthentication'
,
'authentication.backends.api.AccessKeyAuthentication'
,
'authentication.backends.api.AccessTokenAuthentication'
,
'authentication.backends.api.AccessTokenAuthentication'
,
'authentication.backends.api.PrivateTokenAuthentication'
,
'authentication.backends.api.PrivateTokenAuthentication'
,
...
@@ -598,9 +598,12 @@ USER_GUIDE_URL = ""
...
@@ -598,9 +598,12 @@ USER_GUIDE_URL = ""
SWAGGER_SETTINGS
=
{
SWAGGER_SETTINGS
=
{
'DEFAULT_AUTO_SCHEMA_CLASS'
:
'jumpserver.swagger.CustomSwaggerAutoSchema'
,
'DEFAULT_AUTO_SCHEMA_CLASS'
:
'jumpserver.swagger.CustomSwaggerAutoSchema'
,
'USE_SESSION_AUTH'
:
True
,
'SECURITY_DEFINITIONS'
:
{
'SECURITY_DEFINITIONS'
:
{
'basic'
:
{
'Bearer'
:
{
'type'
:
'basic'
'type'
:
'apiKey'
,
'name'
:
'Authorization'
,
'in'
:
'header'
}
}
},
},
}
}
...
...
apps/jumpserver/swagger.py
View file @
841a1ce8
...
@@ -8,7 +8,7 @@ from drf_yasg import openapi
...
@@ -8,7 +8,7 @@ from drf_yasg import openapi
class
CustomSwaggerAutoSchema
(
SwaggerAutoSchema
):
class
CustomSwaggerAutoSchema
(
SwaggerAutoSchema
):
def
get_tags
(
self
,
operation_keys
):
def
get_tags
(
self
,
operation_keys
):
if
len
(
operation_keys
)
>
2
and
operation_keys
[
1
]
.
startswith
(
'v'
):
if
len
(
operation_keys
)
>
2
and
operation_keys
[
1
]
.
startswith
(
'v'
):
return
[
operation_keys
[
2
]]
return
[
operation_keys
[
0
]
+
'_'
+
operation_keys
[
2
]]
return
super
()
.
get_tags
(
operation_keys
)
return
super
()
.
get_tags
(
operation_keys
)
...
...
apps/ops/api/adhoc.py
View file @
841a1ce8
...
@@ -6,6 +6,7 @@ from rest_framework import viewsets, generics
...
@@ -6,6 +6,7 @@ from rest_framework import viewsets, generics
from
rest_framework.views
import
Response
from
rest_framework.views
import
Response
from
common.permissions
import
IsOrgAdmin
from
common.permissions
import
IsOrgAdmin
from
common.serializers
import
CeleryTaskSerializer
from
orgs.utils
import
current_org
from
orgs.utils
import
current_org
from
..models
import
Task
,
AdHoc
,
AdHocRunHistory
from
..models
import
Task
,
AdHoc
,
AdHocRunHistory
from
..serializers
import
TaskSerializer
,
AdHocSerializer
,
\
from
..serializers
import
TaskSerializer
,
AdHocSerializer
,
\
...
@@ -33,7 +34,7 @@ class TaskViewSet(viewsets.ModelViewSet):
...
@@ -33,7 +34,7 @@ class TaskViewSet(viewsets.ModelViewSet):
class
TaskRun
(
generics
.
RetrieveAPIView
):
class
TaskRun
(
generics
.
RetrieveAPIView
):
queryset
=
Task
.
objects
.
all
()
queryset
=
Task
.
objects
.
all
()
# serializer_class = TaskViewSet
serializer_class
=
CeleryTaskSerializer
permission_classes
=
(
IsOrgAdmin
,)
permission_classes
=
(
IsOrgAdmin
,)
def
retrieve
(
self
,
request
,
*
args
,
**
kwargs
):
def
retrieve
(
self
,
request
,
*
args
,
**
kwargs
):
...
...
apps/ops/models/adhoc.py
View file @
841a1ce8
...
@@ -161,9 +161,9 @@ class AdHoc(models.Model):
...
@@ -161,9 +161,9 @@ class AdHoc(models.Model):
_hosts
=
models
.
TextField
(
blank
=
True
,
verbose_name
=
_
(
'Hosts'
))
# ['hostname1', 'hostname2']
_hosts
=
models
.
TextField
(
blank
=
True
,
verbose_name
=
_
(
'Hosts'
))
# ['hostname1', 'hostname2']
hosts
=
models
.
ManyToManyField
(
'assets.Asset'
,
verbose_name
=
_
(
"Host"
))
hosts
=
models
.
ManyToManyField
(
'assets.Asset'
,
verbose_name
=
_
(
"Host"
))
run_as_admin
=
models
.
BooleanField
(
default
=
False
,
verbose_name
=
_
(
'Run as admin'
))
run_as_admin
=
models
.
BooleanField
(
default
=
False
,
verbose_name
=
_
(
'Run as admin'
))
run_as
=
models
.
CharField
(
max_length
=
64
,
default
=
''
,
null
=
True
,
verbose_name
=
_
(
'Username'
))
run_as
=
models
.
CharField
(
max_length
=
64
,
default
=
''
,
blank
=
True
,
null
=
True
,
verbose_name
=
_
(
'Username'
))
_become
=
models
.
CharField
(
max_length
=
1024
,
default
=
''
,
verbose_name
=
_
(
"Become"
))
_become
=
models
.
CharField
(
max_length
=
1024
,
default
=
''
,
blank
=
True
,
verbose_name
=
_
(
"Become"
))
created_by
=
models
.
CharField
(
max_length
=
64
,
default
=
''
,
null
=
True
,
verbose_name
=
_
(
'Create by'
))
created_by
=
models
.
CharField
(
max_length
=
64
,
default
=
''
,
blank
=
True
,
null
=
True
,
verbose_name
=
_
(
'Create by'
))
date_created
=
models
.
DateTimeField
(
auto_now_add
=
True
,
db_index
=
True
)
date_created
=
models
.
DateTimeField
(
auto_now_add
=
True
,
db_index
=
True
)
@property
@property
...
...
apps/orgs/urls/api_urls.py
View file @
841a1ce8
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
#
#
from
django.urls
import
path
from
django.urls
import
re_
path
from
rest_framework.routers
import
DefaultRouter
from
rest_framework.routers
import
DefaultRouter
from
common
import
api
as
capi
from
..
import
api
from
..
import
api
...
@@ -10,20 +12,18 @@ app_name = 'orgs'
...
@@ -10,20 +12,18 @@ app_name = 'orgs'
router
=
DefaultRouter
()
router
=
DefaultRouter
()
# 将会删除
# 将会删除
router
.
register
(
r'org/(?P<org_id>[0-9a-zA-Z\-]{36})/membership/admins'
,
api
.
OrgMembershipAdminsViewSet
,
'membership-admins'
)
router
.
register
(
r'org/(?P<org_id>[0-9a-zA-Z\-]{36})/membership/users'
,
api
.
OrgMembershipUsersViewSet
,
'membership-users'
),
# 替换为这个
router
.
register
(
r'orgs/(?P<org_id>[0-9a-zA-Z\-]{36})/membership/admins'
,
router
.
register
(
r'orgs/(?P<org_id>[0-9a-zA-Z\-]{36})/membership/admins'
,
api
.
OrgMembershipAdminsViewSet
,
'membership-admins
-2
'
)
api
.
OrgMembershipAdminsViewSet
,
'membership-admins'
)
router
.
register
(
r'orgs/(?P<org_id>[0-9a-zA-Z\-]{36})/membership/users'
,
router
.
register
(
r'orgs/(?P<org_id>[0-9a-zA-Z\-]{36})/membership/users'
,
api
.
OrgMembershipUsersViewSet
,
'membership-users
-2
'
),
api
.
OrgMembershipUsersViewSet
,
'membership-users'
),
router
.
register
(
r'orgs'
,
api
.
OrgViewSet
,
'org'
)
router
.
register
(
r'orgs'
,
api
.
OrgViewSet
,
'org'
)
old_version_urlpatterns
=
[
re_path
(
'(?P<resource>org)/.*'
,
capi
.
redirect_plural_name_api
)
]
urlpatterns
=
[
urlpatterns
=
[
]
]
urlpatterns
+=
router
.
urls
urlpatterns
+=
router
.
urls
+
old_version_urlpatterns
apps/users/models/user.py
View file @
841a1ce8
...
@@ -362,7 +362,7 @@ class User(AuthMixin, TokenMixin, RoleMixin, MFAMixin, AbstractUser):
...
@@ -362,7 +362,7 @@ class User(AuthMixin, TokenMixin, RoleMixin, MFAMixin, AbstractUser):
db_index
=
True
,
verbose_name
=
_
(
'Date expired'
)
db_index
=
True
,
verbose_name
=
_
(
'Date expired'
)
)
)
created_by
=
models
.
CharField
(
created_by
=
models
.
CharField
(
max_length
=
30
,
default
=
''
,
verbose_name
=
_
(
'Created by'
)
max_length
=
30
,
default
=
''
,
blank
=
True
,
verbose_name
=
_
(
'Created by'
)
)
)
source
=
models
.
CharField
(
source
=
models
.
CharField
(
max_length
=
30
,
default
=
SOURCE_LOCAL
,
choices
=
SOURCE_CHOICES
,
max_length
=
30
,
default
=
SOURCE_LOCAL
,
choices
=
SOURCE_CHOICES
,
...
...
apps/users/serializers/v1.py
View file @
841a1ce8
...
@@ -45,7 +45,8 @@ class UserSerializer(BulkSerializerMixin, serializers.ModelSerializer):
...
@@ -45,7 +45,8 @@ class UserSerializer(BulkSerializerMixin, serializers.ModelSerializer):
'is_valid'
:
{
'label'
:
_
(
'Is valid'
)},
'is_valid'
:
{
'label'
:
_
(
'Is valid'
)},
'is_expired'
:
{
'label'
:
_
(
'Is expired'
)},
'is_expired'
:
{
'label'
:
_
(
'Is expired'
)},
'avatar_url'
:
{
'label'
:
_
(
'Avatar url'
)},
'avatar_url'
:
{
'label'
:
_
(
'Avatar url'
)},
'created_by'
:
{
'read_only'
:
True
},
'source'
:
{
'read_only'
:
True
}
'created_by'
:
{
'read_only'
:
True
,
'allow_blank'
:
True
},
'source'
:
{
'read_only'
:
True
},
}
}
def
validate_role
(
self
,
value
):
def
validate_role
(
self
,
value
):
...
...
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