From d5084eea841f21b854a91a4045dba3dc8e63e3bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Duffeck?= Date: Wed, 27 Apr 2022 09:30:08 +0200 Subject: [PATCH] Add command for (re-)indexing existing spaces --- extensions/search/pkg/command/index.go | 52 ++++++++++++++++++++++++++ extensions/search/pkg/command/root.go | 1 + 2 files changed, 53 insertions(+) create mode 100644 extensions/search/pkg/command/index.go diff --git a/extensions/search/pkg/command/index.go b/extensions/search/pkg/command/index.go new file mode 100644 index 0000000000..3d57e92642 --- /dev/null +++ b/extensions/search/pkg/command/index.go @@ -0,0 +1,52 @@ +package command + +import ( + "context" + "fmt" + + "github.com/urfave/cli/v2" + + "github.com/owncloud/ocis/extensions/search/pkg/config" + "github.com/owncloud/ocis/extensions/search/pkg/config/parser" + "github.com/owncloud/ocis/ocis-pkg/service/grpc" + searchsvc "github.com/owncloud/ocis/protogen/gen/ocis/services/search/v0" +) + +// Index is the entrypoint for the server command. +func Index(cfg *config.Config) *cli.Command { + return &cli.Command{ + Name: "index", + Usage: "index the files for one one more users", + Category: "index management", + Aliases: []string{"i"}, + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "space", + Aliases: []string{"s"}, + Required: true, + Usage: "the id of the space to travers and index the files of", + }, + &cli.StringFlag{ + Name: "user", + Aliases: []string{"u"}, + Required: true, + Usage: "the username of the user tha shall be used to access the files", + }, + }, + Before: func(c *cli.Context) error { + return parser.ParseConfig(cfg) + }, + Action: func(c *cli.Context) error { + client := searchsvc.NewSearchProviderService("com.owncloud.api.search", grpc.DefaultClient) + _, err := client.IndexSpace(context.Background(), &searchsvc.IndexSpaceRequest{ + SpaceId: c.String("space"), + UserId: c.String("user"), + }) + if err != nil { + fmt.Println("failed to index space: " + err.Error()) + return err + } + return nil + }, + } +} diff --git a/extensions/search/pkg/command/root.go b/extensions/search/pkg/command/root.go index 2e282d6a66..a43261631f 100644 --- a/extensions/search/pkg/command/root.go +++ b/extensions/search/pkg/command/root.go @@ -19,6 +19,7 @@ func GetCommands(cfg *config.Config) cli.Commands { Server(cfg), // interaction with this service + Index(cfg), // infos about this service Health(cfg),