Skip to content

feat: add user secrets file parser and shared validator (PLAT-240)#26723

Merged
dylanhuff-at-coder merged 6 commits into
mainfrom
dylan/plat-240-secrets-import-codersdk
Jul 22, 2026
Merged

feat: add user secrets file parser and shared validator (PLAT-240)#26723
dylanhuff-at-coder merged 6 commits into
mainfrom
dylan/plat-240-secrets-import-codersdk

Conversation

@dylanhuff-at-coder

@dylanhuff-at-coder dylanhuff-at-coder commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Part of the PLAT-240 bulk secret import stack: this PR adds the codersdk parser and shared create-secret validator used by the follow-up batch endpoint and UI PRs.

ParseSecretsFile parses .env, .json, and .yaml files into CreateUserSecretRequest entries in source order, with size, count, duplicate-key, structure, and malformed-input checks. ValidateCreateUserSecretRequest now backs the single-create handler too, so create validation has one SDK-level implementation.

Part of https://linear.app/codercom/issue/PLAT-240

This PR was generated by Coder Agents on behalf of @dylanhuff-at-coder.

Add codersdk.ParseSecretsFile to parse .env/.json/.yaml secret files
into CreateUserSecretRequests, plus codersdk.ValidateCreateUserSecretRequest
as the shared per-entry validator. Both are transport-agnostic so the
import endpoint and a future CLI can reuse them unchanged.
@linear-code

linear-code Bot commented Jun 25, 2026

Copy link
Copy Markdown

PLAT-240

Copy link
Copy Markdown
Contributor Author

Add test entries for \r escape, unknown escape preservation,
and export=foo key edge case in TestParseSecretsFileEnv.
@dylanhuff-at-coder
dylanhuff-at-coder marked this pull request as ready for review July 1, 2026 15:56
Comment thread codersdk/usersecretsimport_test.go
Comment thread codersdk/usersecretsimport.go
Comment thread codersdk/usersecretsimport.go
@github-actions github-actions Bot added the stale This issue is like stale bread. label Jul 10, 2026
@github-actions github-actions Bot closed this Jul 14, 2026
@github-actions github-actions Bot removed the stale This issue is like stale bread. label Jul 15, 2026
@dylanhuff-at-coder
dylanhuff-at-coder requested a review from Emyrk July 16, 2026 15:35
@dylanhuff-at-coder

Copy link
Copy Markdown
Contributor Author

There is the failing doc check, but a later PR in this stack is for the UI, I'll add docs there

Comment thread codersdk/usersecretsimport.go

@BobbyHo BobbyHo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Syntax-wise, the changes look good to me. I just left one minor comment. I don’t have the full context on this feature yet, so I’ll leave the final approval to reviewers who are more familiar with it.

@dylanhuff-at-coder

Copy link
Copy Markdown
Contributor Author

Thanks for the review @BobbyHo

@Emyrk Emyrk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Comments inline — one doc request on the env parser, two nits. Nothing blocking; the token-streaming JSON parse for duplicate-key detection and the YAML type strictness are well done.

Coder Agents on behalf of @Emyrk.

Comment thread codersdk/usersecretsimport_test.go
Comment thread codersdk/usersecretvalidation.go
// ParseSecretsFile parses a secrets file into CreateUserSecretRequests.
// It checks structure and duplicate keys; per-entry validation is left to
// ValidateCreateUserSecretRequest.
func ParseSecretsFile(format SecretsFileFormat, content string) ([]CreateUserSecretRequest, error) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Document the supported dotenv subset here: no $VAR expansion, no inline-comment stripping, no multi-line quoted values. Good strict choices for secrets — but worth stating why this is hand-rolled instead of joho/godotenv / hashicorp/go-envparse (dependency in codersdk, expansion footgun), so nobody "fixes" this into godotenv semantics later.

Coder Agents on behalf of @Emyrk.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd prefer us using a lib to parse env files, but I'll defer that to you if you think we can maintain this easily.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah I've been somewhat punting on docs to the later PRs once the functionality is surfaced. I'll make sure this gets addressed in the second or third PR in this stack 👍

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Re importing was custom rolling, I believe the current implementation is correct: every Go dotenv lib either expands $VAR or strips inline #, both of which silently corrupt secret values, and they return maps so we lose order, line numbers, and dup detection. Wrapping one to undo that costs about as much code as the parser, plus a new dep in codersdk. Documented the subset and reasoning in the code so nobody "fixes" it into godotenv semantics later. Happy to revisit if you disagree 👍

// ParseSecretsFile parses a secrets file into CreateUserSecretRequests.
// It checks structure and duplicate keys; per-entry validation is left to
// ValidateCreateUserSecretRequest.
func ParseSecretsFile(format SecretsFileFormat, content string) ([]CreateUserSecretRequest, error) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd prefer us using a lib to parse env files, but I'll defer that to you if you think we can maintain this easily.

@dylanhuff-at-coder
dylanhuff-at-coder merged commit 99e740b into main Jul 22, 2026
29 of 30 checks passed
@dylanhuff-at-coder
dylanhuff-at-coder deleted the dylan/plat-240-secrets-import-codersdk branch July 22, 2026 13:23
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 22, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants