Expand config file to support env + tags | Ensure uniformity of loading config accross commands#56
Conversation
| loggedInUserDetails = EstablishUserLoginSession() | ||
| } | ||
|
|
||
| if params.WorkspaceId == "" { |
There was a problem hiding this comment.
Get all folders doesn't need to do these checks.
All commands use GetWorkspaceConfigFromCommandOrFile and perform this check in advance.
| 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]") | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
Checks moved to GetWorkspaceConfigFromCommandOrFile
Greptile OverviewGreptile SummaryThis PR successfully expands the Key Changes
Config Precedence LogicThe implementation correctly handles precedence: command flags > config file > defaults
ImpactThis is a non-breaking enhancement that improves user experience by reducing repetitive flag usage and making project configuration more maintainable. Confidence Score: 4/5
Important Files ChangedFile Analysis
Sequence DiagramsequenceDiagram
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
|
|
@greptileai please re-review |
|
@greptileai please re-review |
There was a problem hiding this comment.
Additional Comments (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
|
@greptileai please re-review |
| 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"` | ||
| } |
There was a problem hiding this comment.
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)
Description 📣
Fixes: #55
Expanding config file
workspaceIdandenv.tagsandpath, and these can be prone to typos if I'm changing them every time, having them in the config helps.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
GetWorkspaceConfigFromCommandOrFileGet(String|Boolean|Int|StringSlice)ArgumentGetStringArgument(cmd, "some-flag", "Unable to parse flag --some-flag")Type ✨
Tests 🛠️
Added new unit tests testing functionality around
GetWorkspaceConfigFromCommandOrFilego test -v ./packages/util/...Manually run tests against the build:

With tags vs without tags in file
