-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: If not already existant, create ftl-project.toml
and/or module config or secret
#1273
Conversation
ftl-project.toml
and/or module config or secretftl-project.toml
and/or module config or secret
@@ -92,6 +97,21 @@ func loadFile(path string) (Config, error) { | |||
return config, nil | |||
} | |||
|
|||
func CreateAndSave(config Config) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what this adds over Save()
, which will always recreate the file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh thanks for catching that - I only made this to call GetDefaultConfigPath()
, so I just moved that up to the resolver instead so it could call Save()
directly.
_, err := os.Stat(path) | ||
// Only create a new file if there isn't one already defined at this location | ||
if err != nil && errors.Is(err, os.ErrNotExist) { | ||
if err = os.WriteFile(path, []byte{}, 0600); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per above, I think this function is redundant, but just FTR it's always better to write to a temp file and rename it, rather than overwrite a file directly, because if the write fails halfway through it will result in a corrupted config. With the rename temp file approach, the rename is atomic, so the file is either old or new, never "half written".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, that's very good to know. Thanks!
_, err := os.Stat(path) | ||
if err == nil { | ||
return []string{path} | ||
} | ||
return []string{} | ||
} | ||
|
||
func GetDefaultConfigPath() string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea.
@@ -143,5 +150,8 @@ func (p ProjectConfigResolver[R]) setMapping(config pc.Config, module optional.O | |||
set(&config.Global, mapping) | |||
} | |||
configPaths := pc.ConfigPaths(p.Config) | |||
if len(configPaths) == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is actually unnecessary - pc.ConfigPaths()
will return pc.GetDefaultConfigPath()
if len(p.Config) == 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for catching that! #1276
… logic (#1276) a NOOP followup to PR #1273 (comment)
Fixes issue #1174
Also tested manually by: