@@ -193,50 +193,15 @@ class ApiHttpServer(HTTPServer):
193
193
# any gain and it potentially introduces a race
194
194
hash_cache , scramble_cache = None , None
195
195
196
- def __init__ (self , configuration , ** kwargs ):
196
+ def __init__ (self , configuration , logger = None , host = None , port = None , ** kwargs ):
197
197
self .configuration = configuration
198
- self .logger = configuration .logger
198
+ self .logger = logger if logger else configuration .logger
199
+ self .server_app = None
199
200
self ._on_start = kwargs .pop ('on_start' , lambda _ : None )
200
201
201
- address = configuration .daemon_conf ['address' ]
202
- port = configuration .daemon_conf ['port' ]
203
-
204
- addr = (address , port )
202
+ addr = (host , port )
205
203
HTTPServer .__init__ (self , addr , ApiHttpRequestHandler , ** kwargs )
206
204
207
- fqdn = self .server_name
208
- port = self .server_port
209
- # Masquerading if needed
210
- if configuration .daemon_conf ['show_address' ]:
211
- fqdn = configuration .daemon_conf ['show_address' ]
212
- if configuration .daemon_conf ['show_port' ]:
213
- port = configuration .daemon_conf ['show_port' ]
214
- if configuration .daemon_conf ['nossl' ]:
215
- proto = 'http'
216
- proto_port = 80
217
- else :
218
- proto = 'https'
219
- proto_port = 443
220
- if port != proto_port :
221
- self .base_url = '%s://%s:%s/' % (proto , fqdn , port )
222
- else :
223
- self .base_url = '%s://%s/' % (proto , fqdn )
224
-
225
- # We serve from sub dir to ease targeted proxying
226
- self .server_app = None
227
- self .server_base = 'openid'
228
- self .base_url += "%s/" % self .server_base
229
- self .openid = None
230
- self .approved = {}
231
- self .lastCheckIDRequest = {}
232
-
233
- # print "DEBUG: sreg fields: %s" % sreg.data_fields
234
- for name in cert_field_names :
235
- cert_field_aliases [name ] = []
236
- for target in [i for i in cert_field_names if name != i ]:
237
- if cert_field_map [name ] == cert_field_map [target ]:
238
- cert_field_aliases [name ].append (target )
239
-
240
205
@property
241
206
def base_environ (self ):
242
207
return {}
@@ -263,7 +228,11 @@ def server_activate(self):
263
228
264
229
class ThreadedApiHttpServer (ThreadingMixIn , ApiHttpServer ):
265
230
"""Multi-threaded version of the ApiHttpServer"""
266
- pass
231
+
232
+ @property
233
+ def base_url (self ):
234
+ proto = 'http'
235
+ return '%s://%s:%d/' % (proto , self .server_name , self .server_port )
267
236
268
237
269
238
class ApiHttpRequestHandler (WSGIRequestHandler ):
@@ -311,11 +280,6 @@ class ApiHttpRequestHandler(WSGIRequestHandler):
311
280
def __init__ (self , socket , addr , server , ** kwargs ):
312
281
self .server = server
313
282
314
- if self .daemon_conf ['session_ttl' ] > 0 :
315
- self .session_ttl = self .daemon_conf ['session_ttl' ]
316
- else :
317
- self .session_ttl = 48 * 3600
318
-
319
283
# NOTE: drop idle clients after N seconds to clean stale connections.
320
284
# Does NOT include clients that connect and do nothing at all :-(
321
285
self .timeout = 120
@@ -337,7 +301,7 @@ def daemon_conf(self):
337
301
338
302
@property
339
303
def logger (self ):
340
- return self .server .configuration . daemon_conf [ ' logger' ]
304
+ return self .server .logger
341
305
342
306
343
307
def limited_accept (logger , self , * args , ** kwargs ):
@@ -372,18 +336,16 @@ def start_service(configuration, host=None, port=None):
372
336
assert host is not None , "required kwarg: host"
373
337
assert port is not None , "required kwarg: port"
374
338
375
- """Service launcher"""
376
- daemon_conf = configuration .daemon_conf
377
339
logger = configuration .logger
378
340
379
- nossl = daemon_conf ['nossl' ]
380
- addr = (host , port )
381
341
# TODO: is this threaded version robust enough (thread safety)?
382
342
# OpenIDServer = ApiHttpServer
383
- httpserver = ThreadedApiHttpServer (configuration , addr )
343
+ def _on_start (server , * args , ** kwargs ):
344
+ server .server_app = _create_and_expose_server (None , server .configuration )
345
+ httpserver = ThreadedApiHttpServer (configuration , host = host , port = port , on_start = _on_start )
384
346
385
347
# Wrap in SSL if enabled
386
- if nossl :
348
+ if True :
387
349
logger .warning ('Not wrapping connections in SSL - only for testing!' )
388
350
else :
389
351
# Use best possible SSL/TLS args for this python version
@@ -415,152 +377,37 @@ def start_service(configuration, host=None, port=None):
415
377
httpserver .expire_volatile ()
416
378
417
379
418
- def _extend_configuration (configuration , address , port , ** kwargs ):
419
- configuration .daemon_conf = {
420
- 'address' : address ,
421
- 'port' : port ,
422
- 'root_dir' : os .path .abspath (configuration .user_home ),
423
- 'db_path' : os .path .abspath (default_db_path (configuration )),
424
- 'session_store' : os .path .abspath (configuration .openid_store ),
425
- 'session_ttl' : 24 * 3600 ,
426
- 'allow_password' : 'password' in configuration .user_openid_auth ,
427
- 'allow_digest' : 'digest' in configuration .user_openid_auth ,
428
- 'allow_publickey' : 'publickey' in configuration .user_openid_auth ,
429
- 'user_alias' : configuration .user_openid_alias ,
430
- 'host_rsa_key' : kwargs ['host_rsa_key' ],
431
- 'users' : [],
432
- 'login_map' : {},
433
- 'time_stamp' : 0 ,
434
- 'logger' : kwargs ['logger' ],
435
- 'nossl' : kwargs ['nossl' ],
436
- 'expandusername' : kwargs ['expandusername' ],
437
- 'show_address' : kwargs ['show_address' ],
438
- 'show_port' : kwargs ['show_port' ],
439
- 'support_email' : configuration .support_email ,
440
- # TODO: Add the following to configuration:
441
- # max_openid_user_hits
442
- # max_openid_user_abuse_hits
443
- # max_openid_proto_abuse_hits
444
- # max_openid_secret_hits
445
- 'auth_limits' :
446
- {'max_user_hits' : default_max_user_hits ,
447
- 'user_abuse_hits' : default_user_abuse_hits ,
448
- 'proto_abuse_hits' : default_proto_abuse_hits ,
449
- 'max_secret_hits' : 1 ,
450
- },
451
- }
452
-
453
-
454
- def main ():
455
- # Force no log init since we use separate logger
456
- configuration = get_configuration_object (skip_log = True )
380
+ def main (configuration = None ):
381
+ if not configuration :
382
+ # Force no log init since we use separate logger
383
+ configuration = get_configuration_object (skip_log = True )
457
384
458
385
log_level = configuration .loglevel
459
386
if sys .argv [1 :] and sys .argv [1 ] in ['debug' , 'info' , 'warning' , 'error' ]:
460
387
log_level = sys .argv [1 ]
461
388
462
389
# Use separate logger
463
- logger = daemon_logger ("openid " , configuration .user_openid_log , log_level )
390
+ logger = daemon_logger ("coreapi " , configuration .user_openid_log , log_level )
464
391
configuration .logger = logger
465
392
466
393
# Allow e.g. logrotate to force log re-open after rotates
467
394
register_hangup_handler (configuration )
468
395
469
- # For masquerading
470
- show_address = configuration .user_openid_show_address
471
- show_port = configuration .user_openid_show_port
472
-
473
- # Allow configuration overrides on command line
474
- nossl = False
475
- expandusername = False
476
- if sys .argv [2 :]:
477
- configuration .user_openid_address = sys .argv [2 ]
478
- if sys .argv [3 :]:
479
- configuration .user_openid_port = int (sys .argv [3 ])
480
- if sys .argv [4 :]:
481
- nossl = (sys .argv [4 ].lower () in ('1' , 'true' , 'yes' , 'on' ))
482
- if sys .argv [5 :]:
483
- expandusername = (sys .argv [5 ].lower () in ('1' , 'true' , 'yes' , 'on' ))
484
-
485
- if not configuration .site_enable_openid :
486
- err_msg = "OpenID service is disabled in configuration!"
487
- logger .error (err_msg )
488
- print (err_msg )
489
- sys .exit (1 )
490
- print ("""
491
- Running grid openid server for user authentication against MiG user DB.
492
-
493
- Set the MIG_CONF environment to the server configuration path
494
- unless it is available in mig/server/MiGserver.conf
495
- """ )
496
- print (__doc__ )
497
-
498
- default_host_key = """
499
- -----BEGIN RSA PRIVATE KEY-----
500
- MIIEogIBAAKCAQEA404IBMReHOdvhhJ5YtgquY3DNi0v0QwfPUk+EcH/CxFW8UCC
501
- SUJe85up6lEQmOE9yKvrh+3yJgIjdV/ASOw9bd/u0NgNoPwl6A6P8GzHp94vz7UP
502
- nTp+PEUbA8gwqXnzzdeuF3dLDSXuGHdcv8qQEVRBwj/haecO0fgZcfd4fmLDAG53
503
- e/Vwc4lVIp4xx+OQowm9RW3nsAZge1DUoxlStD1/rEzBq1DvVx1Wu8pWS48f2ABH
504
- fHt2Z4ozypMB+a4B56jervcZCNkV/fN2bdGZ8z07hNbn/EkaH2tPw/d62zdHddum
505
- u7Pi0tYwMZz9GN3t18r9qi5ldUJuJNeNvNc7swIBIwKCAQBuZ7rAfKK9lPunhVDm
506
- 3gYfnKClSSXakNv5MjQXQPg4k2S+UohsudZZERgEGL7rK5MJspb44Um6sJThPSLh
507
- l1EJe2VeH8wa/iEKUD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3AIpPdU8O
523
- 0drRG9zJTyU/BC02FvsGAMo0ZpGQRVMuN1Jj7sHsPaUdV38P4G0EaSQJDNxwFKVN
524
- 3stfzMDGtKM9lntAsfFQ8n4yvvEbn/quEWad6srf1yxt9B4t5JA=
525
- -----END RSA PRIVATE KEY-----
526
- """
396
+ # FIXME:
397
+ host = 'localhost' # configuration.user_openid_address
398
+ port = 5555 # configuration.user_openid_port
399
+ server_address = (host , port )
527
400
528
- try :
529
- host_key_fd = open (configuration .user_openid_key , 'r' )
530
- host_rsa_key = host_key_fd .read ()
531
- host_key_fd .close ()
532
- except IOError :
533
- logger .info ("No valid host key provided - using default" )
534
- host_rsa_key = default_host_key
535
-
536
- address = configuration .user_openid_address
537
- port = configuration .user_openid_port
538
- _extend_configuration (
539
- configuration ,
540
- address ,
541
- port ,
542
- logger = logger ,
543
- expandusername = False ,
544
- host_rsa_key = host_rsa_key ,
545
- nossl = True ,
546
- show_address = False ,
547
- show_port = False ,
548
- )
549
-
550
- logger .info ("Starting OpenID server" )
551
- info_msg = "Listening on address '%s' and port %d" % (address , port )
401
+ info_msg = "Starting coreapi..."
552
402
logger .info (info_msg )
553
403
print (info_msg )
404
+
554
405
try :
555
- start_service (configuration , host = address , port = port )
406
+ start_service (configuration , host = host , port = port )
556
407
except KeyboardInterrupt :
557
408
info_msg = "Received user interrupt"
558
409
logger .info (info_msg )
559
410
print (info_msg )
560
411
info_msg = "Leaving with no more workers active"
561
412
logger .info (info_msg )
562
413
print (info_msg )
563
-
564
-
565
- if __name__ == '__main__' :
566
- main ()
0 commit comments