POC: extensions promoting their own setting bundles onto the settings service
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"github.com/oklog/run"
|
||||
"github.com/owncloud/ocis-accounts/pkg/config"
|
||||
"github.com/owncloud/ocis-accounts/pkg/server/grpc"
|
||||
svc "github.com/owncloud/ocis-accounts/pkg/service/v0"
|
||||
oclog "github.com/owncloud/ocis-pkg/v2/log"
|
||||
)
|
||||
|
||||
@@ -65,7 +66,12 @@ func Server(cfg *config.Config) *cli.Command {
|
||||
},
|
||||
},
|
||||
Before: func(c *cli.Context) error {
|
||||
logger = oclog.NewLogger(oclog.Name(cfg.Server.Name))
|
||||
logger = oclog.NewLogger(
|
||||
oclog.Name(cfg.Server.Name),
|
||||
oclog.Level("info"),
|
||||
oclog.Color(true),
|
||||
oclog.Pretty(true),
|
||||
)
|
||||
return ParseConfig(c, cfg)
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
@@ -83,6 +89,8 @@ func Server(cfg *config.Config) *cli.Command {
|
||||
)
|
||||
|
||||
gr.Add(func() error {
|
||||
logger.Info().Str("service", service.Name()).Msg("Reporting settings bundle to account service")
|
||||
go svc.ReportSettingsBundle(&logger)
|
||||
return service.Run()
|
||||
}, func(_ error) {
|
||||
fmt.Println("shutting down grpc server")
|
||||
|
||||
@@ -4,10 +4,12 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/golang/protobuf/ptypes/empty"
|
||||
"github.com/micro/go-micro/v2"
|
||||
"github.com/owncloud/ocis-accounts/pkg/account"
|
||||
"github.com/owncloud/ocis-accounts/pkg/config"
|
||||
"github.com/owncloud/ocis-accounts/pkg/proto/v0"
|
||||
olog "github.com/owncloud/ocis-pkg/v2/log"
|
||||
settings "github.com/owncloud/ocis-settings/pkg/proto/v0"
|
||||
)
|
||||
|
||||
// New returns a new instance of Service
|
||||
@@ -65,3 +67,81 @@ func (s Service) List(ctx context.Context, in *empty.Empty, res *proto.Records)
|
||||
res.Records = r
|
||||
return nil
|
||||
}
|
||||
|
||||
// ReportSettingsBundle writes the settings bundle for the extension on the ocis-settings service.
|
||||
// TODO implement retry logic.
|
||||
// TODO ensure the settings service is available.
|
||||
func ReportSettingsBundle(l *olog.Logger) {
|
||||
// TODO wrap this in an infinite for loop with a BREAK label to GOTO once the request succeed.
|
||||
svc := micro.NewService()
|
||||
svc.Init()
|
||||
service := settings.NewBundleService("com.owncloud.ocis-settings", svc.Client()) // TODO fetch service name instead of hardcoding it.
|
||||
|
||||
// TODO avoid hardcoding these values, perhaps load them from a file and using jsonpb's type Marshal.
|
||||
createBundleRequest := settings.CreateSettingsBundleRequest{
|
||||
SettingsBundle: &settings.SettingsBundle{
|
||||
Extension: "ocis-accounts",
|
||||
Key: "profile",
|
||||
DisplayName: "Profile",
|
||||
Settings: []*settings.Setting{
|
||||
&settings.Setting{
|
||||
Key: "timezone",
|
||||
DisplayName: "Timezone",
|
||||
Description: "User timezone",
|
||||
Value: &settings.Setting_SingleChoiceValue{
|
||||
SingleChoiceValue: &settings.SingleChoiceListSetting{
|
||||
Options: []*settings.ListOption{
|
||||
&settings.ListOption{
|
||||
Selected: true,
|
||||
Option: &settings.ListOption_StringValue{
|
||||
StringValue: "Europe/Berlin",
|
||||
},
|
||||
},
|
||||
&settings.ListOption{
|
||||
Selected: false,
|
||||
Option: &settings.ListOption_StringValue{
|
||||
StringValue: "Asia/Kathmandu",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
&settings.Setting{
|
||||
Key: "language",
|
||||
DisplayName: "Language",
|
||||
Description: "User language",
|
||||
Value: &settings.Setting_SingleChoiceValue{
|
||||
SingleChoiceValue: &settings.SingleChoiceListSetting{
|
||||
Options: []*settings.ListOption{
|
||||
&settings.ListOption{
|
||||
Selected: true,
|
||||
Option: &settings.ListOption_StringValue{
|
||||
StringValue: "de_DE",
|
||||
},
|
||||
},
|
||||
&settings.ListOption{
|
||||
Selected: false,
|
||||
Option: &settings.ListOption_StringValue{
|
||||
StringValue: "en_EN",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
res, err := service.CreateSettingsBundle(context.Background(), &createBundleRequest)
|
||||
if err != nil {
|
||||
l.Err(err).
|
||||
Msg("Error reporting settings bundle")
|
||||
} else {
|
||||
l.Info().
|
||||
Str("bundle key", res.GetSettingsBundle().GetKey()).
|
||||
Msg("Succesfully reported settings bundle")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user