Skip to content

Commit af662d3

Browse files
Add ports command for instances and nodes (#441)
* Add ports command for instances and nodes * 📝 Add docstrings to `agent/list-instance-ports` Docstrings generation was requested by @callen-bot. The following files were modified: * `pkg/cmd/cmd.go` * `pkg/cmd/ports/ports.go` * `pkg/cmd/util/externalnode.go` * `pkg/cmd/util/util.go` These files were ignored: * `pkg/cmd/ports/ports_test.go` * `pkg/cmd/util/externalnode_test.go` These file types are not supported: * `.agents/skills/brev-cli/SKILL.md` * `.agents/skills/brev-cli/reference/commands.md` * Address ports review feedback * Label SSH ports as network ports * Refine ports list command * Show ports list in command help * Avoid guessing missing destination ports --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent 5fc735b commit af662d3

8 files changed

Lines changed: 1050 additions & 25 deletions

File tree

.agents/skills/brev-cli/SKILL.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ brev copy my-instance:/remote/file ./local-path/
170170

171171
# Port forward
172172
brev port-forward my-instance -p 8080:8080
173+
174+
# List Brev-managed HTTP and network ports for an instance or external node
175+
brev ports ls my-instance
176+
brev ports ls my-node --json
173177
```
174178

175179
### Listing Instances and Nodes

.agents/skills/brev-cli/reference/commands.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,51 @@ brev port-forward my-instance -p 8080:8080
466466
brev port-forward my-instance -p 3000:3000
467467
```
468468

469+
### brev ports ls
470+
List Brev-managed HTTP applications and raw network port mappings for a
471+
managed instance or registered compute node.
472+
473+
```bash
474+
brev ports ls <instance-or-node> [flags]
475+
```
476+
477+
**Flags:**
478+
479+
| Flag | Description |
480+
|------|-------------|
481+
| `--json` | Output the port mappings as JSON |
482+
483+
The table output includes endpoint, IP restrictions, public port, destination
484+
port, and protocol. HTTP applications also include their authorization policy.
485+
486+
For managed instances, this command reads the Brev-managed network
487+
configuration. It does not synthesize the legacy secure-link or firewall rows
488+
shown by the Brev console, because those rows do not have real port IDs and
489+
cannot be used by port-management automation. If the instance is still
490+
provisioning or uses legacy network access, the command returns an error
491+
directing the user to the console.
492+
493+
The JSON output is an array with the following stable fields:
494+
495+
| Field | Meaning |
496+
|------|---------|
497+
| `port_id` | Unique port mapping ID used by automation |
498+
| `endpoint` | Public URL or `host:port` endpoint |
499+
| `public_port` | Externally addressable port |
500+
| `destination_port` | Port listening on the target machine |
501+
| `protocol` | `HTTP`, `HTTPS`, `SSH`, `TCP`, `UDP`, or `UNKNOWN` |
502+
| `allowed_sources` | Allowed IP addresses or CIDR blocks |
503+
| `authorized_emails` | Identities authorized for an HTTP application |
504+
| `allow_public_unauthenticated` | Whether an HTTP application is public |
505+
| `type` | `system`, `user`, `unspecified`, or `unknown` |
506+
507+
**Examples:**
508+
```bash
509+
brev ports ls my-instance
510+
brev ports ls my-node
511+
brev ports ls my-instance --json
512+
```
513+
469514
## Organization Commands
470515

471516
### brev org ls

pkg/cmd/cmd.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
"github.com/brevdev/brev-cli/pkg/cmd/open"
3636
"github.com/brevdev/brev-cli/pkg/cmd/org"
3737
"github.com/brevdev/brev-cli/pkg/cmd/portforward"
38+
"github.com/brevdev/brev-cli/pkg/cmd/ports"
3839
"github.com/brevdev/brev-cli/pkg/cmd/profile"
3940
"github.com/brevdev/brev-cli/pkg/cmd/proxy"
4041
"github.com/brevdev/brev-cli/pkg/cmd/redeem"
@@ -276,6 +277,7 @@ func createCmdTree(cmd *cobra.Command, t *terminal.Terminal, loginCmdStore *stor
276277
cmd.AddCommand(invite.NewCmdInvite(t, loginCmdStore, noLoginCmdStore))
277278
cmd.AddCommand(redeem.NewCmdRedeem(t, loginCmdStore, noLoginCmdStore))
278279
cmd.AddCommand(portforward.NewCmdPortForwardSSH(loginCmdStore, t))
280+
cmd.AddCommand(ports.NewCmdPorts(loginCmdStore))
279281
cmd.AddCommand(login.NewCmdLogin(t, noLoginCmdStore, loginAuth))
280282
cmd.AddCommand(logout.NewCmdLogout(loginAuth, noLoginCmdStore))
281283
cmd.AddCommand(tasks.NewCmdTasks(t, noLoginCmdStore))

0 commit comments

Comments
 (0)