feat: add --project-slug flag as alternative to --projectId#1
feat: add --project-slug flag as alternative to --projectId#1yaswanthkumar1995 merged 2 commits intomainfrom
Conversation
Add --project-slug flag to all commands that accept --projectId, allowing users to specify projects by their human-readable slug instead of UUID. The slug is resolved to a project ID via the existing /v1/projects/slug/:slug API endpoint. Commands updated: run, secrets, secrets get/set/delete, secrets generate-example-env, export, folders get/create/delete, service-token create, ssh add-host. Resolves Infisical#141
📝 WalkthroughWalkthroughAdds a new Changes
Sequence DiagramsequenceDiagram
participant User as User/CLI
participant Cmd as Command Handler
participant Util as ResolveProjectSlug()
participant Auth as Auth System
participant API as Infisical API
User->>Cmd: Execute command with --project-slug
Cmd->>Util: ResolveProjectSlug(cmd)
Util->>Util: Read & validate `--project-slug` and `--projectId` exclusivity
Util->>Auth: Get token or establish session
Auth-->>Util: Auth token
Util->>API: CallGetProjectBySlug(slug, token)
API-->>Util: Project { ID, ... }
Util-->>Cmd: return resolved project ID
Cmd->>API: Execute command using resolved ID
API-->>Cmd: Response
Cmd-->>User: Output/result
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/util/helper.go`:
- Around line 330-333: The code currently swallows parsing/auth errors from
cmd.Flags().GetString for "project-slug" (variable projectSlug) and the other
flag (token), returning "", nil; change the checks so that if err != nil you
return the error (e.g., return "", fmt.Errorf("failed to read flag
'project-slug': %w", err)) instead of nil, and only treat an empty string as the
absent-value case if that is intended; update both usages of
cmd.Flags().GetString(...) (the calls that set projectSlug and the other flag
variable) to propagate errors upward rather than ignoring them.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 2141fdca-23d4-4378-bd18-958a1aa2c3f5
📒 Files selected for processing (7)
packages/cmd/export.gopackages/cmd/folder.gopackages/cmd/run.gopackages/cmd/secrets.gopackages/cmd/ssh.gopackages/cmd/tokens.gopackages/util/helper.go
There was a problem hiding this comment.
♻️ Duplicate comments (1)
packages/util/helper.go (1)
338-341:⚠️ Potential issue | 🟡 MinorHandle
projectIdflag read errors at Line 338.
cmd.Flags().GetString("projectId")still discardserr, which can hide misconfigured/missing flags and weaken the mutual-exclusivity check path.🐛 Proposed fix
- projectId, _ := cmd.Flags().GetString("projectId") + projectId, err := cmd.Flags().GetString("projectId") + if err != nil { + return "", fmt.Errorf("unable to read --projectId flag: %w", err) + } if projectId != "" { return "", fmt.Errorf("cannot specify both --projectId and --project-slug; use one or the other") }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/util/helper.go` around lines 338 - 341, The call to cmd.Flags().GetString("projectId") currently ignores its error; change the code that reads projectId (the cmd.Flags().GetString("projectId") call) to capture and handle the returned error (e.g., if err != nil return "", fmt.Errorf("reading --projectId flag: %w", err)) before performing the mutual-exclusion check so misconfigured or missing flags are surfaced instead of silently ignored.
🧹 Nitpick comments (1)
packages/util/helper.go (1)
334-336: Consider trimming whitespace-only slugs before early return/API call.
" "currently bypasses the empty check and reaches the API. Normalizing withstrings.TrimSpacegives cleaner UX.♻️ Suggested hardening
- if projectSlug == "" { + projectSlug = strings.TrimSpace(projectSlug) + if projectSlug == "" { return "", nil }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/util/helper.go` around lines 334 - 336, Trim whitespace from projectSlug before the empty-check and any API call: normalize projectSlug with strings.TrimSpace at the start of the function that contains the projectSlug variable (the branch checking "if projectSlug == \"\" { return \"\", nil }"), then use the trimmed value for the empty check and for subsequent calls to avoid sending whitespace-only slugs to the API.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In `@packages/util/helper.go`:
- Around line 338-341: The call to cmd.Flags().GetString("projectId") currently
ignores its error; change the code that reads projectId (the
cmd.Flags().GetString("projectId") call) to capture and handle the returned
error (e.g., if err != nil return "", fmt.Errorf("reading --projectId flag: %w",
err)) before performing the mutual-exclusion check so misconfigured or missing
flags are surfaced instead of silently ignored.
---
Nitpick comments:
In `@packages/util/helper.go`:
- Around line 334-336: Trim whitespace from projectSlug before the empty-check
and any API call: normalize projectSlug with strings.TrimSpace at the start of
the function that contains the projectSlug variable (the branch checking "if
projectSlug == \"\" { return \"\", nil }"), then use the trimmed value for the
empty check and for subsequent calls to avoid sending whitespace-only slugs to
the API.
Description
Adds
--project-slugas an alternative to--projectIdacross all CLI commands that accept a project identifier. This allows users to reference projects by their human-readable slug instead of UUID, making CLI usage and config files much more readable.The slug is resolved to a project ID via the existing
/v1/projects/slug/:slugAPI endpoint. If both--projectIdand--project-slugare provided, the CLI returns an error to avoid ambiguity.Commands updated:
run,secrets,secrets get,secrets set,secrets delete,secrets generate-example-env,export,folders get,folders create,folders delete,service-token create,ssh add-host.Resolves Infisical#141
Type
Tests
Example usage
infisical run --project-slug my-project -- env infisical secrets --project-slug my-project infisical export --project-slug my-projectMutual exclusivity check (should error)
Summary by CodeRabbit