From 7b946847dc28acff3735e8be682fa2317d8d1999 Mon Sep 17 00:00:00 2001 From: Mathieu Ancelin Date: Thu, 29 Feb 2024 17:52:49 +0100 Subject: [PATCH] Add custom plugin categories --- otoroshi/app/next/controllers/plugins.scala | 7 ++++++- otoroshi/app/next/plugins/api.scala | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/otoroshi/app/next/controllers/plugins.scala b/otoroshi/app/next/controllers/plugins.scala index a8004b0a5..0b8e253b2 100644 --- a/otoroshi/app/next/controllers/plugins.scala +++ b/otoroshi/app/next/controllers/plugins.scala @@ -17,7 +17,12 @@ class NgPluginsController( implicit val ec = env.otoroshiExecutionContext def categories() = ApiAction { - Ok(JsArray(NgPluginCategory.all.map(_.json))) + val pluginsCategories = env.scriptManager.ngNames.distinct + .filterNot(_.contains(".NgMerged")) + .flatMap(name => env.scriptManager.getAnyScript[NgNamedPlugin](s"cp:$name").toOption.map(o => (name, o))) + .flatMap(_._2.categories) + val categories = (NgPluginCategory.all ++ pluginsCategories).distinct.sortWith((a, b) => a.name.compareToIgnoreCase(b.name) < 0).map(_.json) + Ok(JsArray(categories)) } def steps() = ApiAction { diff --git a/otoroshi/app/next/plugins/api.scala b/otoroshi/app/next/plugins/api.scala index bdb768ae6..71cf25e2f 100644 --- a/otoroshi/app/next/plugins/api.scala +++ b/otoroshi/app/next/plugins/api.scala @@ -245,6 +245,7 @@ object NgPluginCategory { case object Classic extends NgPluginCategory { def name: String = "Classic" } case object ServiceDiscovery extends NgPluginCategory { def name: String = "ServiceDiscovery" } case object Websocket extends NgPluginCategory { def name: String = "Websocket" } + case class Custom(name: String) extends NgPluginCategory val all = Seq( Classic,