From f299afd6f574f4ace50a70bb0a0c596b0ea90290 Mon Sep 17 00:00:00 2001 From: Gianmaria Del Monte Date: Tue, 15 Aug 2023 17:36:08 +0200 Subject: [PATCH 1/2] list all the registered plugins --- cmd/revad/main.go | 49 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/cmd/revad/main.go b/cmd/revad/main.go index 1df9e13e33..0f620f81d6 100644 --- a/cmd/revad/main.go +++ b/cmd/revad/main.go @@ -25,10 +25,14 @@ import ( "io/fs" "os" "path" + "reflect" "regexp" + "strings" "sync" "syscall" + gorun "runtime" + "github.com/cs3org/reva" "github.com/cs3org/reva/cmd/revad/pkg/config" "github.com/cs3org/reva/cmd/revad/pkg/grace" @@ -48,6 +52,7 @@ var ( configFlag = flag.String("c", "/etc/revad/revad.toml", "set configuration file") pidFlag = flag.String("p", "", "pid file. If empty defaults to a random file in the OS temporary directory") dirFlag = flag.String("dev-dir", "", "runs any toml file in the specified directory. Intended for development use only") + pluginsFlag = flag.Bool("plugins", false, "list all the plugins and exit") // Compile time variables initialized with gcc flags. gitCommit, buildDate, version, goVersion string @@ -70,6 +75,7 @@ func Main() { handleVersionFlag() handleSignalFlag() + handlePluginsFlag() confs, err := getConfigs() if err != nil { @@ -107,6 +113,49 @@ func handleVersionFlag() { } } +func handlePluginsFlag() { + if !*pluginsFlag { + return + } + + // TODO (gdelmont): maybe in future if needed we can filter + // by namespace (for example for getting all the http plugins). + // For now we just list all the plugins. + plugins := reva.GetPlugins("") + grouped := groupByNamespace(plugins) + + count := 0 + for ns, plugins := range grouped { + fmt.Printf("[%s]\n", ns) + for _, p := range plugins { + fmt.Printf("%s -> %s\n", p.ID.Name(), pkgOfFunction(p.New)) + } + count++ + if len(grouped) != count { + fmt.Println() + } + } + os.Exit(0) +} + +func nameOfFunction(f any) string { + return gorun.FuncForPC(reflect.ValueOf(f).Pointer()).Name() +} + +func pkgOfFunction(f any) string { + name := nameOfFunction(f) + i := strings.LastIndex(name, ".") + return name[:i] +} + +func groupByNamespace(plugins []reva.PluginInfo) map[string][]reva.PluginInfo { + m := make(map[string][]reva.PluginInfo) + for _, p := range plugins { + m[p.ID.Namespace()] = append(m[p.ID.Namespace()], p) + } + return m +} + func getVersionString() string { msg := "version=%s " msg += "commit=%s " From 7b95edc57de96e5325d32c31ec825f0f330b247b Mon Sep 17 00:00:00 2001 From: Gianmaria Del Monte Date: Tue, 15 Aug 2023 17:40:49 +0200 Subject: [PATCH 2/2] add changelog --- changelog/unreleased/plugin-list.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changelog/unreleased/plugin-list.md diff --git a/changelog/unreleased/plugin-list.md b/changelog/unreleased/plugin-list.md new file mode 100644 index 0000000000..73a2c940ed --- /dev/null +++ b/changelog/unreleased/plugin-list.md @@ -0,0 +1,3 @@ +Enhancement: List all the registered plugins + +https://github.com/cs3org/reva/pull/4114 \ No newline at end of file