Skip to content

Config file is being saved on every invocation of the CLI #153

Closed

Description

@Kumm-Kai

Currently, the STACKIT CLI calls the config.InitConfig function on every invocation.

On the very first call of the binary (no .stackit directory exists), it creates the directory and a config file (with default values).
On every following binary call the config file is being read and directly written to disk again.

This is probably only problematic in some small edge cases, like calling stackit multiple times in one command using process substiution (e.g., <(stackit xyz)). In this case the CLI fails because viper.WriteConfigAs is not concurrency-safe.

This can be solved by either:

  1. Only creating the directory & config file if it is actually needed, e.g., when calling stackit config set/unset
  2. Only writing the config file when necessary (e.g., file on disk differs from config in memory)

From my point of view the first solution would be the best one because in my opinion there is no need to create a config file if the user didn't change the defaults.

Activity

  1. joaopalet commented on Apr 2, 2024

    @joaopalet
    Contributor

    Hi @Kumm-Kai,
    Thanks for the suggestion! This was addressed in the PR linked above and will be included in the next release.

  2. Kumm-Kai commented on Apr 5, 2024

    @Kumm-Kai
    MemberAuthor

    Great, thanks for looking into it @joaopalet ❤️

  3. Kumm-Kai commented on Apr 6, 2024

    @Kumm-Kai
    MemberAuthor

    #185 doesn't completely solve this issue. A empty file is still being created on the very first invocation.
    This still results in failures when using process substiution.
    I would propose only creating the file and directory if something should actually be written.

    If you want to I can open a PR for it.

  4. joaopalet commented on Apr 8, 2024

    @joaopalet
    Contributor

    Ah good point, I though the issue was only in viper.WriteConfigAs.

    If you want to raise the PR making the fix I would be happy to review and support, otherwise I will try to do it within the next few days.

  5. joaopalet commented on Apr 18, 2024

    @joaopalet
    Contributor

    This was addressed in #214 and will be included in the next release.

    Thanks @Kumm-Kai for the contribution 💪

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions