From 1aa57f9550d60b988ea6a47b2bd447a975c60de0 Mon Sep 17 00:00:00 2001 From: Dominik Roos Date: Wed, 5 Jun 2024 23:15:23 +0200 Subject: [PATCH] connectrpc: generate code with buf Generate the additional code required for connectrpc with the buf tool. Currently, there is no bazel ruleset available for buf. We work around this by invoking the buf binary directly and commiting the generated code in git. To deal with generation, we pin the `protoc-gen-connect-go` version in the go.mod file. A small scaffolding go binary is added to deal with setting up the environment correctly for the buf tool. While this could be a shell script, this is more readable and maintainable. This PR is broken out of the https://github.com/scionproto/scion/tree/connectrpc branch to make incremental review easier. TL;DR: Run `bazel run //tools/buf` to generate the connectrpc code. --- BUILD.bazel | 8 +- Makefile | 4 +- WORKSPACE | 17 +- buf.yaml | 9 +- go.mod | 1 + go.sum | 2 + go_deps.bzl | 6 + .../v1/control_planeconnect/BUILD.bazel | 17 + .../v1/control_planeconnect/cppki.connect.go | 164 ++++++++ .../v1/control_planeconnect/drkey.connect.go | 336 +++++++++++++++ .../control_planeconnect/renewal.connect.go | 130 ++++++ .../v1/control_planeconnect/seg.connect.go | 294 +++++++++++++ pkg/proto/daemon/v1/daemonconnect/BUILD.bazel | 13 + .../daemon/v1/daemonconnect/daemon.connect.go | 386 ++++++++++++++++++ .../discovery/v1/discoveryconnect/BUILD.bazel | 12 + .../v1/discoveryconnect/discovery.connect.go | 161 ++++++++ .../gateway/v1/gatewayconnect/BUILD.bazel | 12 + .../v1/gatewayconnect/prefix.connect.go | 129 ++++++ .../v1/hidden_segmentconnect/BUILD.bazel | 12 + .../hidden_segment.connect.go | 300 ++++++++++++++ private/app/xbazel/BUILD.bazel | 9 + private/app/xbazel/xbazel.go | 95 +++++ private/must/BUILD.bazel | 8 + private/must/must.go | 30 ++ tools/buf/BUILD.bazel | 27 ++ tools/buf/deps.bzl | 10 + tools/buf/main.go | 61 +++ tools/buf/tools.go | 24 ++ 28 files changed, 2256 insertions(+), 21 deletions(-) create mode 100644 pkg/proto/control_plane/v1/control_planeconnect/BUILD.bazel create mode 100644 pkg/proto/control_plane/v1/control_planeconnect/cppki.connect.go create mode 100644 pkg/proto/control_plane/v1/control_planeconnect/drkey.connect.go create mode 100644 pkg/proto/control_plane/v1/control_planeconnect/renewal.connect.go create mode 100644 pkg/proto/control_plane/v1/control_planeconnect/seg.connect.go create mode 100644 pkg/proto/daemon/v1/daemonconnect/BUILD.bazel create mode 100644 pkg/proto/daemon/v1/daemonconnect/daemon.connect.go create mode 100644 pkg/proto/discovery/v1/discoveryconnect/BUILD.bazel create mode 100644 pkg/proto/discovery/v1/discoveryconnect/discovery.connect.go create mode 100644 pkg/proto/gateway/v1/gatewayconnect/BUILD.bazel create mode 100644 pkg/proto/gateway/v1/gatewayconnect/prefix.connect.go create mode 100644 pkg/proto/hidden_segment/v1/hidden_segmentconnect/BUILD.bazel create mode 100644 pkg/proto/hidden_segment/v1/hidden_segmentconnect/hidden_segment.connect.go create mode 100644 private/app/xbazel/BUILD.bazel create mode 100644 private/app/xbazel/xbazel.go create mode 100644 private/must/BUILD.bazel create mode 100644 private/must/must.go create mode 100644 tools/buf/BUILD.bazel create mode 100644 tools/buf/deps.bzl create mode 100644 tools/buf/main.go create mode 100644 tools/buf/tools.go diff --git a/BUILD.bazel b/BUILD.bazel index c129c26777..ea63cd8d0f 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -1,5 +1,4 @@ -load("@bazel_skylib//rules:common_settings.bzl", "bool_flag") -load("@bazel_skylib//rules:common_settings.bzl", "string_flag") +load("@bazel_skylib//rules:common_settings.bzl", "bool_flag", "string_flag") load("@bazel_gazelle//:def.bzl", "gazelle") load("@rules_pkg//:pkg.bzl", "pkg_tar") load("@io_bazel_rules_go//go:def.bzl", "nogo") @@ -140,9 +139,10 @@ gazelle( go_lint_config( name = "go_lint_config", exclude_filter = [ - "mock_", - ".pb.go", + ".connect.go", ".gen.go", + ".pb.go", + "mock_", ], visibility = [ "//visibility:public", diff --git a/Makefile b/Makefile index f34413c519..61d645b31c 100644 --- a/Makefile +++ b/Makefile @@ -81,6 +81,8 @@ protobuf: cp -r bazel-bin/pkg/proto/*/*/go_default_library_/github.com/scionproto/scion/pkg/proto/* pkg/proto chmod 0644 pkg/proto/*/*.pb.go + bazel run //tools/buf + mocks: tools/gomocks.py @@ -141,7 +143,7 @@ lint-protobuf: lint-protobuf-buf lint-protobuf-buf: $(info ==> $@) - @tools/quiet bazel run --config=quiet @buf_bin//file:buf -- check lint + @tools/quiet bazel run --config=quiet @buf//:buf -- lint $(PWD) --path $(PWD)/proto lint-openapi: lint-openapi-spectral diff --git a/WORKSPACE b/WORKSPACE index c574af81a0..78b49f0d0b 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -2,7 +2,7 @@ workspace( name = "com_github_scionproto_scion", ) -load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file") +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") # linter rules http_archive( @@ -205,6 +205,11 @@ load("@tester_debian10_packages//:packages.bzl", tester_debian_packages_install_ tester_debian_packages_install_deps() +# Buf CLI to generate connect-go +load("//tools/buf:deps.bzl", "buf_dependencies") + +buf_dependencies() + # protobuf/gRPC http_archive( name = "rules_proto_grpc", @@ -237,16 +242,6 @@ http_archive( ], ) -http_file( - name = "buf_bin", - downloaded_file_path = "buf", - executable = True, - sha256 = "5faf15ed0a3cd4bd0919ba5fcb95334c1fd2ba32770df289d615138fa188d36a", - urls = [ - "https://github.com/bufbuild/buf/releases/download/v0.20.5/buf-Linux-x86_64", - ], -) - load("//tools/lint/python:deps.bzl", "python_lint_deps") python_lint_deps(python_interpreter) diff --git a/buf.yaml b/buf.yaml index a6b06a30cf..0e3ca5a8ce 100644 --- a/buf.yaml +++ b/buf.yaml @@ -1,8 +1,7 @@ -build: - roots: - - . - excludes: - - anapaya/protobuf +version: v1 +breaking: + use: + - FILE lint: use: - DEFAULT diff --git a/go.mod b/go.mod index d0be514b2f..3564d61d38 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,7 @@ module github.com/scionproto/scion require ( + connectrpc.com/connect v1.16.2 github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20220209173558-ad29539cd2e9 github.com/bazelbuild/rules_go v0.47.1 github.com/buildkite/go-buildkite/v2 v2.9.0 diff --git a/go.sum b/go.sum index 02446fd3d1..04ade35967 100644 --- a/go.sum +++ b/go.sum @@ -1,4 +1,6 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +connectrpc.com/connect v1.16.2 h1:ybd6y+ls7GOlb7Bh5C8+ghA6SvCBajHwxssO2CGFjqE= +connectrpc.com/connect v1.16.2/go.mod h1:n2kgwskMHXC+lVqb18wngEpF95ldBHXjZYJussz5FRc= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= diff --git a/go_deps.bzl b/go_deps.bzl index 573a52770f..9b906ef70c 100644 --- a/go_deps.bzl +++ b/go_deps.bzl @@ -13,6 +13,12 @@ def go_deps(): sum = "h1:YGD4H+SuIOOqsyoLOpZDWcieM28W47/zRO7f+9V3nvo=", version = "v0.4.5", ) + go_repository( + name = "com_connectrpc_connect", + importpath = "connectrpc.com/connect", + sum = "h1:ybd6y+ls7GOlb7Bh5C8+ghA6SvCBajHwxssO2CGFjqE=", + version = "v1.16.2", + ) go_repository( name = "com_github_ajstarks_svgo", importpath = "github.com/ajstarks/svgo", diff --git a/pkg/proto/control_plane/v1/control_planeconnect/BUILD.bazel b/pkg/proto/control_plane/v1/control_planeconnect/BUILD.bazel new file mode 100644 index 0000000000..99e61debea --- /dev/null +++ b/pkg/proto/control_plane/v1/control_planeconnect/BUILD.bazel @@ -0,0 +1,17 @@ +load("//tools/lint:go.bzl", "go_library") + +go_library( + name = "go_default_library", + srcs = [ + "cppki.connect.go", + "drkey.connect.go", + "renewal.connect.go", + "seg.connect.go", + ], + importpath = "github.com/scionproto/scion/pkg/proto/control_plane/v1/control_planeconnect", + visibility = ["//visibility:public"], + deps = [ + "//pkg/proto/control_plane:go_default_library", + "@com_connectrpc_connect//:go_default_library", + ], +) diff --git a/pkg/proto/control_plane/v1/control_planeconnect/cppki.connect.go b/pkg/proto/control_plane/v1/control_planeconnect/cppki.connect.go new file mode 100644 index 0000000000..b1838fbe25 --- /dev/null +++ b/pkg/proto/control_plane/v1/control_planeconnect/cppki.connect.go @@ -0,0 +1,164 @@ +// Copyright 2020 Anapaya Systems +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-connect-go. DO NOT EDIT. +// +// Source: proto/control_plane/v1/cppki.proto + +package control_planeconnect + +import ( + connect "connectrpc.com/connect" + context "context" + errors "errors" + control_plane "github.com/scionproto/scion/pkg/proto/control_plane" + http "net/http" + strings "strings" +) + +// This is a compile-time assertion to ensure that this generated file and the connect package are +// compatible. If you get a compiler error that this constant is not defined, this code was +// generated with a version of connect newer than the one compiled into your binary. You can fix the +// problem by either regenerating this code with an older version of connect or updating the connect +// version compiled into your binary. +const _ = connect.IsAtLeastVersion1_13_0 + +const ( + // TrustMaterialServiceName is the fully-qualified name of the TrustMaterialService service. + TrustMaterialServiceName = "proto.control_plane.v1.TrustMaterialService" +) + +// These constants are the fully-qualified names of the RPCs defined in this package. They're +// exposed at runtime as Spec.Procedure and as the final two segments of the HTTP route. +// +// Note that these are different from the fully-qualified method names used by +// google.golang.org/protobuf/reflect/protoreflect. To convert from these constants to +// reflection-formatted method names, remove the leading slash and convert the remaining slash to a +// period. +const ( + // TrustMaterialServiceChainsProcedure is the fully-qualified name of the TrustMaterialService's + // Chains RPC. + TrustMaterialServiceChainsProcedure = "/proto.control_plane.v1.TrustMaterialService/Chains" + // TrustMaterialServiceTRCProcedure is the fully-qualified name of the TrustMaterialService's TRC + // RPC. + TrustMaterialServiceTRCProcedure = "/proto.control_plane.v1.TrustMaterialService/TRC" +) + +// These variables are the protoreflect.Descriptor objects for the RPCs defined in this package. +var ( + trustMaterialServiceServiceDescriptor = control_plane.File_proto_control_plane_v1_cppki_proto.Services().ByName("TrustMaterialService") + trustMaterialServiceChainsMethodDescriptor = trustMaterialServiceServiceDescriptor.Methods().ByName("Chains") + trustMaterialServiceTRCMethodDescriptor = trustMaterialServiceServiceDescriptor.Methods().ByName("TRC") +) + +// TrustMaterialServiceClient is a client for the proto.control_plane.v1.TrustMaterialService +// service. +type TrustMaterialServiceClient interface { + // Return the certificate chains that match the request. + Chains(context.Context, *connect.Request[control_plane.ChainsRequest]) (*connect.Response[control_plane.ChainsResponse], error) + // Return a specific TRC that matches the request. + TRC(context.Context, *connect.Request[control_plane.TRCRequest]) (*connect.Response[control_plane.TRCResponse], error) +} + +// NewTrustMaterialServiceClient constructs a client for the +// proto.control_plane.v1.TrustMaterialService service. By default, it uses the Connect protocol +// with the binary Protobuf Codec, asks for gzipped responses, and sends uncompressed requests. To +// use the gRPC or gRPC-Web protocols, supply the connect.WithGRPC() or connect.WithGRPCWeb() +// options. +// +// The URL supplied here should be the base URL for the Connect or gRPC server (for example, +// http://api.acme.com or https://acme.com/grpc). +func NewTrustMaterialServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) TrustMaterialServiceClient { + baseURL = strings.TrimRight(baseURL, "/") + return &trustMaterialServiceClient{ + chains: connect.NewClient[control_plane.ChainsRequest, control_plane.ChainsResponse]( + httpClient, + baseURL+TrustMaterialServiceChainsProcedure, + connect.WithSchema(trustMaterialServiceChainsMethodDescriptor), + connect.WithClientOptions(opts...), + ), + tRC: connect.NewClient[control_plane.TRCRequest, control_plane.TRCResponse]( + httpClient, + baseURL+TrustMaterialServiceTRCProcedure, + connect.WithSchema(trustMaterialServiceTRCMethodDescriptor), + connect.WithClientOptions(opts...), + ), + } +} + +// trustMaterialServiceClient implements TrustMaterialServiceClient. +type trustMaterialServiceClient struct { + chains *connect.Client[control_plane.ChainsRequest, control_plane.ChainsResponse] + tRC *connect.Client[control_plane.TRCRequest, control_plane.TRCResponse] +} + +// Chains calls proto.control_plane.v1.TrustMaterialService.Chains. +func (c *trustMaterialServiceClient) Chains(ctx context.Context, req *connect.Request[control_plane.ChainsRequest]) (*connect.Response[control_plane.ChainsResponse], error) { + return c.chains.CallUnary(ctx, req) +} + +// TRC calls proto.control_plane.v1.TrustMaterialService.TRC. +func (c *trustMaterialServiceClient) TRC(ctx context.Context, req *connect.Request[control_plane.TRCRequest]) (*connect.Response[control_plane.TRCResponse], error) { + return c.tRC.CallUnary(ctx, req) +} + +// TrustMaterialServiceHandler is an implementation of the +// proto.control_plane.v1.TrustMaterialService service. +type TrustMaterialServiceHandler interface { + // Return the certificate chains that match the request. + Chains(context.Context, *connect.Request[control_plane.ChainsRequest]) (*connect.Response[control_plane.ChainsResponse], error) + // Return a specific TRC that matches the request. + TRC(context.Context, *connect.Request[control_plane.TRCRequest]) (*connect.Response[control_plane.TRCResponse], error) +} + +// NewTrustMaterialServiceHandler builds an HTTP handler from the service implementation. It returns +// the path on which to mount the handler and the handler itself. +// +// By default, handlers support the Connect, gRPC, and gRPC-Web protocols with the binary Protobuf +// and JSON codecs. They also support gzip compression. +func NewTrustMaterialServiceHandler(svc TrustMaterialServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) { + trustMaterialServiceChainsHandler := connect.NewUnaryHandler( + TrustMaterialServiceChainsProcedure, + svc.Chains, + connect.WithSchema(trustMaterialServiceChainsMethodDescriptor), + connect.WithHandlerOptions(opts...), + ) + trustMaterialServiceTRCHandler := connect.NewUnaryHandler( + TrustMaterialServiceTRCProcedure, + svc.TRC, + connect.WithSchema(trustMaterialServiceTRCMethodDescriptor), + connect.WithHandlerOptions(opts...), + ) + return "/proto.control_plane.v1.TrustMaterialService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + switch r.URL.Path { + case TrustMaterialServiceChainsProcedure: + trustMaterialServiceChainsHandler.ServeHTTP(w, r) + case TrustMaterialServiceTRCProcedure: + trustMaterialServiceTRCHandler.ServeHTTP(w, r) + default: + http.NotFound(w, r) + } + }) +} + +// UnimplementedTrustMaterialServiceHandler returns CodeUnimplemented from all methods. +type UnimplementedTrustMaterialServiceHandler struct{} + +func (UnimplementedTrustMaterialServiceHandler) Chains(context.Context, *connect.Request[control_plane.ChainsRequest]) (*connect.Response[control_plane.ChainsResponse], error) { + return nil, connect.NewError(connect.CodeUnimplemented, errors.New("proto.control_plane.v1.TrustMaterialService.Chains is not implemented")) +} + +func (UnimplementedTrustMaterialServiceHandler) TRC(context.Context, *connect.Request[control_plane.TRCRequest]) (*connect.Response[control_plane.TRCResponse], error) { + return nil, connect.NewError(connect.CodeUnimplemented, errors.New("proto.control_plane.v1.TrustMaterialService.TRC is not implemented")) +} diff --git a/pkg/proto/control_plane/v1/control_planeconnect/drkey.connect.go b/pkg/proto/control_plane/v1/control_planeconnect/drkey.connect.go new file mode 100644 index 0000000000..6e2cdb1d9e --- /dev/null +++ b/pkg/proto/control_plane/v1/control_planeconnect/drkey.connect.go @@ -0,0 +1,336 @@ +// Copyright 2022 ETH Zurich +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-connect-go. DO NOT EDIT. +// +// Source: proto/control_plane/v1/drkey.proto + +package control_planeconnect + +import ( + connect "connectrpc.com/connect" + context "context" + errors "errors" + control_plane "github.com/scionproto/scion/pkg/proto/control_plane" + http "net/http" + strings "strings" +) + +// This is a compile-time assertion to ensure that this generated file and the connect package are +// compatible. If you get a compiler error that this constant is not defined, this code was +// generated with a version of connect newer than the one compiled into your binary. You can fix the +// problem by either regenerating this code with an older version of connect or updating the connect +// version compiled into your binary. +const _ = connect.IsAtLeastVersion1_13_0 + +const ( + // DRKeyInterServiceName is the fully-qualified name of the DRKeyInterService service. + DRKeyInterServiceName = "proto.control_plane.v1.DRKeyInterService" + // DRKeyIntraServiceName is the fully-qualified name of the DRKeyIntraService service. + DRKeyIntraServiceName = "proto.control_plane.v1.DRKeyIntraService" +) + +// These constants are the fully-qualified names of the RPCs defined in this package. They're +// exposed at runtime as Spec.Procedure and as the final two segments of the HTTP route. +// +// Note that these are different from the fully-qualified method names used by +// google.golang.org/protobuf/reflect/protoreflect. To convert from these constants to +// reflection-formatted method names, remove the leading slash and convert the remaining slash to a +// period. +const ( + // DRKeyInterServiceDRKeyLevel1Procedure is the fully-qualified name of the DRKeyInterService's + // DRKeyLevel1 RPC. + DRKeyInterServiceDRKeyLevel1Procedure = "/proto.control_plane.v1.DRKeyInterService/DRKeyLevel1" + // DRKeyIntraServiceDRKeyIntraLevel1Procedure is the fully-qualified name of the DRKeyIntraService's + // DRKeyIntraLevel1 RPC. + DRKeyIntraServiceDRKeyIntraLevel1Procedure = "/proto.control_plane.v1.DRKeyIntraService/DRKeyIntraLevel1" + // DRKeyIntraServiceDRKeyASHostProcedure is the fully-qualified name of the DRKeyIntraService's + // DRKeyASHost RPC. + DRKeyIntraServiceDRKeyASHostProcedure = "/proto.control_plane.v1.DRKeyIntraService/DRKeyASHost" + // DRKeyIntraServiceDRKeyHostASProcedure is the fully-qualified name of the DRKeyIntraService's + // DRKeyHostAS RPC. + DRKeyIntraServiceDRKeyHostASProcedure = "/proto.control_plane.v1.DRKeyIntraService/DRKeyHostAS" + // DRKeyIntraServiceDRKeyHostHostProcedure is the fully-qualified name of the DRKeyIntraService's + // DRKeyHostHost RPC. + DRKeyIntraServiceDRKeyHostHostProcedure = "/proto.control_plane.v1.DRKeyIntraService/DRKeyHostHost" + // DRKeyIntraServiceDRKeySecretValueProcedure is the fully-qualified name of the DRKeyIntraService's + // DRKeySecretValue RPC. + DRKeyIntraServiceDRKeySecretValueProcedure = "/proto.control_plane.v1.DRKeyIntraService/DRKeySecretValue" +) + +// These variables are the protoreflect.Descriptor objects for the RPCs defined in this package. +var ( + dRKeyInterServiceServiceDescriptor = control_plane.File_proto_control_plane_v1_drkey_proto.Services().ByName("DRKeyInterService") + dRKeyInterServiceDRKeyLevel1MethodDescriptor = dRKeyInterServiceServiceDescriptor.Methods().ByName("DRKeyLevel1") + dRKeyIntraServiceServiceDescriptor = control_plane.File_proto_control_plane_v1_drkey_proto.Services().ByName("DRKeyIntraService") + dRKeyIntraServiceDRKeyIntraLevel1MethodDescriptor = dRKeyIntraServiceServiceDescriptor.Methods().ByName("DRKeyIntraLevel1") + dRKeyIntraServiceDRKeyASHostMethodDescriptor = dRKeyIntraServiceServiceDescriptor.Methods().ByName("DRKeyASHost") + dRKeyIntraServiceDRKeyHostASMethodDescriptor = dRKeyIntraServiceServiceDescriptor.Methods().ByName("DRKeyHostAS") + dRKeyIntraServiceDRKeyHostHostMethodDescriptor = dRKeyIntraServiceServiceDescriptor.Methods().ByName("DRKeyHostHost") + dRKeyIntraServiceDRKeySecretValueMethodDescriptor = dRKeyIntraServiceServiceDescriptor.Methods().ByName("DRKeySecretValue") +) + +// DRKeyInterServiceClient is a client for the proto.control_plane.v1.DRKeyInterService service. +type DRKeyInterServiceClient interface { + // Return the Level1Key that matches the request + DRKeyLevel1(context.Context, *connect.Request[control_plane.DRKeyLevel1Request]) (*connect.Response[control_plane.DRKeyLevel1Response], error) +} + +// NewDRKeyInterServiceClient constructs a client for the proto.control_plane.v1.DRKeyInterService +// service. By default, it uses the Connect protocol with the binary Protobuf Codec, asks for +// gzipped responses, and sends uncompressed requests. To use the gRPC or gRPC-Web protocols, supply +// the connect.WithGRPC() or connect.WithGRPCWeb() options. +// +// The URL supplied here should be the base URL for the Connect or gRPC server (for example, +// http://api.acme.com or https://acme.com/grpc). +func NewDRKeyInterServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) DRKeyInterServiceClient { + baseURL = strings.TrimRight(baseURL, "/") + return &dRKeyInterServiceClient{ + dRKeyLevel1: connect.NewClient[control_plane.DRKeyLevel1Request, control_plane.DRKeyLevel1Response]( + httpClient, + baseURL+DRKeyInterServiceDRKeyLevel1Procedure, + connect.WithSchema(dRKeyInterServiceDRKeyLevel1MethodDescriptor), + connect.WithClientOptions(opts...), + ), + } +} + +// dRKeyInterServiceClient implements DRKeyInterServiceClient. +type dRKeyInterServiceClient struct { + dRKeyLevel1 *connect.Client[control_plane.DRKeyLevel1Request, control_plane.DRKeyLevel1Response] +} + +// DRKeyLevel1 calls proto.control_plane.v1.DRKeyInterService.DRKeyLevel1. +func (c *dRKeyInterServiceClient) DRKeyLevel1(ctx context.Context, req *connect.Request[control_plane.DRKeyLevel1Request]) (*connect.Response[control_plane.DRKeyLevel1Response], error) { + return c.dRKeyLevel1.CallUnary(ctx, req) +} + +// DRKeyInterServiceHandler is an implementation of the proto.control_plane.v1.DRKeyInterService +// service. +type DRKeyInterServiceHandler interface { + // Return the Level1Key that matches the request + DRKeyLevel1(context.Context, *connect.Request[control_plane.DRKeyLevel1Request]) (*connect.Response[control_plane.DRKeyLevel1Response], error) +} + +// NewDRKeyInterServiceHandler builds an HTTP handler from the service implementation. It returns +// the path on which to mount the handler and the handler itself. +// +// By default, handlers support the Connect, gRPC, and gRPC-Web protocols with the binary Protobuf +// and JSON codecs. They also support gzip compression. +func NewDRKeyInterServiceHandler(svc DRKeyInterServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) { + dRKeyInterServiceDRKeyLevel1Handler := connect.NewUnaryHandler( + DRKeyInterServiceDRKeyLevel1Procedure, + svc.DRKeyLevel1, + connect.WithSchema(dRKeyInterServiceDRKeyLevel1MethodDescriptor), + connect.WithHandlerOptions(opts...), + ) + return "/proto.control_plane.v1.DRKeyInterService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + switch r.URL.Path { + case DRKeyInterServiceDRKeyLevel1Procedure: + dRKeyInterServiceDRKeyLevel1Handler.ServeHTTP(w, r) + default: + http.NotFound(w, r) + } + }) +} + +// UnimplementedDRKeyInterServiceHandler returns CodeUnimplemented from all methods. +type UnimplementedDRKeyInterServiceHandler struct{} + +func (UnimplementedDRKeyInterServiceHandler) DRKeyLevel1(context.Context, *connect.Request[control_plane.DRKeyLevel1Request]) (*connect.Response[control_plane.DRKeyLevel1Response], error) { + return nil, connect.NewError(connect.CodeUnimplemented, errors.New("proto.control_plane.v1.DRKeyInterService.DRKeyLevel1 is not implemented")) +} + +// DRKeyIntraServiceClient is a client for the proto.control_plane.v1.DRKeyIntraService service. +type DRKeyIntraServiceClient interface { + // Return the ASAS that matches the request + DRKeyIntraLevel1(context.Context, *connect.Request[control_plane.DRKeyIntraLevel1Request]) (*connect.Response[control_plane.DRKeyIntraLevel1Response], error) + // Return the AS-Host that matches the request + DRKeyASHost(context.Context, *connect.Request[control_plane.DRKeyASHostRequest]) (*connect.Response[control_plane.DRKeyASHostResponse], error) + // Return the Host-AS that matches the request + DRKeyHostAS(context.Context, *connect.Request[control_plane.DRKeyHostASRequest]) (*connect.Response[control_plane.DRKeyHostASResponse], error) + // Return the Host-Host that matches the request + DRKeyHostHost(context.Context, *connect.Request[control_plane.DRKeyHostHostRequest]) (*connect.Response[control_plane.DRKeyHostHostResponse], error) + // Return the SecretValue that matches the request + DRKeySecretValue(context.Context, *connect.Request[control_plane.DRKeySecretValueRequest]) (*connect.Response[control_plane.DRKeySecretValueResponse], error) +} + +// NewDRKeyIntraServiceClient constructs a client for the proto.control_plane.v1.DRKeyIntraService +// service. By default, it uses the Connect protocol with the binary Protobuf Codec, asks for +// gzipped responses, and sends uncompressed requests. To use the gRPC or gRPC-Web protocols, supply +// the connect.WithGRPC() or connect.WithGRPCWeb() options. +// +// The URL supplied here should be the base URL for the Connect or gRPC server (for example, +// http://api.acme.com or https://acme.com/grpc). +func NewDRKeyIntraServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) DRKeyIntraServiceClient { + baseURL = strings.TrimRight(baseURL, "/") + return &dRKeyIntraServiceClient{ + dRKeyIntraLevel1: connect.NewClient[control_plane.DRKeyIntraLevel1Request, control_plane.DRKeyIntraLevel1Response]( + httpClient, + baseURL+DRKeyIntraServiceDRKeyIntraLevel1Procedure, + connect.WithSchema(dRKeyIntraServiceDRKeyIntraLevel1MethodDescriptor), + connect.WithClientOptions(opts...), + ), + dRKeyASHost: connect.NewClient[control_plane.DRKeyASHostRequest, control_plane.DRKeyASHostResponse]( + httpClient, + baseURL+DRKeyIntraServiceDRKeyASHostProcedure, + connect.WithSchema(dRKeyIntraServiceDRKeyASHostMethodDescriptor), + connect.WithClientOptions(opts...), + ), + dRKeyHostAS: connect.NewClient[control_plane.DRKeyHostASRequest, control_plane.DRKeyHostASResponse]( + httpClient, + baseURL+DRKeyIntraServiceDRKeyHostASProcedure, + connect.WithSchema(dRKeyIntraServiceDRKeyHostASMethodDescriptor), + connect.WithClientOptions(opts...), + ), + dRKeyHostHost: connect.NewClient[control_plane.DRKeyHostHostRequest, control_plane.DRKeyHostHostResponse]( + httpClient, + baseURL+DRKeyIntraServiceDRKeyHostHostProcedure, + connect.WithSchema(dRKeyIntraServiceDRKeyHostHostMethodDescriptor), + connect.WithClientOptions(opts...), + ), + dRKeySecretValue: connect.NewClient[control_plane.DRKeySecretValueRequest, control_plane.DRKeySecretValueResponse]( + httpClient, + baseURL+DRKeyIntraServiceDRKeySecretValueProcedure, + connect.WithSchema(dRKeyIntraServiceDRKeySecretValueMethodDescriptor), + connect.WithClientOptions(opts...), + ), + } +} + +// dRKeyIntraServiceClient implements DRKeyIntraServiceClient. +type dRKeyIntraServiceClient struct { + dRKeyIntraLevel1 *connect.Client[control_plane.DRKeyIntraLevel1Request, control_plane.DRKeyIntraLevel1Response] + dRKeyASHost *connect.Client[control_plane.DRKeyASHostRequest, control_plane.DRKeyASHostResponse] + dRKeyHostAS *connect.Client[control_plane.DRKeyHostASRequest, control_plane.DRKeyHostASResponse] + dRKeyHostHost *connect.Client[control_plane.DRKeyHostHostRequest, control_plane.DRKeyHostHostResponse] + dRKeySecretValue *connect.Client[control_plane.DRKeySecretValueRequest, control_plane.DRKeySecretValueResponse] +} + +// DRKeyIntraLevel1 calls proto.control_plane.v1.DRKeyIntraService.DRKeyIntraLevel1. +func (c *dRKeyIntraServiceClient) DRKeyIntraLevel1(ctx context.Context, req *connect.Request[control_plane.DRKeyIntraLevel1Request]) (*connect.Response[control_plane.DRKeyIntraLevel1Response], error) { + return c.dRKeyIntraLevel1.CallUnary(ctx, req) +} + +// DRKeyASHost calls proto.control_plane.v1.DRKeyIntraService.DRKeyASHost. +func (c *dRKeyIntraServiceClient) DRKeyASHost(ctx context.Context, req *connect.Request[control_plane.DRKeyASHostRequest]) (*connect.Response[control_plane.DRKeyASHostResponse], error) { + return c.dRKeyASHost.CallUnary(ctx, req) +} + +// DRKeyHostAS calls proto.control_plane.v1.DRKeyIntraService.DRKeyHostAS. +func (c *dRKeyIntraServiceClient) DRKeyHostAS(ctx context.Context, req *connect.Request[control_plane.DRKeyHostASRequest]) (*connect.Response[control_plane.DRKeyHostASResponse], error) { + return c.dRKeyHostAS.CallUnary(ctx, req) +} + +// DRKeyHostHost calls proto.control_plane.v1.DRKeyIntraService.DRKeyHostHost. +func (c *dRKeyIntraServiceClient) DRKeyHostHost(ctx context.Context, req *connect.Request[control_plane.DRKeyHostHostRequest]) (*connect.Response[control_plane.DRKeyHostHostResponse], error) { + return c.dRKeyHostHost.CallUnary(ctx, req) +} + +// DRKeySecretValue calls proto.control_plane.v1.DRKeyIntraService.DRKeySecretValue. +func (c *dRKeyIntraServiceClient) DRKeySecretValue(ctx context.Context, req *connect.Request[control_plane.DRKeySecretValueRequest]) (*connect.Response[control_plane.DRKeySecretValueResponse], error) { + return c.dRKeySecretValue.CallUnary(ctx, req) +} + +// DRKeyIntraServiceHandler is an implementation of the proto.control_plane.v1.DRKeyIntraService +// service. +type DRKeyIntraServiceHandler interface { + // Return the ASAS that matches the request + DRKeyIntraLevel1(context.Context, *connect.Request[control_plane.DRKeyIntraLevel1Request]) (*connect.Response[control_plane.DRKeyIntraLevel1Response], error) + // Return the AS-Host that matches the request + DRKeyASHost(context.Context, *connect.Request[control_plane.DRKeyASHostRequest]) (*connect.Response[control_plane.DRKeyASHostResponse], error) + // Return the Host-AS that matches the request + DRKeyHostAS(context.Context, *connect.Request[control_plane.DRKeyHostASRequest]) (*connect.Response[control_plane.DRKeyHostASResponse], error) + // Return the Host-Host that matches the request + DRKeyHostHost(context.Context, *connect.Request[control_plane.DRKeyHostHostRequest]) (*connect.Response[control_plane.DRKeyHostHostResponse], error) + // Return the SecretValue that matches the request + DRKeySecretValue(context.Context, *connect.Request[control_plane.DRKeySecretValueRequest]) (*connect.Response[control_plane.DRKeySecretValueResponse], error) +} + +// NewDRKeyIntraServiceHandler builds an HTTP handler from the service implementation. It returns +// the path on which to mount the handler and the handler itself. +// +// By default, handlers support the Connect, gRPC, and gRPC-Web protocols with the binary Protobuf +// and JSON codecs. They also support gzip compression. +func NewDRKeyIntraServiceHandler(svc DRKeyIntraServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) { + dRKeyIntraServiceDRKeyIntraLevel1Handler := connect.NewUnaryHandler( + DRKeyIntraServiceDRKeyIntraLevel1Procedure, + svc.DRKeyIntraLevel1, + connect.WithSchema(dRKeyIntraServiceDRKeyIntraLevel1MethodDescriptor), + connect.WithHandlerOptions(opts...), + ) + dRKeyIntraServiceDRKeyASHostHandler := connect.NewUnaryHandler( + DRKeyIntraServiceDRKeyASHostProcedure, + svc.DRKeyASHost, + connect.WithSchema(dRKeyIntraServiceDRKeyASHostMethodDescriptor), + connect.WithHandlerOptions(opts...), + ) + dRKeyIntraServiceDRKeyHostASHandler := connect.NewUnaryHandler( + DRKeyIntraServiceDRKeyHostASProcedure, + svc.DRKeyHostAS, + connect.WithSchema(dRKeyIntraServiceDRKeyHostASMethodDescriptor), + connect.WithHandlerOptions(opts...), + ) + dRKeyIntraServiceDRKeyHostHostHandler := connect.NewUnaryHandler( + DRKeyIntraServiceDRKeyHostHostProcedure, + svc.DRKeyHostHost, + connect.WithSchema(dRKeyIntraServiceDRKeyHostHostMethodDescriptor), + connect.WithHandlerOptions(opts...), + ) + dRKeyIntraServiceDRKeySecretValueHandler := connect.NewUnaryHandler( + DRKeyIntraServiceDRKeySecretValueProcedure, + svc.DRKeySecretValue, + connect.WithSchema(dRKeyIntraServiceDRKeySecretValueMethodDescriptor), + connect.WithHandlerOptions(opts...), + ) + return "/proto.control_plane.v1.DRKeyIntraService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + switch r.URL.Path { + case DRKeyIntraServiceDRKeyIntraLevel1Procedure: + dRKeyIntraServiceDRKeyIntraLevel1Handler.ServeHTTP(w, r) + case DRKeyIntraServiceDRKeyASHostProcedure: + dRKeyIntraServiceDRKeyASHostHandler.ServeHTTP(w, r) + case DRKeyIntraServiceDRKeyHostASProcedure: + dRKeyIntraServiceDRKeyHostASHandler.ServeHTTP(w, r) + case DRKeyIntraServiceDRKeyHostHostProcedure: + dRKeyIntraServiceDRKeyHostHostHandler.ServeHTTP(w, r) + case DRKeyIntraServiceDRKeySecretValueProcedure: + dRKeyIntraServiceDRKeySecretValueHandler.ServeHTTP(w, r) + default: + http.NotFound(w, r) + } + }) +} + +// UnimplementedDRKeyIntraServiceHandler returns CodeUnimplemented from all methods. +type UnimplementedDRKeyIntraServiceHandler struct{} + +func (UnimplementedDRKeyIntraServiceHandler) DRKeyIntraLevel1(context.Context, *connect.Request[control_plane.DRKeyIntraLevel1Request]) (*connect.Response[control_plane.DRKeyIntraLevel1Response], error) { + return nil, connect.NewError(connect.CodeUnimplemented, errors.New("proto.control_plane.v1.DRKeyIntraService.DRKeyIntraLevel1 is not implemented")) +} + +func (UnimplementedDRKeyIntraServiceHandler) DRKeyASHost(context.Context, *connect.Request[control_plane.DRKeyASHostRequest]) (*connect.Response[control_plane.DRKeyASHostResponse], error) { + return nil, connect.NewError(connect.CodeUnimplemented, errors.New("proto.control_plane.v1.DRKeyIntraService.DRKeyASHost is not implemented")) +} + +func (UnimplementedDRKeyIntraServiceHandler) DRKeyHostAS(context.Context, *connect.Request[control_plane.DRKeyHostASRequest]) (*connect.Response[control_plane.DRKeyHostASResponse], error) { + return nil, connect.NewError(connect.CodeUnimplemented, errors.New("proto.control_plane.v1.DRKeyIntraService.DRKeyHostAS is not implemented")) +} + +func (UnimplementedDRKeyIntraServiceHandler) DRKeyHostHost(context.Context, *connect.Request[control_plane.DRKeyHostHostRequest]) (*connect.Response[control_plane.DRKeyHostHostResponse], error) { + return nil, connect.NewError(connect.CodeUnimplemented, errors.New("proto.control_plane.v1.DRKeyIntraService.DRKeyHostHost is not implemented")) +} + +func (UnimplementedDRKeyIntraServiceHandler) DRKeySecretValue(context.Context, *connect.Request[control_plane.DRKeySecretValueRequest]) (*connect.Response[control_plane.DRKeySecretValueResponse], error) { + return nil, connect.NewError(connect.CodeUnimplemented, errors.New("proto.control_plane.v1.DRKeyIntraService.DRKeySecretValue is not implemented")) +} diff --git a/pkg/proto/control_plane/v1/control_planeconnect/renewal.connect.go b/pkg/proto/control_plane/v1/control_planeconnect/renewal.connect.go new file mode 100644 index 0000000000..3129d1dade --- /dev/null +++ b/pkg/proto/control_plane/v1/control_planeconnect/renewal.connect.go @@ -0,0 +1,130 @@ +// Copyright 2020 Anapaya Systems +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-connect-go. DO NOT EDIT. +// +// Source: proto/control_plane/v1/renewal.proto + +package control_planeconnect + +import ( + connect "connectrpc.com/connect" + context "context" + errors "errors" + control_plane "github.com/scionproto/scion/pkg/proto/control_plane" + http "net/http" + strings "strings" +) + +// This is a compile-time assertion to ensure that this generated file and the connect package are +// compatible. If you get a compiler error that this constant is not defined, this code was +// generated with a version of connect newer than the one compiled into your binary. You can fix the +// problem by either regenerating this code with an older version of connect or updating the connect +// version compiled into your binary. +const _ = connect.IsAtLeastVersion1_13_0 + +const ( + // ChainRenewalServiceName is the fully-qualified name of the ChainRenewalService service. + ChainRenewalServiceName = "proto.control_plane.v1.ChainRenewalService" +) + +// These constants are the fully-qualified names of the RPCs defined in this package. They're +// exposed at runtime as Spec.Procedure and as the final two segments of the HTTP route. +// +// Note that these are different from the fully-qualified method names used by +// google.golang.org/protobuf/reflect/protoreflect. To convert from these constants to +// reflection-formatted method names, remove the leading slash and convert the remaining slash to a +// period. +const ( + // ChainRenewalServiceChainRenewalProcedure is the fully-qualified name of the ChainRenewalService's + // ChainRenewal RPC. + ChainRenewalServiceChainRenewalProcedure = "/proto.control_plane.v1.ChainRenewalService/ChainRenewal" +) + +// These variables are the protoreflect.Descriptor objects for the RPCs defined in this package. +var ( + chainRenewalServiceServiceDescriptor = control_plane.File_proto_control_plane_v1_renewal_proto.Services().ByName("ChainRenewalService") + chainRenewalServiceChainRenewalMethodDescriptor = chainRenewalServiceServiceDescriptor.Methods().ByName("ChainRenewal") +) + +// ChainRenewalServiceClient is a client for the proto.control_plane.v1.ChainRenewalService service. +type ChainRenewalServiceClient interface { + // RenewChain creates a chain from the chain request. + ChainRenewal(context.Context, *connect.Request[control_plane.ChainRenewalRequest]) (*connect.Response[control_plane.ChainRenewalResponse], error) +} + +// NewChainRenewalServiceClient constructs a client for the +// proto.control_plane.v1.ChainRenewalService service. By default, it uses the Connect protocol with +// the binary Protobuf Codec, asks for gzipped responses, and sends uncompressed requests. To use +// the gRPC or gRPC-Web protocols, supply the connect.WithGRPC() or connect.WithGRPCWeb() options. +// +// The URL supplied here should be the base URL for the Connect or gRPC server (for example, +// http://api.acme.com or https://acme.com/grpc). +func NewChainRenewalServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) ChainRenewalServiceClient { + baseURL = strings.TrimRight(baseURL, "/") + return &chainRenewalServiceClient{ + chainRenewal: connect.NewClient[control_plane.ChainRenewalRequest, control_plane.ChainRenewalResponse]( + httpClient, + baseURL+ChainRenewalServiceChainRenewalProcedure, + connect.WithSchema(chainRenewalServiceChainRenewalMethodDescriptor), + connect.WithClientOptions(opts...), + ), + } +} + +// chainRenewalServiceClient implements ChainRenewalServiceClient. +type chainRenewalServiceClient struct { + chainRenewal *connect.Client[control_plane.ChainRenewalRequest, control_plane.ChainRenewalResponse] +} + +// ChainRenewal calls proto.control_plane.v1.ChainRenewalService.ChainRenewal. +func (c *chainRenewalServiceClient) ChainRenewal(ctx context.Context, req *connect.Request[control_plane.ChainRenewalRequest]) (*connect.Response[control_plane.ChainRenewalResponse], error) { + return c.chainRenewal.CallUnary(ctx, req) +} + +// ChainRenewalServiceHandler is an implementation of the proto.control_plane.v1.ChainRenewalService +// service. +type ChainRenewalServiceHandler interface { + // RenewChain creates a chain from the chain request. + ChainRenewal(context.Context, *connect.Request[control_plane.ChainRenewalRequest]) (*connect.Response[control_plane.ChainRenewalResponse], error) +} + +// NewChainRenewalServiceHandler builds an HTTP handler from the service implementation. It returns +// the path on which to mount the handler and the handler itself. +// +// By default, handlers support the Connect, gRPC, and gRPC-Web protocols with the binary Protobuf +// and JSON codecs. They also support gzip compression. +func NewChainRenewalServiceHandler(svc ChainRenewalServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) { + chainRenewalServiceChainRenewalHandler := connect.NewUnaryHandler( + ChainRenewalServiceChainRenewalProcedure, + svc.ChainRenewal, + connect.WithSchema(chainRenewalServiceChainRenewalMethodDescriptor), + connect.WithHandlerOptions(opts...), + ) + return "/proto.control_plane.v1.ChainRenewalService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + switch r.URL.Path { + case ChainRenewalServiceChainRenewalProcedure: + chainRenewalServiceChainRenewalHandler.ServeHTTP(w, r) + default: + http.NotFound(w, r) + } + }) +} + +// UnimplementedChainRenewalServiceHandler returns CodeUnimplemented from all methods. +type UnimplementedChainRenewalServiceHandler struct{} + +func (UnimplementedChainRenewalServiceHandler) ChainRenewal(context.Context, *connect.Request[control_plane.ChainRenewalRequest]) (*connect.Response[control_plane.ChainRenewalResponse], error) { + return nil, connect.NewError(connect.CodeUnimplemented, errors.New("proto.control_plane.v1.ChainRenewalService.ChainRenewal is not implemented")) +} diff --git a/pkg/proto/control_plane/v1/control_planeconnect/seg.connect.go b/pkg/proto/control_plane/v1/control_planeconnect/seg.connect.go new file mode 100644 index 0000000000..df754112cf --- /dev/null +++ b/pkg/proto/control_plane/v1/control_planeconnect/seg.connect.go @@ -0,0 +1,294 @@ +// Copyright 2020 Anapaya Systems +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-connect-go. DO NOT EDIT. +// +// Source: proto/control_plane/v1/seg.proto + +package control_planeconnect + +import ( + connect "connectrpc.com/connect" + context "context" + errors "errors" + control_plane "github.com/scionproto/scion/pkg/proto/control_plane" + http "net/http" + strings "strings" +) + +// This is a compile-time assertion to ensure that this generated file and the connect package are +// compatible. If you get a compiler error that this constant is not defined, this code was +// generated with a version of connect newer than the one compiled into your binary. You can fix the +// problem by either regenerating this code with an older version of connect or updating the connect +// version compiled into your binary. +const _ = connect.IsAtLeastVersion1_13_0 + +const ( + // SegmentLookupServiceName is the fully-qualified name of the SegmentLookupService service. + SegmentLookupServiceName = "proto.control_plane.v1.SegmentLookupService" + // SegmentRegistrationServiceName is the fully-qualified name of the SegmentRegistrationService + // service. + SegmentRegistrationServiceName = "proto.control_plane.v1.SegmentRegistrationService" + // SegmentCreationServiceName is the fully-qualified name of the SegmentCreationService service. + SegmentCreationServiceName = "proto.control_plane.v1.SegmentCreationService" +) + +// These constants are the fully-qualified names of the RPCs defined in this package. They're +// exposed at runtime as Spec.Procedure and as the final two segments of the HTTP route. +// +// Note that these are different from the fully-qualified method names used by +// google.golang.org/protobuf/reflect/protoreflect. To convert from these constants to +// reflection-formatted method names, remove the leading slash and convert the remaining slash to a +// period. +const ( + // SegmentLookupServiceSegmentsProcedure is the fully-qualified name of the SegmentLookupService's + // Segments RPC. + SegmentLookupServiceSegmentsProcedure = "/proto.control_plane.v1.SegmentLookupService/Segments" + // SegmentRegistrationServiceSegmentsRegistrationProcedure is the fully-qualified name of the + // SegmentRegistrationService's SegmentsRegistration RPC. + SegmentRegistrationServiceSegmentsRegistrationProcedure = "/proto.control_plane.v1.SegmentRegistrationService/SegmentsRegistration" + // SegmentCreationServiceBeaconProcedure is the fully-qualified name of the SegmentCreationService's + // Beacon RPC. + SegmentCreationServiceBeaconProcedure = "/proto.control_plane.v1.SegmentCreationService/Beacon" +) + +// These variables are the protoreflect.Descriptor objects for the RPCs defined in this package. +var ( + segmentLookupServiceServiceDescriptor = control_plane.File_proto_control_plane_v1_seg_proto.Services().ByName("SegmentLookupService") + segmentLookupServiceSegmentsMethodDescriptor = segmentLookupServiceServiceDescriptor.Methods().ByName("Segments") + segmentRegistrationServiceServiceDescriptor = control_plane.File_proto_control_plane_v1_seg_proto.Services().ByName("SegmentRegistrationService") + segmentRegistrationServiceSegmentsRegistrationMethodDescriptor = segmentRegistrationServiceServiceDescriptor.Methods().ByName("SegmentsRegistration") + segmentCreationServiceServiceDescriptor = control_plane.File_proto_control_plane_v1_seg_proto.Services().ByName("SegmentCreationService") + segmentCreationServiceBeaconMethodDescriptor = segmentCreationServiceServiceDescriptor.Methods().ByName("Beacon") +) + +// SegmentLookupServiceClient is a client for the proto.control_plane.v1.SegmentLookupService +// service. +type SegmentLookupServiceClient interface { + // Segments returns all segments that match the request. + Segments(context.Context, *connect.Request[control_plane.SegmentsRequest]) (*connect.Response[control_plane.SegmentsResponse], error) +} + +// NewSegmentLookupServiceClient constructs a client for the +// proto.control_plane.v1.SegmentLookupService service. By default, it uses the Connect protocol +// with the binary Protobuf Codec, asks for gzipped responses, and sends uncompressed requests. To +// use the gRPC or gRPC-Web protocols, supply the connect.WithGRPC() or connect.WithGRPCWeb() +// options. +// +// The URL supplied here should be the base URL for the Connect or gRPC server (for example, +// http://api.acme.com or https://acme.com/grpc). +func NewSegmentLookupServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) SegmentLookupServiceClient { + baseURL = strings.TrimRight(baseURL, "/") + return &segmentLookupServiceClient{ + segments: connect.NewClient[control_plane.SegmentsRequest, control_plane.SegmentsResponse]( + httpClient, + baseURL+SegmentLookupServiceSegmentsProcedure, + connect.WithSchema(segmentLookupServiceSegmentsMethodDescriptor), + connect.WithClientOptions(opts...), + ), + } +} + +// segmentLookupServiceClient implements SegmentLookupServiceClient. +type segmentLookupServiceClient struct { + segments *connect.Client[control_plane.SegmentsRequest, control_plane.SegmentsResponse] +} + +// Segments calls proto.control_plane.v1.SegmentLookupService.Segments. +func (c *segmentLookupServiceClient) Segments(ctx context.Context, req *connect.Request[control_plane.SegmentsRequest]) (*connect.Response[control_plane.SegmentsResponse], error) { + return c.segments.CallUnary(ctx, req) +} + +// SegmentLookupServiceHandler is an implementation of the +// proto.control_plane.v1.SegmentLookupService service. +type SegmentLookupServiceHandler interface { + // Segments returns all segments that match the request. + Segments(context.Context, *connect.Request[control_plane.SegmentsRequest]) (*connect.Response[control_plane.SegmentsResponse], error) +} + +// NewSegmentLookupServiceHandler builds an HTTP handler from the service implementation. It returns +// the path on which to mount the handler and the handler itself. +// +// By default, handlers support the Connect, gRPC, and gRPC-Web protocols with the binary Protobuf +// and JSON codecs. They also support gzip compression. +func NewSegmentLookupServiceHandler(svc SegmentLookupServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) { + segmentLookupServiceSegmentsHandler := connect.NewUnaryHandler( + SegmentLookupServiceSegmentsProcedure, + svc.Segments, + connect.WithSchema(segmentLookupServiceSegmentsMethodDescriptor), + connect.WithHandlerOptions(opts...), + ) + return "/proto.control_plane.v1.SegmentLookupService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + switch r.URL.Path { + case SegmentLookupServiceSegmentsProcedure: + segmentLookupServiceSegmentsHandler.ServeHTTP(w, r) + default: + http.NotFound(w, r) + } + }) +} + +// UnimplementedSegmentLookupServiceHandler returns CodeUnimplemented from all methods. +type UnimplementedSegmentLookupServiceHandler struct{} + +func (UnimplementedSegmentLookupServiceHandler) Segments(context.Context, *connect.Request[control_plane.SegmentsRequest]) (*connect.Response[control_plane.SegmentsResponse], error) { + return nil, connect.NewError(connect.CodeUnimplemented, errors.New("proto.control_plane.v1.SegmentLookupService.Segments is not implemented")) +} + +// SegmentRegistrationServiceClient is a client for the +// proto.control_plane.v1.SegmentRegistrationService service. +type SegmentRegistrationServiceClient interface { + // SegmentsRegistration registers segments at the remote. + SegmentsRegistration(context.Context, *connect.Request[control_plane.SegmentsRegistrationRequest]) (*connect.Response[control_plane.SegmentsRegistrationResponse], error) +} + +// NewSegmentRegistrationServiceClient constructs a client for the +// proto.control_plane.v1.SegmentRegistrationService service. By default, it uses the Connect +// protocol with the binary Protobuf Codec, asks for gzipped responses, and sends uncompressed +// requests. To use the gRPC or gRPC-Web protocols, supply the connect.WithGRPC() or +// connect.WithGRPCWeb() options. +// +// The URL supplied here should be the base URL for the Connect or gRPC server (for example, +// http://api.acme.com or https://acme.com/grpc). +func NewSegmentRegistrationServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) SegmentRegistrationServiceClient { + baseURL = strings.TrimRight(baseURL, "/") + return &segmentRegistrationServiceClient{ + segmentsRegistration: connect.NewClient[control_plane.SegmentsRegistrationRequest, control_plane.SegmentsRegistrationResponse]( + httpClient, + baseURL+SegmentRegistrationServiceSegmentsRegistrationProcedure, + connect.WithSchema(segmentRegistrationServiceSegmentsRegistrationMethodDescriptor), + connect.WithClientOptions(opts...), + ), + } +} + +// segmentRegistrationServiceClient implements SegmentRegistrationServiceClient. +type segmentRegistrationServiceClient struct { + segmentsRegistration *connect.Client[control_plane.SegmentsRegistrationRequest, control_plane.SegmentsRegistrationResponse] +} + +// SegmentsRegistration calls +// proto.control_plane.v1.SegmentRegistrationService.SegmentsRegistration. +func (c *segmentRegistrationServiceClient) SegmentsRegistration(ctx context.Context, req *connect.Request[control_plane.SegmentsRegistrationRequest]) (*connect.Response[control_plane.SegmentsRegistrationResponse], error) { + return c.segmentsRegistration.CallUnary(ctx, req) +} + +// SegmentRegistrationServiceHandler is an implementation of the +// proto.control_plane.v1.SegmentRegistrationService service. +type SegmentRegistrationServiceHandler interface { + // SegmentsRegistration registers segments at the remote. + SegmentsRegistration(context.Context, *connect.Request[control_plane.SegmentsRegistrationRequest]) (*connect.Response[control_plane.SegmentsRegistrationResponse], error) +} + +// NewSegmentRegistrationServiceHandler builds an HTTP handler from the service implementation. It +// returns the path on which to mount the handler and the handler itself. +// +// By default, handlers support the Connect, gRPC, and gRPC-Web protocols with the binary Protobuf +// and JSON codecs. They also support gzip compression. +func NewSegmentRegistrationServiceHandler(svc SegmentRegistrationServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) { + segmentRegistrationServiceSegmentsRegistrationHandler := connect.NewUnaryHandler( + SegmentRegistrationServiceSegmentsRegistrationProcedure, + svc.SegmentsRegistration, + connect.WithSchema(segmentRegistrationServiceSegmentsRegistrationMethodDescriptor), + connect.WithHandlerOptions(opts...), + ) + return "/proto.control_plane.v1.SegmentRegistrationService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + switch r.URL.Path { + case SegmentRegistrationServiceSegmentsRegistrationProcedure: + segmentRegistrationServiceSegmentsRegistrationHandler.ServeHTTP(w, r) + default: + http.NotFound(w, r) + } + }) +} + +// UnimplementedSegmentRegistrationServiceHandler returns CodeUnimplemented from all methods. +type UnimplementedSegmentRegistrationServiceHandler struct{} + +func (UnimplementedSegmentRegistrationServiceHandler) SegmentsRegistration(context.Context, *connect.Request[control_plane.SegmentsRegistrationRequest]) (*connect.Response[control_plane.SegmentsRegistrationResponse], error) { + return nil, connect.NewError(connect.CodeUnimplemented, errors.New("proto.control_plane.v1.SegmentRegistrationService.SegmentsRegistration is not implemented")) +} + +// SegmentCreationServiceClient is a client for the proto.control_plane.v1.SegmentCreationService +// service. +type SegmentCreationServiceClient interface { + // Beacon sends a beacon to the remote. + Beacon(context.Context, *connect.Request[control_plane.BeaconRequest]) (*connect.Response[control_plane.BeaconResponse], error) +} + +// NewSegmentCreationServiceClient constructs a client for the +// proto.control_plane.v1.SegmentCreationService service. By default, it uses the Connect protocol +// with the binary Protobuf Codec, asks for gzipped responses, and sends uncompressed requests. To +// use the gRPC or gRPC-Web protocols, supply the connect.WithGRPC() or connect.WithGRPCWeb() +// options. +// +// The URL supplied here should be the base URL for the Connect or gRPC server (for example, +// http://api.acme.com or https://acme.com/grpc). +func NewSegmentCreationServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) SegmentCreationServiceClient { + baseURL = strings.TrimRight(baseURL, "/") + return &segmentCreationServiceClient{ + beacon: connect.NewClient[control_plane.BeaconRequest, control_plane.BeaconResponse]( + httpClient, + baseURL+SegmentCreationServiceBeaconProcedure, + connect.WithSchema(segmentCreationServiceBeaconMethodDescriptor), + connect.WithClientOptions(opts...), + ), + } +} + +// segmentCreationServiceClient implements SegmentCreationServiceClient. +type segmentCreationServiceClient struct { + beacon *connect.Client[control_plane.BeaconRequest, control_plane.BeaconResponse] +} + +// Beacon calls proto.control_plane.v1.SegmentCreationService.Beacon. +func (c *segmentCreationServiceClient) Beacon(ctx context.Context, req *connect.Request[control_plane.BeaconRequest]) (*connect.Response[control_plane.BeaconResponse], error) { + return c.beacon.CallUnary(ctx, req) +} + +// SegmentCreationServiceHandler is an implementation of the +// proto.control_plane.v1.SegmentCreationService service. +type SegmentCreationServiceHandler interface { + // Beacon sends a beacon to the remote. + Beacon(context.Context, *connect.Request[control_plane.BeaconRequest]) (*connect.Response[control_plane.BeaconResponse], error) +} + +// NewSegmentCreationServiceHandler builds an HTTP handler from the service implementation. It +// returns the path on which to mount the handler and the handler itself. +// +// By default, handlers support the Connect, gRPC, and gRPC-Web protocols with the binary Protobuf +// and JSON codecs. They also support gzip compression. +func NewSegmentCreationServiceHandler(svc SegmentCreationServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) { + segmentCreationServiceBeaconHandler := connect.NewUnaryHandler( + SegmentCreationServiceBeaconProcedure, + svc.Beacon, + connect.WithSchema(segmentCreationServiceBeaconMethodDescriptor), + connect.WithHandlerOptions(opts...), + ) + return "/proto.control_plane.v1.SegmentCreationService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + switch r.URL.Path { + case SegmentCreationServiceBeaconProcedure: + segmentCreationServiceBeaconHandler.ServeHTTP(w, r) + default: + http.NotFound(w, r) + } + }) +} + +// UnimplementedSegmentCreationServiceHandler returns CodeUnimplemented from all methods. +type UnimplementedSegmentCreationServiceHandler struct{} + +func (UnimplementedSegmentCreationServiceHandler) Beacon(context.Context, *connect.Request[control_plane.BeaconRequest]) (*connect.Response[control_plane.BeaconResponse], error) { + return nil, connect.NewError(connect.CodeUnimplemented, errors.New("proto.control_plane.v1.SegmentCreationService.Beacon is not implemented")) +} diff --git a/pkg/proto/daemon/v1/daemonconnect/BUILD.bazel b/pkg/proto/daemon/v1/daemonconnect/BUILD.bazel new file mode 100644 index 0000000000..a6f265e61e --- /dev/null +++ b/pkg/proto/daemon/v1/daemonconnect/BUILD.bazel @@ -0,0 +1,13 @@ +load("//tools/lint:go.bzl", "go_library") + +go_library( + name = "go_default_library", + srcs = ["daemon.connect.go"], + importpath = "github.com/scionproto/scion/pkg/proto/daemon/v1/daemonconnect", + visibility = ["//visibility:public"], + deps = [ + "//pkg/proto/daemon:go_default_library", + "@com_connectrpc_connect//:go_default_library", + "@org_golang_google_protobuf//types/known/emptypb:go_default_library", + ], +) diff --git a/pkg/proto/daemon/v1/daemonconnect/daemon.connect.go b/pkg/proto/daemon/v1/daemonconnect/daemon.connect.go new file mode 100644 index 0000000000..1339a76bcf --- /dev/null +++ b/pkg/proto/daemon/v1/daemonconnect/daemon.connect.go @@ -0,0 +1,386 @@ +// Copyright 2020 Anapaya Systems +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-connect-go. DO NOT EDIT. +// +// Source: proto/daemon/v1/daemon.proto + +package daemonconnect + +import ( + connect "connectrpc.com/connect" + context "context" + errors "errors" + daemon "github.com/scionproto/scion/pkg/proto/daemon" + emptypb "google.golang.org/protobuf/types/known/emptypb" + http "net/http" + strings "strings" +) + +// This is a compile-time assertion to ensure that this generated file and the connect package are +// compatible. If you get a compiler error that this constant is not defined, this code was +// generated with a version of connect newer than the one compiled into your binary. You can fix the +// problem by either regenerating this code with an older version of connect or updating the connect +// version compiled into your binary. +const _ = connect.IsAtLeastVersion1_13_0 + +const ( + // DaemonServiceName is the fully-qualified name of the DaemonService service. + DaemonServiceName = "proto.daemon.v1.DaemonService" +) + +// These constants are the fully-qualified names of the RPCs defined in this package. They're +// exposed at runtime as Spec.Procedure and as the final two segments of the HTTP route. +// +// Note that these are different from the fully-qualified method names used by +// google.golang.org/protobuf/reflect/protoreflect. To convert from these constants to +// reflection-formatted method names, remove the leading slash and convert the remaining slash to a +// period. +const ( + // DaemonServicePathsProcedure is the fully-qualified name of the DaemonService's Paths RPC. + DaemonServicePathsProcedure = "/proto.daemon.v1.DaemonService/Paths" + // DaemonServiceASProcedure is the fully-qualified name of the DaemonService's AS RPC. + DaemonServiceASProcedure = "/proto.daemon.v1.DaemonService/AS" + // DaemonServiceInterfacesProcedure is the fully-qualified name of the DaemonService's Interfaces + // RPC. + DaemonServiceInterfacesProcedure = "/proto.daemon.v1.DaemonService/Interfaces" + // DaemonServiceServicesProcedure is the fully-qualified name of the DaemonService's Services RPC. + DaemonServiceServicesProcedure = "/proto.daemon.v1.DaemonService/Services" + // DaemonServiceNotifyInterfaceDownProcedure is the fully-qualified name of the DaemonService's + // NotifyInterfaceDown RPC. + DaemonServiceNotifyInterfaceDownProcedure = "/proto.daemon.v1.DaemonService/NotifyInterfaceDown" + // DaemonServicePortRangeProcedure is the fully-qualified name of the DaemonService's PortRange RPC. + DaemonServicePortRangeProcedure = "/proto.daemon.v1.DaemonService/PortRange" + // DaemonServiceDRKeyASHostProcedure is the fully-qualified name of the DaemonService's DRKeyASHost + // RPC. + DaemonServiceDRKeyASHostProcedure = "/proto.daemon.v1.DaemonService/DRKeyASHost" + // DaemonServiceDRKeyHostASProcedure is the fully-qualified name of the DaemonService's DRKeyHostAS + // RPC. + DaemonServiceDRKeyHostASProcedure = "/proto.daemon.v1.DaemonService/DRKeyHostAS" + // DaemonServiceDRKeyHostHostProcedure is the fully-qualified name of the DaemonService's + // DRKeyHostHost RPC. + DaemonServiceDRKeyHostHostProcedure = "/proto.daemon.v1.DaemonService/DRKeyHostHost" +) + +// These variables are the protoreflect.Descriptor objects for the RPCs defined in this package. +var ( + daemonServiceServiceDescriptor = daemon.File_proto_daemon_v1_daemon_proto.Services().ByName("DaemonService") + daemonServicePathsMethodDescriptor = daemonServiceServiceDescriptor.Methods().ByName("Paths") + daemonServiceASMethodDescriptor = daemonServiceServiceDescriptor.Methods().ByName("AS") + daemonServiceInterfacesMethodDescriptor = daemonServiceServiceDescriptor.Methods().ByName("Interfaces") + daemonServiceServicesMethodDescriptor = daemonServiceServiceDescriptor.Methods().ByName("Services") + daemonServiceNotifyInterfaceDownMethodDescriptor = daemonServiceServiceDescriptor.Methods().ByName("NotifyInterfaceDown") + daemonServicePortRangeMethodDescriptor = daemonServiceServiceDescriptor.Methods().ByName("PortRange") + daemonServiceDRKeyASHostMethodDescriptor = daemonServiceServiceDescriptor.Methods().ByName("DRKeyASHost") + daemonServiceDRKeyHostASMethodDescriptor = daemonServiceServiceDescriptor.Methods().ByName("DRKeyHostAS") + daemonServiceDRKeyHostHostMethodDescriptor = daemonServiceServiceDescriptor.Methods().ByName("DRKeyHostHost") +) + +// DaemonServiceClient is a client for the proto.daemon.v1.DaemonService service. +type DaemonServiceClient interface { + // Return a set of paths to the requested destination. + Paths(context.Context, *connect.Request[daemon.PathsRequest]) (*connect.Response[daemon.PathsResponse], error) + // Return information about an AS. + AS(context.Context, *connect.Request[daemon.ASRequest]) (*connect.Response[daemon.ASResponse], error) + // Return the underlay addresses associated with + // the specified interfaces. + Interfaces(context.Context, *connect.Request[daemon.InterfacesRequest]) (*connect.Response[daemon.InterfacesResponse], error) + // Return the underlay addresses associated with the + // specified services. + Services(context.Context, *connect.Request[daemon.ServicesRequest]) (*connect.Response[daemon.ServicesResponse], error) + // Inform the SCION Daemon of a revocation. + NotifyInterfaceDown(context.Context, *connect.Request[daemon.NotifyInterfaceDownRequest]) (*connect.Response[daemon.NotifyInterfaceDownResponse], error) + // Returns the endhost portRange defined in the local AS. + PortRange(context.Context, *connect.Request[emptypb.Empty]) (*connect.Response[daemon.PortRangeResponse], error) + // DRKeyASHost returns a key that matches the request. + DRKeyASHost(context.Context, *connect.Request[daemon.DRKeyASHostRequest]) (*connect.Response[daemon.DRKeyASHostResponse], error) + // DRKeyHostAS returns a key that matches the request. + DRKeyHostAS(context.Context, *connect.Request[daemon.DRKeyHostASRequest]) (*connect.Response[daemon.DRKeyHostASResponse], error) + // DRKeyHostHost returns a key that matches the request. + DRKeyHostHost(context.Context, *connect.Request[daemon.DRKeyHostHostRequest]) (*connect.Response[daemon.DRKeyHostHostResponse], error) +} + +// NewDaemonServiceClient constructs a client for the proto.daemon.v1.DaemonService service. By +// default, it uses the Connect protocol with the binary Protobuf Codec, asks for gzipped responses, +// and sends uncompressed requests. To use the gRPC or gRPC-Web protocols, supply the +// connect.WithGRPC() or connect.WithGRPCWeb() options. +// +// The URL supplied here should be the base URL for the Connect or gRPC server (for example, +// http://api.acme.com or https://acme.com/grpc). +func NewDaemonServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) DaemonServiceClient { + baseURL = strings.TrimRight(baseURL, "/") + return &daemonServiceClient{ + paths: connect.NewClient[daemon.PathsRequest, daemon.PathsResponse]( + httpClient, + baseURL+DaemonServicePathsProcedure, + connect.WithSchema(daemonServicePathsMethodDescriptor), + connect.WithClientOptions(opts...), + ), + aS: connect.NewClient[daemon.ASRequest, daemon.ASResponse]( + httpClient, + baseURL+DaemonServiceASProcedure, + connect.WithSchema(daemonServiceASMethodDescriptor), + connect.WithClientOptions(opts...), + ), + interfaces: connect.NewClient[daemon.InterfacesRequest, daemon.InterfacesResponse]( + httpClient, + baseURL+DaemonServiceInterfacesProcedure, + connect.WithSchema(daemonServiceInterfacesMethodDescriptor), + connect.WithClientOptions(opts...), + ), + services: connect.NewClient[daemon.ServicesRequest, daemon.ServicesResponse]( + httpClient, + baseURL+DaemonServiceServicesProcedure, + connect.WithSchema(daemonServiceServicesMethodDescriptor), + connect.WithClientOptions(opts...), + ), + notifyInterfaceDown: connect.NewClient[daemon.NotifyInterfaceDownRequest, daemon.NotifyInterfaceDownResponse]( + httpClient, + baseURL+DaemonServiceNotifyInterfaceDownProcedure, + connect.WithSchema(daemonServiceNotifyInterfaceDownMethodDescriptor), + connect.WithClientOptions(opts...), + ), + portRange: connect.NewClient[emptypb.Empty, daemon.PortRangeResponse]( + httpClient, + baseURL+DaemonServicePortRangeProcedure, + connect.WithSchema(daemonServicePortRangeMethodDescriptor), + connect.WithClientOptions(opts...), + ), + dRKeyASHost: connect.NewClient[daemon.DRKeyASHostRequest, daemon.DRKeyASHostResponse]( + httpClient, + baseURL+DaemonServiceDRKeyASHostProcedure, + connect.WithSchema(daemonServiceDRKeyASHostMethodDescriptor), + connect.WithClientOptions(opts...), + ), + dRKeyHostAS: connect.NewClient[daemon.DRKeyHostASRequest, daemon.DRKeyHostASResponse]( + httpClient, + baseURL+DaemonServiceDRKeyHostASProcedure, + connect.WithSchema(daemonServiceDRKeyHostASMethodDescriptor), + connect.WithClientOptions(opts...), + ), + dRKeyHostHost: connect.NewClient[daemon.DRKeyHostHostRequest, daemon.DRKeyHostHostResponse]( + httpClient, + baseURL+DaemonServiceDRKeyHostHostProcedure, + connect.WithSchema(daemonServiceDRKeyHostHostMethodDescriptor), + connect.WithClientOptions(opts...), + ), + } +} + +// daemonServiceClient implements DaemonServiceClient. +type daemonServiceClient struct { + paths *connect.Client[daemon.PathsRequest, daemon.PathsResponse] + aS *connect.Client[daemon.ASRequest, daemon.ASResponse] + interfaces *connect.Client[daemon.InterfacesRequest, daemon.InterfacesResponse] + services *connect.Client[daemon.ServicesRequest, daemon.ServicesResponse] + notifyInterfaceDown *connect.Client[daemon.NotifyInterfaceDownRequest, daemon.NotifyInterfaceDownResponse] + portRange *connect.Client[emptypb.Empty, daemon.PortRangeResponse] + dRKeyASHost *connect.Client[daemon.DRKeyASHostRequest, daemon.DRKeyASHostResponse] + dRKeyHostAS *connect.Client[daemon.DRKeyHostASRequest, daemon.DRKeyHostASResponse] + dRKeyHostHost *connect.Client[daemon.DRKeyHostHostRequest, daemon.DRKeyHostHostResponse] +} + +// Paths calls proto.daemon.v1.DaemonService.Paths. +func (c *daemonServiceClient) Paths(ctx context.Context, req *connect.Request[daemon.PathsRequest]) (*connect.Response[daemon.PathsResponse], error) { + return c.paths.CallUnary(ctx, req) +} + +// AS calls proto.daemon.v1.DaemonService.AS. +func (c *daemonServiceClient) AS(ctx context.Context, req *connect.Request[daemon.ASRequest]) (*connect.Response[daemon.ASResponse], error) { + return c.aS.CallUnary(ctx, req) +} + +// Interfaces calls proto.daemon.v1.DaemonService.Interfaces. +func (c *daemonServiceClient) Interfaces(ctx context.Context, req *connect.Request[daemon.InterfacesRequest]) (*connect.Response[daemon.InterfacesResponse], error) { + return c.interfaces.CallUnary(ctx, req) +} + +// Services calls proto.daemon.v1.DaemonService.Services. +func (c *daemonServiceClient) Services(ctx context.Context, req *connect.Request[daemon.ServicesRequest]) (*connect.Response[daemon.ServicesResponse], error) { + return c.services.CallUnary(ctx, req) +} + +// NotifyInterfaceDown calls proto.daemon.v1.DaemonService.NotifyInterfaceDown. +func (c *daemonServiceClient) NotifyInterfaceDown(ctx context.Context, req *connect.Request[daemon.NotifyInterfaceDownRequest]) (*connect.Response[daemon.NotifyInterfaceDownResponse], error) { + return c.notifyInterfaceDown.CallUnary(ctx, req) +} + +// PortRange calls proto.daemon.v1.DaemonService.PortRange. +func (c *daemonServiceClient) PortRange(ctx context.Context, req *connect.Request[emptypb.Empty]) (*connect.Response[daemon.PortRangeResponse], error) { + return c.portRange.CallUnary(ctx, req) +} + +// DRKeyASHost calls proto.daemon.v1.DaemonService.DRKeyASHost. +func (c *daemonServiceClient) DRKeyASHost(ctx context.Context, req *connect.Request[daemon.DRKeyASHostRequest]) (*connect.Response[daemon.DRKeyASHostResponse], error) { + return c.dRKeyASHost.CallUnary(ctx, req) +} + +// DRKeyHostAS calls proto.daemon.v1.DaemonService.DRKeyHostAS. +func (c *daemonServiceClient) DRKeyHostAS(ctx context.Context, req *connect.Request[daemon.DRKeyHostASRequest]) (*connect.Response[daemon.DRKeyHostASResponse], error) { + return c.dRKeyHostAS.CallUnary(ctx, req) +} + +// DRKeyHostHost calls proto.daemon.v1.DaemonService.DRKeyHostHost. +func (c *daemonServiceClient) DRKeyHostHost(ctx context.Context, req *connect.Request[daemon.DRKeyHostHostRequest]) (*connect.Response[daemon.DRKeyHostHostResponse], error) { + return c.dRKeyHostHost.CallUnary(ctx, req) +} + +// DaemonServiceHandler is an implementation of the proto.daemon.v1.DaemonService service. +type DaemonServiceHandler interface { + // Return a set of paths to the requested destination. + Paths(context.Context, *connect.Request[daemon.PathsRequest]) (*connect.Response[daemon.PathsResponse], error) + // Return information about an AS. + AS(context.Context, *connect.Request[daemon.ASRequest]) (*connect.Response[daemon.ASResponse], error) + // Return the underlay addresses associated with + // the specified interfaces. + Interfaces(context.Context, *connect.Request[daemon.InterfacesRequest]) (*connect.Response[daemon.InterfacesResponse], error) + // Return the underlay addresses associated with the + // specified services. + Services(context.Context, *connect.Request[daemon.ServicesRequest]) (*connect.Response[daemon.ServicesResponse], error) + // Inform the SCION Daemon of a revocation. + NotifyInterfaceDown(context.Context, *connect.Request[daemon.NotifyInterfaceDownRequest]) (*connect.Response[daemon.NotifyInterfaceDownResponse], error) + // Returns the endhost portRange defined in the local AS. + PortRange(context.Context, *connect.Request[emptypb.Empty]) (*connect.Response[daemon.PortRangeResponse], error) + // DRKeyASHost returns a key that matches the request. + DRKeyASHost(context.Context, *connect.Request[daemon.DRKeyASHostRequest]) (*connect.Response[daemon.DRKeyASHostResponse], error) + // DRKeyHostAS returns a key that matches the request. + DRKeyHostAS(context.Context, *connect.Request[daemon.DRKeyHostASRequest]) (*connect.Response[daemon.DRKeyHostASResponse], error) + // DRKeyHostHost returns a key that matches the request. + DRKeyHostHost(context.Context, *connect.Request[daemon.DRKeyHostHostRequest]) (*connect.Response[daemon.DRKeyHostHostResponse], error) +} + +// NewDaemonServiceHandler builds an HTTP handler from the service implementation. It returns the +// path on which to mount the handler and the handler itself. +// +// By default, handlers support the Connect, gRPC, and gRPC-Web protocols with the binary Protobuf +// and JSON codecs. They also support gzip compression. +func NewDaemonServiceHandler(svc DaemonServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) { + daemonServicePathsHandler := connect.NewUnaryHandler( + DaemonServicePathsProcedure, + svc.Paths, + connect.WithSchema(daemonServicePathsMethodDescriptor), + connect.WithHandlerOptions(opts...), + ) + daemonServiceASHandler := connect.NewUnaryHandler( + DaemonServiceASProcedure, + svc.AS, + connect.WithSchema(daemonServiceASMethodDescriptor), + connect.WithHandlerOptions(opts...), + ) + daemonServiceInterfacesHandler := connect.NewUnaryHandler( + DaemonServiceInterfacesProcedure, + svc.Interfaces, + connect.WithSchema(daemonServiceInterfacesMethodDescriptor), + connect.WithHandlerOptions(opts...), + ) + daemonServiceServicesHandler := connect.NewUnaryHandler( + DaemonServiceServicesProcedure, + svc.Services, + connect.WithSchema(daemonServiceServicesMethodDescriptor), + connect.WithHandlerOptions(opts...), + ) + daemonServiceNotifyInterfaceDownHandler := connect.NewUnaryHandler( + DaemonServiceNotifyInterfaceDownProcedure, + svc.NotifyInterfaceDown, + connect.WithSchema(daemonServiceNotifyInterfaceDownMethodDescriptor), + connect.WithHandlerOptions(opts...), + ) + daemonServicePortRangeHandler := connect.NewUnaryHandler( + DaemonServicePortRangeProcedure, + svc.PortRange, + connect.WithSchema(daemonServicePortRangeMethodDescriptor), + connect.WithHandlerOptions(opts...), + ) + daemonServiceDRKeyASHostHandler := connect.NewUnaryHandler( + DaemonServiceDRKeyASHostProcedure, + svc.DRKeyASHost, + connect.WithSchema(daemonServiceDRKeyASHostMethodDescriptor), + connect.WithHandlerOptions(opts...), + ) + daemonServiceDRKeyHostASHandler := connect.NewUnaryHandler( + DaemonServiceDRKeyHostASProcedure, + svc.DRKeyHostAS, + connect.WithSchema(daemonServiceDRKeyHostASMethodDescriptor), + connect.WithHandlerOptions(opts...), + ) + daemonServiceDRKeyHostHostHandler := connect.NewUnaryHandler( + DaemonServiceDRKeyHostHostProcedure, + svc.DRKeyHostHost, + connect.WithSchema(daemonServiceDRKeyHostHostMethodDescriptor), + connect.WithHandlerOptions(opts...), + ) + return "/proto.daemon.v1.DaemonService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + switch r.URL.Path { + case DaemonServicePathsProcedure: + daemonServicePathsHandler.ServeHTTP(w, r) + case DaemonServiceASProcedure: + daemonServiceASHandler.ServeHTTP(w, r) + case DaemonServiceInterfacesProcedure: + daemonServiceInterfacesHandler.ServeHTTP(w, r) + case DaemonServiceServicesProcedure: + daemonServiceServicesHandler.ServeHTTP(w, r) + case DaemonServiceNotifyInterfaceDownProcedure: + daemonServiceNotifyInterfaceDownHandler.ServeHTTP(w, r) + case DaemonServicePortRangeProcedure: + daemonServicePortRangeHandler.ServeHTTP(w, r) + case DaemonServiceDRKeyASHostProcedure: + daemonServiceDRKeyASHostHandler.ServeHTTP(w, r) + case DaemonServiceDRKeyHostASProcedure: + daemonServiceDRKeyHostASHandler.ServeHTTP(w, r) + case DaemonServiceDRKeyHostHostProcedure: + daemonServiceDRKeyHostHostHandler.ServeHTTP(w, r) + default: + http.NotFound(w, r) + } + }) +} + +// UnimplementedDaemonServiceHandler returns CodeUnimplemented from all methods. +type UnimplementedDaemonServiceHandler struct{} + +func (UnimplementedDaemonServiceHandler) Paths(context.Context, *connect.Request[daemon.PathsRequest]) (*connect.Response[daemon.PathsResponse], error) { + return nil, connect.NewError(connect.CodeUnimplemented, errors.New("proto.daemon.v1.DaemonService.Paths is not implemented")) +} + +func (UnimplementedDaemonServiceHandler) AS(context.Context, *connect.Request[daemon.ASRequest]) (*connect.Response[daemon.ASResponse], error) { + return nil, connect.NewError(connect.CodeUnimplemented, errors.New("proto.daemon.v1.DaemonService.AS is not implemented")) +} + +func (UnimplementedDaemonServiceHandler) Interfaces(context.Context, *connect.Request[daemon.InterfacesRequest]) (*connect.Response[daemon.InterfacesResponse], error) { + return nil, connect.NewError(connect.CodeUnimplemented, errors.New("proto.daemon.v1.DaemonService.Interfaces is not implemented")) +} + +func (UnimplementedDaemonServiceHandler) Services(context.Context, *connect.Request[daemon.ServicesRequest]) (*connect.Response[daemon.ServicesResponse], error) { + return nil, connect.NewError(connect.CodeUnimplemented, errors.New("proto.daemon.v1.DaemonService.Services is not implemented")) +} + +func (UnimplementedDaemonServiceHandler) NotifyInterfaceDown(context.Context, *connect.Request[daemon.NotifyInterfaceDownRequest]) (*connect.Response[daemon.NotifyInterfaceDownResponse], error) { + return nil, connect.NewError(connect.CodeUnimplemented, errors.New("proto.daemon.v1.DaemonService.NotifyInterfaceDown is not implemented")) +} + +func (UnimplementedDaemonServiceHandler) PortRange(context.Context, *connect.Request[emptypb.Empty]) (*connect.Response[daemon.PortRangeResponse], error) { + return nil, connect.NewError(connect.CodeUnimplemented, errors.New("proto.daemon.v1.DaemonService.PortRange is not implemented")) +} + +func (UnimplementedDaemonServiceHandler) DRKeyASHost(context.Context, *connect.Request[daemon.DRKeyASHostRequest]) (*connect.Response[daemon.DRKeyASHostResponse], error) { + return nil, connect.NewError(connect.CodeUnimplemented, errors.New("proto.daemon.v1.DaemonService.DRKeyASHost is not implemented")) +} + +func (UnimplementedDaemonServiceHandler) DRKeyHostAS(context.Context, *connect.Request[daemon.DRKeyHostASRequest]) (*connect.Response[daemon.DRKeyHostASResponse], error) { + return nil, connect.NewError(connect.CodeUnimplemented, errors.New("proto.daemon.v1.DaemonService.DRKeyHostAS is not implemented")) +} + +func (UnimplementedDaemonServiceHandler) DRKeyHostHost(context.Context, *connect.Request[daemon.DRKeyHostHostRequest]) (*connect.Response[daemon.DRKeyHostHostResponse], error) { + return nil, connect.NewError(connect.CodeUnimplemented, errors.New("proto.daemon.v1.DaemonService.DRKeyHostHost is not implemented")) +} diff --git a/pkg/proto/discovery/v1/discoveryconnect/BUILD.bazel b/pkg/proto/discovery/v1/discoveryconnect/BUILD.bazel new file mode 100644 index 0000000000..78d4f5d0b2 --- /dev/null +++ b/pkg/proto/discovery/v1/discoveryconnect/BUILD.bazel @@ -0,0 +1,12 @@ +load("//tools/lint:go.bzl", "go_library") + +go_library( + name = "go_default_library", + srcs = ["discovery.connect.go"], + importpath = "github.com/scionproto/scion/pkg/proto/discovery/v1/discoveryconnect", + visibility = ["//visibility:public"], + deps = [ + "//pkg/proto/discovery:go_default_library", + "@com_connectrpc_connect//:go_default_library", + ], +) diff --git a/pkg/proto/discovery/v1/discoveryconnect/discovery.connect.go b/pkg/proto/discovery/v1/discoveryconnect/discovery.connect.go new file mode 100644 index 0000000000..b637f67ea1 --- /dev/null +++ b/pkg/proto/discovery/v1/discoveryconnect/discovery.connect.go @@ -0,0 +1,161 @@ +// Copyright 2020 Anapaya Systems +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-connect-go. DO NOT EDIT. +// +// Source: proto/discovery/v1/discovery.proto + +package discoveryconnect + +import ( + connect "connectrpc.com/connect" + context "context" + errors "errors" + discovery "github.com/scionproto/scion/pkg/proto/discovery" + http "net/http" + strings "strings" +) + +// This is a compile-time assertion to ensure that this generated file and the connect package are +// compatible. If you get a compiler error that this constant is not defined, this code was +// generated with a version of connect newer than the one compiled into your binary. You can fix the +// problem by either regenerating this code with an older version of connect or updating the connect +// version compiled into your binary. +const _ = connect.IsAtLeastVersion1_13_0 + +const ( + // DiscoveryServiceName is the fully-qualified name of the DiscoveryService service. + DiscoveryServiceName = "proto.discovery.v1.DiscoveryService" +) + +// These constants are the fully-qualified names of the RPCs defined in this package. They're +// exposed at runtime as Spec.Procedure and as the final two segments of the HTTP route. +// +// Note that these are different from the fully-qualified method names used by +// google.golang.org/protobuf/reflect/protoreflect. To convert from these constants to +// reflection-formatted method names, remove the leading slash and convert the remaining slash to a +// period. +const ( + // DiscoveryServiceGatewaysProcedure is the fully-qualified name of the DiscoveryService's Gateways + // RPC. + DiscoveryServiceGatewaysProcedure = "/proto.discovery.v1.DiscoveryService/Gateways" + // DiscoveryServiceHiddenSegmentServicesProcedure is the fully-qualified name of the + // DiscoveryService's HiddenSegmentServices RPC. + DiscoveryServiceHiddenSegmentServicesProcedure = "/proto.discovery.v1.DiscoveryService/HiddenSegmentServices" +) + +// These variables are the protoreflect.Descriptor objects for the RPCs defined in this package. +var ( + discoveryServiceServiceDescriptor = discovery.File_proto_discovery_v1_discovery_proto.Services().ByName("DiscoveryService") + discoveryServiceGatewaysMethodDescriptor = discoveryServiceServiceDescriptor.Methods().ByName("Gateways") + discoveryServiceHiddenSegmentServicesMethodDescriptor = discoveryServiceServiceDescriptor.Methods().ByName("HiddenSegmentServices") +) + +// DiscoveryServiceClient is a client for the proto.discovery.v1.DiscoveryService service. +type DiscoveryServiceClient interface { + // Return the remote gateways. + Gateways(context.Context, *connect.Request[discovery.GatewaysRequest]) (*connect.Response[discovery.GatewaysResponse], error) + // Return the hidden segment services. + HiddenSegmentServices(context.Context, *connect.Request[discovery.HiddenSegmentServicesRequest]) (*connect.Response[discovery.HiddenSegmentServicesResponse], error) +} + +// NewDiscoveryServiceClient constructs a client for the proto.discovery.v1.DiscoveryService +// service. By default, it uses the Connect protocol with the binary Protobuf Codec, asks for +// gzipped responses, and sends uncompressed requests. To use the gRPC or gRPC-Web protocols, supply +// the connect.WithGRPC() or connect.WithGRPCWeb() options. +// +// The URL supplied here should be the base URL for the Connect or gRPC server (for example, +// http://api.acme.com or https://acme.com/grpc). +func NewDiscoveryServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) DiscoveryServiceClient { + baseURL = strings.TrimRight(baseURL, "/") + return &discoveryServiceClient{ + gateways: connect.NewClient[discovery.GatewaysRequest, discovery.GatewaysResponse]( + httpClient, + baseURL+DiscoveryServiceGatewaysProcedure, + connect.WithSchema(discoveryServiceGatewaysMethodDescriptor), + connect.WithClientOptions(opts...), + ), + hiddenSegmentServices: connect.NewClient[discovery.HiddenSegmentServicesRequest, discovery.HiddenSegmentServicesResponse]( + httpClient, + baseURL+DiscoveryServiceHiddenSegmentServicesProcedure, + connect.WithSchema(discoveryServiceHiddenSegmentServicesMethodDescriptor), + connect.WithClientOptions(opts...), + ), + } +} + +// discoveryServiceClient implements DiscoveryServiceClient. +type discoveryServiceClient struct { + gateways *connect.Client[discovery.GatewaysRequest, discovery.GatewaysResponse] + hiddenSegmentServices *connect.Client[discovery.HiddenSegmentServicesRequest, discovery.HiddenSegmentServicesResponse] +} + +// Gateways calls proto.discovery.v1.DiscoveryService.Gateways. +func (c *discoveryServiceClient) Gateways(ctx context.Context, req *connect.Request[discovery.GatewaysRequest]) (*connect.Response[discovery.GatewaysResponse], error) { + return c.gateways.CallUnary(ctx, req) +} + +// HiddenSegmentServices calls proto.discovery.v1.DiscoveryService.HiddenSegmentServices. +func (c *discoveryServiceClient) HiddenSegmentServices(ctx context.Context, req *connect.Request[discovery.HiddenSegmentServicesRequest]) (*connect.Response[discovery.HiddenSegmentServicesResponse], error) { + return c.hiddenSegmentServices.CallUnary(ctx, req) +} + +// DiscoveryServiceHandler is an implementation of the proto.discovery.v1.DiscoveryService service. +type DiscoveryServiceHandler interface { + // Return the remote gateways. + Gateways(context.Context, *connect.Request[discovery.GatewaysRequest]) (*connect.Response[discovery.GatewaysResponse], error) + // Return the hidden segment services. + HiddenSegmentServices(context.Context, *connect.Request[discovery.HiddenSegmentServicesRequest]) (*connect.Response[discovery.HiddenSegmentServicesResponse], error) +} + +// NewDiscoveryServiceHandler builds an HTTP handler from the service implementation. It returns the +// path on which to mount the handler and the handler itself. +// +// By default, handlers support the Connect, gRPC, and gRPC-Web protocols with the binary Protobuf +// and JSON codecs. They also support gzip compression. +func NewDiscoveryServiceHandler(svc DiscoveryServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) { + discoveryServiceGatewaysHandler := connect.NewUnaryHandler( + DiscoveryServiceGatewaysProcedure, + svc.Gateways, + connect.WithSchema(discoveryServiceGatewaysMethodDescriptor), + connect.WithHandlerOptions(opts...), + ) + discoveryServiceHiddenSegmentServicesHandler := connect.NewUnaryHandler( + DiscoveryServiceHiddenSegmentServicesProcedure, + svc.HiddenSegmentServices, + connect.WithSchema(discoveryServiceHiddenSegmentServicesMethodDescriptor), + connect.WithHandlerOptions(opts...), + ) + return "/proto.discovery.v1.DiscoveryService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + switch r.URL.Path { + case DiscoveryServiceGatewaysProcedure: + discoveryServiceGatewaysHandler.ServeHTTP(w, r) + case DiscoveryServiceHiddenSegmentServicesProcedure: + discoveryServiceHiddenSegmentServicesHandler.ServeHTTP(w, r) + default: + http.NotFound(w, r) + } + }) +} + +// UnimplementedDiscoveryServiceHandler returns CodeUnimplemented from all methods. +type UnimplementedDiscoveryServiceHandler struct{} + +func (UnimplementedDiscoveryServiceHandler) Gateways(context.Context, *connect.Request[discovery.GatewaysRequest]) (*connect.Response[discovery.GatewaysResponse], error) { + return nil, connect.NewError(connect.CodeUnimplemented, errors.New("proto.discovery.v1.DiscoveryService.Gateways is not implemented")) +} + +func (UnimplementedDiscoveryServiceHandler) HiddenSegmentServices(context.Context, *connect.Request[discovery.HiddenSegmentServicesRequest]) (*connect.Response[discovery.HiddenSegmentServicesResponse], error) { + return nil, connect.NewError(connect.CodeUnimplemented, errors.New("proto.discovery.v1.DiscoveryService.HiddenSegmentServices is not implemented")) +} diff --git a/pkg/proto/gateway/v1/gatewayconnect/BUILD.bazel b/pkg/proto/gateway/v1/gatewayconnect/BUILD.bazel new file mode 100644 index 0000000000..f0afd1ce6b --- /dev/null +++ b/pkg/proto/gateway/v1/gatewayconnect/BUILD.bazel @@ -0,0 +1,12 @@ +load("//tools/lint:go.bzl", "go_library") + +go_library( + name = "go_default_library", + srcs = ["prefix.connect.go"], + importpath = "github.com/scionproto/scion/pkg/proto/gateway/v1/gatewayconnect", + visibility = ["//visibility:public"], + deps = [ + "//pkg/proto/gateway:go_default_library", + "@com_connectrpc_connect//:go_default_library", + ], +) diff --git a/pkg/proto/gateway/v1/gatewayconnect/prefix.connect.go b/pkg/proto/gateway/v1/gatewayconnect/prefix.connect.go new file mode 100644 index 0000000000..a4c2d9f3cf --- /dev/null +++ b/pkg/proto/gateway/v1/gatewayconnect/prefix.connect.go @@ -0,0 +1,129 @@ +// Copyright 2020 Anapaya Systems +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-connect-go. DO NOT EDIT. +// +// Source: proto/gateway/v1/prefix.proto + +package gatewayconnect + +import ( + connect "connectrpc.com/connect" + context "context" + errors "errors" + gateway "github.com/scionproto/scion/pkg/proto/gateway" + http "net/http" + strings "strings" +) + +// This is a compile-time assertion to ensure that this generated file and the connect package are +// compatible. If you get a compiler error that this constant is not defined, this code was +// generated with a version of connect newer than the one compiled into your binary. You can fix the +// problem by either regenerating this code with an older version of connect or updating the connect +// version compiled into your binary. +const _ = connect.IsAtLeastVersion1_13_0 + +const ( + // IPPrefixesServiceName is the fully-qualified name of the IPPrefixesService service. + IPPrefixesServiceName = "proto.gateway.v1.IPPrefixesService" +) + +// These constants are the fully-qualified names of the RPCs defined in this package. They're +// exposed at runtime as Spec.Procedure and as the final two segments of the HTTP route. +// +// Note that these are different from the fully-qualified method names used by +// google.golang.org/protobuf/reflect/protoreflect. To convert from these constants to +// reflection-formatted method names, remove the leading slash and convert the remaining slash to a +// period. +const ( + // IPPrefixesServicePrefixesProcedure is the fully-qualified name of the IPPrefixesService's + // Prefixes RPC. + IPPrefixesServicePrefixesProcedure = "/proto.gateway.v1.IPPrefixesService/Prefixes" +) + +// These variables are the protoreflect.Descriptor objects for the RPCs defined in this package. +var ( + iPPrefixesServiceServiceDescriptor = gateway.File_proto_gateway_v1_prefix_proto.Services().ByName("IPPrefixesService") + iPPrefixesServicePrefixesMethodDescriptor = iPPrefixesServiceServiceDescriptor.Methods().ByName("Prefixes") +) + +// IPPrefixesServiceClient is a client for the proto.gateway.v1.IPPrefixesService service. +type IPPrefixesServiceClient interface { + // Prefixes requests the IP prefixes that can be reachable via the remote. + Prefixes(context.Context, *connect.Request[gateway.PrefixesRequest]) (*connect.Response[gateway.PrefixesResponse], error) +} + +// NewIPPrefixesServiceClient constructs a client for the proto.gateway.v1.IPPrefixesService +// service. By default, it uses the Connect protocol with the binary Protobuf Codec, asks for +// gzipped responses, and sends uncompressed requests. To use the gRPC or gRPC-Web protocols, supply +// the connect.WithGRPC() or connect.WithGRPCWeb() options. +// +// The URL supplied here should be the base URL for the Connect or gRPC server (for example, +// http://api.acme.com or https://acme.com/grpc). +func NewIPPrefixesServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) IPPrefixesServiceClient { + baseURL = strings.TrimRight(baseURL, "/") + return &iPPrefixesServiceClient{ + prefixes: connect.NewClient[gateway.PrefixesRequest, gateway.PrefixesResponse]( + httpClient, + baseURL+IPPrefixesServicePrefixesProcedure, + connect.WithSchema(iPPrefixesServicePrefixesMethodDescriptor), + connect.WithClientOptions(opts...), + ), + } +} + +// iPPrefixesServiceClient implements IPPrefixesServiceClient. +type iPPrefixesServiceClient struct { + prefixes *connect.Client[gateway.PrefixesRequest, gateway.PrefixesResponse] +} + +// Prefixes calls proto.gateway.v1.IPPrefixesService.Prefixes. +func (c *iPPrefixesServiceClient) Prefixes(ctx context.Context, req *connect.Request[gateway.PrefixesRequest]) (*connect.Response[gateway.PrefixesResponse], error) { + return c.prefixes.CallUnary(ctx, req) +} + +// IPPrefixesServiceHandler is an implementation of the proto.gateway.v1.IPPrefixesService service. +type IPPrefixesServiceHandler interface { + // Prefixes requests the IP prefixes that can be reachable via the remote. + Prefixes(context.Context, *connect.Request[gateway.PrefixesRequest]) (*connect.Response[gateway.PrefixesResponse], error) +} + +// NewIPPrefixesServiceHandler builds an HTTP handler from the service implementation. It returns +// the path on which to mount the handler and the handler itself. +// +// By default, handlers support the Connect, gRPC, and gRPC-Web protocols with the binary Protobuf +// and JSON codecs. They also support gzip compression. +func NewIPPrefixesServiceHandler(svc IPPrefixesServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) { + iPPrefixesServicePrefixesHandler := connect.NewUnaryHandler( + IPPrefixesServicePrefixesProcedure, + svc.Prefixes, + connect.WithSchema(iPPrefixesServicePrefixesMethodDescriptor), + connect.WithHandlerOptions(opts...), + ) + return "/proto.gateway.v1.IPPrefixesService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + switch r.URL.Path { + case IPPrefixesServicePrefixesProcedure: + iPPrefixesServicePrefixesHandler.ServeHTTP(w, r) + default: + http.NotFound(w, r) + } + }) +} + +// UnimplementedIPPrefixesServiceHandler returns CodeUnimplemented from all methods. +type UnimplementedIPPrefixesServiceHandler struct{} + +func (UnimplementedIPPrefixesServiceHandler) Prefixes(context.Context, *connect.Request[gateway.PrefixesRequest]) (*connect.Response[gateway.PrefixesResponse], error) { + return nil, connect.NewError(connect.CodeUnimplemented, errors.New("proto.gateway.v1.IPPrefixesService.Prefixes is not implemented")) +} diff --git a/pkg/proto/hidden_segment/v1/hidden_segmentconnect/BUILD.bazel b/pkg/proto/hidden_segment/v1/hidden_segmentconnect/BUILD.bazel new file mode 100644 index 0000000000..9eb31bab46 --- /dev/null +++ b/pkg/proto/hidden_segment/v1/hidden_segmentconnect/BUILD.bazel @@ -0,0 +1,12 @@ +load("//tools/lint:go.bzl", "go_library") + +go_library( + name = "go_default_library", + srcs = ["hidden_segment.connect.go"], + importpath = "github.com/scionproto/scion/pkg/proto/hidden_segment/v1/hidden_segmentconnect", + visibility = ["//visibility:public"], + deps = [ + "//pkg/proto/hidden_segment:go_default_library", + "@com_connectrpc_connect//:go_default_library", + ], +) diff --git a/pkg/proto/hidden_segment/v1/hidden_segmentconnect/hidden_segment.connect.go b/pkg/proto/hidden_segment/v1/hidden_segmentconnect/hidden_segment.connect.go new file mode 100644 index 0000000000..1bcaf8629a --- /dev/null +++ b/pkg/proto/hidden_segment/v1/hidden_segmentconnect/hidden_segment.connect.go @@ -0,0 +1,300 @@ +// Copyright 2020 Anapaya Systems +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-connect-go. DO NOT EDIT. +// +// Source: proto/hidden_segment/v1/hidden_segment.proto + +package hidden_segmentconnect + +import ( + connect "connectrpc.com/connect" + context "context" + errors "errors" + hidden_segment "github.com/scionproto/scion/pkg/proto/hidden_segment" + http "net/http" + strings "strings" +) + +// This is a compile-time assertion to ensure that this generated file and the connect package are +// compatible. If you get a compiler error that this constant is not defined, this code was +// generated with a version of connect newer than the one compiled into your binary. You can fix the +// problem by either regenerating this code with an older version of connect or updating the connect +// version compiled into your binary. +const _ = connect.IsAtLeastVersion1_13_0 + +const ( + // HiddenSegmentRegistrationServiceName is the fully-qualified name of the + // HiddenSegmentRegistrationService service. + HiddenSegmentRegistrationServiceName = "proto.hidden_segment.v1.HiddenSegmentRegistrationService" + // HiddenSegmentLookupServiceName is the fully-qualified name of the HiddenSegmentLookupService + // service. + HiddenSegmentLookupServiceName = "proto.hidden_segment.v1.HiddenSegmentLookupService" + // AuthoritativeHiddenSegmentLookupServiceName is the fully-qualified name of the + // AuthoritativeHiddenSegmentLookupService service. + AuthoritativeHiddenSegmentLookupServiceName = "proto.hidden_segment.v1.AuthoritativeHiddenSegmentLookupService" +) + +// These constants are the fully-qualified names of the RPCs defined in this package. They're +// exposed at runtime as Spec.Procedure and as the final two segments of the HTTP route. +// +// Note that these are different from the fully-qualified method names used by +// google.golang.org/protobuf/reflect/protoreflect. To convert from these constants to +// reflection-formatted method names, remove the leading slash and convert the remaining slash to a +// period. +const ( + // HiddenSegmentRegistrationServiceHiddenSegmentRegistrationProcedure is the fully-qualified name of + // the HiddenSegmentRegistrationService's HiddenSegmentRegistration RPC. + HiddenSegmentRegistrationServiceHiddenSegmentRegistrationProcedure = "/proto.hidden_segment.v1.HiddenSegmentRegistrationService/HiddenSegmentRegistration" + // HiddenSegmentLookupServiceHiddenSegmentsProcedure is the fully-qualified name of the + // HiddenSegmentLookupService's HiddenSegments RPC. + HiddenSegmentLookupServiceHiddenSegmentsProcedure = "/proto.hidden_segment.v1.HiddenSegmentLookupService/HiddenSegments" + // AuthoritativeHiddenSegmentLookupServiceAuthoritativeHiddenSegmentsProcedure is the + // fully-qualified name of the AuthoritativeHiddenSegmentLookupService's AuthoritativeHiddenSegments + // RPC. + AuthoritativeHiddenSegmentLookupServiceAuthoritativeHiddenSegmentsProcedure = "/proto.hidden_segment.v1.AuthoritativeHiddenSegmentLookupService/AuthoritativeHiddenSegments" +) + +// These variables are the protoreflect.Descriptor objects for the RPCs defined in this package. +var ( + hiddenSegmentRegistrationServiceServiceDescriptor = hidden_segment.File_proto_hidden_segment_v1_hidden_segment_proto.Services().ByName("HiddenSegmentRegistrationService") + hiddenSegmentRegistrationServiceHiddenSegmentRegistrationMethodDescriptor = hiddenSegmentRegistrationServiceServiceDescriptor.Methods().ByName("HiddenSegmentRegistration") + hiddenSegmentLookupServiceServiceDescriptor = hidden_segment.File_proto_hidden_segment_v1_hidden_segment_proto.Services().ByName("HiddenSegmentLookupService") + hiddenSegmentLookupServiceHiddenSegmentsMethodDescriptor = hiddenSegmentLookupServiceServiceDescriptor.Methods().ByName("HiddenSegments") + authoritativeHiddenSegmentLookupServiceServiceDescriptor = hidden_segment.File_proto_hidden_segment_v1_hidden_segment_proto.Services().ByName("AuthoritativeHiddenSegmentLookupService") + authoritativeHiddenSegmentLookupServiceAuthoritativeHiddenSegmentsMethodDescriptor = authoritativeHiddenSegmentLookupServiceServiceDescriptor.Methods().ByName("AuthoritativeHiddenSegments") +) + +// HiddenSegmentRegistrationServiceClient is a client for the +// proto.hidden_segment.v1.HiddenSegmentRegistrationService service. +type HiddenSegmentRegistrationServiceClient interface { + // HiddenSegmentRegistration registers hidden segments at the remote. + HiddenSegmentRegistration(context.Context, *connect.Request[hidden_segment.HiddenSegmentRegistrationRequest]) (*connect.Response[hidden_segment.HiddenSegmentRegistrationResponse], error) +} + +// NewHiddenSegmentRegistrationServiceClient constructs a client for the +// proto.hidden_segment.v1.HiddenSegmentRegistrationService service. By default, it uses the Connect +// protocol with the binary Protobuf Codec, asks for gzipped responses, and sends uncompressed +// requests. To use the gRPC or gRPC-Web protocols, supply the connect.WithGRPC() or +// connect.WithGRPCWeb() options. +// +// The URL supplied here should be the base URL for the Connect or gRPC server (for example, +// http://api.acme.com or https://acme.com/grpc). +func NewHiddenSegmentRegistrationServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) HiddenSegmentRegistrationServiceClient { + baseURL = strings.TrimRight(baseURL, "/") + return &hiddenSegmentRegistrationServiceClient{ + hiddenSegmentRegistration: connect.NewClient[hidden_segment.HiddenSegmentRegistrationRequest, hidden_segment.HiddenSegmentRegistrationResponse]( + httpClient, + baseURL+HiddenSegmentRegistrationServiceHiddenSegmentRegistrationProcedure, + connect.WithSchema(hiddenSegmentRegistrationServiceHiddenSegmentRegistrationMethodDescriptor), + connect.WithClientOptions(opts...), + ), + } +} + +// hiddenSegmentRegistrationServiceClient implements HiddenSegmentRegistrationServiceClient. +type hiddenSegmentRegistrationServiceClient struct { + hiddenSegmentRegistration *connect.Client[hidden_segment.HiddenSegmentRegistrationRequest, hidden_segment.HiddenSegmentRegistrationResponse] +} + +// HiddenSegmentRegistration calls +// proto.hidden_segment.v1.HiddenSegmentRegistrationService.HiddenSegmentRegistration. +func (c *hiddenSegmentRegistrationServiceClient) HiddenSegmentRegistration(ctx context.Context, req *connect.Request[hidden_segment.HiddenSegmentRegistrationRequest]) (*connect.Response[hidden_segment.HiddenSegmentRegistrationResponse], error) { + return c.hiddenSegmentRegistration.CallUnary(ctx, req) +} + +// HiddenSegmentRegistrationServiceHandler is an implementation of the +// proto.hidden_segment.v1.HiddenSegmentRegistrationService service. +type HiddenSegmentRegistrationServiceHandler interface { + // HiddenSegmentRegistration registers hidden segments at the remote. + HiddenSegmentRegistration(context.Context, *connect.Request[hidden_segment.HiddenSegmentRegistrationRequest]) (*connect.Response[hidden_segment.HiddenSegmentRegistrationResponse], error) +} + +// NewHiddenSegmentRegistrationServiceHandler builds an HTTP handler from the service +// implementation. It returns the path on which to mount the handler and the handler itself. +// +// By default, handlers support the Connect, gRPC, and gRPC-Web protocols with the binary Protobuf +// and JSON codecs. They also support gzip compression. +func NewHiddenSegmentRegistrationServiceHandler(svc HiddenSegmentRegistrationServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) { + hiddenSegmentRegistrationServiceHiddenSegmentRegistrationHandler := connect.NewUnaryHandler( + HiddenSegmentRegistrationServiceHiddenSegmentRegistrationProcedure, + svc.HiddenSegmentRegistration, + connect.WithSchema(hiddenSegmentRegistrationServiceHiddenSegmentRegistrationMethodDescriptor), + connect.WithHandlerOptions(opts...), + ) + return "/proto.hidden_segment.v1.HiddenSegmentRegistrationService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + switch r.URL.Path { + case HiddenSegmentRegistrationServiceHiddenSegmentRegistrationProcedure: + hiddenSegmentRegistrationServiceHiddenSegmentRegistrationHandler.ServeHTTP(w, r) + default: + http.NotFound(w, r) + } + }) +} + +// UnimplementedHiddenSegmentRegistrationServiceHandler returns CodeUnimplemented from all methods. +type UnimplementedHiddenSegmentRegistrationServiceHandler struct{} + +func (UnimplementedHiddenSegmentRegistrationServiceHandler) HiddenSegmentRegistration(context.Context, *connect.Request[hidden_segment.HiddenSegmentRegistrationRequest]) (*connect.Response[hidden_segment.HiddenSegmentRegistrationResponse], error) { + return nil, connect.NewError(connect.CodeUnimplemented, errors.New("proto.hidden_segment.v1.HiddenSegmentRegistrationService.HiddenSegmentRegistration is not implemented")) +} + +// HiddenSegmentLookupServiceClient is a client for the +// proto.hidden_segment.v1.HiddenSegmentLookupService service. +type HiddenSegmentLookupServiceClient interface { + // HiddenSegments returns all segments that match the request. + HiddenSegments(context.Context, *connect.Request[hidden_segment.HiddenSegmentsRequest]) (*connect.Response[hidden_segment.HiddenSegmentsResponse], error) +} + +// NewHiddenSegmentLookupServiceClient constructs a client for the +// proto.hidden_segment.v1.HiddenSegmentLookupService service. By default, it uses the Connect +// protocol with the binary Protobuf Codec, asks for gzipped responses, and sends uncompressed +// requests. To use the gRPC or gRPC-Web protocols, supply the connect.WithGRPC() or +// connect.WithGRPCWeb() options. +// +// The URL supplied here should be the base URL for the Connect or gRPC server (for example, +// http://api.acme.com or https://acme.com/grpc). +func NewHiddenSegmentLookupServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) HiddenSegmentLookupServiceClient { + baseURL = strings.TrimRight(baseURL, "/") + return &hiddenSegmentLookupServiceClient{ + hiddenSegments: connect.NewClient[hidden_segment.HiddenSegmentsRequest, hidden_segment.HiddenSegmentsResponse]( + httpClient, + baseURL+HiddenSegmentLookupServiceHiddenSegmentsProcedure, + connect.WithSchema(hiddenSegmentLookupServiceHiddenSegmentsMethodDescriptor), + connect.WithClientOptions(opts...), + ), + } +} + +// hiddenSegmentLookupServiceClient implements HiddenSegmentLookupServiceClient. +type hiddenSegmentLookupServiceClient struct { + hiddenSegments *connect.Client[hidden_segment.HiddenSegmentsRequest, hidden_segment.HiddenSegmentsResponse] +} + +// HiddenSegments calls proto.hidden_segment.v1.HiddenSegmentLookupService.HiddenSegments. +func (c *hiddenSegmentLookupServiceClient) HiddenSegments(ctx context.Context, req *connect.Request[hidden_segment.HiddenSegmentsRequest]) (*connect.Response[hidden_segment.HiddenSegmentsResponse], error) { + return c.hiddenSegments.CallUnary(ctx, req) +} + +// HiddenSegmentLookupServiceHandler is an implementation of the +// proto.hidden_segment.v1.HiddenSegmentLookupService service. +type HiddenSegmentLookupServiceHandler interface { + // HiddenSegments returns all segments that match the request. + HiddenSegments(context.Context, *connect.Request[hidden_segment.HiddenSegmentsRequest]) (*connect.Response[hidden_segment.HiddenSegmentsResponse], error) +} + +// NewHiddenSegmentLookupServiceHandler builds an HTTP handler from the service implementation. It +// returns the path on which to mount the handler and the handler itself. +// +// By default, handlers support the Connect, gRPC, and gRPC-Web protocols with the binary Protobuf +// and JSON codecs. They also support gzip compression. +func NewHiddenSegmentLookupServiceHandler(svc HiddenSegmentLookupServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) { + hiddenSegmentLookupServiceHiddenSegmentsHandler := connect.NewUnaryHandler( + HiddenSegmentLookupServiceHiddenSegmentsProcedure, + svc.HiddenSegments, + connect.WithSchema(hiddenSegmentLookupServiceHiddenSegmentsMethodDescriptor), + connect.WithHandlerOptions(opts...), + ) + return "/proto.hidden_segment.v1.HiddenSegmentLookupService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + switch r.URL.Path { + case HiddenSegmentLookupServiceHiddenSegmentsProcedure: + hiddenSegmentLookupServiceHiddenSegmentsHandler.ServeHTTP(w, r) + default: + http.NotFound(w, r) + } + }) +} + +// UnimplementedHiddenSegmentLookupServiceHandler returns CodeUnimplemented from all methods. +type UnimplementedHiddenSegmentLookupServiceHandler struct{} + +func (UnimplementedHiddenSegmentLookupServiceHandler) HiddenSegments(context.Context, *connect.Request[hidden_segment.HiddenSegmentsRequest]) (*connect.Response[hidden_segment.HiddenSegmentsResponse], error) { + return nil, connect.NewError(connect.CodeUnimplemented, errors.New("proto.hidden_segment.v1.HiddenSegmentLookupService.HiddenSegments is not implemented")) +} + +// AuthoritativeHiddenSegmentLookupServiceClient is a client for the +// proto.hidden_segment.v1.AuthoritativeHiddenSegmentLookupService service. +type AuthoritativeHiddenSegmentLookupServiceClient interface { + // HiddenSegments returns all segments that match the request. + AuthoritativeHiddenSegments(context.Context, *connect.Request[hidden_segment.AuthoritativeHiddenSegmentsRequest]) (*connect.Response[hidden_segment.AuthoritativeHiddenSegmentsResponse], error) +} + +// NewAuthoritativeHiddenSegmentLookupServiceClient constructs a client for the +// proto.hidden_segment.v1.AuthoritativeHiddenSegmentLookupService service. By default, it uses the +// Connect protocol with the binary Protobuf Codec, asks for gzipped responses, and sends +// uncompressed requests. To use the gRPC or gRPC-Web protocols, supply the connect.WithGRPC() or +// connect.WithGRPCWeb() options. +// +// The URL supplied here should be the base URL for the Connect or gRPC server (for example, +// http://api.acme.com or https://acme.com/grpc). +func NewAuthoritativeHiddenSegmentLookupServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) AuthoritativeHiddenSegmentLookupServiceClient { + baseURL = strings.TrimRight(baseURL, "/") + return &authoritativeHiddenSegmentLookupServiceClient{ + authoritativeHiddenSegments: connect.NewClient[hidden_segment.AuthoritativeHiddenSegmentsRequest, hidden_segment.AuthoritativeHiddenSegmentsResponse]( + httpClient, + baseURL+AuthoritativeHiddenSegmentLookupServiceAuthoritativeHiddenSegmentsProcedure, + connect.WithSchema(authoritativeHiddenSegmentLookupServiceAuthoritativeHiddenSegmentsMethodDescriptor), + connect.WithClientOptions(opts...), + ), + } +} + +// authoritativeHiddenSegmentLookupServiceClient implements +// AuthoritativeHiddenSegmentLookupServiceClient. +type authoritativeHiddenSegmentLookupServiceClient struct { + authoritativeHiddenSegments *connect.Client[hidden_segment.AuthoritativeHiddenSegmentsRequest, hidden_segment.AuthoritativeHiddenSegmentsResponse] +} + +// AuthoritativeHiddenSegments calls +// proto.hidden_segment.v1.AuthoritativeHiddenSegmentLookupService.AuthoritativeHiddenSegments. +func (c *authoritativeHiddenSegmentLookupServiceClient) AuthoritativeHiddenSegments(ctx context.Context, req *connect.Request[hidden_segment.AuthoritativeHiddenSegmentsRequest]) (*connect.Response[hidden_segment.AuthoritativeHiddenSegmentsResponse], error) { + return c.authoritativeHiddenSegments.CallUnary(ctx, req) +} + +// AuthoritativeHiddenSegmentLookupServiceHandler is an implementation of the +// proto.hidden_segment.v1.AuthoritativeHiddenSegmentLookupService service. +type AuthoritativeHiddenSegmentLookupServiceHandler interface { + // HiddenSegments returns all segments that match the request. + AuthoritativeHiddenSegments(context.Context, *connect.Request[hidden_segment.AuthoritativeHiddenSegmentsRequest]) (*connect.Response[hidden_segment.AuthoritativeHiddenSegmentsResponse], error) +} + +// NewAuthoritativeHiddenSegmentLookupServiceHandler builds an HTTP handler from the service +// implementation. It returns the path on which to mount the handler and the handler itself. +// +// By default, handlers support the Connect, gRPC, and gRPC-Web protocols with the binary Protobuf +// and JSON codecs. They also support gzip compression. +func NewAuthoritativeHiddenSegmentLookupServiceHandler(svc AuthoritativeHiddenSegmentLookupServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) { + authoritativeHiddenSegmentLookupServiceAuthoritativeHiddenSegmentsHandler := connect.NewUnaryHandler( + AuthoritativeHiddenSegmentLookupServiceAuthoritativeHiddenSegmentsProcedure, + svc.AuthoritativeHiddenSegments, + connect.WithSchema(authoritativeHiddenSegmentLookupServiceAuthoritativeHiddenSegmentsMethodDescriptor), + connect.WithHandlerOptions(opts...), + ) + return "/proto.hidden_segment.v1.AuthoritativeHiddenSegmentLookupService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + switch r.URL.Path { + case AuthoritativeHiddenSegmentLookupServiceAuthoritativeHiddenSegmentsProcedure: + authoritativeHiddenSegmentLookupServiceAuthoritativeHiddenSegmentsHandler.ServeHTTP(w, r) + default: + http.NotFound(w, r) + } + }) +} + +// UnimplementedAuthoritativeHiddenSegmentLookupServiceHandler returns CodeUnimplemented from all +// methods. +type UnimplementedAuthoritativeHiddenSegmentLookupServiceHandler struct{} + +func (UnimplementedAuthoritativeHiddenSegmentLookupServiceHandler) AuthoritativeHiddenSegments(context.Context, *connect.Request[hidden_segment.AuthoritativeHiddenSegmentsRequest]) (*connect.Response[hidden_segment.AuthoritativeHiddenSegmentsResponse], error) { + return nil, connect.NewError(connect.CodeUnimplemented, errors.New("proto.hidden_segment.v1.AuthoritativeHiddenSegmentLookupService.AuthoritativeHiddenSegments is not implemented")) +} diff --git a/private/app/xbazel/BUILD.bazel b/private/app/xbazel/BUILD.bazel new file mode 100644 index 0000000000..57c773acb4 --- /dev/null +++ b/private/app/xbazel/BUILD.bazel @@ -0,0 +1,9 @@ +load("//tools/lint:go.bzl", "go_library") + +go_library( + name = "go_default_library", + srcs = ["xbazel.go"], + importpath = "github.com/scionproto/scion/private/app/xbazel", + visibility = ["//visibility:public"], + deps = ["//private/must:go_default_library"], +) diff --git a/private/app/xbazel/xbazel.go b/private/app/xbazel/xbazel.go new file mode 100644 index 0000000000..a8b9a1aa6b --- /dev/null +++ b/private/app/xbazel/xbazel.go @@ -0,0 +1,95 @@ +// Copyright 2024 Anapaya Systems +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package xbazel + +import ( + "fmt" + "os" + "os/exec" + "path/filepath" + "strings" + + "github.com/scionproto/scion/private/must" +) + +const binDir = "bazel-out/k8-fastbuild/bin/" + +var runfilesDir = must.Get(filepath.Abs(".")) + +// ResolveExecutable resolves the absolute path of an executable from an +// environment variable. If the environment variable is a relative path, it is +// resolved to the CWD at initialziation time. +// +// It is safe to call this function after calling ChdirRoot. +func ResolveExecutable(env string) string { + bin, err := resolveExecutable(env) + if err != nil { + fmt.Fprintf(os.Stderr, "Failed to lookup %q: %s\n", env, err) + os.Exit(42) + } + return bin +} + +func resolveExecutable(env string) (string, error) { + rel := os.Getenv(env) + if rel == "" { + return "", fmt.Errorf("environment variable %s not set", env) + } + + abs, err := resolveFile(rel) + if err != nil { + return "", fmt.Errorf("resolving executable %s: %w", rel, err) + } + + if _, err := exec.LookPath(abs); err != nil { + return "", fmt.Errorf("ensure executable %s: %w", abs, err) + } + return abs, nil +} + +func resolveFile(file string) (string, error) { + // XXX: Strip the bin directory from the file path. This is required for + // some go binaries. + if strings.HasPrefix(filepath.ToSlash(file), binDir) { + var err error + if file, err = filepath.Rel(binDir, file); err != nil { + return "", err + } + } + + if !filepath.IsAbs(file) { + file = filepath.Join(runfilesDir, file) + } + + abs, err := filepath.Abs(file) + if err != nil { + return "", fmt.Errorf("resolve absolute path: %w", err) + } + if _, err := os.Stat(abs); err != nil { + return "", fmt.Errorf("ensure exists %s: %w", abs, err) + } + return abs, nil +} + +// ChdirRoot changes the working directory to the root of the bazel workspace. +// It is safe to use ResovleExecutable after calling this function. +func ChdirRoot() { + if bazelRoot := os.Getenv("BUILD_WORKSPACE_DIRECTORY"); bazelRoot != "" { + if err := os.Chdir(bazelRoot); err != nil { + fmt.Fprintf(os.Stderr, "Error: %s\n", err) + os.Exit(43) + } + } +} diff --git a/private/must/BUILD.bazel b/private/must/BUILD.bazel new file mode 100644 index 0000000000..a38b98d30c --- /dev/null +++ b/private/must/BUILD.bazel @@ -0,0 +1,8 @@ +load("//tools/lint:go.bzl", "go_library") + +go_library( + name = "go_default_library", + srcs = ["must.go"], + importpath = "github.com/scionproto/scion/private/must", + visibility = ["//visibility:public"], +) diff --git a/private/must/must.go b/private/must/must.go new file mode 100644 index 0000000000..3df16f66f9 --- /dev/null +++ b/private/must/must.go @@ -0,0 +1,30 @@ +// Copyright 2024 Anapaya Systems +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package must + +// Do panics if err is not nil. +func Do(err error) { + if err != nil { + panic("must: expected nil, got " + err.Error()) + } +} + +// Get panics if err is not nil. +func Get[T any](v T, err error) T { + if err != nil { + panic("must: expected nil, got " + err.Error()) + } + return v +} diff --git a/tools/buf/BUILD.bazel b/tools/buf/BUILD.bazel new file mode 100644 index 0000000000..6901647079 --- /dev/null +++ b/tools/buf/BUILD.bazel @@ -0,0 +1,27 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_binary") +load("//tools/lint:go.bzl", "go_library") + +go_library( + name = "go_default_library", + srcs = ["main.go"], + importpath = "github.com/scionproto/scion/tools/buf", + visibility = ["//visibility:private"], + deps = [ + "//private/app/xbazel:go_default_library", + "//private/must:go_default_library", + ], +) + +go_binary( + name = "buf", + data = [ + "@buf", + "@com_connectrpc_connect//cmd/protoc-gen-connect-go", + ], + embed = [":go_default_library"], + env = { + "PATH_BUF": "$(location @buf//:buf)", + "PATH_CONNECT": "$(location @com_connectrpc_connect//cmd/protoc-gen-connect-go)", + }, + visibility = ["//visibility:public"], +) diff --git a/tools/buf/deps.bzl b/tools/buf/deps.bzl new file mode 100644 index 0000000000..2b61b1a4d1 --- /dev/null +++ b/tools/buf/deps.bzl @@ -0,0 +1,10 @@ +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +def buf_dependencies(): + http_archive( + name = "buf", + build_file_content = "exports_files([\"buf\"])", + sha256 = "16253b6702dd447ef941b01c9c386a2ab7c8d20bbbc86a5efa5953270f6c9010", + strip_prefix = "buf/bin", + urls = ["https://github.com/bufbuild/buf/releases/download/v1.32.2/buf-Linux-x86_64.tar.gz"], + ) diff --git a/tools/buf/main.go b/tools/buf/main.go new file mode 100644 index 0000000000..64a071bffd --- /dev/null +++ b/tools/buf/main.go @@ -0,0 +1,61 @@ +// Copyright 2024 Anapaya Systems +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package main + +import ( + "encoding/json" + "fmt" + "os" + "os/exec" + "path/filepath" + + "github.com/scionproto/scion/private/app/xbazel" + "github.com/scionproto/scion/private/must" +) + +func main() { + xbazel.ChdirRoot() + + // Dynamically create the generation template. This is necessary to + // set the correct path of the protoc-gen-connect-go binary. + template := must.Get(json.Marshal(map[string]any{ + "version": "v2", + "plugins": []any{ + map[string]any{ + "local": xbazel.ResolveExecutable("PATH_CONNECT"), + "out": "pkg", + "opt": "paths=source_relative", + }, + }, + })) + + args := []string{ + "generate", + "--template", string(template), + } + for _, file := range must.Get(filepath.Glob("bazel-*")) { + args = append(args, "--exclude-path", file) + } + + buf := exec.Command(xbazel.ResolveExecutable("PATH_BUF"), args...) + buf.Stdin = os.Stdin + buf.Stdout = os.Stdout + buf.Stderr = os.Stderr + + if err := buf.Run(); err != nil { + fmt.Fprintf(os.Stderr, "Error: %s\n", err) + os.Exit(2) + } +} diff --git a/tools/buf/tools.go b/tools/buf/tools.go new file mode 100644 index 0000000000..e92713c602 --- /dev/null +++ b/tools/buf/tools.go @@ -0,0 +1,24 @@ +// Copyright 2024 Anapaya Systems +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//go:build tools + +package main + +import ( + // The bazel rule for buf uses protoc-gen-connect-go as a build tool. + // As an easy way to ensure that we have all the appropriate dependencies, + // import it here in this dummy go file. + _ "connectrpc.com/connect" +)