Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
FoD
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
David Schmitz
FoD
Commits
c35eb1fe
Commit
c35eb1fe
authored
10 years ago
by
Stauros Kroustouris
Browse files
Options
Downloads
Patches
Plain Diff
add commit_add, commit_edit, commit_delete hooks in drf viewsets.
parent
5b0e6618
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
README.md
+4
-1
4 additions, 1 deletion
README.md
flowspec/viewsets.py
+22
-3
22 additions, 3 deletions
flowspec/viewsets.py
with
26 additions
and
4 deletions
README.md
+
4
−
1
View file @
c35eb1fe
...
...
@@ -80,9 +80,12 @@ Same with Fragmentypes in `/api/fragmenttypes/<fragmenttype_id>/`, protocols in
Since we have the urls we want to connect with the rule we want to create, we can make a POST request like the following:
curl -X POST -H 'Authorization: Token <Your users token>' -F "name=Example" -F "comments=Description" -F "source=0.0.0.0/0" -F "sourceport=https://fod.example.com/api/ports/7/" -F "destination=203.0.113.12" https://fod.example.com/api/routes/
And here is a PUT request example:
curl -X PUT -F "name=Example" -F "comments=Description" -F "source=0.0.0.0/0" -F "sourceport=https://fod.example.com/api/ports/7/" -F "destination=83.212.9.93" https://fod.example.com/api/routes/12/ -H 'Authorization: Token <Your users token>'
##Contact##
...
...
This diff is collapsed.
Click to expand it.
flowspec/viewsets.py
+
22
−
3
View file @
c35eb1fe
from
django.shortcuts
import
get_object_or_404
from
rest_framework
import
s
tatu
s
from
django.conf
import
s
etting
s
from
rest_framework
import
viewsets
from
flowspec.models
import
(
...
...
@@ -41,7 +41,27 @@ class RouteViewSet(viewsets.ModelViewSet):
return
Response
(
serializer
.
data
)
def
pre_save
(
self
,
obj
):
obj
.
applier
=
self
.
request
.
user
# DEBUG
if
settings
.
DEBUG
:
if
self
.
request
.
user
.
is_anonymous
():
from
django.contrib.auth.models
import
User
obj
.
applier
=
User
.
objects
.
all
()[
0
]
elif
self
.
request
.
user
.
is_authenticated
():
obj
.
applier
=
self
.
request
.
user
else
:
raise
Exception
(
'
User is not Authenticated
'
)
else
:
obj
.
applier
=
self
.
request
.
user
def
post_save
(
self
,
obj
,
created
):
if
created
:
obj
.
commit_add
()
else
:
if
obj
.
status
not
in
[
'
EXPIRED
'
,
'
INACTIVE
'
,
'
ADMININACTIVE
'
]:
obj
.
commit_edit
()
def
pre_delete
(
self
,
obj
):
obj
.
commit_delete
()
class
PortViewSet
(
viewsets
.
ModelViewSet
):
...
...
@@ -62,4 +82,3 @@ class FragmentTypeViewSet(viewsets.ModelViewSet):
class
MatchProtocolViewSet
(
viewsets
.
ModelViewSet
):
queryset
=
MatchProtocol
.
objects
.
all
()
serializer_class
=
MatchProtocolSerializer
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment