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
01185a2d
Commit
01185a2d
authored
Jul 10, 2018
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 添加gateway api
parent
8bfd2be2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
1 deletion
+24
-1
asset.py
apps/assets/api/asset.py
+22
-1
api_urls.py
apps/assets/urls/api_urls.py
+2
-0
No files found.
apps/assets/api/asset.py
View file @
01185a2d
# -*- coding: utf-8 -*-
#
import
random
from
rest_framework
import
generics
from
rest_framework.response
import
Response
from
rest_framework_bulk
import
BulkModelViewSet
...
...
@@ -22,7 +24,8 @@ from ..utils import LabelFilter
logger
=
get_logger
(
__file__
)
__all__
=
[
'AssetViewSet'
,
'AssetListUpdateApi'
,
'AssetRefreshHardwareApi'
,
'AssetAdminUserTestApi'
'AssetRefreshHardwareApi'
,
'AssetAdminUserTestApi'
,
'AssetGatewayApi'
]
...
...
@@ -106,3 +109,20 @@ class AssetAdminUserTestApi(generics.RetrieveAPIView):
asset
=
get_object_or_404
(
Asset
,
pk
=
asset_id
)
task
=
test_asset_connectability_manual
.
delay
(
asset
)
return
Response
({
"task"
:
task
.
id
})
class
AssetGatewayApi
(
generics
.
RetrieveAPIView
):
queryset
=
Asset
.
objects
.
all
()
permission_classes
=
(
IsSuperUserOrAppUser
,)
def
retrieve
(
self
,
request
,
*
args
,
**
kwargs
):
asset_id
=
kwargs
.
get
(
'pk'
)
asset
=
get_object_or_404
(
Asset
,
pk
=
asset_id
)
if
asset
.
domain
and
\
asset
.
domain
.
gateways
.
filter
(
protocol
=
asset
.
protocol
)
.
exists
():
gateway
=
random
.
choice
(
asset
.
domain
.
gateways
.
filter
(
protocol
=
asset
.
protocol
))
serializer
=
serializers
.
GatewayWithAuthSerializer
(
instance
=
gateway
)
return
Response
(
serializer
.
data
)
else
:
return
Response
({
"msg"
:
"Not have gateway"
},
status
=
404
)
\ No newline at end of file
apps/assets/urls/api_urls.py
View file @
01185a2d
...
...
@@ -23,6 +23,8 @@ urlpatterns = [
api
.
AssetRefreshHardwareApi
.
as_view
(),
name
=
'asset-refresh'
),
url
(
r'^v1/assets/(?P<pk>[0-9a-zA-Z\-]{36})/alive/$'
,
api
.
AssetAdminUserTestApi
.
as_view
(),
name
=
'asset-alive-test'
),
url
(
r'^v1/assets/(?P<pk>[0-9a-zA-Z\-]{36})/gateway/$'
,
api
.
AssetGatewayApi
.
as_view
(),
name
=
'asset-gateway'
),
url
(
r'^v1/admin-user/(?P<pk>[0-9a-zA-Z\-]{36})/nodes/$'
,
api
.
ReplaceNodesAdminUserApi
.
as_view
(),
name
=
'replace-nodes-admin-user'
),
url
(
r'^v1/admin-user/(?P<pk>[0-9a-zA-Z\-]{36})/auth/$'
,
...
...
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