Пример #1
0
    def __init__(self, debug: bool = False):
        self.debug = debug
        rules = []
        for endpoint in ENDPOINT_REGISTRY:
            if self.debug:
                # This helps us to make sure we can always generate a valid OpenAPI yaml file.
                _ = endpoint.to_operation_dict()

            rules.append(
                Rule(endpoint.default_path,
                     methods=[endpoint.method],
                     endpoint=Authenticate(endpoint.wrapped)))

        swagger_ui = ServeSwaggerUI(prefix="/[^/]+/check_mk/api/[^/]+/ui")

        self.url_map = Map([
            Submount(
                "/<path:_path>",
                [
                    Rule("/ui/", endpoint=swagger_ui),
                    Rule("/ui/<path:path>", endpoint=swagger_ui),
                    Rule("/openapi.yaml", endpoint=swagger_ui.serve_yaml),
                    Rule("/openapi.json", endpoint=swagger_ui.serve_json),
                    *rules,
                ],
            ),
        ])
        self.wsgi_app = with_context_middleware(
            OverrideRequestMethod(self._wsgi_app))
Пример #2
0
def create_url_map():
    """Instantiate all WSGI Apps and put them into the URL-Map."""
    _api_app = CheckmkApiApp(
        __name__,
        specification_dir=openapi_spec_dir(),
    )
    # NOTE
    # The URL will always contain the most up to date major version number, so that clients
    # exploring the API (browsers, etc.) will have a structural stability guarantee. Within major
    # versions only additions of fields or endpoints are allowed, never field changes or removals.
    # If a new major version is created it should be ADDED here and not replace the older version.
    # NOTE: v0 means totally unstable until we hit v1.
    _api_app.add_api_blueprint(
        'checkmk.yaml',
        base_path='/%s/check_mk/api/v0/' % cmk_version.omd_site(),
    )

    wrapped_api_app = with_context_middleware(
        OverrideRequestMethod(_api_app).wsgi_app)
    cmk_app = CheckmkApp()

    return Map([
        Submount('/<string:site>', [
            Submount("/check_mk", [
                Rule("/", endpoint=cmk_app),
                Rule("/dump.py", endpoint=dump_environ_app),
                Rule("/form.py", endpoint=test_formdata),
                Submount('/api', [
                    Rule("/", endpoint=wrapped_api_app),
                    Rule("/<path:path>", endpoint=wrapped_api_app),
                ]),
                Rule("/<string:script>", endpoint=cmk_app),
            ]),
        ])
    ])
Пример #3
0
    def __init__(self, debug: bool = False):
        self.debug = debug
        # TODO: Add resources for swagger-ui and json/yaml endpoints.
        # TODO: Add redoc.js endpoint.
        rules = []
        for endpoint in ENDPOINT_REGISTRY:
            if self.debug:
                # This helps us to make sure we can always generate a valid OpenAPI yaml file.
                _ = endpoint.to_operation_dict()

            rules.append(
                Rule(endpoint.default_path,
                     methods=[endpoint.method],
                     endpoint=Authenticate(endpoint.wrapped)))

        spec_file_buffer = spec_file()
        swagger_ui = ServeSwaggerUI(prefix="^/[^/]+/check_mk/api/[^/]+/ui")

        self.url_map = Map([
            Submount(
                "/<path:_path>",
                [
                    Rule("/ui/", endpoint=swagger_ui),
                    Rule("/ui/<path:path>", endpoint=swagger_ui),
                    # Rule("/doc/<path:file>", endpoint=serve_content()),
                    Rule(
                        "/openapi.yaml",
                        endpoint=serve_content(
                            file_handle=spec_file_buffer,
                            content_type='application/x-yaml; charset=utf-8',
                        ),
                    ),
                    Rule(
                        "/openapi.json",
                        endpoint=serve_content(
                            file_handle=json_file(spec_file_buffer),
                            content_type='application/json',
                        ),
                    ),
                    *rules,
                ],
            ),
        ])
        self.wsgi_app = with_context_middleware(
            OverrideRequestMethod(self._wsgi_app))
Пример #4
0
    def __init__(self, debug: bool = False):
        self.debug = debug
        # This intermediate data structure is necessary because `Rule`s can't contain anything
        # other than str anymore. Technically they could, but the typing is now fixed to str.
        self.endpoints: Dict[str, WSGIApplication] = {
            "swagger-ui":
            ServeSwaggerUI(prefix="/[^/]+/check_mk/api/[^/]+/ui"),
            "swagger-ui-yaml": ServeSpec("swagger-ui", "yaml"),
            "swagger-ui-json": ServeSpec("swagger-ui", "json"),
            "doc-yaml": ServeSpec("doc", "yaml"),
            "doc-json": ServeSpec("doc", "json"),
        }
        rules: List[Rule] = []
        endpoint: Endpoint
        for endpoint in ENDPOINT_REGISTRY:
            if self.debug:
                # This helps us to make sure we can always generate a valid OpenAPI yaml file.
                _ = endpoint.to_operation_dict()

            rules.append(
                Rule(
                    endpoint.default_path,
                    methods=[endpoint.method],
                    endpoint=endpoint.ident,
                ))
            self.endpoints[endpoint.ident] = Authenticate(endpoint.wrapped)

        self.url_map = Map([
            Submount(
                "/<path:_path>",
                [
                    Rule("/ui/", endpoint="swagger-ui"),
                    Rule("/ui/<path:path>", endpoint="swagger-ui"),
                    Rule("/openapi-swagger-ui.yaml",
                         endpoint="swagger-ui-yaml"),
                    Rule("/openapi-swagger-ui.json",
                         endpoint="swagger-ui-json"),
                    Rule("/openapi-doc.yaml", endpoint="doc-yaml"),
                    Rule("/openapi-doc.json", endpoint="doc-json"),
                    *rules,
                ],
            )
        ])
        self.wsgi_app = with_context_middleware(
            OverrideRequestMethod(self._wsgi_app))