From 68625ebfcd1d0777841bff1cac86252feb862320 Mon Sep 17 00:00:00 2001 From: Alec Thomas Date: Thu, 30 Jan 2025 08:13:47 +1100 Subject: [PATCH] refactor: temporarily disable 1Password secret provider (#4220) This will simplify factoring out `projectconfig`. --- cmd/ftl/main.go | 4 +- go-runtime/ftl/ftltest/ftltest.go | 2 +- internal/configuration/providers/registry.go | 5 +-- internal/profiles/profiles.go | 40 +++++++++++--------- internal/profiles/profiles_test.go | 6 +-- 5 files changed, 29 insertions(+), 28 deletions(-) diff --git a/cmd/ftl/main.go b/cmd/ftl/main.go index 69e2f1b6d1..b3473456e5 100644 --- a/cmd/ftl/main.go +++ b/cmd/ftl/main.go @@ -278,8 +278,8 @@ func makeBindContext(logger *log.Logger, cancel context.CancelCauseFunc) termina }) kctx.FatalIfErrorf(err) - err = kctx.BindToProvider(func(cli *CLI, projectConfig projectconfig.Config) (*providers.Registry[configuration.Secrets], error) { - return providers.NewDefaultSecretsRegistry(projectConfig, cli.Vault), nil + err = kctx.BindToProvider(func() (*providers.Registry[configuration.Secrets], error) { + return providers.NewDefaultSecretsRegistry(), nil }) kctx.FatalIfErrorf(err) diff --git a/go-runtime/ftl/ftltest/ftltest.go b/go-runtime/ftl/ftltest/ftltest.go index 7fa60a2b3a..ede9664a64 100644 --- a/go-runtime/ftl/ftltest/ftltest.go +++ b/go-runtime/ftl/ftltest/ftltest.go @@ -146,7 +146,7 @@ func WithProjectFile(path string) Option { } } - sm, err := cf.NewDefaultSecretsManagerFromConfig(ctx, providers.NewDefaultSecretsRegistry(projectConfig, ""), projectConfig) + sm, err := cf.NewDefaultSecretsManagerFromConfig(ctx, providers.NewDefaultSecretsRegistry(), projectConfig) if err != nil { return fmt.Errorf("could not set up secrets: %w", err) } diff --git a/internal/configuration/providers/registry.go b/internal/configuration/providers/registry.go index 0c833f943d..67113d051b 100644 --- a/internal/configuration/providers/registry.go +++ b/internal/configuration/providers/registry.go @@ -7,7 +7,6 @@ import ( "slices" "github.com/block/ftl/internal/configuration" - "github.com/block/ftl/internal/projectconfig" ) type Factory[R configuration.Role] func(ctx context.Context) (configuration.Provider[R], error) @@ -21,11 +20,11 @@ func NewDefaultConfigRegistry() *Registry[configuration.Configuration] { } // NewDefaultSecretsRegistry creates a new registry with the default secrets providers. -func NewDefaultSecretsRegistry(config projectconfig.Config, onePasswordVault string) *Registry[configuration.Secrets] { +func NewDefaultSecretsRegistry() *Registry[configuration.Secrets] { registry := NewRegistry[configuration.Secrets]() registry.Register(NewEnvarFactory[configuration.Secrets]()) registry.Register(NewInlineFactory[configuration.Secrets]()) - registry.Register(NewOnePasswordFactory(onePasswordVault, config.Name)) + // registry.Register(NewOnePasswordFactory(onePasswordVault, config.Name)) registry.Register(NewKeychainFactory()) return registry } diff --git a/internal/profiles/profiles.go b/internal/profiles/profiles.go index b1586e183a..5b4af753b6 100644 --- a/internal/profiles/profiles.go +++ b/internal/profiles/profiles.go @@ -9,7 +9,6 @@ import ( "github.com/alecthomas/types/either" - "github.com/block/ftl/common/reflect" "github.com/block/ftl/common/slices" "github.com/block/ftl/internal/configuration" "github.com/block/ftl/internal/configuration/manager" @@ -18,25 +17,32 @@ import ( "github.com/block/ftl/internal/profiles/internal" ) -type ProjectConfig internal.Project +// ProjectConfig is the static project-wide configuration shared by all profiles. +// +// It mirrors the internal.Project struct. +type ProjectConfig struct { + Realm string `json:"realm"` + FTLMinVersion string `json:"ftl-min-version,omitempty"` + ModuleRoots []string `json:"module-roots,omitempty"` + NoGit bool `json:"no-git,omitempty"` + DefaultProfile string `json:"default-profile,omitempty"` -type Config struct { - Name string - Endpoint *url.URL + Root string `json:"-"` } type Profile struct { - shared ProjectConfig - config Config - sm *manager.Manager[configuration.Secrets] - cm *manager.Manager[configuration.Configuration] + shared ProjectConfig + name string + endpoint *url.URL + sm *manager.Manager[configuration.Secrets] + cm *manager.Manager[configuration.Configuration] } // ProjectConfig is the static project-wide configuration shared by all profiles. func (p *Profile) ProjectConfig() ProjectConfig { return p.shared } -// Config is the static configuration for a Profile. -func (p *Profile) Config() Config { return reflect.DeepCopy(p.config) } +func (p *Profile) Name() string { return p.name } +func (p *Profile) Endpoint() *url.URL { return p.endpoint } // SecretsManager returns the secrets manager for this profile. func (p *Profile) SecretsManager() *manager.Manager[configuration.Secrets] { return p.sm } @@ -266,12 +272,10 @@ func (p *Project) Load(ctx context.Context, profile string) (Profile, error) { return Profile{}, fmt.Errorf("%s: unknown profile type: %q", profile, prof.Type) } return Profile{ - shared: ProjectConfig(p.project), - config: Config{ - Name: prof.Name, - Endpoint: profileEndpoint, - }, - sm: sm, - cm: cm, + shared: ProjectConfig(p.project), + name: prof.Name, + endpoint: profileEndpoint, + sm: sm, + cm: cm, }, nil } diff --git a/internal/profiles/profiles_test.go b/internal/profiles/profiles_test.go index 9c8c6aa7e9..ce38dfcb1e 100644 --- a/internal/profiles/profiles_test.go +++ b/internal/profiles/profiles_test.go @@ -40,10 +40,8 @@ func TestProfile(t *testing.T) { profile, err := project.Load(ctx, "local") assert.NoError(t, err) - assert.Equal(t, profiles.Config{ - Name: "local", - Endpoint: must.Get(url.Parse("http://localhost:8892")), - }, profile.Config()) + assert.Equal(t, "local", profile.Name()) + assert.Equal(t, must.Get(url.Parse("http://localhost:8892")), profile.Endpoint()) assert.Equal(t, profiles.ProjectConfig{ Root: root,