override fun process()

in dsl/ktor/ktor-lang-parser/src/main/kotlin/io/kotless/parser/ktor/processor/route/DynamicRoutesProcessor.kt [37:70]


    override fun process(files: Set<KtFile>, binding: BindingContext, context: ProcessorContext) {
        val globalPermissions = context.output.get(GlobalActionsProcessor).permissions
        val entrypoint = context.output.get(EntrypointProcessor).entrypoint
        assert(KotlessAWS::prepare.name == KotlessAzure::prepare.name) {
            "Internal Kotless error: Ktor entrypoint classes should have prepare function"
        }

        processClasses(files, binding) { klass, _ ->
            klass.visitNamedFunctions(filter = { func -> func.name == KotlessAWS::prepare.name }) { func ->
                func.visitCallExpressionsWithReferences(binding = binding, filter = { it.getFqName(binding) in functions.keys }) { element ->
                    val outer = getDynamicPath(element, binding)

                    val method = functions[element.getFqName(binding)] ?: error(element, "Unknown Ktor HTTP handler definition")

                    val permissions = PermissionsProcessor.process(element, binding, context) + globalPermissions

                    val path = URIPath(outer, element.getArgument("path", binding).asPath(binding))
                    val name = "${path.parts.joinToString(separator = "_")}_${method.name}"

                    val key = TypedStorage.Key<Lambda>()
                    val function = Lambda(name, context.jar, entrypoint, context.lambda, permissions)

                    context.resources.register(key, function)
                    context.routes.register(Application.API.DynamicRoute(method, path, key))

                    if (context.config.optimization.autoWarm.enable) {
                        context.events.register(
                            Events.Scheduled(name, everyNMinutes(context.config.optimization.autoWarm.minutes), ScheduledEventType.Autowarm, key)
                        )
                    }
                }
            }
        }
    }