<s> import eventlet <EOL> import os <EOL> import sys <EOL> from oslo_config import cfg <EOL> from eventlet import wsgi <EOL> from st2common import log as logging <EOL> from st2common . service_setup import setup as common_setup <EOL> from st2common . service_setup import teardown as common_teardown <EOL> from st2common . util . monkey_patch import monkey_patch <EOL> from st2common . constants . auth import VALID_MODES <EOL> from st2auth import config <EOL> config . register_opts ( ) <EOL> from st2auth import app <EOL> __all__ = [ <EOL> '<STR_LIT>' <EOL> ] <EOL> monkey_patch ( ) <EOL> LOG = logging . getLogger ( __name__ ) <EOL> def _setup ( ) : <EOL> common_setup ( service = '<STR_LIT>' , config = config , setup_db = True , register_mq_exchanges = False , <EOL> register_signal_handlers = True , register_internal_trigger_types = False , <EOL> run_migrations = False ) <EOL> if cfg . CONF . auth . mode not in VALID_MODES : <EOL> raise ValueError ( '<STR_LIT>' % ( '<STR_LIT:U+002C>' . join ( VALID_MODES ) ) ) <EOL> def _run_server ( ) : <EOL> host = cfg . CONF . auth . host <EOL> port = cfg . CONF . auth . port <EOL> use_ssl = cfg . CONF . auth . use_ssl <EOL> cert_file_path = os . path . realpath ( cfg . CONF . auth . cert ) <EOL> key_file_path = os . path . realpath ( cfg . CONF . auth . key ) <EOL> if use_ssl and not os . path . isfile ( cert_file_path ) : <EOL> raise ValueError ( '<STR_LIT>' % ( cert_file_path ) ) <EOL> if use_ssl and not os . path . isfile ( key_file_path ) : <EOL> raise ValueError ( '<STR_LIT>' % ( key_file_path ) ) <EOL> socket = eventlet . listen ( ( host , port ) ) <EOL> if use_ssl : <EOL> socket = eventlet . wrap_ssl ( socket , <EOL> certfile = cert_file_path , <EOL> keyfile = key_file_path , <EOL> server_side = True ) <EOL> LOG . info ( '<STR_LIT>' , cfg . CONF . auth . mode ) <EOL> LOG . info ( '<STR_LIT>' , os . getpid ( ) , <EOL> '<STR_LIT>' if use_ssl else '<STR_LIT:http>' , host , port ) <EOL> wsgi . server ( socket , app . setup_app ( ) ) <EOL> return <NUM_LIT:0> <EOL> def _teardown ( ) : <EOL> common_teardown ( ) <EOL> def main ( ) : <EOL> try : <EOL> _setup ( ) <EOL> return _run_server ( ) <EOL> except SystemExit as exit_code : <EOL> sys . exit ( exit_code ) <EOL> except Exception : <EOL> LOG . exception ( '<STR_LIT>' , os . getpid ( ) ) <EOL> return <NUM_LIT:1> <EOL> finally : <EOL> _teardown ( ) </s>
