Skip to content

Conversation

@Billcountry
Copy link

@Billcountry Billcountry commented Nov 10, 2025

Description 📣

Fixes: #55

Expanding config file

  • The config file used to support only the workspaceId and env.
  • However, for most cases, as a user I'm also working with tags and path, and these can be prone to typos if I'm changing them every time, having them in the config helps.
  • I understand not every command needs these values,part of the refactor below ensures that these values are only read when the command defines them.

Code Refactor + Simplification

I didn't need to do this but I found it necessary to safely introduce the changes above. Here are the motivations around the refactor

  • GetWorkspaceConfigFromCommandOrFile

    • I've introduced this file as a simple way of loading the config, it's going to take into account the flags provided in the command, and the contents of the config file, then give you a unified config.
    • This change was necessary because the logic to check if a project ID is provided or if it's in the config was fragmented all over the code but doing the same thing. In some cases even loading the config file more than once in the same function.
    • This unification ensures that every function needing some or the full config that can be in a file can easily get it.
  • Get(String|Boolean|Int|StringSlice)Argument

    • Being a commandline application, a lot of places have the code
value, err := cmd.Flags().GetString("some-flag")
if err != nil {
  HandleError(err, "A message")
}
  • These 4 lines added a lot of broiler plate that can now be simplified to
    • GetStringArgument(cmd, "some-flag", "Unable to parse flag --some-flag")

Type ✨

  • Bug fix
  • New feature
  • Improvement
  • Breaking change
  • Documentation

Tests 🛠️

Added new unit tests testing functionality around GetWorkspaceConfigFromCommandOrFile

go test -v ./packages/util/...

Manually run tests against the build:
image

With tags vs without tags in file
image


loggedInUserDetails = EstablishUserLoginSession()
}

if params.WorkspaceId == "" {
Copy link
Author

Choose a reason for hiding this comment

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

Get all folders doesn't need to do these checks.

All commands use GetWorkspaceConfigFromCommandOrFile and perform this check in advance.

Comment on lines -199 to -412
func RequireLocalWorkspaceFile() {
workspaceFilePath, _ := FindWorkspaceConfigFile()
if workspaceFilePath == "" {
PrintErrorMessageAndExit("It looks you have not yet connected this project to Infisical", "To do so, run [infisical init] then run your command again")
}

workspaceFile, err := GetWorkSpaceFromFile()
if err != nil {
HandleError(err, "Unable to read your project configuration, please try initializing this project again.", "Run [infisical init]")
}

if workspaceFile.WorkspaceId == "" {
PrintErrorMessageAndExit("Your project id is missing in your local config file. Please add it or run again [infisical init]")
}
}

func ValidateWorkspaceFile(projectConfigFilePath string) {
workspaceFilePath, err := GetWorkSpaceFromFilePath(projectConfigFilePath)
if err != nil {
PrintErrorMessageAndExit(fmt.Sprintf("error reading your project config %v", err))
}

if workspaceFilePath.WorkspaceId == "" {
PrintErrorMessageAndExit("Your project id is missing in your local config file. Please add it or run again [infisical init]")
}
}

Copy link
Author

Choose a reason for hiding this comment

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

Checks moved to GetWorkspaceConfigFromCommandOrFile

@Billcountry Billcountry marked this pull request as ready for review November 11, 2025 01:42
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Nov 11, 2025

Greptile Overview

Greptile Summary

This PR successfully expands the .infisical.json config file to support tags and path fields, and introduces a unified configuration loading mechanism that ensures consistency across all CLI commands.

Key Changes

  • Expanded config file schema to include tags (array) and path (string) alongside existing workspaceId and environment settings
  • Introduced GetWorkspaceConfigFromCommandOrFile() which consolidates fragmented config loading logic that was duplicated across commands
  • Added helper functions (GetStringArgument, GetBooleanArgument, etc.) to reduce boilerplate flag parsing code
  • Refactored all commands to use the unified config loading approach, eliminating ~200+ lines of repetitive code
  • Added comprehensive unit tests covering various config precedence scenarios

Config Precedence Logic

The implementation correctly handles precedence: command flags > config file > defaults

  • For path: Uses flag if changed OR if file value is empty (defaults to "/")
  • For tags: Uses flag if changed, otherwise joins array from file into comma-separated string
  • For env: Uses flag if changed, otherwise checks git branch mapping, falls back to defaultEnvironment
  • For projectId: Uses flag if changed, otherwise uses file value

Impact

This is a non-breaking enhancement that improves user experience by reducing repetitive flag usage and making project configuration more maintainable.

Confidence Score: 4/5

  • This PR is safe to merge with minimal risk - well-tested refactoring that improves code quality
  • Score of 4 reflects solid implementation with comprehensive tests and thoughtful design. Deducted 1 point only for missing documentation about the new config file fields - users need to know about this feature. The refactoring correctly handles config precedence, includes unit tests that verify all scenarios, and the changes are backward compatible (empty config files still work with defaults).
  • Verify that user-facing documentation is updated to describe the new tags and path fields in .infisical.json - particularly packages/models/cli.go where the schema is defined

Important Files Changed

File Analysis

Filename Score Overview
packages/util/config.go 4/5 Added GetWorkspaceConfigFromCommandOrFile function to unify config loading from flags and file; properly handles precedence (flag > file > defaults) for all config values
packages/util/helper.go 5/5 Added helper functions (GetStringArgument, GetBooleanArgument, GetIntArgument, GetStringSliceArgument) to reduce boilerplate for flag parsing
packages/models/cli.go 5/5 Extended WorkspaceConfigFile to include TagSlugs and SecretsPath fields; WorkspaceConfig updated to match
packages/util/secrets.go 4/5 Added GetTokenAndProjectConfigFromCommand helper; removed unused projectConfigFilePath parameter from GetAllEnvironmentVariables
packages/cmd/dynamic_secrets.go 5/5 Refactored to use GetTokenAndProjectConfigFromCommand and new helper functions, reducing ~150 lines of repetitive flag parsing code

Sequence Diagram

sequenceDiagram
    participant User
    participant Command as CLI Command
    participant GetTokenAndProjectConfig as GetTokenAndProjectConfigFromCommand()
    participant GetWorkspaceConfig as GetWorkspaceConfigFromCommandOrFile()
    participant ConfigFile as .infisical.json
    participant Flags as Command Flags

    User->>Command: Execute CLI command (e.g., infisical run)
    Command->>GetTokenAndProjectConfig: Request token & config
    GetTokenAndProjectConfig->>Flags: GetInfisicalToken()
    Flags-->>GetTokenAndProjectConfig: token details
    GetTokenAndProjectConfig->>GetWorkspaceConfig: Load workspace config
    
    GetWorkspaceConfig->>Flags: Check --project-config-dir flag
    alt Custom config dir specified
        GetWorkspaceConfig->>ConfigFile: Read from custom path
    else Default behavior
        GetWorkspaceConfig->>ConfigFile: Search in current dir & parents
    end
    ConfigFile-->>GetWorkspaceConfig: workspaceId, tags, path, env
    
    GetWorkspaceConfig->>Flags: Check if --projectId flag changed
    alt Flag was changed
        Flags-->>GetWorkspaceConfig: Use flag value
    else Flag not changed
        GetWorkspaceConfig->>GetWorkspaceConfig: Use config file value
    end
    
    GetWorkspaceConfig->>Flags: Check if --tags flag changed
    alt Flag was changed
        Flags-->>GetWorkspaceConfig: Use flag value
    else Flag not changed
        GetWorkspaceConfig->>GetWorkspaceConfig: Join tags from file
    end
    
    GetWorkspaceConfig->>Flags: Check if --path flag changed
    alt Flag changed OR file path empty
        Flags-->>GetWorkspaceConfig: Use flag value (default "/")
    else Flag not changed AND file has path
        GetWorkspaceConfig->>GetWorkspaceConfig: Use file path
    end
    
    GetWorkspaceConfig->>Flags: Check if --env flag changed
    alt Flag changed OR no git branch mapping
        Flags-->>GetWorkspaceConfig: Use flag value
    else File has git branch mapping
        GetWorkspaceConfig->>GetWorkspaceConfig: Use mapped environment
    end
    
    GetWorkspaceConfig-->>GetTokenAndProjectConfig: Unified WorkspaceConfig
    GetTokenAndProjectConfig-->>Command: token + projectConfig
    Command->>Command: Execute with merged config
Loading
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

12 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@Billcountry
Copy link
Author

@greptileai please re-review

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

12 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@Billcountry
Copy link
Author

@greptileai please re-review

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Additional Comments (1)

  1. packages/cmd/dynamic_secrets.go, line 352-360 (link)

    style: inconsistent with the refactoring pattern used elsewhere in this function. All other functions in this file use GetStringArgument() utility. Should be:

14 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

@Billcountry
Copy link
Author

@greptileai please re-review

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

14 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment on lines 96 to 102
type WorkspaceConfigFile struct {
WorkspaceId string `json:"workspaceId"`
TagSlugs []string `json:"tags"`
SecretsPath string `json:"path"`
DefaultEnvironment string `json:"defaultEnvironment"`
GitBranchToEnvironmentMapping map[string]string `json:"gitBranchToEnvironmentMapping"`
}
Copy link
Contributor

Choose a reason for hiding this comment

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

style: check that documentation is updated to inform users about the new tags and path fields in .infisical.json - how will customers discover this feature?

Context Used: Context from dashboard - When naming sections in documentation, use clear and descriptive titles that reflect the functionali... (source)

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

Labels

None yet

1 participant