Skip to content

Commit

Permalink
Allow configuring the buf remote (#121)
Browse files Browse the repository at this point in the history
Add an input to the setup action that can control which Buf Schema
Registry to login to, which will be useful for users who have a private
BSR instance. I used `domain` as this is what we refer to in the cli
help:
```
$ buf registry login --help
Log in to the Buf Schema Registry

This prompts for your BSR username and a BSR token and updates your .netrc file with these credentials.
The <domain> argument will default to buf.build if not specified.

Usage:
  buf registry login <domain> [flags]
```
  • Loading branch information
rhbuf committed Apr 11, 2023
1 parent 2bd6541 commit e349d57
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 5 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ You can configure `buf-setup-action` with these parameters:
| `github_token` | The GitHub token to use when making API requests | |
| `buf_user` | The username to use for logging into Buf Schema registry. | |
| `buf_api_token` | The API token to use for logging into Buf Schema registry. | |
| `buf_domain` | The domain of the Buf Schema Registry to login to. | buf.build |

> These parameters are derived from [`action.yml`](./action.yml). <br>
#### Version
Expand Down Expand Up @@ -117,6 +118,12 @@ Note that this only authenticate you with the `buf` cli. You cannot access your
packages in BSR. If you need to access your private remote packages, supply the username and Buf
API Token [as parameters](#buf-username-and-buf-api-token).

#### Buf domain

If you are working with a private BSR then you can set the `buf_domain` input to the domain of
your instance. Please ensure that you are using a token created on your instance (e.g. `https://buf.example.com/settings/user`) and not from the public BSR at `https://buf.build`.


#### Installing `protoc`

In most cases, you _don't_ need to install [`protoc`][protoc] for Buf's GitHub Actions, but some
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ inputs:
buf_api_token:
description: The API token to use for logging into Buf Schema registry.
required: false
buf_domain:
description: The domain of the Buf Schema Registry to login to.
required: false
default: 'buf.build'
runs:
using: "node16"
main: "./dist/main.js"
2 changes: 1 addition & 1 deletion dist/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions dist/main.js.map

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,15 @@ async function runSetup(): Promise<null | Error> {
core.info(`Successfully setup buf version ${version}`);
core.info(cp.execSync(`${binaryPath} --version`).toString());

const bufDomain = core.getInput("buf_domain");
const bufUser = core.getInput("buf_user");
const bufAPIToken = core.getInput("buf_api_token");
if (bufUser !== "" && bufAPIToken !== "") {
core.info(`buf_user and buf_token supplied, logging in...`);
core.info(
cp
.execSync(
`${binaryPath} registry login --username ${bufUser} --token-stdin`,
`${binaryPath} registry login ${bufDomain} --username ${bufUser} --token-stdin`,
{ input: bufAPIToken }
)
.toString()
Expand Down

0 comments on commit e349d57

Please sign in to comment.