Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for secret description #1594

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/huggingface_hub/hf_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4975,7 +4975,9 @@ def hide_discussion_comment(
return deserialize_event(resp.json()["updatedComment"]) # type: ignore

@validate_hf_hub_args
def add_space_secret(self, repo_id: str, key: str, value: str, *, token: Optional[str] = None) -> None:
def add_space_secret(
self, repo_id: str, key: str, value: str, description: Optional[str] = str(), *, token: Optional[str] = None
martinbrose marked this conversation as resolved.
Show resolved Hide resolved
) -> None:
"""Adds or updates a secret in a Space.

Secrets allow to set secret keys or tokens to a Space without hardcoding them.
Expand All @@ -4988,13 +4990,15 @@ def add_space_secret(self, repo_id: str, key: str, value: str, *, token: Optiona
Secret key. Example: `"GITHUB_API_KEY"`
value (`str`):
Secret value. Example: `"your_github_api_key"`.
description (`str`, *optional*):
Secret description. Example: `"Github API key to access the Github API"`.
token (`str`, *optional*):
Hugging Face token. Will default to the locally saved token if not provided.
"""
r = get_session().post(
f"{self.endpoint}/api/spaces/{repo_id}/secrets",
headers=self._build_hf_headers(token=token),
json={"key": key, "value": value},
json={"key": key, "value": value, "description": description},
martinbrose marked this conversation as resolved.
Show resolved Hide resolved
)
hf_raise_for_status(r)

Expand Down
7 changes: 7 additions & 0 deletions tests/test_hf_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2399,9 +2399,16 @@ def test_manage_secrets(self) -> None:
self.api.add_space_secret(self.repo_id, "token", "hf_api_123456")
self.api.add_space_secret(self.repo_id, "gh_api_key", "******")

# Add secret with optional description
self.api.add_space_secret(self.repo_id, "bar", "123", description="This is a secret")

# Update secret
self.api.add_space_secret(self.repo_id, "foo", "456")

# Update secret with optional description
self.api.add_space_secret(self.repo_id, "foo", "789", description="This is a secret")
self.api.add_space_secret(self.repo_id, "bar", "456", description="This is another secret")

# Delete secret
self.api.delete_space_secret(self.repo_id, "gh_api_key")

Expand Down