add proxy

This commit is contained in:
A.Unger
2021-03-04 13:56:49 +01:00
parent f7917bf760
commit e25f5b1c98
6 changed files with 42 additions and 13 deletions

View File

@@ -10,6 +10,7 @@ import (
idp "github.com/owncloud/ocis/idp/pkg/command"
ocs "github.com/owncloud/ocis/ocs/pkg/command"
onlyoffice "github.com/owncloud/ocis/onlyoffice/pkg/command"
proxy "github.com/owncloud/ocis/proxy/pkg/command"
settings "github.com/owncloud/ocis/settings/pkg/command"
"github.com/thejerf/suture"
@@ -120,6 +121,7 @@ func (r *Runtime) Start() error {
addServiceToken("idp", supervisor.Add(idp.NewSutureService(globalCtx, r.c.IDP)))
addServiceToken("ocs", supervisor.Add(ocs.NewSutureService(globalCtx, r.c.OCS)))
addServiceToken("onlyoffice", supervisor.Add(onlyoffice.NewSutureService(globalCtx, r.c.Onlyoffice)))
addServiceToken("proxy", supervisor.Add(proxy.NewSutureService(globalCtx, r.c.Proxy)))
// TODO(refs) debug line with supervised services.
go supervisor.ServeBackground()

View File

@@ -4,10 +4,11 @@ import (
"os"
"github.com/owncloud/ocis/proxy/pkg/command"
"github.com/owncloud/ocis/proxy/pkg/config"
)
func main() {
if err := command.Execute(); err != nil {
if err := command.Execute(config.New()); err != nil {
os.Exit(1)
}
}

View File

@@ -1,6 +1,7 @@
package command
import (
"context"
"os"
"strings"
@@ -13,9 +14,7 @@ import (
)
// Execute is the entry point for the ocis-proxy command.
func Execute() error {
cfg := config.New()
func Execute(cfg *config.Config) error {
app := &cli.App{
Name: "ocis-proxy",
Version: version.String,
@@ -109,3 +108,31 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error {
return nil
}
// SutureService allows for the onlyoffice command to be embedded and supervised by a suture supervisor tree.
type SutureService struct {
ctx context.Context
cancel context.CancelFunc // used to cancel the context go-micro services used to shutdown a service.
cfg *config.Config
}
// NewSutureService creates a new onlyoffice.SutureService
func NewSutureService(ctx context.Context, cfg *config.Config) SutureService {
sctx, cancel := context.WithCancel(ctx)
cfg.Context = sctx // propagate the context down to the go-micro services.
return SutureService{
ctx: sctx,
cancel: cancel,
cfg: cfg,
}
}
func (s SutureService) Serve() {
if err := Execute(s.cfg); err != nil {
return
}
}
func (s SutureService) Stop() {
s.cancel()
}

View File

@@ -45,7 +45,7 @@ func Server(cfg *config.Config) *cli.Command {
return &cli.Command{
Name: "server",
Usage: "Start integrated server",
Flags: flagset.ServerWithConfig(cfg),
Flags: append(flagset.ServerWithConfig(cfg), flagset.RootWithConfig(cfg)...),
Before: func(ctx *cli.Context) error {
if cfg.HTTP.Root != "/" {
cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/")
@@ -176,8 +176,6 @@ func Server(cfg *config.Config) *cli.Command {
proxyHTTP.Context(ctx),
proxyHTTP.Config(cfg),
proxyHTTP.Metrics(metrics),
proxyHTTP.Flags(flagset.RootWithConfig(config.New())),
proxyHTTP.Flags(flagset.ServerWithConfig(config.New())),
proxyHTTP.Middlewares(loadMiddlewares(ctx, logger, cfg)),
)

View File

@@ -1,5 +1,7 @@
package config
import "context"
// Log defines the available logging configuration.
type Log struct {
Level string
@@ -119,6 +121,8 @@ type Config struct {
AutoprovisionAccounts bool
EnableBasicAuth bool
InsecureBackends bool
Context context.Context
}
// OIDC is the config for the OpenID-Connect middleware. If set the proxy will try to authenticate every request

View File

@@ -10,23 +10,20 @@ func RootWithConfig(cfg *config.Config) []cli.Flag {
return []cli.Flag{
&cli.StringFlag{
Name: "log-level",
Value: "info",
Usage: "Set logging level",
EnvVars: []string{"PROXY_LOG_LEVEL"},
EnvVars: []string{"PROXY_LOG_LEVEL", "OCIS_LOG_LEVEL"},
Destination: &cfg.Log.Level,
},
&cli.BoolFlag{
Name: "log-pretty",
Value: true,
Usage: "Enable pretty logging",
EnvVars: []string{"PROXY_LOG_PRETTY"},
EnvVars: []string{"PROXY_LOG_PRETTY", "OCIS_LOG_PRETTY"},
Destination: &cfg.Log.Pretty,
},
&cli.BoolFlag{
Name: "log-color",
Value: true,
Usage: "Enable colored logging",
EnvVars: []string{"PROXY_LOG_COLOR"},
EnvVars: []string{"PROXY_LOG_COLOR", "OCIS_LOG_COLOR"},
Destination: &cfg.Log.Color,
},
}