Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
caucase
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jérome Perrin
caucase
Commits
87ebda84
Commit
87ebda84
authored
Oct 18, 2017
by
Vincent Pelletier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wsgi: Rework request routing.
Prepares for CORS headers auto-generation.
parent
b95aa3ea
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
160 additions
and
132 deletions
+160
-132
caucase/wsgi.py
caucase/wsgi.py
+160
-132
No files found.
caucase/wsgi.py
View file @
87ebda84
...
@@ -98,6 +98,24 @@ class Application(object):
...
@@ -98,6 +98,24 @@ class Application(object):
"""
"""
self
.
_cau
=
cau
self
.
_cau
=
cau
self
.
_cas
=
cas
self
.
_cas
=
cas
self
.
_context_dict
=
{
'cau'
:
cau
,
'cas'
:
cas
,
}
self
.
_routing_dict
=
{
'crl'
:
{
'GET'
:
self
.
getCRL
,
},
'csr'
:
{
'GET'
:
self
.
getCSR
,
'PUT'
:
self
.
putCSR
,
'DELETE'
:
self
.
deleteCSR
,
},
'crt'
:
{
'GET'
:
self
.
getCRT
,
'PUT'
:
self
.
putCRT
,
},
}
def
__call__
(
self
,
environ
,
start_response
):
def
__call__
(
self
,
environ
,
start_response
):
"""
"""
...
@@ -107,21 +125,25 @@ class Application(object):
...
@@ -107,21 +125,25 @@ class Application(object):
try
:
# Convert non-wsgi exceptions into WSGI exceptions
try
:
# Convert non-wsgi exceptions into WSGI exceptions
path_item_list
=
[
x
for
x
in
environ
[
'PATH_INFO'
].
split
(
'/'
)
if
x
]
path_item_list
=
[
x
for
x
in
environ
[
'PATH_INFO'
].
split
(
'/'
)
if
x
]
try
:
try
:
context_id
,
method_id
=
path_item_list
[:
2
]
context_id
,
base_path
=
path_item_list
[:
2
]
except
ValueError
:
except
ValueError
:
raise
NotFound
raise
NotFound
if
context_id
==
'cau'
:
context
=
self
.
_cau
elif
context_id
==
'cas'
:
context
=
self
.
_cas
else
:
raise
NotFound
if
method_id
.
startswith
(
'_'
):
raise
NotFound
try
:
try
:
method
=
getattr
(
self
,
method_id
)
context
=
self
.
_context_dict
[
context_id
]
except
AttributeError
:
method_dict
=
self
.
_routing_dict
[
base_path
]
except
KeyError
:
raise
NotFound
raise
NotFound
request_method
=
environ
[
'REQUEST_METHOD'
]
if
request_method
==
'OPTIONS'
:
status
=
STATUS_NO_CONTENT
header_list
=
[
]
result
=
[]
else
:
try
:
method
=
method_dict
[
request_method
]
except
KeyError
:
raise
BadMethod
status
,
header_list
,
result
=
method
(
context
,
environ
,
path_item_list
[
2
:])
status
,
header_list
,
result
=
method
(
context
,
environ
,
path_item_list
[
2
:])
except
ApplicationError
:
except
ApplicationError
:
raise
raise
...
@@ -208,14 +230,12 @@ class Application(object):
...
@@ -208,14 +230,12 @@ class Application(object):
raise
BadRequest
(
'Invalid json'
)
raise
BadRequest
(
'Invalid json'
)
@
staticmethod
@
staticmethod
def
crl
(
context
,
environ
,
subpath
):
def
getCRL
(
context
,
environ
,
subpath
):
"""
"""
Handle
/{context}/crl urls
.
Handle
GET /{context}/crl
.
"""
"""
if
subpath
:
if
subpath
:
raise
NotFound
raise
NotFound
if
environ
[
'REQUEST_METHOD'
]
!=
'GET'
:
raise
BadMethod
data
=
context
.
getCertificateRevocationList
()
data
=
context
.
getCertificateRevocationList
()
return
(
return
(
STATUS_OK
,
STATUS_OK
,
...
@@ -226,12 +246,10 @@ class Application(object):
...
@@ -226,12 +246,10 @@ class Application(object):
[
data
],
[
data
],
)
)
def
csr
(
self
,
context
,
environ
,
subpath
):
def
getCSR
(
self
,
context
,
environ
,
subpath
):
"""
"""
Handle
/{context}/csr urls
.
Handle
GET /{context}/csr/{csr_id} and GET /{context}/csr
.
"""
"""
http_method
=
environ
[
'REQUEST_METHOD'
]
if
http_method
==
'GET'
:
if
subpath
:
if
subpath
:
try
:
try
:
csr_id
,
=
subpath
csr_id
,
=
subpath
...
@@ -255,7 +273,11 @@ class Application(object):
...
@@ -255,7 +273,11 @@ class Application(object):
],
],
[
data
],
[
data
],
)
)
elif
http_method
==
'PUT'
:
def
putCSR
(
self
,
context
,
environ
,
subpath
):
"""
Handle PUT /{context}/csr .
"""
if
subpath
:
if
subpath
:
raise
NotFound
raise
NotFound
csr_id
=
context
.
appendCertificateSigningRequest
(
self
.
_read
(
environ
))
csr_id
=
context
.
appendCertificateSigningRequest
(
self
.
_read
(
environ
))
...
@@ -266,7 +288,11 @@ class Application(object):
...
@@ -266,7 +288,11 @@ class Application(object):
],
],
[],
[],
)
)
elif
http_method
==
'DELETE'
:
def
deleteCSR
(
self
,
context
,
environ
,
subpath
):
"""
Handle DELETE /{context}/csr/{csr_id} .
"""
try
:
try
:
csr_id
,
=
subpath
csr_id
,
=
subpath
except
ValueError
:
except
ValueError
:
...
@@ -277,19 +303,15 @@ class Application(object):
...
@@ -277,19 +303,15 @@ class Application(object):
except
exceptions
.
NotFound
:
except
exceptions
.
NotFound
:
raise
NotFound
raise
NotFound
return
(
STATUS_NO_CONTENT
,
[],
[])
return
(
STATUS_NO_CONTENT
,
[],
[])
else
:
raise
BadMethod
def
crt
(
self
,
context
,
environ
,
subpath
):
def
getCRT
(
self
,
context
,
environ
,
subpath
):
"""
"""
Handle
/{context}/crt
urls.
Handle
GET /{context}/crt/{crt_id}
urls.
"""
"""
http_method
=
environ
[
'REQUEST_METHOD'
]
try
:
try
:
crt_id
,
=
subpath
crt_id
,
=
subpath
except
ValueError
:
except
ValueError
:
raise
NotFound
raise
NotFound
if
http_method
==
'GET'
:
if
crt_id
==
'ca.crt.pem'
:
if
crt_id
==
'ca.crt.pem'
:
data
=
context
.
getCACertificate
()
data
=
context
.
getCACertificate
()
content_type
=
'application/pkix-cert'
content_type
=
'application/pkix-cert'
...
@@ -311,7 +333,15 @@ class Application(object):
...
@@ -311,7 +333,15 @@ class Application(object):
],
],
[
data
],
[
data
],
)
)
elif
http_method
==
'PUT'
:
def
putCRT
(
self
,
context
,
environ
,
subpath
):
"""
Handle PUT /{context}/crt/{crt_id} urls.
"""
try
:
crt_id
,
=
subpath
except
ValueError
:
raise
NotFound
if
crt_id
==
'renew'
:
if
crt_id
==
'renew'
:
payload
=
utils
.
unwrap
(
payload
=
utils
.
unwrap
(
self
.
_readJSON
(
environ
),
self
.
_readJSON
(
environ
),
...
@@ -366,5 +396,3 @@ class Application(object):
...
@@ -366,5 +396,3 @@ class Application(object):
template_csr
=
template_csr
,
template_csr
=
template_csr
,
)
)
return
(
STATUS_NO_CONTENT
,
[],
[])
return
(
STATUS_NO_CONTENT
,
[],
[])
else
:
raise
BadMethod
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