Skip to content

Commit

Permalink
refactor: temporarily disable 1Password secret provider (#4220)
Browse files Browse the repository at this point in the history
This will simplify factoring out `projectconfig`.
  • Loading branch information
alecthomas authored Jan 29, 2025
1 parent 5dc1a72 commit 68625eb
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 28 deletions.
4 changes: 2 additions & 2 deletions cmd/ftl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion go-runtime/ftl/ftltest/ftltest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
5 changes: 2 additions & 3 deletions internal/configuration/providers/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}
Expand Down
40 changes: 22 additions & 18 deletions internal/profiles/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 }
Expand Down Expand Up @@ -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
}
6 changes: 2 additions & 4 deletions internal/profiles/profiles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 68625eb

Please sign in to comment.