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

Initial work preparing for API/gRPC #204

Merged
merged 16 commits into from
Oct 28, 2021
Merged

Conversation

kradalby
Copy link
Collaborator

This PR starts the work on preparing for generating an API with Protobuf for HTTP and gRPC.

The idea is that this can be used for many things, but most importantly:

  • API allowing users to interact
  • CLI can run away from the server machine/not comm via DB
  • Web UI
  • Terraform?

I need help testing that the TLS setup is still working as intended after moving it, @cure could you have a look?

Please note: This PR does not check in generated code, to compile locally, you need run make generate and follow the new steps in the README.

This commit adds protobuf files and tooling surrounding generating APIs
and datatypes.
This commit moves the TLS configuration into a seperate function.

It also wires up the gRPC interface and prepares handing the API
endpoints to the grpc gateway.
@kradalby kradalby requested review from cure and juanfont October 26, 2021 21:49
This does not have to be reviewed, here is some reasoning:

Go (and go mod) is designed for having code available and we need to
check in the generated code to make sure it is "go gettable". If we dont
we give ourselves a headache trying to setup all the ci, tests etc to
install and generate the code before it runs.

Because the code isnt there, the plugins needed to generate the code
fail to install...

I didnt find any good documentation for this, but there is this github
comment:
golang/go#34514 (comment)
This commit removed `golint`, its deprecated:
https://github.com/golang/lint

and golangci-lint has overlapping features.
@@ -18,22 +18,3 @@ jobs:
# below, but it's still much faster in the end than installing
# golangci-lint manually in the `Run lint` step.
- uses: golangci/golangci-lint-action@v2
Copy link
Owner

Choose a reason for hiding this comment

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

Noice, an omnibus PR

@@ -222,7 +272,11 @@ func (h *Headscale) Serve() error {
go h.scheduledDERPMapUpdateWorker(derpMapCancelChannel)
}

s := &http.Server{
// I HATE THIS
Copy link
Owner

Choose a reason for hiding this comment

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

Me too.

// The two following listeners will be served on the same port below gracefully.
m := cmux.New(l)
// Match gRPC requests here
grpcListener := m.MatchWithWriters(cmux.HTTP2MatchHeaderFieldSendSettings("content-type", "application/grpc"))
Copy link
Owner

Choose a reason for hiding this comment

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

Noice. And clever.

@kradalby kradalby merged commit 2c071a8 into juanfont:main Oct 28, 2021
@kradalby kradalby deleted the api-playground branch March 2, 2022 08:56
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.

2 participants