Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
authserv
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor 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
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
ai
authserv
Commits
a8f9317a
Commit
a8f9317a
authored
11 years ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
allow user to select HTTP engine (supported: gevent and werkzeug)
parent
abeed0b4
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
authserv/openssl.py
+0
-0
0 additions, 0 deletions
authserv/openssl.py
authserv/server.py
+54
-10
54 additions, 10 deletions
authserv/server.py
authserv/test/test_integration.py
+2
-5
2 additions, 5 deletions
authserv/test/test_integration.py
with
56 additions
and
15 deletions
authserv/ssl.py
→
authserv/
open
ssl.py
+
0
−
0
View file @
a8f9317a
File moved
This diff is collapsed.
Click to expand it.
authserv/server.py
+
54
−
10
View file @
a8f9317a
...
@@ -6,7 +6,6 @@ from authserv import app
...
@@ -6,7 +6,6 @@ from authserv import app
from
authserv
import
auth
from
authserv
import
auth
from
authserv
import
protocol
from
authserv
import
protocol
from
authserv.ratelimit
import
*
from
authserv.ratelimit
import
*
from
authserv
import
ssl
from
flask
import
Flask
,
request
,
abort
,
make_response
from
flask
import
Flask
,
request
,
abort
,
make_response
...
@@ -77,14 +76,64 @@ def create_app(userdb=None, mc=None):
...
@@ -77,14 +76,64 @@ def create_app(userdb=None, mc=None):
return
app
return
app
def
run_werkzeug
(
addr
,
port
,
ssl_ca
,
ssl_cert
,
ssl_key
,
dh_params
):
ssl_ctx
=
None
if
ssl_ca
and
os
.
path
.
exists
(
ssl_ca
):
from
authserv
import
openssl
ssl_ctx
=
openssl
.
create_server_context
(
ssl_cert
,
ssl_key
,
ssl_ca
,
dhparams
)
logging
.
info
(
'
starting werkzeug server on %s:%d
'
,
addr
,
port
)
app
.
run
(
host
=
addr
,
port
=
port
,
use_reloader
=
False
,
ssl_context
=
ssl_ctx
)
def
run_gevent
(
addr
,
port
,
ssl_ca
,
ssl_cert
,
ssl_key
,
dh_params
):
from
gevent.monkey
import
patch_all
patch_all
()
from
gevent.pywsgi
import
WSGIServer
ssl_args
=
{}
if
ssl_ca
and
os
.
path
.
exists
(
ssl_ca
):
import
ssl
ssl_args
=
{
'
server_side
'
:
True
,
'
certfile
'
:
ssl_cert
,
'
keyfile
'
:
ssl_key
,
'
ca_certs
'
:
ssl_ca
,
'
cert_reqs
'
:
ssl
.
CERT_REQUIRED
,
'
ssl_version
'
:
ssl
.
PROTOCOL_TLSv1
,
}
logging
.
info
(
'
starting gevent server on %s:%d
'
,
addr
,
port
)
WSGIServer
((
addr
,
port
),
app
.
wsgi_app
,
**
ssl_args
).
serve_forever
()
def
run
(
engines
,
addr
,
port
,
ssl_ca
,
ssl_cert
,
ssl_key
,
dh_params
):
if
engines
:
engines
=
engines
.
split
(
'
,
'
)
else
:
engines
=
[
'
gevent
'
,
'
werkzeug
'
]
for
e
in
engines
:
fn
=
globals
().
get
(
'
run_
'
+
e
,
None
)
if
not
fn
:
logging
.
error
(
'
Unknown HTTP engine
"
%s
"'
,
e
)
continue
try
:
return
fn
(
addr
,
port
,
ssl_ca
,
ssl_cert
,
ssl_key
,
dh_params
)
except
ImportError
:
pass
logging
.
fatal
(
'
No HTTP engine available to run the server
'
)
def
main
():
def
main
():
parser
=
optparse
.
OptionParser
()
parser
=
optparse
.
OptionParser
()
parser
.
add_option
(
'
--config
'
,
parser
.
add_option
(
'
--config
'
,
help
=
'
Configuration file
'
)
help
=
'
Configuration file
'
)
parser
.
add_option
(
'
--port
'
,
type
=
'
int
'
,
default
=
1616
,
help
=
'
TCP port to listen on (default: %default)
'
)
parser
.
add_option
(
'
--addr
'
,
dest
=
'
addr
'
,
default
=
'
0.0.0.0
'
,
parser
.
add_option
(
'
--addr
'
,
dest
=
'
addr
'
,
default
=
'
0.0.0.0
'
,
help
=
'
Address to listen on (default: %default)
'
)
help
=
'
Address to listen on (default: %default)
'
)
parser
.
add_option
(
'
--port
'
,
type
=
'
int
'
,
default
=
1616
,
help
=
'
TCP port to listen on (default: %default)
'
)
parser
.
add_option
(
'
--engine
'
,
dest
=
'
engine
'
,
help
=
'
HTTP engine to use (default: try gevent, then werkzeug)
'
)
parser
.
add_option
(
'
--ca
'
,
dest
=
'
ssl_ca
'
,
parser
.
add_option
(
'
--ca
'
,
dest
=
'
ssl_ca
'
,
default
=
'
/etc/ai/internal_ca.pem
'
,
default
=
'
/etc/ai/internal_ca.pem
'
,
help
=
'
SSL CA certificate file (default: %default)
'
)
help
=
'
SSL CA certificate file (default: %default)
'
)
...
@@ -122,13 +171,8 @@ def main():
...
@@ -122,13 +171,8 @@ def main():
signal
.
signal
(
signal
.
SIGINT
,
_stopall
)
signal
.
signal
(
signal
.
SIGINT
,
_stopall
)
signal
.
signal
(
signal
.
SIGTERM
,
_stopall
)
signal
.
signal
(
signal
.
SIGTERM
,
_stopall
)
ssl_ctx
=
None
run
(
opts
.
engine
,
opts
.
addr
,
opts
.
port
,
opts
.
ssl_ca
,
if
opts
.
ssl_ca
and
os
.
path
.
exists
(
opts
.
ssl_ca
):
opts
.
ssl_cert
,
opts
.
ssl_key
,
opts
.
dh_params
)
ssl_ctx
=
ssl
.
create_server_context
(
opts
.
ssl_cert
,
opts
.
ssl_key
,
opts
.
ssl_ca
,
opts
.
dh_params
)
app
.
run
(
host
=
opts
.
addr
,
port
=
opts
.
port
,
use_reloader
=
False
,
ssl_context
=
ssl_ctx
)
if
__name__
==
'
__main__
'
:
if
__name__
==
'
__main__
'
:
...
...
This diff is collapsed.
Click to expand it.
authserv/test/test_integration.py
+
2
−
5
View file @
a8f9317a
...
@@ -9,7 +9,6 @@ from authserv.test import *
...
@@ -9,7 +9,6 @@ from authserv.test import *
from
authserv.ratelimit
import
*
from
authserv.ratelimit
import
*
from
authserv
import
protocol
from
authserv
import
protocol
from
authserv
import
server
from
authserv
import
server
from
authserv
import
ssl
URL
=
'
/api/1/auth
'
URL
=
'
/api/1/auth
'
...
@@ -70,10 +69,8 @@ class SSLServerTest(unittest.TestCase):
...
@@ -70,10 +69,8 @@ class SSLServerTest(unittest.TestCase):
pid
=
os
.
fork
()
pid
=
os
.
fork
()
if
pid
==
0
:
if
pid
==
0
:
print
>>
sys
.
stderr
,
'
starting server on port %d
'
%
self
.
port
print
>>
sys
.
stderr
,
'
starting server on port %d
'
%
self
.
port
ssl_ctx
=
ssl
.
create_server_context
(
server
.
run
(
None
,
'
127.0.0.1
'
,
self
.
port
,
self
.
ssl_ca
,
self
.
ssl_cert
,
self
.
ssl_key
,
self
.
ssl_ca
,
self
.
dhparams
)
self
.
ssl_cert
,
self
.
ssl_key
,
self
.
dhparams
)
app
.
run
(
host
=
'
127.0.0.1
'
,
port
=
self
.
port
,
use_reloader
=
False
,
ssl_context
=
ssl_ctx
)
else
:
else
:
self
.
pid
=
pid
self
.
pid
=
pid
time
.
sleep
(
0.2
)
time
.
sleep
(
0.2
)
...
...
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