[PR #212] [MERGED] Rework the CLI to use gRPC #1324

Closed
opened 2025-12-29 02:29:41 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/juanfont/headscale/pull/212
Author: @kradalby
Created: 11/4/2021
Status: Merged
Merged: 11/12/2021
Merged by: @kradalby

Base: mainHead: cli-grpc


📝 Commits (10+)

  • a6aa6a4 Add proto rpc interface for cli
  • 5270361 Add generated files from protobuf
  • 4226da3 Add "debug" command
  • 67adea5 Move common integration test commands into common file
  • 787814e Consolidate machine related lookups
  • 77f5f8b Simplify and streamline preauth commands for new cli/rpc/api
  • 95690e6 Simplify and streamline namespace functions for new cli/rpc/api
  • 5526ccc Namespaces are no longer a pointer
  • 94dbaa6 Clean up the return of "pointer list"
  • 9acc3e0 Add a set of ip prefix convert helpers

📊 Changes

51 files changed (+10372 additions, -1699 deletions)

View changed files

📝 acls.go (+35 -26)
📝 acls_test.go (+24 -25)
📝 acls_types.go (+8 -1)
📝 api.go (+2 -2)
📝 app.go (+46 -10)
cli.go (+0 -43)
cmd/headscale/cli/debug.go (+90 -0)
📝 cmd/headscale/cli/namespaces.go (+59 -51)
📝 cmd/headscale/cli/nodes.go (+145 -115)
📝 cmd/headscale/cli/preauthkeys.go (+79 -69)
📝 cmd/headscale/cli/root.go (+2 -1)
📝 cmd/headscale/cli/routes.go (+99 -84)
📝 cmd/headscale/cli/utils.go (+58 -48)
📝 cmd/headscale/cli/version.go (+2 -9)
📝 cmd/headscale/headscale.go (+18 -16)
📝 derp.go (+1 -1)
gen/go/headscale/v1/device.pb.go (+1115 -0)
📝 gen/go/headscale/v1/headscale.pb.go (+232 -749)
📝 gen/go/headscale/v1/headscale.pb.gw.go (+1349 -70)
📝 gen/go/headscale/v1/headscale_grpc.pb.go (+490 -14)

...and 31 more files

📄 Description

First, apologise for the massive PR, I got a bit carried away. (A lot of the code is generated, and is a separate commit)

This PR moves the rest of the user facing CLI (all commands but serve) to use gRPC to communicate with the server.

This means that the PR has "three layers".

  1. It adds protobuf definitions and generate types and rpc based on this
  2. Then it implements the "service" interface provided by gRPC
  3. And then we move all the commands to use the new interface.
  4. Bonus layer: I have added integration tests for the CLI (execute command and read out result) for every command.

In between these steps, there is a lot of code cleanup and streamlining of functions to better fit the new interface. I have also made an attempt on standardising and cleaning up where we had several different ways to get information.

This means that we now have:

  • A CLI that communicates over rpc
    • which means we can run it from everywhere when we add authentication
  • A Web API generated from the same spec, supporting the same as gRPC (currently disabled, due to missing auth)
  • Integration tests for the CLI, should help us find direct and detect underlying issues changes can cause.

What I still would like to tackle (before release):
The cli takes quite inconsistent parameters: database id, machine key, name + namespace. I think we should discuss to standardise on one main approach.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/juanfont/headscale/pull/212 **Author:** [@kradalby](https://github.com/kradalby) **Created:** 11/4/2021 **Status:** ✅ Merged **Merged:** 11/12/2021 **Merged by:** [@kradalby](https://github.com/kradalby) **Base:** `main` ← **Head:** `cli-grpc` --- ### 📝 Commits (10+) - [`a6aa6a4`](https://github.com/juanfont/headscale/commit/a6aa6a4f7b6431abb55f1e82265bc08318405012) Add proto rpc interface for cli - [`5270361`](https://github.com/juanfont/headscale/commit/52703619892e8c4e6a11ddbda6337b492a231986) Add generated files from protobuf - [`4226da3`](https://github.com/juanfont/headscale/commit/4226da3d6b65291ea433272a4b9769ee782fe2b5) Add "debug" command - [`67adea5`](https://github.com/juanfont/headscale/commit/67adea5cab2a7124bd3951d6fb60a369cf99d5ae) Move common integration test commands into common file - [`787814e`](https://github.com/juanfont/headscale/commit/787814ea89b677f28b77435f687b9e357bb1d9e9) Consolidate machine related lookups - [`77f5f8b`](https://github.com/juanfont/headscale/commit/77f5f8bd1cedd9c5bb3cbb20c8918b18ddfbaf08) Simplify and streamline preauth commands for new cli/rpc/api - [`95690e6`](https://github.com/juanfont/headscale/commit/95690e614e42d45dd453f22c73033263b9581ac5) Simplify and streamline namespace functions for new cli/rpc/api - [`5526ccc`](https://github.com/juanfont/headscale/commit/5526ccc6969311e08e30ad5f7ded369c0ef1edf9) Namespaces are no longer a pointer - [`94dbaa6`](https://github.com/juanfont/headscale/commit/94dbaa6822a8225183a54fd8dcb4cdeb424e9df2) Clean up the return of "pointer list" - [`9acc3e0`](https://github.com/juanfont/headscale/commit/9acc3e0e73693ced0ce526b37b3366571d7135fe) Add a set of ip prefix convert helpers ### 📊 Changes **51 files changed** (+10372 additions, -1699 deletions) <details> <summary>View changed files</summary> 📝 `acls.go` (+35 -26) 📝 `acls_test.go` (+24 -25) 📝 `acls_types.go` (+8 -1) 📝 `api.go` (+2 -2) 📝 `app.go` (+46 -10) ➖ `cli.go` (+0 -43) ➕ `cmd/headscale/cli/debug.go` (+90 -0) 📝 `cmd/headscale/cli/namespaces.go` (+59 -51) 📝 `cmd/headscale/cli/nodes.go` (+145 -115) 📝 `cmd/headscale/cli/preauthkeys.go` (+79 -69) 📝 `cmd/headscale/cli/root.go` (+2 -1) 📝 `cmd/headscale/cli/routes.go` (+99 -84) 📝 `cmd/headscale/cli/utils.go` (+58 -48) 📝 `cmd/headscale/cli/version.go` (+2 -9) 📝 `cmd/headscale/headscale.go` (+18 -16) 📝 `derp.go` (+1 -1) ➕ `gen/go/headscale/v1/device.pb.go` (+1115 -0) 📝 `gen/go/headscale/v1/headscale.pb.go` (+232 -749) 📝 `gen/go/headscale/v1/headscale.pb.gw.go` (+1349 -70) 📝 `gen/go/headscale/v1/headscale_grpc.pb.go` (+490 -14) _...and 31 more files_ </details> ### 📄 Description First, apologise for the massive PR, I got a bit carried away. (A lot of the code is generated, and is a separate commit) This PR moves the rest of the user facing CLI (all commands but `serve`) to use gRPC to communicate with the server. This means that the PR has "three layers". 1. It adds `protobuf` definitions and generate types and rpc based on this 2. Then it implements the "service" interface provided by gRPC 3. And then we move all the commands to use the new interface. 4. Bonus layer: I have added integration tests for the CLI (execute command and read out result) for every command. In between these steps, there is a lot of code cleanup and streamlining of functions to better fit the new interface. I have also made an attempt on standardising and cleaning up where we had several different ways to get information. This means that we now have: - A CLI that communicates over rpc - which means we can run it from everywhere when we add authentication - A Web API generated from the same spec, supporting the same as gRPC (currently disabled, due to missing auth) - Integration tests for the CLI, should help us find direct and detect underlying issues changes can cause. What I still would like to tackle (before release): The cli takes quite inconsistent parameters: database id, machine key, name + namespace. I think we should discuss to standardise on one main approach. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-29 02:29:41 +01:00
adam closed this issue 2025-12-29 02:29:41 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/headscale#1324