Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
Warden
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
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Pavel Valach
Warden
Commits
f82abac4
Commit
f82abac4
authored
Sep 1, 2016
by
Pavel Kácha
Browse files
Options
Downloads
Patches
Plain Diff
Server now supports arbitrary content for post and return, not only json
parent
d71101a2
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
warden3/warden_server/warden_server.py
+40
-21
40 additions, 21 deletions
warden3/warden_server/warden_server.py
with
40 additions
and
21 deletions
warden3/warden_server/warden_server.py
+
40
−
21
View file @
f82abac4
...
...
@@ -845,11 +845,6 @@ class Server(ObjectReq):
exception
=
None
try
:
try
:
injson
=
environ
[
'
wsgi.input
'
].
read
()
except
:
raise
self
.
req
.
error
(
message
=
"
Data read error.
"
,
error
=
408
,
exc
=
sys
.
exc_info
())
try
:
method
=
getattr
(
self
.
handler
,
path
)
method
.
exposed
# dummy access to trigger AttributeError
...
...
@@ -862,14 +857,6 @@ class Server(ObjectReq):
if
not
client
:
raise
self
.
req
.
error
(
message
=
"
I
'
m watching. Authenticate.
"
,
error
=
403
)
try
:
events
=
json
.
loads
(
injson
)
if
injson
else
None
except
Exception
as
e
:
raise
self
.
req
.
error
(
message
=
"
Deserialization error.
"
,
error
=
400
,
exc
=
sys
.
exc_info
(),
args
=
injson
,
parser
=
str
(
e
))
if
events
:
args
[
"
events
"
]
=
events
auth
=
self
.
auth
.
authorize
(
self
.
req
.
env
,
self
.
req
.
client
,
self
.
req
.
path
,
method
)
if
not
auth
:
raise
self
.
req
.
error
(
message
=
"
I
'
m watching. Not authorized.
"
,
error
=
403
,
client
=
client
.
name
)
...
...
@@ -880,15 +867,13 @@ class Server(ObjectReq):
args
.
pop
(
"
hostnames
"
,
None
)
args
=
self
.
sanitize_args
(
path
,
method
,
args
)
result
=
method
(
**
args
)
# call requested method
try
:
# 'default': takes care of non JSON serializable objects,
# which could (although shouldn't) appear in handler code
output
=
json
.
dumps
(
result
,
default
=
lambda
v
:
str
(
v
))
except
Exception
as
e
:
raise
self
.
req
.
error
(
message
=
"
Serialization error
"
,
error
=
500
,
exc
=
sys
.
exc_info
(),
args
=
str
(
result
))
post_data
=
environ
[
'
wsgi.input
'
].
read
()
except
:
raise
self
.
req
.
error
(
message
=
"
Data read error.
"
,
error
=
408
,
exc
=
sys
.
exc_info
())
headers
,
output
=
method
(
post_data
,
**
args
)
except
Error
as
e
:
exception
=
e
...
...
@@ -919,6 +904,33 @@ class Server(ObjectReq):
def
json_wrapper
(
method
):
def
meth_deco
(
self
,
post
,
**
args
):
if
"
events
"
in
method
.
func_code
.
co_varnames
[
0
:
method
.
func_code
.
co_argcount
]:
try
:
events
=
json
.
loads
(
post
)
if
post
else
None
except
Exception
as
e
:
raise
self
.
req
.
error
(
message
=
"
Deserialization error.
"
,
error
=
400
,
exc
=
sys
.
exc_info
(),
args
=
post
,
parser
=
str
(
e
))
if
events
:
args
[
"
events
"
]
=
events
result
=
method
(
self
,
**
args
)
# call requested method
try
:
# 'default': takes care of non JSON serializable objects,
# which could (although shouldn't) appear in handler code
output
=
json
.
dumps
(
result
,
default
=
lambda
v
:
str
(
v
))
except
Exception
as
e
:
raise
self
.
req
.
error
(
message
=
"
Serialization error
"
,
error
=
500
,
exc
=
sys
.
exc_info
(),
args
=
str
(
result
))
return
[(
'
Content-type
'
,
'
application/json
'
)],
output
return
meth_deco
class
WardenHandler
(
ObjectReq
):
def
__init__
(
self
,
req
,
validator
,
db
,
auth
,
...
...
@@ -941,6 +953,7 @@ class WardenHandler(ObjectReq):
@expose
(
read
=
1
,
debug
=
1
)
@json_wrapper
def
getDebug
(
self
):
return
{
"
environment
"
:
self
.
req
.
env
,
...
...
@@ -964,6 +977,7 @@ class WardenHandler(ObjectReq):
@expose
(
read
=
1
)
@json_wrapper
def
getInfo
(
self
):
info
=
{
"
version
"
:
VERSION
,
...
...
@@ -976,6 +990,7 @@ class WardenHandler(ObjectReq):
@expose
(
read
=
1
)
@json_wrapper
def
getEvents
(
self
,
id
=
None
,
count
=
None
,
cat
=
None
,
nocat
=
None
,
tag
=
None
,
notag
=
None
,
...
...
@@ -1041,12 +1056,16 @@ class WardenHandler(ObjectReq):
ev_ids
=
err
.
setdefault
(
"
events_id
"
,
[])
for
i
in
ilist
:
event
=
events
[
i
]
id
=
event
.
get
(
"
ID
"
,
None
)
try
:
id
=
event
[
"
ID
"
]
except
(
AttributeError
,
TypeError
,
ValueError
):
id
=
None
ev_ids
.
append
(
id
)
return
errlist
@expose
(
write
=
1
)
@json_wrapper
def
sendEvents
(
self
,
events
=
[]):
if
not
isinstance
(
events
,
list
):
raise
self
.
req
.
error
(
message
=
"
List of events expected.
"
,
error
=
400
)
...
...
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