Create and configure the Keeper Commander Service.
()
| 22 | |
| 23 | |
| 24 | def create_app(): |
| 25 | """Create and configure the Keeper Commander Service.""" |
| 26 | logger.debug("Initializing Keeper Commander Service") |
| 27 | |
| 28 | log = logging.getLogger('werkzeug') |
| 29 | log.setLevel(logging.ERROR) |
| 30 | log.addFilter(SSLHandshakeFilter()) |
| 31 | |
| 32 | app = Flask(__name__) |
| 33 | |
| 34 | if is_behind_proxy(): |
| 35 | app.wsgi_app = ProxyFix(app.wsgi_app, x_for=1, x_proto=1, x_host=1, x_prefix=1) |
| 36 | |
| 37 | try: |
| 38 | logger.debug("Configuring rate limiter") |
| 39 | limiter.init_app(app) |
| 40 | |
| 41 | @app.errorhandler(RateLimitExceeded) |
| 42 | def handle_rate_limit_exceeded(e): |
| 43 | detail = getattr(e, 'description', None) or str(e) |
| 44 | body, status = rate_limited_response(detail) |
| 45 | return jsonify(body), status |
| 46 | |
| 47 | logger.debug("Initializing API routes") |
| 48 | init_routes(app) |
| 49 | |
| 50 | if (os.environ.get('SAILPOINT_RECORD') or '').strip(): |
| 51 | from .commands.integrations.sailpoint.service import SailPointService |
| 52 | SailPointService.start_background_services() |
| 53 | |
| 54 | print("Keeper Commander Service initialization complete") |
| 55 | return app |
| 56 | |
| 57 | except Exception as e: |
| 58 | logger.error(f"Failed to initialize Keeper Commander Service: {str(e)}") |
| 59 | raise |