mirror of
https://github.com/juanfont/headscale.git
synced 2024-12-20 19:09:07 +01:00
Create an initial gRPC service
This commit adds protobuf files and tooling surrounding generating APIs and datatypes.
This commit is contained in:
parent
e8277595f5
commit
b096a2e7e5
3
.gitignore
vendored
3
.gitignore
vendored
@ -25,3 +25,6 @@ config.yaml
|
||||
.idea
|
||||
|
||||
test_output/
|
||||
|
||||
# Protobuf generated code
|
||||
gen/
|
||||
|
21
buf.gen.yaml
Normal file
21
buf.gen.yaml
Normal file
@ -0,0 +1,21 @@
|
||||
version: v1
|
||||
plugins:
|
||||
- name: go
|
||||
out: gen/go
|
||||
opt:
|
||||
- paths=source_relative
|
||||
- name: go-grpc
|
||||
out: gen/go
|
||||
opt:
|
||||
- paths=source_relative
|
||||
- name: grpc-gateway
|
||||
out: gen/go
|
||||
opt:
|
||||
- paths=source_relative
|
||||
- generate_unbound_methods=true
|
||||
# - name: gorm
|
||||
# out: gen/go
|
||||
# opt:
|
||||
# - paths=source_relative,enums=string,gateway=true
|
||||
- name: openapiv2
|
||||
out: gen/openapiv2
|
24
proto/buf.lock
Normal file
24
proto/buf.lock
Normal file
@ -0,0 +1,24 @@
|
||||
# Generated by buf. DO NOT EDIT.
|
||||
version: v1
|
||||
deps:
|
||||
- remote: buf.build
|
||||
owner: googleapis
|
||||
repository: googleapis
|
||||
branch: main
|
||||
commit: cd101b0abb7b4404a0b1ecc1afd4ce10
|
||||
digest: b1-H4GHwHVHcJBbVPg-Cdmnx812reFCDQws_QoQ0W2hYQA=
|
||||
create_time: 2021-10-23T15:04:06.087748Z
|
||||
- remote: buf.build
|
||||
owner: grpc-ecosystem
|
||||
repository: grpc-gateway
|
||||
branch: main
|
||||
commit: ff83506eb9cc4cf8972f49ce87e6ed3e
|
||||
digest: b1-iLPHgLaoeWWinMiXXqPnxqE4BThtY3eSbswVGh9GOGI=
|
||||
create_time: 2021-10-23T16:26:52.283938Z
|
||||
- remote: buf.build
|
||||
owner: ufoundit-dev
|
||||
repository: protoc-gen-gorm
|
||||
branch: main
|
||||
commit: e2ecbaa0d37843298104bd29fd866df8
|
||||
digest: b1-SV9yKH_8P-IKTOlHZxP-bb0ALANYeEqH_mtPA0EWfLc=
|
||||
create_time: 2021-10-08T06:03:05.64876Z
|
12
proto/buf.yaml
Normal file
12
proto/buf.yaml
Normal file
@ -0,0 +1,12 @@
|
||||
version: v1
|
||||
lint:
|
||||
use:
|
||||
- DEFAULT
|
||||
breaking:
|
||||
use:
|
||||
- FILE
|
||||
|
||||
deps:
|
||||
- buf.build/googleapis/googleapis
|
||||
- buf.build/grpc-ecosystem/grpc-gateway
|
||||
- buf.build/ufoundit-dev/protoc-gen-gorm
|
71
proto/v1/headscale.proto
Normal file
71
proto/v1/headscale.proto
Normal file
@ -0,0 +1,71 @@
|
||||
syntax = "proto3";
|
||||
package headscale.v1;
|
||||
option go_package = "github.com/juanfont/headscale/gen/go/v1";
|
||||
|
||||
import "google/protobuf/timestamp.proto";
|
||||
import "google/api/annotations.proto";
|
||||
import "options/gorm.proto";
|
||||
|
||||
enum RegisterMethod {
|
||||
AUTH_KEY = 0;
|
||||
CLI = 1;
|
||||
OIDC = 2;
|
||||
}
|
||||
|
||||
message Namespace {
|
||||
string Name = 1;
|
||||
}
|
||||
|
||||
message PreAuthKey {
|
||||
uint64 ID = 1;
|
||||
string Key = 2;
|
||||
uint32 NamespaceID = 3;
|
||||
Namespace Namespace = 4;
|
||||
bool Reusable = 5;
|
||||
bool Ephemeral = 6;
|
||||
bool Used = 7;
|
||||
|
||||
google.protobuf.Timestamp CreatedAt = 8;
|
||||
google.protobuf.Timestamp Expiration = 9;
|
||||
}
|
||||
|
||||
message GetMachineRequest {
|
||||
uint64 machine_id = 1;
|
||||
}
|
||||
|
||||
message Machine {
|
||||
option(gorm.opts).ormable = true;
|
||||
uint64 ID = 1;
|
||||
string MachineKey = 2;
|
||||
string NodeKey = 3;
|
||||
string DiscoKey = 4;
|
||||
string IPAddress = 5;
|
||||
string Name = 6;
|
||||
uint32 NamespaceID = 7;
|
||||
|
||||
bool Registered = 8;
|
||||
RegisterMethod RegisterMethod = 9;
|
||||
uint32 AuthKeyID = 10;
|
||||
PreAuthKey AuthKey = 11;
|
||||
|
||||
google.protobuf.Timestamp LastSeen = 12;
|
||||
google.protobuf.Timestamp LastSuccessfulUpdate = 13;
|
||||
google.protobuf.Timestamp Expiry = 14;
|
||||
|
||||
bytes HostInfo = 15;
|
||||
bytes Endpoints = 16;
|
||||
bytes EnabledRoutes = 17;
|
||||
|
||||
google.protobuf.Timestamp CreatedAt = 18;
|
||||
google.protobuf.Timestamp UpdatedAt = 19;
|
||||
google.protobuf.Timestamp DeletedAt = 20;
|
||||
}
|
||||
|
||||
// Gin Router will prefix this with /api/v1
|
||||
service HeadscaleService {
|
||||
rpc GetMachine(GetMachineRequest) returns(Machine) {
|
||||
option(google.api.http) = {
|
||||
get : "/api/v1/machine/{machine_id}"
|
||||
};
|
||||
}
|
||||
}
|
12
tools.go
Normal file
12
tools.go
Normal file
@ -0,0 +1,12 @@
|
||||
//go:build tools
|
||||
// +build tools
|
||||
|
||||
package tools
|
||||
|
||||
import (
|
||||
_ "github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway"
|
||||
_ "github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2"
|
||||
_ "github.com/infobloxopen/protoc-gen-gorm"
|
||||
_ "google.golang.org/grpc/cmd/protoc-gen-go-grpc"
|
||||
_ "google.golang.org/protobuf/cmd/protoc-gen-go"
|
||||
)
|
Loading…
Reference in New Issue
Block a user