Skip to content
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

Merged
merged 8 commits into from
Apr 16, 2024

Conversation

deniseli
Copy link
Contributor

Fixes issue #1174

Also tested manually by:

Open ftl-project.toml and confirm no module "echooo" is referenced
$ ftl config set --inline echooo.HILLBILLY JENKINS
Open ftl-project.toml and confirm this KV pair was added

$ rm ftl-project.toml
$ ftl config set --inline echooo.HILLBILLY JENKINS
Open ftl-project.toml and confirm this KV pair was added

Repeat for s/config/secret/

@deniseli deniseli requested a review from a team as a code owner April 16, 2024 02:17
@deniseli deniseli requested review from worstell and removed request for a team April 16, 2024 02:17
@github-actions github-actions bot changed the title If not already existant, create ftl-project.toml and/or module config or secret feat: If not already existant, create ftl-project.toml and/or module config or secret Apr 16, 2024
@alecthomas alecthomas mentioned this pull request Apr 16, 2024
@@ -92,6 +97,21 @@ func loadFile(path string) (Config, error) {
return config, nil
}

func CreateAndSave(config Config) error {
Copy link
Collaborator

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?

Copy link
Contributor Author

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 {
Copy link
Collaborator

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".

Copy link
Contributor Author

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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea.

@deniseli deniseli merged commit cdca0a0 into main Apr 16, 2024
11 checks passed
@deniseli deniseli deleted the dli/toml-panic-attacks branch April 16, 2024 02:45
@@ -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 {
Copy link
Collaborator

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

Copy link
Contributor Author

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

deniseli added a commit that referenced this pull request Apr 16, 2024
@worstell worstell added the approved Marks an already closed PR as approved label Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Marks an already closed PR as approved
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants