Skip to content

REST API for managing trusted publishers#19909

Open
thatch wants to merge 2 commits into
pypi:mainfrom
thatch:thatch/trusted-publisher-api
Open

REST API for managing trusted publishers#19909
thatch wants to merge 2 commits into
pypi:mainfrom
thatch:thatch/trusted-publisher-api

Conversation

@thatch
Copy link
Copy Markdown

@thatch thatch commented Apr 20, 2026

Add POST/GET/DELETE endpoints under /danger-api/projects/{name}/trusted-publishers
authenticated by a project-owner API token (macaroon), supporting all four
providers: GitHub, GitLab, Google, and ActiveState.

Also adds bin/configure-trusted-publisher, a standalone CLI that reads credentials
from ~/.pypirc like twine, auto-detects the provider and repo from the current git
checkout, and lets you select a workflow file interactively.

Closes #14456

The configure-trusted-publisher script should go into its own project (but that should be owned by pypa, not me). Comments welcome on whether this is "danger-api"-worthy. I'll test manually more once the basic idea is validated.

thatch and others added 2 commits April 20, 2026 14:45
Add POST/GET/DELETE endpoints under /danger-api/projects/{name}/trusted-publishers
authenticated by a project-owner API token (macaroon), supporting all four
providers: GitHub, GitLab, Google, and ActiveState.

Also adds bin/configure-trusted-publisher, a standalone CLI that reads credentials
from ~/.pypirc like twine, auto-detects the provider and repo from the current git
checkout, and lets you select a workflow file interactively.

Closes pypi#14456

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…s, hide token in dry-run

- Try "upstream" remote before falling back to "origin"
- Add -n as an alias for --dry-run
- Replace the real token with <YOUR-API-TOKEN> in dry-run curl output;
  add --show-token flag (with a warning in the help text) to opt back in

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@thatch thatch requested a review from a team as a code owner April 20, 2026 17:11
Copy link
Copy Markdown
Contributor

@jaraco jaraco left a comment

Choose a reason for hiding this comment

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

Looks good to me. I'm fairly confident this will have the intended effect of making it possible to bulk enable trusted publishing across any number of repos.

Comment on lines +69 to +88
def _resolve_token(args: argparse.Namespace) -> str:
"""Resolve API token from CLI arg, env var, or .pypirc."""
if args.token:
return args.token

token = os.environ.get("PYPI_TOKEN")
if token:
return token

config = _read_pypirc(getattr(args, "config_file", None), args.repository)
token = config.get("password")
if token:
return token

print(
"Error: No API token found.\n"
"Provide via --token, PYPI_TOKEN env var, or ~/.pypirc [pypi] password field.",
file=sys.stderr,
)
sys.exit(1)
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.

I keep my token safely stored encrypted using keyring (here's how twine does it). Ideally, this script would provide that as an option (or maybe I just pass in --token $(keyring get ...)).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

My hope is that this script either becomes part of twine, or its own project, and we can sort that out there. It's a demo here because without an api client it's kind of hard to show that it works :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow configuring of trusted publisher through an API (or other bulk mechanism)

2 participants