Skip to content

Commit

Permalink
Remove server's support for .yaml based configuration (#183)
Browse files Browse the repository at this point in the history
* Rename server's config flag to --config-dir

* .

* remove server --config completely

* .

* Delete mTLS test as config not supported
  • Loading branch information
feedmeapples authored Mar 31, 2023
1 parent d4a0004 commit d7f2c05
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 249 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- name: Test
env:
CGO_ENABLED: 0
run: go test -v ./...
run: go test ./...

test-shellcheck:
name: Shellcheck
Expand Down
148 changes: 0 additions & 148 deletions app/mtls_test.go

This file was deleted.

1 change: 0 additions & 1 deletion common/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ var (
FlagCodecAuth = "codec-auth"
FlagCodecEndpoint = "codec-endpoint"
FlagConcurrency = "concurrency"
FlagConfig = "config"
FlagContextTimeout = "context-timeout"
FlagCronSchedule = "cron"
FlagDBPath = "db-filename"
Expand Down
34 changes: 3 additions & 31 deletions server/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,6 @@ func NewServerCommands(defaultCfg *sconfig.Config) []*cli.Command {
EnvVars: nil,
Value: nil,
},
&cli.StringFlag{
Name: common.FlagConfig,
Aliases: []string{"c"},
Usage: `Path to config directory.`,
EnvVars: []string{config.EnvKeyConfigDir},
Value: "",
},
&cli.StringSliceFlag{
Name: common.FlagDynamicConfigValue,
Usage: `Dynamic config value, as KEY=JSON_VALUE (string values need quotes).`,
Expand Down Expand Up @@ -170,13 +163,6 @@ func NewServerCommands(defaultCfg *sconfig.Config) []*cli.Command {
return cli.Exit(fmt.Sprintf("bad value %q passed for flag %q", c.String(common.FlagIP), common.FlagIP), 1)
}

if c.IsSet(common.FlagConfig) {
cfgPath := c.String(common.FlagConfig)
if _, err := os.Stat(cfgPath); os.IsNotExist(err) {
return cli.Exit(fmt.Sprintf("bad value %q passed for flag %q: file not found", c.String(common.FlagConfig), common.FlagConfig), 1)
}
}

return nil
},
Action: func(c *cli.Context) error {
Expand Down Expand Up @@ -210,20 +196,6 @@ func NewServerCommands(defaultCfg *sconfig.Config) []*cli.Command {
if err != nil {
return err
}

baseConfig := &config.Config{}
if c.IsSet(common.FlagConfig) {
// Temporal server requires a couple of persistence config values to
// be explicitly set or the config loading fails. While these are the
// same values used internally, they are overridden later anyways,
// they are just here to pass validation.
baseConfig.Persistence.DefaultStore = sconfig.PersistenceStoreName
baseConfig.Persistence.NumHistoryShards = 1
if err := config.Load("temporal", c.String(common.FlagConfig), "", &baseConfig); err != nil {
return err
}
}

interruptChan := make(chan interface{}, 1)
go func() {
if doneChan := c.Done(); doneChan != nil {
Expand All @@ -245,7 +217,7 @@ func NewServerCommands(defaultCfg *sconfig.Config) []*cli.Command {
WithUpstreamOptions(
temporal.InterruptOn(interruptChan),
),
WithBaseConfig(baseConfig),
WithBaseConfig(&config.Config{}),
}

if c.IsSet(common.FlagDBPath) {
Expand All @@ -267,11 +239,11 @@ func NewServerCommands(defaultCfg *sconfig.Config) []*cli.Command {
},
}

opt, err := newUIOption(uiBaseCfg, c.String(common.FlagConfig))

opt, err := newUIOption(uiBaseCfg)
if err != nil {
return err
}

if opt != nil {
opts = append(opts, opt)
}
Expand Down
26 changes: 2 additions & 24 deletions server/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,33 +29,11 @@ package server
// This file should be the only one to import ui-server packages.
// This is to avoid embedding the UI's static assets in the binary when the `headless` build tag is enabled.
import (
"strings"

provider "github.com/temporalio/ui-server/v2/plugins/fs_config_provider"
uiserver "github.com/temporalio/ui-server/v2/server"
uiconfig "github.com/temporalio/ui-server/v2/server/config"
uiserveroptions "github.com/temporalio/ui-server/v2/server/server_options"
)

func newUIOption(c *uiconfig.Config, configDir string) (ServerOption, error) {
cfg, err := MergeWithConfigFile(
c,
configDir,
)
if err != nil {
return nil, err
}
return WithUI(uiserver.NewServer(uiserveroptions.WithConfigProvider(cfg))), nil
}

func MergeWithConfigFile(cfg *uiconfig.Config, configDir string) (*uiconfig.Config, error) {
if configDir != "" {
if err := provider.Load(configDir, cfg, "temporal-ui"); err != nil {
if !strings.HasPrefix(err.Error(), "no config files found") {
return nil, err
}
}
}

return cfg, nil
func newUIOption(c *uiconfig.Config) (ServerOption, error) {
return WithUI(uiserver.NewServer(uiserveroptions.WithConfigProvider(c))), nil
}
46 changes: 2 additions & 44 deletions server/ui_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,55 +33,13 @@ import (
)

func TestNewUIConfig(t *testing.T) {
c := &uiconfig.Config{
cfg := &uiconfig.Config{
Host: "localhost",
Port: 8233,
TemporalGRPCAddress: "localhost:7233",
EnableUI: true,
}
cfg, err := MergeWithConfigFile(c, "")
if err != nil {
t.Errorf("cannot create config: %s", err)
return
}
if err = cfg.Validate(); err != nil {
t.Errorf("config not valid: %s", err)
}
}

func TestNewUIConfigWithMissingConfigFile(t *testing.T) {
c := &uiconfig.Config{
Host: "localhost",
Port: 8233,
TemporalGRPCAddress: "localhost:7233",
EnableUI: true,
}
cfg, err := MergeWithConfigFile(c, "wibble")
if err != nil {
t.Errorf("cannot create config: %s", err)
return
}
if err = cfg.Validate(); err != nil {
if err := cfg.Validate(); err != nil {
t.Errorf("config not valid: %s", err)
}
}

func TestNewUIConfigWithPresentConfigFile(t *testing.T) {
c := &uiconfig.Config{
Host: "localhost",
Port: 8233,
TemporalGRPCAddress: "localhost:7233",
EnableUI: true,
}
cfg, err := MergeWithConfigFile(c, "testdata")
if err != nil {
t.Errorf("cannot create config: %s", err)
return
}
if err = cfg.Validate(); err != nil {
t.Errorf("config not valid: %s", err)
}
if cfg.TLS.ServerName != "local.dev" {
t.Errorf("did not load expected config file")
}
}

0 comments on commit d7f2c05

Please sign in to comment.