[CLI] Add hf spaces secrets and variables subgroups#4170
Conversation
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
|
Hi @davanstrien , haven't reviewed the code yet but to answer the "design notes" from the PR description:
It would actually make sense to expose secrets keys even if values are hidden. Currently not possible in the API but I'll open a PR in moon-landing for that. Can be addressed in a later PR in huggingface_hub (but let's not forget about it)
I would confirm + -y/--yes on both delete commands. Variable values are not recoverable after deletion so it's the same problem as secrets. Besides, it'll make the CLI consistent between secrets and variables which is good
Then maybe
Good 👍
ok 👍
out of curiosity, what about variables? |
- `hf spaces secrets {set,delete}` wraps add_space_secret / delete_space_secret.
- `hf spaces variables {set,delete,ls}` wraps add/delete_space_variable and get_space_variables.
- Both `set` commands accept multiple `-s`/`-e` flags and `--secrets-file`/`--env-file`
(dotenv) via the existing `parse_env_map` helper — no new parsing code.
- No `secrets ls`: Hub exposes secrets as write-only (no GET endpoint).
- Confirm + `--yes` on `secrets delete` only (lost-value risk); variables delete is
replayable so it skips the prompt, per the #4155 rule.
- `set` is upsert (one API call per key — no bulk endpoint), not replace-collection.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
- Rename `secrets set` / `variables set` to `add` (mirrors add_space_secret/ add_space_variable, signals upsert vs volumes set's replace). - Add confirm + `-y/--yes` to `variables delete` for parity with `secrets delete`. Kept the warning text intentionally asymmetric: secrets says "value cannot be recovered" (true: write-only API), variables uses the shorter volumes-style phrasing (the value is visible via `ls` before deletion). - Remove now-stale per-command `--format` declarations. #4162 made --format global, so these were dead code that was breaking the import after the rebase. Per @Wauplin review at #4170 (comment 4351208819). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
23133f2 to
55fda90
Compare
|
Thanks @Wauplin - applied all three:
re: idempotent delete on variables both have same behaviour:
|
Co-authored-by: Lucain <[email protected]>
Co-authored-by: Lucain <[email protected]>
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
This PR has been shipped as part of the v1.14.0 release. |
Summary
Adds two nested subgroups under
hf spaces, mirroringvolumesper the #4155 thread:hf spaces secrets {add,delete}→add_space_secret/delete_space_secrethf spaces variables {add,delete,ls}→add_space_variable/delete_space_variable/get_space_variablesBoth
addcommands accept multiple-s/-eflags and--secrets-file/--env-file(dotenv), reusing the existingparse_env_maphelper — no new parsing code.Examples (smoke-tested on a live Space)
Design notes
add(notset) — mirrors the underlyingadd_space_secret/add_space_variableAPI verbs and signals upsert semantics explicitly (vsvolumes set, which is replace-all).--yeson bothdeletecommands. Per @Wauplin's review — consistency over micro-optimization.secrets deletewarns "...The value cannot be recovered." because the Hub never exposes secret values.variables deleteuses the shorter volumes-style "...Proceed?" because variable values are visible vialsbefore deletion, so a "cannot be recovered" warning would be misleading.secrets ls— Hub exposes secrets as write-only (no GET endpoint). Will land in a follow-up here once @Wauplin's moon-landing PR exposes secret keys.deleteto match every other destructive command in the CLI.hf spaces volumescommands #4109 (volumes) and [CLI] Add spaces lifecycle commands: pause, restart, sleep #4155 (lifecycle) precedent for thinHfApiwrappers. Parsing is covered by existingparse_env_maptests viajobs run/repos create.delete_space_secretanddelete_space_variableare idempotent server-side — deleting a non-existent key returns success, not 4xx.Note
Medium Risk
Introduces new CLI surface area that mutates Space configuration and handles secret values, so mistakes could overwrite or delete environment settings. Implementation is thin wrappers over existing API calls with confirmation prompts on destructive actions.
Overview
Adds two new
hf spacessubgroups:secrets(supportsadd/delete) andvariables(supportsls/add/delete) to manage a Space’s secret and non-secret environment variables viaHfApi.Both
addcommands accept repeated flags and dotenv-style files (--secrets-file/--env-file) via existingparse_env_map, and bothdeletecommands add confirmation prompts with--yes. Documentation and the generated CLI reference are updated to describe the new commands and the write-only nature of secrets (nosecrets ls).Reviewed by Cursor Bugbot for commit 4a883e8. Bugbot is set up for automated code reviews on this repo. Configure here.