Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
Warden - archive
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
713
Warden
Warden - archive
Commits
59ce4518
Commit
59ce4518
authored
10 years ago
by
Pavel Kácha
Browse files
Options
Downloads
Patches
Plain Diff
Diversified HTTP codes, more unified error messages, completed authentication.
parent
8e3eaed6
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
warden3/warden_server/warden_server.py
+20
-9
20 additions, 9 deletions
warden3/warden_server/warden_server.py
with
20 additions
and
9 deletions
warden3/warden_server/warden_server.py
+
20
−
9
View file @
59ce4518
...
...
@@ -200,9 +200,12 @@ class X509Authenticator(NoAuthenticator):
return
None
return
client
if
method
in
[
'
getInfo
'
,
'
getEvents
'
]:
return
client
try
:
identity
=
event
[
'
Node
'
][
0
][
'
Name
'
].
lower
()
except
KeyError
:
except
(
KeyError
,
TypeError
)
:
# Event does not bear valid Node attribute
logging
.
info
(
"
Auth failed: event does not bear valid Node attribute
"
)
return
None
...
...
@@ -365,13 +368,13 @@ class MySQL(Object):
logging
.
debug
(
"
fetch_events: id=%i, count=%i, cat=%s, nocat=%s, tag=%s, notag=%s, group=%s, nogroup=%s
"
%
(
id
,
count
,
str
(
cat
),
str
(
nocat
),
str
(
tag
),
str
(
notag
),
str
(
group
),
str
(
nogroup
)))
if
cat
and
nocat
:
raise
Error
(
"
Unrealizable conditions. Choose cat or nocat option.
"
,
500
,
method
=
'
getEvents
'
,
raise
Error
(
"
Unrealizable conditions. Choose cat or nocat option.
"
,
422
,
method
=
'
getEvents
'
,
exc
=
sys
.
exc_info
(),
detail
=
{
'
cat
'
:
cat
,
'
nocat
'
:
nocat
})
if
tag
and
notag
:
raise
Error
(
"
Unrealizable conditions. Choose tag or notag option.
"
,
500
,
method
=
'
getEvents
'
,
raise
Error
(
"
Unrealizable conditions. Choose tag or notag option.
"
,
422
,
method
=
'
getEvents
'
,
exc
=
sys
.
exc_info
(),
detail
=
{
'
tag
'
:
cat
,
'
notag
'
:
nocat
})
if
group
and
nogroup
:
raise
Error
(
"
Unrealizable conditions. Choose group or nogroup option.
"
,
500
,
method
=
'
getEvents
'
,
raise
Error
(
"
Unrealizable conditions. Choose group or nogroup option.
"
,
422
,
method
=
'
getEvents
'
,
exc
=
sys
.
exc_info
(),
detail
=
{
'
tag
'
:
cat
,
'
notag
'
:
nocat
})
sqlwhere
=
[]
...
...
@@ -604,7 +607,7 @@ class Server(Object):
try
:
injson
=
environ
[
'
wsgi.input
'
].
read
()
except
:
raise
Error
(
"
Data read error
"
,
40
0
,
method
=
path
,
exc
=
sys
.
exc_info
())
raise
Error
(
"
Data read error
"
,
40
8
,
method
=
path
,
exc
=
sys
.
exc_info
())
try
:
method
=
getattr
(
self
.
handler
,
path
)
...
...
@@ -614,7 +617,7 @@ class Server(Object):
client
=
self
.
auth
.
authenticate
(
environ
)
if
not
client
:
raise
Error
(
"
I
'
m watching
YOU
.
(
Authenticate
)
"
,
403
,
method
=
path
)
raise
Error
(
"
I
'
m watching. Authenticate
.
"
,
403
,
method
=
path
)
try
:
events
=
json
.
loads
(
injson
)
if
injson
else
None
...
...
@@ -694,7 +697,7 @@ class WardenHandler(Object):
def
getDebug
(
self
,
_env
,
_client
):
auth
=
self
.
auth
.
authorize
(
_env
,
_client
,
'
getDebug
'
,
None
,
None
)
if
not
auth
:
raise
Error
(
"
I
'
m watching
YOU
.
(
Authoriz
ation)
"
,
403
,
method
=
'
getDebug
'
,
detail
=
{
"
client
"
:
_client
})
raise
Error
(
"
I
'
m watching. Authoriz
e.
"
,
403
,
method
=
'
getDebug
'
,
detail
=
{
"
client
"
:
_client
})
return
{
"
environment
"
:
_env
,
...
...
@@ -704,6 +707,10 @@ class WardenHandler(Object):
@expose
def
getInfo
(
self
,
_env
,
_client
):
auth
=
self
.
auth
.
authorize
(
_env
,
_client
,
'
getInfo
'
,
None
,
None
)
if
not
auth
:
raise
Error
(
"
I
'
m watching. Authorize.
"
,
403
,
method
=
'
getDebug
'
,
detail
=
{
"
client
"
:
_client
})
info
=
{
"
version
"
:
VERSION
,
"
send_events_limit
"
:
self
.
send_events_limit
,
...
...
@@ -720,6 +727,10 @@ class WardenHandler(Object):
tag
=
None
,
notag
=
None
,
group
=
None
,
nogroup
=
None
):
auth
=
self
.
auth
.
authorize
(
_env
,
_client
,
'
getEvents
'
,
None
,
None
)
if
not
auth
:
raise
Error
(
"
I
'
m watching. Authorize.
"
,
403
,
method
=
'
getDebug
'
,
detail
=
{
"
client
"
:
_client
})
try
:
id
=
int
(
id
[
0
])
except
(
ValueError
,
TypeError
,
IndexError
):
...
...
@@ -760,10 +771,10 @@ class WardenHandler(Object):
@expose
def
sendEvents
(
self
,
_env
,
_client
,
events
=
[]):
if
not
isinstance
(
events
,
list
):
raise
Error
(
"
List of events expected
"
,
400
,
method
=
"
sendEvents
"
)
raise
Error
(
"
List of events expected
.
"
,
400
,
method
=
"
sendEvents
"
)
if
len
(
events
)
>
self
.
send_events_limit
:
raise
Error
(
"
Too much events in one batch
"
,
4
00
,
method
=
"
sendEvents
"
,
raise
Error
(
"
Too much events in one batch
.
"
,
4
13
,
method
=
"
sendEvents
"
,
detail
=
{
"
limit
"
:
self
.
send_events_limit
})
saved
=
0
...
...
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