Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
R
red-ci-cd
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
red-group-test
red-ci-cd
Commits
61861cb9
Commit
61861cb9
authored
May 31, 2019
by
John Red Medrano
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
removed unused codes
parent
a9844ae2
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
24 additions
and
33 deletions
+24
-33
api/urls.py
api/urls.py
+1
-1
api/utils.py
api/utils.py
+0
-1
api/viewsets/applications.py
api/viewsets/applications.py
+0
-9
api/viewsets/endpoints.py
api/viewsets/endpoints.py
+14
-12
api/viewsets/services.py
api/viewsets/services.py
+9
-10
No files found.
api/urls.py
View file @
61861cb9
...
...
@@ -10,7 +10,7 @@ from api.views import (
router
=
DefaultRouter
()
router
.
register
(
r'applications'
,
ApplicationViewSet
)
router
.
register
(
r'services'
,
APIServiceViewSet
)
router
.
register
(
r'endpoint'
,
APIEndpointViewSet
)
router
.
register
(
r'endpoint
s
'
,
APIEndpointViewSet
)
router
.
register
(
r'main-application'
,
MainApplicationViewSet
)
urlpatterns
=
[
...
...
api/utils.py
View file @
61861cb9
...
...
@@ -9,7 +9,6 @@ from .models import APIEndpoint
from
rest_framework.pagination
import
PageNumberPagination
from
rest_framework.response
import
Response
import
datetime
from
functools
import
wraps
VALIDATE_TOKEN_URL
=
settings
.
VALIDATE_TOKEN_URL
...
...
api/viewsets/applications.py
View file @
61861cb9
...
...
@@ -246,12 +246,3 @@ class ApplicationViewSet(viewsets.ModelViewSet):
class
MainApplicationViewSet
(
viewsets
.
ModelViewSet
):
queryset
=
Application
.
objects
.
all
()
serializer_class
=
GroupDependentSerializer
# def get_queryset(self):
# groups = self.request.query_params.get(
# 'groups', None
# )
# groups = groups.split(',')
# # print()
# app = Application.objects.filter(id__in=groups)
# return app
api/viewsets/endpoints.py
View file @
61861cb9
...
...
@@ -3,7 +3,10 @@ from rest_framework.decorators import action
from
rest_framework.response
import
Response
from
api.models
import
APIEndpoint
from
api.serializers
import
APIEndpointSerializer
from
api.utils
import
(
APIEndpointFilter
,
CustomPagination
,
BadRequestException
,
status_message_response
)
from
api.utils
import
(
APIEndpointFilter
,
CustomPagination
,
BadRequestException
,
status_message_response
)
from
django_filters.rest_framework
import
DjangoFilterBackend
...
...
@@ -24,11 +27,10 @@ class APIEndpointViewSet(viewsets.ModelViewSet):
serializer
=
self
.
get_serializer
(
data
=
request
.
data
)
serializer
.
is_valid
(
raise_exception
=
True
)
self
.
perform_create
(
serializer
)
headers
=
self
.
get_success_headers
(
serializer
.
data
)
message
=
status_message_response
(
201
,
'success'
,
'New endpoint created'
,
serializer
.
data
)
return
Response
(
message
)
except
BadRequestException
as
e
:
message
=
status_message_response
(
400
,
'failed'
,
str
(
e
),
[])
return
Response
(
message
,
status
=
status
.
HTTP_400_BAD_REQUEST
)
...
...
@@ -45,7 +47,7 @@ class APIEndpointViewSet(viewsets.ModelViewSet):
if
not
queryset
.
exists
():
message
=
status_message_response
(
200
,
'success'
,
'No records found'
,
[])
return
Response
(
message
)
page
=
self
.
paginate_queryset
(
queryset
)
if
page
is
not
None
:
serializer
=
self
.
get_serializer
(
page
,
many
=
True
)
...
...
@@ -67,14 +69,14 @@ class APIEndpointViewSet(viewsets.ModelViewSet):
id
=
self
.
kwargs
[
'pk'
]
queryset
=
APIEndpoint
.
objects
.
filter
(
id
=
id
)
serializer
=
self
.
get_serializer
(
queryset
,
many
=
True
)
if
not
queryset
.
exists
():
message
=
status_message_response
(
404
,
'failed'
,
'No record found'
,
[])
return
Response
(
message
,
status
=
status
.
HTTP_404_NOT_FOUND
)
else
:
message
=
status_message_response
(
200
,
'success'
,
'Endpoint retrieved'
,
serializer
.
data
)
return
Response
(
message
,
status
=
status
.
HTTP_200_OK
)
except
Exception
as
e
:
message
=
status_message_response
(
500
,
'failed'
,
'Request was not able to process'
+
str
(
e
),
[])
return
Response
(
message
,
status
=
status
.
HTTP_500_INTERNAL_SERVER_ERROR
)
...
...
@@ -89,10 +91,10 @@ class APIEndpointViewSet(viewsets.ModelViewSet):
self
.
perform_update
(
serializer
)
if
getattr
(
instance
,
'_prefetched_objects_cache'
,
None
):
instance
.
_prefetched_objects_cache
=
{}
message
=
status_message_response
(
200
,
'success'
,
'Endpoint updated'
,
serializer
.
data
)
return
Response
(
message
)
except
Exception
as
e
:
message
=
status_message_response
(
500
,
'failed'
,
'Request was not able to process'
+
str
(
e
),
[])
return
Response
(
message
,
status
=
status
.
HTTP_500_INTERNAL_SERVER_ERROR
)
...
...
@@ -102,13 +104,13 @@ class APIEndpointViewSet(viewsets.ModelViewSet):
try
:
instance
=
self
.
get_object
()
self
.
perform_destroy
(
instance
)
message
=
status_message_response
(
200
,
'success'
,
'Endpoint deleted'
,
[])
return
Response
(
message
,
status
=
status
.
HTTP_200_OK
)
except
Exception
as
e
:
message
=
status_message_response
(
500
,
'failed'
,
'Request was not able to process'
+
str
(
e
),
[])
return
Response
(
message
,
status
=
status
.
HTTP_500_INTERNAL_SERVER_ERROR
)
return
Response
(
message
,
status
=
status
.
HTTP_500_INTERNAL_SERVER_ERROR
)
# PATCH - RESTORE archived endpoint
...
...
@@ -125,14 +127,14 @@ class APIEndpointViewSet(viewsets.ModelViewSet):
except
Exception
as
e
:
message
=
status_message_response
(
500
,
'failed'
,
'Request was not able to process'
+
str
(
e
),
[])
return
Response
(
message
,
status
=
status
.
HTTP_500_INTERNAL_SERVER_ERROR
)
# /archived - show list of archived endpoints
@
action
(
methods
=
[
"GET"
],
detail
=
False
)
def
archived
(
self
,
request
,
pk
=
None
):
try
:
queryset
=
APIEndpoint
.
objects
.
filter
(
deleted_at__isnull
=
False
)
if
not
queryset
.
exists
():
message
=
status_message_response
(
200
,
'success'
,
'No archived endpoints'
,
[])
return
Response
(
message
)
...
...
api/viewsets/services.py
View file @
61861cb9
...
...
@@ -21,11 +21,10 @@ class APIServiceViewSet(viewsets.ModelViewSet):
serializer
=
self
.
get_serializer
(
data
=
request
.
data
)
serializer
.
is_valid
(
raise_exception
=
True
)
self
.
perform_create
(
serializer
)
headers
=
self
.
get_success_headers
(
serializer
.
data
)
message
=
status_message_response
(
201
,
'success'
,
'New service created'
,
serializer
.
data
)
return
Response
(
message
)
except
BadRequestException
as
e
:
message
=
status_message_response
(
400
,
'failed'
,
str
(
e
),
[])
return
Response
(
message
,
status
=
status
.
HTTP_400_BAD_REQUEST
)
...
...
@@ -42,7 +41,7 @@ class APIServiceViewSet(viewsets.ModelViewSet):
if
not
queryset
.
exists
():
message
=
status_message_response
(
200
,
'success'
,
'No records found'
,
[])
return
Response
(
message
)
page
=
self
.
paginate_queryset
(
queryset
)
if
page
is
not
None
:
serializer
=
self
.
get_serializer
(
page
,
many
=
True
)
...
...
@@ -71,7 +70,7 @@ class APIServiceViewSet(viewsets.ModelViewSet):
else
:
message
=
status_message_response
(
200
,
'success'
,
'Service retrieved'
,
serializer
.
data
)
return
Response
(
message
,
status
=
status
.
HTTP_200_OK
)
except
Exception
as
e
:
message
=
status_message_response
(
500
,
'failed'
,
'Request was not able to process'
+
str
(
e
),
[])
return
Response
(
message
,
status
=
status
.
HTTP_500_INTERNAL_SERVER_ERROR
)
...
...
@@ -86,10 +85,10 @@ class APIServiceViewSet(viewsets.ModelViewSet):
self
.
perform_update
(
serializer
)
if
getattr
(
instance
,
'_prefetched_objects_cache'
,
None
):
instance
.
_prefetched_objects_cache
=
{}
message
=
status_message_response
(
200
,
'success'
,
'Service updated'
,
serializer
.
data
)
return
Response
(
message
)
except
Exception
as
e
:
message
=
status_message_response
(
500
,
'failed'
,
'Request was not able to process'
+
str
(
e
),
[])
return
Response
(
message
,
status
=
status
.
HTTP_500_INTERNAL_SERVER_ERROR
)
...
...
@@ -105,7 +104,7 @@ class APIServiceViewSet(viewsets.ModelViewSet):
except
Exception
as
e
:
message
=
status_message_response
(
500
,
'failed'
,
'Request was not able to process'
+
str
(
e
),
[])
return
Response
(
message
,
status
=
status
.
HTTP_500_INTERNAL_SERVER_ERROR
)
return
Response
(
message
,
status
=
status
.
HTTP_500_INTERNAL_SERVER_ERROR
)
# PATCH - RESTORE archived service
...
...
@@ -122,14 +121,14 @@ class APIServiceViewSet(viewsets.ModelViewSet):
except
Exception
as
e
:
message
=
status_message_response
(
500
,
'failed'
,
'Request was not able to process'
+
str
(
e
),
[])
return
Response
(
message
,
status
=
status
.
HTTP_500_INTERNAL_SERVER_ERROR
)
# /archived - show list of archived services
@
action
(
methods
=
[
"GET"
],
detail
=
False
)
def
archived
(
self
,
request
,
pk
=
None
):
try
:
queryset
=
APIService
.
objects
.
filter
(
deleted_at__isnull
=
False
)
if
not
queryset
.
exists
():
message
=
status_message_response
(
200
,
'success'
,
'No archived services'
,
[])
return
Response
(
message
)
...
...
@@ -154,7 +153,7 @@ class APIServiceViewSet(viewsets.ModelViewSet):
def
endpoints
(
self
,
request
,
pk
):
try
:
endpoints
=
APIEndpoint
.
objects
.
filter
(
service
=
pk
)
page
=
self
.
paginate_queryset
(
endpoints
)
if
page
is
not
None
:
serializer
=
APIEndpointSerializer
(
page
,
many
=
True
)
...
...
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