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
c99a2b7f
Commit
c99a2b7f
authored
Aug 02, 2019
by
BaiJiangJie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Feature] 应用管理: Database 添加Model、APIView
parent
ebd92547
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
117 additions
and
1 deletion
+117
-1
__init__.py
apps/applications/api/__init__.py
+1
-0
database.py
apps/applications/api/database.py
+20
-0
__init__.py
apps/applications/models/__init__.py
+1
-0
database.py
apps/applications/models/database.py
+67
-0
__init__.py
apps/applications/serializers/__init__.py
+1
-0
database.py
apps/applications/serializers/database.py
+25
-0
api_urls.py
apps/applications/urls/api_urls.py
+2
-1
No files found.
apps/applications/api/__init__.py
View file @
c99a2b7f
from
.remote_app
import
*
from
.database
import
*
apps/applications/api/database.py
0 → 100644
View file @
c99a2b7f
# coding: utf-8
#
from
rest_framework.pagination
import
LimitOffsetPagination
from
rest_framework_bulk
import
BulkModelViewSet
from
..hands
import
IsOrgAdmin
from
..models
import
Database
from
..serializers
import
DatabaseSerializer
__all__
=
[
'DataBaseViewSet'
]
class
DataBaseViewSet
(
BulkModelViewSet
):
filter_fields
=
(
'name'
,)
search_fields
=
filter_fields
permission_classes
=
(
IsOrgAdmin
,)
queryset
=
Database
.
objects
.
all
()
serializer_class
=
DatabaseSerializer
pagination_class
=
LimitOffsetPagination
apps/applications/models/__init__.py
View file @
c99a2b7f
from
.remote_app
import
*
from
.database
import
*
apps/applications/models/database.py
0 → 100644
View file @
c99a2b7f
# coding: utf-8
#
import
uuid
from
django.db
import
models
from
django.utils.translation
import
ugettext_lazy
as
_
from
orgs.mixins
import
OrgModelMixin
from
common.validators
import
alphanumeric
from
common
import
fields
__all__
=
[
'Database'
]
class
Database
(
OrgModelMixin
):
LOGIN_AUTO
=
'auto'
LOGIN_MANUAL
=
'manual'
LOGIN_MODE_CHOICES
=
(
(
LOGIN_AUTO
,
_
(
'Automatic login'
)),
(
LOGIN_MANUAL
,
_
(
'Manually login'
))
)
TYPE_MYSQL
=
'mysql'
TYPE_CHOICES
=
(
(
TYPE_MYSQL
,
_
(
'MySQL'
)),
)
id
=
models
.
UUIDField
(
default
=
uuid
.
uuid4
,
primary_key
=
True
)
name
=
models
.
CharField
(
max_length
=
128
,
verbose_name
=
_
(
'Name'
))
login_mode
=
models
.
CharField
(
choices
=
LOGIN_MODE_CHOICES
,
default
=
LOGIN_AUTO
,
max_length
=
10
,
verbose_name
=
_
(
'Login mode'
)
)
type
=
models
.
CharField
(
choices
=
TYPE_CHOICES
,
default
=
TYPE_MYSQL
,
max_length
=
10
,
verbose_name
=
_
(
'Type'
)
)
host
=
models
.
CharField
(
max_length
=
128
,
verbose_name
=
_
(
'Host'
))
port
=
models
.
IntegerField
(
default
=
3306
,
verbose_name
=
_
(
'Port'
))
user
=
models
.
CharField
(
max_length
=
32
,
blank
=
True
,
null
=
True
,
validators
=
[
alphanumeric
],
verbose_name
=
_
(
'User'
)
)
password
=
fields
.
EncryptCharField
(
max_length
=
256
,
blank
=
True
,
null
=
True
,
verbose_name
=
_
(
'Password'
)
)
database
=
models
.
CharField
(
max_length
=
128
,
blank
=
True
,
null
=
True
,
verbose_name
=
_
(
'Database'
)
)
comment
=
models
.
TextField
(
blank
=
True
,
verbose_name
=
_
(
'Comment'
))
created_by
=
models
.
CharField
(
max_length
=
128
,
null
=
True
,
verbose_name
=
_
(
'Created by'
)
)
date_created
=
models
.
DateTimeField
(
auto_now_add
=
True
,
verbose_name
=
_
(
'Date Created'
)
)
date_updated
=
models
.
DateTimeField
(
auto_now
=
True
,
verbose_name
=
_
(
'Date updated'
)
)
class
Meta
:
verbose_name
=
_
(
'Database'
)
unique_together
=
[(
'org_id'
,
'name'
)]
ordering
=
(
'name'
,)
def
__str__
(
self
):
return
self
.
name
apps/applications/serializers/__init__.py
View file @
c99a2b7f
from
.remote_app
import
*
from
.database
import
*
apps/applications/serializers/database.py
0 → 100644
View file @
c99a2b7f
# coding: utf-8
#
from
common.serializers
import
AdaptedBulkListSerializer
from
orgs.mixins
import
BulkOrgResourceModelSerializer
from
..models
import
Database
__all__
=
[
'DatabaseSerializer'
]
class
DatabaseSerializer
(
BulkOrgResourceModelSerializer
):
class
Meta
:
model
=
Database
list_serializer_class
=
AdaptedBulkListSerializer
fields
=
[
'id'
,
'name'
,
'login_mode'
,
'host'
,
'port'
,
'user'
,
'password'
,
'database'
,
'comment'
,
'created_by'
,
'date_created'
,
'date_updated'
,
]
read_only_fields
=
[
'created_by'
,
'date_created'
,
'date_updated'
]
extra_kwargs
=
{
'password'
:
{
'write_only'
:
True
},
}
apps/applications/urls/api_urls.py
View file @
c99a2b7f
...
...
@@ -11,6 +11,7 @@ app_name = 'applications'
router
=
BulkRouter
()
router
.
register
(
r'remote-apps'
,
api
.
RemoteAppViewSet
,
'remote-app'
)
router
.
register
(
r'databases'
,
api
.
DataBaseViewSet
,
'database'
)
urlpatterns
=
[
path
(
'remote-apps/<uuid:pk>/connection-info/'
,
...
...
@@ -18,7 +19,7 @@ urlpatterns = [
name
=
'remote-app-connection-info'
)
]
old_version_urlpatterns
=
[
re_path
(
'(?P<resource>remote-app)/.*'
,
capi
.
redirect_plural_name_api
)
re_path
(
'(?P<resource>remote-app
|database
)/.*'
,
capi
.
redirect_plural_name_api
)
]
urlpatterns
+=
router
.
urls
+
old_version_urlpatterns
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