From 0673379443b36eac08c24e7d54d990bd222ca43b Mon Sep 17 00:00:00 2001 From: Stefan Majer Date: Thu, 3 Sep 2026 13:52:15 +0200 Subject: [PATCH 1/2] Update deps --- go.mod | 12 +++++------ go.sum | 20 +++++++++---------- js/buf/validate/validate_pb.d.ts | 12 +++++------ js/buf/validate/validate_pb.ts | 16 +++++++-------- js/metalstack/admin/v2/audit_pb.js | 2 +- js/metalstack/admin/v2/audit_pb.ts | 2 +- js/metalstack/admin/v2/component_pb.js | 2 +- js/metalstack/admin/v2/component_pb.ts | 2 +- js/metalstack/admin/v2/filesystem_pb.js | 2 +- js/metalstack/admin/v2/filesystem_pb.ts | 2 +- js/metalstack/admin/v2/image_pb.js | 2 +- js/metalstack/admin/v2/image_pb.ts | 2 +- js/metalstack/admin/v2/ip_pb.js | 2 +- js/metalstack/admin/v2/ip_pb.ts | 2 +- js/metalstack/admin/v2/machine_pb.js | 2 +- js/metalstack/admin/v2/machine_pb.ts | 2 +- js/metalstack/admin/v2/network_pb.js | 2 +- js/metalstack/admin/v2/network_pb.ts | 2 +- js/metalstack/admin/v2/partition_pb.js | 2 +- js/metalstack/admin/v2/partition_pb.ts | 2 +- js/metalstack/admin/v2/project_pb.js | 2 +- js/metalstack/admin/v2/project_pb.ts | 2 +- .../admin/v2/size_imageconstraint_pb.js | 2 +- .../admin/v2/size_imageconstraint_pb.ts | 2 +- js/metalstack/admin/v2/size_pb.js | 2 +- js/metalstack/admin/v2/size_pb.ts | 2 +- js/metalstack/admin/v2/size_reservation_pb.js | 2 +- js/metalstack/admin/v2/size_reservation_pb.ts | 2 +- js/metalstack/admin/v2/switch_pb.js | 2 +- js/metalstack/admin/v2/switch_pb.ts | 2 +- js/metalstack/admin/v2/task_pb.js | 2 +- js/metalstack/admin/v2/task_pb.ts | 2 +- js/metalstack/admin/v2/tenant_pb.js | 2 +- js/metalstack/admin/v2/tenant_pb.ts | 2 +- js/metalstack/admin/v2/token_pb.js | 2 +- js/metalstack/admin/v2/token_pb.ts | 2 +- js/metalstack/admin/v2/vpn_pb.js | 2 +- js/metalstack/admin/v2/vpn_pb.ts | 2 +- js/metalstack/api/v2/audit_pb.js | 2 +- js/metalstack/api/v2/audit_pb.ts | 2 +- js/metalstack/api/v2/common_pb.js | 2 +- js/metalstack/api/v2/common_pb.ts | 2 +- js/metalstack/api/v2/component_pb.js | 2 +- js/metalstack/api/v2/component_pb.ts | 2 +- js/metalstack/api/v2/filesystem_pb.js | 2 +- js/metalstack/api/v2/filesystem_pb.ts | 2 +- js/metalstack/api/v2/health_pb.js | 2 +- js/metalstack/api/v2/health_pb.ts | 2 +- js/metalstack/api/v2/image_pb.js | 2 +- js/metalstack/api/v2/image_pb.ts | 2 +- js/metalstack/api/v2/ip_pb.js | 2 +- js/metalstack/api/v2/ip_pb.ts | 2 +- js/metalstack/api/v2/machine_pb.js | 2 +- js/metalstack/api/v2/machine_pb.ts | 2 +- js/metalstack/api/v2/method_pb.js | 2 +- js/metalstack/api/v2/method_pb.ts | 2 +- js/metalstack/api/v2/network_pb.js | 2 +- js/metalstack/api/v2/network_pb.ts | 2 +- js/metalstack/api/v2/partition_pb.js | 2 +- js/metalstack/api/v2/partition_pb.ts | 2 +- js/metalstack/api/v2/predefined_rules_pb.js | 2 +- js/metalstack/api/v2/predefined_rules_pb.ts | 2 +- js/metalstack/api/v2/project_pb.js | 2 +- js/metalstack/api/v2/project_pb.ts | 2 +- .../api/v2/size_imageconstraint_pb.js | 2 +- .../api/v2/size_imageconstraint_pb.ts | 2 +- js/metalstack/api/v2/size_pb.js | 2 +- js/metalstack/api/v2/size_pb.ts | 2 +- js/metalstack/api/v2/size_reservation_pb.js | 2 +- js/metalstack/api/v2/size_reservation_pb.ts | 2 +- js/metalstack/api/v2/switch_pb.js | 2 +- js/metalstack/api/v2/switch_pb.ts | 2 +- js/metalstack/api/v2/tenant_pb.js | 2 +- js/metalstack/api/v2/tenant_pb.ts | 2 +- js/metalstack/api/v2/token_pb.js | 2 +- js/metalstack/api/v2/token_pb.ts | 2 +- js/metalstack/api/v2/user_pb.js | 2 +- js/metalstack/api/v2/user_pb.ts | 2 +- js/metalstack/api/v2/version_pb.js | 2 +- js/metalstack/api/v2/version_pb.ts | 2 +- js/metalstack/api/v2/vpn_pb.js | 2 +- js/metalstack/api/v2/vpn_pb.ts | 2 +- js/metalstack/infra/v2/bmc_pb.js | 2 +- js/metalstack/infra/v2/bmc_pb.ts | 2 +- js/metalstack/infra/v2/boot_pb.js | 2 +- js/metalstack/infra/v2/boot_pb.ts | 2 +- js/metalstack/infra/v2/component_pb.js | 2 +- js/metalstack/infra/v2/component_pb.ts | 2 +- js/metalstack/infra/v2/event_pb.js | 2 +- js/metalstack/infra/v2/event_pb.ts | 2 +- js/metalstack/infra/v2/switch_pb.js | 2 +- js/metalstack/infra/v2/switch_pb.ts | 2 +- proto/buf.gen.yaml | 6 +++--- proto/buf.lock | 4 ++-- python/buf/validate/validate_pb2.py | 4 ++-- python/metalstack/admin/v2/audit_pb2.py | 4 ++-- python/metalstack/admin/v2/component_pb2.py | 4 ++-- python/metalstack/admin/v2/filesystem_pb2.py | 4 ++-- python/metalstack/admin/v2/image_pb2.py | 4 ++-- python/metalstack/admin/v2/ip_pb2.py | 4 ++-- python/metalstack/admin/v2/machine_pb2.py | 4 ++-- python/metalstack/admin/v2/network_pb2.py | 4 ++-- python/metalstack/admin/v2/partition_pb2.py | 4 ++-- python/metalstack/admin/v2/project_pb2.py | 4 ++-- .../admin/v2/size_imageconstraint_pb2.py | 4 ++-- python/metalstack/admin/v2/size_pb2.py | 4 ++-- .../admin/v2/size_reservation_pb2.py | 4 ++-- python/metalstack/admin/v2/switch_pb2.py | 4 ++-- python/metalstack/admin/v2/task_pb2.py | 4 ++-- python/metalstack/admin/v2/tenant_pb2.py | 4 ++-- python/metalstack/admin/v2/token_pb2.py | 4 ++-- python/metalstack/admin/v2/vpn_pb2.py | 4 ++-- python/metalstack/api/v2/audit_pb2.py | 4 ++-- python/metalstack/api/v2/common_pb2.py | 4 ++-- python/metalstack/api/v2/component_pb2.py | 4 ++-- python/metalstack/api/v2/filesystem_pb2.py | 4 ++-- python/metalstack/api/v2/health_pb2.py | 4 ++-- python/metalstack/api/v2/image_pb2.py | 4 ++-- python/metalstack/api/v2/ip_pb2.py | 4 ++-- python/metalstack/api/v2/machine_pb2.py | 4 ++-- python/metalstack/api/v2/method_pb2.py | 4 ++-- python/metalstack/api/v2/network_pb2.py | 4 ++-- python/metalstack/api/v2/partition_pb2.py | 4 ++-- .../metalstack/api/v2/predefined_rules_pb2.py | 4 ++-- python/metalstack/api/v2/project_pb2.py | 4 ++-- .../api/v2/size_imageconstraint_pb2.py | 4 ++-- python/metalstack/api/v2/size_pb2.py | 4 ++-- .../metalstack/api/v2/size_reservation_pb2.py | 4 ++-- python/metalstack/api/v2/switch_pb2.py | 4 ++-- python/metalstack/api/v2/tenant_pb2.py | 4 ++-- python/metalstack/api/v2/token_pb2.py | 4 ++-- python/metalstack/api/v2/user_pb2.py | 4 ++-- python/metalstack/api/v2/version_pb2.py | 4 ++-- python/metalstack/api/v2/vpn_pb2.py | 4 ++-- python/metalstack/infra/v2/bmc_pb2.py | 4 ++-- python/metalstack/infra/v2/boot_pb2.py | 4 ++-- python/metalstack/infra/v2/component_pb2.py | 4 ++-- python/metalstack/infra/v2/event_pb2.py | 4 ++-- python/metalstack/infra/v2/switch_pb2.py | 4 ++-- 139 files changed, 213 insertions(+), 213 deletions(-) diff --git a/go.mod b/go.mod index 898d8aef..27a5ad28 100644 --- a/go.mod +++ b/go.mod @@ -1,10 +1,10 @@ module github.com/metal-stack/api -go 1.26.0 +go 1.27 require ( buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.12-20260825204119-511051f7f437.1 - buf.build/go/protovalidate v1.3.0 + buf.build/go/protovalidate v1.4.0 connectrpc.com/connect v1.20.0 github.com/bufbuild/protocompile v0.14.1 github.com/go-task/slim-sprig/v3 v3.0.0 @@ -18,15 +18,15 @@ require ( ) require ( + cel.dev/cel-go v0.32.0 // indirect cel.dev/expr v0.25.3 // indirect github.com/antlr4-go/antlr/v4 v4.13.1 // indirect - github.com/google/cel-go v0.31.0 // indirect - github.com/klauspost/compress v1.19.2 // indirect + github.com/klauspost/compress v1.20.0 // indirect github.com/minio/minlz v1.2.0 // indirect go.yaml.in/yaml/v3 v3.0.5 // indirect golang.org/x/exp v0.0.0-20260824195058-e88cd73687aa // indirect golang.org/x/sys v0.47.0 // indirect golang.org/x/text v0.41.0 // indirect - google.golang.org/genproto/googleapis/api v0.0.0-20260825221802-da73d73af1c5 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20260825221802-da73d73af1c5 // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20260831171406-18b4a7587f8a // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20260831171406-18b4a7587f8a // indirect ) diff --git a/go.sum b/go.sum index 4f0937c3..18a8f414 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,9 @@ buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.12-20260825204119-511051f7f437.1 h1:Slv0uGxx219srASyiaI5C9cDlyG8kNDcXpTSYcuAeE4= buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.12-20260825204119-511051f7f437.1/go.mod h1:TCt1lluMFnctISJXvkIQ4x3ABrPuUKCWKyjKdkJNBpw= -buf.build/go/protovalidate v1.3.0 h1:8ITcnZGkAHx6TyhZvro+iET/AyqU8gEWQJK2WsT62ms= -buf.build/go/protovalidate v1.3.0/go.mod h1:82s5g+rFRj1CZPiLv6OTA31jBu2fpq7mLXHwa9mZfEs= +buf.build/go/protovalidate v1.4.0 h1:UjLrYbt5VX7+TMOs2+pG5FhZhIG1mSfK4EIopbb4LcM= +buf.build/go/protovalidate v1.4.0/go.mod h1:8vJfzNT6NIG2qm3uFsJDXMlRmG+bQJzbcIn1Aa0vPGs= +cel.dev/cel-go v0.32.0 h1:irvpFKr5EuGPyxeME03ERh0rii1TX+BDAnB9eL3IvNk= +cel.dev/cel-go v0.32.0/go.mod h1:DnVip7tpJSsgZymwfT+m1tnEVy3ivAjSMXPx12YrMkU= cel.dev/expr v0.25.3 h1:A2jO8jwOugrrovveCWfj0KEZOfqiLgAcwjpHPhzIGw0= cel.dev/expr v0.25.3/go.mod h1:hrXvqGP6G6gyx8UAHSHJ5RGk//1Oj5nXQ2NI02Nrsg4= connectrpc.com/connect v1.20.0 h1:6TNDAB+WeNd2uolWNlYczB5E0KNNaVMNUEx8JEUsPmQ= @@ -18,14 +20,12 @@ github.com/golang-jwt/jwt/v5 v5.3.1 h1:kYf81DTWFe7t+1VvL7eS+jKFVWaUnK9cB1qbwn63Y github.com/golang-jwt/jwt/v5 v5.3.1/go.mod h1:fxCRLWMO43lRc8nhHWY6LGqRcf+1gQWArsqaEUEa5bE= github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= -github.com/google/cel-go v0.31.0 h1:H0bhpFTqOvmHrBGrWKp7ZlhBm5Hh8PYUEXnwxT1LL7A= -github.com/google/cel-go v0.31.0/go.mod h1:X0bD6iVNR8pkROSOoHVdgTkzmRcosof7WQqCD6wcMc8= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/klauspost/compress v1.19.2 h1:hMRETovs/pu/dVWN7zIT1PGG8t509MwT6bO7XSi26R8= -github.com/klauspost/compress v1.19.2/go.mod h1:cwPg85FWrGar70rWktvGQj8/hthj3wpl0PGDogxkrSQ= +github.com/klauspost/compress v1.20.0 h1:a3C1ke2ohxFymNlb2HWAHjDeKCI90scRskErZkR0ezA= +github.com/klauspost/compress v1.20.0/go.mod h1:LUdAzn7YLVvxLpc7y3V1m40wESHTgc1422pwwBSKYuI= github.com/klauspost/connect-compress/v2 v2.1.1 h1:ycZNp4rWOZBodVE2Ls5AzK4aHkyK+GteEfzRZgKNs+c= github.com/klauspost/connect-compress/v2 v2.1.1/go.mod h1:9oilsPHJMzGKkjafSBk9J7iVo4mO+dw0G0KSdVpnlVE= github.com/minio/minlz v1.2.0 h1:6IOBuiHg04QxvbFfgFLT/9sMaO/UhL7S+ApW1mK8q5A= @@ -44,10 +44,10 @@ golang.org/x/sys v0.47.0 h1:o7XGOvZQCADBQQ4Y7VNq2dRWQR7JmOUW8Kxx4ZsNgWs= golang.org/x/sys v0.47.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= golang.org/x/text v0.41.0 h1:vz/seA0lnX87Othu2f/0L24RcgrXD9/YFTSuGjj3rH8= golang.org/x/text v0.41.0/go.mod h1:jvf1O8ajNzZqhSrQBPbutR/EB83Cc0CFrezNQIwbb5M= -google.golang.org/genproto/googleapis/api v0.0.0-20260825221802-da73d73af1c5 h1:izFU9hz7aeLI/Mi1J0991ae+xcwRLr7hTqWnB/9aIIU= -google.golang.org/genproto/googleapis/api v0.0.0-20260825221802-da73d73af1c5/go.mod h1:3LhxRw4YYkf+ylAfgaY9JlVLFKhokkCV8duhLLe7+t0= -google.golang.org/genproto/googleapis/rpc v0.0.0-20260825221802-da73d73af1c5 h1:1VUiZAXyC+zmiFYi+WLtBzr68Cj8wOofHjjrA/kkizc= -google.golang.org/genproto/googleapis/rpc v0.0.0-20260825221802-da73d73af1c5/go.mod h1:DjtHYE8FKJLivXcBEjGwndXfIC23G0VpXiXKqG179uA= +google.golang.org/genproto/googleapis/api v0.0.0-20260831171406-18b4a7587f8a h1:i3TAXhpKc7TUP1VAPiBBrv45kamjoizCC3rOC0cAbOs= +google.golang.org/genproto/googleapis/api v0.0.0-20260831171406-18b4a7587f8a/go.mod h1:CvYJHpbzPlT0fb/PsgtAamdwru/GVxUsomFdXTpOTI8= +google.golang.org/genproto/googleapis/rpc v0.0.0-20260831171406-18b4a7587f8a h1:3Dnd1cDaZlB68lziofO+bJXpjOy8UfRv8Unt+yH8tQ4= +google.golang.org/genproto/googleapis/rpc v0.0.0-20260831171406-18b4a7587f8a/go.mod h1:DjtHYE8FKJLivXcBEjGwndXfIC23G0VpXiXKqG179uA= google.golang.org/grpc v1.83.2 h1:EManeRomTObA0BU7I8vXgg/78uE5MJ9M8B39EX2WscU= google.golang.org/grpc v1.83.2/go.mod h1:YPI1hK3kDked6iHvgX3tR0y+nX/qpMFKhPgFsokw1S8= google.golang.org/protobuf v1.36.12 h1:pJOKDDOyeXErUroCihFAd5LQuwXBSpVnKGrj5o/fwxc= diff --git a/js/buf/validate/validate_pb.d.ts b/js/buf/validate/validate_pb.d.ts index 8b4d2efb..910c2fde 100644 --- a/js/buf/validate/validate_pb.d.ts +++ b/js/buf/validate/validate_pb.d.ts @@ -9,7 +9,7 @@ export declare const file_buf_validate_validate: GenFile; * `Rule` represents a validation rule written in the Common Expression * Language (CEL) syntax. Each Rule includes a unique identifier, an * optional error message, and the CEL expression to evaluate. For more - * information, [see our documentation](https://buf.build/docs/protovalidate/schemas/custom-rules/). + * information, [see our documentation](https://protovalidate.com/schemas/custom-rules/). * * ```proto * message Foo { @@ -71,7 +71,7 @@ export type MessageRules = Message<"buf.validate.MessageRules"> & { * simpler syntax when defining CEL Rules where `id` and `message` derived from the `expression`. `id` will * be same as the `expression`. * - * For more information, [see our documentation](https://buf.build/docs/protovalidate/schemas/custom-rules/). + * For more information, [see our documentation](https://protovalidate.com/schemas/custom-rules/). * * ```proto * message MyMessage { @@ -89,7 +89,7 @@ export type MessageRules = Message<"buf.validate.MessageRules"> & { /** * `cel` is a repeated field of type Rule. Each Rule specifies a validation rule to be applied to this message. * These rules are written in Common Expression Language (CEL) syntax. For more information, - * [see our documentation](https://buf.build/docs/protovalidate/schemas/custom-rules/). + * [see our documentation](https://protovalidate.com/schemas/custom-rules/). * * * ```proto @@ -225,7 +225,7 @@ export type FieldRules = Message<"buf.validate.FieldRules"> & { * simpler syntax when defining CEL Rules where `id` and `message` derived from the `expression`. `id` will * be same as the `expression`. * - * For more information, [see our documentation](https://buf.build/docs/protovalidate/schemas/custom-rules/). + * For more information, [see our documentation](https://protovalidate.com/schemas/custom-rules/). * * ```proto * message MyMessage { @@ -240,7 +240,7 @@ export type FieldRules = Message<"buf.validate.FieldRules"> & { /** * `cel` is a repeated field used to represent a textual expression * in the Common Expression Language (CEL) syntax. For more information, - * [see our documentation](https://buf.build/docs/protovalidate/schemas/custom-rules/). + * [see our documentation](https://protovalidate.com/schemas/custom-rules/). * * ```proto * message MyMessage { @@ -495,7 +495,7 @@ export type PredefinedRules = Message<"buf.validate.PredefinedRules"> & { /** * `cel` is a repeated field used to represent a textual expression * in the Common Expression Language (CEL) syntax. For more information, - * [see our documentation](https://buf.build/docs/protovalidate/schemas/predefined-rules/). + * [see our documentation](https://protovalidate.com/schemas/predefined-rules/). * * ```proto * message MyMessage { diff --git a/js/buf/validate/validate_pb.ts b/js/buf/validate/validate_pb.ts index 641c80e6..fa726a2f 100644 --- a/js/buf/validate/validate_pb.ts +++ b/js/buf/validate/validate_pb.ts @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file buf/validate/validate.proto (package buf.validate, syntax proto2) /* eslint-disable */ @@ -42,7 +42,7 @@ // [Go](https://github.com/bufbuild/protovalidate-go), // [JavaScript/TypeScript](https://github.com/bufbuild/protovalidate-es), // [Java](https://github.com/bufbuild/protovalidate-java), -// [Python](https://github.com/bufbuild/protovalidate-python), +// [Python](https://github.com/bufbuild/protovalidate-py), // or [C++](https://github.com/bufbuild/protovalidate-cc). import type { GenEnum, GenExtension, GenFile, GenMessage } from "@bufbuild/protobuf/codegenv2"; @@ -61,7 +61,7 @@ export const file_buf_validate_validate: GenFile = /*@__PURE__*/ * `Rule` represents a validation rule written in the Common Expression * Language (CEL) syntax. Each Rule includes a unique identifier, an * optional error message, and the CEL expression to evaluate. For more - * information, [see our documentation](https://buf.build/docs/protovalidate/schemas/custom-rules/). + * information, [see our documentation](https://protovalidate.com/schemas/custom-rules/). * * ```proto * message Foo { @@ -128,7 +128,7 @@ export type MessageRules = Message<"buf.validate.MessageRules"> & { * simpler syntax when defining CEL Rules where `id` and `message` derived from the `expression`. `id` will * be same as the `expression`. * - * For more information, [see our documentation](https://buf.build/docs/protovalidate/schemas/custom-rules/). + * For more information, [see our documentation](https://protovalidate.com/schemas/custom-rules/). * * ```proto * message MyMessage { @@ -147,7 +147,7 @@ export type MessageRules = Message<"buf.validate.MessageRules"> & { /** * `cel` is a repeated field of type Rule. Each Rule specifies a validation rule to be applied to this message. * These rules are written in Common Expression Language (CEL) syntax. For more information, - * [see our documentation](https://buf.build/docs/protovalidate/schemas/custom-rules/). + * [see our documentation](https://protovalidate.com/schemas/custom-rules/). * * * ```proto @@ -294,7 +294,7 @@ export type FieldRules = Message<"buf.validate.FieldRules"> & { * simpler syntax when defining CEL Rules where `id` and `message` derived from the `expression`. `id` will * be same as the `expression`. * - * For more information, [see our documentation](https://buf.build/docs/protovalidate/schemas/custom-rules/). + * For more information, [see our documentation](https://protovalidate.com/schemas/custom-rules/). * * ```proto * message MyMessage { @@ -310,7 +310,7 @@ export type FieldRules = Message<"buf.validate.FieldRules"> & { /** * `cel` is a repeated field used to represent a textual expression * in the Common Expression Language (CEL) syntax. For more information, - * [see our documentation](https://buf.build/docs/protovalidate/schemas/custom-rules/). + * [see our documentation](https://protovalidate.com/schemas/custom-rules/). * * ```proto * message MyMessage { @@ -568,7 +568,7 @@ export type PredefinedRules = Message<"buf.validate.PredefinedRules"> & { /** * `cel` is a repeated field used to represent a textual expression * in the Common Expression Language (CEL) syntax. For more information, - * [see our documentation](https://buf.build/docs/protovalidate/schemas/predefined-rules/). + * [see our documentation](https://protovalidate.com/schemas/predefined-rules/). * * ```proto * message MyMessage { diff --git a/js/metalstack/admin/v2/audit_pb.js b/js/metalstack/admin/v2/audit_pb.js index 03de8736..c9e91546 100644 --- a/js/metalstack/admin/v2/audit_pb.js +++ b/js/metalstack/admin/v2/audit_pb.js @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/admin/v2/audit.proto (package metalstack.admin.v2, syntax proto3) /* eslint-disable */ import { fileDesc, messageDesc, serviceDesc } from "@bufbuild/protobuf/codegenv2"; diff --git a/js/metalstack/admin/v2/audit_pb.ts b/js/metalstack/admin/v2/audit_pb.ts index 626feff0..1f042517 100644 --- a/js/metalstack/admin/v2/audit_pb.ts +++ b/js/metalstack/admin/v2/audit_pb.ts @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/admin/v2/audit.proto (package metalstack.admin.v2, syntax proto3) /* eslint-disable */ diff --git a/js/metalstack/admin/v2/component_pb.js b/js/metalstack/admin/v2/component_pb.js index 432d58d0..0464335e 100644 --- a/js/metalstack/admin/v2/component_pb.js +++ b/js/metalstack/admin/v2/component_pb.js @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/admin/v2/component.proto (package metalstack.admin.v2, syntax proto3) /* eslint-disable */ import { fileDesc, messageDesc, serviceDesc } from "@bufbuild/protobuf/codegenv2"; diff --git a/js/metalstack/admin/v2/component_pb.ts b/js/metalstack/admin/v2/component_pb.ts index 8dc35dd7..c40c982b 100644 --- a/js/metalstack/admin/v2/component_pb.ts +++ b/js/metalstack/admin/v2/component_pb.ts @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/admin/v2/component.proto (package metalstack.admin.v2, syntax proto3) /* eslint-disable */ diff --git a/js/metalstack/admin/v2/filesystem_pb.js b/js/metalstack/admin/v2/filesystem_pb.js index 0fac9c3c..5a287c85 100644 --- a/js/metalstack/admin/v2/filesystem_pb.js +++ b/js/metalstack/admin/v2/filesystem_pb.js @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/admin/v2/filesystem.proto (package metalstack.admin.v2, syntax proto3) /* eslint-disable */ import { fileDesc, messageDesc, serviceDesc } from "@bufbuild/protobuf/codegenv2"; diff --git a/js/metalstack/admin/v2/filesystem_pb.ts b/js/metalstack/admin/v2/filesystem_pb.ts index caef7736..2b63c9f9 100644 --- a/js/metalstack/admin/v2/filesystem_pb.ts +++ b/js/metalstack/admin/v2/filesystem_pb.ts @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/admin/v2/filesystem.proto (package metalstack.admin.v2, syntax proto3) /* eslint-disable */ diff --git a/js/metalstack/admin/v2/image_pb.js b/js/metalstack/admin/v2/image_pb.js index cfaa178f..d93843ba 100644 --- a/js/metalstack/admin/v2/image_pb.js +++ b/js/metalstack/admin/v2/image_pb.js @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/admin/v2/image.proto (package metalstack.admin.v2, syntax proto3) /* eslint-disable */ import { fileDesc, messageDesc, serviceDesc } from "@bufbuild/protobuf/codegenv2"; diff --git a/js/metalstack/admin/v2/image_pb.ts b/js/metalstack/admin/v2/image_pb.ts index 7639865c..16813c73 100644 --- a/js/metalstack/admin/v2/image_pb.ts +++ b/js/metalstack/admin/v2/image_pb.ts @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/admin/v2/image.proto (package metalstack.admin.v2, syntax proto3) /* eslint-disable */ diff --git a/js/metalstack/admin/v2/ip_pb.js b/js/metalstack/admin/v2/ip_pb.js index 7d09ffc1..918b1be3 100644 --- a/js/metalstack/admin/v2/ip_pb.js +++ b/js/metalstack/admin/v2/ip_pb.js @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/admin/v2/ip.proto (package metalstack.admin.v2, syntax proto3) /* eslint-disable */ import { fileDesc, messageDesc, serviceDesc } from "@bufbuild/protobuf/codegenv2"; diff --git a/js/metalstack/admin/v2/ip_pb.ts b/js/metalstack/admin/v2/ip_pb.ts index 0ac709fa..8feb0286 100644 --- a/js/metalstack/admin/v2/ip_pb.ts +++ b/js/metalstack/admin/v2/ip_pb.ts @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/admin/v2/ip.proto (package metalstack.admin.v2, syntax proto3) /* eslint-disable */ diff --git a/js/metalstack/admin/v2/machine_pb.js b/js/metalstack/admin/v2/machine_pb.js index cf8c0539..da4dc168 100644 --- a/js/metalstack/admin/v2/machine_pb.js +++ b/js/metalstack/admin/v2/machine_pb.js @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/admin/v2/machine.proto (package metalstack.admin.v2, syntax proto3) /* eslint-disable */ import { fileDesc, messageDesc, serviceDesc } from "@bufbuild/protobuf/codegenv2"; diff --git a/js/metalstack/admin/v2/machine_pb.ts b/js/metalstack/admin/v2/machine_pb.ts index 557bac81..47271fc4 100644 --- a/js/metalstack/admin/v2/machine_pb.ts +++ b/js/metalstack/admin/v2/machine_pb.ts @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/admin/v2/machine.proto (package metalstack.admin.v2, syntax proto3) /* eslint-disable */ diff --git a/js/metalstack/admin/v2/network_pb.js b/js/metalstack/admin/v2/network_pb.js index c2d64f4a..c23310bd 100644 --- a/js/metalstack/admin/v2/network_pb.js +++ b/js/metalstack/admin/v2/network_pb.js @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/admin/v2/network.proto (package metalstack.admin.v2, syntax proto3) /* eslint-disable */ import { fileDesc, messageDesc, serviceDesc } from "@bufbuild/protobuf/codegenv2"; diff --git a/js/metalstack/admin/v2/network_pb.ts b/js/metalstack/admin/v2/network_pb.ts index c0e747e6..53b816ed 100644 --- a/js/metalstack/admin/v2/network_pb.ts +++ b/js/metalstack/admin/v2/network_pb.ts @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/admin/v2/network.proto (package metalstack.admin.v2, syntax proto3) /* eslint-disable */ diff --git a/js/metalstack/admin/v2/partition_pb.js b/js/metalstack/admin/v2/partition_pb.js index 8c66094b..7b1347bd 100644 --- a/js/metalstack/admin/v2/partition_pb.js +++ b/js/metalstack/admin/v2/partition_pb.js @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/admin/v2/partition.proto (package metalstack.admin.v2, syntax proto3) /* eslint-disable */ import { fileDesc, messageDesc, serviceDesc } from "@bufbuild/protobuf/codegenv2"; diff --git a/js/metalstack/admin/v2/partition_pb.ts b/js/metalstack/admin/v2/partition_pb.ts index c8c0317c..f796f935 100644 --- a/js/metalstack/admin/v2/partition_pb.ts +++ b/js/metalstack/admin/v2/partition_pb.ts @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/admin/v2/partition.proto (package metalstack.admin.v2, syntax proto3) /* eslint-disable */ diff --git a/js/metalstack/admin/v2/project_pb.js b/js/metalstack/admin/v2/project_pb.js index 06c77820..93d57d0b 100644 --- a/js/metalstack/admin/v2/project_pb.js +++ b/js/metalstack/admin/v2/project_pb.js @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/admin/v2/project.proto (package metalstack.admin.v2, syntax proto3) /* eslint-disable */ import { fileDesc, messageDesc, serviceDesc } from "@bufbuild/protobuf/codegenv2"; diff --git a/js/metalstack/admin/v2/project_pb.ts b/js/metalstack/admin/v2/project_pb.ts index 74ba6af0..591b3a13 100644 --- a/js/metalstack/admin/v2/project_pb.ts +++ b/js/metalstack/admin/v2/project_pb.ts @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/admin/v2/project.proto (package metalstack.admin.v2, syntax proto3) /* eslint-disable */ diff --git a/js/metalstack/admin/v2/size_imageconstraint_pb.js b/js/metalstack/admin/v2/size_imageconstraint_pb.js index e19ed395..c5000adf 100644 --- a/js/metalstack/admin/v2/size_imageconstraint_pb.js +++ b/js/metalstack/admin/v2/size_imageconstraint_pb.js @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/admin/v2/size_imageconstraint.proto (package metalstack.admin.v2, syntax proto3) /* eslint-disable */ import { fileDesc, messageDesc, serviceDesc } from "@bufbuild/protobuf/codegenv2"; diff --git a/js/metalstack/admin/v2/size_imageconstraint_pb.ts b/js/metalstack/admin/v2/size_imageconstraint_pb.ts index 7aca6411..0923e381 100644 --- a/js/metalstack/admin/v2/size_imageconstraint_pb.ts +++ b/js/metalstack/admin/v2/size_imageconstraint_pb.ts @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/admin/v2/size_imageconstraint.proto (package metalstack.admin.v2, syntax proto3) /* eslint-disable */ diff --git a/js/metalstack/admin/v2/size_pb.js b/js/metalstack/admin/v2/size_pb.js index ef58043d..bc4a5270 100644 --- a/js/metalstack/admin/v2/size_pb.js +++ b/js/metalstack/admin/v2/size_pb.js @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/admin/v2/size.proto (package metalstack.admin.v2, syntax proto3) /* eslint-disable */ import { fileDesc, messageDesc, serviceDesc } from "@bufbuild/protobuf/codegenv2"; diff --git a/js/metalstack/admin/v2/size_pb.ts b/js/metalstack/admin/v2/size_pb.ts index c8d9c68a..aecbc126 100644 --- a/js/metalstack/admin/v2/size_pb.ts +++ b/js/metalstack/admin/v2/size_pb.ts @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/admin/v2/size.proto (package metalstack.admin.v2, syntax proto3) /* eslint-disable */ diff --git a/js/metalstack/admin/v2/size_reservation_pb.js b/js/metalstack/admin/v2/size_reservation_pb.js index 348dbfb1..b3b89069 100644 --- a/js/metalstack/admin/v2/size_reservation_pb.js +++ b/js/metalstack/admin/v2/size_reservation_pb.js @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/admin/v2/size_reservation.proto (package metalstack.admin.v2, syntax proto3) /* eslint-disable */ import { fileDesc, messageDesc, serviceDesc } from "@bufbuild/protobuf/codegenv2"; diff --git a/js/metalstack/admin/v2/size_reservation_pb.ts b/js/metalstack/admin/v2/size_reservation_pb.ts index f24e8987..5c8517ba 100644 --- a/js/metalstack/admin/v2/size_reservation_pb.ts +++ b/js/metalstack/admin/v2/size_reservation_pb.ts @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/admin/v2/size_reservation.proto (package metalstack.admin.v2, syntax proto3) /* eslint-disable */ diff --git a/js/metalstack/admin/v2/switch_pb.js b/js/metalstack/admin/v2/switch_pb.js index 4634e4f4..142370b6 100644 --- a/js/metalstack/admin/v2/switch_pb.js +++ b/js/metalstack/admin/v2/switch_pb.js @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/admin/v2/switch.proto (package metalstack.admin.v2, syntax proto3) /* eslint-disable */ import { fileDesc, messageDesc, serviceDesc } from "@bufbuild/protobuf/codegenv2"; diff --git a/js/metalstack/admin/v2/switch_pb.ts b/js/metalstack/admin/v2/switch_pb.ts index fe85ffdf..4948faa9 100644 --- a/js/metalstack/admin/v2/switch_pb.ts +++ b/js/metalstack/admin/v2/switch_pb.ts @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/admin/v2/switch.proto (package metalstack.admin.v2, syntax proto3) /* eslint-disable */ diff --git a/js/metalstack/admin/v2/task_pb.js b/js/metalstack/admin/v2/task_pb.js index 4569731f..f01e9bc2 100644 --- a/js/metalstack/admin/v2/task_pb.js +++ b/js/metalstack/admin/v2/task_pb.js @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/admin/v2/task.proto (package metalstack.admin.v2, syntax proto3) /* eslint-disable */ import { enumDesc, fileDesc, messageDesc, serviceDesc } from "@bufbuild/protobuf/codegenv2"; diff --git a/js/metalstack/admin/v2/task_pb.ts b/js/metalstack/admin/v2/task_pb.ts index 65ae5753..9a04971b 100644 --- a/js/metalstack/admin/v2/task_pb.ts +++ b/js/metalstack/admin/v2/task_pb.ts @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/admin/v2/task.proto (package metalstack.admin.v2, syntax proto3) /* eslint-disable */ diff --git a/js/metalstack/admin/v2/tenant_pb.js b/js/metalstack/admin/v2/tenant_pb.js index 7f7d9f7b..2590df81 100644 --- a/js/metalstack/admin/v2/tenant_pb.js +++ b/js/metalstack/admin/v2/tenant_pb.js @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/admin/v2/tenant.proto (package metalstack.admin.v2, syntax proto3) /* eslint-disable */ import { fileDesc, messageDesc, serviceDesc } from "@bufbuild/protobuf/codegenv2"; diff --git a/js/metalstack/admin/v2/tenant_pb.ts b/js/metalstack/admin/v2/tenant_pb.ts index 2fcb29b0..ce08a058 100644 --- a/js/metalstack/admin/v2/tenant_pb.ts +++ b/js/metalstack/admin/v2/tenant_pb.ts @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/admin/v2/tenant.proto (package metalstack.admin.v2, syntax proto3) /* eslint-disable */ diff --git a/js/metalstack/admin/v2/token_pb.js b/js/metalstack/admin/v2/token_pb.js index 1270e31e..076bf756 100644 --- a/js/metalstack/admin/v2/token_pb.js +++ b/js/metalstack/admin/v2/token_pb.js @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/admin/v2/token.proto (package metalstack.admin.v2, syntax proto3) /* eslint-disable */ import { fileDesc, messageDesc, serviceDesc } from "@bufbuild/protobuf/codegenv2"; diff --git a/js/metalstack/admin/v2/token_pb.ts b/js/metalstack/admin/v2/token_pb.ts index 45aca58d..83b21623 100644 --- a/js/metalstack/admin/v2/token_pb.ts +++ b/js/metalstack/admin/v2/token_pb.ts @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/admin/v2/token.proto (package metalstack.admin.v2, syntax proto3) /* eslint-disable */ diff --git a/js/metalstack/admin/v2/vpn_pb.js b/js/metalstack/admin/v2/vpn_pb.js index e418a5c7..72c9d9f6 100644 --- a/js/metalstack/admin/v2/vpn_pb.js +++ b/js/metalstack/admin/v2/vpn_pb.js @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/admin/v2/vpn.proto (package metalstack.admin.v2, syntax proto3) /* eslint-disable */ import { fileDesc, messageDesc, serviceDesc } from "@bufbuild/protobuf/codegenv2"; diff --git a/js/metalstack/admin/v2/vpn_pb.ts b/js/metalstack/admin/v2/vpn_pb.ts index 114ff7df..2d62a566 100644 --- a/js/metalstack/admin/v2/vpn_pb.ts +++ b/js/metalstack/admin/v2/vpn_pb.ts @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/admin/v2/vpn.proto (package metalstack.admin.v2, syntax proto3) /* eslint-disable */ diff --git a/js/metalstack/api/v2/audit_pb.js b/js/metalstack/api/v2/audit_pb.js index 9aa955e3..60b36974 100644 --- a/js/metalstack/api/v2/audit_pb.js +++ b/js/metalstack/api/v2/audit_pb.js @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/api/v2/audit.proto (package metalstack.api.v2, syntax proto3) /* eslint-disable */ import { enumDesc, fileDesc, messageDesc, serviceDesc } from "@bufbuild/protobuf/codegenv2"; diff --git a/js/metalstack/api/v2/audit_pb.ts b/js/metalstack/api/v2/audit_pb.ts index 88ff724e..7653c268 100644 --- a/js/metalstack/api/v2/audit_pb.ts +++ b/js/metalstack/api/v2/audit_pb.ts @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/api/v2/audit.proto (package metalstack.api.v2, syntax proto3) /* eslint-disable */ diff --git a/js/metalstack/api/v2/common_pb.js b/js/metalstack/api/v2/common_pb.js index 31969083..afcf19ff 100644 --- a/js/metalstack/api/v2/common_pb.js +++ b/js/metalstack/api/v2/common_pb.js @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/api/v2/common.proto (package metalstack.api.v2, syntax proto3) /* eslint-disable */ import { enumDesc, extDesc, fileDesc, messageDesc } from "@bufbuild/protobuf/codegenv2"; diff --git a/js/metalstack/api/v2/common_pb.ts b/js/metalstack/api/v2/common_pb.ts index c88dea7b..288a08e8 100644 --- a/js/metalstack/api/v2/common_pb.ts +++ b/js/metalstack/api/v2/common_pb.ts @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/api/v2/common.proto (package metalstack.api.v2, syntax proto3) /* eslint-disable */ diff --git a/js/metalstack/api/v2/component_pb.js b/js/metalstack/api/v2/component_pb.js index 28df322a..530412cd 100644 --- a/js/metalstack/api/v2/component_pb.js +++ b/js/metalstack/api/v2/component_pb.js @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/api/v2/component.proto (package metalstack.api.v2, syntax proto3) /* eslint-disable */ import { enumDesc, fileDesc, messageDesc } from "@bufbuild/protobuf/codegenv2"; diff --git a/js/metalstack/api/v2/component_pb.ts b/js/metalstack/api/v2/component_pb.ts index 59740cd7..bff7ae97 100644 --- a/js/metalstack/api/v2/component_pb.ts +++ b/js/metalstack/api/v2/component_pb.ts @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/api/v2/component.proto (package metalstack.api.v2, syntax proto3) /* eslint-disable */ diff --git a/js/metalstack/api/v2/filesystem_pb.js b/js/metalstack/api/v2/filesystem_pb.js index c52cf18e..5b0d72aa 100644 --- a/js/metalstack/api/v2/filesystem_pb.js +++ b/js/metalstack/api/v2/filesystem_pb.js @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/api/v2/filesystem.proto (package metalstack.api.v2, syntax proto3) /* eslint-disable */ import { enumDesc, fileDesc, messageDesc, serviceDesc } from "@bufbuild/protobuf/codegenv2"; diff --git a/js/metalstack/api/v2/filesystem_pb.ts b/js/metalstack/api/v2/filesystem_pb.ts index 55f3d1fd..ee8d5dc0 100644 --- a/js/metalstack/api/v2/filesystem_pb.ts +++ b/js/metalstack/api/v2/filesystem_pb.ts @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/api/v2/filesystem.proto (package metalstack.api.v2, syntax proto3) /* eslint-disable */ diff --git a/js/metalstack/api/v2/health_pb.js b/js/metalstack/api/v2/health_pb.js index 489904d5..d16f210c 100644 --- a/js/metalstack/api/v2/health_pb.js +++ b/js/metalstack/api/v2/health_pb.js @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/api/v2/health.proto (package metalstack.api.v2, syntax proto3) /* eslint-disable */ import { enumDesc, fileDesc, messageDesc, serviceDesc } from "@bufbuild/protobuf/codegenv2"; diff --git a/js/metalstack/api/v2/health_pb.ts b/js/metalstack/api/v2/health_pb.ts index 9f0e01f3..8335d90d 100644 --- a/js/metalstack/api/v2/health_pb.ts +++ b/js/metalstack/api/v2/health_pb.ts @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/api/v2/health.proto (package metalstack.api.v2, syntax proto3) /* eslint-disable */ diff --git a/js/metalstack/api/v2/image_pb.js b/js/metalstack/api/v2/image_pb.js index 254ce7d9..50e5b332 100644 --- a/js/metalstack/api/v2/image_pb.js +++ b/js/metalstack/api/v2/image_pb.js @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/api/v2/image.proto (package metalstack.api.v2, syntax proto3) /* eslint-disable */ import { enumDesc, fileDesc, messageDesc, serviceDesc } from "@bufbuild/protobuf/codegenv2"; diff --git a/js/metalstack/api/v2/image_pb.ts b/js/metalstack/api/v2/image_pb.ts index f54017c7..cd7b582c 100644 --- a/js/metalstack/api/v2/image_pb.ts +++ b/js/metalstack/api/v2/image_pb.ts @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/api/v2/image.proto (package metalstack.api.v2, syntax proto3) /* eslint-disable */ diff --git a/js/metalstack/api/v2/ip_pb.js b/js/metalstack/api/v2/ip_pb.js index aadb1095..6841f190 100644 --- a/js/metalstack/api/v2/ip_pb.js +++ b/js/metalstack/api/v2/ip_pb.js @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/api/v2/ip.proto (package metalstack.api.v2, syntax proto3) /* eslint-disable */ import { enumDesc, fileDesc, messageDesc, serviceDesc } from "@bufbuild/protobuf/codegenv2"; diff --git a/js/metalstack/api/v2/ip_pb.ts b/js/metalstack/api/v2/ip_pb.ts index 7172d8d3..488514c3 100644 --- a/js/metalstack/api/v2/ip_pb.ts +++ b/js/metalstack/api/v2/ip_pb.ts @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/api/v2/ip.proto (package metalstack.api.v2, syntax proto3) /* eslint-disable */ diff --git a/js/metalstack/api/v2/machine_pb.js b/js/metalstack/api/v2/machine_pb.js index fb5524c1..b1574288 100644 --- a/js/metalstack/api/v2/machine_pb.js +++ b/js/metalstack/api/v2/machine_pb.js @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/api/v2/machine.proto (package metalstack.api.v2, syntax proto3) /* eslint-disable */ import { enumDesc, fileDesc, messageDesc, serviceDesc } from "@bufbuild/protobuf/codegenv2"; diff --git a/js/metalstack/api/v2/machine_pb.ts b/js/metalstack/api/v2/machine_pb.ts index d423dc9d..381e4756 100644 --- a/js/metalstack/api/v2/machine_pb.ts +++ b/js/metalstack/api/v2/machine_pb.ts @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/api/v2/machine.proto (package metalstack.api.v2, syntax proto3) /* eslint-disable */ diff --git a/js/metalstack/api/v2/method_pb.js b/js/metalstack/api/v2/method_pb.js index a404f858..02033d7f 100644 --- a/js/metalstack/api/v2/method_pb.js +++ b/js/metalstack/api/v2/method_pb.js @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/api/v2/method.proto (package metalstack.api.v2, syntax proto3) /* eslint-disable */ import { fileDesc, messageDesc, serviceDesc } from "@bufbuild/protobuf/codegenv2"; diff --git a/js/metalstack/api/v2/method_pb.ts b/js/metalstack/api/v2/method_pb.ts index 5edd69df..95376198 100644 --- a/js/metalstack/api/v2/method_pb.ts +++ b/js/metalstack/api/v2/method_pb.ts @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/api/v2/method.proto (package metalstack.api.v2, syntax proto3) /* eslint-disable */ diff --git a/js/metalstack/api/v2/network_pb.js b/js/metalstack/api/v2/network_pb.js index 370cc131..655a4824 100644 --- a/js/metalstack/api/v2/network_pb.js +++ b/js/metalstack/api/v2/network_pb.js @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/api/v2/network.proto (package metalstack.api.v2, syntax proto3) /* eslint-disable */ import { enumDesc, fileDesc, messageDesc, serviceDesc } from "@bufbuild/protobuf/codegenv2"; diff --git a/js/metalstack/api/v2/network_pb.ts b/js/metalstack/api/v2/network_pb.ts index 6cb29371..e7e10ae9 100644 --- a/js/metalstack/api/v2/network_pb.ts +++ b/js/metalstack/api/v2/network_pb.ts @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/api/v2/network.proto (package metalstack.api.v2, syntax proto3) /* eslint-disable */ diff --git a/js/metalstack/api/v2/partition_pb.js b/js/metalstack/api/v2/partition_pb.js index 03bf3a8d..d64c3540 100644 --- a/js/metalstack/api/v2/partition_pb.js +++ b/js/metalstack/api/v2/partition_pb.js @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/api/v2/partition.proto (package metalstack.api.v2, syntax proto3) /* eslint-disable */ import { fileDesc, messageDesc, serviceDesc } from "@bufbuild/protobuf/codegenv2"; diff --git a/js/metalstack/api/v2/partition_pb.ts b/js/metalstack/api/v2/partition_pb.ts index 2ccc6730..a4f33fbc 100644 --- a/js/metalstack/api/v2/partition_pb.ts +++ b/js/metalstack/api/v2/partition_pb.ts @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/api/v2/partition.proto (package metalstack.api.v2, syntax proto3) /* eslint-disable */ diff --git a/js/metalstack/api/v2/predefined_rules_pb.js b/js/metalstack/api/v2/predefined_rules_pb.js index f61e91f6..af216e0e 100644 --- a/js/metalstack/api/v2/predefined_rules_pb.js +++ b/js/metalstack/api/v2/predefined_rules_pb.js @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/api/v2/predefined_rules.proto (package metalstack.api.v2, syntax proto2) /* eslint-disable */ import { extDesc, fileDesc } from "@bufbuild/protobuf/codegenv2"; diff --git a/js/metalstack/api/v2/predefined_rules_pb.ts b/js/metalstack/api/v2/predefined_rules_pb.ts index c9fa8549..28aa7599 100644 --- a/js/metalstack/api/v2/predefined_rules_pb.ts +++ b/js/metalstack/api/v2/predefined_rules_pb.ts @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/api/v2/predefined_rules.proto (package metalstack.api.v2, syntax proto2) /* eslint-disable */ diff --git a/js/metalstack/api/v2/project_pb.js b/js/metalstack/api/v2/project_pb.js index 2f64d9c0..64caf325 100644 --- a/js/metalstack/api/v2/project_pb.js +++ b/js/metalstack/api/v2/project_pb.js @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/api/v2/project.proto (package metalstack.api.v2, syntax proto3) /* eslint-disable */ import { fileDesc, messageDesc, serviceDesc } from "@bufbuild/protobuf/codegenv2"; diff --git a/js/metalstack/api/v2/project_pb.ts b/js/metalstack/api/v2/project_pb.ts index c2f45483..2a5d5daf 100644 --- a/js/metalstack/api/v2/project_pb.ts +++ b/js/metalstack/api/v2/project_pb.ts @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/api/v2/project.proto (package metalstack.api.v2, syntax proto3) /* eslint-disable */ diff --git a/js/metalstack/api/v2/size_imageconstraint_pb.js b/js/metalstack/api/v2/size_imageconstraint_pb.js index 5105ac0d..0849e642 100644 --- a/js/metalstack/api/v2/size_imageconstraint_pb.js +++ b/js/metalstack/api/v2/size_imageconstraint_pb.js @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/api/v2/size_imageconstraint.proto (package metalstack.api.v2, syntax proto3) /* eslint-disable */ import { fileDesc, messageDesc, serviceDesc } from "@bufbuild/protobuf/codegenv2"; diff --git a/js/metalstack/api/v2/size_imageconstraint_pb.ts b/js/metalstack/api/v2/size_imageconstraint_pb.ts index d2d41b3f..d447b677 100644 --- a/js/metalstack/api/v2/size_imageconstraint_pb.ts +++ b/js/metalstack/api/v2/size_imageconstraint_pb.ts @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/api/v2/size_imageconstraint.proto (package metalstack.api.v2, syntax proto3) /* eslint-disable */ diff --git a/js/metalstack/api/v2/size_pb.js b/js/metalstack/api/v2/size_pb.js index d21c23cf..70eacc39 100644 --- a/js/metalstack/api/v2/size_pb.js +++ b/js/metalstack/api/v2/size_pb.js @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/api/v2/size.proto (package metalstack.api.v2, syntax proto3) /* eslint-disable */ import { enumDesc, fileDesc, messageDesc, serviceDesc } from "@bufbuild/protobuf/codegenv2"; diff --git a/js/metalstack/api/v2/size_pb.ts b/js/metalstack/api/v2/size_pb.ts index 4c166b9d..878f7740 100644 --- a/js/metalstack/api/v2/size_pb.ts +++ b/js/metalstack/api/v2/size_pb.ts @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/api/v2/size.proto (package metalstack.api.v2, syntax proto3) /* eslint-disable */ diff --git a/js/metalstack/api/v2/size_reservation_pb.js b/js/metalstack/api/v2/size_reservation_pb.js index 834404e6..abdf88ef 100644 --- a/js/metalstack/api/v2/size_reservation_pb.js +++ b/js/metalstack/api/v2/size_reservation_pb.js @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/api/v2/size_reservation.proto (package metalstack.api.v2, syntax proto3) /* eslint-disable */ import { fileDesc, messageDesc, serviceDesc } from "@bufbuild/protobuf/codegenv2"; diff --git a/js/metalstack/api/v2/size_reservation_pb.ts b/js/metalstack/api/v2/size_reservation_pb.ts index c86c4caa..cd9fa4ec 100644 --- a/js/metalstack/api/v2/size_reservation_pb.ts +++ b/js/metalstack/api/v2/size_reservation_pb.ts @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/api/v2/size_reservation.proto (package metalstack.api.v2, syntax proto3) /* eslint-disable */ diff --git a/js/metalstack/api/v2/switch_pb.js b/js/metalstack/api/v2/switch_pb.js index 56db191a..ae76fb8c 100644 --- a/js/metalstack/api/v2/switch_pb.js +++ b/js/metalstack/api/v2/switch_pb.js @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/api/v2/switch.proto (package metalstack.api.v2, syntax proto3) /* eslint-disable */ import { enumDesc, fileDesc, messageDesc } from "@bufbuild/protobuf/codegenv2"; diff --git a/js/metalstack/api/v2/switch_pb.ts b/js/metalstack/api/v2/switch_pb.ts index 9a1cadf3..e821ad27 100644 --- a/js/metalstack/api/v2/switch_pb.ts +++ b/js/metalstack/api/v2/switch_pb.ts @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/api/v2/switch.proto (package metalstack.api.v2, syntax proto3) /* eslint-disable */ diff --git a/js/metalstack/api/v2/tenant_pb.js b/js/metalstack/api/v2/tenant_pb.js index 55e969ad..9eb270b6 100644 --- a/js/metalstack/api/v2/tenant_pb.js +++ b/js/metalstack/api/v2/tenant_pb.js @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/api/v2/tenant.proto (package metalstack.api.v2, syntax proto3) /* eslint-disable */ import { fileDesc, messageDesc, serviceDesc } from "@bufbuild/protobuf/codegenv2"; diff --git a/js/metalstack/api/v2/tenant_pb.ts b/js/metalstack/api/v2/tenant_pb.ts index dfdaa8af..e327cdbc 100644 --- a/js/metalstack/api/v2/tenant_pb.ts +++ b/js/metalstack/api/v2/tenant_pb.ts @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/api/v2/tenant.proto (package metalstack.api.v2, syntax proto3) /* eslint-disable */ diff --git a/js/metalstack/api/v2/token_pb.js b/js/metalstack/api/v2/token_pb.js index bb380d4a..582a0bc9 100644 --- a/js/metalstack/api/v2/token_pb.js +++ b/js/metalstack/api/v2/token_pb.js @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/api/v2/token.proto (package metalstack.api.v2, syntax proto3) /* eslint-disable */ import { enumDesc, fileDesc, messageDesc, serviceDesc } from "@bufbuild/protobuf/codegenv2"; diff --git a/js/metalstack/api/v2/token_pb.ts b/js/metalstack/api/v2/token_pb.ts index f921fae5..3ac5d0f7 100644 --- a/js/metalstack/api/v2/token_pb.ts +++ b/js/metalstack/api/v2/token_pb.ts @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/api/v2/token.proto (package metalstack.api.v2, syntax proto3) /* eslint-disable */ diff --git a/js/metalstack/api/v2/user_pb.js b/js/metalstack/api/v2/user_pb.js index 43fdb6ba..1d2dcca1 100644 --- a/js/metalstack/api/v2/user_pb.js +++ b/js/metalstack/api/v2/user_pb.js @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/api/v2/user.proto (package metalstack.api.v2, syntax proto3) /* eslint-disable */ import { fileDesc, messageDesc, serviceDesc } from "@bufbuild/protobuf/codegenv2"; diff --git a/js/metalstack/api/v2/user_pb.ts b/js/metalstack/api/v2/user_pb.ts index 3f79cdd6..8a6f058f 100644 --- a/js/metalstack/api/v2/user_pb.ts +++ b/js/metalstack/api/v2/user_pb.ts @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/api/v2/user.proto (package metalstack.api.v2, syntax proto3) /* eslint-disable */ diff --git a/js/metalstack/api/v2/version_pb.js b/js/metalstack/api/v2/version_pb.js index c9b8f231..f47345fd 100644 --- a/js/metalstack/api/v2/version_pb.js +++ b/js/metalstack/api/v2/version_pb.js @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/api/v2/version.proto (package metalstack.api.v2, syntax proto3) /* eslint-disable */ import { fileDesc, messageDesc, serviceDesc } from "@bufbuild/protobuf/codegenv2"; diff --git a/js/metalstack/api/v2/version_pb.ts b/js/metalstack/api/v2/version_pb.ts index ec83a702..90cbda37 100644 --- a/js/metalstack/api/v2/version_pb.ts +++ b/js/metalstack/api/v2/version_pb.ts @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/api/v2/version.proto (package metalstack.api.v2, syntax proto3) /* eslint-disable */ diff --git a/js/metalstack/api/v2/vpn_pb.js b/js/metalstack/api/v2/vpn_pb.js index 53effe5b..7842b8fa 100644 --- a/js/metalstack/api/v2/vpn_pb.js +++ b/js/metalstack/api/v2/vpn_pb.js @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/api/v2/vpn.proto (package metalstack.api.v2, syntax proto3) /* eslint-disable */ import { fileDesc, messageDesc } from "@bufbuild/protobuf/codegenv2"; diff --git a/js/metalstack/api/v2/vpn_pb.ts b/js/metalstack/api/v2/vpn_pb.ts index a56cc427..82f6d091 100644 --- a/js/metalstack/api/v2/vpn_pb.ts +++ b/js/metalstack/api/v2/vpn_pb.ts @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/api/v2/vpn.proto (package metalstack.api.v2, syntax proto3) /* eslint-disable */ diff --git a/js/metalstack/infra/v2/bmc_pb.js b/js/metalstack/infra/v2/bmc_pb.js index e72a8872..15bf449b 100644 --- a/js/metalstack/infra/v2/bmc_pb.js +++ b/js/metalstack/infra/v2/bmc_pb.js @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/infra/v2/bmc.proto (package metalstack.infra.v2, syntax proto3) /* eslint-disable */ import { fileDesc, messageDesc, serviceDesc } from "@bufbuild/protobuf/codegenv2"; diff --git a/js/metalstack/infra/v2/bmc_pb.ts b/js/metalstack/infra/v2/bmc_pb.ts index 06a66061..9c482918 100644 --- a/js/metalstack/infra/v2/bmc_pb.ts +++ b/js/metalstack/infra/v2/bmc_pb.ts @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/infra/v2/bmc.proto (package metalstack.infra.v2, syntax proto3) /* eslint-disable */ diff --git a/js/metalstack/infra/v2/boot_pb.js b/js/metalstack/infra/v2/boot_pb.js index 7a31932b..d9827645 100644 --- a/js/metalstack/infra/v2/boot_pb.js +++ b/js/metalstack/infra/v2/boot_pb.js @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/infra/v2/boot.proto (package metalstack.infra.v2, syntax proto3) /* eslint-disable */ import { fileDesc, messageDesc, serviceDesc } from "@bufbuild/protobuf/codegenv2"; diff --git a/js/metalstack/infra/v2/boot_pb.ts b/js/metalstack/infra/v2/boot_pb.ts index 4506e262..08b1c60e 100644 --- a/js/metalstack/infra/v2/boot_pb.ts +++ b/js/metalstack/infra/v2/boot_pb.ts @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/infra/v2/boot.proto (package metalstack.infra.v2, syntax proto3) /* eslint-disable */ diff --git a/js/metalstack/infra/v2/component_pb.js b/js/metalstack/infra/v2/component_pb.js index c83040c8..ec844cbd 100644 --- a/js/metalstack/infra/v2/component_pb.js +++ b/js/metalstack/infra/v2/component_pb.js @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/infra/v2/component.proto (package metalstack.infra.v2, syntax proto3) /* eslint-disable */ import { fileDesc, messageDesc, serviceDesc } from "@bufbuild/protobuf/codegenv2"; diff --git a/js/metalstack/infra/v2/component_pb.ts b/js/metalstack/infra/v2/component_pb.ts index 884cf2e5..b39e214b 100644 --- a/js/metalstack/infra/v2/component_pb.ts +++ b/js/metalstack/infra/v2/component_pb.ts @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/infra/v2/component.proto (package metalstack.infra.v2, syntax proto3) /* eslint-disable */ diff --git a/js/metalstack/infra/v2/event_pb.js b/js/metalstack/infra/v2/event_pb.js index 1774543f..dceebc5f 100644 --- a/js/metalstack/infra/v2/event_pb.js +++ b/js/metalstack/infra/v2/event_pb.js @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/infra/v2/event.proto (package metalstack.infra.v2, syntax proto3) /* eslint-disable */ import { fileDesc, messageDesc, serviceDesc } from "@bufbuild/protobuf/codegenv2"; diff --git a/js/metalstack/infra/v2/event_pb.ts b/js/metalstack/infra/v2/event_pb.ts index 366d112e..ce12e45f 100644 --- a/js/metalstack/infra/v2/event_pb.ts +++ b/js/metalstack/infra/v2/event_pb.ts @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/infra/v2/event.proto (package metalstack.infra.v2, syntax proto3) /* eslint-disable */ diff --git a/js/metalstack/infra/v2/switch_pb.js b/js/metalstack/infra/v2/switch_pb.js index 593954ab..582c3eff 100644 --- a/js/metalstack/infra/v2/switch_pb.js +++ b/js/metalstack/infra/v2/switch_pb.js @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/infra/v2/switch.proto (package metalstack.infra.v2, syntax proto3) /* eslint-disable */ import { fileDesc, messageDesc, serviceDesc } from "@bufbuild/protobuf/codegenv2"; diff --git a/js/metalstack/infra/v2/switch_pb.ts b/js/metalstack/infra/v2/switch_pb.ts index 5c8b824e..5f325834 100644 --- a/js/metalstack/infra/v2/switch_pb.ts +++ b/js/metalstack/infra/v2/switch_pb.ts @@ -1,4 +1,4 @@ -// @generated by protoc-gen-es v2.14.0 with parameter "target=ts" +// @generated by protoc-gen-es v2.14.1 with parameter "target=ts" // @generated from file metalstack/infra/v2/switch.proto (package metalstack.infra.v2, syntax proto3) /* eslint-disable */ diff --git a/proto/buf.gen.yaml b/proto/buf.gen.yaml index 31431956..30502aa3 100644 --- a/proto/buf.gen.yaml +++ b/proto/buf.gen.yaml @@ -20,15 +20,15 @@ plugins: out: ../go opt: paths=source_relative,simple # python - - remote: buf.build/protocolbuffers/python:v36.0 + - remote: buf.build/protocolbuffers/python:v36.1 out: ../python include_imports: True - - remote: buf.build/protocolbuffers/pyi:v36.0 + - remote: buf.build/protocolbuffers/pyi:v36.1 out: ../python - remote: buf.build/connectrpc/python:v0.10.1 out: ../python # js - - remote: buf.build/bufbuild/es:v2.14.0 + - remote: buf.build/bufbuild/es:v2.14.1 include_imports: true out: ../js opt: target=ts diff --git a/proto/buf.lock b/proto/buf.lock index 7b474667..eca92dc8 100644 --- a/proto/buf.lock +++ b/proto/buf.lock @@ -2,5 +2,5 @@ version: v2 deps: - name: buf.build/bufbuild/protovalidate - commit: 435963d1631043e694e56e6bcc3c79c3 - digest: b5:f4ea07ad2dd94bd7243562f9908b9fb104feef8076040c89d9f7c1dedc074de4d4ce2b997686ef4400f3eccb765a7cfc20ed4acdd70b9a3699351245c61dba97 + commit: 511051f7f4374c3ca873b53ae68a9288 + digest: b5:a4a2d4d808a25984cced60769c822c5d496ef0b740f56ac0c9e6b97aaa25b86a9332a00ffd74e0cd202be29e91bd3edfb0bf2ba4dacfe48ff2d8217f9986e3c8 diff --git a/python/buf/validate/validate_pb2.py b/python/buf/validate/validate_pb2.py index 5a262b36..f4353e37 100644 --- a/python/buf/validate/validate_pb2.py +++ b/python/buf/validate/validate_pb2.py @@ -2,7 +2,7 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # NO CHECKED-IN PROTOBUF GENCODE # source: buf/validate/validate.proto -# Protobuf Python Version: 7.36.0 +# Protobuf Python Version: 7.36.1 """Generated protocol buffer code.""" from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool @@ -13,7 +13,7 @@ _runtime_version.Domain.PUBLIC, 7, 36, - 0, + 1, '', 'buf/validate/validate.proto' ) diff --git a/python/metalstack/admin/v2/audit_pb2.py b/python/metalstack/admin/v2/audit_pb2.py index 76f979cd..91c1f0e1 100644 --- a/python/metalstack/admin/v2/audit_pb2.py +++ b/python/metalstack/admin/v2/audit_pb2.py @@ -2,7 +2,7 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # NO CHECKED-IN PROTOBUF GENCODE # source: metalstack/admin/v2/audit.proto -# Protobuf Python Version: 7.36.0 +# Protobuf Python Version: 7.36.1 """Generated protocol buffer code.""" from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool @@ -13,7 +13,7 @@ _runtime_version.Domain.PUBLIC, 7, 36, - 0, + 1, '', 'metalstack/admin/v2/audit.proto' ) diff --git a/python/metalstack/admin/v2/component_pb2.py b/python/metalstack/admin/v2/component_pb2.py index dc782b00..7bb9f75e 100644 --- a/python/metalstack/admin/v2/component_pb2.py +++ b/python/metalstack/admin/v2/component_pb2.py @@ -2,7 +2,7 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # NO CHECKED-IN PROTOBUF GENCODE # source: metalstack/admin/v2/component.proto -# Protobuf Python Version: 7.36.0 +# Protobuf Python Version: 7.36.1 """Generated protocol buffer code.""" from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool @@ -13,7 +13,7 @@ _runtime_version.Domain.PUBLIC, 7, 36, - 0, + 1, '', 'metalstack/admin/v2/component.proto' ) diff --git a/python/metalstack/admin/v2/filesystem_pb2.py b/python/metalstack/admin/v2/filesystem_pb2.py index dde90598..27e78b50 100644 --- a/python/metalstack/admin/v2/filesystem_pb2.py +++ b/python/metalstack/admin/v2/filesystem_pb2.py @@ -2,7 +2,7 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # NO CHECKED-IN PROTOBUF GENCODE # source: metalstack/admin/v2/filesystem.proto -# Protobuf Python Version: 7.36.0 +# Protobuf Python Version: 7.36.1 """Generated protocol buffer code.""" from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool @@ -13,7 +13,7 @@ _runtime_version.Domain.PUBLIC, 7, 36, - 0, + 1, '', 'metalstack/admin/v2/filesystem.proto' ) diff --git a/python/metalstack/admin/v2/image_pb2.py b/python/metalstack/admin/v2/image_pb2.py index 040b3206..31efebe4 100644 --- a/python/metalstack/admin/v2/image_pb2.py +++ b/python/metalstack/admin/v2/image_pb2.py @@ -2,7 +2,7 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # NO CHECKED-IN PROTOBUF GENCODE # source: metalstack/admin/v2/image.proto -# Protobuf Python Version: 7.36.0 +# Protobuf Python Version: 7.36.1 """Generated protocol buffer code.""" from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool @@ -13,7 +13,7 @@ _runtime_version.Domain.PUBLIC, 7, 36, - 0, + 1, '', 'metalstack/admin/v2/image.proto' ) diff --git a/python/metalstack/admin/v2/ip_pb2.py b/python/metalstack/admin/v2/ip_pb2.py index b4c52b44..ed890348 100644 --- a/python/metalstack/admin/v2/ip_pb2.py +++ b/python/metalstack/admin/v2/ip_pb2.py @@ -2,7 +2,7 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # NO CHECKED-IN PROTOBUF GENCODE # source: metalstack/admin/v2/ip.proto -# Protobuf Python Version: 7.36.0 +# Protobuf Python Version: 7.36.1 """Generated protocol buffer code.""" from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool @@ -13,7 +13,7 @@ _runtime_version.Domain.PUBLIC, 7, 36, - 0, + 1, '', 'metalstack/admin/v2/ip.proto' ) diff --git a/python/metalstack/admin/v2/machine_pb2.py b/python/metalstack/admin/v2/machine_pb2.py index 8f5a5483..a7b651a2 100644 --- a/python/metalstack/admin/v2/machine_pb2.py +++ b/python/metalstack/admin/v2/machine_pb2.py @@ -2,7 +2,7 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # NO CHECKED-IN PROTOBUF GENCODE # source: metalstack/admin/v2/machine.proto -# Protobuf Python Version: 7.36.0 +# Protobuf Python Version: 7.36.1 """Generated protocol buffer code.""" from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool @@ -13,7 +13,7 @@ _runtime_version.Domain.PUBLIC, 7, 36, - 0, + 1, '', 'metalstack/admin/v2/machine.proto' ) diff --git a/python/metalstack/admin/v2/network_pb2.py b/python/metalstack/admin/v2/network_pb2.py index b3dcfa1a..26ce531d 100644 --- a/python/metalstack/admin/v2/network_pb2.py +++ b/python/metalstack/admin/v2/network_pb2.py @@ -2,7 +2,7 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # NO CHECKED-IN PROTOBUF GENCODE # source: metalstack/admin/v2/network.proto -# Protobuf Python Version: 7.36.0 +# Protobuf Python Version: 7.36.1 """Generated protocol buffer code.""" from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool @@ -13,7 +13,7 @@ _runtime_version.Domain.PUBLIC, 7, 36, - 0, + 1, '', 'metalstack/admin/v2/network.proto' ) diff --git a/python/metalstack/admin/v2/partition_pb2.py b/python/metalstack/admin/v2/partition_pb2.py index 833f8b46..5c54e097 100644 --- a/python/metalstack/admin/v2/partition_pb2.py +++ b/python/metalstack/admin/v2/partition_pb2.py @@ -2,7 +2,7 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # NO CHECKED-IN PROTOBUF GENCODE # source: metalstack/admin/v2/partition.proto -# Protobuf Python Version: 7.36.0 +# Protobuf Python Version: 7.36.1 """Generated protocol buffer code.""" from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool @@ -13,7 +13,7 @@ _runtime_version.Domain.PUBLIC, 7, 36, - 0, + 1, '', 'metalstack/admin/v2/partition.proto' ) diff --git a/python/metalstack/admin/v2/project_pb2.py b/python/metalstack/admin/v2/project_pb2.py index 725fe454..5fcc5c18 100644 --- a/python/metalstack/admin/v2/project_pb2.py +++ b/python/metalstack/admin/v2/project_pb2.py @@ -2,7 +2,7 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # NO CHECKED-IN PROTOBUF GENCODE # source: metalstack/admin/v2/project.proto -# Protobuf Python Version: 7.36.0 +# Protobuf Python Version: 7.36.1 """Generated protocol buffer code.""" from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool @@ -13,7 +13,7 @@ _runtime_version.Domain.PUBLIC, 7, 36, - 0, + 1, '', 'metalstack/admin/v2/project.proto' ) diff --git a/python/metalstack/admin/v2/size_imageconstraint_pb2.py b/python/metalstack/admin/v2/size_imageconstraint_pb2.py index ec60ba03..bc39a68d 100644 --- a/python/metalstack/admin/v2/size_imageconstraint_pb2.py +++ b/python/metalstack/admin/v2/size_imageconstraint_pb2.py @@ -2,7 +2,7 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # NO CHECKED-IN PROTOBUF GENCODE # source: metalstack/admin/v2/size_imageconstraint.proto -# Protobuf Python Version: 7.36.0 +# Protobuf Python Version: 7.36.1 """Generated protocol buffer code.""" from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool @@ -13,7 +13,7 @@ _runtime_version.Domain.PUBLIC, 7, 36, - 0, + 1, '', 'metalstack/admin/v2/size_imageconstraint.proto' ) diff --git a/python/metalstack/admin/v2/size_pb2.py b/python/metalstack/admin/v2/size_pb2.py index 9901cd21..39417f8b 100644 --- a/python/metalstack/admin/v2/size_pb2.py +++ b/python/metalstack/admin/v2/size_pb2.py @@ -2,7 +2,7 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # NO CHECKED-IN PROTOBUF GENCODE # source: metalstack/admin/v2/size.proto -# Protobuf Python Version: 7.36.0 +# Protobuf Python Version: 7.36.1 """Generated protocol buffer code.""" from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool @@ -13,7 +13,7 @@ _runtime_version.Domain.PUBLIC, 7, 36, - 0, + 1, '', 'metalstack/admin/v2/size.proto' ) diff --git a/python/metalstack/admin/v2/size_reservation_pb2.py b/python/metalstack/admin/v2/size_reservation_pb2.py index fa543f7d..f92a266a 100644 --- a/python/metalstack/admin/v2/size_reservation_pb2.py +++ b/python/metalstack/admin/v2/size_reservation_pb2.py @@ -2,7 +2,7 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # NO CHECKED-IN PROTOBUF GENCODE # source: metalstack/admin/v2/size_reservation.proto -# Protobuf Python Version: 7.36.0 +# Protobuf Python Version: 7.36.1 """Generated protocol buffer code.""" from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool @@ -13,7 +13,7 @@ _runtime_version.Domain.PUBLIC, 7, 36, - 0, + 1, '', 'metalstack/admin/v2/size_reservation.proto' ) diff --git a/python/metalstack/admin/v2/switch_pb2.py b/python/metalstack/admin/v2/switch_pb2.py index f5da3f80..36f51994 100644 --- a/python/metalstack/admin/v2/switch_pb2.py +++ b/python/metalstack/admin/v2/switch_pb2.py @@ -2,7 +2,7 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # NO CHECKED-IN PROTOBUF GENCODE # source: metalstack/admin/v2/switch.proto -# Protobuf Python Version: 7.36.0 +# Protobuf Python Version: 7.36.1 """Generated protocol buffer code.""" from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool @@ -13,7 +13,7 @@ _runtime_version.Domain.PUBLIC, 7, 36, - 0, + 1, '', 'metalstack/admin/v2/switch.proto' ) diff --git a/python/metalstack/admin/v2/task_pb2.py b/python/metalstack/admin/v2/task_pb2.py index b578b7da..3cc67593 100644 --- a/python/metalstack/admin/v2/task_pb2.py +++ b/python/metalstack/admin/v2/task_pb2.py @@ -2,7 +2,7 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # NO CHECKED-IN PROTOBUF GENCODE # source: metalstack/admin/v2/task.proto -# Protobuf Python Version: 7.36.0 +# Protobuf Python Version: 7.36.1 """Generated protocol buffer code.""" from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool @@ -13,7 +13,7 @@ _runtime_version.Domain.PUBLIC, 7, 36, - 0, + 1, '', 'metalstack/admin/v2/task.proto' ) diff --git a/python/metalstack/admin/v2/tenant_pb2.py b/python/metalstack/admin/v2/tenant_pb2.py index 15abe4d9..16d5a779 100644 --- a/python/metalstack/admin/v2/tenant_pb2.py +++ b/python/metalstack/admin/v2/tenant_pb2.py @@ -2,7 +2,7 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # NO CHECKED-IN PROTOBUF GENCODE # source: metalstack/admin/v2/tenant.proto -# Protobuf Python Version: 7.36.0 +# Protobuf Python Version: 7.36.1 """Generated protocol buffer code.""" from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool @@ -13,7 +13,7 @@ _runtime_version.Domain.PUBLIC, 7, 36, - 0, + 1, '', 'metalstack/admin/v2/tenant.proto' ) diff --git a/python/metalstack/admin/v2/token_pb2.py b/python/metalstack/admin/v2/token_pb2.py index 126ab5a4..ae369e4e 100644 --- a/python/metalstack/admin/v2/token_pb2.py +++ b/python/metalstack/admin/v2/token_pb2.py @@ -2,7 +2,7 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # NO CHECKED-IN PROTOBUF GENCODE # source: metalstack/admin/v2/token.proto -# Protobuf Python Version: 7.36.0 +# Protobuf Python Version: 7.36.1 """Generated protocol buffer code.""" from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool @@ -13,7 +13,7 @@ _runtime_version.Domain.PUBLIC, 7, 36, - 0, + 1, '', 'metalstack/admin/v2/token.proto' ) diff --git a/python/metalstack/admin/v2/vpn_pb2.py b/python/metalstack/admin/v2/vpn_pb2.py index 683ea17b..1e318cfd 100644 --- a/python/metalstack/admin/v2/vpn_pb2.py +++ b/python/metalstack/admin/v2/vpn_pb2.py @@ -2,7 +2,7 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # NO CHECKED-IN PROTOBUF GENCODE # source: metalstack/admin/v2/vpn.proto -# Protobuf Python Version: 7.36.0 +# Protobuf Python Version: 7.36.1 """Generated protocol buffer code.""" from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool @@ -13,7 +13,7 @@ _runtime_version.Domain.PUBLIC, 7, 36, - 0, + 1, '', 'metalstack/admin/v2/vpn.proto' ) diff --git a/python/metalstack/api/v2/audit_pb2.py b/python/metalstack/api/v2/audit_pb2.py index 9da80591..8839f825 100644 --- a/python/metalstack/api/v2/audit_pb2.py +++ b/python/metalstack/api/v2/audit_pb2.py @@ -2,7 +2,7 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # NO CHECKED-IN PROTOBUF GENCODE # source: metalstack/api/v2/audit.proto -# Protobuf Python Version: 7.36.0 +# Protobuf Python Version: 7.36.1 """Generated protocol buffer code.""" from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool @@ -13,7 +13,7 @@ _runtime_version.Domain.PUBLIC, 7, 36, - 0, + 1, '', 'metalstack/api/v2/audit.proto' ) diff --git a/python/metalstack/api/v2/common_pb2.py b/python/metalstack/api/v2/common_pb2.py index b93c25b8..d8f09a99 100644 --- a/python/metalstack/api/v2/common_pb2.py +++ b/python/metalstack/api/v2/common_pb2.py @@ -2,7 +2,7 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # NO CHECKED-IN PROTOBUF GENCODE # source: metalstack/api/v2/common.proto -# Protobuf Python Version: 7.36.0 +# Protobuf Python Version: 7.36.1 """Generated protocol buffer code.""" from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool @@ -13,7 +13,7 @@ _runtime_version.Domain.PUBLIC, 7, 36, - 0, + 1, '', 'metalstack/api/v2/common.proto' ) diff --git a/python/metalstack/api/v2/component_pb2.py b/python/metalstack/api/v2/component_pb2.py index cf9a7170..5da00c0a 100644 --- a/python/metalstack/api/v2/component_pb2.py +++ b/python/metalstack/api/v2/component_pb2.py @@ -2,7 +2,7 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # NO CHECKED-IN PROTOBUF GENCODE # source: metalstack/api/v2/component.proto -# Protobuf Python Version: 7.36.0 +# Protobuf Python Version: 7.36.1 """Generated protocol buffer code.""" from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool @@ -13,7 +13,7 @@ _runtime_version.Domain.PUBLIC, 7, 36, - 0, + 1, '', 'metalstack/api/v2/component.proto' ) diff --git a/python/metalstack/api/v2/filesystem_pb2.py b/python/metalstack/api/v2/filesystem_pb2.py index a88b8250..c1841fc4 100644 --- a/python/metalstack/api/v2/filesystem_pb2.py +++ b/python/metalstack/api/v2/filesystem_pb2.py @@ -2,7 +2,7 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # NO CHECKED-IN PROTOBUF GENCODE # source: metalstack/api/v2/filesystem.proto -# Protobuf Python Version: 7.36.0 +# Protobuf Python Version: 7.36.1 """Generated protocol buffer code.""" from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool @@ -13,7 +13,7 @@ _runtime_version.Domain.PUBLIC, 7, 36, - 0, + 1, '', 'metalstack/api/v2/filesystem.proto' ) diff --git a/python/metalstack/api/v2/health_pb2.py b/python/metalstack/api/v2/health_pb2.py index dfa2b805..3d5bb501 100644 --- a/python/metalstack/api/v2/health_pb2.py +++ b/python/metalstack/api/v2/health_pb2.py @@ -2,7 +2,7 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # NO CHECKED-IN PROTOBUF GENCODE # source: metalstack/api/v2/health.proto -# Protobuf Python Version: 7.36.0 +# Protobuf Python Version: 7.36.1 """Generated protocol buffer code.""" from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool @@ -13,7 +13,7 @@ _runtime_version.Domain.PUBLIC, 7, 36, - 0, + 1, '', 'metalstack/api/v2/health.proto' ) diff --git a/python/metalstack/api/v2/image_pb2.py b/python/metalstack/api/v2/image_pb2.py index 2ab98c8c..8296d4a9 100644 --- a/python/metalstack/api/v2/image_pb2.py +++ b/python/metalstack/api/v2/image_pb2.py @@ -2,7 +2,7 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # NO CHECKED-IN PROTOBUF GENCODE # source: metalstack/api/v2/image.proto -# Protobuf Python Version: 7.36.0 +# Protobuf Python Version: 7.36.1 """Generated protocol buffer code.""" from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool @@ -13,7 +13,7 @@ _runtime_version.Domain.PUBLIC, 7, 36, - 0, + 1, '', 'metalstack/api/v2/image.proto' ) diff --git a/python/metalstack/api/v2/ip_pb2.py b/python/metalstack/api/v2/ip_pb2.py index 40373862..5083261c 100644 --- a/python/metalstack/api/v2/ip_pb2.py +++ b/python/metalstack/api/v2/ip_pb2.py @@ -2,7 +2,7 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # NO CHECKED-IN PROTOBUF GENCODE # source: metalstack/api/v2/ip.proto -# Protobuf Python Version: 7.36.0 +# Protobuf Python Version: 7.36.1 """Generated protocol buffer code.""" from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool @@ -13,7 +13,7 @@ _runtime_version.Domain.PUBLIC, 7, 36, - 0, + 1, '', 'metalstack/api/v2/ip.proto' ) diff --git a/python/metalstack/api/v2/machine_pb2.py b/python/metalstack/api/v2/machine_pb2.py index 3c0f8483..348c9ef7 100644 --- a/python/metalstack/api/v2/machine_pb2.py +++ b/python/metalstack/api/v2/machine_pb2.py @@ -2,7 +2,7 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # NO CHECKED-IN PROTOBUF GENCODE # source: metalstack/api/v2/machine.proto -# Protobuf Python Version: 7.36.0 +# Protobuf Python Version: 7.36.1 """Generated protocol buffer code.""" from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool @@ -13,7 +13,7 @@ _runtime_version.Domain.PUBLIC, 7, 36, - 0, + 1, '', 'metalstack/api/v2/machine.proto' ) diff --git a/python/metalstack/api/v2/method_pb2.py b/python/metalstack/api/v2/method_pb2.py index 80863f4b..bc4b5ca1 100644 --- a/python/metalstack/api/v2/method_pb2.py +++ b/python/metalstack/api/v2/method_pb2.py @@ -2,7 +2,7 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # NO CHECKED-IN PROTOBUF GENCODE # source: metalstack/api/v2/method.proto -# Protobuf Python Version: 7.36.0 +# Protobuf Python Version: 7.36.1 """Generated protocol buffer code.""" from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool @@ -13,7 +13,7 @@ _runtime_version.Domain.PUBLIC, 7, 36, - 0, + 1, '', 'metalstack/api/v2/method.proto' ) diff --git a/python/metalstack/api/v2/network_pb2.py b/python/metalstack/api/v2/network_pb2.py index c601e049..598ae26e 100644 --- a/python/metalstack/api/v2/network_pb2.py +++ b/python/metalstack/api/v2/network_pb2.py @@ -2,7 +2,7 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # NO CHECKED-IN PROTOBUF GENCODE # source: metalstack/api/v2/network.proto -# Protobuf Python Version: 7.36.0 +# Protobuf Python Version: 7.36.1 """Generated protocol buffer code.""" from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool @@ -13,7 +13,7 @@ _runtime_version.Domain.PUBLIC, 7, 36, - 0, + 1, '', 'metalstack/api/v2/network.proto' ) diff --git a/python/metalstack/api/v2/partition_pb2.py b/python/metalstack/api/v2/partition_pb2.py index dfb50c84..609b8db8 100644 --- a/python/metalstack/api/v2/partition_pb2.py +++ b/python/metalstack/api/v2/partition_pb2.py @@ -2,7 +2,7 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # NO CHECKED-IN PROTOBUF GENCODE # source: metalstack/api/v2/partition.proto -# Protobuf Python Version: 7.36.0 +# Protobuf Python Version: 7.36.1 """Generated protocol buffer code.""" from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool @@ -13,7 +13,7 @@ _runtime_version.Domain.PUBLIC, 7, 36, - 0, + 1, '', 'metalstack/api/v2/partition.proto' ) diff --git a/python/metalstack/api/v2/predefined_rules_pb2.py b/python/metalstack/api/v2/predefined_rules_pb2.py index d345b572..45ea6c91 100644 --- a/python/metalstack/api/v2/predefined_rules_pb2.py +++ b/python/metalstack/api/v2/predefined_rules_pb2.py @@ -2,7 +2,7 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # NO CHECKED-IN PROTOBUF GENCODE # source: metalstack/api/v2/predefined_rules.proto -# Protobuf Python Version: 7.36.0 +# Protobuf Python Version: 7.36.1 """Generated protocol buffer code.""" from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool @@ -13,7 +13,7 @@ _runtime_version.Domain.PUBLIC, 7, 36, - 0, + 1, '', 'metalstack/api/v2/predefined_rules.proto' ) diff --git a/python/metalstack/api/v2/project_pb2.py b/python/metalstack/api/v2/project_pb2.py index 28e3adcb..618b4ecb 100644 --- a/python/metalstack/api/v2/project_pb2.py +++ b/python/metalstack/api/v2/project_pb2.py @@ -2,7 +2,7 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # NO CHECKED-IN PROTOBUF GENCODE # source: metalstack/api/v2/project.proto -# Protobuf Python Version: 7.36.0 +# Protobuf Python Version: 7.36.1 """Generated protocol buffer code.""" from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool @@ -13,7 +13,7 @@ _runtime_version.Domain.PUBLIC, 7, 36, - 0, + 1, '', 'metalstack/api/v2/project.proto' ) diff --git a/python/metalstack/api/v2/size_imageconstraint_pb2.py b/python/metalstack/api/v2/size_imageconstraint_pb2.py index ddc45e62..2353fb55 100644 --- a/python/metalstack/api/v2/size_imageconstraint_pb2.py +++ b/python/metalstack/api/v2/size_imageconstraint_pb2.py @@ -2,7 +2,7 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # NO CHECKED-IN PROTOBUF GENCODE # source: metalstack/api/v2/size_imageconstraint.proto -# Protobuf Python Version: 7.36.0 +# Protobuf Python Version: 7.36.1 """Generated protocol buffer code.""" from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool @@ -13,7 +13,7 @@ _runtime_version.Domain.PUBLIC, 7, 36, - 0, + 1, '', 'metalstack/api/v2/size_imageconstraint.proto' ) diff --git a/python/metalstack/api/v2/size_pb2.py b/python/metalstack/api/v2/size_pb2.py index 92da1790..c805b76f 100644 --- a/python/metalstack/api/v2/size_pb2.py +++ b/python/metalstack/api/v2/size_pb2.py @@ -2,7 +2,7 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # NO CHECKED-IN PROTOBUF GENCODE # source: metalstack/api/v2/size.proto -# Protobuf Python Version: 7.36.0 +# Protobuf Python Version: 7.36.1 """Generated protocol buffer code.""" from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool @@ -13,7 +13,7 @@ _runtime_version.Domain.PUBLIC, 7, 36, - 0, + 1, '', 'metalstack/api/v2/size.proto' ) diff --git a/python/metalstack/api/v2/size_reservation_pb2.py b/python/metalstack/api/v2/size_reservation_pb2.py index 2c22d4c5..6059da65 100644 --- a/python/metalstack/api/v2/size_reservation_pb2.py +++ b/python/metalstack/api/v2/size_reservation_pb2.py @@ -2,7 +2,7 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # NO CHECKED-IN PROTOBUF GENCODE # source: metalstack/api/v2/size_reservation.proto -# Protobuf Python Version: 7.36.0 +# Protobuf Python Version: 7.36.1 """Generated protocol buffer code.""" from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool @@ -13,7 +13,7 @@ _runtime_version.Domain.PUBLIC, 7, 36, - 0, + 1, '', 'metalstack/api/v2/size_reservation.proto' ) diff --git a/python/metalstack/api/v2/switch_pb2.py b/python/metalstack/api/v2/switch_pb2.py index 01f7e882..d690c3e8 100644 --- a/python/metalstack/api/v2/switch_pb2.py +++ b/python/metalstack/api/v2/switch_pb2.py @@ -2,7 +2,7 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # NO CHECKED-IN PROTOBUF GENCODE # source: metalstack/api/v2/switch.proto -# Protobuf Python Version: 7.36.0 +# Protobuf Python Version: 7.36.1 """Generated protocol buffer code.""" from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool @@ -13,7 +13,7 @@ _runtime_version.Domain.PUBLIC, 7, 36, - 0, + 1, '', 'metalstack/api/v2/switch.proto' ) diff --git a/python/metalstack/api/v2/tenant_pb2.py b/python/metalstack/api/v2/tenant_pb2.py index a02f29cb..abe73ae6 100644 --- a/python/metalstack/api/v2/tenant_pb2.py +++ b/python/metalstack/api/v2/tenant_pb2.py @@ -2,7 +2,7 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # NO CHECKED-IN PROTOBUF GENCODE # source: metalstack/api/v2/tenant.proto -# Protobuf Python Version: 7.36.0 +# Protobuf Python Version: 7.36.1 """Generated protocol buffer code.""" from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool @@ -13,7 +13,7 @@ _runtime_version.Domain.PUBLIC, 7, 36, - 0, + 1, '', 'metalstack/api/v2/tenant.proto' ) diff --git a/python/metalstack/api/v2/token_pb2.py b/python/metalstack/api/v2/token_pb2.py index a4ef4d66..4d709a87 100644 --- a/python/metalstack/api/v2/token_pb2.py +++ b/python/metalstack/api/v2/token_pb2.py @@ -2,7 +2,7 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # NO CHECKED-IN PROTOBUF GENCODE # source: metalstack/api/v2/token.proto -# Protobuf Python Version: 7.36.0 +# Protobuf Python Version: 7.36.1 """Generated protocol buffer code.""" from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool @@ -13,7 +13,7 @@ _runtime_version.Domain.PUBLIC, 7, 36, - 0, + 1, '', 'metalstack/api/v2/token.proto' ) diff --git a/python/metalstack/api/v2/user_pb2.py b/python/metalstack/api/v2/user_pb2.py index 3ea1f144..d9556014 100644 --- a/python/metalstack/api/v2/user_pb2.py +++ b/python/metalstack/api/v2/user_pb2.py @@ -2,7 +2,7 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # NO CHECKED-IN PROTOBUF GENCODE # source: metalstack/api/v2/user.proto -# Protobuf Python Version: 7.36.0 +# Protobuf Python Version: 7.36.1 """Generated protocol buffer code.""" from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool @@ -13,7 +13,7 @@ _runtime_version.Domain.PUBLIC, 7, 36, - 0, + 1, '', 'metalstack/api/v2/user.proto' ) diff --git a/python/metalstack/api/v2/version_pb2.py b/python/metalstack/api/v2/version_pb2.py index c8d1f9e7..2cf1e30b 100644 --- a/python/metalstack/api/v2/version_pb2.py +++ b/python/metalstack/api/v2/version_pb2.py @@ -2,7 +2,7 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # NO CHECKED-IN PROTOBUF GENCODE # source: metalstack/api/v2/version.proto -# Protobuf Python Version: 7.36.0 +# Protobuf Python Version: 7.36.1 """Generated protocol buffer code.""" from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool @@ -13,7 +13,7 @@ _runtime_version.Domain.PUBLIC, 7, 36, - 0, + 1, '', 'metalstack/api/v2/version.proto' ) diff --git a/python/metalstack/api/v2/vpn_pb2.py b/python/metalstack/api/v2/vpn_pb2.py index 5b861541..70575874 100644 --- a/python/metalstack/api/v2/vpn_pb2.py +++ b/python/metalstack/api/v2/vpn_pb2.py @@ -2,7 +2,7 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # NO CHECKED-IN PROTOBUF GENCODE # source: metalstack/api/v2/vpn.proto -# Protobuf Python Version: 7.36.0 +# Protobuf Python Version: 7.36.1 """Generated protocol buffer code.""" from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool @@ -13,7 +13,7 @@ _runtime_version.Domain.PUBLIC, 7, 36, - 0, + 1, '', 'metalstack/api/v2/vpn.proto' ) diff --git a/python/metalstack/infra/v2/bmc_pb2.py b/python/metalstack/infra/v2/bmc_pb2.py index 5a98293f..54126fda 100644 --- a/python/metalstack/infra/v2/bmc_pb2.py +++ b/python/metalstack/infra/v2/bmc_pb2.py @@ -2,7 +2,7 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # NO CHECKED-IN PROTOBUF GENCODE # source: metalstack/infra/v2/bmc.proto -# Protobuf Python Version: 7.36.0 +# Protobuf Python Version: 7.36.1 """Generated protocol buffer code.""" from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool @@ -13,7 +13,7 @@ _runtime_version.Domain.PUBLIC, 7, 36, - 0, + 1, '', 'metalstack/infra/v2/bmc.proto' ) diff --git a/python/metalstack/infra/v2/boot_pb2.py b/python/metalstack/infra/v2/boot_pb2.py index 3298a250..0b03a88e 100644 --- a/python/metalstack/infra/v2/boot_pb2.py +++ b/python/metalstack/infra/v2/boot_pb2.py @@ -2,7 +2,7 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # NO CHECKED-IN PROTOBUF GENCODE # source: metalstack/infra/v2/boot.proto -# Protobuf Python Version: 7.36.0 +# Protobuf Python Version: 7.36.1 """Generated protocol buffer code.""" from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool @@ -13,7 +13,7 @@ _runtime_version.Domain.PUBLIC, 7, 36, - 0, + 1, '', 'metalstack/infra/v2/boot.proto' ) diff --git a/python/metalstack/infra/v2/component_pb2.py b/python/metalstack/infra/v2/component_pb2.py index 77e5823c..e68f651c 100644 --- a/python/metalstack/infra/v2/component_pb2.py +++ b/python/metalstack/infra/v2/component_pb2.py @@ -2,7 +2,7 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # NO CHECKED-IN PROTOBUF GENCODE # source: metalstack/infra/v2/component.proto -# Protobuf Python Version: 7.36.0 +# Protobuf Python Version: 7.36.1 """Generated protocol buffer code.""" from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool @@ -13,7 +13,7 @@ _runtime_version.Domain.PUBLIC, 7, 36, - 0, + 1, '', 'metalstack/infra/v2/component.proto' ) diff --git a/python/metalstack/infra/v2/event_pb2.py b/python/metalstack/infra/v2/event_pb2.py index 03329caf..80e22276 100644 --- a/python/metalstack/infra/v2/event_pb2.py +++ b/python/metalstack/infra/v2/event_pb2.py @@ -2,7 +2,7 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # NO CHECKED-IN PROTOBUF GENCODE # source: metalstack/infra/v2/event.proto -# Protobuf Python Version: 7.36.0 +# Protobuf Python Version: 7.36.1 """Generated protocol buffer code.""" from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool @@ -13,7 +13,7 @@ _runtime_version.Domain.PUBLIC, 7, 36, - 0, + 1, '', 'metalstack/infra/v2/event.proto' ) diff --git a/python/metalstack/infra/v2/switch_pb2.py b/python/metalstack/infra/v2/switch_pb2.py index 2b28371b..74cf5922 100644 --- a/python/metalstack/infra/v2/switch_pb2.py +++ b/python/metalstack/infra/v2/switch_pb2.py @@ -2,7 +2,7 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # NO CHECKED-IN PROTOBUF GENCODE # source: metalstack/infra/v2/switch.proto -# Protobuf Python Version: 7.36.0 +# Protobuf Python Version: 7.36.1 """Generated protocol buffer code.""" from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool @@ -13,7 +13,7 @@ _runtime_version.Domain.PUBLIC, 7, 36, - 0, + 1, '', 'metalstack/infra/v2/switch.proto' ) From d46069467da4d4b43f356ad1ec683395787d4a35 Mon Sep 17 00:00:00 2001 From: Stefan Majer Date: Sat, 10 Oct 2026 15:21:34 +0200 Subject: [PATCH 2/2] Migrate to connect-go v2 --- generate/go_client.tpl | 16 +- generate/go_servicepermissions.tpl | 53 +- go.mod | 11 +- go.sum | 22 +- go/client/client-interceptors.go | 94 +- go/client/client.go | 282 +----- go/client/client_test.go | 40 +- go/client/conn.go | 35 +- go/client/ping_test.go | 6 +- go/client/stream.go | 32 +- go/client/stream_test.go | 46 +- go/client/test_interceptor.go | 119 ++- go/client/test_interceptor_test.go | 11 +- go/errorutil/errors.go | 72 +- go/errorutil/errors_test.go | 32 +- .../admin/v2/adminv2connect/audit.connect.go | 175 ++-- .../v2/adminv2connect/component.connect.go | 229 +++-- .../v2/adminv2connect/filesystem.connect.go | 288 +++--- .../admin/v2/adminv2connect/image.connect.go | 287 +++--- .../admin/v2/adminv2connect/ip.connect.go | 119 ++- .../v2/adminv2connect/machine.connect.go | 564 ++++++------ .../v2/adminv2connect/network.connect.go | 341 +++---- .../v2/adminv2connect/partition.connect.go | 286 +++--- .../v2/adminv2connect/project.connect.go | 117 ++- .../admin/v2/adminv2connect/size.connect.go | 231 +++-- .../size_imageconstraint.connect.go | 349 +++---- .../size_reservation.connect.go | 288 +++--- .../admin/v2/adminv2connect/switch.connect.go | 453 +++++----- .../admin/v2/adminv2connect/task.connect.go | 287 +++--- .../admin/v2/adminv2connect/tenant.connect.go | 288 +++--- .../admin/v2/adminv2connect/token.connect.go | 231 +++-- .../admin/v2/adminv2connect/vpn.connect.go | 175 ++-- .../api/v2/apiv2connect/audit.connect.go | 175 ++-- .../api/v2/apiv2connect/filesystem.connect.go | 173 ++-- .../api/v2/apiv2connect/health.connect.go | 119 ++- .../api/v2/apiv2connect/image.connect.go | 231 +++-- .../api/v2/apiv2connect/ip.connect.go | 343 +++---- .../api/v2/apiv2connect/machine.connect.go | 454 +++++----- .../api/v2/apiv2connect/method.connect.go | 175 ++-- .../api/v2/apiv2connect/network.connect.go | 399 ++++---- .../api/v2/apiv2connect/partition.connect.go | 173 ++-- .../api/v2/apiv2connect/project.connect.go | 850 +++++++++--------- .../api/v2/apiv2connect/size.connect.go | 175 ++-- .../size_imageconstraint.connect.go | 123 ++- .../apiv2connect/size_reservation.connect.go | 177 ++-- .../api/v2/apiv2connect/tenant.connect.go | 844 ++++++++--------- .../api/v2/apiv2connect/token.connect.go | 399 ++++---- .../api/v2/apiv2connect/user.connect.go | 119 ++- .../api/v2/apiv2connect/version.connect.go | 119 ++- .../infra/v2/infrav2connect/bmc.connect.go | 256 +++--- .../infra/v2/infrav2connect/boot.connect.go | 531 ++++++----- .../v2/infrav2connect/component.connect.go | 117 ++- .../infra/v2/infrav2connect/event.connect.go | 119 ++- .../infra/v2/infrav2connect/switch.connect.go | 231 +++-- go/permissions/servicepermissions.go | 53 +- proto/buf.gen.yaml | 4 +- 56 files changed, 5834 insertions(+), 6104 deletions(-) diff --git a/generate/go_client.tpl b/generate/go_client.tpl index 16edcbf9..b08e15aa 100644 --- a/generate/go_client.tpl +++ b/generate/go_client.tpl @@ -3,10 +3,6 @@ package client import ( "context" - - "connectrpc.com/connect" - compress "github.com/klauspost/connect-compress/v2" - {{ range $name, $api := . -}} "github.com/metal-stack/api/go{{ $api.Path }}/{{ $api.Name }}connect" {{ end }} @@ -19,11 +15,6 @@ type ( {{ end }} Ping(context.Context, *PingConfig) } - client struct { - config *DialConfig - - interceptors []connect.Interceptor - } {{ range $name, $api := . -}} {{ $name | title }} interface { {{ range $svc := $api.Services -}} @@ -44,12 +35,7 @@ type ( func (c *client) {{ $name | title }}() {{ $name | title }} { a := &{{ $name }}{ {{ range $svc := $api.Services -}} - {{ $svc.Name | lower }}: {{ $name }}connect.New{{ $svc.Name }}Client( - c.config.HttpClient(), - c.config.BaseURL, - connect.WithInterceptors(c.interceptors...), - compress.WithAll(compress.LevelBalanced), - ), + {{ $svc.Name | lower }}: {{ $name }}connect.New{{ $svc.Name }}Client(c.httpClient), {{ end }} } return a diff --git a/generate/go_servicepermissions.tpl b/generate/go_servicepermissions.tpl index 650d2c46..2543f47f 100644 --- a/generate/go_servicepermissions.tpl +++ b/generate/go_servicepermissions.tpl @@ -3,7 +3,8 @@ package permissions import ( apiv2 "github.com/metal-stack/api/go/metalstack/api/v2" - "connectrpc.com/connect" + "connectrpc.com/connect/v2" + "google.golang.org/protobuf/proto" ) func GetServices() []string { @@ -113,73 +114,73 @@ func GetServicePermissions() *ServicePermissions { } } -func IsPublicScope(req connect.AnyRequest) bool { - _, ok := GetServicePermissions().Visibility.Public[req.Spec().Procedure] +func IsPublicScope(spec connect.Spec) bool { + _, ok := GetServicePermissions().Visibility.Public[spec.Procedure] return ok } -func IsSelfScope(req connect.AnyRequest) bool { - _, ok := GetServicePermissions().Visibility.Self[req.Spec().Procedure] +func IsSelfScope(spec connect.Spec) bool { + _, ok := GetServicePermissions().Visibility.Self[spec.Procedure] return ok } -func IsAdminScope(req connect.AnyRequest) bool { - _, ok := GetServicePermissions().Visibility.Admin[req.Spec().Procedure] +func IsAdminScope(spec connect.Spec) bool { + _, ok := GetServicePermissions().Visibility.Admin[spec.Procedure] return ok } -func IsInfraScope(req connect.AnyRequest) bool { - _, ok := GetServicePermissions().Visibility.Infra[req.Spec().Procedure] +func IsInfraScope(spec connect.Spec) bool { + _, ok := GetServicePermissions().Visibility.Infra[spec.Procedure] return ok } -func IsMachineScope(req connect.AnyRequest) bool { - _, ok := GetServicePermissions().Visibility.Machine[req.Spec().Procedure] +func IsMachineScope(spec connect.Spec) bool { + _, ok := GetServicePermissions().Visibility.Machine[spec.Procedure] return ok } -func IsTenantScope(req connect.AnyRequest) bool { - _, ok := GetServicePermissions().Visibility.Tenant[req.Spec().Procedure] +func IsTenantScope(spec connect.Spec) bool { + _, ok := GetServicePermissions().Visibility.Tenant[spec.Procedure] return ok } -func IsProjectScope(req connect.AnyRequest) bool { - _, ok := GetServicePermissions().Visibility.Project[req.Spec().Procedure] +func IsProjectScope(spec connect.Spec) bool { + _, ok := GetServicePermissions().Visibility.Project[spec.Procedure] return ok } -func IsAuditable(req connect.AnyRequest) bool { - _, ok := GetServicePermissions().Auditable[req.Spec().Procedure] +func IsAuditable(spec connect.Spec) bool { + _, ok := GetServicePermissions().Auditable[spec.Procedure] return ok } -func GetTenantFromRequest(req connect.AnyRequest) (string, bool) { - if !IsTenantScope(req) { +func GetTenantFromRequest(spec connect.Spec, req proto.Message) (string, bool) { + if !IsTenantScope(spec) { return "", false } - switch rq := req.Any().(type) { + switch rq := req.(type) { case interface{ GetLogin() string }: return rq.GetLogin(), true } return "", false } -func GetProjectFromRequest(req connect.AnyRequest) (string, bool) { - if !IsProjectScope(req) { +func GetProjectFromRequest(spec connect.Spec, req proto.Message) (string, bool) { + if !IsProjectScope(spec) { return "", false } - switch rq := req.Any().(type) { + switch rq := req.(type) { case interface{ GetProject() string }: return rq.GetProject(), true } return "", false } -func GetMachineIdFromRequest(req connect.AnyRequest) (string, bool) { - if !IsMachineScope(req) { +func GetMachineIdFromRequest(spec connect.Spec, req proto.Message) (string, bool) { + if !IsMachineScope(spec) { return "", false } - switch rq := req.Any().(type) { + switch rq := req.(type) { case interface{ GetUuid() string }: return rq.GetUuid(), true } diff --git a/go.mod b/go.mod index 70c8f1d4..ea92cb4d 100644 --- a/go.mod +++ b/go.mod @@ -5,13 +5,12 @@ go 1.27 require ( buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.12-20260825204119-511051f7f437.2 buf.build/go/protovalidate v1.4.0 - connectrpc.com/connect v1.21.0 + connectrpc.com/connect/v2 v2.0.0 github.com/bufbuild/protocompile v0.14.1 github.com/go-task/slim-sprig/v3 v3.0.0 github.com/golang-jwt/jwt/v5 v5.3.1 github.com/google/go-cmp v0.7.0 github.com/google/uuid v1.6.0 - github.com/klauspost/connect-compress/v2 v2.1.1 github.com/stretchr/testify v1.12.1 google.golang.org/grpc v1.84.0 google.golang.org/protobuf v1.36.12 @@ -21,12 +20,10 @@ require ( cel.dev/cel-go v0.32.0 // indirect cel.dev/expr v0.25.3 // indirect github.com/antlr4-go/antlr/v4 v4.13.1 // indirect - github.com/klauspost/compress v1.20.1 // indirect - github.com/minio/minlz v1.2.2 // indirect go.yaml.in/yaml/v3 v3.0.5 // indirect - golang.org/x/exp v0.0.0-20261007192929-f45ad48fbe92 // indirect - golang.org/x/sys v0.48.0 // indirect - golang.org/x/text v0.42.0 // indirect + golang.org/x/exp v0.0.0-20261009195045-ca0d7ba23607 // indirect + golang.org/x/sys v0.49.0 // indirect + golang.org/x/text v0.43.0 // indirect google.golang.org/genproto/googleapis/api v0.0.0-20261005182115-fad411399dd8 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20261005182115-fad411399dd8 // indirect ) diff --git a/go.sum b/go.sum index b22c9b74..01e3ac99 100644 --- a/go.sum +++ b/go.sum @@ -6,8 +6,8 @@ cel.dev/cel-go v0.32.0 h1:irvpFKr5EuGPyxeME03ERh0rii1TX+BDAnB9eL3IvNk= cel.dev/cel-go v0.32.0/go.mod h1:DnVip7tpJSsgZymwfT+m1tnEVy3ivAjSMXPx12YrMkU= cel.dev/expr v0.25.3 h1:A2jO8jwOugrrovveCWfj0KEZOfqiLgAcwjpHPhzIGw0= cel.dev/expr v0.25.3/go.mod h1:hrXvqGP6G6gyx8UAHSHJ5RGk//1Oj5nXQ2NI02Nrsg4= -connectrpc.com/connect v1.21.0 h1:LhqSJt7jHf5NJBo9Jq/t/9FjcYAideif0mg+qe2jCUs= -connectrpc.com/connect v1.21.0/go.mod h1:A2ygJrukXwWy32vkCAAHNVguZrqZ+jeZ9rGRnGR4dN4= +connectrpc.com/connect/v2 v2.0.0 h1:PVVpWl2Xv9dIWN2gijs4HK40NSnPFzLqCEEmZ8fCUQ8= +connectrpc.com/connect/v2 v2.0.0/go.mod h1:N32OLrstcPUzkykFynnefFro3+xzSdOrZlK2jHmS/xo= github.com/antlr4-go/antlr/v4 v4.13.1 h1:SqQKkuVZ+zWkMMNkjy5FZe5mr5WURWnlpmOuzYWrPrQ= github.com/antlr4-go/antlr/v4 v4.13.1/go.mod h1:GKmUxMtwp6ZgGwZSva4eWPC5mS6vUAmOABFgjdkM7Nw= github.com/brianvoe/gofakeit/v6 v6.28.0 h1:Xib46XXuQfmlLS2EXRuJpqcw8St6qSZz75OUo0tgAW4= @@ -24,26 +24,20 @@ github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/klauspost/compress v1.20.1 h1:T7kKElXUMXrUJ2E9QhQhxFtcK5rPyLdsGZvdbLMPdiQ= -github.com/klauspost/compress v1.20.1/go.mod h1:LUdAzn7YLVvxLpc7y3V1m40wESHTgc1422pwwBSKYuI= -github.com/klauspost/connect-compress/v2 v2.1.1 h1:ycZNp4rWOZBodVE2Ls5AzK4aHkyK+GteEfzRZgKNs+c= -github.com/klauspost/connect-compress/v2 v2.1.1/go.mod h1:9oilsPHJMzGKkjafSBk9J7iVo4mO+dw0G0KSdVpnlVE= -github.com/minio/minlz v1.2.2 h1:o3YoP6f3VG0oY3Ykhx2mHrpCywsoobsFPVWslgfKcbY= -github.com/minio/minlz v1.2.2/go.mod h1:xHhZ+MJmC2U4ssK/rSENsoyCfv0VFQo1mT6AdCA2RJ8= github.com/rodaine/protogofakeit v0.1.1 h1:ZKouljuRM3A+TArppfBqnH8tGZHOwM/pjvtXe9DaXH8= github.com/rodaine/protogofakeit v0.1.1/go.mod h1:pXn/AstBYMaSfc1/RqH3N82pBuxtWgejz1AlYpY1mI0= github.com/stretchr/testify v1.12.1 h1:EuwCh5fleGS7H32xRwO3wRGT7DxrDhLAT6FF8MpWDWE= github.com/stretchr/testify v1.12.1/go.mod h1:MDEgiDPPsNp5cuIrHPPCyornHKgEVbtFUmoNlxoYthg= go.yaml.in/yaml/v3 v3.0.5 h1:N6y/pJk8buWs9NY5ERU2HSMfm+IuD/OtfdAnq6kESPw= go.yaml.in/yaml/v3 v3.0.5/go.mod h1:HVTZu1O7/Vkt2N+BFy8Zza+lnLsABggaTM2ZpNIGuKg= -golang.org/x/exp v0.0.0-20261007192929-f45ad48fbe92 h1:kc+Gi2MFkd0KWtdDlVxVwjw4KB98/77usJDFj+6YFQ8= -golang.org/x/exp v0.0.0-20261007192929-f45ad48fbe92/go.mod h1:SRjTzy5WcYqRRqquLUvHeeovSwLO0CZ3xcltZNO4Fck= +golang.org/x/exp v0.0.0-20261009195045-ca0d7ba23607 h1:o259es6R0mYtmCeID0xv+dkp5kQSf6qp8zs0j4MdUaI= +golang.org/x/exp v0.0.0-20261009195045-ca0d7ba23607/go.mod h1:SRjTzy5WcYqRRqquLUvHeeovSwLO0CZ3xcltZNO4Fck= golang.org/x/net v0.57.0 h1:K5+3DljvIuDG9/Jv9rvyMywYNFCQ9RSUY6OOTTkT+tE= golang.org/x/net v0.57.0/go.mod h1:KpXc8iv+r3XplLAG/f7Jsf9RPszJzdR0f58q9vGOuEU= -golang.org/x/sys v0.48.0 h1:bbX/i/6MgT9BVLM9RT1thmxL04yeTAhbEz4SyadbXoo= -golang.org/x/sys v0.48.0/go.mod h1:hNLxWAXmnKAxqDtdwIYC4bM9oQPEecfsnNMuSxOs3og= -golang.org/x/text v0.42.0 h1:JbOZXgfeCPU9gacVtYliJqOhD+zhrEqK4LfdpmlUZqI= -golang.org/x/text v0.42.0/go.mod h1:ojzP1Z+2QtioaF8DTtO8K5q7JWVVYwZKenzujK0Zd0E= +golang.org/x/sys v0.49.0 h1:XbzkgYJHdqh/8m2Uu0W/dQv8nktxx4BFHp1M0gROTXA= +golang.org/x/sys v0.49.0/go.mod h1:hNLxWAXmnKAxqDtdwIYC4bM9oQPEecfsnNMuSxOs3og= +golang.org/x/text v0.43.0 h1:1QivrlhwAsnMOcqgOdl9my7s9OyZl8O5/UGUTJVXoWc= +golang.org/x/text v0.43.0/go.mod h1:hbSIYA/amXcRXTFSZqh8tWHEoqRvvbKPJ2uz/KU+a+s= google.golang.org/genproto/googleapis/api v0.0.0-20261005182115-fad411399dd8 h1:cFbkNigDInw+wVTXc+CyhUsoHGJCw0BR6mlNoRVfre0= google.golang.org/genproto/googleapis/api v0.0.0-20261005182115-fad411399dd8/go.mod h1:QK6p7IgD7IZEZJBhhSUCib5X2vMOzlrGCGUw2XyVDh0= google.golang.org/genproto/googleapis/rpc v0.0.0-20261005182115-fad411399dd8 h1:0SXBqli5dnuCKMjI/X3FM226zEaEa0GUcSCJtN1vL2o= diff --git a/go/client/client-interceptors.go b/go/client/client-interceptors.go index e85f14b8..4536f198 100644 --- a/go/client/client-interceptors.go +++ b/go/client/client-interceptors.go @@ -9,68 +9,68 @@ import ( "sync/atomic" "time" - "connectrpc.com/connect" + "connectrpc.com/connect/v2" apiv2models "github.com/metal-stack/api/go/metalstack/api/v2" ) -// authinterceptor adds the required auth headers +// authInterceptor adds the required auth headers type authInterceptor struct { config *DialConfig } -func (i *authInterceptor) WrapUnary(next connect.UnaryFunc) connect.UnaryFunc { - return connect.UnaryFunc(func(ctx context.Context, request connect.AnyRequest) (connect.AnyResponse, error) { - request.Header().Add("Authorization", "Bearer "+i.config.Token) - return next(ctx, request) - }) -} - -func (i *authInterceptor) WrapStreamingClient(next connect.StreamingClientFunc) connect.StreamingClientFunc { - return func(ctx context.Context, spec connect.Spec) connect.StreamingClientConn { - return &streamingInterceptorConn{ - StreamingClientConn: next(ctx, spec), - token: i.config.Token, +func (i *authInterceptor) intercept(next connect.ClientFunc) connect.ClientFunc { + return func(ctx context.Context, spec connect.Spec) (connect.ClientStream, error) { + if callInfo, ok := connect.CallInfoForClientContext(ctx); ok { + callInfo.RequestHeader().Set("Authorization", "Bearer "+i.config.Token) } + return next(ctx, spec) } } -func (i *authInterceptor) WrapStreamingHandler(next connect.StreamingHandlerFunc) connect.StreamingHandlerFunc { - return next +type loggingInterceptor struct { + config *DialConfig } -type streamingInterceptorConn struct { - connect.StreamingClientConn - token string +func (i *loggingInterceptor) intercept(next connect.ClientFunc) connect.ClientFunc { + return func(ctx context.Context, spec connect.Spec) (connect.ClientStream, error) { + stream, err := next(ctx, spec) + if err != nil { + return nil, err + } + return &loggingStream{config: i.config, spec: spec, stream: stream}, nil + } } -func (conn *streamingInterceptorConn) Send(m any) error { - conn.RequestHeader().Add("Authorization", "Bearer "+conn.token) - return conn.StreamingClientConn.Send(m) +type loggingStream struct { + config *DialConfig + spec connect.Spec + stream connect.ClientStream } -type loggingInterceptor struct { - config *DialConfig +func (s *loggingStream) SendHeaders() error { + return s.stream.SendHeaders() } -func (i *loggingInterceptor) WrapUnary(next connect.UnaryFunc) connect.UnaryFunc { - return connect.UnaryFunc(func(ctx context.Context, request connect.AnyRequest) (connect.AnyResponse, error) { - i.config.Log.Debug("intercept", "request procedure", request.Spec().Procedure, "body", request.Any()) - response, err := next(ctx, request) - if err != nil { - return nil, err - } - i.config.Log.Debug("intercept", "request procedure", request.Spec().Procedure, "response", response.Any()) - return response, err - }) +func (s *loggingStream) Send(msg any) error { + s.config.Log.Debug("intercept", "request procedure", s.spec.Procedure, "body", msg) + return s.stream.Send(msg) +} + +func (s *loggingStream) CloseSend() error { + return s.stream.CloseSend() } -func (i *loggingInterceptor) WrapStreamingClient(next connect.StreamingClientFunc) connect.StreamingClientFunc { - // TODO also log here - return next +func (s *loggingStream) Receive(msg any) error { + err := s.stream.Receive(msg) + if err != nil { + return err + } + s.config.Log.Debug("intercept", "request procedure", s.spec.Procedure, "response", msg) + return nil } -func (i *loggingInterceptor) WrapStreamingHandler(next connect.StreamingHandlerFunc) connect.StreamingHandlerFunc { - return next +func (s *loggingStream) Close() error { + return s.stream.Close() } type tokenRenewingInterceptor struct { @@ -82,22 +82,14 @@ type tokenRenewingInterceptor struct { sync.Mutex } -func (i *tokenRenewingInterceptor) WrapUnary(next connect.UnaryFunc) connect.UnaryFunc { - return connect.UnaryFunc(func(ctx context.Context, request connect.AnyRequest) (connect.AnyResponse, error) { +func (i *tokenRenewingInterceptor) intercept(next connect.ClientFunc) connect.ClientFunc { + return func(ctx context.Context, spec connect.Spec) (connect.ClientStream, error) { err := i.renewTokenIfNeeded() if err != nil { return nil, err } - return next(ctx, request) - }) -} - -func (i *tokenRenewingInterceptor) WrapStreamingClient(next connect.StreamingClientFunc) connect.StreamingClientFunc { - return next -} - -func (i *tokenRenewingInterceptor) WrapStreamingHandler(next connect.StreamingHandlerFunc) connect.StreamingHandlerFunc { - return next + return next(ctx, spec) + } } func (i *tokenRenewingInterceptor) renewTokenIfNeeded() error { diff --git a/go/client/client.go b/go/client/client.go index 40b546e1..3f03d2a7 100755 --- a/go/client/client.go +++ b/go/client/client.go @@ -3,10 +3,6 @@ package client import ( "context" - - "connectrpc.com/connect" - compress "github.com/klauspost/connect-compress/v2" - "github.com/metal-stack/api/go/metalstack/admin/v2/adminv2connect" "github.com/metal-stack/api/go/metalstack/api/v2/apiv2connect" "github.com/metal-stack/api/go/metalstack/infra/v2/infrav2connect" @@ -20,11 +16,6 @@ type ( Ping(context.Context, *PingConfig) } - client struct { - config *DialConfig - - interceptors []connect.Interceptor - } Adminv2 interface { Audit() adminv2connect.AuditServiceClient Component() adminv2connect.ComponentServiceClient @@ -124,108 +115,23 @@ type ( func (c *client) Adminv2() Adminv2 { a := &adminv2{ - auditservice: adminv2connect.NewAuditServiceClient( - c.config.HttpClient(), - c.config.BaseURL, - connect.WithInterceptors(c.interceptors...), - compress.WithAll(compress.LevelBalanced), - ), - componentservice: adminv2connect.NewComponentServiceClient( - c.config.HttpClient(), - c.config.BaseURL, - connect.WithInterceptors(c.interceptors...), - compress.WithAll(compress.LevelBalanced), - ), - filesystemservice: adminv2connect.NewFilesystemServiceClient( - c.config.HttpClient(), - c.config.BaseURL, - connect.WithInterceptors(c.interceptors...), - compress.WithAll(compress.LevelBalanced), - ), - imageservice: adminv2connect.NewImageServiceClient( - c.config.HttpClient(), - c.config.BaseURL, - connect.WithInterceptors(c.interceptors...), - compress.WithAll(compress.LevelBalanced), - ), - ipservice: adminv2connect.NewIPServiceClient( - c.config.HttpClient(), - c.config.BaseURL, - connect.WithInterceptors(c.interceptors...), - compress.WithAll(compress.LevelBalanced), - ), - machineservice: adminv2connect.NewMachineServiceClient( - c.config.HttpClient(), - c.config.BaseURL, - connect.WithInterceptors(c.interceptors...), - compress.WithAll(compress.LevelBalanced), - ), - networkservice: adminv2connect.NewNetworkServiceClient( - c.config.HttpClient(), - c.config.BaseURL, - connect.WithInterceptors(c.interceptors...), - compress.WithAll(compress.LevelBalanced), - ), - partitionservice: adminv2connect.NewPartitionServiceClient( - c.config.HttpClient(), - c.config.BaseURL, - connect.WithInterceptors(c.interceptors...), - compress.WithAll(compress.LevelBalanced), - ), - projectservice: adminv2connect.NewProjectServiceClient( - c.config.HttpClient(), - c.config.BaseURL, - connect.WithInterceptors(c.interceptors...), - compress.WithAll(compress.LevelBalanced), - ), - sizeservice: adminv2connect.NewSizeServiceClient( - c.config.HttpClient(), - c.config.BaseURL, - connect.WithInterceptors(c.interceptors...), - compress.WithAll(compress.LevelBalanced), - ), - sizeimageconstraintservice: adminv2connect.NewSizeImageConstraintServiceClient( - c.config.HttpClient(), - c.config.BaseURL, - connect.WithInterceptors(c.interceptors...), - compress.WithAll(compress.LevelBalanced), - ), - sizereservationservice: adminv2connect.NewSizeReservationServiceClient( - c.config.HttpClient(), - c.config.BaseURL, - connect.WithInterceptors(c.interceptors...), - compress.WithAll(compress.LevelBalanced), - ), - switchservice: adminv2connect.NewSwitchServiceClient( - c.config.HttpClient(), - c.config.BaseURL, - connect.WithInterceptors(c.interceptors...), - compress.WithAll(compress.LevelBalanced), - ), - taskservice: adminv2connect.NewTaskServiceClient( - c.config.HttpClient(), - c.config.BaseURL, - connect.WithInterceptors(c.interceptors...), - compress.WithAll(compress.LevelBalanced), - ), - tenantservice: adminv2connect.NewTenantServiceClient( - c.config.HttpClient(), - c.config.BaseURL, - connect.WithInterceptors(c.interceptors...), - compress.WithAll(compress.LevelBalanced), - ), - tokenservice: adminv2connect.NewTokenServiceClient( - c.config.HttpClient(), - c.config.BaseURL, - connect.WithInterceptors(c.interceptors...), - compress.WithAll(compress.LevelBalanced), - ), - vpnservice: adminv2connect.NewVPNServiceClient( - c.config.HttpClient(), - c.config.BaseURL, - connect.WithInterceptors(c.interceptors...), - compress.WithAll(compress.LevelBalanced), - ), + auditservice: adminv2connect.NewAuditServiceClient(c.httpClient), + componentservice: adminv2connect.NewComponentServiceClient(c.httpClient), + filesystemservice: adminv2connect.NewFilesystemServiceClient(c.httpClient), + imageservice: adminv2connect.NewImageServiceClient(c.httpClient), + ipservice: adminv2connect.NewIPServiceClient(c.httpClient), + machineservice: adminv2connect.NewMachineServiceClient(c.httpClient), + networkservice: adminv2connect.NewNetworkServiceClient(c.httpClient), + partitionservice: adminv2connect.NewPartitionServiceClient(c.httpClient), + projectservice: adminv2connect.NewProjectServiceClient(c.httpClient), + sizeservice: adminv2connect.NewSizeServiceClient(c.httpClient), + sizeimageconstraintservice: adminv2connect.NewSizeImageConstraintServiceClient(c.httpClient), + sizereservationservice: adminv2connect.NewSizeReservationServiceClient(c.httpClient), + switchservice: adminv2connect.NewSwitchServiceClient(c.httpClient), + taskservice: adminv2connect.NewTaskServiceClient(c.httpClient), + tenantservice: adminv2connect.NewTenantServiceClient(c.httpClient), + tokenservice: adminv2connect.NewTokenServiceClient(c.httpClient), + vpnservice: adminv2connect.NewVPNServiceClient(c.httpClient), } return a } @@ -284,108 +190,23 @@ func (c *adminv2) VPN() adminv2connect.VPNServiceClient { func (c *client) Apiv2() Apiv2 { a := &apiv2{ - auditservice: apiv2connect.NewAuditServiceClient( - c.config.HttpClient(), - c.config.BaseURL, - connect.WithInterceptors(c.interceptors...), - compress.WithAll(compress.LevelBalanced), - ), - filesystemservice: apiv2connect.NewFilesystemServiceClient( - c.config.HttpClient(), - c.config.BaseURL, - connect.WithInterceptors(c.interceptors...), - compress.WithAll(compress.LevelBalanced), - ), - healthservice: apiv2connect.NewHealthServiceClient( - c.config.HttpClient(), - c.config.BaseURL, - connect.WithInterceptors(c.interceptors...), - compress.WithAll(compress.LevelBalanced), - ), - imageservice: apiv2connect.NewImageServiceClient( - c.config.HttpClient(), - c.config.BaseURL, - connect.WithInterceptors(c.interceptors...), - compress.WithAll(compress.LevelBalanced), - ), - ipservice: apiv2connect.NewIPServiceClient( - c.config.HttpClient(), - c.config.BaseURL, - connect.WithInterceptors(c.interceptors...), - compress.WithAll(compress.LevelBalanced), - ), - machineservice: apiv2connect.NewMachineServiceClient( - c.config.HttpClient(), - c.config.BaseURL, - connect.WithInterceptors(c.interceptors...), - compress.WithAll(compress.LevelBalanced), - ), - methodservice: apiv2connect.NewMethodServiceClient( - c.config.HttpClient(), - c.config.BaseURL, - connect.WithInterceptors(c.interceptors...), - compress.WithAll(compress.LevelBalanced), - ), - networkservice: apiv2connect.NewNetworkServiceClient( - c.config.HttpClient(), - c.config.BaseURL, - connect.WithInterceptors(c.interceptors...), - compress.WithAll(compress.LevelBalanced), - ), - partitionservice: apiv2connect.NewPartitionServiceClient( - c.config.HttpClient(), - c.config.BaseURL, - connect.WithInterceptors(c.interceptors...), - compress.WithAll(compress.LevelBalanced), - ), - projectservice: apiv2connect.NewProjectServiceClient( - c.config.HttpClient(), - c.config.BaseURL, - connect.WithInterceptors(c.interceptors...), - compress.WithAll(compress.LevelBalanced), - ), - sizeservice: apiv2connect.NewSizeServiceClient( - c.config.HttpClient(), - c.config.BaseURL, - connect.WithInterceptors(c.interceptors...), - compress.WithAll(compress.LevelBalanced), - ), - sizeimageconstraintservice: apiv2connect.NewSizeImageConstraintServiceClient( - c.config.HttpClient(), - c.config.BaseURL, - connect.WithInterceptors(c.interceptors...), - compress.WithAll(compress.LevelBalanced), - ), - sizereservationservice: apiv2connect.NewSizeReservationServiceClient( - c.config.HttpClient(), - c.config.BaseURL, - connect.WithInterceptors(c.interceptors...), - compress.WithAll(compress.LevelBalanced), - ), - tenantservice: apiv2connect.NewTenantServiceClient( - c.config.HttpClient(), - c.config.BaseURL, - connect.WithInterceptors(c.interceptors...), - compress.WithAll(compress.LevelBalanced), - ), - tokenservice: apiv2connect.NewTokenServiceClient( - c.config.HttpClient(), - c.config.BaseURL, - connect.WithInterceptors(c.interceptors...), - compress.WithAll(compress.LevelBalanced), - ), - userservice: apiv2connect.NewUserServiceClient( - c.config.HttpClient(), - c.config.BaseURL, - connect.WithInterceptors(c.interceptors...), - compress.WithAll(compress.LevelBalanced), - ), - versionservice: apiv2connect.NewVersionServiceClient( - c.config.HttpClient(), - c.config.BaseURL, - connect.WithInterceptors(c.interceptors...), - compress.WithAll(compress.LevelBalanced), - ), + auditservice: apiv2connect.NewAuditServiceClient(c.httpClient), + filesystemservice: apiv2connect.NewFilesystemServiceClient(c.httpClient), + healthservice: apiv2connect.NewHealthServiceClient(c.httpClient), + imageservice: apiv2connect.NewImageServiceClient(c.httpClient), + ipservice: apiv2connect.NewIPServiceClient(c.httpClient), + machineservice: apiv2connect.NewMachineServiceClient(c.httpClient), + methodservice: apiv2connect.NewMethodServiceClient(c.httpClient), + networkservice: apiv2connect.NewNetworkServiceClient(c.httpClient), + partitionservice: apiv2connect.NewPartitionServiceClient(c.httpClient), + projectservice: apiv2connect.NewProjectServiceClient(c.httpClient), + sizeservice: apiv2connect.NewSizeServiceClient(c.httpClient), + sizeimageconstraintservice: apiv2connect.NewSizeImageConstraintServiceClient(c.httpClient), + sizereservationservice: apiv2connect.NewSizeReservationServiceClient(c.httpClient), + tenantservice: apiv2connect.NewTenantServiceClient(c.httpClient), + tokenservice: apiv2connect.NewTokenServiceClient(c.httpClient), + userservice: apiv2connect.NewUserServiceClient(c.httpClient), + versionservice: apiv2connect.NewVersionServiceClient(c.httpClient), } return a } @@ -444,36 +265,11 @@ func (c *apiv2) Version() apiv2connect.VersionServiceClient { func (c *client) Infrav2() Infrav2 { a := &infrav2{ - bmcservice: infrav2connect.NewBMCServiceClient( - c.config.HttpClient(), - c.config.BaseURL, - connect.WithInterceptors(c.interceptors...), - compress.WithAll(compress.LevelBalanced), - ), - bootservice: infrav2connect.NewBootServiceClient( - c.config.HttpClient(), - c.config.BaseURL, - connect.WithInterceptors(c.interceptors...), - compress.WithAll(compress.LevelBalanced), - ), - componentservice: infrav2connect.NewComponentServiceClient( - c.config.HttpClient(), - c.config.BaseURL, - connect.WithInterceptors(c.interceptors...), - compress.WithAll(compress.LevelBalanced), - ), - eventservice: infrav2connect.NewEventServiceClient( - c.config.HttpClient(), - c.config.BaseURL, - connect.WithInterceptors(c.interceptors...), - compress.WithAll(compress.LevelBalanced), - ), - switchservice: infrav2connect.NewSwitchServiceClient( - c.config.HttpClient(), - c.config.BaseURL, - connect.WithInterceptors(c.interceptors...), - compress.WithAll(compress.LevelBalanced), - ), + bmcservice: infrav2connect.NewBMCServiceClient(c.httpClient), + bootservice: infrav2connect.NewBootServiceClient(c.httpClient), + componentservice: infrav2connect.NewComponentServiceClient(c.httpClient), + eventservice: infrav2connect.NewEventServiceClient(c.httpClient), + switchservice: infrav2connect.NewSwitchServiceClient(c.httpClient), } return a } diff --git a/go/client/client_test.go b/go/client/client_test.go index 3dc2399e..f5324c5d 100644 --- a/go/client/client_test.go +++ b/go/client/client_test.go @@ -16,13 +16,15 @@ import ( "time" - "connectrpc.com/connect" + "connectrpc.com/connect/v2" + "connectrpc.com/connect/v2/connecthttp" "github.com/golang-jwt/jwt/v5" "github.com/metal-stack/api/go/client" apiv2 "github.com/metal-stack/api/go/metalstack/api/v2" infrav2 "github.com/metal-stack/api/go/metalstack/infra/v2" "github.com/metal-stack/api/go/metalstack/infra/v2/infrav2connect" "github.com/stretchr/testify/require" + "google.golang.org/protobuf/proto" ) func Test_Client(t *testing.T) { @@ -39,41 +41,41 @@ func Test_Client(t *testing.T) { BaseURL: "http://localhost", Token: tokenString, - Interceptors: []connect.Interceptor{ + Interceptors: []connect.ClientInterceptor{ client.NewTestInterceptor(t, []client.ClientCall{ { WantRequest: &apiv2.VersionServiceGetRequest{}, - WantResponse: func() connect.AnyResponse { - return connect.NewResponse(&apiv2.VersionServiceGetResponse{ + WantResponse: func() proto.Message { + return &apiv2.VersionServiceGetResponse{ Version: &apiv2.Version{Version: "1.0"}, - }) + } }, }, { WantRequest: &apiv2.VersionServiceGetRequest{}, - WantResponse: func() connect.AnyResponse { - return connect.NewResponse(&apiv2.VersionServiceGetResponse{ + WantResponse: func() proto.Message { + return &apiv2.VersionServiceGetResponse{ Version: &apiv2.Version{Version: "1.0"}, - }) + } }, }, { WantRequest: &apiv2.TokenServiceRefreshRequest{}, - WantResponse: func() connect.AnyResponse { + WantResponse: func() proto.Message { tokenString, err := generateToken(2 * time.Second) require.NoError(t, err) - return connect.NewResponse(&apiv2.TokenServiceRefreshResponse{ + return &apiv2.TokenServiceRefreshResponse{ Secret: tokenString, - }) + } }, }, { WantRequest: &apiv2.VersionServiceGetRequest{}, - WantResponse: func() connect.AnyResponse { - return connect.NewResponse(&apiv2.VersionServiceGetResponse{ + WantResponse: func() proto.Message { + return &apiv2.VersionServiceGetResponse{ Version: &apiv2.Version{Version: "1.0"}, - }) + } }, }, }), @@ -134,11 +136,13 @@ func Test_ClientInterceptors(t *testing.T) { var ( bs = &mockBMCService{} mux = http.NewServeMux() + srv = connect.NewServer() log = slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelDebug})) ctx = t.Context() ) - mux.Handle(infrav2connect.NewBMCServiceHandler(bs)) + infrav2connect.RegisterBMCServiceHandler(srv, bs) + connecthttp.Mount(mux, srv) server := httptest.NewTLSServer(mux) server.EnableHTTP2 = true defer func() { @@ -179,7 +183,7 @@ func (m *mockBMCService) BMCCommandDone(context.Context, *infrav2.BMCCommandDone } func (m *mockBMCService) UpdateBMCInfo(ctx context.Context, _ *infrav2.UpdateBMCInfoRequest) (*infrav2.UpdateBMCInfoResponse, error) { - callinfo, _ := connect.CallInfoForHandlerContext(ctx) + callinfo, _ := connect.CallInfoForServerContext(ctx) authHeader := callinfo.RequestHeader().Get("Authorization") _, token, found := strings.Cut(authHeader, "Bearer ") @@ -191,8 +195,8 @@ func (m *mockBMCService) UpdateBMCInfo(ctx context.Context, _ *infrav2.UpdateBMC return &infrav2.UpdateBMCInfoResponse{}, nil } -func (m *mockBMCService) WaitForBMCCommand(ctx context.Context, _ *infrav2.WaitForBMCCommandRequest, stream *connect.ServerStream[infrav2.WaitForBMCCommandResponse]) error { - callinfo, _ := connect.CallInfoForHandlerContext(ctx) +func (m *mockBMCService) WaitForBMCCommand(ctx context.Context, _ *infrav2.WaitForBMCCommandRequest, stream infrav2connect.BMCServiceWaitForBMCCommandServerStream) error { + callinfo, _ := connect.CallInfoForServerContext(ctx) authHeader := callinfo.RequestHeader().Get("Authorization") _, token, found := strings.Cut(authHeader, "Bearer ") diff --git a/go/client/conn.go b/go/client/conn.go index a415bc83..9412283e 100644 --- a/go/client/conn.go +++ b/go/client/conn.go @@ -9,7 +9,9 @@ import ( "os" "time" - "connectrpc.com/connect" + "connectrpc.com/connect/v2" + "connectrpc.com/connect/v2/connectgzip" + "connectrpc.com/connect/v2/connecthttp" "github.com/golang-jwt/jwt/v5" ) @@ -38,7 +40,7 @@ type ( TokenFileRereadDuration time.Duration // Optional client Interceptors - Interceptors []connect.Interceptor + Interceptors []connect.ClientInterceptor UserAgent string // TokenRenewal defines if and how the token should be renewed @@ -61,6 +63,13 @@ type ( } PersistTokenFn func(token string) error + client struct { + config *DialConfig + + interceptors []connect.ClientInterceptor + + httpClient *connect.Client + } ) func New(config *DialConfig) (Client, error) { @@ -71,33 +80,43 @@ func New(config *DialConfig) (Client, error) { c := &client{ config: config, - interceptors: []connect.Interceptor{}, + interceptors: []connect.ClientInterceptor{}, } if config.Token != "" { authInterceptor := &authInterceptor{config: config} - c.interceptors = append(c.interceptors, authInterceptor) + c.interceptors = append(c.interceptors, authInterceptor.intercept) if config.TokenRenewal != nil { tokenRenewingInterceptor := &tokenRenewingInterceptor{config: config, client: c} - c.interceptors = append(c.interceptors, tokenRenewingInterceptor) + c.interceptors = append(c.interceptors, tokenRenewingInterceptor.intercept) } } if config.TokenFile != "" { authInterceptor := &authInterceptor{config: config} - c.interceptors = append(c.interceptors, authInterceptor) + c.interceptors = append(c.interceptors, authInterceptor.intercept) tokenRenewingInterceptor := &tokenRenewingInterceptor{config: config, client: c} - c.interceptors = append(c.interceptors, tokenRenewingInterceptor) + c.interceptors = append(c.interceptors, tokenRenewingInterceptor.intercept) } if config.Log != nil { loggingInterceptor := &loggingInterceptor{config: config} - c.interceptors = append(c.interceptors, loggingInterceptor) + c.interceptors = append(c.interceptors, loggingInterceptor.intercept) } c.interceptors = append(c.interceptors, config.Interceptors...) + gzipCompressor := connectgzip.New() + options := []connecthttp.Option{ + connecthttp.WithCompressors(gzipCompressor), + connecthttp.WithSendCompression(gzipCompressor.Name()), + } + c.httpClient = connect.NewClient( + connecthttp.NewTransport(c.config.HttpClient(), c.config.BaseURL, options...), + c.interceptors..., + ) + return c, nil } diff --git a/go/client/ping_test.go b/go/client/ping_test.go index b8168c87..72f62b8e 100644 --- a/go/client/ping_test.go +++ b/go/client/ping_test.go @@ -9,6 +9,8 @@ import ( "testing" "time" + "connectrpc.com/connect/v2" + "connectrpc.com/connect/v2/connecthttp" "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/metal-stack/api/go/client" @@ -24,11 +26,13 @@ import ( func Test_Ping(t *testing.T) { var ( mux = http.NewServeMux() + srv = connect.NewServer() log = slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelDebug})) cs = &mockComponentService{log: log} ) - mux.Handle(infrav2connect.NewComponentServiceHandler(cs)) + infrav2connect.RegisterComponentServiceHandler(srv, cs) + connecthttp.Mount(mux, srv) server := httptest.NewTLSServer(mux) server.EnableHTTP2 = true defer server.Close() diff --git a/go/client/stream.go b/go/client/stream.go index 9b0164ac..d9c7e2d6 100644 --- a/go/client/stream.go +++ b/go/client/stream.go @@ -3,16 +3,21 @@ package client import ( "context" "errors" + "io" "log/slog" "time" - - "connectrpc.com/connect" ) const defaultStreamBackoff = time.Second type ( - StreamFunc[T any] func(ctx context.Context) (*connect.ServerStreamForClient[T], error) + // Stream is the client-side view of a server-streaming RPC. + Stream[T any] interface { + Receive() (*T, error) + Close() error + } + + StreamFunc[T any] func(ctx context.Context) (Stream[T], error) StreamOption func(*streamOptions) @@ -100,17 +105,20 @@ func ReconnectingStreamRead[T any](ctx context.Context, open StreamFunc[T], opts return messages, errorsChan } -func consumeStream[T any](ctx context.Context, stream *connect.ServerStreamForClient[T], messages chan<- *T, errorsChan chan<- error, options *streamOptions) bool { - for stream.Receive() { - if !send(ctx, messages, stream.Msg()) { - return false +func consumeStream[T any](ctx context.Context, stream Stream[T], messages chan<- *T, errorsChan chan<- error, options *streamOptions) bool { + for { + msg, err := stream.Receive() + if err != nil { + if !errors.Is(err, io.EOF) && !errors.Is(err, context.Canceled) && ctx.Err() == nil { + options.error("reading stream failed, reconnecting", err) + if !send(ctx, errorsChan, err) { + return false + } + } + break } - } - err := stream.Err() - if err != nil && !errors.Is(err, context.Canceled) && ctx.Err() == nil { - options.error("reading stream failed, reconnecting", err) - if !send(ctx, errorsChan, err) { + if !send(ctx, messages, msg) { return false } } diff --git a/go/client/stream_test.go b/go/client/stream_test.go index 3642d464..cf41ae94 100644 --- a/go/client/stream_test.go +++ b/go/client/stream_test.go @@ -2,16 +2,16 @@ package client_test import ( "context" - "errors" "log/slog" "strconv" "testing" "time" - "connectrpc.com/connect" + "connectrpc.com/connect/v2" "github.com/metal-stack/api/go/client" infrav2 "github.com/metal-stack/api/go/metalstack/infra/v2" "github.com/stretchr/testify/require" + "google.golang.org/protobuf/proto" ) func Test_ReconnectingStreamRead_Reconnects(t *testing.T) { @@ -19,30 +19,30 @@ func Test_ReconnectingStreamRead_Reconnects(t *testing.T) { c, err := client.New(&client.DialConfig{ BaseURL: "http://this-is-just-for-testing", - Interceptors: []connect.Interceptor{ + Interceptors: []connect.ClientInterceptor{ client.NewTestInterceptor(t, []client.ClientCall{ { WantRequest: req, - WantStreamResponses: func() []connect.AnyResponse { - return []connect.AnyResponse{ - connect.NewResponse(&infrav2.WaitForBMCCommandResponse{CommandId: "1"}), - connect.NewResponse(&infrav2.WaitForBMCCommandResponse{CommandId: "2"}), + WantStreamResponses: func() []proto.Message { + return []proto.Message{ + (&infrav2.WaitForBMCCommandResponse{CommandId: "1"}), + (&infrav2.WaitForBMCCommandResponse{CommandId: "2"}), } }, }, { WantRequest: req, - WantStreamResponses: func() []connect.AnyResponse { - return []connect.AnyResponse{ - connect.NewResponse(&infrav2.WaitForBMCCommandResponse{CommandId: "3"}), - connect.NewResponse(&infrav2.WaitForBMCCommandResponse{CommandId: "4"}), + WantStreamResponses: func() []proto.Message { + return []proto.Message{ + (&infrav2.WaitForBMCCommandResponse{CommandId: "3"}), + (&infrav2.WaitForBMCCommandResponse{CommandId: "4"}), } }, }, { WantRequest: req, - WantStreamResponses: func() []connect.AnyResponse { - return []connect.AnyResponse{connect.NewResponse(&infrav2.WaitForBMCCommandResponse{CommandId: "5"})} + WantStreamResponses: func() []proto.Message { + return []proto.Message{(&infrav2.WaitForBMCCommandResponse{CommandId: "5"})} }, BlockingStream: true, }, @@ -54,7 +54,7 @@ func Test_ReconnectingStreamRead_Reconnects(t *testing.T) { ctx, cancel := context.WithCancel(t.Context()) defer cancel() - messages, errs := client.ReconnectingStreamRead(ctx, func(ctx context.Context) (*connect.ServerStreamForClient[infrav2.WaitForBMCCommandResponse], error) { + messages, errs := client.ReconnectingStreamRead(ctx, func(ctx context.Context) (client.Stream[infrav2.WaitForBMCCommandResponse], error) { return c.Infrav2().BMC().WaitForBMCCommand(ctx, &infrav2.WaitForBMCCommandRequest{Partition: "p1"}) }, client.WithStreamBackoff(0), client.WithStreamLogger(slog.Default())) @@ -78,18 +78,18 @@ func Test_ReconnectingStreamRead_ReportsErrorsAndReconnects(t *testing.T) { c, err := client.New(&client.DialConfig{ BaseURL: "http://this-is-just-for-testing", - Interceptors: []connect.Interceptor{ + Interceptors: []connect.ClientInterceptor{ client.NewTestInterceptor(t, []client.ClientCall{ { WantRequest: req, - WantError: connect.NewError(connect.CodeInternal, errors.New("stream failure")), + WantError: connect.NewError(connect.CodeInternal, "stream failure"), }, { WantRequest: req, - WantStreamResponses: func() []connect.AnyResponse { - return []connect.AnyResponse{ - connect.NewResponse(&infrav2.WaitForBMCCommandResponse{CommandId: "1"}), - connect.NewResponse(&infrav2.WaitForBMCCommandResponse{CommandId: "2"}), + WantStreamResponses: func() []proto.Message { + return []proto.Message{ + (&infrav2.WaitForBMCCommandResponse{CommandId: "1"}), + (&infrav2.WaitForBMCCommandResponse{CommandId: "2"}), } }, BlockingStream: true, @@ -102,7 +102,7 @@ func Test_ReconnectingStreamRead_ReportsErrorsAndReconnects(t *testing.T) { ctx, cancel := context.WithCancel(t.Context()) defer cancel() - messages, errs := client.ReconnectingStreamRead(ctx, func(ctx context.Context) (*connect.ServerStreamForClient[infrav2.WaitForBMCCommandResponse], error) { + messages, errs := client.ReconnectingStreamRead(ctx, func(ctx context.Context) (client.Stream[infrav2.WaitForBMCCommandResponse], error) { return c.Infrav2().BMC().WaitForBMCCommand(ctx, &infrav2.WaitForBMCCommandRequest{Partition: "p1"}) }, client.WithStreamBackoff(0)) @@ -131,7 +131,7 @@ func Test_ReconnectingStreamRead_ClosesOnContextCancel(t *testing.T) { c, err := client.New(&client.DialConfig{ BaseURL: "http://this-is-just-for-testing", - Interceptors: []connect.Interceptor{ + Interceptors: []connect.ClientInterceptor{ client.NewTestInterceptor(t, []client.ClientCall{ { WantRequest: req, @@ -144,7 +144,7 @@ func Test_ReconnectingStreamRead_ClosesOnContextCancel(t *testing.T) { ctx, cancel := context.WithCancel(t.Context()) - messages, errs := client.ReconnectingStreamRead(ctx, func(ctx context.Context) (*connect.ServerStreamForClient[infrav2.WaitForBMCCommandResponse], error) { + messages, errs := client.ReconnectingStreamRead(ctx, func(ctx context.Context) (client.Stream[infrav2.WaitForBMCCommandResponse], error) { return c.Infrav2().BMC().WaitForBMCCommand(ctx, &infrav2.WaitForBMCCommandRequest{Partition: "p1"}) }, client.WithStreamBackoff(0)) diff --git a/go/client/test_interceptor.go b/go/client/test_interceptor.go index debd7468..1b26e95c 100644 --- a/go/client/test_interceptor.go +++ b/go/client/test_interceptor.go @@ -2,13 +2,11 @@ package client import ( "context" - "errors" "io" - "net/http" "reflect" "testing" - "connectrpc.com/connect" + "connectrpc.com/connect/v2" "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "google.golang.org/protobuf/proto" @@ -24,87 +22,58 @@ type TestClientInterceptor struct { type ClientCall struct { WantRequest proto.Message - WantResponse func() connect.AnyResponse + WantResponse func() proto.Message WantError *connect.Error - WantStreamResponses func() []connect.AnyResponse + WantStreamResponses func() []proto.Message BlockingStream bool } -func NewTestInterceptor(t *testing.T, calls []ClientCall) *TestClientInterceptor { - return &TestClientInterceptor{ +func NewTestInterceptor(t *testing.T, calls []ClientCall) connect.ClientInterceptor { + interceptor := &TestClientInterceptor{ t: t, calls: calls, } + return interceptor.intercept } -func (t *TestClientInterceptor) WrapUnary(next connect.UnaryFunc) connect.UnaryFunc { - return func(ctx context.Context, ar connect.AnyRequest) (connect.AnyResponse, error) { - defer func() { t.count++ }() - +func (t *TestClientInterceptor) intercept(next connect.ClientFunc) connect.ClientFunc { + return func(ctx context.Context, spec connect.Spec) (connect.ClientStream, error) { if t.count >= len(t.calls) { - t.t.Errorf("received an unexpected client call of type %T: %v", ar.Any(), ar.Any()) - t.t.FailNow() - } - - call := t.calls[t.count] - - if diff := cmp.Diff(call.WantRequest, ar.Any(), protocmp.Transform(), IgnoreUnexported(), cmpopts.IgnoreTypes(protoimpl.MessageState{})); diff != "" { - t.t.Errorf("request diff (+got -want):\n %s", diff) - t.t.FailNow() - } - - if call.WantError != nil { - return nil, call.WantError - } - - return call.WantResponse(), nil - } -} - -func (t *TestClientInterceptor) WrapStreamingClient(connect.StreamingClientFunc) connect.StreamingClientFunc { - return func(ctx context.Context, spec connect.Spec) connect.StreamingClientConn { - if t.count >= len(t.calls) { - t.t.Errorf("received an unexpected streaming client call for procedure %s", spec.Procedure) + t.t.Errorf("received an unexpected client call for procedure %s", spec.Procedure) t.t.FailNow() } call := t.calls[t.count] t.count++ - return &testStreamingClientConn{t: t.t, ctx: ctx, spec: spec, call: call} + return &testClientStream{t: t.t, ctx: ctx, spec: spec, call: call}, nil } } -func (t *TestClientInterceptor) WrapStreamingHandler(connect.StreamingHandlerFunc) connect.StreamingHandlerFunc { - t.t.Errorf("streaming handler not supported") - return nil -} - -type testStreamingClientConn struct { +type testClientStream struct { t *testing.T ctx context.Context spec connect.Spec call ClientCall - responses []connect.AnyResponse + responses []proto.Message recvIndex int errReturned bool } -func (c *testStreamingClientConn) Spec() connect.Spec { return c.spec } -func (c *testStreamingClientConn) Peer() connect.Peer { return connect.Peer{} } +func (c *testClientStream) SendHeaders() error { return nil } -func (c *testStreamingClientConn) Send(msg any) error { +func (c *testClientStream) Send(msg any) error { got, ok := msg.(proto.Message) if !ok { c.t.Errorf("unexpected send message of type %T", msg) - return connect.NewError(connect.CodeInternal, errors.New("unexpected send message")) + return connect.NewError(connect.CodeInternal, "unexpected send message") } if diff := cmp.Diff(c.call.WantRequest, got, protocmp.Transform(), IgnoreUnexported(), cmpopts.IgnoreTypes(protoimpl.MessageState{})); diff != "" { c.t.Errorf("request diff (+got -want):\n %s", diff) - return connect.NewError(connect.CodeInvalidArgument, errors.New("unexpected request")) + return connect.NewError(connect.CodeInvalidArgument, "unexpected request") } if c.call.WantStreamResponses != nil { @@ -114,32 +83,30 @@ func (c *testStreamingClientConn) Send(msg any) error { return nil } -func (c *testStreamingClientConn) RequestHeader() http.Header { return http.Header{} } -func (c *testStreamingClientConn) CloseRequest() error { return nil } -func (c *testStreamingClientConn) ResponseHeader() http.Header { return http.Header{} } -func (c *testStreamingClientConn) ResponseTrailer() http.Header { - return http.Header{} -} -func (c *testStreamingClientConn) CloseResponse() error { return nil } +func (c *testClientStream) CloseSend() error { return nil } -func (c *testStreamingClientConn) Receive(msg any) error { - if c.recvIndex < len(c.responses) { - target, ok := msg.(proto.Message) - if !ok { - c.t.Errorf("unexpected receive message of type %T", msg) - return connect.NewError(connect.CodeInternal, errors.New("unexpected receive message")) - } +func (c *testClientStream) Receive(msg any) error { + if c.spec.StreamType == connect.StreamTypeUnary { + return c.receiveUnary(msg) + } + return c.receiveStream(msg) +} - source, ok := c.responses[c.recvIndex].Any().(proto.Message) - if !ok { - c.t.Errorf("unexpected response message of type %T", c.responses[c.recvIndex].Any()) - return connect.NewError(connect.CodeInternal, errors.New("unexpected response message")) - } +func (c *testClientStream) receiveUnary(msg any) error { + if c.call.WantError != nil { + return c.call.WantError + } + if c.call.WantResponse == nil { + return nil + } + return c.copyMessage(msg, c.call.WantResponse()) +} - proto.Reset(target) - proto.Merge(target, source) +func (c *testClientStream) receiveStream(msg any) error { + if c.recvIndex < len(c.responses) { + err := c.copyMessage(msg, c.responses[c.recvIndex]) c.recvIndex++ - return nil + return err } if c.call.WantError != nil && !c.errReturned { @@ -154,6 +121,20 @@ func (c *testStreamingClientConn) Receive(msg any) error { return io.EOF } +func (c *testClientStream) Close() error { return nil } + +func (c *testClientStream) copyMessage(dst any, src proto.Message) error { + target, ok := dst.(proto.Message) + if !ok { + c.t.Errorf("unexpected receive message of type %T", dst) + return connect.NewError(connect.CodeInternal, "unexpected receive message") + } + + proto.Reset(target) + proto.Merge(target, src) + return nil +} + func IgnoreUnexported() cmp.Option { // the exporter opt allows all unexported fields: https://github.com/google/go-cmp/pull/176 return cmp.Exporter(func(reflect.Type) bool { return true }) diff --git a/go/client/test_interceptor_test.go b/go/client/test_interceptor_test.go index c8f938a3..decc69af 100644 --- a/go/client/test_interceptor_test.go +++ b/go/client/test_interceptor_test.go @@ -4,12 +4,13 @@ import ( "log/slog" "testing" - "connectrpc.com/connect" + "connectrpc.com/connect/v2" "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" client "github.com/metal-stack/api/go/client" apiv2 "github.com/metal-stack/api/go/metalstack/api/v2" "github.com/stretchr/testify/require" + "google.golang.org/protobuf/proto" "google.golang.org/protobuf/runtime/protoimpl" "google.golang.org/protobuf/testing/protocmp" ) @@ -17,16 +18,16 @@ import ( func TestInterceptor(t *testing.T) { cl, err := client.New(&client.DialConfig{ BaseURL: "http://this-is-just-for-testing", - Interceptors: []connect.Interceptor{ + Interceptors: []connect.ClientInterceptor{ client.NewTestInterceptor(t, []client.ClientCall{ { WantRequest: &apiv2.IPServiceGetRequest{ Ip: "1.2.3.4", }, - WantResponse: func() connect.AnyResponse { - return connect.NewResponse(&apiv2.IPServiceGetResponse{ + WantResponse: func() proto.Message { + return &apiv2.IPServiceGetResponse{ Ip: &apiv2.IP{Ip: "1.2.3.4"}, - }) + } }, }, }), diff --git a/go/errorutil/errors.go b/go/errorutil/errors.go index 4926a72e..fb8ed943 100644 --- a/go/errorutil/errors.go +++ b/go/errorutil/errors.go @@ -5,7 +5,7 @@ import ( "fmt" "strings" - "connectrpc.com/connect" + "connectrpc.com/connect/v2" "google.golang.org/grpc/status" "github.com/google/go-cmp/cmp" @@ -15,13 +15,17 @@ import ( // If there is no backend-specific wrapped error given to this function, it will return an internal error. // If there are multiple errors wrapped, this function only cares about the first found error in the error tree. func Convert(err error) *connect.Error { + if err == nil { + return connect.NewError(connect.CodeUnknown, "") + } + // Ipam or other connect errors if connectErr, ok := errors.AsType[*connect.Error](err); ok { // when the connect error is wrapped deeper a tree, connect.Error() calls the string function on // the error and adds things like "internal: ..." // so we replace the wrapped error message with the direct message cleaned := strings.Replace(err.Error(), connectErr.Error(), connectErr.Message(), 1) - return connect.NewError(connectErr.Code(), errors.New(cleaned)) + return connect.NewError(connectErr.Code(), cleaned) } // for other pure grpc apis @@ -38,118 +42,134 @@ func Convert(err error) *connect.Error { st, ok := iterErr.(grpcstatus) if ok { cleaned := strings.Replace(err.Error(), st.GRPCStatus().String(), st.GRPCStatus().Message(), 1) - return connect.NewError(connect.Code(st.GRPCStatus().Code()), errors.New(cleaned)) + return connect.NewError(connect.Code(st.GRPCStatus().Code()), cleaned) } iterErr = errors.Unwrap(iterErr) if iterErr == nil { // just a theoretical case - return connect.NewError(connect.CodeUnknown, err) + return connect.NewError(connect.CodeUnknown, err.Error()) } } } - return connect.NewError(connect.CodeInternal, err) + return connect.NewError(connect.CodeInternal, err.Error()).WithCause(err) +} + +// newError creates a connect.Error with the given code and formats the message +// using the supplied format and arguments. It supports the %w verb, wrapping +// the referenced error as the connect.Error's cause. +func newError(code connect.Code, format string, args ...any) *connect.Error { + err := fmt.Errorf(format, args...) + return connect.NewError(code, err.Error()).WithCause(err) +} + +// newErrorFrom creates a connect.Error with the given code from an underlying error. +func newErrorFrom(code connect.Code, err error) error { + if err == nil { + return connect.NewError(code, "") + } + return connect.NewError(code, err.Error()).WithCause(err) } // NotFound creates a new Not Found error (Connect Code 5) with a formatted error message. func NotFound(format string, args ...any) error { - return connect.NewError(connect.CodeNotFound, fmt.Errorf(format, args...)) + return newError(connect.CodeNotFound, format, args...) } // Conflict creates a new Already Exists error (Connect Code 6) with a formatted error message. func Conflict(format string, args ...any) error { - return connect.NewError(connect.CodeAlreadyExists, fmt.Errorf(format, args...)) + return newError(connect.CodeAlreadyExists, format, args...) } // Internal creates a new Internal error (Connect Code 13) with a formatted error message. func Internal(format string, args ...any) error { - return connect.NewError(connect.CodeInternal, fmt.Errorf(format, args...)) + return newError(connect.CodeInternal, format, args...) } // Aborted creates a new Aborted error (Connect Code 10) with a formatted error message. func Aborted(format string, args ...any) error { - return connect.NewError(connect.CodeAborted, fmt.Errorf(format, args...)) + return newError(connect.CodeAborted, format, args...) } // InvalidArgument creates a new Invalid Argument error (Connect Code 3) with a formatted error message. func InvalidArgument(format string, args ...any) error { - return connect.NewError(connect.CodeInvalidArgument, fmt.Errorf(format, args...)) + return newError(connect.CodeInvalidArgument, format, args...) } // FailedPrecondition creates a new Failed Precondition error (Connect Code 9) with a formatted error message. func FailedPrecondition(format string, args ...any) error { - return connect.NewError(connect.CodeFailedPrecondition, fmt.Errorf(format, args...)) + return newError(connect.CodeFailedPrecondition, format, args...) } // Unauthenticated creates a new Unauthenticated error (Connect Code 16) with a formatted error message. func Unauthenticated(format string, args ...any) error { - return connect.NewError(connect.CodeUnauthenticated, fmt.Errorf(format, args...)) + return newError(connect.CodeUnauthenticated, format, args...) } // ResourceExhausted creates a new Resource Exhausted error (Connect Code 8) with a formatted error message. func ResourceExhausted(format string, args ...any) error { - return connect.NewError(connect.CodeResourceExhausted, fmt.Errorf(format, args...)) + return newError(connect.CodeResourceExhausted, format, args...) } // PermissionDenied creates a new Permission Denied error (Connect Code 7) with a formatted error message. func PermissionDenied(format string, args ...any) error { - return connect.NewError(connect.CodePermissionDenied, fmt.Errorf(format, args...)) + return newError(connect.CodePermissionDenied, format, args...) } // Unimplemented creates a new Unimplemented error (Connect Code 12) with a formatted error message. func Unimplemented(format string, args ...any) error { - return connect.NewError(connect.CodeUnimplemented, fmt.Errorf(format, args...)) + return newError(connect.CodeUnimplemented, format, args...) } // NewNotFound creates a new Not Found error (Connect Code 5) from an underlying error. func NewNotFound(err error) error { - return connect.NewError(connect.CodeNotFound, err) + return newErrorFrom(connect.CodeNotFound, err) } // NewConflict creates a new Already Exists error (Connect Code 6) from an underlying error. func NewConflict(err error) error { - return connect.NewError(connect.CodeAlreadyExists, err) + return newErrorFrom(connect.CodeAlreadyExists, err) } // NewInternal creates a new Internal error (Connect Code 13) from an underlying error. func NewInternal(err error) error { - return connect.NewError(connect.CodeInternal, err) + return newErrorFrom(connect.CodeInternal, err) } // NewAborted creates a new Aborted error (Connect Code 10) from an underlying error. func NewAborted(err error) error { - return connect.NewError(connect.CodeAborted, err) + return newErrorFrom(connect.CodeAborted, err) } // NewInvalidArgument creates a new Invalid Argument error (Connect Code 3) from an underlying error. func NewInvalidArgument(err error) error { - return connect.NewError(connect.CodeInvalidArgument, err) + return newErrorFrom(connect.CodeInvalidArgument, err) } // NewFailedPrecondition creates a new Failed Precondition error (Connect Code 9) from an underlying error. func NewFailedPrecondition(err error) error { - return connect.NewError(connect.CodeFailedPrecondition, err) + return newErrorFrom(connect.CodeFailedPrecondition, err) } // NewUnauthenticated creates a new Unauthenticated error (Connect Code 16) from an underlying error. func NewUnauthenticated(err error) error { - return connect.NewError(connect.CodeUnauthenticated, err) + return newErrorFrom(connect.CodeUnauthenticated, err) } // NewResourceExhausted creates a new Resource Exhausted error (Connect Code 8) from an underlying error. func NewResourceExhausted(err error) error { - return connect.NewError(connect.CodeResourceExhausted, err) + return newErrorFrom(connect.CodeResourceExhausted, err) } // NewPermissionDenied creates a new Permission Denied error (Connect Code 7) from an underlying error. func NewPermissionDenied(err error) error { - return connect.NewError(connect.CodePermissionDenied, err) + return newErrorFrom(connect.CodePermissionDenied, err) } // NewUnimplemented creates a new Unimplemented error (Connect Code 12) from an underlying error. func NewUnimplemented(err error) error { - return connect.NewError(connect.CodeUnimplemented, err) + return newErrorFrom(connect.CodeUnimplemented, err) } // IsNotFound reports whether the error is a Not Found error (Connect Code 5). @@ -219,7 +239,7 @@ func WrapConnectErr(c connect.Code, underlying error) *connect.Error { return connectErr } - return connect.NewError(c, underlying) + return connect.NewError(c, underlying.Error()).WithCause(underlying) } // ConnectErrorComparer returns a go-cmp Option for comparing *connect.Error values. diff --git a/go/errorutil/errors_test.go b/go/errorutil/errors_test.go index ca3134bf..9a8ba1a5 100644 --- a/go/errorutil/errors_test.go +++ b/go/errorutil/errors_test.go @@ -5,7 +5,7 @@ import ( "fmt" "testing" - "connectrpc.com/connect" + "connectrpc.com/connect/v2" "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -97,7 +97,7 @@ func TestIsErrFns(t *testing.T) { { name: "connect error", errorFn: fns.errFn, - err: connect.NewError(fns.code, errors.New("")), + err: connect.NewError(fns.code, ""), want: true, }, { @@ -109,7 +109,7 @@ func TestIsErrFns(t *testing.T) { { name: "wrapped", errorFn: fns.errFn, - err: fmt.Errorf("wrapped: %w", connect.NewError(fns.code, errors.New(""))), + err: fmt.Errorf("wrapped: %w", connect.NewError(fns.code, "")), want: true, }, { @@ -143,7 +143,7 @@ func TestIsInternal(t *testing.T) { }, { name: "connect error", - err: connect.NewError(connect.CodeInternal, errors.New("")), + err: connect.NewError(connect.CodeInternal, ""), want: true, }, { @@ -153,7 +153,7 @@ func TestIsInternal(t *testing.T) { }, { name: "wrapped", - err: fmt.Errorf("wrapped: %w", connect.NewError(connect.CodeInternal, errors.New(""))), + err: fmt.Errorf("wrapped: %w", connect.NewError(connect.CodeInternal, "")), want: true, }, { @@ -181,17 +181,17 @@ func TestWrappedInternal(t *testing.T) { { name: "one error", err: Internal("something went wrong"), - wantErr: connect.NewError(connect.CodeInternal, errors.New("something went wrong")), + wantErr: connect.NewError(connect.CodeInternal, "something went wrong"), }, { name: "two errors", err: Internal("wrapping error: %w", fmt.Errorf("root error")), - wantErr: connect.NewError(connect.CodeInternal, fmt.Errorf("wrapping error: %w", errors.New("root error"))), + wantErr: connect.NewError(connect.CodeInternal, "wrapping error: root error"), }, { name: "two errors upside down", err: fmt.Errorf("wrapping error: %w", Internal("root error")), - wantErr: fmt.Errorf("wrapping error: %w", connect.NewError(connect.CodeInternal, errors.New("root error"))), + wantErr: fmt.Errorf("wrapping error: %w", connect.NewError(connect.CodeInternal, "root error")), }, } for i := range tests { @@ -213,42 +213,42 @@ func TestConvert(t *testing.T) { { name: "non specific error", err: fmt.Errorf("something went wrong"), - wantErr: connect.NewError(connect.CodeInternal, errors.New("something went wrong")), + wantErr: connect.NewError(connect.CodeInternal, "something went wrong"), }, { name: "passing connect error", err: Internal("something went wrong"), - wantErr: connect.NewError(connect.CodeInternal, errors.New("something went wrong")), + wantErr: connect.NewError(connect.CodeInternal, "something went wrong"), }, { name: "wrapped connect error", err: Internal("wrapping error: %w", fmt.Errorf("root error")), - wantErr: connect.NewError(connect.CodeInternal, fmt.Errorf("wrapping error: %w", errors.New("root error"))), + wantErr: connect.NewError(connect.CodeInternal, "wrapping error: root error"), }, { name: "wrapped connect error gets unwrapped", err: fmt.Errorf("wrapping error: %w", Internal("root error")), - wantErr: connect.NewError(connect.CodeInternal, fmt.Errorf("wrapping error: root error")), + wantErr: connect.NewError(connect.CodeInternal, "wrapping error: root error"), }, { name: "doubly-wrapped connect error gets unwraps the first and maintains the last", err: fmt.Errorf("wrapping error: %w", Internal("doubly-wrapped: %w", InvalidArgument("invalid"))), - wantErr: connect.NewError(connect.CodeInternal, fmt.Errorf("wrapping error: doubly-wrapped: invalid_argument: invalid")), + wantErr: connect.NewError(connect.CodeInternal, "wrapping error: doubly-wrapped: invalid_argument: invalid"), }, { name: "grpc error gets converted", err: status.Errorf(codes.AlreadyExists, "project already exists"), // TODO: check if this is really returned by a grpc client like that - wantErr: connect.NewError(connect.CodeAlreadyExists, fmt.Errorf("project already exists")), + wantErr: connect.NewError(connect.CodeAlreadyExists, "project already exists"), }, { name: "wrapped grpc error gets unwrapped", err: fmt.Errorf("wrapping error: %w", status.Errorf(codes.AlreadyExists, "project already exists")), - wantErr: connect.NewError(connect.CodeAlreadyExists, fmt.Errorf("wrapping error: project already exists")), + wantErr: connect.NewError(connect.CodeAlreadyExists, "wrapping error: project already exists"), }, { name: "doubly-wrapped grpc error unwraps the first and maintains the last", err: fmt.Errorf("wrapping error: %w", status.Errorf(codes.AlreadyExists, "doubly-wrapped: %s", status.Errorf(codes.FailedPrecondition, "precondition"))), - wantErr: connect.NewError(connect.CodeAlreadyExists, fmt.Errorf("wrapping error: doubly-wrapped: rpc error: code = FailedPrecondition desc = precondition")), + wantErr: connect.NewError(connect.CodeAlreadyExists, "wrapping error: doubly-wrapped: rpc error: code = FailedPrecondition desc = precondition"), }, } for i := range tests { diff --git a/go/metalstack/admin/v2/adminv2connect/audit.connect.go b/go/metalstack/admin/v2/adminv2connect/audit.connect.go index 2241e2d5..e720eb36 100644 --- a/go/metalstack/admin/v2/adminv2connect/audit.connect.go +++ b/go/metalstack/admin/v2/adminv2connect/audit.connect.go @@ -5,40 +5,48 @@ package adminv2connect import ( - connect "connectrpc.com/connect" + connect "connectrpc.com/connect/v2" context "context" - errors "errors" v2 "github.com/metal-stack/api/go/metalstack/admin/v2" - http "net/http" - strings "strings" + sync "sync" ) -// 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 ( // AuditServiceName is the fully-qualified name of the AuditService service. AuditServiceName = "metalstack.admin.v2.AuditService" ) -// 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. +// These constants are the procedure 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 ( - // AuditServiceGetProcedure is the fully-qualified name of the AuditService's Get RPC. + // AuditServiceGetProcedure is the procedure name of the AuditService's Get RPC. AuditServiceGetProcedure = "/metalstack.admin.v2.AuditService/Get" - // AuditServiceListProcedure is the fully-qualified name of the AuditService's List RPC. + // AuditServiceListProcedure is the procedure name of the AuditService's List RPC. AuditServiceListProcedure = "/metalstack.admin.v2.AuditService/List" ) +var ( + auditServiceGetSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_admin_v2_audit_proto.Services().ByName("AuditService").Methods().ByName("Get"), + Procedure: AuditServiceGetProcedure, + } + }) + auditServiceListSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_admin_v2_audit_proto.Services().ByName("AuditService").Methods().ByName("List"), + Procedure: AuditServiceListProcedure, + } + }) +) + // AuditServiceClient is a client for the metalstack.admin.v2.AuditService service. type AuditServiceClient interface { // Returns the audit trace with the specified UUID. @@ -47,54 +55,10 @@ type AuditServiceClient interface { List(context.Context, *v2.AuditServiceListRequest) (*v2.AuditServiceListResponse, error) } -// NewAuditServiceClient constructs a client for the metalstack.admin.v2.AuditService 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 NewAuditServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) AuditServiceClient { - baseURL = strings.TrimRight(baseURL, "/") - auditServiceMethods := v2.File_metalstack_admin_v2_audit_proto.Services().ByName("AuditService").Methods() - return &auditServiceClient{ - get: connect.NewClient[v2.AuditServiceGetRequest, v2.AuditServiceGetResponse]( - httpClient, - baseURL+AuditServiceGetProcedure, - connect.WithSchema(auditServiceMethods.ByName("Get")), - connect.WithClientOptions(opts...), - ), - list: connect.NewClient[v2.AuditServiceListRequest, v2.AuditServiceListResponse]( - httpClient, - baseURL+AuditServiceListProcedure, - connect.WithSchema(auditServiceMethods.ByName("List")), - connect.WithClientOptions(opts...), - ), - } -} - -// auditServiceClient implements AuditServiceClient. -type auditServiceClient struct { - get *connect.Client[v2.AuditServiceGetRequest, v2.AuditServiceGetResponse] - list *connect.Client[v2.AuditServiceListRequest, v2.AuditServiceListResponse] -} - -// Get calls metalstack.admin.v2.AuditService.Get. -func (c *auditServiceClient) Get(ctx context.Context, req *v2.AuditServiceGetRequest) (*v2.AuditServiceGetResponse, error) { - response, err := c.get.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err -} - -// List calls metalstack.admin.v2.AuditService.List. -func (c *auditServiceClient) List(ctx context.Context, req *v2.AuditServiceListRequest) (*v2.AuditServiceListResponse, error) { - response, err := c.list.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err +// NewAuditServiceClient constructs a client for the metalstack.admin.v2.AuditService service. +// Multiple service clients may share a single connect.Client. +func NewAuditServiceClient(client *connect.Client) AuditServiceClient { + return &auditServiceClient{client: client} } // AuditServiceHandler is an implementation of the metalstack.admin.v2.AuditService service. @@ -105,44 +69,69 @@ type AuditServiceHandler interface { List(context.Context, *v2.AuditServiceListRequest) (*v2.AuditServiceListResponse, error) } -// NewAuditServiceHandler 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 NewAuditServiceHandler(svc AuditServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) { - auditServiceMethods := v2.File_metalstack_admin_v2_audit_proto.Services().ByName("AuditService").Methods() - auditServiceGetHandler := connect.NewUnaryHandlerSimple( - AuditServiceGetProcedure, - svc.Get, - connect.WithSchema(auditServiceMethods.ByName("Get")), - connect.WithHandlerOptions(opts...), - ) - auditServiceListHandler := connect.NewUnaryHandlerSimple( - AuditServiceListProcedure, - svc.List, - connect.WithSchema(auditServiceMethods.ByName("List")), - connect.WithHandlerOptions(opts...), +// RegisterAuditServiceHandler registers svc as the metalstack.admin.v2.AuditService implementation +// on server. +func RegisterAuditServiceHandler(server *connect.Server, svc AuditServiceHandler) { + adapter := auditServiceHandler{svc: svc} + server.Register( + connect.Method{Spec: auditServiceGetSpec(), Handler: adapter.get}, + connect.Method{Spec: auditServiceListSpec(), Handler: adapter.list}, ) - return "/metalstack.admin.v2.AuditService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - switch r.URL.Path { - case AuditServiceGetProcedure: - auditServiceGetHandler.ServeHTTP(w, r) - case AuditServiceListProcedure: - auditServiceListHandler.ServeHTTP(w, r) - default: - http.NotFound(w, r) - } - }) } // UnimplementedAuditServiceHandler returns CodeUnimplemented from all methods. type UnimplementedAuditServiceHandler struct{} func (UnimplementedAuditServiceHandler) Get(context.Context, *v2.AuditServiceGetRequest) (*v2.AuditServiceGetResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.AuditService.Get is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.admin.v2.AuditService.Get is not implemented") } func (UnimplementedAuditServiceHandler) List(context.Context, *v2.AuditServiceListRequest) (*v2.AuditServiceListResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.AuditService.List is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.admin.v2.AuditService.List is not implemented") +} + +type auditServiceClient struct { + client *connect.Client +} + +func (c *auditServiceClient) Get(ctx context.Context, req *v2.AuditServiceGetRequest) (*v2.AuditServiceGetResponse, error) { + var res v2.AuditServiceGetResponse + if err := c.client.CallUnary(ctx, auditServiceGetSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *auditServiceClient) List(ctx context.Context, req *v2.AuditServiceListRequest) (*v2.AuditServiceListResponse, error) { + var res v2.AuditServiceListResponse + if err := c.client.CallUnary(ctx, auditServiceListSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +type auditServiceHandler struct{ svc AuditServiceHandler } + +func (h auditServiceHandler) get(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.AuditServiceGetRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Get(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) +} + +func (h auditServiceHandler) list(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.AuditServiceListRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.List(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } diff --git a/go/metalstack/admin/v2/adminv2connect/component.connect.go b/go/metalstack/admin/v2/adminv2connect/component.connect.go index da843f1a..2034b810 100644 --- a/go/metalstack/admin/v2/adminv2connect/component.connect.go +++ b/go/metalstack/admin/v2/adminv2connect/component.connect.go @@ -5,42 +5,57 @@ package adminv2connect import ( - connect "connectrpc.com/connect" + connect "connectrpc.com/connect/v2" context "context" - errors "errors" v2 "github.com/metal-stack/api/go/metalstack/admin/v2" - http "net/http" - strings "strings" + sync "sync" ) -// 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 ( // ComponentServiceName is the fully-qualified name of the ComponentService service. ComponentServiceName = "metalstack.admin.v2.ComponentService" ) -// 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. +// These constants are the procedure 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 ( - // ComponentServiceGetProcedure is the fully-qualified name of the ComponentService's Get RPC. + // ComponentServiceGetProcedure is the procedure name of the ComponentService's Get RPC. ComponentServiceGetProcedure = "/metalstack.admin.v2.ComponentService/Get" - // ComponentServiceDeleteProcedure is the fully-qualified name of the ComponentService's Delete RPC. + // ComponentServiceDeleteProcedure is the procedure name of the ComponentService's Delete RPC. ComponentServiceDeleteProcedure = "/metalstack.admin.v2.ComponentService/Delete" - // ComponentServiceListProcedure is the fully-qualified name of the ComponentService's List RPC. + // ComponentServiceListProcedure is the procedure name of the ComponentService's List RPC. ComponentServiceListProcedure = "/metalstack.admin.v2.ComponentService/List" ) +var ( + componentServiceGetSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_admin_v2_component_proto.Services().ByName("ComponentService").Methods().ByName("Get"), + Procedure: ComponentServiceGetProcedure, + } + }) + componentServiceDeleteSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_admin_v2_component_proto.Services().ByName("ComponentService").Methods().ByName("Delete"), + Procedure: ComponentServiceDeleteProcedure, + } + }) + componentServiceListSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_admin_v2_component_proto.Services().ByName("ComponentService").Methods().ByName("List"), + Procedure: ComponentServiceListProcedure, + } + }) +) + // ComponentServiceClient is a client for the metalstack.admin.v2.ComponentService service. type ComponentServiceClient interface { // Returns the component with the specified UUID. @@ -52,69 +67,9 @@ type ComponentServiceClient interface { } // NewComponentServiceClient constructs a client for the metalstack.admin.v2.ComponentService -// 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 NewComponentServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) ComponentServiceClient { - baseURL = strings.TrimRight(baseURL, "/") - componentServiceMethods := v2.File_metalstack_admin_v2_component_proto.Services().ByName("ComponentService").Methods() - return &componentServiceClient{ - get: connect.NewClient[v2.ComponentServiceGetRequest, v2.ComponentServiceGetResponse]( - httpClient, - baseURL+ComponentServiceGetProcedure, - connect.WithSchema(componentServiceMethods.ByName("Get")), - connect.WithClientOptions(opts...), - ), - delete: connect.NewClient[v2.ComponentServiceDeleteRequest, v2.ComponentServiceDeleteResponse]( - httpClient, - baseURL+ComponentServiceDeleteProcedure, - connect.WithSchema(componentServiceMethods.ByName("Delete")), - connect.WithClientOptions(opts...), - ), - list: connect.NewClient[v2.ComponentServiceListRequest, v2.ComponentServiceListResponse]( - httpClient, - baseURL+ComponentServiceListProcedure, - connect.WithSchema(componentServiceMethods.ByName("List")), - connect.WithClientOptions(opts...), - ), - } -} - -// componentServiceClient implements ComponentServiceClient. -type componentServiceClient struct { - get *connect.Client[v2.ComponentServiceGetRequest, v2.ComponentServiceGetResponse] - delete *connect.Client[v2.ComponentServiceDeleteRequest, v2.ComponentServiceDeleteResponse] - list *connect.Client[v2.ComponentServiceListRequest, v2.ComponentServiceListResponse] -} - -// Get calls metalstack.admin.v2.ComponentService.Get. -func (c *componentServiceClient) Get(ctx context.Context, req *v2.ComponentServiceGetRequest) (*v2.ComponentServiceGetResponse, error) { - response, err := c.get.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err -} - -// Delete calls metalstack.admin.v2.ComponentService.Delete. -func (c *componentServiceClient) Delete(ctx context.Context, req *v2.ComponentServiceDeleteRequest) (*v2.ComponentServiceDeleteResponse, error) { - response, err := c.delete.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err -} - -// List calls metalstack.admin.v2.ComponentService.List. -func (c *componentServiceClient) List(ctx context.Context, req *v2.ComponentServiceListRequest) (*v2.ComponentServiceListResponse, error) { - response, err := c.list.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err +// service. Multiple service clients may share a single connect.Client. +func NewComponentServiceClient(client *connect.Client) ComponentServiceClient { + return &componentServiceClient{client: client} } // ComponentServiceHandler is an implementation of the metalstack.admin.v2.ComponentService service. @@ -127,56 +82,94 @@ type ComponentServiceHandler interface { List(context.Context, *v2.ComponentServiceListRequest) (*v2.ComponentServiceListResponse, error) } -// NewComponentServiceHandler 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 NewComponentServiceHandler(svc ComponentServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) { - componentServiceMethods := v2.File_metalstack_admin_v2_component_proto.Services().ByName("ComponentService").Methods() - componentServiceGetHandler := connect.NewUnaryHandlerSimple( - ComponentServiceGetProcedure, - svc.Get, - connect.WithSchema(componentServiceMethods.ByName("Get")), - connect.WithHandlerOptions(opts...), +// RegisterComponentServiceHandler registers svc as the metalstack.admin.v2.ComponentService +// implementation on server. +func RegisterComponentServiceHandler(server *connect.Server, svc ComponentServiceHandler) { + adapter := componentServiceHandler{svc: svc} + server.Register( + connect.Method{Spec: componentServiceGetSpec(), Handler: adapter.get}, + connect.Method{Spec: componentServiceDeleteSpec(), Handler: adapter.delete}, + connect.Method{Spec: componentServiceListSpec(), Handler: adapter.list}, ) - componentServiceDeleteHandler := connect.NewUnaryHandlerSimple( - ComponentServiceDeleteProcedure, - svc.Delete, - connect.WithSchema(componentServiceMethods.ByName("Delete")), - connect.WithHandlerOptions(opts...), - ) - componentServiceListHandler := connect.NewUnaryHandlerSimple( - ComponentServiceListProcedure, - svc.List, - connect.WithSchema(componentServiceMethods.ByName("List")), - connect.WithHandlerOptions(opts...), - ) - return "/metalstack.admin.v2.ComponentService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - switch r.URL.Path { - case ComponentServiceGetProcedure: - componentServiceGetHandler.ServeHTTP(w, r) - case ComponentServiceDeleteProcedure: - componentServiceDeleteHandler.ServeHTTP(w, r) - case ComponentServiceListProcedure: - componentServiceListHandler.ServeHTTP(w, r) - default: - http.NotFound(w, r) - } - }) } // UnimplementedComponentServiceHandler returns CodeUnimplemented from all methods. type UnimplementedComponentServiceHandler struct{} func (UnimplementedComponentServiceHandler) Get(context.Context, *v2.ComponentServiceGetRequest) (*v2.ComponentServiceGetResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.ComponentService.Get is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.admin.v2.ComponentService.Get is not implemented") } func (UnimplementedComponentServiceHandler) Delete(context.Context, *v2.ComponentServiceDeleteRequest) (*v2.ComponentServiceDeleteResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.ComponentService.Delete is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.admin.v2.ComponentService.Delete is not implemented") } func (UnimplementedComponentServiceHandler) List(context.Context, *v2.ComponentServiceListRequest) (*v2.ComponentServiceListResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.ComponentService.List is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.admin.v2.ComponentService.List is not implemented") +} + +type componentServiceClient struct { + client *connect.Client +} + +func (c *componentServiceClient) Get(ctx context.Context, req *v2.ComponentServiceGetRequest) (*v2.ComponentServiceGetResponse, error) { + var res v2.ComponentServiceGetResponse + if err := c.client.CallUnary(ctx, componentServiceGetSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *componentServiceClient) Delete(ctx context.Context, req *v2.ComponentServiceDeleteRequest) (*v2.ComponentServiceDeleteResponse, error) { + var res v2.ComponentServiceDeleteResponse + if err := c.client.CallUnary(ctx, componentServiceDeleteSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *componentServiceClient) List(ctx context.Context, req *v2.ComponentServiceListRequest) (*v2.ComponentServiceListResponse, error) { + var res v2.ComponentServiceListResponse + if err := c.client.CallUnary(ctx, componentServiceListSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +type componentServiceHandler struct{ svc ComponentServiceHandler } + +func (h componentServiceHandler) get(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.ComponentServiceGetRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Get(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) +} + +func (h componentServiceHandler) delete(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.ComponentServiceDeleteRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Delete(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) +} + +func (h componentServiceHandler) list(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.ComponentServiceListRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.List(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } diff --git a/go/metalstack/admin/v2/adminv2connect/filesystem.connect.go b/go/metalstack/admin/v2/adminv2connect/filesystem.connect.go index 939c6d00..48dbec02 100644 --- a/go/metalstack/admin/v2/adminv2connect/filesystem.connect.go +++ b/go/metalstack/admin/v2/adminv2connect/filesystem.connect.go @@ -5,47 +5,66 @@ package adminv2connect import ( - connect "connectrpc.com/connect" + connect "connectrpc.com/connect/v2" context "context" - errors "errors" v2 "github.com/metal-stack/api/go/metalstack/admin/v2" - http "net/http" - strings "strings" + sync "sync" ) -// 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 ( // FilesystemServiceName is the fully-qualified name of the FilesystemService service. FilesystemServiceName = "metalstack.admin.v2.FilesystemService" ) -// 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. +// These constants are the procedure 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 ( - // FilesystemServiceCreateProcedure is the fully-qualified name of the FilesystemService's Create - // RPC. + // FilesystemServiceCreateProcedure is the procedure name of the FilesystemService's Create RPC. FilesystemServiceCreateProcedure = "/metalstack.admin.v2.FilesystemService/Create" - // FilesystemServiceUpdateProcedure is the fully-qualified name of the FilesystemService's Update - // RPC. + // FilesystemServiceUpdateProcedure is the procedure name of the FilesystemService's Update RPC. FilesystemServiceUpdateProcedure = "/metalstack.admin.v2.FilesystemService/Update" - // FilesystemServiceDeleteProcedure is the fully-qualified name of the FilesystemService's Delete - // RPC. + // FilesystemServiceDeleteProcedure is the procedure name of the FilesystemService's Delete RPC. FilesystemServiceDeleteProcedure = "/metalstack.admin.v2.FilesystemService/Delete" - // FilesystemServiceMatchProcedure is the fully-qualified name of the FilesystemService's Match RPC. + // FilesystemServiceMatchProcedure is the procedure name of the FilesystemService's Match RPC. FilesystemServiceMatchProcedure = "/metalstack.admin.v2.FilesystemService/Match" ) +var ( + filesystemServiceCreateSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_admin_v2_filesystem_proto.Services().ByName("FilesystemService").Methods().ByName("Create"), + Procedure: FilesystemServiceCreateProcedure, + } + }) + filesystemServiceUpdateSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_admin_v2_filesystem_proto.Services().ByName("FilesystemService").Methods().ByName("Update"), + Procedure: FilesystemServiceUpdateProcedure, + } + }) + filesystemServiceDeleteSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_admin_v2_filesystem_proto.Services().ByName("FilesystemService").Methods().ByName("Delete"), + Procedure: FilesystemServiceDeleteProcedure, + } + }) + filesystemServiceMatchSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_admin_v2_filesystem_proto.Services().ByName("FilesystemService").Methods().ByName("Match"), + Procedure: FilesystemServiceMatchProcedure, + } + }) +) + // FilesystemServiceClient is a client for the metalstack.admin.v2.FilesystemService service. type FilesystemServiceClient interface { // Creates a new filesystem. @@ -59,85 +78,9 @@ type FilesystemServiceClient interface { } // NewFilesystemServiceClient constructs a client for the metalstack.admin.v2.FilesystemService -// 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 NewFilesystemServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) FilesystemServiceClient { - baseURL = strings.TrimRight(baseURL, "/") - filesystemServiceMethods := v2.File_metalstack_admin_v2_filesystem_proto.Services().ByName("FilesystemService").Methods() - return &filesystemServiceClient{ - create: connect.NewClient[v2.FilesystemServiceCreateRequest, v2.FilesystemServiceCreateResponse]( - httpClient, - baseURL+FilesystemServiceCreateProcedure, - connect.WithSchema(filesystemServiceMethods.ByName("Create")), - connect.WithClientOptions(opts...), - ), - update: connect.NewClient[v2.FilesystemServiceUpdateRequest, v2.FilesystemServiceUpdateResponse]( - httpClient, - baseURL+FilesystemServiceUpdateProcedure, - connect.WithSchema(filesystemServiceMethods.ByName("Update")), - connect.WithClientOptions(opts...), - ), - delete: connect.NewClient[v2.FilesystemServiceDeleteRequest, v2.FilesystemServiceDeleteResponse]( - httpClient, - baseURL+FilesystemServiceDeleteProcedure, - connect.WithSchema(filesystemServiceMethods.ByName("Delete")), - connect.WithClientOptions(opts...), - ), - match: connect.NewClient[v2.FilesystemServiceMatchRequest, v2.FilesystemServiceMatchResponse]( - httpClient, - baseURL+FilesystemServiceMatchProcedure, - connect.WithSchema(filesystemServiceMethods.ByName("Match")), - connect.WithClientOptions(opts...), - ), - } -} - -// filesystemServiceClient implements FilesystemServiceClient. -type filesystemServiceClient struct { - create *connect.Client[v2.FilesystemServiceCreateRequest, v2.FilesystemServiceCreateResponse] - update *connect.Client[v2.FilesystemServiceUpdateRequest, v2.FilesystemServiceUpdateResponse] - delete *connect.Client[v2.FilesystemServiceDeleteRequest, v2.FilesystemServiceDeleteResponse] - match *connect.Client[v2.FilesystemServiceMatchRequest, v2.FilesystemServiceMatchResponse] -} - -// Create calls metalstack.admin.v2.FilesystemService.Create. -func (c *filesystemServiceClient) Create(ctx context.Context, req *v2.FilesystemServiceCreateRequest) (*v2.FilesystemServiceCreateResponse, error) { - response, err := c.create.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err -} - -// Update calls metalstack.admin.v2.FilesystemService.Update. -func (c *filesystemServiceClient) Update(ctx context.Context, req *v2.FilesystemServiceUpdateRequest) (*v2.FilesystemServiceUpdateResponse, error) { - response, err := c.update.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err -} - -// Delete calls metalstack.admin.v2.FilesystemService.Delete. -func (c *filesystemServiceClient) Delete(ctx context.Context, req *v2.FilesystemServiceDeleteRequest) (*v2.FilesystemServiceDeleteResponse, error) { - response, err := c.delete.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err -} - -// Match calls metalstack.admin.v2.FilesystemService.Match. -func (c *filesystemServiceClient) Match(ctx context.Context, req *v2.FilesystemServiceMatchRequest) (*v2.FilesystemServiceMatchResponse, error) { - response, err := c.match.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err +// service. Multiple service clients may share a single connect.Client. +func NewFilesystemServiceClient(client *connect.Client) FilesystemServiceClient { + return &filesystemServiceClient{client: client} } // FilesystemServiceHandler is an implementation of the metalstack.admin.v2.FilesystemService @@ -153,68 +96,119 @@ type FilesystemServiceHandler interface { Match(context.Context, *v2.FilesystemServiceMatchRequest) (*v2.FilesystemServiceMatchResponse, error) } -// NewFilesystemServiceHandler 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 NewFilesystemServiceHandler(svc FilesystemServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) { - filesystemServiceMethods := v2.File_metalstack_admin_v2_filesystem_proto.Services().ByName("FilesystemService").Methods() - filesystemServiceCreateHandler := connect.NewUnaryHandlerSimple( - FilesystemServiceCreateProcedure, - svc.Create, - connect.WithSchema(filesystemServiceMethods.ByName("Create")), - connect.WithHandlerOptions(opts...), +// RegisterFilesystemServiceHandler registers svc as the metalstack.admin.v2.FilesystemService +// implementation on server. +func RegisterFilesystemServiceHandler(server *connect.Server, svc FilesystemServiceHandler) { + adapter := filesystemServiceHandler{svc: svc} + server.Register( + connect.Method{Spec: filesystemServiceCreateSpec(), Handler: adapter.create}, + connect.Method{Spec: filesystemServiceUpdateSpec(), Handler: adapter.update}, + connect.Method{Spec: filesystemServiceDeleteSpec(), Handler: adapter.delete}, + connect.Method{Spec: filesystemServiceMatchSpec(), Handler: adapter.match}, ) - filesystemServiceUpdateHandler := connect.NewUnaryHandlerSimple( - FilesystemServiceUpdateProcedure, - svc.Update, - connect.WithSchema(filesystemServiceMethods.ByName("Update")), - connect.WithHandlerOptions(opts...), - ) - filesystemServiceDeleteHandler := connect.NewUnaryHandlerSimple( - FilesystemServiceDeleteProcedure, - svc.Delete, - connect.WithSchema(filesystemServiceMethods.ByName("Delete")), - connect.WithHandlerOptions(opts...), - ) - filesystemServiceMatchHandler := connect.NewUnaryHandlerSimple( - FilesystemServiceMatchProcedure, - svc.Match, - connect.WithSchema(filesystemServiceMethods.ByName("Match")), - connect.WithHandlerOptions(opts...), - ) - return "/metalstack.admin.v2.FilesystemService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - switch r.URL.Path { - case FilesystemServiceCreateProcedure: - filesystemServiceCreateHandler.ServeHTTP(w, r) - case FilesystemServiceUpdateProcedure: - filesystemServiceUpdateHandler.ServeHTTP(w, r) - case FilesystemServiceDeleteProcedure: - filesystemServiceDeleteHandler.ServeHTTP(w, r) - case FilesystemServiceMatchProcedure: - filesystemServiceMatchHandler.ServeHTTP(w, r) - default: - http.NotFound(w, r) - } - }) } // UnimplementedFilesystemServiceHandler returns CodeUnimplemented from all methods. type UnimplementedFilesystemServiceHandler struct{} func (UnimplementedFilesystemServiceHandler) Create(context.Context, *v2.FilesystemServiceCreateRequest) (*v2.FilesystemServiceCreateResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.FilesystemService.Create is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.admin.v2.FilesystemService.Create is not implemented") } func (UnimplementedFilesystemServiceHandler) Update(context.Context, *v2.FilesystemServiceUpdateRequest) (*v2.FilesystemServiceUpdateResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.FilesystemService.Update is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.admin.v2.FilesystemService.Update is not implemented") } func (UnimplementedFilesystemServiceHandler) Delete(context.Context, *v2.FilesystemServiceDeleteRequest) (*v2.FilesystemServiceDeleteResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.FilesystemService.Delete is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.admin.v2.FilesystemService.Delete is not implemented") } func (UnimplementedFilesystemServiceHandler) Match(context.Context, *v2.FilesystemServiceMatchRequest) (*v2.FilesystemServiceMatchResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.FilesystemService.Match is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.admin.v2.FilesystemService.Match is not implemented") +} + +type filesystemServiceClient struct { + client *connect.Client +} + +func (c *filesystemServiceClient) Create(ctx context.Context, req *v2.FilesystemServiceCreateRequest) (*v2.FilesystemServiceCreateResponse, error) { + var res v2.FilesystemServiceCreateResponse + if err := c.client.CallUnary(ctx, filesystemServiceCreateSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *filesystemServiceClient) Update(ctx context.Context, req *v2.FilesystemServiceUpdateRequest) (*v2.FilesystemServiceUpdateResponse, error) { + var res v2.FilesystemServiceUpdateResponse + if err := c.client.CallUnary(ctx, filesystemServiceUpdateSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *filesystemServiceClient) Delete(ctx context.Context, req *v2.FilesystemServiceDeleteRequest) (*v2.FilesystemServiceDeleteResponse, error) { + var res v2.FilesystemServiceDeleteResponse + if err := c.client.CallUnary(ctx, filesystemServiceDeleteSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *filesystemServiceClient) Match(ctx context.Context, req *v2.FilesystemServiceMatchRequest) (*v2.FilesystemServiceMatchResponse, error) { + var res v2.FilesystemServiceMatchResponse + if err := c.client.CallUnary(ctx, filesystemServiceMatchSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +type filesystemServiceHandler struct{ svc FilesystemServiceHandler } + +func (h filesystemServiceHandler) create(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.FilesystemServiceCreateRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Create(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) +} + +func (h filesystemServiceHandler) update(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.FilesystemServiceUpdateRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Update(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) +} + +func (h filesystemServiceHandler) delete(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.FilesystemServiceDeleteRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Delete(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) +} + +func (h filesystemServiceHandler) match(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.FilesystemServiceMatchRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Match(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } diff --git a/go/metalstack/admin/v2/adminv2connect/image.connect.go b/go/metalstack/admin/v2/adminv2connect/image.connect.go index 321e7267..91de8884 100644 --- a/go/metalstack/admin/v2/adminv2connect/image.connect.go +++ b/go/metalstack/admin/v2/adminv2connect/image.connect.go @@ -5,44 +5,66 @@ package adminv2connect import ( - connect "connectrpc.com/connect" + connect "connectrpc.com/connect/v2" context "context" - errors "errors" v2 "github.com/metal-stack/api/go/metalstack/admin/v2" - http "net/http" - strings "strings" + sync "sync" ) -// 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 ( // ImageServiceName is the fully-qualified name of the ImageService service. ImageServiceName = "metalstack.admin.v2.ImageService" ) -// 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. +// These constants are the procedure 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 ( - // ImageServiceCreateProcedure is the fully-qualified name of the ImageService's Create RPC. + // ImageServiceCreateProcedure is the procedure name of the ImageService's Create RPC. ImageServiceCreateProcedure = "/metalstack.admin.v2.ImageService/Create" - // ImageServiceUpdateProcedure is the fully-qualified name of the ImageService's Update RPC. + // ImageServiceUpdateProcedure is the procedure name of the ImageService's Update RPC. ImageServiceUpdateProcedure = "/metalstack.admin.v2.ImageService/Update" - // ImageServiceDeleteProcedure is the fully-qualified name of the ImageService's Delete RPC. + // ImageServiceDeleteProcedure is the procedure name of the ImageService's Delete RPC. ImageServiceDeleteProcedure = "/metalstack.admin.v2.ImageService/Delete" - // ImageServiceUsageProcedure is the fully-qualified name of the ImageService's Usage RPC. + // ImageServiceUsageProcedure is the procedure name of the ImageService's Usage RPC. ImageServiceUsageProcedure = "/metalstack.admin.v2.ImageService/Usage" ) +var ( + imageServiceCreateSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_admin_v2_image_proto.Services().ByName("ImageService").Methods().ByName("Create"), + Procedure: ImageServiceCreateProcedure, + } + }) + imageServiceUpdateSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_admin_v2_image_proto.Services().ByName("ImageService").Methods().ByName("Update"), + Procedure: ImageServiceUpdateProcedure, + } + }) + imageServiceDeleteSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_admin_v2_image_proto.Services().ByName("ImageService").Methods().ByName("Delete"), + Procedure: ImageServiceDeleteProcedure, + } + }) + imageServiceUsageSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_admin_v2_image_proto.Services().ByName("ImageService").Methods().ByName("Usage"), + Procedure: ImageServiceUsageProcedure, + } + }) +) + // ImageServiceClient is a client for the metalstack.admin.v2.ImageService service. type ImageServiceClient interface { // Creates a new image. @@ -55,86 +77,10 @@ type ImageServiceClient interface { Usage(context.Context, *v2.ImageServiceUsageRequest) (*v2.ImageServiceUsageResponse, error) } -// NewImageServiceClient constructs a client for the metalstack.admin.v2.ImageService 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 NewImageServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) ImageServiceClient { - baseURL = strings.TrimRight(baseURL, "/") - imageServiceMethods := v2.File_metalstack_admin_v2_image_proto.Services().ByName("ImageService").Methods() - return &imageServiceClient{ - create: connect.NewClient[v2.ImageServiceCreateRequest, v2.ImageServiceCreateResponse]( - httpClient, - baseURL+ImageServiceCreateProcedure, - connect.WithSchema(imageServiceMethods.ByName("Create")), - connect.WithClientOptions(opts...), - ), - update: connect.NewClient[v2.ImageServiceUpdateRequest, v2.ImageServiceUpdateResponse]( - httpClient, - baseURL+ImageServiceUpdateProcedure, - connect.WithSchema(imageServiceMethods.ByName("Update")), - connect.WithClientOptions(opts...), - ), - delete: connect.NewClient[v2.ImageServiceDeleteRequest, v2.ImageServiceDeleteResponse]( - httpClient, - baseURL+ImageServiceDeleteProcedure, - connect.WithSchema(imageServiceMethods.ByName("Delete")), - connect.WithClientOptions(opts...), - ), - usage: connect.NewClient[v2.ImageServiceUsageRequest, v2.ImageServiceUsageResponse]( - httpClient, - baseURL+ImageServiceUsageProcedure, - connect.WithSchema(imageServiceMethods.ByName("Usage")), - connect.WithClientOptions(opts...), - ), - } -} - -// imageServiceClient implements ImageServiceClient. -type imageServiceClient struct { - create *connect.Client[v2.ImageServiceCreateRequest, v2.ImageServiceCreateResponse] - update *connect.Client[v2.ImageServiceUpdateRequest, v2.ImageServiceUpdateResponse] - delete *connect.Client[v2.ImageServiceDeleteRequest, v2.ImageServiceDeleteResponse] - usage *connect.Client[v2.ImageServiceUsageRequest, v2.ImageServiceUsageResponse] -} - -// Create calls metalstack.admin.v2.ImageService.Create. -func (c *imageServiceClient) Create(ctx context.Context, req *v2.ImageServiceCreateRequest) (*v2.ImageServiceCreateResponse, error) { - response, err := c.create.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err -} - -// Update calls metalstack.admin.v2.ImageService.Update. -func (c *imageServiceClient) Update(ctx context.Context, req *v2.ImageServiceUpdateRequest) (*v2.ImageServiceUpdateResponse, error) { - response, err := c.update.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err -} - -// Delete calls metalstack.admin.v2.ImageService.Delete. -func (c *imageServiceClient) Delete(ctx context.Context, req *v2.ImageServiceDeleteRequest) (*v2.ImageServiceDeleteResponse, error) { - response, err := c.delete.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err -} - -// Usage calls metalstack.admin.v2.ImageService.Usage. -func (c *imageServiceClient) Usage(ctx context.Context, req *v2.ImageServiceUsageRequest) (*v2.ImageServiceUsageResponse, error) { - response, err := c.usage.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err +// NewImageServiceClient constructs a client for the metalstack.admin.v2.ImageService service. +// Multiple service clients may share a single connect.Client. +func NewImageServiceClient(client *connect.Client) ImageServiceClient { + return &imageServiceClient{client: client} } // ImageServiceHandler is an implementation of the metalstack.admin.v2.ImageService service. @@ -149,68 +95,119 @@ type ImageServiceHandler interface { Usage(context.Context, *v2.ImageServiceUsageRequest) (*v2.ImageServiceUsageResponse, error) } -// NewImageServiceHandler 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 NewImageServiceHandler(svc ImageServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) { - imageServiceMethods := v2.File_metalstack_admin_v2_image_proto.Services().ByName("ImageService").Methods() - imageServiceCreateHandler := connect.NewUnaryHandlerSimple( - ImageServiceCreateProcedure, - svc.Create, - connect.WithSchema(imageServiceMethods.ByName("Create")), - connect.WithHandlerOptions(opts...), +// RegisterImageServiceHandler registers svc as the metalstack.admin.v2.ImageService implementation +// on server. +func RegisterImageServiceHandler(server *connect.Server, svc ImageServiceHandler) { + adapter := imageServiceHandler{svc: svc} + server.Register( + connect.Method{Spec: imageServiceCreateSpec(), Handler: adapter.create}, + connect.Method{Spec: imageServiceUpdateSpec(), Handler: adapter.update}, + connect.Method{Spec: imageServiceDeleteSpec(), Handler: adapter.delete}, + connect.Method{Spec: imageServiceUsageSpec(), Handler: adapter.usage}, ) - imageServiceUpdateHandler := connect.NewUnaryHandlerSimple( - ImageServiceUpdateProcedure, - svc.Update, - connect.WithSchema(imageServiceMethods.ByName("Update")), - connect.WithHandlerOptions(opts...), - ) - imageServiceDeleteHandler := connect.NewUnaryHandlerSimple( - ImageServiceDeleteProcedure, - svc.Delete, - connect.WithSchema(imageServiceMethods.ByName("Delete")), - connect.WithHandlerOptions(opts...), - ) - imageServiceUsageHandler := connect.NewUnaryHandlerSimple( - ImageServiceUsageProcedure, - svc.Usage, - connect.WithSchema(imageServiceMethods.ByName("Usage")), - connect.WithHandlerOptions(opts...), - ) - return "/metalstack.admin.v2.ImageService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - switch r.URL.Path { - case ImageServiceCreateProcedure: - imageServiceCreateHandler.ServeHTTP(w, r) - case ImageServiceUpdateProcedure: - imageServiceUpdateHandler.ServeHTTP(w, r) - case ImageServiceDeleteProcedure: - imageServiceDeleteHandler.ServeHTTP(w, r) - case ImageServiceUsageProcedure: - imageServiceUsageHandler.ServeHTTP(w, r) - default: - http.NotFound(w, r) - } - }) } // UnimplementedImageServiceHandler returns CodeUnimplemented from all methods. type UnimplementedImageServiceHandler struct{} func (UnimplementedImageServiceHandler) Create(context.Context, *v2.ImageServiceCreateRequest) (*v2.ImageServiceCreateResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.ImageService.Create is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.admin.v2.ImageService.Create is not implemented") } func (UnimplementedImageServiceHandler) Update(context.Context, *v2.ImageServiceUpdateRequest) (*v2.ImageServiceUpdateResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.ImageService.Update is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.admin.v2.ImageService.Update is not implemented") } func (UnimplementedImageServiceHandler) Delete(context.Context, *v2.ImageServiceDeleteRequest) (*v2.ImageServiceDeleteResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.ImageService.Delete is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.admin.v2.ImageService.Delete is not implemented") } func (UnimplementedImageServiceHandler) Usage(context.Context, *v2.ImageServiceUsageRequest) (*v2.ImageServiceUsageResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.ImageService.Usage is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.admin.v2.ImageService.Usage is not implemented") +} + +type imageServiceClient struct { + client *connect.Client +} + +func (c *imageServiceClient) Create(ctx context.Context, req *v2.ImageServiceCreateRequest) (*v2.ImageServiceCreateResponse, error) { + var res v2.ImageServiceCreateResponse + if err := c.client.CallUnary(ctx, imageServiceCreateSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *imageServiceClient) Update(ctx context.Context, req *v2.ImageServiceUpdateRequest) (*v2.ImageServiceUpdateResponse, error) { + var res v2.ImageServiceUpdateResponse + if err := c.client.CallUnary(ctx, imageServiceUpdateSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *imageServiceClient) Delete(ctx context.Context, req *v2.ImageServiceDeleteRequest) (*v2.ImageServiceDeleteResponse, error) { + var res v2.ImageServiceDeleteResponse + if err := c.client.CallUnary(ctx, imageServiceDeleteSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *imageServiceClient) Usage(ctx context.Context, req *v2.ImageServiceUsageRequest) (*v2.ImageServiceUsageResponse, error) { + var res v2.ImageServiceUsageResponse + if err := c.client.CallUnary(ctx, imageServiceUsageSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +type imageServiceHandler struct{ svc ImageServiceHandler } + +func (h imageServiceHandler) create(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.ImageServiceCreateRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Create(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) +} + +func (h imageServiceHandler) update(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.ImageServiceUpdateRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Update(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) +} + +func (h imageServiceHandler) delete(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.ImageServiceDeleteRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Delete(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) +} + +func (h imageServiceHandler) usage(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.ImageServiceUsageRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Usage(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } diff --git a/go/metalstack/admin/v2/adminv2connect/ip.connect.go b/go/metalstack/admin/v2/adminv2connect/ip.connect.go index ce2541e1..b616d9ef 100644 --- a/go/metalstack/admin/v2/adminv2connect/ip.connect.go +++ b/go/metalstack/admin/v2/adminv2connect/ip.connect.go @@ -5,76 +5,49 @@ package adminv2connect import ( - connect "connectrpc.com/connect" + connect "connectrpc.com/connect/v2" context "context" - errors "errors" v2 "github.com/metal-stack/api/go/metalstack/admin/v2" - http "net/http" - strings "strings" + sync "sync" ) -// 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 ( // IPServiceName is the fully-qualified name of the IPService service. IPServiceName = "metalstack.admin.v2.IPService" ) -// 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. +// These constants are the procedure 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 ( - // IPServiceListProcedure is the fully-qualified name of the IPService's List RPC. + // IPServiceListProcedure is the procedure name of the IPService's List RPC. IPServiceListProcedure = "/metalstack.admin.v2.IPService/List" ) +var ( + iPServiceListSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_admin_v2_ip_proto.Services().ByName("IPService").Methods().ByName("List"), + Procedure: IPServiceListProcedure, + } + }) +) + // IPServiceClient is a client for the metalstack.admin.v2.IPService service. type IPServiceClient interface { // Returns the list of all IP addresses. List(context.Context, *v2.IPServiceListRequest) (*v2.IPServiceListResponse, error) } -// NewIPServiceClient constructs a client for the metalstack.admin.v2.IPService 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 NewIPServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) IPServiceClient { - baseURL = strings.TrimRight(baseURL, "/") - iPServiceMethods := v2.File_metalstack_admin_v2_ip_proto.Services().ByName("IPService").Methods() - return &iPServiceClient{ - list: connect.NewClient[v2.IPServiceListRequest, v2.IPServiceListResponse]( - httpClient, - baseURL+IPServiceListProcedure, - connect.WithSchema(iPServiceMethods.ByName("List")), - connect.WithClientOptions(opts...), - ), - } -} - -// iPServiceClient implements IPServiceClient. -type iPServiceClient struct { - list *connect.Client[v2.IPServiceListRequest, v2.IPServiceListResponse] -} - -// List calls metalstack.admin.v2.IPService.List. -func (c *iPServiceClient) List(ctx context.Context, req *v2.IPServiceListRequest) (*v2.IPServiceListResponse, error) { - response, err := c.list.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err +// NewIPServiceClient constructs a client for the metalstack.admin.v2.IPService service. Multiple +// service clients may share a single connect.Client. +func NewIPServiceClient(client *connect.Client) IPServiceClient { + return &iPServiceClient{client: client} } // IPServiceHandler is an implementation of the metalstack.admin.v2.IPService service. @@ -83,32 +56,44 @@ type IPServiceHandler interface { List(context.Context, *v2.IPServiceListRequest) (*v2.IPServiceListResponse, error) } -// NewIPServiceHandler 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 NewIPServiceHandler(svc IPServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) { - iPServiceMethods := v2.File_metalstack_admin_v2_ip_proto.Services().ByName("IPService").Methods() - iPServiceListHandler := connect.NewUnaryHandlerSimple( - IPServiceListProcedure, - svc.List, - connect.WithSchema(iPServiceMethods.ByName("List")), - connect.WithHandlerOptions(opts...), +// RegisterIPServiceHandler registers svc as the metalstack.admin.v2.IPService implementation on +// server. +func RegisterIPServiceHandler(server *connect.Server, svc IPServiceHandler) { + adapter := iPServiceHandler{svc: svc} + server.Register( + connect.Method{Spec: iPServiceListSpec(), Handler: adapter.list}, ) - return "/metalstack.admin.v2.IPService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - switch r.URL.Path { - case IPServiceListProcedure: - iPServiceListHandler.ServeHTTP(w, r) - default: - http.NotFound(w, r) - } - }) } // UnimplementedIPServiceHandler returns CodeUnimplemented from all methods. type UnimplementedIPServiceHandler struct{} func (UnimplementedIPServiceHandler) List(context.Context, *v2.IPServiceListRequest) (*v2.IPServiceListResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.IPService.List is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.admin.v2.IPService.List is not implemented") +} + +type iPServiceClient struct { + client *connect.Client +} + +func (c *iPServiceClient) List(ctx context.Context, req *v2.IPServiceListRequest) (*v2.IPServiceListResponse, error) { + var res v2.IPServiceListResponse + if err := c.client.CallUnary(ctx, iPServiceListSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +type iPServiceHandler struct{ svc IPServiceHandler } + +func (h iPServiceHandler) list(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.IPServiceListRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.List(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } diff --git a/go/metalstack/admin/v2/adminv2connect/machine.connect.go b/go/metalstack/admin/v2/adminv2connect/machine.connect.go index bcccad43..a80b6a1d 100644 --- a/go/metalstack/admin/v2/adminv2connect/machine.connect.go +++ b/go/metalstack/admin/v2/adminv2connect/machine.connect.go @@ -5,56 +5,112 @@ package adminv2connect import ( - connect "connectrpc.com/connect" + connect "connectrpc.com/connect/v2" context "context" - errors "errors" v2 "github.com/metal-stack/api/go/metalstack/admin/v2" - http "net/http" - strings "strings" + sync "sync" ) -// 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 ( // MachineServiceName is the fully-qualified name of the MachineService service. MachineServiceName = "metalstack.admin.v2.MachineService" ) -// 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. +// These constants are the procedure 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 ( - // MachineServiceGetProcedure is the fully-qualified name of the MachineService's Get RPC. + // MachineServiceGetProcedure is the procedure name of the MachineService's Get RPC. MachineServiceGetProcedure = "/metalstack.admin.v2.MachineService/Get" - // MachineServiceListProcedure is the fully-qualified name of the MachineService's List RPC. + // MachineServiceListProcedure is the procedure name of the MachineService's List RPC. MachineServiceListProcedure = "/metalstack.admin.v2.MachineService/List" - // MachineServiceDeleteProcedure is the fully-qualified name of the MachineService's Delete RPC. + // MachineServiceDeleteProcedure is the procedure name of the MachineService's Delete RPC. MachineServiceDeleteProcedure = "/metalstack.admin.v2.MachineService/Delete" - // MachineServiceBMCCommandProcedure is the fully-qualified name of the MachineService's BMCCommand - // RPC. + // MachineServiceBMCCommandProcedure is the procedure name of the MachineService's BMCCommand RPC. MachineServiceBMCCommandProcedure = "/metalstack.admin.v2.MachineService/BMCCommand" - // MachineServiceGetBMCProcedure is the fully-qualified name of the MachineService's GetBMC RPC. + // MachineServiceGetBMCProcedure is the procedure name of the MachineService's GetBMC RPC. MachineServiceGetBMCProcedure = "/metalstack.admin.v2.MachineService/GetBMC" - // MachineServiceListBMCProcedure is the fully-qualified name of the MachineService's ListBMC RPC. + // MachineServiceListBMCProcedure is the procedure name of the MachineService's ListBMC RPC. MachineServiceListBMCProcedure = "/metalstack.admin.v2.MachineService/ListBMC" - // MachineServiceConsolePasswordProcedure is the fully-qualified name of the MachineService's + // MachineServiceConsolePasswordProcedure is the procedure name of the MachineService's // ConsolePassword RPC. MachineServiceConsolePasswordProcedure = "/metalstack.admin.v2.MachineService/ConsolePassword" - // MachineServiceSetStateProcedure is the fully-qualified name of the MachineService's SetState RPC. + // MachineServiceSetStateProcedure is the procedure name of the MachineService's SetState RPC. MachineServiceSetStateProcedure = "/metalstack.admin.v2.MachineService/SetState" - // MachineServiceIssuesProcedure is the fully-qualified name of the MachineService's Issues RPC. + // MachineServiceIssuesProcedure is the procedure name of the MachineService's Issues RPC. MachineServiceIssuesProcedure = "/metalstack.admin.v2.MachineService/Issues" ) +var ( + machineServiceGetSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_admin_v2_machine_proto.Services().ByName("MachineService").Methods().ByName("Get"), + Procedure: MachineServiceGetProcedure, + } + }) + machineServiceListSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_admin_v2_machine_proto.Services().ByName("MachineService").Methods().ByName("List"), + Procedure: MachineServiceListProcedure, + } + }) + machineServiceDeleteSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_admin_v2_machine_proto.Services().ByName("MachineService").Methods().ByName("Delete"), + Procedure: MachineServiceDeleteProcedure, + } + }) + machineServiceBMCCommandSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_admin_v2_machine_proto.Services().ByName("MachineService").Methods().ByName("BMCCommand"), + Procedure: MachineServiceBMCCommandProcedure, + } + }) + machineServiceGetBMCSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_admin_v2_machine_proto.Services().ByName("MachineService").Methods().ByName("GetBMC"), + Procedure: MachineServiceGetBMCProcedure, + } + }) + machineServiceListBMCSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_admin_v2_machine_proto.Services().ByName("MachineService").Methods().ByName("ListBMC"), + Procedure: MachineServiceListBMCProcedure, + } + }) + machineServiceConsolePasswordSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_admin_v2_machine_proto.Services().ByName("MachineService").Methods().ByName("ConsolePassword"), + Procedure: MachineServiceConsolePasswordProcedure, + } + }) + machineServiceSetStateSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_admin_v2_machine_proto.Services().ByName("MachineService").Methods().ByName("SetState"), + Procedure: MachineServiceSetStateProcedure, + } + }) + machineServiceIssuesSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_admin_v2_machine_proto.Services().ByName("MachineService").Methods().ByName("Issues"), + Procedure: MachineServiceIssuesProcedure, + } + }) +) + // MachineServiceClient is a client for the metalstack.admin.v2.MachineService service. type MachineServiceClient interface { // Returns the machine with the specified UUID. @@ -78,311 +134,271 @@ type MachineServiceClient interface { } // NewMachineServiceClient constructs a client for the metalstack.admin.v2.MachineService 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 NewMachineServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) MachineServiceClient { - baseURL = strings.TrimRight(baseURL, "/") - machineServiceMethods := v2.File_metalstack_admin_v2_machine_proto.Services().ByName("MachineService").Methods() - return &machineServiceClient{ - get: connect.NewClient[v2.MachineServiceGetRequest, v2.MachineServiceGetResponse]( - httpClient, - baseURL+MachineServiceGetProcedure, - connect.WithSchema(machineServiceMethods.ByName("Get")), - connect.WithClientOptions(opts...), - ), - list: connect.NewClient[v2.MachineServiceListRequest, v2.MachineServiceListResponse]( - httpClient, - baseURL+MachineServiceListProcedure, - connect.WithSchema(machineServiceMethods.ByName("List")), - connect.WithClientOptions(opts...), - ), - delete: connect.NewClient[v2.MachineServiceDeleteRequest, v2.MachineServiceDeleteResponse]( - httpClient, - baseURL+MachineServiceDeleteProcedure, - connect.WithSchema(machineServiceMethods.ByName("Delete")), - connect.WithClientOptions(opts...), - ), - bMCCommand: connect.NewClient[v2.MachineServiceBMCCommandRequest, v2.MachineServiceBMCCommandResponse]( - httpClient, - baseURL+MachineServiceBMCCommandProcedure, - connect.WithSchema(machineServiceMethods.ByName("BMCCommand")), - connect.WithClientOptions(opts...), - ), - getBMC: connect.NewClient[v2.MachineServiceGetBMCRequest, v2.MachineServiceGetBMCResponse]( - httpClient, - baseURL+MachineServiceGetBMCProcedure, - connect.WithSchema(machineServiceMethods.ByName("GetBMC")), - connect.WithClientOptions(opts...), - ), - listBMC: connect.NewClient[v2.MachineServiceListBMCRequest, v2.MachineServiceListBMCResponse]( - httpClient, - baseURL+MachineServiceListBMCProcedure, - connect.WithSchema(machineServiceMethods.ByName("ListBMC")), - connect.WithClientOptions(opts...), - ), - consolePassword: connect.NewClient[v2.MachineServiceConsolePasswordRequest, v2.MachineServiceConsolePasswordResponse]( - httpClient, - baseURL+MachineServiceConsolePasswordProcedure, - connect.WithSchema(machineServiceMethods.ByName("ConsolePassword")), - connect.WithClientOptions(opts...), - ), - setState: connect.NewClient[v2.MachineServiceSetStateRequest, v2.MachineServiceSetStateResponse]( - httpClient, - baseURL+MachineServiceSetStateProcedure, - connect.WithSchema(machineServiceMethods.ByName("SetState")), - connect.WithClientOptions(opts...), - ), - issues: connect.NewClient[v2.MachineServiceIssuesRequest, v2.MachineServiceIssuesResponse]( - httpClient, - baseURL+MachineServiceIssuesProcedure, - connect.WithSchema(machineServiceMethods.ByName("Issues")), - connect.WithClientOptions(opts...), - ), - } +// Multiple service clients may share a single connect.Client. +func NewMachineServiceClient(client *connect.Client) MachineServiceClient { + return &machineServiceClient{client: client} +} + +// MachineServiceHandler is an implementation of the metalstack.admin.v2.MachineService service. +type MachineServiceHandler interface { + // Returns the machine with the specified UUID. + Get(context.Context, *v2.MachineServiceGetRequest) (*v2.MachineServiceGetResponse, error) + // Returns the list of all machines. + List(context.Context, *v2.MachineServiceListRequest) (*v2.MachineServiceListResponse, error) + // Delete a machine from the database. This can only be done if the machine is offline and dead. + Delete(context.Context, *v2.MachineServiceDeleteRequest) (*v2.MachineServiceDeleteResponse, error) + // BMCCommand sends a command to the BMC of a machine. + BMCCommand(context.Context, *v2.MachineServiceBMCCommandRequest) (*v2.MachineServiceBMCCommandResponse, error) + // Returns the BMC details of a machine. + GetBMC(context.Context, *v2.MachineServiceGetBMCRequest) (*v2.MachineServiceGetBMCResponse, error) + // ListBMC returns the BMC details of many machines. + ListBMC(context.Context, *v2.MachineServiceListBMCRequest) (*v2.MachineServiceListBMCResponse, error) + // GetConsolePassword returns the password to access the serial console of the machine. + ConsolePassword(context.Context, *v2.MachineServiceConsolePasswordRequest) (*v2.MachineServiceConsolePasswordResponse, error) + // SetState set the state of a machine. + SetState(context.Context, *v2.MachineServiceSetStateRequest) (*v2.MachineServiceSetStateResponse, error) + // Issues allows to query issues of machines. + Issues(context.Context, *v2.MachineServiceIssuesRequest) (*v2.MachineServiceIssuesResponse, error) +} + +// RegisterMachineServiceHandler registers svc as the metalstack.admin.v2.MachineService +// implementation on server. +func RegisterMachineServiceHandler(server *connect.Server, svc MachineServiceHandler) { + adapter := machineServiceHandler{svc: svc} + server.Register( + connect.Method{Spec: machineServiceGetSpec(), Handler: adapter.get}, + connect.Method{Spec: machineServiceListSpec(), Handler: adapter.list}, + connect.Method{Spec: machineServiceDeleteSpec(), Handler: adapter.delete}, + connect.Method{Spec: machineServiceBMCCommandSpec(), Handler: adapter.bMCCommand}, + connect.Method{Spec: machineServiceGetBMCSpec(), Handler: adapter.getBMC}, + connect.Method{Spec: machineServiceListBMCSpec(), Handler: adapter.listBMC}, + connect.Method{Spec: machineServiceConsolePasswordSpec(), Handler: adapter.consolePassword}, + connect.Method{Spec: machineServiceSetStateSpec(), Handler: adapter.setState}, + connect.Method{Spec: machineServiceIssuesSpec(), Handler: adapter.issues}, + ) +} + +// UnimplementedMachineServiceHandler returns CodeUnimplemented from all methods. +type UnimplementedMachineServiceHandler struct{} + +func (UnimplementedMachineServiceHandler) Get(context.Context, *v2.MachineServiceGetRequest) (*v2.MachineServiceGetResponse, error) { + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.admin.v2.MachineService.Get is not implemented") +} + +func (UnimplementedMachineServiceHandler) List(context.Context, *v2.MachineServiceListRequest) (*v2.MachineServiceListResponse, error) { + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.admin.v2.MachineService.List is not implemented") +} + +func (UnimplementedMachineServiceHandler) Delete(context.Context, *v2.MachineServiceDeleteRequest) (*v2.MachineServiceDeleteResponse, error) { + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.admin.v2.MachineService.Delete is not implemented") +} + +func (UnimplementedMachineServiceHandler) BMCCommand(context.Context, *v2.MachineServiceBMCCommandRequest) (*v2.MachineServiceBMCCommandResponse, error) { + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.admin.v2.MachineService.BMCCommand is not implemented") +} + +func (UnimplementedMachineServiceHandler) GetBMC(context.Context, *v2.MachineServiceGetBMCRequest) (*v2.MachineServiceGetBMCResponse, error) { + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.admin.v2.MachineService.GetBMC is not implemented") +} + +func (UnimplementedMachineServiceHandler) ListBMC(context.Context, *v2.MachineServiceListBMCRequest) (*v2.MachineServiceListBMCResponse, error) { + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.admin.v2.MachineService.ListBMC is not implemented") +} + +func (UnimplementedMachineServiceHandler) ConsolePassword(context.Context, *v2.MachineServiceConsolePasswordRequest) (*v2.MachineServiceConsolePasswordResponse, error) { + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.admin.v2.MachineService.ConsolePassword is not implemented") +} + +func (UnimplementedMachineServiceHandler) SetState(context.Context, *v2.MachineServiceSetStateRequest) (*v2.MachineServiceSetStateResponse, error) { + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.admin.v2.MachineService.SetState is not implemented") +} + +func (UnimplementedMachineServiceHandler) Issues(context.Context, *v2.MachineServiceIssuesRequest) (*v2.MachineServiceIssuesResponse, error) { + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.admin.v2.MachineService.Issues is not implemented") } -// machineServiceClient implements MachineServiceClient. type machineServiceClient struct { - get *connect.Client[v2.MachineServiceGetRequest, v2.MachineServiceGetResponse] - list *connect.Client[v2.MachineServiceListRequest, v2.MachineServiceListResponse] - delete *connect.Client[v2.MachineServiceDeleteRequest, v2.MachineServiceDeleteResponse] - bMCCommand *connect.Client[v2.MachineServiceBMCCommandRequest, v2.MachineServiceBMCCommandResponse] - getBMC *connect.Client[v2.MachineServiceGetBMCRequest, v2.MachineServiceGetBMCResponse] - listBMC *connect.Client[v2.MachineServiceListBMCRequest, v2.MachineServiceListBMCResponse] - consolePassword *connect.Client[v2.MachineServiceConsolePasswordRequest, v2.MachineServiceConsolePasswordResponse] - setState *connect.Client[v2.MachineServiceSetStateRequest, v2.MachineServiceSetStateResponse] - issues *connect.Client[v2.MachineServiceIssuesRequest, v2.MachineServiceIssuesResponse] -} - -// Get calls metalstack.admin.v2.MachineService.Get. + client *connect.Client +} + func (c *machineServiceClient) Get(ctx context.Context, req *v2.MachineServiceGetRequest) (*v2.MachineServiceGetResponse, error) { - response, err := c.get.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err + var res v2.MachineServiceGetResponse + if err := c.client.CallUnary(ctx, machineServiceGetSpec(), req, &res); err != nil { + return nil, err } - return nil, err + return &res, nil } -// List calls metalstack.admin.v2.MachineService.List. func (c *machineServiceClient) List(ctx context.Context, req *v2.MachineServiceListRequest) (*v2.MachineServiceListResponse, error) { - response, err := c.list.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err + var res v2.MachineServiceListResponse + if err := c.client.CallUnary(ctx, machineServiceListSpec(), req, &res); err != nil { + return nil, err } - return nil, err + return &res, nil } -// Delete calls metalstack.admin.v2.MachineService.Delete. func (c *machineServiceClient) Delete(ctx context.Context, req *v2.MachineServiceDeleteRequest) (*v2.MachineServiceDeleteResponse, error) { - response, err := c.delete.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err + var res v2.MachineServiceDeleteResponse + if err := c.client.CallUnary(ctx, machineServiceDeleteSpec(), req, &res); err != nil { + return nil, err } - return nil, err + return &res, nil } -// BMCCommand calls metalstack.admin.v2.MachineService.BMCCommand. func (c *machineServiceClient) BMCCommand(ctx context.Context, req *v2.MachineServiceBMCCommandRequest) (*v2.MachineServiceBMCCommandResponse, error) { - response, err := c.bMCCommand.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err + var res v2.MachineServiceBMCCommandResponse + if err := c.client.CallUnary(ctx, machineServiceBMCCommandSpec(), req, &res); err != nil { + return nil, err } - return nil, err + return &res, nil } -// GetBMC calls metalstack.admin.v2.MachineService.GetBMC. func (c *machineServiceClient) GetBMC(ctx context.Context, req *v2.MachineServiceGetBMCRequest) (*v2.MachineServiceGetBMCResponse, error) { - response, err := c.getBMC.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err + var res v2.MachineServiceGetBMCResponse + if err := c.client.CallUnary(ctx, machineServiceGetBMCSpec(), req, &res); err != nil { + return nil, err } - return nil, err + return &res, nil } -// ListBMC calls metalstack.admin.v2.MachineService.ListBMC. func (c *machineServiceClient) ListBMC(ctx context.Context, req *v2.MachineServiceListBMCRequest) (*v2.MachineServiceListBMCResponse, error) { - response, err := c.listBMC.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err + var res v2.MachineServiceListBMCResponse + if err := c.client.CallUnary(ctx, machineServiceListBMCSpec(), req, &res); err != nil { + return nil, err } - return nil, err + return &res, nil } -// ConsolePassword calls metalstack.admin.v2.MachineService.ConsolePassword. func (c *machineServiceClient) ConsolePassword(ctx context.Context, req *v2.MachineServiceConsolePasswordRequest) (*v2.MachineServiceConsolePasswordResponse, error) { - response, err := c.consolePassword.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err + var res v2.MachineServiceConsolePasswordResponse + if err := c.client.CallUnary(ctx, machineServiceConsolePasswordSpec(), req, &res); err != nil { + return nil, err } - return nil, err + return &res, nil } -// SetState calls metalstack.admin.v2.MachineService.SetState. func (c *machineServiceClient) SetState(ctx context.Context, req *v2.MachineServiceSetStateRequest) (*v2.MachineServiceSetStateResponse, error) { - response, err := c.setState.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err + var res v2.MachineServiceSetStateResponse + if err := c.client.CallUnary(ctx, machineServiceSetStateSpec(), req, &res); err != nil { + return nil, err } - return nil, err + return &res, nil } -// Issues calls metalstack.admin.v2.MachineService.Issues. func (c *machineServiceClient) Issues(ctx context.Context, req *v2.MachineServiceIssuesRequest) (*v2.MachineServiceIssuesResponse, error) { - response, err := c.issues.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err + var res v2.MachineServiceIssuesResponse + if err := c.client.CallUnary(ctx, machineServiceIssuesSpec(), req, &res); err != nil { + return nil, err } - return nil, err -} - -// MachineServiceHandler is an implementation of the metalstack.admin.v2.MachineService service. -type MachineServiceHandler interface { - // Returns the machine with the specified UUID. - Get(context.Context, *v2.MachineServiceGetRequest) (*v2.MachineServiceGetResponse, error) - // Returns the list of all machines. - List(context.Context, *v2.MachineServiceListRequest) (*v2.MachineServiceListResponse, error) - // Delete a machine from the database. This can only be done if the machine is offline and dead. - Delete(context.Context, *v2.MachineServiceDeleteRequest) (*v2.MachineServiceDeleteResponse, error) - // BMCCommand sends a command to the BMC of a machine. - BMCCommand(context.Context, *v2.MachineServiceBMCCommandRequest) (*v2.MachineServiceBMCCommandResponse, error) - // Returns the BMC details of a machine. - GetBMC(context.Context, *v2.MachineServiceGetBMCRequest) (*v2.MachineServiceGetBMCResponse, error) - // ListBMC returns the BMC details of many machines. - ListBMC(context.Context, *v2.MachineServiceListBMCRequest) (*v2.MachineServiceListBMCResponse, error) - // GetConsolePassword returns the password to access the serial console of the machine. - ConsolePassword(context.Context, *v2.MachineServiceConsolePasswordRequest) (*v2.MachineServiceConsolePasswordResponse, error) - // SetState set the state of a machine. - SetState(context.Context, *v2.MachineServiceSetStateRequest) (*v2.MachineServiceSetStateResponse, error) - // Issues allows to query issues of machines. - Issues(context.Context, *v2.MachineServiceIssuesRequest) (*v2.MachineServiceIssuesResponse, error) -} - -// NewMachineServiceHandler 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 NewMachineServiceHandler(svc MachineServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) { - machineServiceMethods := v2.File_metalstack_admin_v2_machine_proto.Services().ByName("MachineService").Methods() - machineServiceGetHandler := connect.NewUnaryHandlerSimple( - MachineServiceGetProcedure, - svc.Get, - connect.WithSchema(machineServiceMethods.ByName("Get")), - connect.WithHandlerOptions(opts...), - ) - machineServiceListHandler := connect.NewUnaryHandlerSimple( - MachineServiceListProcedure, - svc.List, - connect.WithSchema(machineServiceMethods.ByName("List")), - connect.WithHandlerOptions(opts...), - ) - machineServiceDeleteHandler := connect.NewUnaryHandlerSimple( - MachineServiceDeleteProcedure, - svc.Delete, - connect.WithSchema(machineServiceMethods.ByName("Delete")), - connect.WithHandlerOptions(opts...), - ) - machineServiceBMCCommandHandler := connect.NewUnaryHandlerSimple( - MachineServiceBMCCommandProcedure, - svc.BMCCommand, - connect.WithSchema(machineServiceMethods.ByName("BMCCommand")), - connect.WithHandlerOptions(opts...), - ) - machineServiceGetBMCHandler := connect.NewUnaryHandlerSimple( - MachineServiceGetBMCProcedure, - svc.GetBMC, - connect.WithSchema(machineServiceMethods.ByName("GetBMC")), - connect.WithHandlerOptions(opts...), - ) - machineServiceListBMCHandler := connect.NewUnaryHandlerSimple( - MachineServiceListBMCProcedure, - svc.ListBMC, - connect.WithSchema(machineServiceMethods.ByName("ListBMC")), - connect.WithHandlerOptions(opts...), - ) - machineServiceConsolePasswordHandler := connect.NewUnaryHandlerSimple( - MachineServiceConsolePasswordProcedure, - svc.ConsolePassword, - connect.WithSchema(machineServiceMethods.ByName("ConsolePassword")), - connect.WithHandlerOptions(opts...), - ) - machineServiceSetStateHandler := connect.NewUnaryHandlerSimple( - MachineServiceSetStateProcedure, - svc.SetState, - connect.WithSchema(machineServiceMethods.ByName("SetState")), - connect.WithHandlerOptions(opts...), - ) - machineServiceIssuesHandler := connect.NewUnaryHandlerSimple( - MachineServiceIssuesProcedure, - svc.Issues, - connect.WithSchema(machineServiceMethods.ByName("Issues")), - connect.WithHandlerOptions(opts...), - ) - return "/metalstack.admin.v2.MachineService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - switch r.URL.Path { - case MachineServiceGetProcedure: - machineServiceGetHandler.ServeHTTP(w, r) - case MachineServiceListProcedure: - machineServiceListHandler.ServeHTTP(w, r) - case MachineServiceDeleteProcedure: - machineServiceDeleteHandler.ServeHTTP(w, r) - case MachineServiceBMCCommandProcedure: - machineServiceBMCCommandHandler.ServeHTTP(w, r) - case MachineServiceGetBMCProcedure: - machineServiceGetBMCHandler.ServeHTTP(w, r) - case MachineServiceListBMCProcedure: - machineServiceListBMCHandler.ServeHTTP(w, r) - case MachineServiceConsolePasswordProcedure: - machineServiceConsolePasswordHandler.ServeHTTP(w, r) - case MachineServiceSetStateProcedure: - machineServiceSetStateHandler.ServeHTTP(w, r) - case MachineServiceIssuesProcedure: - machineServiceIssuesHandler.ServeHTTP(w, r) - default: - http.NotFound(w, r) - } - }) + return &res, nil } -// UnimplementedMachineServiceHandler returns CodeUnimplemented from all methods. -type UnimplementedMachineServiceHandler struct{} +type machineServiceHandler struct{ svc MachineServiceHandler } -func (UnimplementedMachineServiceHandler) Get(context.Context, *v2.MachineServiceGetRequest) (*v2.MachineServiceGetResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.MachineService.Get is not implemented")) +func (h machineServiceHandler) get(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.MachineServiceGetRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Get(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } -func (UnimplementedMachineServiceHandler) List(context.Context, *v2.MachineServiceListRequest) (*v2.MachineServiceListResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.MachineService.List is not implemented")) +func (h machineServiceHandler) list(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.MachineServiceListRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.List(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } -func (UnimplementedMachineServiceHandler) Delete(context.Context, *v2.MachineServiceDeleteRequest) (*v2.MachineServiceDeleteResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.MachineService.Delete is not implemented")) +func (h machineServiceHandler) delete(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.MachineServiceDeleteRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Delete(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } -func (UnimplementedMachineServiceHandler) BMCCommand(context.Context, *v2.MachineServiceBMCCommandRequest) (*v2.MachineServiceBMCCommandResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.MachineService.BMCCommand is not implemented")) +func (h machineServiceHandler) bMCCommand(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.MachineServiceBMCCommandRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.BMCCommand(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } -func (UnimplementedMachineServiceHandler) GetBMC(context.Context, *v2.MachineServiceGetBMCRequest) (*v2.MachineServiceGetBMCResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.MachineService.GetBMC is not implemented")) +func (h machineServiceHandler) getBMC(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.MachineServiceGetBMCRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.GetBMC(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } -func (UnimplementedMachineServiceHandler) ListBMC(context.Context, *v2.MachineServiceListBMCRequest) (*v2.MachineServiceListBMCResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.MachineService.ListBMC is not implemented")) +func (h machineServiceHandler) listBMC(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.MachineServiceListBMCRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.ListBMC(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } -func (UnimplementedMachineServiceHandler) ConsolePassword(context.Context, *v2.MachineServiceConsolePasswordRequest) (*v2.MachineServiceConsolePasswordResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.MachineService.ConsolePassword is not implemented")) +func (h machineServiceHandler) consolePassword(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.MachineServiceConsolePasswordRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.ConsolePassword(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } -func (UnimplementedMachineServiceHandler) SetState(context.Context, *v2.MachineServiceSetStateRequest) (*v2.MachineServiceSetStateResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.MachineService.SetState is not implemented")) +func (h machineServiceHandler) setState(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.MachineServiceSetStateRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.SetState(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } -func (UnimplementedMachineServiceHandler) Issues(context.Context, *v2.MachineServiceIssuesRequest) (*v2.MachineServiceIssuesResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.MachineService.Issues is not implemented")) +func (h machineServiceHandler) issues(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.MachineServiceIssuesRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Issues(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } diff --git a/go/metalstack/admin/v2/adminv2connect/network.connect.go b/go/metalstack/admin/v2/adminv2connect/network.connect.go index 039d93d0..6d19f198 100644 --- a/go/metalstack/admin/v2/adminv2connect/network.connect.go +++ b/go/metalstack/admin/v2/adminv2connect/network.connect.go @@ -5,46 +5,75 @@ package adminv2connect import ( - connect "connectrpc.com/connect" + connect "connectrpc.com/connect/v2" context "context" - errors "errors" v2 "github.com/metal-stack/api/go/metalstack/admin/v2" - http "net/http" - strings "strings" + sync "sync" ) -// 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 ( // NetworkServiceName is the fully-qualified name of the NetworkService service. NetworkServiceName = "metalstack.admin.v2.NetworkService" ) -// 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. +// These constants are the procedure 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 ( - // NetworkServiceGetProcedure is the fully-qualified name of the NetworkService's Get RPC. + // NetworkServiceGetProcedure is the procedure name of the NetworkService's Get RPC. NetworkServiceGetProcedure = "/metalstack.admin.v2.NetworkService/Get" - // NetworkServiceCreateProcedure is the fully-qualified name of the NetworkService's Create RPC. + // NetworkServiceCreateProcedure is the procedure name of the NetworkService's Create RPC. NetworkServiceCreateProcedure = "/metalstack.admin.v2.NetworkService/Create" - // NetworkServiceUpdateProcedure is the fully-qualified name of the NetworkService's Update RPC. + // NetworkServiceUpdateProcedure is the procedure name of the NetworkService's Update RPC. NetworkServiceUpdateProcedure = "/metalstack.admin.v2.NetworkService/Update" - // NetworkServiceDeleteProcedure is the fully-qualified name of the NetworkService's Delete RPC. + // NetworkServiceDeleteProcedure is the procedure name of the NetworkService's Delete RPC. NetworkServiceDeleteProcedure = "/metalstack.admin.v2.NetworkService/Delete" - // NetworkServiceListProcedure is the fully-qualified name of the NetworkService's List RPC. + // NetworkServiceListProcedure is the procedure name of the NetworkService's List RPC. NetworkServiceListProcedure = "/metalstack.admin.v2.NetworkService/List" ) +var ( + networkServiceGetSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_admin_v2_network_proto.Services().ByName("NetworkService").Methods().ByName("Get"), + Procedure: NetworkServiceGetProcedure, + } + }) + networkServiceCreateSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_admin_v2_network_proto.Services().ByName("NetworkService").Methods().ByName("Create"), + Procedure: NetworkServiceCreateProcedure, + } + }) + networkServiceUpdateSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_admin_v2_network_proto.Services().ByName("NetworkService").Methods().ByName("Update"), + Procedure: NetworkServiceUpdateProcedure, + } + }) + networkServiceDeleteSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_admin_v2_network_proto.Services().ByName("NetworkService").Methods().ByName("Delete"), + Procedure: NetworkServiceDeleteProcedure, + } + }) + networkServiceListSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_admin_v2_network_proto.Services().ByName("NetworkService").Methods().ByName("List"), + Procedure: NetworkServiceListProcedure, + } + }) +) + // NetworkServiceClient is a client for the metalstack.admin.v2.NetworkService service. type NetworkServiceClient interface { // Returns the network with the specified ID. @@ -60,101 +89,9 @@ type NetworkServiceClient interface { } // NewNetworkServiceClient constructs a client for the metalstack.admin.v2.NetworkService 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 NewNetworkServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) NetworkServiceClient { - baseURL = strings.TrimRight(baseURL, "/") - networkServiceMethods := v2.File_metalstack_admin_v2_network_proto.Services().ByName("NetworkService").Methods() - return &networkServiceClient{ - get: connect.NewClient[v2.NetworkServiceGetRequest, v2.NetworkServiceGetResponse]( - httpClient, - baseURL+NetworkServiceGetProcedure, - connect.WithSchema(networkServiceMethods.ByName("Get")), - connect.WithClientOptions(opts...), - ), - create: connect.NewClient[v2.NetworkServiceCreateRequest, v2.NetworkServiceCreateResponse]( - httpClient, - baseURL+NetworkServiceCreateProcedure, - connect.WithSchema(networkServiceMethods.ByName("Create")), - connect.WithClientOptions(opts...), - ), - update: connect.NewClient[v2.NetworkServiceUpdateRequest, v2.NetworkServiceUpdateResponse]( - httpClient, - baseURL+NetworkServiceUpdateProcedure, - connect.WithSchema(networkServiceMethods.ByName("Update")), - connect.WithClientOptions(opts...), - ), - delete: connect.NewClient[v2.NetworkServiceDeleteRequest, v2.NetworkServiceDeleteResponse]( - httpClient, - baseURL+NetworkServiceDeleteProcedure, - connect.WithSchema(networkServiceMethods.ByName("Delete")), - connect.WithClientOptions(opts...), - ), - list: connect.NewClient[v2.NetworkServiceListRequest, v2.NetworkServiceListResponse]( - httpClient, - baseURL+NetworkServiceListProcedure, - connect.WithSchema(networkServiceMethods.ByName("List")), - connect.WithClientOptions(opts...), - ), - } -} - -// networkServiceClient implements NetworkServiceClient. -type networkServiceClient struct { - get *connect.Client[v2.NetworkServiceGetRequest, v2.NetworkServiceGetResponse] - create *connect.Client[v2.NetworkServiceCreateRequest, v2.NetworkServiceCreateResponse] - update *connect.Client[v2.NetworkServiceUpdateRequest, v2.NetworkServiceUpdateResponse] - delete *connect.Client[v2.NetworkServiceDeleteRequest, v2.NetworkServiceDeleteResponse] - list *connect.Client[v2.NetworkServiceListRequest, v2.NetworkServiceListResponse] -} - -// Get calls metalstack.admin.v2.NetworkService.Get. -func (c *networkServiceClient) Get(ctx context.Context, req *v2.NetworkServiceGetRequest) (*v2.NetworkServiceGetResponse, error) { - response, err := c.get.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err -} - -// Create calls metalstack.admin.v2.NetworkService.Create. -func (c *networkServiceClient) Create(ctx context.Context, req *v2.NetworkServiceCreateRequest) (*v2.NetworkServiceCreateResponse, error) { - response, err := c.create.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err -} - -// Update calls metalstack.admin.v2.NetworkService.Update. -func (c *networkServiceClient) Update(ctx context.Context, req *v2.NetworkServiceUpdateRequest) (*v2.NetworkServiceUpdateResponse, error) { - response, err := c.update.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err -} - -// Delete calls metalstack.admin.v2.NetworkService.Delete. -func (c *networkServiceClient) Delete(ctx context.Context, req *v2.NetworkServiceDeleteRequest) (*v2.NetworkServiceDeleteResponse, error) { - response, err := c.delete.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err -} - -// List calls metalstack.admin.v2.NetworkService.List. -func (c *networkServiceClient) List(ctx context.Context, req *v2.NetworkServiceListRequest) (*v2.NetworkServiceListResponse, error) { - response, err := c.list.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err +// Multiple service clients may share a single connect.Client. +func NewNetworkServiceClient(client *connect.Client) NetworkServiceClient { + return &networkServiceClient{client: client} } // NetworkServiceHandler is an implementation of the metalstack.admin.v2.NetworkService service. @@ -171,80 +108,144 @@ type NetworkServiceHandler interface { List(context.Context, *v2.NetworkServiceListRequest) (*v2.NetworkServiceListResponse, error) } -// NewNetworkServiceHandler 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 NewNetworkServiceHandler(svc NetworkServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) { - networkServiceMethods := v2.File_metalstack_admin_v2_network_proto.Services().ByName("NetworkService").Methods() - networkServiceGetHandler := connect.NewUnaryHandlerSimple( - NetworkServiceGetProcedure, - svc.Get, - connect.WithSchema(networkServiceMethods.ByName("Get")), - connect.WithHandlerOptions(opts...), - ) - networkServiceCreateHandler := connect.NewUnaryHandlerSimple( - NetworkServiceCreateProcedure, - svc.Create, - connect.WithSchema(networkServiceMethods.ByName("Create")), - connect.WithHandlerOptions(opts...), +// RegisterNetworkServiceHandler registers svc as the metalstack.admin.v2.NetworkService +// implementation on server. +func RegisterNetworkServiceHandler(server *connect.Server, svc NetworkServiceHandler) { + adapter := networkServiceHandler{svc: svc} + server.Register( + connect.Method{Spec: networkServiceGetSpec(), Handler: adapter.get}, + connect.Method{Spec: networkServiceCreateSpec(), Handler: adapter.create}, + connect.Method{Spec: networkServiceUpdateSpec(), Handler: adapter.update}, + connect.Method{Spec: networkServiceDeleteSpec(), Handler: adapter.delete}, + connect.Method{Spec: networkServiceListSpec(), Handler: adapter.list}, ) - networkServiceUpdateHandler := connect.NewUnaryHandlerSimple( - NetworkServiceUpdateProcedure, - svc.Update, - connect.WithSchema(networkServiceMethods.ByName("Update")), - connect.WithHandlerOptions(opts...), - ) - networkServiceDeleteHandler := connect.NewUnaryHandlerSimple( - NetworkServiceDeleteProcedure, - svc.Delete, - connect.WithSchema(networkServiceMethods.ByName("Delete")), - connect.WithHandlerOptions(opts...), - ) - networkServiceListHandler := connect.NewUnaryHandlerSimple( - NetworkServiceListProcedure, - svc.List, - connect.WithSchema(networkServiceMethods.ByName("List")), - connect.WithHandlerOptions(opts...), - ) - return "/metalstack.admin.v2.NetworkService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - switch r.URL.Path { - case NetworkServiceGetProcedure: - networkServiceGetHandler.ServeHTTP(w, r) - case NetworkServiceCreateProcedure: - networkServiceCreateHandler.ServeHTTP(w, r) - case NetworkServiceUpdateProcedure: - networkServiceUpdateHandler.ServeHTTP(w, r) - case NetworkServiceDeleteProcedure: - networkServiceDeleteHandler.ServeHTTP(w, r) - case NetworkServiceListProcedure: - networkServiceListHandler.ServeHTTP(w, r) - default: - http.NotFound(w, r) - } - }) } // UnimplementedNetworkServiceHandler returns CodeUnimplemented from all methods. type UnimplementedNetworkServiceHandler struct{} func (UnimplementedNetworkServiceHandler) Get(context.Context, *v2.NetworkServiceGetRequest) (*v2.NetworkServiceGetResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.NetworkService.Get is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.admin.v2.NetworkService.Get is not implemented") } func (UnimplementedNetworkServiceHandler) Create(context.Context, *v2.NetworkServiceCreateRequest) (*v2.NetworkServiceCreateResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.NetworkService.Create is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.admin.v2.NetworkService.Create is not implemented") } func (UnimplementedNetworkServiceHandler) Update(context.Context, *v2.NetworkServiceUpdateRequest) (*v2.NetworkServiceUpdateResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.NetworkService.Update is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.admin.v2.NetworkService.Update is not implemented") } func (UnimplementedNetworkServiceHandler) Delete(context.Context, *v2.NetworkServiceDeleteRequest) (*v2.NetworkServiceDeleteResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.NetworkService.Delete is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.admin.v2.NetworkService.Delete is not implemented") } func (UnimplementedNetworkServiceHandler) List(context.Context, *v2.NetworkServiceListRequest) (*v2.NetworkServiceListResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.NetworkService.List is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.admin.v2.NetworkService.List is not implemented") +} + +type networkServiceClient struct { + client *connect.Client +} + +func (c *networkServiceClient) Get(ctx context.Context, req *v2.NetworkServiceGetRequest) (*v2.NetworkServiceGetResponse, error) { + var res v2.NetworkServiceGetResponse + if err := c.client.CallUnary(ctx, networkServiceGetSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *networkServiceClient) Create(ctx context.Context, req *v2.NetworkServiceCreateRequest) (*v2.NetworkServiceCreateResponse, error) { + var res v2.NetworkServiceCreateResponse + if err := c.client.CallUnary(ctx, networkServiceCreateSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *networkServiceClient) Update(ctx context.Context, req *v2.NetworkServiceUpdateRequest) (*v2.NetworkServiceUpdateResponse, error) { + var res v2.NetworkServiceUpdateResponse + if err := c.client.CallUnary(ctx, networkServiceUpdateSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *networkServiceClient) Delete(ctx context.Context, req *v2.NetworkServiceDeleteRequest) (*v2.NetworkServiceDeleteResponse, error) { + var res v2.NetworkServiceDeleteResponse + if err := c.client.CallUnary(ctx, networkServiceDeleteSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *networkServiceClient) List(ctx context.Context, req *v2.NetworkServiceListRequest) (*v2.NetworkServiceListResponse, error) { + var res v2.NetworkServiceListResponse + if err := c.client.CallUnary(ctx, networkServiceListSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +type networkServiceHandler struct{ svc NetworkServiceHandler } + +func (h networkServiceHandler) get(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.NetworkServiceGetRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Get(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) +} + +func (h networkServiceHandler) create(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.NetworkServiceCreateRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Create(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) +} + +func (h networkServiceHandler) update(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.NetworkServiceUpdateRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Update(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) +} + +func (h networkServiceHandler) delete(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.NetworkServiceDeleteRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Delete(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) +} + +func (h networkServiceHandler) list(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.NetworkServiceListRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.List(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } diff --git a/go/metalstack/admin/v2/adminv2connect/partition.connect.go b/go/metalstack/admin/v2/adminv2connect/partition.connect.go index 1f6dcdf9..d9fe5c10 100644 --- a/go/metalstack/admin/v2/adminv2connect/partition.connect.go +++ b/go/metalstack/admin/v2/adminv2connect/partition.connect.go @@ -5,45 +5,66 @@ package adminv2connect import ( - connect "connectrpc.com/connect" + connect "connectrpc.com/connect/v2" context "context" - errors "errors" v2 "github.com/metal-stack/api/go/metalstack/admin/v2" - http "net/http" - strings "strings" + sync "sync" ) -// 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 ( // PartitionServiceName is the fully-qualified name of the PartitionService service. PartitionServiceName = "metalstack.admin.v2.PartitionService" ) -// 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. +// These constants are the procedure 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 ( - // PartitionServiceCreateProcedure is the fully-qualified name of the PartitionService's Create RPC. + // PartitionServiceCreateProcedure is the procedure name of the PartitionService's Create RPC. PartitionServiceCreateProcedure = "/metalstack.admin.v2.PartitionService/Create" - // PartitionServiceUpdateProcedure is the fully-qualified name of the PartitionService's Update RPC. + // PartitionServiceUpdateProcedure is the procedure name of the PartitionService's Update RPC. PartitionServiceUpdateProcedure = "/metalstack.admin.v2.PartitionService/Update" - // PartitionServiceDeleteProcedure is the fully-qualified name of the PartitionService's Delete RPC. + // PartitionServiceDeleteProcedure is the procedure name of the PartitionService's Delete RPC. PartitionServiceDeleteProcedure = "/metalstack.admin.v2.PartitionService/Delete" - // PartitionServiceCapacityProcedure is the fully-qualified name of the PartitionService's Capacity - // RPC. + // PartitionServiceCapacityProcedure is the procedure name of the PartitionService's Capacity RPC. PartitionServiceCapacityProcedure = "/metalstack.admin.v2.PartitionService/Capacity" ) +var ( + partitionServiceCreateSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_admin_v2_partition_proto.Services().ByName("PartitionService").Methods().ByName("Create"), + Procedure: PartitionServiceCreateProcedure, + } + }) + partitionServiceUpdateSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_admin_v2_partition_proto.Services().ByName("PartitionService").Methods().ByName("Update"), + Procedure: PartitionServiceUpdateProcedure, + } + }) + partitionServiceDeleteSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_admin_v2_partition_proto.Services().ByName("PartitionService").Methods().ByName("Delete"), + Procedure: PartitionServiceDeleteProcedure, + } + }) + partitionServiceCapacitySpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_admin_v2_partition_proto.Services().ByName("PartitionService").Methods().ByName("Capacity"), + Procedure: PartitionServiceCapacityProcedure, + } + }) +) + // PartitionServiceClient is a client for the metalstack.admin.v2.PartitionService service. type PartitionServiceClient interface { // Creates a new partition. @@ -57,85 +78,9 @@ type PartitionServiceClient interface { } // NewPartitionServiceClient constructs a client for the metalstack.admin.v2.PartitionService -// 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 NewPartitionServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) PartitionServiceClient { - baseURL = strings.TrimRight(baseURL, "/") - partitionServiceMethods := v2.File_metalstack_admin_v2_partition_proto.Services().ByName("PartitionService").Methods() - return &partitionServiceClient{ - create: connect.NewClient[v2.PartitionServiceCreateRequest, v2.PartitionServiceCreateResponse]( - httpClient, - baseURL+PartitionServiceCreateProcedure, - connect.WithSchema(partitionServiceMethods.ByName("Create")), - connect.WithClientOptions(opts...), - ), - update: connect.NewClient[v2.PartitionServiceUpdateRequest, v2.PartitionServiceUpdateResponse]( - httpClient, - baseURL+PartitionServiceUpdateProcedure, - connect.WithSchema(partitionServiceMethods.ByName("Update")), - connect.WithClientOptions(opts...), - ), - delete: connect.NewClient[v2.PartitionServiceDeleteRequest, v2.PartitionServiceDeleteResponse]( - httpClient, - baseURL+PartitionServiceDeleteProcedure, - connect.WithSchema(partitionServiceMethods.ByName("Delete")), - connect.WithClientOptions(opts...), - ), - capacity: connect.NewClient[v2.PartitionServiceCapacityRequest, v2.PartitionServiceCapacityResponse]( - httpClient, - baseURL+PartitionServiceCapacityProcedure, - connect.WithSchema(partitionServiceMethods.ByName("Capacity")), - connect.WithClientOptions(opts...), - ), - } -} - -// partitionServiceClient implements PartitionServiceClient. -type partitionServiceClient struct { - create *connect.Client[v2.PartitionServiceCreateRequest, v2.PartitionServiceCreateResponse] - update *connect.Client[v2.PartitionServiceUpdateRequest, v2.PartitionServiceUpdateResponse] - delete *connect.Client[v2.PartitionServiceDeleteRequest, v2.PartitionServiceDeleteResponse] - capacity *connect.Client[v2.PartitionServiceCapacityRequest, v2.PartitionServiceCapacityResponse] -} - -// Create calls metalstack.admin.v2.PartitionService.Create. -func (c *partitionServiceClient) Create(ctx context.Context, req *v2.PartitionServiceCreateRequest) (*v2.PartitionServiceCreateResponse, error) { - response, err := c.create.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err -} - -// Update calls metalstack.admin.v2.PartitionService.Update. -func (c *partitionServiceClient) Update(ctx context.Context, req *v2.PartitionServiceUpdateRequest) (*v2.PartitionServiceUpdateResponse, error) { - response, err := c.update.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err -} - -// Delete calls metalstack.admin.v2.PartitionService.Delete. -func (c *partitionServiceClient) Delete(ctx context.Context, req *v2.PartitionServiceDeleteRequest) (*v2.PartitionServiceDeleteResponse, error) { - response, err := c.delete.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err -} - -// Capacity calls metalstack.admin.v2.PartitionService.Capacity. -func (c *partitionServiceClient) Capacity(ctx context.Context, req *v2.PartitionServiceCapacityRequest) (*v2.PartitionServiceCapacityResponse, error) { - response, err := c.capacity.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err +// service. Multiple service clients may share a single connect.Client. +func NewPartitionServiceClient(client *connect.Client) PartitionServiceClient { + return &partitionServiceClient{client: client} } // PartitionServiceHandler is an implementation of the metalstack.admin.v2.PartitionService service. @@ -150,68 +95,119 @@ type PartitionServiceHandler interface { Capacity(context.Context, *v2.PartitionServiceCapacityRequest) (*v2.PartitionServiceCapacityResponse, error) } -// NewPartitionServiceHandler 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 NewPartitionServiceHandler(svc PartitionServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) { - partitionServiceMethods := v2.File_metalstack_admin_v2_partition_proto.Services().ByName("PartitionService").Methods() - partitionServiceCreateHandler := connect.NewUnaryHandlerSimple( - PartitionServiceCreateProcedure, - svc.Create, - connect.WithSchema(partitionServiceMethods.ByName("Create")), - connect.WithHandlerOptions(opts...), +// RegisterPartitionServiceHandler registers svc as the metalstack.admin.v2.PartitionService +// implementation on server. +func RegisterPartitionServiceHandler(server *connect.Server, svc PartitionServiceHandler) { + adapter := partitionServiceHandler{svc: svc} + server.Register( + connect.Method{Spec: partitionServiceCreateSpec(), Handler: adapter.create}, + connect.Method{Spec: partitionServiceUpdateSpec(), Handler: adapter.update}, + connect.Method{Spec: partitionServiceDeleteSpec(), Handler: adapter.delete}, + connect.Method{Spec: partitionServiceCapacitySpec(), Handler: adapter.capacity}, ) - partitionServiceUpdateHandler := connect.NewUnaryHandlerSimple( - PartitionServiceUpdateProcedure, - svc.Update, - connect.WithSchema(partitionServiceMethods.ByName("Update")), - connect.WithHandlerOptions(opts...), - ) - partitionServiceDeleteHandler := connect.NewUnaryHandlerSimple( - PartitionServiceDeleteProcedure, - svc.Delete, - connect.WithSchema(partitionServiceMethods.ByName("Delete")), - connect.WithHandlerOptions(opts...), - ) - partitionServiceCapacityHandler := connect.NewUnaryHandlerSimple( - PartitionServiceCapacityProcedure, - svc.Capacity, - connect.WithSchema(partitionServiceMethods.ByName("Capacity")), - connect.WithHandlerOptions(opts...), - ) - return "/metalstack.admin.v2.PartitionService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - switch r.URL.Path { - case PartitionServiceCreateProcedure: - partitionServiceCreateHandler.ServeHTTP(w, r) - case PartitionServiceUpdateProcedure: - partitionServiceUpdateHandler.ServeHTTP(w, r) - case PartitionServiceDeleteProcedure: - partitionServiceDeleteHandler.ServeHTTP(w, r) - case PartitionServiceCapacityProcedure: - partitionServiceCapacityHandler.ServeHTTP(w, r) - default: - http.NotFound(w, r) - } - }) } // UnimplementedPartitionServiceHandler returns CodeUnimplemented from all methods. type UnimplementedPartitionServiceHandler struct{} func (UnimplementedPartitionServiceHandler) Create(context.Context, *v2.PartitionServiceCreateRequest) (*v2.PartitionServiceCreateResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.PartitionService.Create is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.admin.v2.PartitionService.Create is not implemented") } func (UnimplementedPartitionServiceHandler) Update(context.Context, *v2.PartitionServiceUpdateRequest) (*v2.PartitionServiceUpdateResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.PartitionService.Update is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.admin.v2.PartitionService.Update is not implemented") } func (UnimplementedPartitionServiceHandler) Delete(context.Context, *v2.PartitionServiceDeleteRequest) (*v2.PartitionServiceDeleteResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.PartitionService.Delete is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.admin.v2.PartitionService.Delete is not implemented") } func (UnimplementedPartitionServiceHandler) Capacity(context.Context, *v2.PartitionServiceCapacityRequest) (*v2.PartitionServiceCapacityResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.PartitionService.Capacity is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.admin.v2.PartitionService.Capacity is not implemented") +} + +type partitionServiceClient struct { + client *connect.Client +} + +func (c *partitionServiceClient) Create(ctx context.Context, req *v2.PartitionServiceCreateRequest) (*v2.PartitionServiceCreateResponse, error) { + var res v2.PartitionServiceCreateResponse + if err := c.client.CallUnary(ctx, partitionServiceCreateSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *partitionServiceClient) Update(ctx context.Context, req *v2.PartitionServiceUpdateRequest) (*v2.PartitionServiceUpdateResponse, error) { + var res v2.PartitionServiceUpdateResponse + if err := c.client.CallUnary(ctx, partitionServiceUpdateSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *partitionServiceClient) Delete(ctx context.Context, req *v2.PartitionServiceDeleteRequest) (*v2.PartitionServiceDeleteResponse, error) { + var res v2.PartitionServiceDeleteResponse + if err := c.client.CallUnary(ctx, partitionServiceDeleteSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *partitionServiceClient) Capacity(ctx context.Context, req *v2.PartitionServiceCapacityRequest) (*v2.PartitionServiceCapacityResponse, error) { + var res v2.PartitionServiceCapacityResponse + if err := c.client.CallUnary(ctx, partitionServiceCapacitySpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +type partitionServiceHandler struct{ svc PartitionServiceHandler } + +func (h partitionServiceHandler) create(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.PartitionServiceCreateRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Create(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) +} + +func (h partitionServiceHandler) update(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.PartitionServiceUpdateRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Update(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) +} + +func (h partitionServiceHandler) delete(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.PartitionServiceDeleteRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Delete(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) +} + +func (h partitionServiceHandler) capacity(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.PartitionServiceCapacityRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Capacity(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } diff --git a/go/metalstack/admin/v2/adminv2connect/project.connect.go b/go/metalstack/admin/v2/adminv2connect/project.connect.go index 9d614b2f..bc93974f 100644 --- a/go/metalstack/admin/v2/adminv2connect/project.connect.go +++ b/go/metalstack/admin/v2/adminv2connect/project.connect.go @@ -5,38 +5,39 @@ package adminv2connect import ( - connect "connectrpc.com/connect" + connect "connectrpc.com/connect/v2" context "context" - errors "errors" v2 "github.com/metal-stack/api/go/metalstack/admin/v2" - http "net/http" - strings "strings" + sync "sync" ) -// 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 ( // ProjectServiceName is the fully-qualified name of the ProjectService service. ProjectServiceName = "metalstack.admin.v2.ProjectService" ) -// 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. +// These constants are the procedure 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 ( - // ProjectServiceListProcedure is the fully-qualified name of the ProjectService's List RPC. + // ProjectServiceListProcedure is the procedure name of the ProjectService's List RPC. ProjectServiceListProcedure = "/metalstack.admin.v2.ProjectService/List" ) +var ( + projectServiceListSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_admin_v2_project_proto.Services().ByName("ProjectService").Methods().ByName("List"), + Procedure: ProjectServiceListProcedure, + } + }) +) + // ProjectServiceClient is a client for the metalstack.admin.v2.ProjectService service. type ProjectServiceClient interface { // Returns the list of projects matching the filter criteria. @@ -44,37 +45,9 @@ type ProjectServiceClient interface { } // NewProjectServiceClient constructs a client for the metalstack.admin.v2.ProjectService 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 NewProjectServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) ProjectServiceClient { - baseURL = strings.TrimRight(baseURL, "/") - projectServiceMethods := v2.File_metalstack_admin_v2_project_proto.Services().ByName("ProjectService").Methods() - return &projectServiceClient{ - list: connect.NewClient[v2.ProjectServiceListRequest, v2.ProjectServiceListResponse]( - httpClient, - baseURL+ProjectServiceListProcedure, - connect.WithSchema(projectServiceMethods.ByName("List")), - connect.WithClientOptions(opts...), - ), - } -} - -// projectServiceClient implements ProjectServiceClient. -type projectServiceClient struct { - list *connect.Client[v2.ProjectServiceListRequest, v2.ProjectServiceListResponse] -} - -// List calls metalstack.admin.v2.ProjectService.List. -func (c *projectServiceClient) List(ctx context.Context, req *v2.ProjectServiceListRequest) (*v2.ProjectServiceListResponse, error) { - response, err := c.list.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err +// Multiple service clients may share a single connect.Client. +func NewProjectServiceClient(client *connect.Client) ProjectServiceClient { + return &projectServiceClient{client: client} } // ProjectServiceHandler is an implementation of the metalstack.admin.v2.ProjectService service. @@ -83,32 +56,44 @@ type ProjectServiceHandler interface { List(context.Context, *v2.ProjectServiceListRequest) (*v2.ProjectServiceListResponse, error) } -// NewProjectServiceHandler 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 NewProjectServiceHandler(svc ProjectServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) { - projectServiceMethods := v2.File_metalstack_admin_v2_project_proto.Services().ByName("ProjectService").Methods() - projectServiceListHandler := connect.NewUnaryHandlerSimple( - ProjectServiceListProcedure, - svc.List, - connect.WithSchema(projectServiceMethods.ByName("List")), - connect.WithHandlerOptions(opts...), +// RegisterProjectServiceHandler registers svc as the metalstack.admin.v2.ProjectService +// implementation on server. +func RegisterProjectServiceHandler(server *connect.Server, svc ProjectServiceHandler) { + adapter := projectServiceHandler{svc: svc} + server.Register( + connect.Method{Spec: projectServiceListSpec(), Handler: adapter.list}, ) - return "/metalstack.admin.v2.ProjectService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - switch r.URL.Path { - case ProjectServiceListProcedure: - projectServiceListHandler.ServeHTTP(w, r) - default: - http.NotFound(w, r) - } - }) } // UnimplementedProjectServiceHandler returns CodeUnimplemented from all methods. type UnimplementedProjectServiceHandler struct{} func (UnimplementedProjectServiceHandler) List(context.Context, *v2.ProjectServiceListRequest) (*v2.ProjectServiceListResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.ProjectService.List is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.admin.v2.ProjectService.List is not implemented") +} + +type projectServiceClient struct { + client *connect.Client +} + +func (c *projectServiceClient) List(ctx context.Context, req *v2.ProjectServiceListRequest) (*v2.ProjectServiceListResponse, error) { + var res v2.ProjectServiceListResponse + if err := c.client.CallUnary(ctx, projectServiceListSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +type projectServiceHandler struct{ svc ProjectServiceHandler } + +func (h projectServiceHandler) list(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.ProjectServiceListRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.List(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } diff --git a/go/metalstack/admin/v2/adminv2connect/size.connect.go b/go/metalstack/admin/v2/adminv2connect/size.connect.go index 4f94d4a9..272ecdb2 100644 --- a/go/metalstack/admin/v2/adminv2connect/size.connect.go +++ b/go/metalstack/admin/v2/adminv2connect/size.connect.go @@ -5,42 +5,57 @@ package adminv2connect import ( - connect "connectrpc.com/connect" + connect "connectrpc.com/connect/v2" context "context" - errors "errors" v2 "github.com/metal-stack/api/go/metalstack/admin/v2" - http "net/http" - strings "strings" + sync "sync" ) -// 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 ( // SizeServiceName is the fully-qualified name of the SizeService service. SizeServiceName = "metalstack.admin.v2.SizeService" ) -// 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. +// These constants are the procedure 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 ( - // SizeServiceCreateProcedure is the fully-qualified name of the SizeService's Create RPC. + // SizeServiceCreateProcedure is the procedure name of the SizeService's Create RPC. SizeServiceCreateProcedure = "/metalstack.admin.v2.SizeService/Create" - // SizeServiceUpdateProcedure is the fully-qualified name of the SizeService's Update RPC. + // SizeServiceUpdateProcedure is the procedure name of the SizeService's Update RPC. SizeServiceUpdateProcedure = "/metalstack.admin.v2.SizeService/Update" - // SizeServiceDeleteProcedure is the fully-qualified name of the SizeService's Delete RPC. + // SizeServiceDeleteProcedure is the procedure name of the SizeService's Delete RPC. SizeServiceDeleteProcedure = "/metalstack.admin.v2.SizeService/Delete" ) +var ( + sizeServiceCreateSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_admin_v2_size_proto.Services().ByName("SizeService").Methods().ByName("Create"), + Procedure: SizeServiceCreateProcedure, + } + }) + sizeServiceUpdateSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_admin_v2_size_proto.Services().ByName("SizeService").Methods().ByName("Update"), + Procedure: SizeServiceUpdateProcedure, + } + }) + sizeServiceDeleteSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_admin_v2_size_proto.Services().ByName("SizeService").Methods().ByName("Delete"), + Procedure: SizeServiceDeleteProcedure, + } + }) +) + // SizeServiceClient is a client for the metalstack.admin.v2.SizeService service. type SizeServiceClient interface { // Creates a new size. @@ -51,70 +66,10 @@ type SizeServiceClient interface { Delete(context.Context, *v2.SizeServiceDeleteRequest) (*v2.SizeServiceDeleteResponse, error) } -// NewSizeServiceClient constructs a client for the metalstack.admin.v2.SizeService 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 NewSizeServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) SizeServiceClient { - baseURL = strings.TrimRight(baseURL, "/") - sizeServiceMethods := v2.File_metalstack_admin_v2_size_proto.Services().ByName("SizeService").Methods() - return &sizeServiceClient{ - create: connect.NewClient[v2.SizeServiceCreateRequest, v2.SizeServiceCreateResponse]( - httpClient, - baseURL+SizeServiceCreateProcedure, - connect.WithSchema(sizeServiceMethods.ByName("Create")), - connect.WithClientOptions(opts...), - ), - update: connect.NewClient[v2.SizeServiceUpdateRequest, v2.SizeServiceUpdateResponse]( - httpClient, - baseURL+SizeServiceUpdateProcedure, - connect.WithSchema(sizeServiceMethods.ByName("Update")), - connect.WithClientOptions(opts...), - ), - delete: connect.NewClient[v2.SizeServiceDeleteRequest, v2.SizeServiceDeleteResponse]( - httpClient, - baseURL+SizeServiceDeleteProcedure, - connect.WithSchema(sizeServiceMethods.ByName("Delete")), - connect.WithClientOptions(opts...), - ), - } -} - -// sizeServiceClient implements SizeServiceClient. -type sizeServiceClient struct { - create *connect.Client[v2.SizeServiceCreateRequest, v2.SizeServiceCreateResponse] - update *connect.Client[v2.SizeServiceUpdateRequest, v2.SizeServiceUpdateResponse] - delete *connect.Client[v2.SizeServiceDeleteRequest, v2.SizeServiceDeleteResponse] -} - -// Create calls metalstack.admin.v2.SizeService.Create. -func (c *sizeServiceClient) Create(ctx context.Context, req *v2.SizeServiceCreateRequest) (*v2.SizeServiceCreateResponse, error) { - response, err := c.create.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err -} - -// Update calls metalstack.admin.v2.SizeService.Update. -func (c *sizeServiceClient) Update(ctx context.Context, req *v2.SizeServiceUpdateRequest) (*v2.SizeServiceUpdateResponse, error) { - response, err := c.update.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err -} - -// Delete calls metalstack.admin.v2.SizeService.Delete. -func (c *sizeServiceClient) Delete(ctx context.Context, req *v2.SizeServiceDeleteRequest) (*v2.SizeServiceDeleteResponse, error) { - response, err := c.delete.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err +// NewSizeServiceClient constructs a client for the metalstack.admin.v2.SizeService service. +// Multiple service clients may share a single connect.Client. +func NewSizeServiceClient(client *connect.Client) SizeServiceClient { + return &sizeServiceClient{client: client} } // SizeServiceHandler is an implementation of the metalstack.admin.v2.SizeService service. @@ -127,56 +82,94 @@ type SizeServiceHandler interface { Delete(context.Context, *v2.SizeServiceDeleteRequest) (*v2.SizeServiceDeleteResponse, error) } -// NewSizeServiceHandler 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 NewSizeServiceHandler(svc SizeServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) { - sizeServiceMethods := v2.File_metalstack_admin_v2_size_proto.Services().ByName("SizeService").Methods() - sizeServiceCreateHandler := connect.NewUnaryHandlerSimple( - SizeServiceCreateProcedure, - svc.Create, - connect.WithSchema(sizeServiceMethods.ByName("Create")), - connect.WithHandlerOptions(opts...), +// RegisterSizeServiceHandler registers svc as the metalstack.admin.v2.SizeService implementation on +// server. +func RegisterSizeServiceHandler(server *connect.Server, svc SizeServiceHandler) { + adapter := sizeServiceHandler{svc: svc} + server.Register( + connect.Method{Spec: sizeServiceCreateSpec(), Handler: adapter.create}, + connect.Method{Spec: sizeServiceUpdateSpec(), Handler: adapter.update}, + connect.Method{Spec: sizeServiceDeleteSpec(), Handler: adapter.delete}, ) - sizeServiceUpdateHandler := connect.NewUnaryHandlerSimple( - SizeServiceUpdateProcedure, - svc.Update, - connect.WithSchema(sizeServiceMethods.ByName("Update")), - connect.WithHandlerOptions(opts...), - ) - sizeServiceDeleteHandler := connect.NewUnaryHandlerSimple( - SizeServiceDeleteProcedure, - svc.Delete, - connect.WithSchema(sizeServiceMethods.ByName("Delete")), - connect.WithHandlerOptions(opts...), - ) - return "/metalstack.admin.v2.SizeService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - switch r.URL.Path { - case SizeServiceCreateProcedure: - sizeServiceCreateHandler.ServeHTTP(w, r) - case SizeServiceUpdateProcedure: - sizeServiceUpdateHandler.ServeHTTP(w, r) - case SizeServiceDeleteProcedure: - sizeServiceDeleteHandler.ServeHTTP(w, r) - default: - http.NotFound(w, r) - } - }) } // UnimplementedSizeServiceHandler returns CodeUnimplemented from all methods. type UnimplementedSizeServiceHandler struct{} func (UnimplementedSizeServiceHandler) Create(context.Context, *v2.SizeServiceCreateRequest) (*v2.SizeServiceCreateResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.SizeService.Create is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.admin.v2.SizeService.Create is not implemented") } func (UnimplementedSizeServiceHandler) Update(context.Context, *v2.SizeServiceUpdateRequest) (*v2.SizeServiceUpdateResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.SizeService.Update is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.admin.v2.SizeService.Update is not implemented") } func (UnimplementedSizeServiceHandler) Delete(context.Context, *v2.SizeServiceDeleteRequest) (*v2.SizeServiceDeleteResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.SizeService.Delete is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.admin.v2.SizeService.Delete is not implemented") +} + +type sizeServiceClient struct { + client *connect.Client +} + +func (c *sizeServiceClient) Create(ctx context.Context, req *v2.SizeServiceCreateRequest) (*v2.SizeServiceCreateResponse, error) { + var res v2.SizeServiceCreateResponse + if err := c.client.CallUnary(ctx, sizeServiceCreateSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *sizeServiceClient) Update(ctx context.Context, req *v2.SizeServiceUpdateRequest) (*v2.SizeServiceUpdateResponse, error) { + var res v2.SizeServiceUpdateResponse + if err := c.client.CallUnary(ctx, sizeServiceUpdateSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *sizeServiceClient) Delete(ctx context.Context, req *v2.SizeServiceDeleteRequest) (*v2.SizeServiceDeleteResponse, error) { + var res v2.SizeServiceDeleteResponse + if err := c.client.CallUnary(ctx, sizeServiceDeleteSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +type sizeServiceHandler struct{ svc SizeServiceHandler } + +func (h sizeServiceHandler) create(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.SizeServiceCreateRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Create(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) +} + +func (h sizeServiceHandler) update(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.SizeServiceUpdateRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Update(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) +} + +func (h sizeServiceHandler) delete(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.SizeServiceDeleteRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Delete(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } diff --git a/go/metalstack/admin/v2/adminv2connect/size_imageconstraint.connect.go b/go/metalstack/admin/v2/adminv2connect/size_imageconstraint.connect.go index 29b12288..734ae85a 100644 --- a/go/metalstack/admin/v2/adminv2connect/size_imageconstraint.connect.go +++ b/go/metalstack/admin/v2/adminv2connect/size_imageconstraint.connect.go @@ -5,52 +5,81 @@ package adminv2connect import ( - connect "connectrpc.com/connect" + connect "connectrpc.com/connect/v2" context "context" - errors "errors" v2 "github.com/metal-stack/api/go/metalstack/admin/v2" - http "net/http" - strings "strings" + sync "sync" ) -// 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 ( // SizeImageConstraintServiceName is the fully-qualified name of the SizeImageConstraintService // service. SizeImageConstraintServiceName = "metalstack.admin.v2.SizeImageConstraintService" ) -// 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. +// These constants are the procedure 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 ( - // SizeImageConstraintServiceCreateProcedure is the fully-qualified name of the + // SizeImageConstraintServiceCreateProcedure is the procedure name of the // SizeImageConstraintService's Create RPC. SizeImageConstraintServiceCreateProcedure = "/metalstack.admin.v2.SizeImageConstraintService/Create" - // SizeImageConstraintServiceUpdateProcedure is the fully-qualified name of the + // SizeImageConstraintServiceUpdateProcedure is the procedure name of the // SizeImageConstraintService's Update RPC. SizeImageConstraintServiceUpdateProcedure = "/metalstack.admin.v2.SizeImageConstraintService/Update" - // SizeImageConstraintServiceDeleteProcedure is the fully-qualified name of the + // SizeImageConstraintServiceDeleteProcedure is the procedure name of the // SizeImageConstraintService's Delete RPC. SizeImageConstraintServiceDeleteProcedure = "/metalstack.admin.v2.SizeImageConstraintService/Delete" - // SizeImageConstraintServiceGetProcedure is the fully-qualified name of the - // SizeImageConstraintService's Get RPC. + // SizeImageConstraintServiceGetProcedure is the procedure name of the SizeImageConstraintService's + // Get RPC. SizeImageConstraintServiceGetProcedure = "/metalstack.admin.v2.SizeImageConstraintService/Get" - // SizeImageConstraintServiceListProcedure is the fully-qualified name of the - // SizeImageConstraintService's List RPC. + // SizeImageConstraintServiceListProcedure is the procedure name of the SizeImageConstraintService's + // List RPC. SizeImageConstraintServiceListProcedure = "/metalstack.admin.v2.SizeImageConstraintService/List" ) +var ( + sizeImageConstraintServiceCreateSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_admin_v2_size_imageconstraint_proto.Services().ByName("SizeImageConstraintService").Methods().ByName("Create"), + Procedure: SizeImageConstraintServiceCreateProcedure, + } + }) + sizeImageConstraintServiceUpdateSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_admin_v2_size_imageconstraint_proto.Services().ByName("SizeImageConstraintService").Methods().ByName("Update"), + Procedure: SizeImageConstraintServiceUpdateProcedure, + } + }) + sizeImageConstraintServiceDeleteSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_admin_v2_size_imageconstraint_proto.Services().ByName("SizeImageConstraintService").Methods().ByName("Delete"), + Procedure: SizeImageConstraintServiceDeleteProcedure, + } + }) + sizeImageConstraintServiceGetSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_admin_v2_size_imageconstraint_proto.Services().ByName("SizeImageConstraintService").Methods().ByName("Get"), + Procedure: SizeImageConstraintServiceGetProcedure, + } + }) + sizeImageConstraintServiceListSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_admin_v2_size_imageconstraint_proto.Services().ByName("SizeImageConstraintService").Methods().ByName("List"), + Procedure: SizeImageConstraintServiceListProcedure, + } + }) +) + // SizeImageConstraintServiceClient is a client for the // metalstack.admin.v2.SizeImageConstraintService service. type SizeImageConstraintServiceClient interface { @@ -67,102 +96,10 @@ type SizeImageConstraintServiceClient interface { } // NewSizeImageConstraintServiceClient constructs a client for the -// metalstack.admin.v2.SizeImageConstraintService 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 NewSizeImageConstraintServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) SizeImageConstraintServiceClient { - baseURL = strings.TrimRight(baseURL, "/") - sizeImageConstraintServiceMethods := v2.File_metalstack_admin_v2_size_imageconstraint_proto.Services().ByName("SizeImageConstraintService").Methods() - return &sizeImageConstraintServiceClient{ - create: connect.NewClient[v2.SizeImageConstraintServiceCreateRequest, v2.SizeImageConstraintServiceCreateResponse]( - httpClient, - baseURL+SizeImageConstraintServiceCreateProcedure, - connect.WithSchema(sizeImageConstraintServiceMethods.ByName("Create")), - connect.WithClientOptions(opts...), - ), - update: connect.NewClient[v2.SizeImageConstraintServiceUpdateRequest, v2.SizeImageConstraintServiceUpdateResponse]( - httpClient, - baseURL+SizeImageConstraintServiceUpdateProcedure, - connect.WithSchema(sizeImageConstraintServiceMethods.ByName("Update")), - connect.WithClientOptions(opts...), - ), - delete: connect.NewClient[v2.SizeImageConstraintServiceDeleteRequest, v2.SizeImageConstraintServiceDeleteResponse]( - httpClient, - baseURL+SizeImageConstraintServiceDeleteProcedure, - connect.WithSchema(sizeImageConstraintServiceMethods.ByName("Delete")), - connect.WithClientOptions(opts...), - ), - get: connect.NewClient[v2.SizeImageConstraintServiceGetRequest, v2.SizeImageConstraintServiceGetResponse]( - httpClient, - baseURL+SizeImageConstraintServiceGetProcedure, - connect.WithSchema(sizeImageConstraintServiceMethods.ByName("Get")), - connect.WithClientOptions(opts...), - ), - list: connect.NewClient[v2.SizeImageConstraintServiceListRequest, v2.SizeImageConstraintServiceListResponse]( - httpClient, - baseURL+SizeImageConstraintServiceListProcedure, - connect.WithSchema(sizeImageConstraintServiceMethods.ByName("List")), - connect.WithClientOptions(opts...), - ), - } -} - -// sizeImageConstraintServiceClient implements SizeImageConstraintServiceClient. -type sizeImageConstraintServiceClient struct { - create *connect.Client[v2.SizeImageConstraintServiceCreateRequest, v2.SizeImageConstraintServiceCreateResponse] - update *connect.Client[v2.SizeImageConstraintServiceUpdateRequest, v2.SizeImageConstraintServiceUpdateResponse] - delete *connect.Client[v2.SizeImageConstraintServiceDeleteRequest, v2.SizeImageConstraintServiceDeleteResponse] - get *connect.Client[v2.SizeImageConstraintServiceGetRequest, v2.SizeImageConstraintServiceGetResponse] - list *connect.Client[v2.SizeImageConstraintServiceListRequest, v2.SizeImageConstraintServiceListResponse] -} - -// Create calls metalstack.admin.v2.SizeImageConstraintService.Create. -func (c *sizeImageConstraintServiceClient) Create(ctx context.Context, req *v2.SizeImageConstraintServiceCreateRequest) (*v2.SizeImageConstraintServiceCreateResponse, error) { - response, err := c.create.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err -} - -// Update calls metalstack.admin.v2.SizeImageConstraintService.Update. -func (c *sizeImageConstraintServiceClient) Update(ctx context.Context, req *v2.SizeImageConstraintServiceUpdateRequest) (*v2.SizeImageConstraintServiceUpdateResponse, error) { - response, err := c.update.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err -} - -// Delete calls metalstack.admin.v2.SizeImageConstraintService.Delete. -func (c *sizeImageConstraintServiceClient) Delete(ctx context.Context, req *v2.SizeImageConstraintServiceDeleteRequest) (*v2.SizeImageConstraintServiceDeleteResponse, error) { - response, err := c.delete.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err -} - -// Get calls metalstack.admin.v2.SizeImageConstraintService.Get. -func (c *sizeImageConstraintServiceClient) Get(ctx context.Context, req *v2.SizeImageConstraintServiceGetRequest) (*v2.SizeImageConstraintServiceGetResponse, error) { - response, err := c.get.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err -} - -// List calls metalstack.admin.v2.SizeImageConstraintService.List. -func (c *sizeImageConstraintServiceClient) List(ctx context.Context, req *v2.SizeImageConstraintServiceListRequest) (*v2.SizeImageConstraintServiceListResponse, error) { - response, err := c.list.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err +// metalstack.admin.v2.SizeImageConstraintService service. Multiple service clients may share a +// single connect.Client. +func NewSizeImageConstraintServiceClient(client *connect.Client) SizeImageConstraintServiceClient { + return &sizeImageConstraintServiceClient{client: client} } // SizeImageConstraintServiceHandler is an implementation of the @@ -180,80 +117,146 @@ type SizeImageConstraintServiceHandler interface { List(context.Context, *v2.SizeImageConstraintServiceListRequest) (*v2.SizeImageConstraintServiceListResponse, error) } -// NewSizeImageConstraintServiceHandler 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 NewSizeImageConstraintServiceHandler(svc SizeImageConstraintServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) { - sizeImageConstraintServiceMethods := v2.File_metalstack_admin_v2_size_imageconstraint_proto.Services().ByName("SizeImageConstraintService").Methods() - sizeImageConstraintServiceCreateHandler := connect.NewUnaryHandlerSimple( - SizeImageConstraintServiceCreateProcedure, - svc.Create, - connect.WithSchema(sizeImageConstraintServiceMethods.ByName("Create")), - connect.WithHandlerOptions(opts...), - ) - sizeImageConstraintServiceUpdateHandler := connect.NewUnaryHandlerSimple( - SizeImageConstraintServiceUpdateProcedure, - svc.Update, - connect.WithSchema(sizeImageConstraintServiceMethods.ByName("Update")), - connect.WithHandlerOptions(opts...), +// RegisterSizeImageConstraintServiceHandler registers svc as the +// metalstack.admin.v2.SizeImageConstraintService implementation on server. +func RegisterSizeImageConstraintServiceHandler(server *connect.Server, svc SizeImageConstraintServiceHandler) { + adapter := sizeImageConstraintServiceHandler{svc: svc} + server.Register( + connect.Method{Spec: sizeImageConstraintServiceCreateSpec(), Handler: adapter.create}, + connect.Method{Spec: sizeImageConstraintServiceUpdateSpec(), Handler: adapter.update}, + connect.Method{Spec: sizeImageConstraintServiceDeleteSpec(), Handler: adapter.delete}, + connect.Method{Spec: sizeImageConstraintServiceGetSpec(), Handler: adapter.get}, + connect.Method{Spec: sizeImageConstraintServiceListSpec(), Handler: adapter.list}, ) - sizeImageConstraintServiceDeleteHandler := connect.NewUnaryHandlerSimple( - SizeImageConstraintServiceDeleteProcedure, - svc.Delete, - connect.WithSchema(sizeImageConstraintServiceMethods.ByName("Delete")), - connect.WithHandlerOptions(opts...), - ) - sizeImageConstraintServiceGetHandler := connect.NewUnaryHandlerSimple( - SizeImageConstraintServiceGetProcedure, - svc.Get, - connect.WithSchema(sizeImageConstraintServiceMethods.ByName("Get")), - connect.WithHandlerOptions(opts...), - ) - sizeImageConstraintServiceListHandler := connect.NewUnaryHandlerSimple( - SizeImageConstraintServiceListProcedure, - svc.List, - connect.WithSchema(sizeImageConstraintServiceMethods.ByName("List")), - connect.WithHandlerOptions(opts...), - ) - return "/metalstack.admin.v2.SizeImageConstraintService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - switch r.URL.Path { - case SizeImageConstraintServiceCreateProcedure: - sizeImageConstraintServiceCreateHandler.ServeHTTP(w, r) - case SizeImageConstraintServiceUpdateProcedure: - sizeImageConstraintServiceUpdateHandler.ServeHTTP(w, r) - case SizeImageConstraintServiceDeleteProcedure: - sizeImageConstraintServiceDeleteHandler.ServeHTTP(w, r) - case SizeImageConstraintServiceGetProcedure: - sizeImageConstraintServiceGetHandler.ServeHTTP(w, r) - case SizeImageConstraintServiceListProcedure: - sizeImageConstraintServiceListHandler.ServeHTTP(w, r) - default: - http.NotFound(w, r) - } - }) } // UnimplementedSizeImageConstraintServiceHandler returns CodeUnimplemented from all methods. type UnimplementedSizeImageConstraintServiceHandler struct{} func (UnimplementedSizeImageConstraintServiceHandler) Create(context.Context, *v2.SizeImageConstraintServiceCreateRequest) (*v2.SizeImageConstraintServiceCreateResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.SizeImageConstraintService.Create is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.admin.v2.SizeImageConstraintService.Create is not implemented") } func (UnimplementedSizeImageConstraintServiceHandler) Update(context.Context, *v2.SizeImageConstraintServiceUpdateRequest) (*v2.SizeImageConstraintServiceUpdateResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.SizeImageConstraintService.Update is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.admin.v2.SizeImageConstraintService.Update is not implemented") } func (UnimplementedSizeImageConstraintServiceHandler) Delete(context.Context, *v2.SizeImageConstraintServiceDeleteRequest) (*v2.SizeImageConstraintServiceDeleteResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.SizeImageConstraintService.Delete is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.admin.v2.SizeImageConstraintService.Delete is not implemented") } func (UnimplementedSizeImageConstraintServiceHandler) Get(context.Context, *v2.SizeImageConstraintServiceGetRequest) (*v2.SizeImageConstraintServiceGetResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.SizeImageConstraintService.Get is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.admin.v2.SizeImageConstraintService.Get is not implemented") } func (UnimplementedSizeImageConstraintServiceHandler) List(context.Context, *v2.SizeImageConstraintServiceListRequest) (*v2.SizeImageConstraintServiceListResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.SizeImageConstraintService.List is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.admin.v2.SizeImageConstraintService.List is not implemented") +} + +type sizeImageConstraintServiceClient struct { + client *connect.Client +} + +func (c *sizeImageConstraintServiceClient) Create(ctx context.Context, req *v2.SizeImageConstraintServiceCreateRequest) (*v2.SizeImageConstraintServiceCreateResponse, error) { + var res v2.SizeImageConstraintServiceCreateResponse + if err := c.client.CallUnary(ctx, sizeImageConstraintServiceCreateSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *sizeImageConstraintServiceClient) Update(ctx context.Context, req *v2.SizeImageConstraintServiceUpdateRequest) (*v2.SizeImageConstraintServiceUpdateResponse, error) { + var res v2.SizeImageConstraintServiceUpdateResponse + if err := c.client.CallUnary(ctx, sizeImageConstraintServiceUpdateSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *sizeImageConstraintServiceClient) Delete(ctx context.Context, req *v2.SizeImageConstraintServiceDeleteRequest) (*v2.SizeImageConstraintServiceDeleteResponse, error) { + var res v2.SizeImageConstraintServiceDeleteResponse + if err := c.client.CallUnary(ctx, sizeImageConstraintServiceDeleteSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *sizeImageConstraintServiceClient) Get(ctx context.Context, req *v2.SizeImageConstraintServiceGetRequest) (*v2.SizeImageConstraintServiceGetResponse, error) { + var res v2.SizeImageConstraintServiceGetResponse + if err := c.client.CallUnary(ctx, sizeImageConstraintServiceGetSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *sizeImageConstraintServiceClient) List(ctx context.Context, req *v2.SizeImageConstraintServiceListRequest) (*v2.SizeImageConstraintServiceListResponse, error) { + var res v2.SizeImageConstraintServiceListResponse + if err := c.client.CallUnary(ctx, sizeImageConstraintServiceListSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +type sizeImageConstraintServiceHandler struct { + svc SizeImageConstraintServiceHandler +} + +func (h sizeImageConstraintServiceHandler) create(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.SizeImageConstraintServiceCreateRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Create(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) +} + +func (h sizeImageConstraintServiceHandler) update(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.SizeImageConstraintServiceUpdateRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Update(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) +} + +func (h sizeImageConstraintServiceHandler) delete(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.SizeImageConstraintServiceDeleteRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Delete(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) +} + +func (h sizeImageConstraintServiceHandler) get(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.SizeImageConstraintServiceGetRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Get(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) +} + +func (h sizeImageConstraintServiceHandler) list(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.SizeImageConstraintServiceListRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.List(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } diff --git a/go/metalstack/admin/v2/adminv2connect/size_reservation.connect.go b/go/metalstack/admin/v2/adminv2connect/size_reservation.connect.go index 823544c5..20fd7650 100644 --- a/go/metalstack/admin/v2/adminv2connect/size_reservation.connect.go +++ b/go/metalstack/admin/v2/adminv2connect/size_reservation.connect.go @@ -5,48 +5,70 @@ package adminv2connect import ( - connect "connectrpc.com/connect" + connect "connectrpc.com/connect/v2" context "context" - errors "errors" v2 "github.com/metal-stack/api/go/metalstack/admin/v2" - http "net/http" - strings "strings" + sync "sync" ) -// 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 ( // SizeReservationServiceName is the fully-qualified name of the SizeReservationService service. SizeReservationServiceName = "metalstack.admin.v2.SizeReservationService" ) -// 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. +// These constants are the procedure 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 ( - // SizeReservationServiceCreateProcedure is the fully-qualified name of the SizeReservationService's + // SizeReservationServiceCreateProcedure is the procedure name of the SizeReservationService's // Create RPC. SizeReservationServiceCreateProcedure = "/metalstack.admin.v2.SizeReservationService/Create" - // SizeReservationServiceUpdateProcedure is the fully-qualified name of the SizeReservationService's + // SizeReservationServiceUpdateProcedure is the procedure name of the SizeReservationService's // Update RPC. SizeReservationServiceUpdateProcedure = "/metalstack.admin.v2.SizeReservationService/Update" - // SizeReservationServiceDeleteProcedure is the fully-qualified name of the SizeReservationService's + // SizeReservationServiceDeleteProcedure is the procedure name of the SizeReservationService's // Delete RPC. SizeReservationServiceDeleteProcedure = "/metalstack.admin.v2.SizeReservationService/Delete" - // SizeReservationServiceListProcedure is the fully-qualified name of the SizeReservationService's - // List RPC. + // SizeReservationServiceListProcedure is the procedure name of the SizeReservationService's List + // RPC. SizeReservationServiceListProcedure = "/metalstack.admin.v2.SizeReservationService/List" ) +var ( + sizeReservationServiceCreateSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_admin_v2_size_reservation_proto.Services().ByName("SizeReservationService").Methods().ByName("Create"), + Procedure: SizeReservationServiceCreateProcedure, + } + }) + sizeReservationServiceUpdateSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_admin_v2_size_reservation_proto.Services().ByName("SizeReservationService").Methods().ByName("Update"), + Procedure: SizeReservationServiceUpdateProcedure, + } + }) + sizeReservationServiceDeleteSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_admin_v2_size_reservation_proto.Services().ByName("SizeReservationService").Methods().ByName("Delete"), + Procedure: SizeReservationServiceDeleteProcedure, + } + }) + sizeReservationServiceListSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_admin_v2_size_reservation_proto.Services().ByName("SizeReservationService").Methods().ByName("List"), + Procedure: SizeReservationServiceListProcedure, + } + }) +) + // SizeReservationServiceClient is a client for the metalstack.admin.v2.SizeReservationService // service. type SizeReservationServiceClient interface { @@ -61,85 +83,10 @@ type SizeReservationServiceClient interface { } // NewSizeReservationServiceClient constructs a client for the -// metalstack.admin.v2.SizeReservationService 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 NewSizeReservationServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) SizeReservationServiceClient { - baseURL = strings.TrimRight(baseURL, "/") - sizeReservationServiceMethods := v2.File_metalstack_admin_v2_size_reservation_proto.Services().ByName("SizeReservationService").Methods() - return &sizeReservationServiceClient{ - create: connect.NewClient[v2.SizeReservationServiceCreateRequest, v2.SizeReservationServiceCreateResponse]( - httpClient, - baseURL+SizeReservationServiceCreateProcedure, - connect.WithSchema(sizeReservationServiceMethods.ByName("Create")), - connect.WithClientOptions(opts...), - ), - update: connect.NewClient[v2.SizeReservationServiceUpdateRequest, v2.SizeReservationServiceUpdateResponse]( - httpClient, - baseURL+SizeReservationServiceUpdateProcedure, - connect.WithSchema(sizeReservationServiceMethods.ByName("Update")), - connect.WithClientOptions(opts...), - ), - delete: connect.NewClient[v2.SizeReservationServiceDeleteRequest, v2.SizeReservationServiceDeleteResponse]( - httpClient, - baseURL+SizeReservationServiceDeleteProcedure, - connect.WithSchema(sizeReservationServiceMethods.ByName("Delete")), - connect.WithClientOptions(opts...), - ), - list: connect.NewClient[v2.SizeReservationServiceListRequest, v2.SizeReservationServiceListResponse]( - httpClient, - baseURL+SizeReservationServiceListProcedure, - connect.WithSchema(sizeReservationServiceMethods.ByName("List")), - connect.WithClientOptions(opts...), - ), - } -} - -// sizeReservationServiceClient implements SizeReservationServiceClient. -type sizeReservationServiceClient struct { - create *connect.Client[v2.SizeReservationServiceCreateRequest, v2.SizeReservationServiceCreateResponse] - update *connect.Client[v2.SizeReservationServiceUpdateRequest, v2.SizeReservationServiceUpdateResponse] - delete *connect.Client[v2.SizeReservationServiceDeleteRequest, v2.SizeReservationServiceDeleteResponse] - list *connect.Client[v2.SizeReservationServiceListRequest, v2.SizeReservationServiceListResponse] -} - -// Create calls metalstack.admin.v2.SizeReservationService.Create. -func (c *sizeReservationServiceClient) Create(ctx context.Context, req *v2.SizeReservationServiceCreateRequest) (*v2.SizeReservationServiceCreateResponse, error) { - response, err := c.create.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err -} - -// Update calls metalstack.admin.v2.SizeReservationService.Update. -func (c *sizeReservationServiceClient) Update(ctx context.Context, req *v2.SizeReservationServiceUpdateRequest) (*v2.SizeReservationServiceUpdateResponse, error) { - response, err := c.update.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err -} - -// Delete calls metalstack.admin.v2.SizeReservationService.Delete. -func (c *sizeReservationServiceClient) Delete(ctx context.Context, req *v2.SizeReservationServiceDeleteRequest) (*v2.SizeReservationServiceDeleteResponse, error) { - response, err := c.delete.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err -} - -// List calls metalstack.admin.v2.SizeReservationService.List. -func (c *sizeReservationServiceClient) List(ctx context.Context, req *v2.SizeReservationServiceListRequest) (*v2.SizeReservationServiceListResponse, error) { - response, err := c.list.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err +// metalstack.admin.v2.SizeReservationService service. Multiple service clients may share a single +// connect.Client. +func NewSizeReservationServiceClient(client *connect.Client) SizeReservationServiceClient { + return &sizeReservationServiceClient{client: client} } // SizeReservationServiceHandler is an implementation of the @@ -155,68 +102,119 @@ type SizeReservationServiceHandler interface { List(context.Context, *v2.SizeReservationServiceListRequest) (*v2.SizeReservationServiceListResponse, error) } -// NewSizeReservationServiceHandler 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 NewSizeReservationServiceHandler(svc SizeReservationServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) { - sizeReservationServiceMethods := v2.File_metalstack_admin_v2_size_reservation_proto.Services().ByName("SizeReservationService").Methods() - sizeReservationServiceCreateHandler := connect.NewUnaryHandlerSimple( - SizeReservationServiceCreateProcedure, - svc.Create, - connect.WithSchema(sizeReservationServiceMethods.ByName("Create")), - connect.WithHandlerOptions(opts...), +// RegisterSizeReservationServiceHandler registers svc as the +// metalstack.admin.v2.SizeReservationService implementation on server. +func RegisterSizeReservationServiceHandler(server *connect.Server, svc SizeReservationServiceHandler) { + adapter := sizeReservationServiceHandler{svc: svc} + server.Register( + connect.Method{Spec: sizeReservationServiceCreateSpec(), Handler: adapter.create}, + connect.Method{Spec: sizeReservationServiceUpdateSpec(), Handler: adapter.update}, + connect.Method{Spec: sizeReservationServiceDeleteSpec(), Handler: adapter.delete}, + connect.Method{Spec: sizeReservationServiceListSpec(), Handler: adapter.list}, ) - sizeReservationServiceUpdateHandler := connect.NewUnaryHandlerSimple( - SizeReservationServiceUpdateProcedure, - svc.Update, - connect.WithSchema(sizeReservationServiceMethods.ByName("Update")), - connect.WithHandlerOptions(opts...), - ) - sizeReservationServiceDeleteHandler := connect.NewUnaryHandlerSimple( - SizeReservationServiceDeleteProcedure, - svc.Delete, - connect.WithSchema(sizeReservationServiceMethods.ByName("Delete")), - connect.WithHandlerOptions(opts...), - ) - sizeReservationServiceListHandler := connect.NewUnaryHandlerSimple( - SizeReservationServiceListProcedure, - svc.List, - connect.WithSchema(sizeReservationServiceMethods.ByName("List")), - connect.WithHandlerOptions(opts...), - ) - return "/metalstack.admin.v2.SizeReservationService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - switch r.URL.Path { - case SizeReservationServiceCreateProcedure: - sizeReservationServiceCreateHandler.ServeHTTP(w, r) - case SizeReservationServiceUpdateProcedure: - sizeReservationServiceUpdateHandler.ServeHTTP(w, r) - case SizeReservationServiceDeleteProcedure: - sizeReservationServiceDeleteHandler.ServeHTTP(w, r) - case SizeReservationServiceListProcedure: - sizeReservationServiceListHandler.ServeHTTP(w, r) - default: - http.NotFound(w, r) - } - }) } // UnimplementedSizeReservationServiceHandler returns CodeUnimplemented from all methods. type UnimplementedSizeReservationServiceHandler struct{} func (UnimplementedSizeReservationServiceHandler) Create(context.Context, *v2.SizeReservationServiceCreateRequest) (*v2.SizeReservationServiceCreateResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.SizeReservationService.Create is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.admin.v2.SizeReservationService.Create is not implemented") } func (UnimplementedSizeReservationServiceHandler) Update(context.Context, *v2.SizeReservationServiceUpdateRequest) (*v2.SizeReservationServiceUpdateResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.SizeReservationService.Update is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.admin.v2.SizeReservationService.Update is not implemented") } func (UnimplementedSizeReservationServiceHandler) Delete(context.Context, *v2.SizeReservationServiceDeleteRequest) (*v2.SizeReservationServiceDeleteResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.SizeReservationService.Delete is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.admin.v2.SizeReservationService.Delete is not implemented") } func (UnimplementedSizeReservationServiceHandler) List(context.Context, *v2.SizeReservationServiceListRequest) (*v2.SizeReservationServiceListResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.SizeReservationService.List is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.admin.v2.SizeReservationService.List is not implemented") +} + +type sizeReservationServiceClient struct { + client *connect.Client +} + +func (c *sizeReservationServiceClient) Create(ctx context.Context, req *v2.SizeReservationServiceCreateRequest) (*v2.SizeReservationServiceCreateResponse, error) { + var res v2.SizeReservationServiceCreateResponse + if err := c.client.CallUnary(ctx, sizeReservationServiceCreateSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *sizeReservationServiceClient) Update(ctx context.Context, req *v2.SizeReservationServiceUpdateRequest) (*v2.SizeReservationServiceUpdateResponse, error) { + var res v2.SizeReservationServiceUpdateResponse + if err := c.client.CallUnary(ctx, sizeReservationServiceUpdateSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *sizeReservationServiceClient) Delete(ctx context.Context, req *v2.SizeReservationServiceDeleteRequest) (*v2.SizeReservationServiceDeleteResponse, error) { + var res v2.SizeReservationServiceDeleteResponse + if err := c.client.CallUnary(ctx, sizeReservationServiceDeleteSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *sizeReservationServiceClient) List(ctx context.Context, req *v2.SizeReservationServiceListRequest) (*v2.SizeReservationServiceListResponse, error) { + var res v2.SizeReservationServiceListResponse + if err := c.client.CallUnary(ctx, sizeReservationServiceListSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +type sizeReservationServiceHandler struct{ svc SizeReservationServiceHandler } + +func (h sizeReservationServiceHandler) create(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.SizeReservationServiceCreateRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Create(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) +} + +func (h sizeReservationServiceHandler) update(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.SizeReservationServiceUpdateRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Update(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) +} + +func (h sizeReservationServiceHandler) delete(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.SizeReservationServiceDeleteRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Delete(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) +} + +func (h sizeReservationServiceHandler) list(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.SizeReservationServiceListRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.List(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } diff --git a/go/metalstack/admin/v2/adminv2connect/switch.connect.go b/go/metalstack/admin/v2/adminv2connect/switch.connect.go index a44c2320..a6c0e1f6 100644 --- a/go/metalstack/admin/v2/adminv2connect/switch.connect.go +++ b/go/metalstack/admin/v2/adminv2connect/switch.connect.go @@ -5,51 +5,94 @@ package adminv2connect import ( - connect "connectrpc.com/connect" + connect "connectrpc.com/connect/v2" context "context" - errors "errors" v2 "github.com/metal-stack/api/go/metalstack/admin/v2" - http "net/http" - strings "strings" + sync "sync" ) -// 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 ( // SwitchServiceName is the fully-qualified name of the SwitchService service. SwitchServiceName = "metalstack.admin.v2.SwitchService" ) -// 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. +// These constants are the procedure 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 ( - // SwitchServiceGetProcedure is the fully-qualified name of the SwitchService's Get RPC. + // SwitchServiceGetProcedure is the procedure name of the SwitchService's Get RPC. SwitchServiceGetProcedure = "/metalstack.admin.v2.SwitchService/Get" - // SwitchServiceListProcedure is the fully-qualified name of the SwitchService's List RPC. + // SwitchServiceListProcedure is the procedure name of the SwitchService's List RPC. SwitchServiceListProcedure = "/metalstack.admin.v2.SwitchService/List" - // SwitchServiceUpdateProcedure is the fully-qualified name of the SwitchService's Update RPC. + // SwitchServiceUpdateProcedure is the procedure name of the SwitchService's Update RPC. SwitchServiceUpdateProcedure = "/metalstack.admin.v2.SwitchService/Update" - // SwitchServiceDeleteProcedure is the fully-qualified name of the SwitchService's Delete RPC. + // SwitchServiceDeleteProcedure is the procedure name of the SwitchService's Delete RPC. SwitchServiceDeleteProcedure = "/metalstack.admin.v2.SwitchService/Delete" - // SwitchServiceMigrateProcedure is the fully-qualified name of the SwitchService's Migrate RPC. + // SwitchServiceMigrateProcedure is the procedure name of the SwitchService's Migrate RPC. SwitchServiceMigrateProcedure = "/metalstack.admin.v2.SwitchService/Migrate" - // SwitchServicePortProcedure is the fully-qualified name of the SwitchService's Port RPC. + // SwitchServicePortProcedure is the procedure name of the SwitchService's Port RPC. SwitchServicePortProcedure = "/metalstack.admin.v2.SwitchService/Port" - // SwitchServiceConnectedMachinesProcedure is the fully-qualified name of the SwitchService's + // SwitchServiceConnectedMachinesProcedure is the procedure name of the SwitchService's // ConnectedMachines RPC. SwitchServiceConnectedMachinesProcedure = "/metalstack.admin.v2.SwitchService/ConnectedMachines" ) +var ( + switchServiceGetSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_admin_v2_switch_proto.Services().ByName("SwitchService").Methods().ByName("Get"), + Procedure: SwitchServiceGetProcedure, + } + }) + switchServiceListSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_admin_v2_switch_proto.Services().ByName("SwitchService").Methods().ByName("List"), + Procedure: SwitchServiceListProcedure, + } + }) + switchServiceUpdateSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_admin_v2_switch_proto.Services().ByName("SwitchService").Methods().ByName("Update"), + Procedure: SwitchServiceUpdateProcedure, + } + }) + switchServiceDeleteSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_admin_v2_switch_proto.Services().ByName("SwitchService").Methods().ByName("Delete"), + Procedure: SwitchServiceDeleteProcedure, + } + }) + switchServiceMigrateSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_admin_v2_switch_proto.Services().ByName("SwitchService").Methods().ByName("Migrate"), + Procedure: SwitchServiceMigrateProcedure, + } + }) + switchServicePortSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_admin_v2_switch_proto.Services().ByName("SwitchService").Methods().ByName("Port"), + Procedure: SwitchServicePortProcedure, + } + }) + switchServiceConnectedMachinesSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_admin_v2_switch_proto.Services().ByName("SwitchService").Methods().ByName("ConnectedMachines"), + Procedure: SwitchServiceConnectedMachinesProcedure, + } + }) +) + // SwitchServiceClient is a client for the metalstack.admin.v2.SwitchService service. type SwitchServiceClient interface { // Returns the switch with the specified ID. @@ -68,252 +111,218 @@ type SwitchServiceClient interface { ConnectedMachines(context.Context, *v2.SwitchServiceConnectedMachinesRequest) (*v2.SwitchServiceConnectedMachinesResponse, error) } -// NewSwitchServiceClient constructs a client for the metalstack.admin.v2.SwitchService 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 NewSwitchServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) SwitchServiceClient { - baseURL = strings.TrimRight(baseURL, "/") - switchServiceMethods := v2.File_metalstack_admin_v2_switch_proto.Services().ByName("SwitchService").Methods() - return &switchServiceClient{ - get: connect.NewClient[v2.SwitchServiceGetRequest, v2.SwitchServiceGetResponse]( - httpClient, - baseURL+SwitchServiceGetProcedure, - connect.WithSchema(switchServiceMethods.ByName("Get")), - connect.WithClientOptions(opts...), - ), - list: connect.NewClient[v2.SwitchServiceListRequest, v2.SwitchServiceListResponse]( - httpClient, - baseURL+SwitchServiceListProcedure, - connect.WithSchema(switchServiceMethods.ByName("List")), - connect.WithClientOptions(opts...), - ), - update: connect.NewClient[v2.SwitchServiceUpdateRequest, v2.SwitchServiceUpdateResponse]( - httpClient, - baseURL+SwitchServiceUpdateProcedure, - connect.WithSchema(switchServiceMethods.ByName("Update")), - connect.WithClientOptions(opts...), - ), - delete: connect.NewClient[v2.SwitchServiceDeleteRequest, v2.SwitchServiceDeleteResponse]( - httpClient, - baseURL+SwitchServiceDeleteProcedure, - connect.WithSchema(switchServiceMethods.ByName("Delete")), - connect.WithClientOptions(opts...), - ), - migrate: connect.NewClient[v2.SwitchServiceMigrateRequest, v2.SwitchServiceMigrateResponse]( - httpClient, - baseURL+SwitchServiceMigrateProcedure, - connect.WithSchema(switchServiceMethods.ByName("Migrate")), - connect.WithClientOptions(opts...), - ), - port: connect.NewClient[v2.SwitchServicePortRequest, v2.SwitchServicePortResponse]( - httpClient, - baseURL+SwitchServicePortProcedure, - connect.WithSchema(switchServiceMethods.ByName("Port")), - connect.WithClientOptions(opts...), - ), - connectedMachines: connect.NewClient[v2.SwitchServiceConnectedMachinesRequest, v2.SwitchServiceConnectedMachinesResponse]( - httpClient, - baseURL+SwitchServiceConnectedMachinesProcedure, - connect.WithSchema(switchServiceMethods.ByName("ConnectedMachines")), - connect.WithClientOptions(opts...), - ), - } +// NewSwitchServiceClient constructs a client for the metalstack.admin.v2.SwitchService service. +// Multiple service clients may share a single connect.Client. +func NewSwitchServiceClient(client *connect.Client) SwitchServiceClient { + return &switchServiceClient{client: client} +} + +// SwitchServiceHandler is an implementation of the metalstack.admin.v2.SwitchService service. +type SwitchServiceHandler interface { + // Returns the switch with the specified ID. + Get(context.Context, *v2.SwitchServiceGetRequest) (*v2.SwitchServiceGetResponse, error) + // Returns the list of switches. + List(context.Context, *v2.SwitchServiceListRequest) (*v2.SwitchServiceListResponse, error) + // Updates a switch. + Update(context.Context, *v2.SwitchServiceUpdateRequest) (*v2.SwitchServiceUpdateResponse, error) + // Deletes a switch. + Delete(context.Context, *v2.SwitchServiceDeleteRequest) (*v2.SwitchServiceDeleteResponse, error) + // Migrates a switch. + Migrate(context.Context, *v2.SwitchServiceMigrateRequest) (*v2.SwitchServiceMigrateResponse, error) + // Sets the port status of a switch port. + Port(context.Context, *v2.SwitchServicePortRequest) (*v2.SwitchServicePortResponse, error) + // Returns all switches with their machine connections. + ConnectedMachines(context.Context, *v2.SwitchServiceConnectedMachinesRequest) (*v2.SwitchServiceConnectedMachinesResponse, error) +} + +// RegisterSwitchServiceHandler registers svc as the metalstack.admin.v2.SwitchService +// implementation on server. +func RegisterSwitchServiceHandler(server *connect.Server, svc SwitchServiceHandler) { + adapter := switchServiceHandler{svc: svc} + server.Register( + connect.Method{Spec: switchServiceGetSpec(), Handler: adapter.get}, + connect.Method{Spec: switchServiceListSpec(), Handler: adapter.list}, + connect.Method{Spec: switchServiceUpdateSpec(), Handler: adapter.update}, + connect.Method{Spec: switchServiceDeleteSpec(), Handler: adapter.delete}, + connect.Method{Spec: switchServiceMigrateSpec(), Handler: adapter.migrate}, + connect.Method{Spec: switchServicePortSpec(), Handler: adapter.port}, + connect.Method{Spec: switchServiceConnectedMachinesSpec(), Handler: adapter.connectedMachines}, + ) +} + +// UnimplementedSwitchServiceHandler returns CodeUnimplemented from all methods. +type UnimplementedSwitchServiceHandler struct{} + +func (UnimplementedSwitchServiceHandler) Get(context.Context, *v2.SwitchServiceGetRequest) (*v2.SwitchServiceGetResponse, error) { + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.admin.v2.SwitchService.Get is not implemented") +} + +func (UnimplementedSwitchServiceHandler) List(context.Context, *v2.SwitchServiceListRequest) (*v2.SwitchServiceListResponse, error) { + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.admin.v2.SwitchService.List is not implemented") +} + +func (UnimplementedSwitchServiceHandler) Update(context.Context, *v2.SwitchServiceUpdateRequest) (*v2.SwitchServiceUpdateResponse, error) { + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.admin.v2.SwitchService.Update is not implemented") +} + +func (UnimplementedSwitchServiceHandler) Delete(context.Context, *v2.SwitchServiceDeleteRequest) (*v2.SwitchServiceDeleteResponse, error) { + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.admin.v2.SwitchService.Delete is not implemented") +} + +func (UnimplementedSwitchServiceHandler) Migrate(context.Context, *v2.SwitchServiceMigrateRequest) (*v2.SwitchServiceMigrateResponse, error) { + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.admin.v2.SwitchService.Migrate is not implemented") +} + +func (UnimplementedSwitchServiceHandler) Port(context.Context, *v2.SwitchServicePortRequest) (*v2.SwitchServicePortResponse, error) { + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.admin.v2.SwitchService.Port is not implemented") +} + +func (UnimplementedSwitchServiceHandler) ConnectedMachines(context.Context, *v2.SwitchServiceConnectedMachinesRequest) (*v2.SwitchServiceConnectedMachinesResponse, error) { + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.admin.v2.SwitchService.ConnectedMachines is not implemented") } -// switchServiceClient implements SwitchServiceClient. type switchServiceClient struct { - get *connect.Client[v2.SwitchServiceGetRequest, v2.SwitchServiceGetResponse] - list *connect.Client[v2.SwitchServiceListRequest, v2.SwitchServiceListResponse] - update *connect.Client[v2.SwitchServiceUpdateRequest, v2.SwitchServiceUpdateResponse] - delete *connect.Client[v2.SwitchServiceDeleteRequest, v2.SwitchServiceDeleteResponse] - migrate *connect.Client[v2.SwitchServiceMigrateRequest, v2.SwitchServiceMigrateResponse] - port *connect.Client[v2.SwitchServicePortRequest, v2.SwitchServicePortResponse] - connectedMachines *connect.Client[v2.SwitchServiceConnectedMachinesRequest, v2.SwitchServiceConnectedMachinesResponse] + client *connect.Client } -// Get calls metalstack.admin.v2.SwitchService.Get. func (c *switchServiceClient) Get(ctx context.Context, req *v2.SwitchServiceGetRequest) (*v2.SwitchServiceGetResponse, error) { - response, err := c.get.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err + var res v2.SwitchServiceGetResponse + if err := c.client.CallUnary(ctx, switchServiceGetSpec(), req, &res); err != nil { + return nil, err } - return nil, err + return &res, nil } -// List calls metalstack.admin.v2.SwitchService.List. func (c *switchServiceClient) List(ctx context.Context, req *v2.SwitchServiceListRequest) (*v2.SwitchServiceListResponse, error) { - response, err := c.list.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err + var res v2.SwitchServiceListResponse + if err := c.client.CallUnary(ctx, switchServiceListSpec(), req, &res); err != nil { + return nil, err } - return nil, err + return &res, nil } -// Update calls metalstack.admin.v2.SwitchService.Update. func (c *switchServiceClient) Update(ctx context.Context, req *v2.SwitchServiceUpdateRequest) (*v2.SwitchServiceUpdateResponse, error) { - response, err := c.update.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err + var res v2.SwitchServiceUpdateResponse + if err := c.client.CallUnary(ctx, switchServiceUpdateSpec(), req, &res); err != nil { + return nil, err } - return nil, err + return &res, nil } -// Delete calls metalstack.admin.v2.SwitchService.Delete. func (c *switchServiceClient) Delete(ctx context.Context, req *v2.SwitchServiceDeleteRequest) (*v2.SwitchServiceDeleteResponse, error) { - response, err := c.delete.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err + var res v2.SwitchServiceDeleteResponse + if err := c.client.CallUnary(ctx, switchServiceDeleteSpec(), req, &res); err != nil { + return nil, err } - return nil, err + return &res, nil } -// Migrate calls metalstack.admin.v2.SwitchService.Migrate. func (c *switchServiceClient) Migrate(ctx context.Context, req *v2.SwitchServiceMigrateRequest) (*v2.SwitchServiceMigrateResponse, error) { - response, err := c.migrate.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err + var res v2.SwitchServiceMigrateResponse + if err := c.client.CallUnary(ctx, switchServiceMigrateSpec(), req, &res); err != nil { + return nil, err } - return nil, err + return &res, nil } -// Port calls metalstack.admin.v2.SwitchService.Port. func (c *switchServiceClient) Port(ctx context.Context, req *v2.SwitchServicePortRequest) (*v2.SwitchServicePortResponse, error) { - response, err := c.port.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err + var res v2.SwitchServicePortResponse + if err := c.client.CallUnary(ctx, switchServicePortSpec(), req, &res); err != nil { + return nil, err } - return nil, err + return &res, nil } -// ConnectedMachines calls metalstack.admin.v2.SwitchService.ConnectedMachines. func (c *switchServiceClient) ConnectedMachines(ctx context.Context, req *v2.SwitchServiceConnectedMachinesRequest) (*v2.SwitchServiceConnectedMachinesResponse, error) { - response, err := c.connectedMachines.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err + var res v2.SwitchServiceConnectedMachinesResponse + if err := c.client.CallUnary(ctx, switchServiceConnectedMachinesSpec(), req, &res); err != nil { + return nil, err } - return nil, err -} - -// SwitchServiceHandler is an implementation of the metalstack.admin.v2.SwitchService service. -type SwitchServiceHandler interface { - // Returns the switch with the specified ID. - Get(context.Context, *v2.SwitchServiceGetRequest) (*v2.SwitchServiceGetResponse, error) - // Returns the list of switches. - List(context.Context, *v2.SwitchServiceListRequest) (*v2.SwitchServiceListResponse, error) - // Updates a switch. - Update(context.Context, *v2.SwitchServiceUpdateRequest) (*v2.SwitchServiceUpdateResponse, error) - // Deletes a switch. - Delete(context.Context, *v2.SwitchServiceDeleteRequest) (*v2.SwitchServiceDeleteResponse, error) - // Migrates a switch. - Migrate(context.Context, *v2.SwitchServiceMigrateRequest) (*v2.SwitchServiceMigrateResponse, error) - // Sets the port status of a switch port. - Port(context.Context, *v2.SwitchServicePortRequest) (*v2.SwitchServicePortResponse, error) - // Returns all switches with their machine connections. - ConnectedMachines(context.Context, *v2.SwitchServiceConnectedMachinesRequest) (*v2.SwitchServiceConnectedMachinesResponse, error) -} - -// NewSwitchServiceHandler 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 NewSwitchServiceHandler(svc SwitchServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) { - switchServiceMethods := v2.File_metalstack_admin_v2_switch_proto.Services().ByName("SwitchService").Methods() - switchServiceGetHandler := connect.NewUnaryHandlerSimple( - SwitchServiceGetProcedure, - svc.Get, - connect.WithSchema(switchServiceMethods.ByName("Get")), - connect.WithHandlerOptions(opts...), - ) - switchServiceListHandler := connect.NewUnaryHandlerSimple( - SwitchServiceListProcedure, - svc.List, - connect.WithSchema(switchServiceMethods.ByName("List")), - connect.WithHandlerOptions(opts...), - ) - switchServiceUpdateHandler := connect.NewUnaryHandlerSimple( - SwitchServiceUpdateProcedure, - svc.Update, - connect.WithSchema(switchServiceMethods.ByName("Update")), - connect.WithHandlerOptions(opts...), - ) - switchServiceDeleteHandler := connect.NewUnaryHandlerSimple( - SwitchServiceDeleteProcedure, - svc.Delete, - connect.WithSchema(switchServiceMethods.ByName("Delete")), - connect.WithHandlerOptions(opts...), - ) - switchServiceMigrateHandler := connect.NewUnaryHandlerSimple( - SwitchServiceMigrateProcedure, - svc.Migrate, - connect.WithSchema(switchServiceMethods.ByName("Migrate")), - connect.WithHandlerOptions(opts...), - ) - switchServicePortHandler := connect.NewUnaryHandlerSimple( - SwitchServicePortProcedure, - svc.Port, - connect.WithSchema(switchServiceMethods.ByName("Port")), - connect.WithHandlerOptions(opts...), - ) - switchServiceConnectedMachinesHandler := connect.NewUnaryHandlerSimple( - SwitchServiceConnectedMachinesProcedure, - svc.ConnectedMachines, - connect.WithSchema(switchServiceMethods.ByName("ConnectedMachines")), - connect.WithHandlerOptions(opts...), - ) - return "/metalstack.admin.v2.SwitchService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - switch r.URL.Path { - case SwitchServiceGetProcedure: - switchServiceGetHandler.ServeHTTP(w, r) - case SwitchServiceListProcedure: - switchServiceListHandler.ServeHTTP(w, r) - case SwitchServiceUpdateProcedure: - switchServiceUpdateHandler.ServeHTTP(w, r) - case SwitchServiceDeleteProcedure: - switchServiceDeleteHandler.ServeHTTP(w, r) - case SwitchServiceMigrateProcedure: - switchServiceMigrateHandler.ServeHTTP(w, r) - case SwitchServicePortProcedure: - switchServicePortHandler.ServeHTTP(w, r) - case SwitchServiceConnectedMachinesProcedure: - switchServiceConnectedMachinesHandler.ServeHTTP(w, r) - default: - http.NotFound(w, r) - } - }) + return &res, nil } -// UnimplementedSwitchServiceHandler returns CodeUnimplemented from all methods. -type UnimplementedSwitchServiceHandler struct{} +type switchServiceHandler struct{ svc SwitchServiceHandler } -func (UnimplementedSwitchServiceHandler) Get(context.Context, *v2.SwitchServiceGetRequest) (*v2.SwitchServiceGetResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.SwitchService.Get is not implemented")) +func (h switchServiceHandler) get(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.SwitchServiceGetRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Get(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } -func (UnimplementedSwitchServiceHandler) List(context.Context, *v2.SwitchServiceListRequest) (*v2.SwitchServiceListResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.SwitchService.List is not implemented")) +func (h switchServiceHandler) list(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.SwitchServiceListRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.List(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } -func (UnimplementedSwitchServiceHandler) Update(context.Context, *v2.SwitchServiceUpdateRequest) (*v2.SwitchServiceUpdateResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.SwitchService.Update is not implemented")) +func (h switchServiceHandler) update(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.SwitchServiceUpdateRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Update(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } -func (UnimplementedSwitchServiceHandler) Delete(context.Context, *v2.SwitchServiceDeleteRequest) (*v2.SwitchServiceDeleteResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.SwitchService.Delete is not implemented")) +func (h switchServiceHandler) delete(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.SwitchServiceDeleteRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Delete(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } -func (UnimplementedSwitchServiceHandler) Migrate(context.Context, *v2.SwitchServiceMigrateRequest) (*v2.SwitchServiceMigrateResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.SwitchService.Migrate is not implemented")) +func (h switchServiceHandler) migrate(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.SwitchServiceMigrateRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Migrate(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } -func (UnimplementedSwitchServiceHandler) Port(context.Context, *v2.SwitchServicePortRequest) (*v2.SwitchServicePortResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.SwitchService.Port is not implemented")) +func (h switchServiceHandler) port(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.SwitchServicePortRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Port(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } -func (UnimplementedSwitchServiceHandler) ConnectedMachines(context.Context, *v2.SwitchServiceConnectedMachinesRequest) (*v2.SwitchServiceConnectedMachinesResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.SwitchService.ConnectedMachines is not implemented")) +func (h switchServiceHandler) connectedMachines(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.SwitchServiceConnectedMachinesRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.ConnectedMachines(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } diff --git a/go/metalstack/admin/v2/adminv2connect/task.connect.go b/go/metalstack/admin/v2/adminv2connect/task.connect.go index 70279fca..b6936459 100644 --- a/go/metalstack/admin/v2/adminv2connect/task.connect.go +++ b/go/metalstack/admin/v2/adminv2connect/task.connect.go @@ -5,44 +5,66 @@ package adminv2connect import ( - connect "connectrpc.com/connect" + connect "connectrpc.com/connect/v2" context "context" - errors "errors" v2 "github.com/metal-stack/api/go/metalstack/admin/v2" - http "net/http" - strings "strings" + sync "sync" ) -// 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 ( // TaskServiceName is the fully-qualified name of the TaskService service. TaskServiceName = "metalstack.admin.v2.TaskService" ) -// 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. +// These constants are the procedure 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 ( - // TaskServiceGetProcedure is the fully-qualified name of the TaskService's Get RPC. + // TaskServiceGetProcedure is the procedure name of the TaskService's Get RPC. TaskServiceGetProcedure = "/metalstack.admin.v2.TaskService/Get" - // TaskServiceDeleteProcedure is the fully-qualified name of the TaskService's Delete RPC. + // TaskServiceDeleteProcedure is the procedure name of the TaskService's Delete RPC. TaskServiceDeleteProcedure = "/metalstack.admin.v2.TaskService/Delete" - // TaskServiceQueuesProcedure is the fully-qualified name of the TaskService's Queues RPC. + // TaskServiceQueuesProcedure is the procedure name of the TaskService's Queues RPC. TaskServiceQueuesProcedure = "/metalstack.admin.v2.TaskService/Queues" - // TaskServiceListProcedure is the fully-qualified name of the TaskService's List RPC. + // TaskServiceListProcedure is the procedure name of the TaskService's List RPC. TaskServiceListProcedure = "/metalstack.admin.v2.TaskService/List" ) +var ( + taskServiceGetSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_admin_v2_task_proto.Services().ByName("TaskService").Methods().ByName("Get"), + Procedure: TaskServiceGetProcedure, + } + }) + taskServiceDeleteSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_admin_v2_task_proto.Services().ByName("TaskService").Methods().ByName("Delete"), + Procedure: TaskServiceDeleteProcedure, + } + }) + taskServiceQueuesSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_admin_v2_task_proto.Services().ByName("TaskService").Methods().ByName("Queues"), + Procedure: TaskServiceQueuesProcedure, + } + }) + taskServiceListSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_admin_v2_task_proto.Services().ByName("TaskService").Methods().ByName("List"), + Procedure: TaskServiceListProcedure, + } + }) +) + // TaskServiceClient is a client for the metalstack.admin.v2.TaskService service. type TaskServiceClient interface { // Returns the task with the specified identifier. @@ -55,86 +77,10 @@ type TaskServiceClient interface { List(context.Context, *v2.TaskServiceListRequest) (*v2.TaskServiceListResponse, error) } -// NewTaskServiceClient constructs a client for the metalstack.admin.v2.TaskService 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 NewTaskServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) TaskServiceClient { - baseURL = strings.TrimRight(baseURL, "/") - taskServiceMethods := v2.File_metalstack_admin_v2_task_proto.Services().ByName("TaskService").Methods() - return &taskServiceClient{ - get: connect.NewClient[v2.TaskServiceGetRequest, v2.TaskServiceGetResponse]( - httpClient, - baseURL+TaskServiceGetProcedure, - connect.WithSchema(taskServiceMethods.ByName("Get")), - connect.WithClientOptions(opts...), - ), - delete: connect.NewClient[v2.TaskServiceDeleteRequest, v2.TaskServiceDeleteResponse]( - httpClient, - baseURL+TaskServiceDeleteProcedure, - connect.WithSchema(taskServiceMethods.ByName("Delete")), - connect.WithClientOptions(opts...), - ), - queues: connect.NewClient[v2.TaskServiceQueuesRequest, v2.TaskServiceQueuesResponse]( - httpClient, - baseURL+TaskServiceQueuesProcedure, - connect.WithSchema(taskServiceMethods.ByName("Queues")), - connect.WithClientOptions(opts...), - ), - list: connect.NewClient[v2.TaskServiceListRequest, v2.TaskServiceListResponse]( - httpClient, - baseURL+TaskServiceListProcedure, - connect.WithSchema(taskServiceMethods.ByName("List")), - connect.WithClientOptions(opts...), - ), - } -} - -// taskServiceClient implements TaskServiceClient. -type taskServiceClient struct { - get *connect.Client[v2.TaskServiceGetRequest, v2.TaskServiceGetResponse] - delete *connect.Client[v2.TaskServiceDeleteRequest, v2.TaskServiceDeleteResponse] - queues *connect.Client[v2.TaskServiceQueuesRequest, v2.TaskServiceQueuesResponse] - list *connect.Client[v2.TaskServiceListRequest, v2.TaskServiceListResponse] -} - -// Get calls metalstack.admin.v2.TaskService.Get. -func (c *taskServiceClient) Get(ctx context.Context, req *v2.TaskServiceGetRequest) (*v2.TaskServiceGetResponse, error) { - response, err := c.get.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err -} - -// Delete calls metalstack.admin.v2.TaskService.Delete. -func (c *taskServiceClient) Delete(ctx context.Context, req *v2.TaskServiceDeleteRequest) (*v2.TaskServiceDeleteResponse, error) { - response, err := c.delete.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err -} - -// Queues calls metalstack.admin.v2.TaskService.Queues. -func (c *taskServiceClient) Queues(ctx context.Context, req *v2.TaskServiceQueuesRequest) (*v2.TaskServiceQueuesResponse, error) { - response, err := c.queues.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err -} - -// List calls metalstack.admin.v2.TaskService.List. -func (c *taskServiceClient) List(ctx context.Context, req *v2.TaskServiceListRequest) (*v2.TaskServiceListResponse, error) { - response, err := c.list.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err +// NewTaskServiceClient constructs a client for the metalstack.admin.v2.TaskService service. +// Multiple service clients may share a single connect.Client. +func NewTaskServiceClient(client *connect.Client) TaskServiceClient { + return &taskServiceClient{client: client} } // TaskServiceHandler is an implementation of the metalstack.admin.v2.TaskService service. @@ -149,68 +95,119 @@ type TaskServiceHandler interface { List(context.Context, *v2.TaskServiceListRequest) (*v2.TaskServiceListResponse, error) } -// NewTaskServiceHandler 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 NewTaskServiceHandler(svc TaskServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) { - taskServiceMethods := v2.File_metalstack_admin_v2_task_proto.Services().ByName("TaskService").Methods() - taskServiceGetHandler := connect.NewUnaryHandlerSimple( - TaskServiceGetProcedure, - svc.Get, - connect.WithSchema(taskServiceMethods.ByName("Get")), - connect.WithHandlerOptions(opts...), +// RegisterTaskServiceHandler registers svc as the metalstack.admin.v2.TaskService implementation on +// server. +func RegisterTaskServiceHandler(server *connect.Server, svc TaskServiceHandler) { + adapter := taskServiceHandler{svc: svc} + server.Register( + connect.Method{Spec: taskServiceGetSpec(), Handler: adapter.get}, + connect.Method{Spec: taskServiceDeleteSpec(), Handler: adapter.delete}, + connect.Method{Spec: taskServiceQueuesSpec(), Handler: adapter.queues}, + connect.Method{Spec: taskServiceListSpec(), Handler: adapter.list}, ) - taskServiceDeleteHandler := connect.NewUnaryHandlerSimple( - TaskServiceDeleteProcedure, - svc.Delete, - connect.WithSchema(taskServiceMethods.ByName("Delete")), - connect.WithHandlerOptions(opts...), - ) - taskServiceQueuesHandler := connect.NewUnaryHandlerSimple( - TaskServiceQueuesProcedure, - svc.Queues, - connect.WithSchema(taskServiceMethods.ByName("Queues")), - connect.WithHandlerOptions(opts...), - ) - taskServiceListHandler := connect.NewUnaryHandlerSimple( - TaskServiceListProcedure, - svc.List, - connect.WithSchema(taskServiceMethods.ByName("List")), - connect.WithHandlerOptions(opts...), - ) - return "/metalstack.admin.v2.TaskService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - switch r.URL.Path { - case TaskServiceGetProcedure: - taskServiceGetHandler.ServeHTTP(w, r) - case TaskServiceDeleteProcedure: - taskServiceDeleteHandler.ServeHTTP(w, r) - case TaskServiceQueuesProcedure: - taskServiceQueuesHandler.ServeHTTP(w, r) - case TaskServiceListProcedure: - taskServiceListHandler.ServeHTTP(w, r) - default: - http.NotFound(w, r) - } - }) } // UnimplementedTaskServiceHandler returns CodeUnimplemented from all methods. type UnimplementedTaskServiceHandler struct{} func (UnimplementedTaskServiceHandler) Get(context.Context, *v2.TaskServiceGetRequest) (*v2.TaskServiceGetResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.TaskService.Get is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.admin.v2.TaskService.Get is not implemented") } func (UnimplementedTaskServiceHandler) Delete(context.Context, *v2.TaskServiceDeleteRequest) (*v2.TaskServiceDeleteResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.TaskService.Delete is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.admin.v2.TaskService.Delete is not implemented") } func (UnimplementedTaskServiceHandler) Queues(context.Context, *v2.TaskServiceQueuesRequest) (*v2.TaskServiceQueuesResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.TaskService.Queues is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.admin.v2.TaskService.Queues is not implemented") } func (UnimplementedTaskServiceHandler) List(context.Context, *v2.TaskServiceListRequest) (*v2.TaskServiceListResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.TaskService.List is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.admin.v2.TaskService.List is not implemented") +} + +type taskServiceClient struct { + client *connect.Client +} + +func (c *taskServiceClient) Get(ctx context.Context, req *v2.TaskServiceGetRequest) (*v2.TaskServiceGetResponse, error) { + var res v2.TaskServiceGetResponse + if err := c.client.CallUnary(ctx, taskServiceGetSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *taskServiceClient) Delete(ctx context.Context, req *v2.TaskServiceDeleteRequest) (*v2.TaskServiceDeleteResponse, error) { + var res v2.TaskServiceDeleteResponse + if err := c.client.CallUnary(ctx, taskServiceDeleteSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *taskServiceClient) Queues(ctx context.Context, req *v2.TaskServiceQueuesRequest) (*v2.TaskServiceQueuesResponse, error) { + var res v2.TaskServiceQueuesResponse + if err := c.client.CallUnary(ctx, taskServiceQueuesSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *taskServiceClient) List(ctx context.Context, req *v2.TaskServiceListRequest) (*v2.TaskServiceListResponse, error) { + var res v2.TaskServiceListResponse + if err := c.client.CallUnary(ctx, taskServiceListSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +type taskServiceHandler struct{ svc TaskServiceHandler } + +func (h taskServiceHandler) get(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.TaskServiceGetRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Get(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) +} + +func (h taskServiceHandler) delete(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.TaskServiceDeleteRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Delete(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) +} + +func (h taskServiceHandler) queues(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.TaskServiceQueuesRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Queues(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) +} + +func (h taskServiceHandler) list(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.TaskServiceListRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.List(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } diff --git a/go/metalstack/admin/v2/adminv2connect/tenant.connect.go b/go/metalstack/admin/v2/adminv2connect/tenant.connect.go index 13890a76..dff6bb3b 100644 --- a/go/metalstack/admin/v2/adminv2connect/tenant.connect.go +++ b/go/metalstack/admin/v2/adminv2connect/tenant.connect.go @@ -5,45 +5,66 @@ package adminv2connect import ( - connect "connectrpc.com/connect" + connect "connectrpc.com/connect/v2" context "context" - errors "errors" v2 "github.com/metal-stack/api/go/metalstack/admin/v2" - http "net/http" - strings "strings" + sync "sync" ) -// 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 ( // TenantServiceName is the fully-qualified name of the TenantService service. TenantServiceName = "metalstack.admin.v2.TenantService" ) -// 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. +// These constants are the procedure 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 ( - // TenantServiceCreateProcedure is the fully-qualified name of the TenantService's Create RPC. + // TenantServiceCreateProcedure is the procedure name of the TenantService's Create RPC. TenantServiceCreateProcedure = "/metalstack.admin.v2.TenantService/Create" - // TenantServiceListProcedure is the fully-qualified name of the TenantService's List RPC. + // TenantServiceListProcedure is the procedure name of the TenantService's List RPC. TenantServiceListProcedure = "/metalstack.admin.v2.TenantService/List" - // TenantServiceAddMemberProcedure is the fully-qualified name of the TenantService's AddMember RPC. + // TenantServiceAddMemberProcedure is the procedure name of the TenantService's AddMember RPC. TenantServiceAddMemberProcedure = "/metalstack.admin.v2.TenantService/AddMember" - // TenantServiceRemoveMemberProcedure is the fully-qualified name of the TenantService's - // RemoveMember RPC. + // TenantServiceRemoveMemberProcedure is the procedure name of the TenantService's RemoveMember RPC. TenantServiceRemoveMemberProcedure = "/metalstack.admin.v2.TenantService/RemoveMember" ) +var ( + tenantServiceCreateSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_admin_v2_tenant_proto.Services().ByName("TenantService").Methods().ByName("Create"), + Procedure: TenantServiceCreateProcedure, + } + }) + tenantServiceListSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_admin_v2_tenant_proto.Services().ByName("TenantService").Methods().ByName("List"), + Procedure: TenantServiceListProcedure, + } + }) + tenantServiceAddMemberSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_admin_v2_tenant_proto.Services().ByName("TenantService").Methods().ByName("AddMember"), + Procedure: TenantServiceAddMemberProcedure, + } + }) + tenantServiceRemoveMemberSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_admin_v2_tenant_proto.Services().ByName("TenantService").Methods().ByName("RemoveMember"), + Procedure: TenantServiceRemoveMemberProcedure, + } + }) +) + // TenantServiceClient is a client for the metalstack.admin.v2.TenantService service. type TenantServiceClient interface { // Creates a new tenant. @@ -56,86 +77,10 @@ type TenantServiceClient interface { RemoveMember(context.Context, *v2.TenantServiceRemoveMemberRequest) (*v2.TenantServiceRemoveMemberResponse, error) } -// NewTenantServiceClient constructs a client for the metalstack.admin.v2.TenantService 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 NewTenantServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) TenantServiceClient { - baseURL = strings.TrimRight(baseURL, "/") - tenantServiceMethods := v2.File_metalstack_admin_v2_tenant_proto.Services().ByName("TenantService").Methods() - return &tenantServiceClient{ - create: connect.NewClient[v2.TenantServiceCreateRequest, v2.TenantServiceCreateResponse]( - httpClient, - baseURL+TenantServiceCreateProcedure, - connect.WithSchema(tenantServiceMethods.ByName("Create")), - connect.WithClientOptions(opts...), - ), - list: connect.NewClient[v2.TenantServiceListRequest, v2.TenantServiceListResponse]( - httpClient, - baseURL+TenantServiceListProcedure, - connect.WithSchema(tenantServiceMethods.ByName("List")), - connect.WithClientOptions(opts...), - ), - addMember: connect.NewClient[v2.TenantServiceAddMemberRequest, v2.TenantServiceAddMemberResponse]( - httpClient, - baseURL+TenantServiceAddMemberProcedure, - connect.WithSchema(tenantServiceMethods.ByName("AddMember")), - connect.WithClientOptions(opts...), - ), - removeMember: connect.NewClient[v2.TenantServiceRemoveMemberRequest, v2.TenantServiceRemoveMemberResponse]( - httpClient, - baseURL+TenantServiceRemoveMemberProcedure, - connect.WithSchema(tenantServiceMethods.ByName("RemoveMember")), - connect.WithClientOptions(opts...), - ), - } -} - -// tenantServiceClient implements TenantServiceClient. -type tenantServiceClient struct { - create *connect.Client[v2.TenantServiceCreateRequest, v2.TenantServiceCreateResponse] - list *connect.Client[v2.TenantServiceListRequest, v2.TenantServiceListResponse] - addMember *connect.Client[v2.TenantServiceAddMemberRequest, v2.TenantServiceAddMemberResponse] - removeMember *connect.Client[v2.TenantServiceRemoveMemberRequest, v2.TenantServiceRemoveMemberResponse] -} - -// Create calls metalstack.admin.v2.TenantService.Create. -func (c *tenantServiceClient) Create(ctx context.Context, req *v2.TenantServiceCreateRequest) (*v2.TenantServiceCreateResponse, error) { - response, err := c.create.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err -} - -// List calls metalstack.admin.v2.TenantService.List. -func (c *tenantServiceClient) List(ctx context.Context, req *v2.TenantServiceListRequest) (*v2.TenantServiceListResponse, error) { - response, err := c.list.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err -} - -// AddMember calls metalstack.admin.v2.TenantService.AddMember. -func (c *tenantServiceClient) AddMember(ctx context.Context, req *v2.TenantServiceAddMemberRequest) (*v2.TenantServiceAddMemberResponse, error) { - response, err := c.addMember.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err -} - -// RemoveMember calls metalstack.admin.v2.TenantService.RemoveMember. -func (c *tenantServiceClient) RemoveMember(ctx context.Context, req *v2.TenantServiceRemoveMemberRequest) (*v2.TenantServiceRemoveMemberResponse, error) { - response, err := c.removeMember.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err +// NewTenantServiceClient constructs a client for the metalstack.admin.v2.TenantService service. +// Multiple service clients may share a single connect.Client. +func NewTenantServiceClient(client *connect.Client) TenantServiceClient { + return &tenantServiceClient{client: client} } // TenantServiceHandler is an implementation of the metalstack.admin.v2.TenantService service. @@ -150,68 +95,119 @@ type TenantServiceHandler interface { RemoveMember(context.Context, *v2.TenantServiceRemoveMemberRequest) (*v2.TenantServiceRemoveMemberResponse, error) } -// NewTenantServiceHandler 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 NewTenantServiceHandler(svc TenantServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) { - tenantServiceMethods := v2.File_metalstack_admin_v2_tenant_proto.Services().ByName("TenantService").Methods() - tenantServiceCreateHandler := connect.NewUnaryHandlerSimple( - TenantServiceCreateProcedure, - svc.Create, - connect.WithSchema(tenantServiceMethods.ByName("Create")), - connect.WithHandlerOptions(opts...), +// RegisterTenantServiceHandler registers svc as the metalstack.admin.v2.TenantService +// implementation on server. +func RegisterTenantServiceHandler(server *connect.Server, svc TenantServiceHandler) { + adapter := tenantServiceHandler{svc: svc} + server.Register( + connect.Method{Spec: tenantServiceCreateSpec(), Handler: adapter.create}, + connect.Method{Spec: tenantServiceListSpec(), Handler: adapter.list}, + connect.Method{Spec: tenantServiceAddMemberSpec(), Handler: adapter.addMember}, + connect.Method{Spec: tenantServiceRemoveMemberSpec(), Handler: adapter.removeMember}, ) - tenantServiceListHandler := connect.NewUnaryHandlerSimple( - TenantServiceListProcedure, - svc.List, - connect.WithSchema(tenantServiceMethods.ByName("List")), - connect.WithHandlerOptions(opts...), - ) - tenantServiceAddMemberHandler := connect.NewUnaryHandlerSimple( - TenantServiceAddMemberProcedure, - svc.AddMember, - connect.WithSchema(tenantServiceMethods.ByName("AddMember")), - connect.WithHandlerOptions(opts...), - ) - tenantServiceRemoveMemberHandler := connect.NewUnaryHandlerSimple( - TenantServiceRemoveMemberProcedure, - svc.RemoveMember, - connect.WithSchema(tenantServiceMethods.ByName("RemoveMember")), - connect.WithHandlerOptions(opts...), - ) - return "/metalstack.admin.v2.TenantService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - switch r.URL.Path { - case TenantServiceCreateProcedure: - tenantServiceCreateHandler.ServeHTTP(w, r) - case TenantServiceListProcedure: - tenantServiceListHandler.ServeHTTP(w, r) - case TenantServiceAddMemberProcedure: - tenantServiceAddMemberHandler.ServeHTTP(w, r) - case TenantServiceRemoveMemberProcedure: - tenantServiceRemoveMemberHandler.ServeHTTP(w, r) - default: - http.NotFound(w, r) - } - }) } // UnimplementedTenantServiceHandler returns CodeUnimplemented from all methods. type UnimplementedTenantServiceHandler struct{} func (UnimplementedTenantServiceHandler) Create(context.Context, *v2.TenantServiceCreateRequest) (*v2.TenantServiceCreateResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.TenantService.Create is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.admin.v2.TenantService.Create is not implemented") } func (UnimplementedTenantServiceHandler) List(context.Context, *v2.TenantServiceListRequest) (*v2.TenantServiceListResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.TenantService.List is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.admin.v2.TenantService.List is not implemented") } func (UnimplementedTenantServiceHandler) AddMember(context.Context, *v2.TenantServiceAddMemberRequest) (*v2.TenantServiceAddMemberResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.TenantService.AddMember is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.admin.v2.TenantService.AddMember is not implemented") } func (UnimplementedTenantServiceHandler) RemoveMember(context.Context, *v2.TenantServiceRemoveMemberRequest) (*v2.TenantServiceRemoveMemberResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.TenantService.RemoveMember is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.admin.v2.TenantService.RemoveMember is not implemented") +} + +type tenantServiceClient struct { + client *connect.Client +} + +func (c *tenantServiceClient) Create(ctx context.Context, req *v2.TenantServiceCreateRequest) (*v2.TenantServiceCreateResponse, error) { + var res v2.TenantServiceCreateResponse + if err := c.client.CallUnary(ctx, tenantServiceCreateSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *tenantServiceClient) List(ctx context.Context, req *v2.TenantServiceListRequest) (*v2.TenantServiceListResponse, error) { + var res v2.TenantServiceListResponse + if err := c.client.CallUnary(ctx, tenantServiceListSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *tenantServiceClient) AddMember(ctx context.Context, req *v2.TenantServiceAddMemberRequest) (*v2.TenantServiceAddMemberResponse, error) { + var res v2.TenantServiceAddMemberResponse + if err := c.client.CallUnary(ctx, tenantServiceAddMemberSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *tenantServiceClient) RemoveMember(ctx context.Context, req *v2.TenantServiceRemoveMemberRequest) (*v2.TenantServiceRemoveMemberResponse, error) { + var res v2.TenantServiceRemoveMemberResponse + if err := c.client.CallUnary(ctx, tenantServiceRemoveMemberSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +type tenantServiceHandler struct{ svc TenantServiceHandler } + +func (h tenantServiceHandler) create(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.TenantServiceCreateRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Create(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) +} + +func (h tenantServiceHandler) list(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.TenantServiceListRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.List(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) +} + +func (h tenantServiceHandler) addMember(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.TenantServiceAddMemberRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.AddMember(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) +} + +func (h tenantServiceHandler) removeMember(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.TenantServiceRemoveMemberRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.RemoveMember(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } diff --git a/go/metalstack/admin/v2/adminv2connect/token.connect.go b/go/metalstack/admin/v2/adminv2connect/token.connect.go index 98cf0434..af10d020 100644 --- a/go/metalstack/admin/v2/adminv2connect/token.connect.go +++ b/go/metalstack/admin/v2/adminv2connect/token.connect.go @@ -5,42 +5,57 @@ package adminv2connect import ( - connect "connectrpc.com/connect" + connect "connectrpc.com/connect/v2" context "context" - errors "errors" v2 "github.com/metal-stack/api/go/metalstack/admin/v2" - http "net/http" - strings "strings" + sync "sync" ) -// 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 ( // TokenServiceName is the fully-qualified name of the TokenService service. TokenServiceName = "metalstack.admin.v2.TokenService" ) -// 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. +// These constants are the procedure 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 ( - // TokenServiceListProcedure is the fully-qualified name of the TokenService's List RPC. + // TokenServiceListProcedure is the procedure name of the TokenService's List RPC. TokenServiceListProcedure = "/metalstack.admin.v2.TokenService/List" - // TokenServiceRevokeProcedure is the fully-qualified name of the TokenService's Revoke RPC. + // TokenServiceRevokeProcedure is the procedure name of the TokenService's Revoke RPC. TokenServiceRevokeProcedure = "/metalstack.admin.v2.TokenService/Revoke" - // TokenServiceCreateProcedure is the fully-qualified name of the TokenService's Create RPC. + // TokenServiceCreateProcedure is the procedure name of the TokenService's Create RPC. TokenServiceCreateProcedure = "/metalstack.admin.v2.TokenService/Create" ) +var ( + tokenServiceListSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_admin_v2_token_proto.Services().ByName("TokenService").Methods().ByName("List"), + Procedure: TokenServiceListProcedure, + } + }) + tokenServiceRevokeSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_admin_v2_token_proto.Services().ByName("TokenService").Methods().ByName("Revoke"), + Procedure: TokenServiceRevokeProcedure, + } + }) + tokenServiceCreateSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_admin_v2_token_proto.Services().ByName("TokenService").Methods().ByName("Create"), + Procedure: TokenServiceCreateProcedure, + } + }) +) + // TokenServiceClient is a client for the metalstack.admin.v2.TokenService service. type TokenServiceClient interface { // Returns the list of tokens for a user. @@ -52,70 +67,10 @@ type TokenServiceClient interface { Create(context.Context, *v2.TokenServiceCreateRequest) (*v2.TokenServiceCreateResponse, error) } -// NewTokenServiceClient constructs a client for the metalstack.admin.v2.TokenService 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 NewTokenServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) TokenServiceClient { - baseURL = strings.TrimRight(baseURL, "/") - tokenServiceMethods := v2.File_metalstack_admin_v2_token_proto.Services().ByName("TokenService").Methods() - return &tokenServiceClient{ - list: connect.NewClient[v2.TokenServiceListRequest, v2.TokenServiceListResponse]( - httpClient, - baseURL+TokenServiceListProcedure, - connect.WithSchema(tokenServiceMethods.ByName("List")), - connect.WithClientOptions(opts...), - ), - revoke: connect.NewClient[v2.TokenServiceRevokeRequest, v2.TokenServiceRevokeResponse]( - httpClient, - baseURL+TokenServiceRevokeProcedure, - connect.WithSchema(tokenServiceMethods.ByName("Revoke")), - connect.WithClientOptions(opts...), - ), - create: connect.NewClient[v2.TokenServiceCreateRequest, v2.TokenServiceCreateResponse]( - httpClient, - baseURL+TokenServiceCreateProcedure, - connect.WithSchema(tokenServiceMethods.ByName("Create")), - connect.WithClientOptions(opts...), - ), - } -} - -// tokenServiceClient implements TokenServiceClient. -type tokenServiceClient struct { - list *connect.Client[v2.TokenServiceListRequest, v2.TokenServiceListResponse] - revoke *connect.Client[v2.TokenServiceRevokeRequest, v2.TokenServiceRevokeResponse] - create *connect.Client[v2.TokenServiceCreateRequest, v2.TokenServiceCreateResponse] -} - -// List calls metalstack.admin.v2.TokenService.List. -func (c *tokenServiceClient) List(ctx context.Context, req *v2.TokenServiceListRequest) (*v2.TokenServiceListResponse, error) { - response, err := c.list.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err -} - -// Revoke calls metalstack.admin.v2.TokenService.Revoke. -func (c *tokenServiceClient) Revoke(ctx context.Context, req *v2.TokenServiceRevokeRequest) (*v2.TokenServiceRevokeResponse, error) { - response, err := c.revoke.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err -} - -// Create calls metalstack.admin.v2.TokenService.Create. -func (c *tokenServiceClient) Create(ctx context.Context, req *v2.TokenServiceCreateRequest) (*v2.TokenServiceCreateResponse, error) { - response, err := c.create.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err +// NewTokenServiceClient constructs a client for the metalstack.admin.v2.TokenService service. +// Multiple service clients may share a single connect.Client. +func NewTokenServiceClient(client *connect.Client) TokenServiceClient { + return &tokenServiceClient{client: client} } // TokenServiceHandler is an implementation of the metalstack.admin.v2.TokenService service. @@ -129,56 +84,94 @@ type TokenServiceHandler interface { Create(context.Context, *v2.TokenServiceCreateRequest) (*v2.TokenServiceCreateResponse, error) } -// NewTokenServiceHandler 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 NewTokenServiceHandler(svc TokenServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) { - tokenServiceMethods := v2.File_metalstack_admin_v2_token_proto.Services().ByName("TokenService").Methods() - tokenServiceListHandler := connect.NewUnaryHandlerSimple( - TokenServiceListProcedure, - svc.List, - connect.WithSchema(tokenServiceMethods.ByName("List")), - connect.WithHandlerOptions(opts...), +// RegisterTokenServiceHandler registers svc as the metalstack.admin.v2.TokenService implementation +// on server. +func RegisterTokenServiceHandler(server *connect.Server, svc TokenServiceHandler) { + adapter := tokenServiceHandler{svc: svc} + server.Register( + connect.Method{Spec: tokenServiceListSpec(), Handler: adapter.list}, + connect.Method{Spec: tokenServiceRevokeSpec(), Handler: adapter.revoke}, + connect.Method{Spec: tokenServiceCreateSpec(), Handler: adapter.create}, ) - tokenServiceRevokeHandler := connect.NewUnaryHandlerSimple( - TokenServiceRevokeProcedure, - svc.Revoke, - connect.WithSchema(tokenServiceMethods.ByName("Revoke")), - connect.WithHandlerOptions(opts...), - ) - tokenServiceCreateHandler := connect.NewUnaryHandlerSimple( - TokenServiceCreateProcedure, - svc.Create, - connect.WithSchema(tokenServiceMethods.ByName("Create")), - connect.WithHandlerOptions(opts...), - ) - return "/metalstack.admin.v2.TokenService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - switch r.URL.Path { - case TokenServiceListProcedure: - tokenServiceListHandler.ServeHTTP(w, r) - case TokenServiceRevokeProcedure: - tokenServiceRevokeHandler.ServeHTTP(w, r) - case TokenServiceCreateProcedure: - tokenServiceCreateHandler.ServeHTTP(w, r) - default: - http.NotFound(w, r) - } - }) } // UnimplementedTokenServiceHandler returns CodeUnimplemented from all methods. type UnimplementedTokenServiceHandler struct{} func (UnimplementedTokenServiceHandler) List(context.Context, *v2.TokenServiceListRequest) (*v2.TokenServiceListResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.TokenService.List is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.admin.v2.TokenService.List is not implemented") } func (UnimplementedTokenServiceHandler) Revoke(context.Context, *v2.TokenServiceRevokeRequest) (*v2.TokenServiceRevokeResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.TokenService.Revoke is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.admin.v2.TokenService.Revoke is not implemented") } func (UnimplementedTokenServiceHandler) Create(context.Context, *v2.TokenServiceCreateRequest) (*v2.TokenServiceCreateResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.TokenService.Create is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.admin.v2.TokenService.Create is not implemented") +} + +type tokenServiceClient struct { + client *connect.Client +} + +func (c *tokenServiceClient) List(ctx context.Context, req *v2.TokenServiceListRequest) (*v2.TokenServiceListResponse, error) { + var res v2.TokenServiceListResponse + if err := c.client.CallUnary(ctx, tokenServiceListSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *tokenServiceClient) Revoke(ctx context.Context, req *v2.TokenServiceRevokeRequest) (*v2.TokenServiceRevokeResponse, error) { + var res v2.TokenServiceRevokeResponse + if err := c.client.CallUnary(ctx, tokenServiceRevokeSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *tokenServiceClient) Create(ctx context.Context, req *v2.TokenServiceCreateRequest) (*v2.TokenServiceCreateResponse, error) { + var res v2.TokenServiceCreateResponse + if err := c.client.CallUnary(ctx, tokenServiceCreateSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +type tokenServiceHandler struct{ svc TokenServiceHandler } + +func (h tokenServiceHandler) list(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.TokenServiceListRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.List(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) +} + +func (h tokenServiceHandler) revoke(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.TokenServiceRevokeRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Revoke(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) +} + +func (h tokenServiceHandler) create(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.TokenServiceCreateRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Create(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } diff --git a/go/metalstack/admin/v2/adminv2connect/vpn.connect.go b/go/metalstack/admin/v2/adminv2connect/vpn.connect.go index eec85d0b..4581c4ff 100644 --- a/go/metalstack/admin/v2/adminv2connect/vpn.connect.go +++ b/go/metalstack/admin/v2/adminv2connect/vpn.connect.go @@ -5,40 +5,48 @@ package adminv2connect import ( - connect "connectrpc.com/connect" + connect "connectrpc.com/connect/v2" context "context" - errors "errors" v2 "github.com/metal-stack/api/go/metalstack/admin/v2" - http "net/http" - strings "strings" + sync "sync" ) -// 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 ( // VPNServiceName is the fully-qualified name of the VPNService service. VPNServiceName = "metalstack.admin.v2.VPNService" ) -// 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. +// These constants are the procedure 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 ( - // VPNServiceAuthKeyProcedure is the fully-qualified name of the VPNService's AuthKey RPC. + // VPNServiceAuthKeyProcedure is the procedure name of the VPNService's AuthKey RPC. VPNServiceAuthKeyProcedure = "/metalstack.admin.v2.VPNService/AuthKey" - // VPNServiceListNodesProcedure is the fully-qualified name of the VPNService's ListNodes RPC. + // VPNServiceListNodesProcedure is the procedure name of the VPNService's ListNodes RPC. VPNServiceListNodesProcedure = "/metalstack.admin.v2.VPNService/ListNodes" ) +var ( + vPNServiceAuthKeySpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_admin_v2_vpn_proto.Services().ByName("VPNService").Methods().ByName("AuthKey"), + Procedure: VPNServiceAuthKeyProcedure, + } + }) + vPNServiceListNodesSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_admin_v2_vpn_proto.Services().ByName("VPNService").Methods().ByName("ListNodes"), + Procedure: VPNServiceListNodesProcedure, + } + }) +) + // VPNServiceClient is a client for the metalstack.admin.v2.VPNService service. type VPNServiceClient interface { // GenerateAuthKey generates an authentication key for a project to join a machine to the project VPN. @@ -47,54 +55,10 @@ type VPNServiceClient interface { ListNodes(context.Context, *v2.VPNServiceListNodesRequest) (*v2.VPNServiceListNodesResponse, error) } -// NewVPNServiceClient constructs a client for the metalstack.admin.v2.VPNService 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 NewVPNServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) VPNServiceClient { - baseURL = strings.TrimRight(baseURL, "/") - vPNServiceMethods := v2.File_metalstack_admin_v2_vpn_proto.Services().ByName("VPNService").Methods() - return &vPNServiceClient{ - authKey: connect.NewClient[v2.VPNServiceAuthKeyRequest, v2.VPNServiceAuthKeyResponse]( - httpClient, - baseURL+VPNServiceAuthKeyProcedure, - connect.WithSchema(vPNServiceMethods.ByName("AuthKey")), - connect.WithClientOptions(opts...), - ), - listNodes: connect.NewClient[v2.VPNServiceListNodesRequest, v2.VPNServiceListNodesResponse]( - httpClient, - baseURL+VPNServiceListNodesProcedure, - connect.WithSchema(vPNServiceMethods.ByName("ListNodes")), - connect.WithClientOptions(opts...), - ), - } -} - -// vPNServiceClient implements VPNServiceClient. -type vPNServiceClient struct { - authKey *connect.Client[v2.VPNServiceAuthKeyRequest, v2.VPNServiceAuthKeyResponse] - listNodes *connect.Client[v2.VPNServiceListNodesRequest, v2.VPNServiceListNodesResponse] -} - -// AuthKey calls metalstack.admin.v2.VPNService.AuthKey. -func (c *vPNServiceClient) AuthKey(ctx context.Context, req *v2.VPNServiceAuthKeyRequest) (*v2.VPNServiceAuthKeyResponse, error) { - response, err := c.authKey.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err -} - -// ListNodes calls metalstack.admin.v2.VPNService.ListNodes. -func (c *vPNServiceClient) ListNodes(ctx context.Context, req *v2.VPNServiceListNodesRequest) (*v2.VPNServiceListNodesResponse, error) { - response, err := c.listNodes.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err +// NewVPNServiceClient constructs a client for the metalstack.admin.v2.VPNService service. Multiple +// service clients may share a single connect.Client. +func NewVPNServiceClient(client *connect.Client) VPNServiceClient { + return &vPNServiceClient{client: client} } // VPNServiceHandler is an implementation of the metalstack.admin.v2.VPNService service. @@ -105,44 +69,69 @@ type VPNServiceHandler interface { ListNodes(context.Context, *v2.VPNServiceListNodesRequest) (*v2.VPNServiceListNodesResponse, error) } -// NewVPNServiceHandler 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 NewVPNServiceHandler(svc VPNServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) { - vPNServiceMethods := v2.File_metalstack_admin_v2_vpn_proto.Services().ByName("VPNService").Methods() - vPNServiceAuthKeyHandler := connect.NewUnaryHandlerSimple( - VPNServiceAuthKeyProcedure, - svc.AuthKey, - connect.WithSchema(vPNServiceMethods.ByName("AuthKey")), - connect.WithHandlerOptions(opts...), - ) - vPNServiceListNodesHandler := connect.NewUnaryHandlerSimple( - VPNServiceListNodesProcedure, - svc.ListNodes, - connect.WithSchema(vPNServiceMethods.ByName("ListNodes")), - connect.WithHandlerOptions(opts...), +// RegisterVPNServiceHandler registers svc as the metalstack.admin.v2.VPNService implementation on +// server. +func RegisterVPNServiceHandler(server *connect.Server, svc VPNServiceHandler) { + adapter := vPNServiceHandler{svc: svc} + server.Register( + connect.Method{Spec: vPNServiceAuthKeySpec(), Handler: adapter.authKey}, + connect.Method{Spec: vPNServiceListNodesSpec(), Handler: adapter.listNodes}, ) - return "/metalstack.admin.v2.VPNService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - switch r.URL.Path { - case VPNServiceAuthKeyProcedure: - vPNServiceAuthKeyHandler.ServeHTTP(w, r) - case VPNServiceListNodesProcedure: - vPNServiceListNodesHandler.ServeHTTP(w, r) - default: - http.NotFound(w, r) - } - }) } // UnimplementedVPNServiceHandler returns CodeUnimplemented from all methods. type UnimplementedVPNServiceHandler struct{} func (UnimplementedVPNServiceHandler) AuthKey(context.Context, *v2.VPNServiceAuthKeyRequest) (*v2.VPNServiceAuthKeyResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.VPNService.AuthKey is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.admin.v2.VPNService.AuthKey is not implemented") } func (UnimplementedVPNServiceHandler) ListNodes(context.Context, *v2.VPNServiceListNodesRequest) (*v2.VPNServiceListNodesResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.admin.v2.VPNService.ListNodes is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.admin.v2.VPNService.ListNodes is not implemented") +} + +type vPNServiceClient struct { + client *connect.Client +} + +func (c *vPNServiceClient) AuthKey(ctx context.Context, req *v2.VPNServiceAuthKeyRequest) (*v2.VPNServiceAuthKeyResponse, error) { + var res v2.VPNServiceAuthKeyResponse + if err := c.client.CallUnary(ctx, vPNServiceAuthKeySpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *vPNServiceClient) ListNodes(ctx context.Context, req *v2.VPNServiceListNodesRequest) (*v2.VPNServiceListNodesResponse, error) { + var res v2.VPNServiceListNodesResponse + if err := c.client.CallUnary(ctx, vPNServiceListNodesSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +type vPNServiceHandler struct{ svc VPNServiceHandler } + +func (h vPNServiceHandler) authKey(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.VPNServiceAuthKeyRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.AuthKey(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) +} + +func (h vPNServiceHandler) listNodes(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.VPNServiceListNodesRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.ListNodes(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } diff --git a/go/metalstack/api/v2/apiv2connect/audit.connect.go b/go/metalstack/api/v2/apiv2connect/audit.connect.go index df8ceb7d..18e95140 100644 --- a/go/metalstack/api/v2/apiv2connect/audit.connect.go +++ b/go/metalstack/api/v2/apiv2connect/audit.connect.go @@ -5,40 +5,48 @@ package apiv2connect import ( - connect "connectrpc.com/connect" + connect "connectrpc.com/connect/v2" context "context" - errors "errors" v2 "github.com/metal-stack/api/go/metalstack/api/v2" - http "net/http" - strings "strings" + sync "sync" ) -// 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 ( // AuditServiceName is the fully-qualified name of the AuditService service. AuditServiceName = "metalstack.api.v2.AuditService" ) -// 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. +// These constants are the procedure 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 ( - // AuditServiceGetProcedure is the fully-qualified name of the AuditService's Get RPC. + // AuditServiceGetProcedure is the procedure name of the AuditService's Get RPC. AuditServiceGetProcedure = "/metalstack.api.v2.AuditService/Get" - // AuditServiceListProcedure is the fully-qualified name of the AuditService's List RPC. + // AuditServiceListProcedure is the procedure name of the AuditService's List RPC. AuditServiceListProcedure = "/metalstack.api.v2.AuditService/List" ) +var ( + auditServiceGetSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_audit_proto.Services().ByName("AuditService").Methods().ByName("Get"), + Procedure: AuditServiceGetProcedure, + } + }) + auditServiceListSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_audit_proto.Services().ByName("AuditService").Methods().ByName("List"), + Procedure: AuditServiceListProcedure, + } + }) +) + // AuditServiceClient is a client for the metalstack.api.v2.AuditService service. type AuditServiceClient interface { // Returns the audit trace with the specified UUID. @@ -47,54 +55,10 @@ type AuditServiceClient interface { List(context.Context, *v2.AuditServiceListRequest) (*v2.AuditServiceListResponse, error) } -// NewAuditServiceClient constructs a client for the metalstack.api.v2.AuditService 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 NewAuditServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) AuditServiceClient { - baseURL = strings.TrimRight(baseURL, "/") - auditServiceMethods := v2.File_metalstack_api_v2_audit_proto.Services().ByName("AuditService").Methods() - return &auditServiceClient{ - get: connect.NewClient[v2.AuditServiceGetRequest, v2.AuditServiceGetResponse]( - httpClient, - baseURL+AuditServiceGetProcedure, - connect.WithSchema(auditServiceMethods.ByName("Get")), - connect.WithClientOptions(opts...), - ), - list: connect.NewClient[v2.AuditServiceListRequest, v2.AuditServiceListResponse]( - httpClient, - baseURL+AuditServiceListProcedure, - connect.WithSchema(auditServiceMethods.ByName("List")), - connect.WithClientOptions(opts...), - ), - } -} - -// auditServiceClient implements AuditServiceClient. -type auditServiceClient struct { - get *connect.Client[v2.AuditServiceGetRequest, v2.AuditServiceGetResponse] - list *connect.Client[v2.AuditServiceListRequest, v2.AuditServiceListResponse] -} - -// Get calls metalstack.api.v2.AuditService.Get. -func (c *auditServiceClient) Get(ctx context.Context, req *v2.AuditServiceGetRequest) (*v2.AuditServiceGetResponse, error) { - response, err := c.get.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err -} - -// List calls metalstack.api.v2.AuditService.List. -func (c *auditServiceClient) List(ctx context.Context, req *v2.AuditServiceListRequest) (*v2.AuditServiceListResponse, error) { - response, err := c.list.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err +// NewAuditServiceClient constructs a client for the metalstack.api.v2.AuditService service. +// Multiple service clients may share a single connect.Client. +func NewAuditServiceClient(client *connect.Client) AuditServiceClient { + return &auditServiceClient{client: client} } // AuditServiceHandler is an implementation of the metalstack.api.v2.AuditService service. @@ -105,44 +69,69 @@ type AuditServiceHandler interface { List(context.Context, *v2.AuditServiceListRequest) (*v2.AuditServiceListResponse, error) } -// NewAuditServiceHandler 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 NewAuditServiceHandler(svc AuditServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) { - auditServiceMethods := v2.File_metalstack_api_v2_audit_proto.Services().ByName("AuditService").Methods() - auditServiceGetHandler := connect.NewUnaryHandlerSimple( - AuditServiceGetProcedure, - svc.Get, - connect.WithSchema(auditServiceMethods.ByName("Get")), - connect.WithHandlerOptions(opts...), - ) - auditServiceListHandler := connect.NewUnaryHandlerSimple( - AuditServiceListProcedure, - svc.List, - connect.WithSchema(auditServiceMethods.ByName("List")), - connect.WithHandlerOptions(opts...), +// RegisterAuditServiceHandler registers svc as the metalstack.api.v2.AuditService implementation on +// server. +func RegisterAuditServiceHandler(server *connect.Server, svc AuditServiceHandler) { + adapter := auditServiceHandler{svc: svc} + server.Register( + connect.Method{Spec: auditServiceGetSpec(), Handler: adapter.get}, + connect.Method{Spec: auditServiceListSpec(), Handler: adapter.list}, ) - return "/metalstack.api.v2.AuditService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - switch r.URL.Path { - case AuditServiceGetProcedure: - auditServiceGetHandler.ServeHTTP(w, r) - case AuditServiceListProcedure: - auditServiceListHandler.ServeHTTP(w, r) - default: - http.NotFound(w, r) - } - }) } // UnimplementedAuditServiceHandler returns CodeUnimplemented from all methods. type UnimplementedAuditServiceHandler struct{} func (UnimplementedAuditServiceHandler) Get(context.Context, *v2.AuditServiceGetRequest) (*v2.AuditServiceGetResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.AuditService.Get is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.AuditService.Get is not implemented") } func (UnimplementedAuditServiceHandler) List(context.Context, *v2.AuditServiceListRequest) (*v2.AuditServiceListResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.AuditService.List is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.AuditService.List is not implemented") +} + +type auditServiceClient struct { + client *connect.Client +} + +func (c *auditServiceClient) Get(ctx context.Context, req *v2.AuditServiceGetRequest) (*v2.AuditServiceGetResponse, error) { + var res v2.AuditServiceGetResponse + if err := c.client.CallUnary(ctx, auditServiceGetSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *auditServiceClient) List(ctx context.Context, req *v2.AuditServiceListRequest) (*v2.AuditServiceListResponse, error) { + var res v2.AuditServiceListResponse + if err := c.client.CallUnary(ctx, auditServiceListSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +type auditServiceHandler struct{ svc AuditServiceHandler } + +func (h auditServiceHandler) get(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.AuditServiceGetRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Get(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) +} + +func (h auditServiceHandler) list(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.AuditServiceListRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.List(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } diff --git a/go/metalstack/api/v2/apiv2connect/filesystem.connect.go b/go/metalstack/api/v2/apiv2connect/filesystem.connect.go index 7a09ab01..7d9f29eb 100644 --- a/go/metalstack/api/v2/apiv2connect/filesystem.connect.go +++ b/go/metalstack/api/v2/apiv2connect/filesystem.connect.go @@ -5,40 +5,48 @@ package apiv2connect import ( - connect "connectrpc.com/connect" + connect "connectrpc.com/connect/v2" context "context" - errors "errors" v2 "github.com/metal-stack/api/go/metalstack/api/v2" - http "net/http" - strings "strings" + sync "sync" ) -// 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 ( // FilesystemServiceName is the fully-qualified name of the FilesystemService service. FilesystemServiceName = "metalstack.api.v2.FilesystemService" ) -// 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. +// These constants are the procedure 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 ( - // FilesystemServiceGetProcedure is the fully-qualified name of the FilesystemService's Get RPC. + // FilesystemServiceGetProcedure is the procedure name of the FilesystemService's Get RPC. FilesystemServiceGetProcedure = "/metalstack.api.v2.FilesystemService/Get" - // FilesystemServiceListProcedure is the fully-qualified name of the FilesystemService's List RPC. + // FilesystemServiceListProcedure is the procedure name of the FilesystemService's List RPC. FilesystemServiceListProcedure = "/metalstack.api.v2.FilesystemService/List" ) +var ( + filesystemServiceGetSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_filesystem_proto.Services().ByName("FilesystemService").Methods().ByName("Get"), + Procedure: FilesystemServiceGetProcedure, + } + }) + filesystemServiceListSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_filesystem_proto.Services().ByName("FilesystemService").Methods().ByName("List"), + Procedure: FilesystemServiceListProcedure, + } + }) +) + // FilesystemServiceClient is a client for the metalstack.api.v2.FilesystemService service. type FilesystemServiceClient interface { // Returns the filesystem with the specified ID. @@ -48,53 +56,9 @@ type FilesystemServiceClient interface { } // NewFilesystemServiceClient constructs a client for the metalstack.api.v2.FilesystemService -// 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 NewFilesystemServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) FilesystemServiceClient { - baseURL = strings.TrimRight(baseURL, "/") - filesystemServiceMethods := v2.File_metalstack_api_v2_filesystem_proto.Services().ByName("FilesystemService").Methods() - return &filesystemServiceClient{ - get: connect.NewClient[v2.FilesystemServiceGetRequest, v2.FilesystemServiceGetResponse]( - httpClient, - baseURL+FilesystemServiceGetProcedure, - connect.WithSchema(filesystemServiceMethods.ByName("Get")), - connect.WithClientOptions(opts...), - ), - list: connect.NewClient[v2.FilesystemServiceListRequest, v2.FilesystemServiceListResponse]( - httpClient, - baseURL+FilesystemServiceListProcedure, - connect.WithSchema(filesystemServiceMethods.ByName("List")), - connect.WithClientOptions(opts...), - ), - } -} - -// filesystemServiceClient implements FilesystemServiceClient. -type filesystemServiceClient struct { - get *connect.Client[v2.FilesystemServiceGetRequest, v2.FilesystemServiceGetResponse] - list *connect.Client[v2.FilesystemServiceListRequest, v2.FilesystemServiceListResponse] -} - -// Get calls metalstack.api.v2.FilesystemService.Get. -func (c *filesystemServiceClient) Get(ctx context.Context, req *v2.FilesystemServiceGetRequest) (*v2.FilesystemServiceGetResponse, error) { - response, err := c.get.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err -} - -// List calls metalstack.api.v2.FilesystemService.List. -func (c *filesystemServiceClient) List(ctx context.Context, req *v2.FilesystemServiceListRequest) (*v2.FilesystemServiceListResponse, error) { - response, err := c.list.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err +// service. Multiple service clients may share a single connect.Client. +func NewFilesystemServiceClient(client *connect.Client) FilesystemServiceClient { + return &filesystemServiceClient{client: client} } // FilesystemServiceHandler is an implementation of the metalstack.api.v2.FilesystemService service. @@ -105,44 +69,69 @@ type FilesystemServiceHandler interface { List(context.Context, *v2.FilesystemServiceListRequest) (*v2.FilesystemServiceListResponse, error) } -// NewFilesystemServiceHandler 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 NewFilesystemServiceHandler(svc FilesystemServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) { - filesystemServiceMethods := v2.File_metalstack_api_v2_filesystem_proto.Services().ByName("FilesystemService").Methods() - filesystemServiceGetHandler := connect.NewUnaryHandlerSimple( - FilesystemServiceGetProcedure, - svc.Get, - connect.WithSchema(filesystemServiceMethods.ByName("Get")), - connect.WithHandlerOptions(opts...), - ) - filesystemServiceListHandler := connect.NewUnaryHandlerSimple( - FilesystemServiceListProcedure, - svc.List, - connect.WithSchema(filesystemServiceMethods.ByName("List")), - connect.WithHandlerOptions(opts...), +// RegisterFilesystemServiceHandler registers svc as the metalstack.api.v2.FilesystemService +// implementation on server. +func RegisterFilesystemServiceHandler(server *connect.Server, svc FilesystemServiceHandler) { + adapter := filesystemServiceHandler{svc: svc} + server.Register( + connect.Method{Spec: filesystemServiceGetSpec(), Handler: adapter.get}, + connect.Method{Spec: filesystemServiceListSpec(), Handler: adapter.list}, ) - return "/metalstack.api.v2.FilesystemService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - switch r.URL.Path { - case FilesystemServiceGetProcedure: - filesystemServiceGetHandler.ServeHTTP(w, r) - case FilesystemServiceListProcedure: - filesystemServiceListHandler.ServeHTTP(w, r) - default: - http.NotFound(w, r) - } - }) } // UnimplementedFilesystemServiceHandler returns CodeUnimplemented from all methods. type UnimplementedFilesystemServiceHandler struct{} func (UnimplementedFilesystemServiceHandler) Get(context.Context, *v2.FilesystemServiceGetRequest) (*v2.FilesystemServiceGetResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.FilesystemService.Get is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.FilesystemService.Get is not implemented") } func (UnimplementedFilesystemServiceHandler) List(context.Context, *v2.FilesystemServiceListRequest) (*v2.FilesystemServiceListResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.FilesystemService.List is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.FilesystemService.List is not implemented") +} + +type filesystemServiceClient struct { + client *connect.Client +} + +func (c *filesystemServiceClient) Get(ctx context.Context, req *v2.FilesystemServiceGetRequest) (*v2.FilesystemServiceGetResponse, error) { + var res v2.FilesystemServiceGetResponse + if err := c.client.CallUnary(ctx, filesystemServiceGetSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *filesystemServiceClient) List(ctx context.Context, req *v2.FilesystemServiceListRequest) (*v2.FilesystemServiceListResponse, error) { + var res v2.FilesystemServiceListResponse + if err := c.client.CallUnary(ctx, filesystemServiceListSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +type filesystemServiceHandler struct{ svc FilesystemServiceHandler } + +func (h filesystemServiceHandler) get(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.FilesystemServiceGetRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Get(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) +} + +func (h filesystemServiceHandler) list(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.FilesystemServiceListRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.List(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } diff --git a/go/metalstack/api/v2/apiv2connect/health.connect.go b/go/metalstack/api/v2/apiv2connect/health.connect.go index b0703610..7bdad1f8 100644 --- a/go/metalstack/api/v2/apiv2connect/health.connect.go +++ b/go/metalstack/api/v2/apiv2connect/health.connect.go @@ -5,76 +5,49 @@ package apiv2connect import ( - connect "connectrpc.com/connect" + connect "connectrpc.com/connect/v2" context "context" - errors "errors" v2 "github.com/metal-stack/api/go/metalstack/api/v2" - http "net/http" - strings "strings" + sync "sync" ) -// 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 ( // HealthServiceName is the fully-qualified name of the HealthService service. HealthServiceName = "metalstack.api.v2.HealthService" ) -// 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. +// These constants are the procedure 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 ( - // HealthServiceGetProcedure is the fully-qualified name of the HealthService's Get RPC. + // HealthServiceGetProcedure is the procedure name of the HealthService's Get RPC. HealthServiceGetProcedure = "/metalstack.api.v2.HealthService/Get" ) +var ( + healthServiceGetSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_health_proto.Services().ByName("HealthService").Methods().ByName("Get"), + Procedure: HealthServiceGetProcedure, + } + }) +) + // HealthServiceClient is a client for the metalstack.api.v2.HealthService service. type HealthServiceClient interface { // Returns the health status of the platform. Get(context.Context, *v2.HealthServiceGetRequest) (*v2.HealthServiceGetResponse, error) } -// NewHealthServiceClient constructs a client for the metalstack.api.v2.HealthService 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 NewHealthServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) HealthServiceClient { - baseURL = strings.TrimRight(baseURL, "/") - healthServiceMethods := v2.File_metalstack_api_v2_health_proto.Services().ByName("HealthService").Methods() - return &healthServiceClient{ - get: connect.NewClient[v2.HealthServiceGetRequest, v2.HealthServiceGetResponse]( - httpClient, - baseURL+HealthServiceGetProcedure, - connect.WithSchema(healthServiceMethods.ByName("Get")), - connect.WithClientOptions(opts...), - ), - } -} - -// healthServiceClient implements HealthServiceClient. -type healthServiceClient struct { - get *connect.Client[v2.HealthServiceGetRequest, v2.HealthServiceGetResponse] -} - -// Get calls metalstack.api.v2.HealthService.Get. -func (c *healthServiceClient) Get(ctx context.Context, req *v2.HealthServiceGetRequest) (*v2.HealthServiceGetResponse, error) { - response, err := c.get.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err +// NewHealthServiceClient constructs a client for the metalstack.api.v2.HealthService service. +// Multiple service clients may share a single connect.Client. +func NewHealthServiceClient(client *connect.Client) HealthServiceClient { + return &healthServiceClient{client: client} } // HealthServiceHandler is an implementation of the metalstack.api.v2.HealthService service. @@ -83,32 +56,44 @@ type HealthServiceHandler interface { Get(context.Context, *v2.HealthServiceGetRequest) (*v2.HealthServiceGetResponse, error) } -// NewHealthServiceHandler 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 NewHealthServiceHandler(svc HealthServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) { - healthServiceMethods := v2.File_metalstack_api_v2_health_proto.Services().ByName("HealthService").Methods() - healthServiceGetHandler := connect.NewUnaryHandlerSimple( - HealthServiceGetProcedure, - svc.Get, - connect.WithSchema(healthServiceMethods.ByName("Get")), - connect.WithHandlerOptions(opts...), +// RegisterHealthServiceHandler registers svc as the metalstack.api.v2.HealthService implementation +// on server. +func RegisterHealthServiceHandler(server *connect.Server, svc HealthServiceHandler) { + adapter := healthServiceHandler{svc: svc} + server.Register( + connect.Method{Spec: healthServiceGetSpec(), Handler: adapter.get}, ) - return "/metalstack.api.v2.HealthService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - switch r.URL.Path { - case HealthServiceGetProcedure: - healthServiceGetHandler.ServeHTTP(w, r) - default: - http.NotFound(w, r) - } - }) } // UnimplementedHealthServiceHandler returns CodeUnimplemented from all methods. type UnimplementedHealthServiceHandler struct{} func (UnimplementedHealthServiceHandler) Get(context.Context, *v2.HealthServiceGetRequest) (*v2.HealthServiceGetResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.HealthService.Get is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.HealthService.Get is not implemented") +} + +type healthServiceClient struct { + client *connect.Client +} + +func (c *healthServiceClient) Get(ctx context.Context, req *v2.HealthServiceGetRequest) (*v2.HealthServiceGetResponse, error) { + var res v2.HealthServiceGetResponse + if err := c.client.CallUnary(ctx, healthServiceGetSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +type healthServiceHandler struct{ svc HealthServiceHandler } + +func (h healthServiceHandler) get(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.HealthServiceGetRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Get(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } diff --git a/go/metalstack/api/v2/apiv2connect/image.connect.go b/go/metalstack/api/v2/apiv2connect/image.connect.go index 5a44e8a7..ea01c149 100644 --- a/go/metalstack/api/v2/apiv2connect/image.connect.go +++ b/go/metalstack/api/v2/apiv2connect/image.connect.go @@ -5,42 +5,57 @@ package apiv2connect import ( - connect "connectrpc.com/connect" + connect "connectrpc.com/connect/v2" context "context" - errors "errors" v2 "github.com/metal-stack/api/go/metalstack/api/v2" - http "net/http" - strings "strings" + sync "sync" ) -// 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 ( // ImageServiceName is the fully-qualified name of the ImageService service. ImageServiceName = "metalstack.api.v2.ImageService" ) -// 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. +// These constants are the procedure 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 ( - // ImageServiceGetProcedure is the fully-qualified name of the ImageService's Get RPC. + // ImageServiceGetProcedure is the procedure name of the ImageService's Get RPC. ImageServiceGetProcedure = "/metalstack.api.v2.ImageService/Get" - // ImageServiceListProcedure is the fully-qualified name of the ImageService's List RPC. + // ImageServiceListProcedure is the procedure name of the ImageService's List RPC. ImageServiceListProcedure = "/metalstack.api.v2.ImageService/List" - // ImageServiceLatestProcedure is the fully-qualified name of the ImageService's Latest RPC. + // ImageServiceLatestProcedure is the procedure name of the ImageService's Latest RPC. ImageServiceLatestProcedure = "/metalstack.api.v2.ImageService/Latest" ) +var ( + imageServiceGetSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_image_proto.Services().ByName("ImageService").Methods().ByName("Get"), + Procedure: ImageServiceGetProcedure, + } + }) + imageServiceListSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_image_proto.Services().ByName("ImageService").Methods().ByName("List"), + Procedure: ImageServiceListProcedure, + } + }) + imageServiceLatestSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_image_proto.Services().ByName("ImageService").Methods().ByName("Latest"), + Procedure: ImageServiceLatestProcedure, + } + }) +) + // ImageServiceClient is a client for the metalstack.api.v2.ImageService service. type ImageServiceClient interface { // Returns the image with the specified ID. @@ -51,70 +66,10 @@ type ImageServiceClient interface { Latest(context.Context, *v2.ImageServiceLatestRequest) (*v2.ImageServiceLatestResponse, error) } -// NewImageServiceClient constructs a client for the metalstack.api.v2.ImageService 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 NewImageServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) ImageServiceClient { - baseURL = strings.TrimRight(baseURL, "/") - imageServiceMethods := v2.File_metalstack_api_v2_image_proto.Services().ByName("ImageService").Methods() - return &imageServiceClient{ - get: connect.NewClient[v2.ImageServiceGetRequest, v2.ImageServiceGetResponse]( - httpClient, - baseURL+ImageServiceGetProcedure, - connect.WithSchema(imageServiceMethods.ByName("Get")), - connect.WithClientOptions(opts...), - ), - list: connect.NewClient[v2.ImageServiceListRequest, v2.ImageServiceListResponse]( - httpClient, - baseURL+ImageServiceListProcedure, - connect.WithSchema(imageServiceMethods.ByName("List")), - connect.WithClientOptions(opts...), - ), - latest: connect.NewClient[v2.ImageServiceLatestRequest, v2.ImageServiceLatestResponse]( - httpClient, - baseURL+ImageServiceLatestProcedure, - connect.WithSchema(imageServiceMethods.ByName("Latest")), - connect.WithClientOptions(opts...), - ), - } -} - -// imageServiceClient implements ImageServiceClient. -type imageServiceClient struct { - get *connect.Client[v2.ImageServiceGetRequest, v2.ImageServiceGetResponse] - list *connect.Client[v2.ImageServiceListRequest, v2.ImageServiceListResponse] - latest *connect.Client[v2.ImageServiceLatestRequest, v2.ImageServiceLatestResponse] -} - -// Get calls metalstack.api.v2.ImageService.Get. -func (c *imageServiceClient) Get(ctx context.Context, req *v2.ImageServiceGetRequest) (*v2.ImageServiceGetResponse, error) { - response, err := c.get.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err -} - -// List calls metalstack.api.v2.ImageService.List. -func (c *imageServiceClient) List(ctx context.Context, req *v2.ImageServiceListRequest) (*v2.ImageServiceListResponse, error) { - response, err := c.list.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err -} - -// Latest calls metalstack.api.v2.ImageService.Latest. -func (c *imageServiceClient) Latest(ctx context.Context, req *v2.ImageServiceLatestRequest) (*v2.ImageServiceLatestResponse, error) { - response, err := c.latest.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err +// NewImageServiceClient constructs a client for the metalstack.api.v2.ImageService service. +// Multiple service clients may share a single connect.Client. +func NewImageServiceClient(client *connect.Client) ImageServiceClient { + return &imageServiceClient{client: client} } // ImageServiceHandler is an implementation of the metalstack.api.v2.ImageService service. @@ -127,56 +82,94 @@ type ImageServiceHandler interface { Latest(context.Context, *v2.ImageServiceLatestRequest) (*v2.ImageServiceLatestResponse, error) } -// NewImageServiceHandler 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 NewImageServiceHandler(svc ImageServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) { - imageServiceMethods := v2.File_metalstack_api_v2_image_proto.Services().ByName("ImageService").Methods() - imageServiceGetHandler := connect.NewUnaryHandlerSimple( - ImageServiceGetProcedure, - svc.Get, - connect.WithSchema(imageServiceMethods.ByName("Get")), - connect.WithHandlerOptions(opts...), +// RegisterImageServiceHandler registers svc as the metalstack.api.v2.ImageService implementation on +// server. +func RegisterImageServiceHandler(server *connect.Server, svc ImageServiceHandler) { + adapter := imageServiceHandler{svc: svc} + server.Register( + connect.Method{Spec: imageServiceGetSpec(), Handler: adapter.get}, + connect.Method{Spec: imageServiceListSpec(), Handler: adapter.list}, + connect.Method{Spec: imageServiceLatestSpec(), Handler: adapter.latest}, ) - imageServiceListHandler := connect.NewUnaryHandlerSimple( - ImageServiceListProcedure, - svc.List, - connect.WithSchema(imageServiceMethods.ByName("List")), - connect.WithHandlerOptions(opts...), - ) - imageServiceLatestHandler := connect.NewUnaryHandlerSimple( - ImageServiceLatestProcedure, - svc.Latest, - connect.WithSchema(imageServiceMethods.ByName("Latest")), - connect.WithHandlerOptions(opts...), - ) - return "/metalstack.api.v2.ImageService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - switch r.URL.Path { - case ImageServiceGetProcedure: - imageServiceGetHandler.ServeHTTP(w, r) - case ImageServiceListProcedure: - imageServiceListHandler.ServeHTTP(w, r) - case ImageServiceLatestProcedure: - imageServiceLatestHandler.ServeHTTP(w, r) - default: - http.NotFound(w, r) - } - }) } // UnimplementedImageServiceHandler returns CodeUnimplemented from all methods. type UnimplementedImageServiceHandler struct{} func (UnimplementedImageServiceHandler) Get(context.Context, *v2.ImageServiceGetRequest) (*v2.ImageServiceGetResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.ImageService.Get is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.ImageService.Get is not implemented") } func (UnimplementedImageServiceHandler) List(context.Context, *v2.ImageServiceListRequest) (*v2.ImageServiceListResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.ImageService.List is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.ImageService.List is not implemented") } func (UnimplementedImageServiceHandler) Latest(context.Context, *v2.ImageServiceLatestRequest) (*v2.ImageServiceLatestResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.ImageService.Latest is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.ImageService.Latest is not implemented") +} + +type imageServiceClient struct { + client *connect.Client +} + +func (c *imageServiceClient) Get(ctx context.Context, req *v2.ImageServiceGetRequest) (*v2.ImageServiceGetResponse, error) { + var res v2.ImageServiceGetResponse + if err := c.client.CallUnary(ctx, imageServiceGetSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *imageServiceClient) List(ctx context.Context, req *v2.ImageServiceListRequest) (*v2.ImageServiceListResponse, error) { + var res v2.ImageServiceListResponse + if err := c.client.CallUnary(ctx, imageServiceListSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *imageServiceClient) Latest(ctx context.Context, req *v2.ImageServiceLatestRequest) (*v2.ImageServiceLatestResponse, error) { + var res v2.ImageServiceLatestResponse + if err := c.client.CallUnary(ctx, imageServiceLatestSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +type imageServiceHandler struct{ svc ImageServiceHandler } + +func (h imageServiceHandler) get(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.ImageServiceGetRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Get(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) +} + +func (h imageServiceHandler) list(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.ImageServiceListRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.List(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) +} + +func (h imageServiceHandler) latest(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.ImageServiceLatestRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Latest(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } diff --git a/go/metalstack/api/v2/apiv2connect/ip.connect.go b/go/metalstack/api/v2/apiv2connect/ip.connect.go index 00bb2709..3a5a0911 100644 --- a/go/metalstack/api/v2/apiv2connect/ip.connect.go +++ b/go/metalstack/api/v2/apiv2connect/ip.connect.go @@ -5,46 +5,75 @@ package apiv2connect import ( - connect "connectrpc.com/connect" + connect "connectrpc.com/connect/v2" context "context" - errors "errors" v2 "github.com/metal-stack/api/go/metalstack/api/v2" - http "net/http" - strings "strings" + sync "sync" ) -// 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 ( // IPServiceName is the fully-qualified name of the IPService service. IPServiceName = "metalstack.api.v2.IPService" ) -// 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. +// These constants are the procedure 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 ( - // IPServiceGetProcedure is the fully-qualified name of the IPService's Get RPC. + // IPServiceGetProcedure is the procedure name of the IPService's Get RPC. IPServiceGetProcedure = "/metalstack.api.v2.IPService/Get" - // IPServiceCreateProcedure is the fully-qualified name of the IPService's Create RPC. + // IPServiceCreateProcedure is the procedure name of the IPService's Create RPC. IPServiceCreateProcedure = "/metalstack.api.v2.IPService/Create" - // IPServiceUpdateProcedure is the fully-qualified name of the IPService's Update RPC. + // IPServiceUpdateProcedure is the procedure name of the IPService's Update RPC. IPServiceUpdateProcedure = "/metalstack.api.v2.IPService/Update" - // IPServiceListProcedure is the fully-qualified name of the IPService's List RPC. + // IPServiceListProcedure is the procedure name of the IPService's List RPC. IPServiceListProcedure = "/metalstack.api.v2.IPService/List" - // IPServiceDeleteProcedure is the fully-qualified name of the IPService's Delete RPC. + // IPServiceDeleteProcedure is the procedure name of the IPService's Delete RPC. IPServiceDeleteProcedure = "/metalstack.api.v2.IPService/Delete" ) +var ( + iPServiceGetSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_ip_proto.Services().ByName("IPService").Methods().ByName("Get"), + Procedure: IPServiceGetProcedure, + } + }) + iPServiceCreateSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_ip_proto.Services().ByName("IPService").Methods().ByName("Create"), + Procedure: IPServiceCreateProcedure, + } + }) + iPServiceUpdateSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_ip_proto.Services().ByName("IPService").Methods().ByName("Update"), + Procedure: IPServiceUpdateProcedure, + } + }) + iPServiceListSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_ip_proto.Services().ByName("IPService").Methods().ByName("List"), + Procedure: IPServiceListProcedure, + } + }) + iPServiceDeleteSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_ip_proto.Services().ByName("IPService").Methods().ByName("Delete"), + Procedure: IPServiceDeleteProcedure, + } + }) +) + // IPServiceClient is a client for the metalstack.api.v2.IPService service. type IPServiceClient interface { // Returns the IP address with the specified IP. @@ -59,102 +88,10 @@ type IPServiceClient interface { Delete(context.Context, *v2.IPServiceDeleteRequest) (*v2.IPServiceDeleteResponse, error) } -// NewIPServiceClient constructs a client for the metalstack.api.v2.IPService 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 NewIPServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) IPServiceClient { - baseURL = strings.TrimRight(baseURL, "/") - iPServiceMethods := v2.File_metalstack_api_v2_ip_proto.Services().ByName("IPService").Methods() - return &iPServiceClient{ - get: connect.NewClient[v2.IPServiceGetRequest, v2.IPServiceGetResponse]( - httpClient, - baseURL+IPServiceGetProcedure, - connect.WithSchema(iPServiceMethods.ByName("Get")), - connect.WithClientOptions(opts...), - ), - create: connect.NewClient[v2.IPServiceCreateRequest, v2.IPServiceCreateResponse]( - httpClient, - baseURL+IPServiceCreateProcedure, - connect.WithSchema(iPServiceMethods.ByName("Create")), - connect.WithClientOptions(opts...), - ), - update: connect.NewClient[v2.IPServiceUpdateRequest, v2.IPServiceUpdateResponse]( - httpClient, - baseURL+IPServiceUpdateProcedure, - connect.WithSchema(iPServiceMethods.ByName("Update")), - connect.WithClientOptions(opts...), - ), - list: connect.NewClient[v2.IPServiceListRequest, v2.IPServiceListResponse]( - httpClient, - baseURL+IPServiceListProcedure, - connect.WithSchema(iPServiceMethods.ByName("List")), - connect.WithClientOptions(opts...), - ), - delete: connect.NewClient[v2.IPServiceDeleteRequest, v2.IPServiceDeleteResponse]( - httpClient, - baseURL+IPServiceDeleteProcedure, - connect.WithSchema(iPServiceMethods.ByName("Delete")), - connect.WithClientOptions(opts...), - ), - } -} - -// iPServiceClient implements IPServiceClient. -type iPServiceClient struct { - get *connect.Client[v2.IPServiceGetRequest, v2.IPServiceGetResponse] - create *connect.Client[v2.IPServiceCreateRequest, v2.IPServiceCreateResponse] - update *connect.Client[v2.IPServiceUpdateRequest, v2.IPServiceUpdateResponse] - list *connect.Client[v2.IPServiceListRequest, v2.IPServiceListResponse] - delete *connect.Client[v2.IPServiceDeleteRequest, v2.IPServiceDeleteResponse] -} - -// Get calls metalstack.api.v2.IPService.Get. -func (c *iPServiceClient) Get(ctx context.Context, req *v2.IPServiceGetRequest) (*v2.IPServiceGetResponse, error) { - response, err := c.get.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err -} - -// Create calls metalstack.api.v2.IPService.Create. -func (c *iPServiceClient) Create(ctx context.Context, req *v2.IPServiceCreateRequest) (*v2.IPServiceCreateResponse, error) { - response, err := c.create.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err -} - -// Update calls metalstack.api.v2.IPService.Update. -func (c *iPServiceClient) Update(ctx context.Context, req *v2.IPServiceUpdateRequest) (*v2.IPServiceUpdateResponse, error) { - response, err := c.update.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err -} - -// List calls metalstack.api.v2.IPService.List. -func (c *iPServiceClient) List(ctx context.Context, req *v2.IPServiceListRequest) (*v2.IPServiceListResponse, error) { - response, err := c.list.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err -} - -// Delete calls metalstack.api.v2.IPService.Delete. -func (c *iPServiceClient) Delete(ctx context.Context, req *v2.IPServiceDeleteRequest) (*v2.IPServiceDeleteResponse, error) { - response, err := c.delete.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err +// NewIPServiceClient constructs a client for the metalstack.api.v2.IPService service. Multiple +// service clients may share a single connect.Client. +func NewIPServiceClient(client *connect.Client) IPServiceClient { + return &iPServiceClient{client: client} } // IPServiceHandler is an implementation of the metalstack.api.v2.IPService service. @@ -171,80 +108,144 @@ type IPServiceHandler interface { Delete(context.Context, *v2.IPServiceDeleteRequest) (*v2.IPServiceDeleteResponse, error) } -// NewIPServiceHandler 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 NewIPServiceHandler(svc IPServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) { - iPServiceMethods := v2.File_metalstack_api_v2_ip_proto.Services().ByName("IPService").Methods() - iPServiceGetHandler := connect.NewUnaryHandlerSimple( - IPServiceGetProcedure, - svc.Get, - connect.WithSchema(iPServiceMethods.ByName("Get")), - connect.WithHandlerOptions(opts...), - ) - iPServiceCreateHandler := connect.NewUnaryHandlerSimple( - IPServiceCreateProcedure, - svc.Create, - connect.WithSchema(iPServiceMethods.ByName("Create")), - connect.WithHandlerOptions(opts...), +// RegisterIPServiceHandler registers svc as the metalstack.api.v2.IPService implementation on +// server. +func RegisterIPServiceHandler(server *connect.Server, svc IPServiceHandler) { + adapter := iPServiceHandler{svc: svc} + server.Register( + connect.Method{Spec: iPServiceGetSpec(), Handler: adapter.get}, + connect.Method{Spec: iPServiceCreateSpec(), Handler: adapter.create}, + connect.Method{Spec: iPServiceUpdateSpec(), Handler: adapter.update}, + connect.Method{Spec: iPServiceListSpec(), Handler: adapter.list}, + connect.Method{Spec: iPServiceDeleteSpec(), Handler: adapter.delete}, ) - iPServiceUpdateHandler := connect.NewUnaryHandlerSimple( - IPServiceUpdateProcedure, - svc.Update, - connect.WithSchema(iPServiceMethods.ByName("Update")), - connect.WithHandlerOptions(opts...), - ) - iPServiceListHandler := connect.NewUnaryHandlerSimple( - IPServiceListProcedure, - svc.List, - connect.WithSchema(iPServiceMethods.ByName("List")), - connect.WithHandlerOptions(opts...), - ) - iPServiceDeleteHandler := connect.NewUnaryHandlerSimple( - IPServiceDeleteProcedure, - svc.Delete, - connect.WithSchema(iPServiceMethods.ByName("Delete")), - connect.WithHandlerOptions(opts...), - ) - return "/metalstack.api.v2.IPService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - switch r.URL.Path { - case IPServiceGetProcedure: - iPServiceGetHandler.ServeHTTP(w, r) - case IPServiceCreateProcedure: - iPServiceCreateHandler.ServeHTTP(w, r) - case IPServiceUpdateProcedure: - iPServiceUpdateHandler.ServeHTTP(w, r) - case IPServiceListProcedure: - iPServiceListHandler.ServeHTTP(w, r) - case IPServiceDeleteProcedure: - iPServiceDeleteHandler.ServeHTTP(w, r) - default: - http.NotFound(w, r) - } - }) } // UnimplementedIPServiceHandler returns CodeUnimplemented from all methods. type UnimplementedIPServiceHandler struct{} func (UnimplementedIPServiceHandler) Get(context.Context, *v2.IPServiceGetRequest) (*v2.IPServiceGetResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.IPService.Get is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.IPService.Get is not implemented") } func (UnimplementedIPServiceHandler) Create(context.Context, *v2.IPServiceCreateRequest) (*v2.IPServiceCreateResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.IPService.Create is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.IPService.Create is not implemented") } func (UnimplementedIPServiceHandler) Update(context.Context, *v2.IPServiceUpdateRequest) (*v2.IPServiceUpdateResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.IPService.Update is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.IPService.Update is not implemented") } func (UnimplementedIPServiceHandler) List(context.Context, *v2.IPServiceListRequest) (*v2.IPServiceListResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.IPService.List is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.IPService.List is not implemented") } func (UnimplementedIPServiceHandler) Delete(context.Context, *v2.IPServiceDeleteRequest) (*v2.IPServiceDeleteResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.IPService.Delete is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.IPService.Delete is not implemented") +} + +type iPServiceClient struct { + client *connect.Client +} + +func (c *iPServiceClient) Get(ctx context.Context, req *v2.IPServiceGetRequest) (*v2.IPServiceGetResponse, error) { + var res v2.IPServiceGetResponse + if err := c.client.CallUnary(ctx, iPServiceGetSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *iPServiceClient) Create(ctx context.Context, req *v2.IPServiceCreateRequest) (*v2.IPServiceCreateResponse, error) { + var res v2.IPServiceCreateResponse + if err := c.client.CallUnary(ctx, iPServiceCreateSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *iPServiceClient) Update(ctx context.Context, req *v2.IPServiceUpdateRequest) (*v2.IPServiceUpdateResponse, error) { + var res v2.IPServiceUpdateResponse + if err := c.client.CallUnary(ctx, iPServiceUpdateSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *iPServiceClient) List(ctx context.Context, req *v2.IPServiceListRequest) (*v2.IPServiceListResponse, error) { + var res v2.IPServiceListResponse + if err := c.client.CallUnary(ctx, iPServiceListSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *iPServiceClient) Delete(ctx context.Context, req *v2.IPServiceDeleteRequest) (*v2.IPServiceDeleteResponse, error) { + var res v2.IPServiceDeleteResponse + if err := c.client.CallUnary(ctx, iPServiceDeleteSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +type iPServiceHandler struct{ svc IPServiceHandler } + +func (h iPServiceHandler) get(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.IPServiceGetRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Get(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) +} + +func (h iPServiceHandler) create(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.IPServiceCreateRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Create(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) +} + +func (h iPServiceHandler) update(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.IPServiceUpdateRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Update(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) +} + +func (h iPServiceHandler) list(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.IPServiceListRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.List(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) +} + +func (h iPServiceHandler) delete(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.IPServiceDeleteRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Delete(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } diff --git a/go/metalstack/api/v2/apiv2connect/machine.connect.go b/go/metalstack/api/v2/apiv2connect/machine.connect.go index 9674fc72..9b29b399 100644 --- a/go/metalstack/api/v2/apiv2connect/machine.connect.go +++ b/go/metalstack/api/v2/apiv2connect/machine.connect.go @@ -5,51 +5,93 @@ package apiv2connect import ( - connect "connectrpc.com/connect" + connect "connectrpc.com/connect/v2" context "context" - errors "errors" v2 "github.com/metal-stack/api/go/metalstack/api/v2" - http "net/http" - strings "strings" + sync "sync" ) -// 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 ( // MachineServiceName is the fully-qualified name of the MachineService service. MachineServiceName = "metalstack.api.v2.MachineService" ) -// 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. +// These constants are the procedure 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 ( - // MachineServiceGetProcedure is the fully-qualified name of the MachineService's Get RPC. + // MachineServiceGetProcedure is the procedure name of the MachineService's Get RPC. MachineServiceGetProcedure = "/metalstack.api.v2.MachineService/Get" - // MachineServiceCreateProcedure is the fully-qualified name of the MachineService's Create RPC. + // MachineServiceCreateProcedure is the procedure name of the MachineService's Create RPC. MachineServiceCreateProcedure = "/metalstack.api.v2.MachineService/Create" - // MachineServiceUpdateProcedure is the fully-qualified name of the MachineService's Update RPC. + // MachineServiceUpdateProcedure is the procedure name of the MachineService's Update RPC. MachineServiceUpdateProcedure = "/metalstack.api.v2.MachineService/Update" - // MachineServiceListProcedure is the fully-qualified name of the MachineService's List RPC. + // MachineServiceListProcedure is the procedure name of the MachineService's List RPC. MachineServiceListProcedure = "/metalstack.api.v2.MachineService/List" - // MachineServiceDeleteProcedure is the fully-qualified name of the MachineService's Delete RPC. + // MachineServiceDeleteProcedure is the procedure name of the MachineService's Delete RPC. MachineServiceDeleteProcedure = "/metalstack.api.v2.MachineService/Delete" - // MachineServiceBMCCommandProcedure is the fully-qualified name of the MachineService's BMCCommand - // RPC. + // MachineServiceBMCCommandProcedure is the procedure name of the MachineService's BMCCommand RPC. MachineServiceBMCCommandProcedure = "/metalstack.api.v2.MachineService/BMCCommand" - // MachineServiceGetBMCProcedure is the fully-qualified name of the MachineService's GetBMC RPC. + // MachineServiceGetBMCProcedure is the procedure name of the MachineService's GetBMC RPC. MachineServiceGetBMCProcedure = "/metalstack.api.v2.MachineService/GetBMC" ) +var ( + machineServiceGetSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_machine_proto.Services().ByName("MachineService").Methods().ByName("Get"), + Procedure: MachineServiceGetProcedure, + } + }) + machineServiceCreateSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_machine_proto.Services().ByName("MachineService").Methods().ByName("Create"), + Procedure: MachineServiceCreateProcedure, + } + }) + machineServiceUpdateSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_machine_proto.Services().ByName("MachineService").Methods().ByName("Update"), + Procedure: MachineServiceUpdateProcedure, + } + }) + machineServiceListSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_machine_proto.Services().ByName("MachineService").Methods().ByName("List"), + Procedure: MachineServiceListProcedure, + } + }) + machineServiceDeleteSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_machine_proto.Services().ByName("MachineService").Methods().ByName("Delete"), + Procedure: MachineServiceDeleteProcedure, + } + }) + machineServiceBMCCommandSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_machine_proto.Services().ByName("MachineService").Methods().ByName("BMCCommand"), + Procedure: MachineServiceBMCCommandProcedure, + } + }) + machineServiceGetBMCSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_machine_proto.Services().ByName("MachineService").Methods().ByName("GetBMC"), + Procedure: MachineServiceGetBMCProcedure, + } + }) +) + // MachineServiceClient is a client for the metalstack.api.v2.MachineService service. type MachineServiceClient interface { // Returns the machine with the specified UUID. @@ -68,252 +110,218 @@ type MachineServiceClient interface { GetBMC(context.Context, *v2.MachineServiceGetBMCRequest) (*v2.MachineServiceGetBMCResponse, error) } -// NewMachineServiceClient constructs a client for the metalstack.api.v2.MachineService 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 NewMachineServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) MachineServiceClient { - baseURL = strings.TrimRight(baseURL, "/") - machineServiceMethods := v2.File_metalstack_api_v2_machine_proto.Services().ByName("MachineService").Methods() - return &machineServiceClient{ - get: connect.NewClient[v2.MachineServiceGetRequest, v2.MachineServiceGetResponse]( - httpClient, - baseURL+MachineServiceGetProcedure, - connect.WithSchema(machineServiceMethods.ByName("Get")), - connect.WithClientOptions(opts...), - ), - create: connect.NewClient[v2.MachineServiceCreateRequest, v2.MachineServiceCreateResponse]( - httpClient, - baseURL+MachineServiceCreateProcedure, - connect.WithSchema(machineServiceMethods.ByName("Create")), - connect.WithClientOptions(opts...), - ), - update: connect.NewClient[v2.MachineServiceUpdateRequest, v2.MachineServiceUpdateResponse]( - httpClient, - baseURL+MachineServiceUpdateProcedure, - connect.WithSchema(machineServiceMethods.ByName("Update")), - connect.WithClientOptions(opts...), - ), - list: connect.NewClient[v2.MachineServiceListRequest, v2.MachineServiceListResponse]( - httpClient, - baseURL+MachineServiceListProcedure, - connect.WithSchema(machineServiceMethods.ByName("List")), - connect.WithClientOptions(opts...), - ), - delete: connect.NewClient[v2.MachineServiceDeleteRequest, v2.MachineServiceDeleteResponse]( - httpClient, - baseURL+MachineServiceDeleteProcedure, - connect.WithSchema(machineServiceMethods.ByName("Delete")), - connect.WithClientOptions(opts...), - ), - bMCCommand: connect.NewClient[v2.MachineServiceBMCCommandRequest, v2.MachineServiceBMCCommandResponse]( - httpClient, - baseURL+MachineServiceBMCCommandProcedure, - connect.WithSchema(machineServiceMethods.ByName("BMCCommand")), - connect.WithClientOptions(opts...), - ), - getBMC: connect.NewClient[v2.MachineServiceGetBMCRequest, v2.MachineServiceGetBMCResponse]( - httpClient, - baseURL+MachineServiceGetBMCProcedure, - connect.WithSchema(machineServiceMethods.ByName("GetBMC")), - connect.WithClientOptions(opts...), - ), - } +// NewMachineServiceClient constructs a client for the metalstack.api.v2.MachineService service. +// Multiple service clients may share a single connect.Client. +func NewMachineServiceClient(client *connect.Client) MachineServiceClient { + return &machineServiceClient{client: client} +} + +// MachineServiceHandler is an implementation of the metalstack.api.v2.MachineService service. +type MachineServiceHandler interface { + // Returns the machine with the specified UUID. + Get(context.Context, *v2.MachineServiceGetRequest) (*v2.MachineServiceGetResponse, error) + // Creates a new machine. + Create(context.Context, *v2.MachineServiceCreateRequest) (*v2.MachineServiceCreateResponse, error) + // Updates a machine. + Update(context.Context, *v2.MachineServiceUpdateRequest) (*v2.MachineServiceUpdateResponse, error) + // Returns the list of all machines. + List(context.Context, *v2.MachineServiceListRequest) (*v2.MachineServiceListResponse, error) + // Deletes a machine. + Delete(context.Context, *v2.MachineServiceDeleteRequest) (*v2.MachineServiceDeleteResponse, error) + // BMCCommand sends a command to the BMC of a machine. + BMCCommand(context.Context, *v2.MachineServiceBMCCommandRequest) (*v2.MachineServiceBMCCommandResponse, error) + // Returns the BMC details of a machine. + GetBMC(context.Context, *v2.MachineServiceGetBMCRequest) (*v2.MachineServiceGetBMCResponse, error) +} + +// RegisterMachineServiceHandler registers svc as the metalstack.api.v2.MachineService +// implementation on server. +func RegisterMachineServiceHandler(server *connect.Server, svc MachineServiceHandler) { + adapter := machineServiceHandler{svc: svc} + server.Register( + connect.Method{Spec: machineServiceGetSpec(), Handler: adapter.get}, + connect.Method{Spec: machineServiceCreateSpec(), Handler: adapter.create}, + connect.Method{Spec: machineServiceUpdateSpec(), Handler: adapter.update}, + connect.Method{Spec: machineServiceListSpec(), Handler: adapter.list}, + connect.Method{Spec: machineServiceDeleteSpec(), Handler: adapter.delete}, + connect.Method{Spec: machineServiceBMCCommandSpec(), Handler: adapter.bMCCommand}, + connect.Method{Spec: machineServiceGetBMCSpec(), Handler: adapter.getBMC}, + ) +} + +// UnimplementedMachineServiceHandler returns CodeUnimplemented from all methods. +type UnimplementedMachineServiceHandler struct{} + +func (UnimplementedMachineServiceHandler) Get(context.Context, *v2.MachineServiceGetRequest) (*v2.MachineServiceGetResponse, error) { + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.MachineService.Get is not implemented") +} + +func (UnimplementedMachineServiceHandler) Create(context.Context, *v2.MachineServiceCreateRequest) (*v2.MachineServiceCreateResponse, error) { + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.MachineService.Create is not implemented") +} + +func (UnimplementedMachineServiceHandler) Update(context.Context, *v2.MachineServiceUpdateRequest) (*v2.MachineServiceUpdateResponse, error) { + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.MachineService.Update is not implemented") +} + +func (UnimplementedMachineServiceHandler) List(context.Context, *v2.MachineServiceListRequest) (*v2.MachineServiceListResponse, error) { + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.MachineService.List is not implemented") +} + +func (UnimplementedMachineServiceHandler) Delete(context.Context, *v2.MachineServiceDeleteRequest) (*v2.MachineServiceDeleteResponse, error) { + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.MachineService.Delete is not implemented") +} + +func (UnimplementedMachineServiceHandler) BMCCommand(context.Context, *v2.MachineServiceBMCCommandRequest) (*v2.MachineServiceBMCCommandResponse, error) { + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.MachineService.BMCCommand is not implemented") +} + +func (UnimplementedMachineServiceHandler) GetBMC(context.Context, *v2.MachineServiceGetBMCRequest) (*v2.MachineServiceGetBMCResponse, error) { + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.MachineService.GetBMC is not implemented") } -// machineServiceClient implements MachineServiceClient. type machineServiceClient struct { - get *connect.Client[v2.MachineServiceGetRequest, v2.MachineServiceGetResponse] - create *connect.Client[v2.MachineServiceCreateRequest, v2.MachineServiceCreateResponse] - update *connect.Client[v2.MachineServiceUpdateRequest, v2.MachineServiceUpdateResponse] - list *connect.Client[v2.MachineServiceListRequest, v2.MachineServiceListResponse] - delete *connect.Client[v2.MachineServiceDeleteRequest, v2.MachineServiceDeleteResponse] - bMCCommand *connect.Client[v2.MachineServiceBMCCommandRequest, v2.MachineServiceBMCCommandResponse] - getBMC *connect.Client[v2.MachineServiceGetBMCRequest, v2.MachineServiceGetBMCResponse] + client *connect.Client } -// Get calls metalstack.api.v2.MachineService.Get. func (c *machineServiceClient) Get(ctx context.Context, req *v2.MachineServiceGetRequest) (*v2.MachineServiceGetResponse, error) { - response, err := c.get.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err + var res v2.MachineServiceGetResponse + if err := c.client.CallUnary(ctx, machineServiceGetSpec(), req, &res); err != nil { + return nil, err } - return nil, err + return &res, nil } -// Create calls metalstack.api.v2.MachineService.Create. func (c *machineServiceClient) Create(ctx context.Context, req *v2.MachineServiceCreateRequest) (*v2.MachineServiceCreateResponse, error) { - response, err := c.create.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err + var res v2.MachineServiceCreateResponse + if err := c.client.CallUnary(ctx, machineServiceCreateSpec(), req, &res); err != nil { + return nil, err } - return nil, err + return &res, nil } -// Update calls metalstack.api.v2.MachineService.Update. func (c *machineServiceClient) Update(ctx context.Context, req *v2.MachineServiceUpdateRequest) (*v2.MachineServiceUpdateResponse, error) { - response, err := c.update.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err + var res v2.MachineServiceUpdateResponse + if err := c.client.CallUnary(ctx, machineServiceUpdateSpec(), req, &res); err != nil { + return nil, err } - return nil, err + return &res, nil } -// List calls metalstack.api.v2.MachineService.List. func (c *machineServiceClient) List(ctx context.Context, req *v2.MachineServiceListRequest) (*v2.MachineServiceListResponse, error) { - response, err := c.list.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err + var res v2.MachineServiceListResponse + if err := c.client.CallUnary(ctx, machineServiceListSpec(), req, &res); err != nil { + return nil, err } - return nil, err + return &res, nil } -// Delete calls metalstack.api.v2.MachineService.Delete. func (c *machineServiceClient) Delete(ctx context.Context, req *v2.MachineServiceDeleteRequest) (*v2.MachineServiceDeleteResponse, error) { - response, err := c.delete.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err + var res v2.MachineServiceDeleteResponse + if err := c.client.CallUnary(ctx, machineServiceDeleteSpec(), req, &res); err != nil { + return nil, err } - return nil, err + return &res, nil } -// BMCCommand calls metalstack.api.v2.MachineService.BMCCommand. func (c *machineServiceClient) BMCCommand(ctx context.Context, req *v2.MachineServiceBMCCommandRequest) (*v2.MachineServiceBMCCommandResponse, error) { - response, err := c.bMCCommand.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err + var res v2.MachineServiceBMCCommandResponse + if err := c.client.CallUnary(ctx, machineServiceBMCCommandSpec(), req, &res); err != nil { + return nil, err } - return nil, err + return &res, nil } -// GetBMC calls metalstack.api.v2.MachineService.GetBMC. func (c *machineServiceClient) GetBMC(ctx context.Context, req *v2.MachineServiceGetBMCRequest) (*v2.MachineServiceGetBMCResponse, error) { - response, err := c.getBMC.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err + var res v2.MachineServiceGetBMCResponse + if err := c.client.CallUnary(ctx, machineServiceGetBMCSpec(), req, &res); err != nil { + return nil, err } - return nil, err -} - -// MachineServiceHandler is an implementation of the metalstack.api.v2.MachineService service. -type MachineServiceHandler interface { - // Returns the machine with the specified UUID. - Get(context.Context, *v2.MachineServiceGetRequest) (*v2.MachineServiceGetResponse, error) - // Creates a new machine. - Create(context.Context, *v2.MachineServiceCreateRequest) (*v2.MachineServiceCreateResponse, error) - // Updates a machine. - Update(context.Context, *v2.MachineServiceUpdateRequest) (*v2.MachineServiceUpdateResponse, error) - // Returns the list of all machines. - List(context.Context, *v2.MachineServiceListRequest) (*v2.MachineServiceListResponse, error) - // Deletes a machine. - Delete(context.Context, *v2.MachineServiceDeleteRequest) (*v2.MachineServiceDeleteResponse, error) - // BMCCommand sends a command to the BMC of a machine. - BMCCommand(context.Context, *v2.MachineServiceBMCCommandRequest) (*v2.MachineServiceBMCCommandResponse, error) - // Returns the BMC details of a machine. - GetBMC(context.Context, *v2.MachineServiceGetBMCRequest) (*v2.MachineServiceGetBMCResponse, error) -} - -// NewMachineServiceHandler 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 NewMachineServiceHandler(svc MachineServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) { - machineServiceMethods := v2.File_metalstack_api_v2_machine_proto.Services().ByName("MachineService").Methods() - machineServiceGetHandler := connect.NewUnaryHandlerSimple( - MachineServiceGetProcedure, - svc.Get, - connect.WithSchema(machineServiceMethods.ByName("Get")), - connect.WithHandlerOptions(opts...), - ) - machineServiceCreateHandler := connect.NewUnaryHandlerSimple( - MachineServiceCreateProcedure, - svc.Create, - connect.WithSchema(machineServiceMethods.ByName("Create")), - connect.WithHandlerOptions(opts...), - ) - machineServiceUpdateHandler := connect.NewUnaryHandlerSimple( - MachineServiceUpdateProcedure, - svc.Update, - connect.WithSchema(machineServiceMethods.ByName("Update")), - connect.WithHandlerOptions(opts...), - ) - machineServiceListHandler := connect.NewUnaryHandlerSimple( - MachineServiceListProcedure, - svc.List, - connect.WithSchema(machineServiceMethods.ByName("List")), - connect.WithHandlerOptions(opts...), - ) - machineServiceDeleteHandler := connect.NewUnaryHandlerSimple( - MachineServiceDeleteProcedure, - svc.Delete, - connect.WithSchema(machineServiceMethods.ByName("Delete")), - connect.WithHandlerOptions(opts...), - ) - machineServiceBMCCommandHandler := connect.NewUnaryHandlerSimple( - MachineServiceBMCCommandProcedure, - svc.BMCCommand, - connect.WithSchema(machineServiceMethods.ByName("BMCCommand")), - connect.WithHandlerOptions(opts...), - ) - machineServiceGetBMCHandler := connect.NewUnaryHandlerSimple( - MachineServiceGetBMCProcedure, - svc.GetBMC, - connect.WithSchema(machineServiceMethods.ByName("GetBMC")), - connect.WithHandlerOptions(opts...), - ) - return "/metalstack.api.v2.MachineService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - switch r.URL.Path { - case MachineServiceGetProcedure: - machineServiceGetHandler.ServeHTTP(w, r) - case MachineServiceCreateProcedure: - machineServiceCreateHandler.ServeHTTP(w, r) - case MachineServiceUpdateProcedure: - machineServiceUpdateHandler.ServeHTTP(w, r) - case MachineServiceListProcedure: - machineServiceListHandler.ServeHTTP(w, r) - case MachineServiceDeleteProcedure: - machineServiceDeleteHandler.ServeHTTP(w, r) - case MachineServiceBMCCommandProcedure: - machineServiceBMCCommandHandler.ServeHTTP(w, r) - case MachineServiceGetBMCProcedure: - machineServiceGetBMCHandler.ServeHTTP(w, r) - default: - http.NotFound(w, r) - } - }) + return &res, nil } -// UnimplementedMachineServiceHandler returns CodeUnimplemented from all methods. -type UnimplementedMachineServiceHandler struct{} +type machineServiceHandler struct{ svc MachineServiceHandler } -func (UnimplementedMachineServiceHandler) Get(context.Context, *v2.MachineServiceGetRequest) (*v2.MachineServiceGetResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.MachineService.Get is not implemented")) +func (h machineServiceHandler) get(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.MachineServiceGetRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Get(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } -func (UnimplementedMachineServiceHandler) Create(context.Context, *v2.MachineServiceCreateRequest) (*v2.MachineServiceCreateResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.MachineService.Create is not implemented")) +func (h machineServiceHandler) create(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.MachineServiceCreateRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Create(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } -func (UnimplementedMachineServiceHandler) Update(context.Context, *v2.MachineServiceUpdateRequest) (*v2.MachineServiceUpdateResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.MachineService.Update is not implemented")) +func (h machineServiceHandler) update(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.MachineServiceUpdateRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Update(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } -func (UnimplementedMachineServiceHandler) List(context.Context, *v2.MachineServiceListRequest) (*v2.MachineServiceListResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.MachineService.List is not implemented")) +func (h machineServiceHandler) list(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.MachineServiceListRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.List(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } -func (UnimplementedMachineServiceHandler) Delete(context.Context, *v2.MachineServiceDeleteRequest) (*v2.MachineServiceDeleteResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.MachineService.Delete is not implemented")) +func (h machineServiceHandler) delete(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.MachineServiceDeleteRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Delete(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } -func (UnimplementedMachineServiceHandler) BMCCommand(context.Context, *v2.MachineServiceBMCCommandRequest) (*v2.MachineServiceBMCCommandResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.MachineService.BMCCommand is not implemented")) +func (h machineServiceHandler) bMCCommand(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.MachineServiceBMCCommandRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.BMCCommand(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } -func (UnimplementedMachineServiceHandler) GetBMC(context.Context, *v2.MachineServiceGetBMCRequest) (*v2.MachineServiceGetBMCResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.MachineService.GetBMC is not implemented")) +func (h machineServiceHandler) getBMC(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.MachineServiceGetBMCRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.GetBMC(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } diff --git a/go/metalstack/api/v2/apiv2connect/method.connect.go b/go/metalstack/api/v2/apiv2connect/method.connect.go index e49be3cb..25872185 100644 --- a/go/metalstack/api/v2/apiv2connect/method.connect.go +++ b/go/metalstack/api/v2/apiv2connect/method.connect.go @@ -5,41 +5,49 @@ package apiv2connect import ( - connect "connectrpc.com/connect" + connect "connectrpc.com/connect/v2" context "context" - errors "errors" v2 "github.com/metal-stack/api/go/metalstack/api/v2" - http "net/http" - strings "strings" + sync "sync" ) -// 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 ( // MethodServiceName is the fully-qualified name of the MethodService service. MethodServiceName = "metalstack.api.v2.MethodService" ) -// 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. +// These constants are the procedure 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 ( - // MethodServiceListProcedure is the fully-qualified name of the MethodService's List RPC. + // MethodServiceListProcedure is the procedure name of the MethodService's List RPC. MethodServiceListProcedure = "/metalstack.api.v2.MethodService/List" - // MethodServiceTokenScopedListProcedure is the fully-qualified name of the MethodService's + // MethodServiceTokenScopedListProcedure is the procedure name of the MethodService's // TokenScopedList RPC. MethodServiceTokenScopedListProcedure = "/metalstack.api.v2.MethodService/TokenScopedList" ) +var ( + methodServiceListSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_method_proto.Services().ByName("MethodService").Methods().ByName("List"), + Procedure: MethodServiceListProcedure, + } + }) + methodServiceTokenScopedListSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_method_proto.Services().ByName("MethodService").Methods().ByName("TokenScopedList"), + Procedure: MethodServiceTokenScopedListProcedure, + } + }) +) + // MethodServiceClient is a client for the metalstack.api.v2.MethodService service. type MethodServiceClient interface { // Returns the list of all public visible methods. @@ -48,54 +56,10 @@ type MethodServiceClient interface { TokenScopedList(context.Context, *v2.MethodServiceTokenScopedListRequest) (*v2.MethodServiceTokenScopedListResponse, error) } -// NewMethodServiceClient constructs a client for the metalstack.api.v2.MethodService 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 NewMethodServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) MethodServiceClient { - baseURL = strings.TrimRight(baseURL, "/") - methodServiceMethods := v2.File_metalstack_api_v2_method_proto.Services().ByName("MethodService").Methods() - return &methodServiceClient{ - list: connect.NewClient[v2.MethodServiceListRequest, v2.MethodServiceListResponse]( - httpClient, - baseURL+MethodServiceListProcedure, - connect.WithSchema(methodServiceMethods.ByName("List")), - connect.WithClientOptions(opts...), - ), - tokenScopedList: connect.NewClient[v2.MethodServiceTokenScopedListRequest, v2.MethodServiceTokenScopedListResponse]( - httpClient, - baseURL+MethodServiceTokenScopedListProcedure, - connect.WithSchema(methodServiceMethods.ByName("TokenScopedList")), - connect.WithClientOptions(opts...), - ), - } -} - -// methodServiceClient implements MethodServiceClient. -type methodServiceClient struct { - list *connect.Client[v2.MethodServiceListRequest, v2.MethodServiceListResponse] - tokenScopedList *connect.Client[v2.MethodServiceTokenScopedListRequest, v2.MethodServiceTokenScopedListResponse] -} - -// List calls metalstack.api.v2.MethodService.List. -func (c *methodServiceClient) List(ctx context.Context, req *v2.MethodServiceListRequest) (*v2.MethodServiceListResponse, error) { - response, err := c.list.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err -} - -// TokenScopedList calls metalstack.api.v2.MethodService.TokenScopedList. -func (c *methodServiceClient) TokenScopedList(ctx context.Context, req *v2.MethodServiceTokenScopedListRequest) (*v2.MethodServiceTokenScopedListResponse, error) { - response, err := c.tokenScopedList.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err +// NewMethodServiceClient constructs a client for the metalstack.api.v2.MethodService service. +// Multiple service clients may share a single connect.Client. +func NewMethodServiceClient(client *connect.Client) MethodServiceClient { + return &methodServiceClient{client: client} } // MethodServiceHandler is an implementation of the metalstack.api.v2.MethodService service. @@ -106,44 +70,69 @@ type MethodServiceHandler interface { TokenScopedList(context.Context, *v2.MethodServiceTokenScopedListRequest) (*v2.MethodServiceTokenScopedListResponse, error) } -// NewMethodServiceHandler 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 NewMethodServiceHandler(svc MethodServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) { - methodServiceMethods := v2.File_metalstack_api_v2_method_proto.Services().ByName("MethodService").Methods() - methodServiceListHandler := connect.NewUnaryHandlerSimple( - MethodServiceListProcedure, - svc.List, - connect.WithSchema(methodServiceMethods.ByName("List")), - connect.WithHandlerOptions(opts...), - ) - methodServiceTokenScopedListHandler := connect.NewUnaryHandlerSimple( - MethodServiceTokenScopedListProcedure, - svc.TokenScopedList, - connect.WithSchema(methodServiceMethods.ByName("TokenScopedList")), - connect.WithHandlerOptions(opts...), +// RegisterMethodServiceHandler registers svc as the metalstack.api.v2.MethodService implementation +// on server. +func RegisterMethodServiceHandler(server *connect.Server, svc MethodServiceHandler) { + adapter := methodServiceHandler{svc: svc} + server.Register( + connect.Method{Spec: methodServiceListSpec(), Handler: adapter.list}, + connect.Method{Spec: methodServiceTokenScopedListSpec(), Handler: adapter.tokenScopedList}, ) - return "/metalstack.api.v2.MethodService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - switch r.URL.Path { - case MethodServiceListProcedure: - methodServiceListHandler.ServeHTTP(w, r) - case MethodServiceTokenScopedListProcedure: - methodServiceTokenScopedListHandler.ServeHTTP(w, r) - default: - http.NotFound(w, r) - } - }) } // UnimplementedMethodServiceHandler returns CodeUnimplemented from all methods. type UnimplementedMethodServiceHandler struct{} func (UnimplementedMethodServiceHandler) List(context.Context, *v2.MethodServiceListRequest) (*v2.MethodServiceListResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.MethodService.List is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.MethodService.List is not implemented") } func (UnimplementedMethodServiceHandler) TokenScopedList(context.Context, *v2.MethodServiceTokenScopedListRequest) (*v2.MethodServiceTokenScopedListResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.MethodService.TokenScopedList is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.MethodService.TokenScopedList is not implemented") +} + +type methodServiceClient struct { + client *connect.Client +} + +func (c *methodServiceClient) List(ctx context.Context, req *v2.MethodServiceListRequest) (*v2.MethodServiceListResponse, error) { + var res v2.MethodServiceListResponse + if err := c.client.CallUnary(ctx, methodServiceListSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *methodServiceClient) TokenScopedList(ctx context.Context, req *v2.MethodServiceTokenScopedListRequest) (*v2.MethodServiceTokenScopedListResponse, error) { + var res v2.MethodServiceTokenScopedListResponse + if err := c.client.CallUnary(ctx, methodServiceTokenScopedListSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +type methodServiceHandler struct{ svc MethodServiceHandler } + +func (h methodServiceHandler) list(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.MethodServiceListRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.List(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) +} + +func (h methodServiceHandler) tokenScopedList(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.MethodServiceTokenScopedListRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.TokenScopedList(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } diff --git a/go/metalstack/api/v2/apiv2connect/network.connect.go b/go/metalstack/api/v2/apiv2connect/network.connect.go index ed05b0ea..79d983dc 100644 --- a/go/metalstack/api/v2/apiv2connect/network.connect.go +++ b/go/metalstack/api/v2/apiv2connect/network.connect.go @@ -5,49 +5,85 @@ package apiv2connect import ( - connect "connectrpc.com/connect" + connect "connectrpc.com/connect/v2" context "context" - errors "errors" v2 "github.com/metal-stack/api/go/metalstack/api/v2" - http "net/http" - strings "strings" + sync "sync" ) -// 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 ( // NetworkServiceName is the fully-qualified name of the NetworkService service. NetworkServiceName = "metalstack.api.v2.NetworkService" ) -// 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. +// These constants are the procedure 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 ( - // NetworkServiceGetProcedure is the fully-qualified name of the NetworkService's Get RPC. + // NetworkServiceGetProcedure is the procedure name of the NetworkService's Get RPC. NetworkServiceGetProcedure = "/metalstack.api.v2.NetworkService/Get" - // NetworkServiceCreateProcedure is the fully-qualified name of the NetworkService's Create RPC. + // NetworkServiceCreateProcedure is the procedure name of the NetworkService's Create RPC. NetworkServiceCreateProcedure = "/metalstack.api.v2.NetworkService/Create" - // NetworkServiceUpdateProcedure is the fully-qualified name of the NetworkService's Update RPC. + // NetworkServiceUpdateProcedure is the procedure name of the NetworkService's Update RPC. NetworkServiceUpdateProcedure = "/metalstack.api.v2.NetworkService/Update" - // NetworkServiceListProcedure is the fully-qualified name of the NetworkService's List RPC. + // NetworkServiceListProcedure is the procedure name of the NetworkService's List RPC. NetworkServiceListProcedure = "/metalstack.api.v2.NetworkService/List" - // NetworkServiceListBaseNetworksProcedure is the fully-qualified name of the NetworkService's + // NetworkServiceListBaseNetworksProcedure is the procedure name of the NetworkService's // ListBaseNetworks RPC. NetworkServiceListBaseNetworksProcedure = "/metalstack.api.v2.NetworkService/ListBaseNetworks" - // NetworkServiceDeleteProcedure is the fully-qualified name of the NetworkService's Delete RPC. + // NetworkServiceDeleteProcedure is the procedure name of the NetworkService's Delete RPC. NetworkServiceDeleteProcedure = "/metalstack.api.v2.NetworkService/Delete" ) +var ( + networkServiceGetSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_network_proto.Services().ByName("NetworkService").Methods().ByName("Get"), + Procedure: NetworkServiceGetProcedure, + } + }) + networkServiceCreateSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_network_proto.Services().ByName("NetworkService").Methods().ByName("Create"), + Procedure: NetworkServiceCreateProcedure, + } + }) + networkServiceUpdateSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_network_proto.Services().ByName("NetworkService").Methods().ByName("Update"), + Procedure: NetworkServiceUpdateProcedure, + } + }) + networkServiceListSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_network_proto.Services().ByName("NetworkService").Methods().ByName("List"), + Procedure: NetworkServiceListProcedure, + } + }) + networkServiceListBaseNetworksSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_network_proto.Services().ByName("NetworkService").Methods().ByName("ListBaseNetworks"), + Procedure: NetworkServiceListBaseNetworksProcedure, + } + }) + networkServiceDeleteSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_network_proto.Services().ByName("NetworkService").Methods().ByName("Delete"), + Procedure: NetworkServiceDeleteProcedure, + } + }) +) + // NetworkServiceClient is a client for the metalstack.api.v2.NetworkService service. type NetworkServiceClient interface { // Returns the network with the specified ID. @@ -64,118 +100,10 @@ type NetworkServiceClient interface { Delete(context.Context, *v2.NetworkServiceDeleteRequest) (*v2.NetworkServiceDeleteResponse, error) } -// NewNetworkServiceClient constructs a client for the metalstack.api.v2.NetworkService 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 NewNetworkServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) NetworkServiceClient { - baseURL = strings.TrimRight(baseURL, "/") - networkServiceMethods := v2.File_metalstack_api_v2_network_proto.Services().ByName("NetworkService").Methods() - return &networkServiceClient{ - get: connect.NewClient[v2.NetworkServiceGetRequest, v2.NetworkServiceGetResponse]( - httpClient, - baseURL+NetworkServiceGetProcedure, - connect.WithSchema(networkServiceMethods.ByName("Get")), - connect.WithClientOptions(opts...), - ), - create: connect.NewClient[v2.NetworkServiceCreateRequest, v2.NetworkServiceCreateResponse]( - httpClient, - baseURL+NetworkServiceCreateProcedure, - connect.WithSchema(networkServiceMethods.ByName("Create")), - connect.WithClientOptions(opts...), - ), - update: connect.NewClient[v2.NetworkServiceUpdateRequest, v2.NetworkServiceUpdateResponse]( - httpClient, - baseURL+NetworkServiceUpdateProcedure, - connect.WithSchema(networkServiceMethods.ByName("Update")), - connect.WithClientOptions(opts...), - ), - list: connect.NewClient[v2.NetworkServiceListRequest, v2.NetworkServiceListResponse]( - httpClient, - baseURL+NetworkServiceListProcedure, - connect.WithSchema(networkServiceMethods.ByName("List")), - connect.WithClientOptions(opts...), - ), - listBaseNetworks: connect.NewClient[v2.NetworkServiceListBaseNetworksRequest, v2.NetworkServiceListBaseNetworksResponse]( - httpClient, - baseURL+NetworkServiceListBaseNetworksProcedure, - connect.WithSchema(networkServiceMethods.ByName("ListBaseNetworks")), - connect.WithClientOptions(opts...), - ), - delete: connect.NewClient[v2.NetworkServiceDeleteRequest, v2.NetworkServiceDeleteResponse]( - httpClient, - baseURL+NetworkServiceDeleteProcedure, - connect.WithSchema(networkServiceMethods.ByName("Delete")), - connect.WithClientOptions(opts...), - ), - } -} - -// networkServiceClient implements NetworkServiceClient. -type networkServiceClient struct { - get *connect.Client[v2.NetworkServiceGetRequest, v2.NetworkServiceGetResponse] - create *connect.Client[v2.NetworkServiceCreateRequest, v2.NetworkServiceCreateResponse] - update *connect.Client[v2.NetworkServiceUpdateRequest, v2.NetworkServiceUpdateResponse] - list *connect.Client[v2.NetworkServiceListRequest, v2.NetworkServiceListResponse] - listBaseNetworks *connect.Client[v2.NetworkServiceListBaseNetworksRequest, v2.NetworkServiceListBaseNetworksResponse] - delete *connect.Client[v2.NetworkServiceDeleteRequest, v2.NetworkServiceDeleteResponse] -} - -// Get calls metalstack.api.v2.NetworkService.Get. -func (c *networkServiceClient) Get(ctx context.Context, req *v2.NetworkServiceGetRequest) (*v2.NetworkServiceGetResponse, error) { - response, err := c.get.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err -} - -// Create calls metalstack.api.v2.NetworkService.Create. -func (c *networkServiceClient) Create(ctx context.Context, req *v2.NetworkServiceCreateRequest) (*v2.NetworkServiceCreateResponse, error) { - response, err := c.create.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err -} - -// Update calls metalstack.api.v2.NetworkService.Update. -func (c *networkServiceClient) Update(ctx context.Context, req *v2.NetworkServiceUpdateRequest) (*v2.NetworkServiceUpdateResponse, error) { - response, err := c.update.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err -} - -// List calls metalstack.api.v2.NetworkService.List. -func (c *networkServiceClient) List(ctx context.Context, req *v2.NetworkServiceListRequest) (*v2.NetworkServiceListResponse, error) { - response, err := c.list.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err -} - -// ListBaseNetworks calls metalstack.api.v2.NetworkService.ListBaseNetworks. -func (c *networkServiceClient) ListBaseNetworks(ctx context.Context, req *v2.NetworkServiceListBaseNetworksRequest) (*v2.NetworkServiceListBaseNetworksResponse, error) { - response, err := c.listBaseNetworks.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err -} - -// Delete calls metalstack.api.v2.NetworkService.Delete. -func (c *networkServiceClient) Delete(ctx context.Context, req *v2.NetworkServiceDeleteRequest) (*v2.NetworkServiceDeleteResponse, error) { - response, err := c.delete.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err +// NewNetworkServiceClient constructs a client for the metalstack.api.v2.NetworkService service. +// Multiple service clients may share a single connect.Client. +func NewNetworkServiceClient(client *connect.Client) NetworkServiceClient { + return &networkServiceClient{client: client} } // NetworkServiceHandler is an implementation of the metalstack.api.v2.NetworkService service. @@ -194,92 +122,169 @@ type NetworkServiceHandler interface { Delete(context.Context, *v2.NetworkServiceDeleteRequest) (*v2.NetworkServiceDeleteResponse, error) } -// NewNetworkServiceHandler 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 NewNetworkServiceHandler(svc NetworkServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) { - networkServiceMethods := v2.File_metalstack_api_v2_network_proto.Services().ByName("NetworkService").Methods() - networkServiceGetHandler := connect.NewUnaryHandlerSimple( - NetworkServiceGetProcedure, - svc.Get, - connect.WithSchema(networkServiceMethods.ByName("Get")), - connect.WithHandlerOptions(opts...), - ) - networkServiceCreateHandler := connect.NewUnaryHandlerSimple( - NetworkServiceCreateProcedure, - svc.Create, - connect.WithSchema(networkServiceMethods.ByName("Create")), - connect.WithHandlerOptions(opts...), +// RegisterNetworkServiceHandler registers svc as the metalstack.api.v2.NetworkService +// implementation on server. +func RegisterNetworkServiceHandler(server *connect.Server, svc NetworkServiceHandler) { + adapter := networkServiceHandler{svc: svc} + server.Register( + connect.Method{Spec: networkServiceGetSpec(), Handler: adapter.get}, + connect.Method{Spec: networkServiceCreateSpec(), Handler: adapter.create}, + connect.Method{Spec: networkServiceUpdateSpec(), Handler: adapter.update}, + connect.Method{Spec: networkServiceListSpec(), Handler: adapter.list}, + connect.Method{Spec: networkServiceListBaseNetworksSpec(), Handler: adapter.listBaseNetworks}, + connect.Method{Spec: networkServiceDeleteSpec(), Handler: adapter.delete}, ) - networkServiceUpdateHandler := connect.NewUnaryHandlerSimple( - NetworkServiceUpdateProcedure, - svc.Update, - connect.WithSchema(networkServiceMethods.ByName("Update")), - connect.WithHandlerOptions(opts...), - ) - networkServiceListHandler := connect.NewUnaryHandlerSimple( - NetworkServiceListProcedure, - svc.List, - connect.WithSchema(networkServiceMethods.ByName("List")), - connect.WithHandlerOptions(opts...), - ) - networkServiceListBaseNetworksHandler := connect.NewUnaryHandlerSimple( - NetworkServiceListBaseNetworksProcedure, - svc.ListBaseNetworks, - connect.WithSchema(networkServiceMethods.ByName("ListBaseNetworks")), - connect.WithHandlerOptions(opts...), - ) - networkServiceDeleteHandler := connect.NewUnaryHandlerSimple( - NetworkServiceDeleteProcedure, - svc.Delete, - connect.WithSchema(networkServiceMethods.ByName("Delete")), - connect.WithHandlerOptions(opts...), - ) - return "/metalstack.api.v2.NetworkService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - switch r.URL.Path { - case NetworkServiceGetProcedure: - networkServiceGetHandler.ServeHTTP(w, r) - case NetworkServiceCreateProcedure: - networkServiceCreateHandler.ServeHTTP(w, r) - case NetworkServiceUpdateProcedure: - networkServiceUpdateHandler.ServeHTTP(w, r) - case NetworkServiceListProcedure: - networkServiceListHandler.ServeHTTP(w, r) - case NetworkServiceListBaseNetworksProcedure: - networkServiceListBaseNetworksHandler.ServeHTTP(w, r) - case NetworkServiceDeleteProcedure: - networkServiceDeleteHandler.ServeHTTP(w, r) - default: - http.NotFound(w, r) - } - }) } // UnimplementedNetworkServiceHandler returns CodeUnimplemented from all methods. type UnimplementedNetworkServiceHandler struct{} func (UnimplementedNetworkServiceHandler) Get(context.Context, *v2.NetworkServiceGetRequest) (*v2.NetworkServiceGetResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.NetworkService.Get is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.NetworkService.Get is not implemented") } func (UnimplementedNetworkServiceHandler) Create(context.Context, *v2.NetworkServiceCreateRequest) (*v2.NetworkServiceCreateResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.NetworkService.Create is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.NetworkService.Create is not implemented") } func (UnimplementedNetworkServiceHandler) Update(context.Context, *v2.NetworkServiceUpdateRequest) (*v2.NetworkServiceUpdateResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.NetworkService.Update is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.NetworkService.Update is not implemented") } func (UnimplementedNetworkServiceHandler) List(context.Context, *v2.NetworkServiceListRequest) (*v2.NetworkServiceListResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.NetworkService.List is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.NetworkService.List is not implemented") } func (UnimplementedNetworkServiceHandler) ListBaseNetworks(context.Context, *v2.NetworkServiceListBaseNetworksRequest) (*v2.NetworkServiceListBaseNetworksResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.NetworkService.ListBaseNetworks is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.NetworkService.ListBaseNetworks is not implemented") } func (UnimplementedNetworkServiceHandler) Delete(context.Context, *v2.NetworkServiceDeleteRequest) (*v2.NetworkServiceDeleteResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.NetworkService.Delete is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.NetworkService.Delete is not implemented") +} + +type networkServiceClient struct { + client *connect.Client +} + +func (c *networkServiceClient) Get(ctx context.Context, req *v2.NetworkServiceGetRequest) (*v2.NetworkServiceGetResponse, error) { + var res v2.NetworkServiceGetResponse + if err := c.client.CallUnary(ctx, networkServiceGetSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *networkServiceClient) Create(ctx context.Context, req *v2.NetworkServiceCreateRequest) (*v2.NetworkServiceCreateResponse, error) { + var res v2.NetworkServiceCreateResponse + if err := c.client.CallUnary(ctx, networkServiceCreateSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *networkServiceClient) Update(ctx context.Context, req *v2.NetworkServiceUpdateRequest) (*v2.NetworkServiceUpdateResponse, error) { + var res v2.NetworkServiceUpdateResponse + if err := c.client.CallUnary(ctx, networkServiceUpdateSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *networkServiceClient) List(ctx context.Context, req *v2.NetworkServiceListRequest) (*v2.NetworkServiceListResponse, error) { + var res v2.NetworkServiceListResponse + if err := c.client.CallUnary(ctx, networkServiceListSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *networkServiceClient) ListBaseNetworks(ctx context.Context, req *v2.NetworkServiceListBaseNetworksRequest) (*v2.NetworkServiceListBaseNetworksResponse, error) { + var res v2.NetworkServiceListBaseNetworksResponse + if err := c.client.CallUnary(ctx, networkServiceListBaseNetworksSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *networkServiceClient) Delete(ctx context.Context, req *v2.NetworkServiceDeleteRequest) (*v2.NetworkServiceDeleteResponse, error) { + var res v2.NetworkServiceDeleteResponse + if err := c.client.CallUnary(ctx, networkServiceDeleteSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +type networkServiceHandler struct{ svc NetworkServiceHandler } + +func (h networkServiceHandler) get(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.NetworkServiceGetRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Get(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) +} + +func (h networkServiceHandler) create(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.NetworkServiceCreateRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Create(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) +} + +func (h networkServiceHandler) update(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.NetworkServiceUpdateRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Update(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) +} + +func (h networkServiceHandler) list(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.NetworkServiceListRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.List(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) +} + +func (h networkServiceHandler) listBaseNetworks(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.NetworkServiceListBaseNetworksRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.ListBaseNetworks(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) +} + +func (h networkServiceHandler) delete(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.NetworkServiceDeleteRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Delete(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } diff --git a/go/metalstack/api/v2/apiv2connect/partition.connect.go b/go/metalstack/api/v2/apiv2connect/partition.connect.go index 0899b4c8..e3b2132e 100644 --- a/go/metalstack/api/v2/apiv2connect/partition.connect.go +++ b/go/metalstack/api/v2/apiv2connect/partition.connect.go @@ -5,40 +5,48 @@ package apiv2connect import ( - connect "connectrpc.com/connect" + connect "connectrpc.com/connect/v2" context "context" - errors "errors" v2 "github.com/metal-stack/api/go/metalstack/api/v2" - http "net/http" - strings "strings" + sync "sync" ) -// 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 ( // PartitionServiceName is the fully-qualified name of the PartitionService service. PartitionServiceName = "metalstack.api.v2.PartitionService" ) -// 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. +// These constants are the procedure 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 ( - // PartitionServiceGetProcedure is the fully-qualified name of the PartitionService's Get RPC. + // PartitionServiceGetProcedure is the procedure name of the PartitionService's Get RPC. PartitionServiceGetProcedure = "/metalstack.api.v2.PartitionService/Get" - // PartitionServiceListProcedure is the fully-qualified name of the PartitionService's List RPC. + // PartitionServiceListProcedure is the procedure name of the PartitionService's List RPC. PartitionServiceListProcedure = "/metalstack.api.v2.PartitionService/List" ) +var ( + partitionServiceGetSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_partition_proto.Services().ByName("PartitionService").Methods().ByName("Get"), + Procedure: PartitionServiceGetProcedure, + } + }) + partitionServiceListSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_partition_proto.Services().ByName("PartitionService").Methods().ByName("List"), + Procedure: PartitionServiceListProcedure, + } + }) +) + // PartitionServiceClient is a client for the metalstack.api.v2.PartitionService service. type PartitionServiceClient interface { // Returns the partition with the specified ID. @@ -48,53 +56,9 @@ type PartitionServiceClient interface { } // NewPartitionServiceClient constructs a client for the metalstack.api.v2.PartitionService 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 NewPartitionServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) PartitionServiceClient { - baseURL = strings.TrimRight(baseURL, "/") - partitionServiceMethods := v2.File_metalstack_api_v2_partition_proto.Services().ByName("PartitionService").Methods() - return &partitionServiceClient{ - get: connect.NewClient[v2.PartitionServiceGetRequest, v2.PartitionServiceGetResponse]( - httpClient, - baseURL+PartitionServiceGetProcedure, - connect.WithSchema(partitionServiceMethods.ByName("Get")), - connect.WithClientOptions(opts...), - ), - list: connect.NewClient[v2.PartitionServiceListRequest, v2.PartitionServiceListResponse]( - httpClient, - baseURL+PartitionServiceListProcedure, - connect.WithSchema(partitionServiceMethods.ByName("List")), - connect.WithClientOptions(opts...), - ), - } -} - -// partitionServiceClient implements PartitionServiceClient. -type partitionServiceClient struct { - get *connect.Client[v2.PartitionServiceGetRequest, v2.PartitionServiceGetResponse] - list *connect.Client[v2.PartitionServiceListRequest, v2.PartitionServiceListResponse] -} - -// Get calls metalstack.api.v2.PartitionService.Get. -func (c *partitionServiceClient) Get(ctx context.Context, req *v2.PartitionServiceGetRequest) (*v2.PartitionServiceGetResponse, error) { - response, err := c.get.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err -} - -// List calls metalstack.api.v2.PartitionService.List. -func (c *partitionServiceClient) List(ctx context.Context, req *v2.PartitionServiceListRequest) (*v2.PartitionServiceListResponse, error) { - response, err := c.list.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err +// Multiple service clients may share a single connect.Client. +func NewPartitionServiceClient(client *connect.Client) PartitionServiceClient { + return &partitionServiceClient{client: client} } // PartitionServiceHandler is an implementation of the metalstack.api.v2.PartitionService service. @@ -105,44 +69,69 @@ type PartitionServiceHandler interface { List(context.Context, *v2.PartitionServiceListRequest) (*v2.PartitionServiceListResponse, error) } -// NewPartitionServiceHandler 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 NewPartitionServiceHandler(svc PartitionServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) { - partitionServiceMethods := v2.File_metalstack_api_v2_partition_proto.Services().ByName("PartitionService").Methods() - partitionServiceGetHandler := connect.NewUnaryHandlerSimple( - PartitionServiceGetProcedure, - svc.Get, - connect.WithSchema(partitionServiceMethods.ByName("Get")), - connect.WithHandlerOptions(opts...), - ) - partitionServiceListHandler := connect.NewUnaryHandlerSimple( - PartitionServiceListProcedure, - svc.List, - connect.WithSchema(partitionServiceMethods.ByName("List")), - connect.WithHandlerOptions(opts...), +// RegisterPartitionServiceHandler registers svc as the metalstack.api.v2.PartitionService +// implementation on server. +func RegisterPartitionServiceHandler(server *connect.Server, svc PartitionServiceHandler) { + adapter := partitionServiceHandler{svc: svc} + server.Register( + connect.Method{Spec: partitionServiceGetSpec(), Handler: adapter.get}, + connect.Method{Spec: partitionServiceListSpec(), Handler: adapter.list}, ) - return "/metalstack.api.v2.PartitionService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - switch r.URL.Path { - case PartitionServiceGetProcedure: - partitionServiceGetHandler.ServeHTTP(w, r) - case PartitionServiceListProcedure: - partitionServiceListHandler.ServeHTTP(w, r) - default: - http.NotFound(w, r) - } - }) } // UnimplementedPartitionServiceHandler returns CodeUnimplemented from all methods. type UnimplementedPartitionServiceHandler struct{} func (UnimplementedPartitionServiceHandler) Get(context.Context, *v2.PartitionServiceGetRequest) (*v2.PartitionServiceGetResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.PartitionService.Get is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.PartitionService.Get is not implemented") } func (UnimplementedPartitionServiceHandler) List(context.Context, *v2.PartitionServiceListRequest) (*v2.PartitionServiceListResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.PartitionService.List is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.PartitionService.List is not implemented") +} + +type partitionServiceClient struct { + client *connect.Client +} + +func (c *partitionServiceClient) Get(ctx context.Context, req *v2.PartitionServiceGetRequest) (*v2.PartitionServiceGetResponse, error) { + var res v2.PartitionServiceGetResponse + if err := c.client.CallUnary(ctx, partitionServiceGetSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *partitionServiceClient) List(ctx context.Context, req *v2.PartitionServiceListRequest) (*v2.PartitionServiceListResponse, error) { + var res v2.PartitionServiceListResponse + if err := c.client.CallUnary(ctx, partitionServiceListSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +type partitionServiceHandler struct{ svc PartitionServiceHandler } + +func (h partitionServiceHandler) get(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.PartitionServiceGetRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Get(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) +} + +func (h partitionServiceHandler) list(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.PartitionServiceListRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.List(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } diff --git a/go/metalstack/api/v2/apiv2connect/project.connect.go b/go/metalstack/api/v2/apiv2connect/project.connect.go index 74e16577..2e76d616 100644 --- a/go/metalstack/api/v2/apiv2connect/project.connect.go +++ b/go/metalstack/api/v2/apiv2connect/project.connect.go @@ -5,71 +5,160 @@ package apiv2connect import ( - connect "connectrpc.com/connect" + connect "connectrpc.com/connect/v2" context "context" - errors "errors" v2 "github.com/metal-stack/api/go/metalstack/api/v2" - http "net/http" - strings "strings" + sync "sync" ) -// 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 ( // ProjectServiceName is the fully-qualified name of the ProjectService service. ProjectServiceName = "metalstack.api.v2.ProjectService" ) -// 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. +// These constants are the procedure 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 ( - // ProjectServiceListProcedure is the fully-qualified name of the ProjectService's List RPC. + // ProjectServiceListProcedure is the procedure name of the ProjectService's List RPC. ProjectServiceListProcedure = "/metalstack.api.v2.ProjectService/List" - // ProjectServiceGetProcedure is the fully-qualified name of the ProjectService's Get RPC. + // ProjectServiceGetProcedure is the procedure name of the ProjectService's Get RPC. ProjectServiceGetProcedure = "/metalstack.api.v2.ProjectService/Get" - // ProjectServiceCreateProcedure is the fully-qualified name of the ProjectService's Create RPC. + // ProjectServiceCreateProcedure is the procedure name of the ProjectService's Create RPC. ProjectServiceCreateProcedure = "/metalstack.api.v2.ProjectService/Create" - // ProjectServiceDeleteProcedure is the fully-qualified name of the ProjectService's Delete RPC. + // ProjectServiceDeleteProcedure is the procedure name of the ProjectService's Delete RPC. ProjectServiceDeleteProcedure = "/metalstack.api.v2.ProjectService/Delete" - // ProjectServiceUpdateProcedure is the fully-qualified name of the ProjectService's Update RPC. + // ProjectServiceUpdateProcedure is the procedure name of the ProjectService's Update RPC. ProjectServiceUpdateProcedure = "/metalstack.api.v2.ProjectService/Update" - // ProjectServiceLeaveProcedure is the fully-qualified name of the ProjectService's Leave RPC. + // ProjectServiceLeaveProcedure is the procedure name of the ProjectService's Leave RPC. ProjectServiceLeaveProcedure = "/metalstack.api.v2.ProjectService/Leave" - // ProjectServiceAddMemberProcedure is the fully-qualified name of the ProjectService's AddMember - // RPC. + // ProjectServiceAddMemberProcedure is the procedure name of the ProjectService's AddMember RPC. ProjectServiceAddMemberProcedure = "/metalstack.api.v2.ProjectService/AddMember" - // ProjectServiceRemoveMemberProcedure is the fully-qualified name of the ProjectService's - // RemoveMember RPC. + // ProjectServiceRemoveMemberProcedure is the procedure name of the ProjectService's RemoveMember + // RPC. ProjectServiceRemoveMemberProcedure = "/metalstack.api.v2.ProjectService/RemoveMember" - // ProjectServiceUpdateMemberProcedure is the fully-qualified name of the ProjectService's - // UpdateMember RPC. + // ProjectServiceUpdateMemberProcedure is the procedure name of the ProjectService's UpdateMember + // RPC. ProjectServiceUpdateMemberProcedure = "/metalstack.api.v2.ProjectService/UpdateMember" - // ProjectServiceInviteProcedure is the fully-qualified name of the ProjectService's Invite RPC. + // ProjectServiceInviteProcedure is the procedure name of the ProjectService's Invite RPC. ProjectServiceInviteProcedure = "/metalstack.api.v2.ProjectService/Invite" - // ProjectServiceInviteAcceptProcedure is the fully-qualified name of the ProjectService's - // InviteAccept RPC. + // ProjectServiceInviteAcceptProcedure is the procedure name of the ProjectService's InviteAccept + // RPC. ProjectServiceInviteAcceptProcedure = "/metalstack.api.v2.ProjectService/InviteAccept" - // ProjectServiceInviteDeleteProcedure is the fully-qualified name of the ProjectService's - // InviteDelete RPC. + // ProjectServiceInviteDeleteProcedure is the procedure name of the ProjectService's InviteDelete + // RPC. ProjectServiceInviteDeleteProcedure = "/metalstack.api.v2.ProjectService/InviteDelete" - // ProjectServiceInvitesListProcedure is the fully-qualified name of the ProjectService's - // InvitesList RPC. + // ProjectServiceInvitesListProcedure is the procedure name of the ProjectService's InvitesList RPC. ProjectServiceInvitesListProcedure = "/metalstack.api.v2.ProjectService/InvitesList" - // ProjectServiceInviteGetProcedure is the fully-qualified name of the ProjectService's InviteGet - // RPC. + // ProjectServiceInviteGetProcedure is the procedure name of the ProjectService's InviteGet RPC. ProjectServiceInviteGetProcedure = "/metalstack.api.v2.ProjectService/InviteGet" ) +var ( + projectServiceListSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_project_proto.Services().ByName("ProjectService").Methods().ByName("List"), + Procedure: ProjectServiceListProcedure, + } + }) + projectServiceGetSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_project_proto.Services().ByName("ProjectService").Methods().ByName("Get"), + Procedure: ProjectServiceGetProcedure, + } + }) + projectServiceCreateSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_project_proto.Services().ByName("ProjectService").Methods().ByName("Create"), + Procedure: ProjectServiceCreateProcedure, + } + }) + projectServiceDeleteSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_project_proto.Services().ByName("ProjectService").Methods().ByName("Delete"), + Procedure: ProjectServiceDeleteProcedure, + } + }) + projectServiceUpdateSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_project_proto.Services().ByName("ProjectService").Methods().ByName("Update"), + Procedure: ProjectServiceUpdateProcedure, + } + }) + projectServiceLeaveSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_project_proto.Services().ByName("ProjectService").Methods().ByName("Leave"), + Procedure: ProjectServiceLeaveProcedure, + } + }) + projectServiceAddMemberSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_project_proto.Services().ByName("ProjectService").Methods().ByName("AddMember"), + Procedure: ProjectServiceAddMemberProcedure, + } + }) + projectServiceRemoveMemberSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_project_proto.Services().ByName("ProjectService").Methods().ByName("RemoveMember"), + Procedure: ProjectServiceRemoveMemberProcedure, + } + }) + projectServiceUpdateMemberSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_project_proto.Services().ByName("ProjectService").Methods().ByName("UpdateMember"), + Procedure: ProjectServiceUpdateMemberProcedure, + } + }) + projectServiceInviteSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_project_proto.Services().ByName("ProjectService").Methods().ByName("Invite"), + Procedure: ProjectServiceInviteProcedure, + } + }) + projectServiceInviteAcceptSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_project_proto.Services().ByName("ProjectService").Methods().ByName("InviteAccept"), + Procedure: ProjectServiceInviteAcceptProcedure, + } + }) + projectServiceInviteDeleteSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_project_proto.Services().ByName("ProjectService").Methods().ByName("InviteDelete"), + Procedure: ProjectServiceInviteDeleteProcedure, + } + }) + projectServiceInvitesListSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_project_proto.Services().ByName("ProjectService").Methods().ByName("InvitesList"), + Procedure: ProjectServiceInvitesListProcedure, + } + }) + projectServiceInviteGetSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_project_proto.Services().ByName("ProjectService").Methods().ByName("InviteGet"), + Procedure: ProjectServiceInviteGetProcedure, + } + }) +) + // ProjectServiceClient is a client for the metalstack.api.v2.ProjectService service. type ProjectServiceClient interface { // Returns the list of all accessible projects. @@ -102,462 +191,407 @@ type ProjectServiceClient interface { InviteGet(context.Context, *v2.ProjectServiceInviteGetRequest) (*v2.ProjectServiceInviteGetResponse, error) } -// NewProjectServiceClient constructs a client for the metalstack.api.v2.ProjectService 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 NewProjectServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) ProjectServiceClient { - baseURL = strings.TrimRight(baseURL, "/") - projectServiceMethods := v2.File_metalstack_api_v2_project_proto.Services().ByName("ProjectService").Methods() - return &projectServiceClient{ - list: connect.NewClient[v2.ProjectServiceListRequest, v2.ProjectServiceListResponse]( - httpClient, - baseURL+ProjectServiceListProcedure, - connect.WithSchema(projectServiceMethods.ByName("List")), - connect.WithClientOptions(opts...), - ), - get: connect.NewClient[v2.ProjectServiceGetRequest, v2.ProjectServiceGetResponse]( - httpClient, - baseURL+ProjectServiceGetProcedure, - connect.WithSchema(projectServiceMethods.ByName("Get")), - connect.WithClientOptions(opts...), - ), - create: connect.NewClient[v2.ProjectServiceCreateRequest, v2.ProjectServiceCreateResponse]( - httpClient, - baseURL+ProjectServiceCreateProcedure, - connect.WithSchema(projectServiceMethods.ByName("Create")), - connect.WithClientOptions(opts...), - ), - delete: connect.NewClient[v2.ProjectServiceDeleteRequest, v2.ProjectServiceDeleteResponse]( - httpClient, - baseURL+ProjectServiceDeleteProcedure, - connect.WithSchema(projectServiceMethods.ByName("Delete")), - connect.WithClientOptions(opts...), - ), - update: connect.NewClient[v2.ProjectServiceUpdateRequest, v2.ProjectServiceUpdateResponse]( - httpClient, - baseURL+ProjectServiceUpdateProcedure, - connect.WithSchema(projectServiceMethods.ByName("Update")), - connect.WithClientOptions(opts...), - ), - leave: connect.NewClient[v2.ProjectServiceLeaveRequest, v2.ProjectServiceLeaveResponse]( - httpClient, - baseURL+ProjectServiceLeaveProcedure, - connect.WithSchema(projectServiceMethods.ByName("Leave")), - connect.WithClientOptions(opts...), - ), - addMember: connect.NewClient[v2.ProjectServiceAddMemberRequest, v2.ProjectServiceAddMemberResponse]( - httpClient, - baseURL+ProjectServiceAddMemberProcedure, - connect.WithSchema(projectServiceMethods.ByName("AddMember")), - connect.WithClientOptions(opts...), - ), - removeMember: connect.NewClient[v2.ProjectServiceRemoveMemberRequest, v2.ProjectServiceRemoveMemberResponse]( - httpClient, - baseURL+ProjectServiceRemoveMemberProcedure, - connect.WithSchema(projectServiceMethods.ByName("RemoveMember")), - connect.WithClientOptions(opts...), - ), - updateMember: connect.NewClient[v2.ProjectServiceUpdateMemberRequest, v2.ProjectServiceUpdateMemberResponse]( - httpClient, - baseURL+ProjectServiceUpdateMemberProcedure, - connect.WithSchema(projectServiceMethods.ByName("UpdateMember")), - connect.WithClientOptions(opts...), - ), - invite: connect.NewClient[v2.ProjectServiceInviteRequest, v2.ProjectServiceInviteResponse]( - httpClient, - baseURL+ProjectServiceInviteProcedure, - connect.WithSchema(projectServiceMethods.ByName("Invite")), - connect.WithClientOptions(opts...), - ), - inviteAccept: connect.NewClient[v2.ProjectServiceInviteAcceptRequest, v2.ProjectServiceInviteAcceptResponse]( - httpClient, - baseURL+ProjectServiceInviteAcceptProcedure, - connect.WithSchema(projectServiceMethods.ByName("InviteAccept")), - connect.WithClientOptions(opts...), - ), - inviteDelete: connect.NewClient[v2.ProjectServiceInviteDeleteRequest, v2.ProjectServiceInviteDeleteResponse]( - httpClient, - baseURL+ProjectServiceInviteDeleteProcedure, - connect.WithSchema(projectServiceMethods.ByName("InviteDelete")), - connect.WithClientOptions(opts...), - ), - invitesList: connect.NewClient[v2.ProjectServiceInvitesListRequest, v2.ProjectServiceInvitesListResponse]( - httpClient, - baseURL+ProjectServiceInvitesListProcedure, - connect.WithSchema(projectServiceMethods.ByName("InvitesList")), - connect.WithClientOptions(opts...), - ), - inviteGet: connect.NewClient[v2.ProjectServiceInviteGetRequest, v2.ProjectServiceInviteGetResponse]( - httpClient, - baseURL+ProjectServiceInviteGetProcedure, - connect.WithSchema(projectServiceMethods.ByName("InviteGet")), - connect.WithClientOptions(opts...), - ), - } -} - -// projectServiceClient implements ProjectServiceClient. +// NewProjectServiceClient constructs a client for the metalstack.api.v2.ProjectService service. +// Multiple service clients may share a single connect.Client. +func NewProjectServiceClient(client *connect.Client) ProjectServiceClient { + return &projectServiceClient{client: client} +} + +// ProjectServiceHandler is an implementation of the metalstack.api.v2.ProjectService service. +type ProjectServiceHandler interface { + // Returns the list of all accessible projects. + List(context.Context, *v2.ProjectServiceListRequest) (*v2.ProjectServiceListResponse, error) + // Returns the project with the specified UUID. + Get(context.Context, *v2.ProjectServiceGetRequest) (*v2.ProjectServiceGetResponse, error) + // Create a project. + Create(context.Context, *v2.ProjectServiceCreateRequest) (*v2.ProjectServiceCreateResponse, error) + // Delete a project. + Delete(context.Context, *v2.ProjectServiceDeleteRequest) (*v2.ProjectServiceDeleteResponse, error) + // Update a project. + Update(context.Context, *v2.ProjectServiceUpdateRequest) (*v2.ProjectServiceUpdateResponse, error) + // Leave project. + Leave(context.Context, *v2.ProjectServiceLeaveRequest) (*v2.ProjectServiceLeaveResponse, error) + // AddMember adds a user to a project. + AddMember(context.Context, *v2.ProjectServiceAddMemberRequest) (*v2.ProjectServiceAddMemberResponse, error) + // RemoveMember removes a user from a project. + RemoveMember(context.Context, *v2.ProjectServiceRemoveMemberRequest) (*v2.ProjectServiceRemoveMemberResponse, error) + // UpdateMember updates a user for a project. + UpdateMember(context.Context, *v2.ProjectServiceUpdateMemberRequest) (*v2.ProjectServiceUpdateMemberResponse, error) + // Invite a user to a project. + Invite(context.Context, *v2.ProjectServiceInviteRequest) (*v2.ProjectServiceInviteResponse, error) + // InviteAccept is called by a user to accept an invitation. + InviteAccept(context.Context, *v2.ProjectServiceInviteAcceptRequest) (*v2.ProjectServiceInviteAcceptResponse, error) + // InviteDelete deletes a pending invitation. + InviteDelete(context.Context, *v2.ProjectServiceInviteDeleteRequest) (*v2.ProjectServiceInviteDeleteResponse, error) + // InvitesList list all invites to a project. + InvitesList(context.Context, *v2.ProjectServiceInvitesListRequest) (*v2.ProjectServiceInvitesListResponse, error) + // InviteGet get an invite. + InviteGet(context.Context, *v2.ProjectServiceInviteGetRequest) (*v2.ProjectServiceInviteGetResponse, error) +} + +// RegisterProjectServiceHandler registers svc as the metalstack.api.v2.ProjectService +// implementation on server. +func RegisterProjectServiceHandler(server *connect.Server, svc ProjectServiceHandler) { + adapter := projectServiceHandler{svc: svc} + server.Register( + connect.Method{Spec: projectServiceListSpec(), Handler: adapter.list}, + connect.Method{Spec: projectServiceGetSpec(), Handler: adapter.get}, + connect.Method{Spec: projectServiceCreateSpec(), Handler: adapter.create}, + connect.Method{Spec: projectServiceDeleteSpec(), Handler: adapter.delete}, + connect.Method{Spec: projectServiceUpdateSpec(), Handler: adapter.update}, + connect.Method{Spec: projectServiceLeaveSpec(), Handler: adapter.leave}, + connect.Method{Spec: projectServiceAddMemberSpec(), Handler: adapter.addMember}, + connect.Method{Spec: projectServiceRemoveMemberSpec(), Handler: adapter.removeMember}, + connect.Method{Spec: projectServiceUpdateMemberSpec(), Handler: adapter.updateMember}, + connect.Method{Spec: projectServiceInviteSpec(), Handler: adapter.invite}, + connect.Method{Spec: projectServiceInviteAcceptSpec(), Handler: adapter.inviteAccept}, + connect.Method{Spec: projectServiceInviteDeleteSpec(), Handler: adapter.inviteDelete}, + connect.Method{Spec: projectServiceInvitesListSpec(), Handler: adapter.invitesList}, + connect.Method{Spec: projectServiceInviteGetSpec(), Handler: adapter.inviteGet}, + ) +} + +// UnimplementedProjectServiceHandler returns CodeUnimplemented from all methods. +type UnimplementedProjectServiceHandler struct{} + +func (UnimplementedProjectServiceHandler) List(context.Context, *v2.ProjectServiceListRequest) (*v2.ProjectServiceListResponse, error) { + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.ProjectService.List is not implemented") +} + +func (UnimplementedProjectServiceHandler) Get(context.Context, *v2.ProjectServiceGetRequest) (*v2.ProjectServiceGetResponse, error) { + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.ProjectService.Get is not implemented") +} + +func (UnimplementedProjectServiceHandler) Create(context.Context, *v2.ProjectServiceCreateRequest) (*v2.ProjectServiceCreateResponse, error) { + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.ProjectService.Create is not implemented") +} + +func (UnimplementedProjectServiceHandler) Delete(context.Context, *v2.ProjectServiceDeleteRequest) (*v2.ProjectServiceDeleteResponse, error) { + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.ProjectService.Delete is not implemented") +} + +func (UnimplementedProjectServiceHandler) Update(context.Context, *v2.ProjectServiceUpdateRequest) (*v2.ProjectServiceUpdateResponse, error) { + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.ProjectService.Update is not implemented") +} + +func (UnimplementedProjectServiceHandler) Leave(context.Context, *v2.ProjectServiceLeaveRequest) (*v2.ProjectServiceLeaveResponse, error) { + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.ProjectService.Leave is not implemented") +} + +func (UnimplementedProjectServiceHandler) AddMember(context.Context, *v2.ProjectServiceAddMemberRequest) (*v2.ProjectServiceAddMemberResponse, error) { + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.ProjectService.AddMember is not implemented") +} + +func (UnimplementedProjectServiceHandler) RemoveMember(context.Context, *v2.ProjectServiceRemoveMemberRequest) (*v2.ProjectServiceRemoveMemberResponse, error) { + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.ProjectService.RemoveMember is not implemented") +} + +func (UnimplementedProjectServiceHandler) UpdateMember(context.Context, *v2.ProjectServiceUpdateMemberRequest) (*v2.ProjectServiceUpdateMemberResponse, error) { + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.ProjectService.UpdateMember is not implemented") +} + +func (UnimplementedProjectServiceHandler) Invite(context.Context, *v2.ProjectServiceInviteRequest) (*v2.ProjectServiceInviteResponse, error) { + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.ProjectService.Invite is not implemented") +} + +func (UnimplementedProjectServiceHandler) InviteAccept(context.Context, *v2.ProjectServiceInviteAcceptRequest) (*v2.ProjectServiceInviteAcceptResponse, error) { + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.ProjectService.InviteAccept is not implemented") +} + +func (UnimplementedProjectServiceHandler) InviteDelete(context.Context, *v2.ProjectServiceInviteDeleteRequest) (*v2.ProjectServiceInviteDeleteResponse, error) { + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.ProjectService.InviteDelete is not implemented") +} + +func (UnimplementedProjectServiceHandler) InvitesList(context.Context, *v2.ProjectServiceInvitesListRequest) (*v2.ProjectServiceInvitesListResponse, error) { + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.ProjectService.InvitesList is not implemented") +} + +func (UnimplementedProjectServiceHandler) InviteGet(context.Context, *v2.ProjectServiceInviteGetRequest) (*v2.ProjectServiceInviteGetResponse, error) { + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.ProjectService.InviteGet is not implemented") +} + type projectServiceClient struct { - list *connect.Client[v2.ProjectServiceListRequest, v2.ProjectServiceListResponse] - get *connect.Client[v2.ProjectServiceGetRequest, v2.ProjectServiceGetResponse] - create *connect.Client[v2.ProjectServiceCreateRequest, v2.ProjectServiceCreateResponse] - delete *connect.Client[v2.ProjectServiceDeleteRequest, v2.ProjectServiceDeleteResponse] - update *connect.Client[v2.ProjectServiceUpdateRequest, v2.ProjectServiceUpdateResponse] - leave *connect.Client[v2.ProjectServiceLeaveRequest, v2.ProjectServiceLeaveResponse] - addMember *connect.Client[v2.ProjectServiceAddMemberRequest, v2.ProjectServiceAddMemberResponse] - removeMember *connect.Client[v2.ProjectServiceRemoveMemberRequest, v2.ProjectServiceRemoveMemberResponse] - updateMember *connect.Client[v2.ProjectServiceUpdateMemberRequest, v2.ProjectServiceUpdateMemberResponse] - invite *connect.Client[v2.ProjectServiceInviteRequest, v2.ProjectServiceInviteResponse] - inviteAccept *connect.Client[v2.ProjectServiceInviteAcceptRequest, v2.ProjectServiceInviteAcceptResponse] - inviteDelete *connect.Client[v2.ProjectServiceInviteDeleteRequest, v2.ProjectServiceInviteDeleteResponse] - invitesList *connect.Client[v2.ProjectServiceInvitesListRequest, v2.ProjectServiceInvitesListResponse] - inviteGet *connect.Client[v2.ProjectServiceInviteGetRequest, v2.ProjectServiceInviteGetResponse] -} - -// List calls metalstack.api.v2.ProjectService.List. + client *connect.Client +} + func (c *projectServiceClient) List(ctx context.Context, req *v2.ProjectServiceListRequest) (*v2.ProjectServiceListResponse, error) { - response, err := c.list.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err + var res v2.ProjectServiceListResponse + if err := c.client.CallUnary(ctx, projectServiceListSpec(), req, &res); err != nil { + return nil, err } - return nil, err + return &res, nil } -// Get calls metalstack.api.v2.ProjectService.Get. func (c *projectServiceClient) Get(ctx context.Context, req *v2.ProjectServiceGetRequest) (*v2.ProjectServiceGetResponse, error) { - response, err := c.get.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err + var res v2.ProjectServiceGetResponse + if err := c.client.CallUnary(ctx, projectServiceGetSpec(), req, &res); err != nil { + return nil, err } - return nil, err + return &res, nil } -// Create calls metalstack.api.v2.ProjectService.Create. func (c *projectServiceClient) Create(ctx context.Context, req *v2.ProjectServiceCreateRequest) (*v2.ProjectServiceCreateResponse, error) { - response, err := c.create.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err + var res v2.ProjectServiceCreateResponse + if err := c.client.CallUnary(ctx, projectServiceCreateSpec(), req, &res); err != nil { + return nil, err } - return nil, err + return &res, nil } -// Delete calls metalstack.api.v2.ProjectService.Delete. func (c *projectServiceClient) Delete(ctx context.Context, req *v2.ProjectServiceDeleteRequest) (*v2.ProjectServiceDeleteResponse, error) { - response, err := c.delete.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err + var res v2.ProjectServiceDeleteResponse + if err := c.client.CallUnary(ctx, projectServiceDeleteSpec(), req, &res); err != nil { + return nil, err } - return nil, err + return &res, nil } -// Update calls metalstack.api.v2.ProjectService.Update. func (c *projectServiceClient) Update(ctx context.Context, req *v2.ProjectServiceUpdateRequest) (*v2.ProjectServiceUpdateResponse, error) { - response, err := c.update.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err + var res v2.ProjectServiceUpdateResponse + if err := c.client.CallUnary(ctx, projectServiceUpdateSpec(), req, &res); err != nil { + return nil, err } - return nil, err + return &res, nil } -// Leave calls metalstack.api.v2.ProjectService.Leave. func (c *projectServiceClient) Leave(ctx context.Context, req *v2.ProjectServiceLeaveRequest) (*v2.ProjectServiceLeaveResponse, error) { - response, err := c.leave.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err + var res v2.ProjectServiceLeaveResponse + if err := c.client.CallUnary(ctx, projectServiceLeaveSpec(), req, &res); err != nil { + return nil, err } - return nil, err + return &res, nil } -// AddMember calls metalstack.api.v2.ProjectService.AddMember. func (c *projectServiceClient) AddMember(ctx context.Context, req *v2.ProjectServiceAddMemberRequest) (*v2.ProjectServiceAddMemberResponse, error) { - response, err := c.addMember.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err + var res v2.ProjectServiceAddMemberResponse + if err := c.client.CallUnary(ctx, projectServiceAddMemberSpec(), req, &res); err != nil { + return nil, err } - return nil, err + return &res, nil } -// RemoveMember calls metalstack.api.v2.ProjectService.RemoveMember. func (c *projectServiceClient) RemoveMember(ctx context.Context, req *v2.ProjectServiceRemoveMemberRequest) (*v2.ProjectServiceRemoveMemberResponse, error) { - response, err := c.removeMember.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err + var res v2.ProjectServiceRemoveMemberResponse + if err := c.client.CallUnary(ctx, projectServiceRemoveMemberSpec(), req, &res); err != nil { + return nil, err } - return nil, err + return &res, nil } -// UpdateMember calls metalstack.api.v2.ProjectService.UpdateMember. func (c *projectServiceClient) UpdateMember(ctx context.Context, req *v2.ProjectServiceUpdateMemberRequest) (*v2.ProjectServiceUpdateMemberResponse, error) { - response, err := c.updateMember.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err + var res v2.ProjectServiceUpdateMemberResponse + if err := c.client.CallUnary(ctx, projectServiceUpdateMemberSpec(), req, &res); err != nil { + return nil, err } - return nil, err + return &res, nil } -// Invite calls metalstack.api.v2.ProjectService.Invite. func (c *projectServiceClient) Invite(ctx context.Context, req *v2.ProjectServiceInviteRequest) (*v2.ProjectServiceInviteResponse, error) { - response, err := c.invite.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err + var res v2.ProjectServiceInviteResponse + if err := c.client.CallUnary(ctx, projectServiceInviteSpec(), req, &res); err != nil { + return nil, err } - return nil, err + return &res, nil } -// InviteAccept calls metalstack.api.v2.ProjectService.InviteAccept. func (c *projectServiceClient) InviteAccept(ctx context.Context, req *v2.ProjectServiceInviteAcceptRequest) (*v2.ProjectServiceInviteAcceptResponse, error) { - response, err := c.inviteAccept.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err + var res v2.ProjectServiceInviteAcceptResponse + if err := c.client.CallUnary(ctx, projectServiceInviteAcceptSpec(), req, &res); err != nil { + return nil, err } - return nil, err + return &res, nil } -// InviteDelete calls metalstack.api.v2.ProjectService.InviteDelete. func (c *projectServiceClient) InviteDelete(ctx context.Context, req *v2.ProjectServiceInviteDeleteRequest) (*v2.ProjectServiceInviteDeleteResponse, error) { - response, err := c.inviteDelete.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err + var res v2.ProjectServiceInviteDeleteResponse + if err := c.client.CallUnary(ctx, projectServiceInviteDeleteSpec(), req, &res); err != nil { + return nil, err } - return nil, err + return &res, nil } -// InvitesList calls metalstack.api.v2.ProjectService.InvitesList. func (c *projectServiceClient) InvitesList(ctx context.Context, req *v2.ProjectServiceInvitesListRequest) (*v2.ProjectServiceInvitesListResponse, error) { - response, err := c.invitesList.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err + var res v2.ProjectServiceInvitesListResponse + if err := c.client.CallUnary(ctx, projectServiceInvitesListSpec(), req, &res); err != nil { + return nil, err } - return nil, err + return &res, nil } -// InviteGet calls metalstack.api.v2.ProjectService.InviteGet. func (c *projectServiceClient) InviteGet(ctx context.Context, req *v2.ProjectServiceInviteGetRequest) (*v2.ProjectServiceInviteGetResponse, error) { - response, err := c.inviteGet.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err + var res v2.ProjectServiceInviteGetResponse + if err := c.client.CallUnary(ctx, projectServiceInviteGetSpec(), req, &res); err != nil { + return nil, err } - return nil, err -} - -// ProjectServiceHandler is an implementation of the metalstack.api.v2.ProjectService service. -type ProjectServiceHandler interface { - // Returns the list of all accessible projects. - List(context.Context, *v2.ProjectServiceListRequest) (*v2.ProjectServiceListResponse, error) - // Returns the project with the specified UUID. - Get(context.Context, *v2.ProjectServiceGetRequest) (*v2.ProjectServiceGetResponse, error) - // Create a project. - Create(context.Context, *v2.ProjectServiceCreateRequest) (*v2.ProjectServiceCreateResponse, error) - // Delete a project. - Delete(context.Context, *v2.ProjectServiceDeleteRequest) (*v2.ProjectServiceDeleteResponse, error) - // Update a project. - Update(context.Context, *v2.ProjectServiceUpdateRequest) (*v2.ProjectServiceUpdateResponse, error) - // Leave project. - Leave(context.Context, *v2.ProjectServiceLeaveRequest) (*v2.ProjectServiceLeaveResponse, error) - // AddMember adds a user to a project. - AddMember(context.Context, *v2.ProjectServiceAddMemberRequest) (*v2.ProjectServiceAddMemberResponse, error) - // RemoveMember removes a user from a project. - RemoveMember(context.Context, *v2.ProjectServiceRemoveMemberRequest) (*v2.ProjectServiceRemoveMemberResponse, error) - // UpdateMember updates a user for a project. - UpdateMember(context.Context, *v2.ProjectServiceUpdateMemberRequest) (*v2.ProjectServiceUpdateMemberResponse, error) - // Invite a user to a project. - Invite(context.Context, *v2.ProjectServiceInviteRequest) (*v2.ProjectServiceInviteResponse, error) - // InviteAccept is called by a user to accept an invitation. - InviteAccept(context.Context, *v2.ProjectServiceInviteAcceptRequest) (*v2.ProjectServiceInviteAcceptResponse, error) - // InviteDelete deletes a pending invitation. - InviteDelete(context.Context, *v2.ProjectServiceInviteDeleteRequest) (*v2.ProjectServiceInviteDeleteResponse, error) - // InvitesList list all invites to a project. - InvitesList(context.Context, *v2.ProjectServiceInvitesListRequest) (*v2.ProjectServiceInvitesListResponse, error) - // InviteGet get an invite. - InviteGet(context.Context, *v2.ProjectServiceInviteGetRequest) (*v2.ProjectServiceInviteGetResponse, error) -} - -// NewProjectServiceHandler 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 NewProjectServiceHandler(svc ProjectServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) { - projectServiceMethods := v2.File_metalstack_api_v2_project_proto.Services().ByName("ProjectService").Methods() - projectServiceListHandler := connect.NewUnaryHandlerSimple( - ProjectServiceListProcedure, - svc.List, - connect.WithSchema(projectServiceMethods.ByName("List")), - connect.WithHandlerOptions(opts...), - ) - projectServiceGetHandler := connect.NewUnaryHandlerSimple( - ProjectServiceGetProcedure, - svc.Get, - connect.WithSchema(projectServiceMethods.ByName("Get")), - connect.WithHandlerOptions(opts...), - ) - projectServiceCreateHandler := connect.NewUnaryHandlerSimple( - ProjectServiceCreateProcedure, - svc.Create, - connect.WithSchema(projectServiceMethods.ByName("Create")), - connect.WithHandlerOptions(opts...), - ) - projectServiceDeleteHandler := connect.NewUnaryHandlerSimple( - ProjectServiceDeleteProcedure, - svc.Delete, - connect.WithSchema(projectServiceMethods.ByName("Delete")), - connect.WithHandlerOptions(opts...), - ) - projectServiceUpdateHandler := connect.NewUnaryHandlerSimple( - ProjectServiceUpdateProcedure, - svc.Update, - connect.WithSchema(projectServiceMethods.ByName("Update")), - connect.WithHandlerOptions(opts...), - ) - projectServiceLeaveHandler := connect.NewUnaryHandlerSimple( - ProjectServiceLeaveProcedure, - svc.Leave, - connect.WithSchema(projectServiceMethods.ByName("Leave")), - connect.WithHandlerOptions(opts...), - ) - projectServiceAddMemberHandler := connect.NewUnaryHandlerSimple( - ProjectServiceAddMemberProcedure, - svc.AddMember, - connect.WithSchema(projectServiceMethods.ByName("AddMember")), - connect.WithHandlerOptions(opts...), - ) - projectServiceRemoveMemberHandler := connect.NewUnaryHandlerSimple( - ProjectServiceRemoveMemberProcedure, - svc.RemoveMember, - connect.WithSchema(projectServiceMethods.ByName("RemoveMember")), - connect.WithHandlerOptions(opts...), - ) - projectServiceUpdateMemberHandler := connect.NewUnaryHandlerSimple( - ProjectServiceUpdateMemberProcedure, - svc.UpdateMember, - connect.WithSchema(projectServiceMethods.ByName("UpdateMember")), - connect.WithHandlerOptions(opts...), - ) - projectServiceInviteHandler := connect.NewUnaryHandlerSimple( - ProjectServiceInviteProcedure, - svc.Invite, - connect.WithSchema(projectServiceMethods.ByName("Invite")), - connect.WithHandlerOptions(opts...), - ) - projectServiceInviteAcceptHandler := connect.NewUnaryHandlerSimple( - ProjectServiceInviteAcceptProcedure, - svc.InviteAccept, - connect.WithSchema(projectServiceMethods.ByName("InviteAccept")), - connect.WithHandlerOptions(opts...), - ) - projectServiceInviteDeleteHandler := connect.NewUnaryHandlerSimple( - ProjectServiceInviteDeleteProcedure, - svc.InviteDelete, - connect.WithSchema(projectServiceMethods.ByName("InviteDelete")), - connect.WithHandlerOptions(opts...), - ) - projectServiceInvitesListHandler := connect.NewUnaryHandlerSimple( - ProjectServiceInvitesListProcedure, - svc.InvitesList, - connect.WithSchema(projectServiceMethods.ByName("InvitesList")), - connect.WithHandlerOptions(opts...), - ) - projectServiceInviteGetHandler := connect.NewUnaryHandlerSimple( - ProjectServiceInviteGetProcedure, - svc.InviteGet, - connect.WithSchema(projectServiceMethods.ByName("InviteGet")), - connect.WithHandlerOptions(opts...), - ) - return "/metalstack.api.v2.ProjectService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - switch r.URL.Path { - case ProjectServiceListProcedure: - projectServiceListHandler.ServeHTTP(w, r) - case ProjectServiceGetProcedure: - projectServiceGetHandler.ServeHTTP(w, r) - case ProjectServiceCreateProcedure: - projectServiceCreateHandler.ServeHTTP(w, r) - case ProjectServiceDeleteProcedure: - projectServiceDeleteHandler.ServeHTTP(w, r) - case ProjectServiceUpdateProcedure: - projectServiceUpdateHandler.ServeHTTP(w, r) - case ProjectServiceLeaveProcedure: - projectServiceLeaveHandler.ServeHTTP(w, r) - case ProjectServiceAddMemberProcedure: - projectServiceAddMemberHandler.ServeHTTP(w, r) - case ProjectServiceRemoveMemberProcedure: - projectServiceRemoveMemberHandler.ServeHTTP(w, r) - case ProjectServiceUpdateMemberProcedure: - projectServiceUpdateMemberHandler.ServeHTTP(w, r) - case ProjectServiceInviteProcedure: - projectServiceInviteHandler.ServeHTTP(w, r) - case ProjectServiceInviteAcceptProcedure: - projectServiceInviteAcceptHandler.ServeHTTP(w, r) - case ProjectServiceInviteDeleteProcedure: - projectServiceInviteDeleteHandler.ServeHTTP(w, r) - case ProjectServiceInvitesListProcedure: - projectServiceInvitesListHandler.ServeHTTP(w, r) - case ProjectServiceInviteGetProcedure: - projectServiceInviteGetHandler.ServeHTTP(w, r) - default: - http.NotFound(w, r) - } - }) + return &res, nil } -// UnimplementedProjectServiceHandler returns CodeUnimplemented from all methods. -type UnimplementedProjectServiceHandler struct{} +type projectServiceHandler struct{ svc ProjectServiceHandler } -func (UnimplementedProjectServiceHandler) List(context.Context, *v2.ProjectServiceListRequest) (*v2.ProjectServiceListResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.ProjectService.List is not implemented")) +func (h projectServiceHandler) list(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.ProjectServiceListRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.List(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } -func (UnimplementedProjectServiceHandler) Get(context.Context, *v2.ProjectServiceGetRequest) (*v2.ProjectServiceGetResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.ProjectService.Get is not implemented")) +func (h projectServiceHandler) get(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.ProjectServiceGetRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Get(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } -func (UnimplementedProjectServiceHandler) Create(context.Context, *v2.ProjectServiceCreateRequest) (*v2.ProjectServiceCreateResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.ProjectService.Create is not implemented")) +func (h projectServiceHandler) create(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.ProjectServiceCreateRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Create(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } -func (UnimplementedProjectServiceHandler) Delete(context.Context, *v2.ProjectServiceDeleteRequest) (*v2.ProjectServiceDeleteResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.ProjectService.Delete is not implemented")) +func (h projectServiceHandler) delete(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.ProjectServiceDeleteRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Delete(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } -func (UnimplementedProjectServiceHandler) Update(context.Context, *v2.ProjectServiceUpdateRequest) (*v2.ProjectServiceUpdateResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.ProjectService.Update is not implemented")) +func (h projectServiceHandler) update(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.ProjectServiceUpdateRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Update(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } -func (UnimplementedProjectServiceHandler) Leave(context.Context, *v2.ProjectServiceLeaveRequest) (*v2.ProjectServiceLeaveResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.ProjectService.Leave is not implemented")) +func (h projectServiceHandler) leave(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.ProjectServiceLeaveRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Leave(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } -func (UnimplementedProjectServiceHandler) AddMember(context.Context, *v2.ProjectServiceAddMemberRequest) (*v2.ProjectServiceAddMemberResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.ProjectService.AddMember is not implemented")) +func (h projectServiceHandler) addMember(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.ProjectServiceAddMemberRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.AddMember(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } -func (UnimplementedProjectServiceHandler) RemoveMember(context.Context, *v2.ProjectServiceRemoveMemberRequest) (*v2.ProjectServiceRemoveMemberResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.ProjectService.RemoveMember is not implemented")) +func (h projectServiceHandler) removeMember(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.ProjectServiceRemoveMemberRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.RemoveMember(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } -func (UnimplementedProjectServiceHandler) UpdateMember(context.Context, *v2.ProjectServiceUpdateMemberRequest) (*v2.ProjectServiceUpdateMemberResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.ProjectService.UpdateMember is not implemented")) +func (h projectServiceHandler) updateMember(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.ProjectServiceUpdateMemberRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.UpdateMember(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } -func (UnimplementedProjectServiceHandler) Invite(context.Context, *v2.ProjectServiceInviteRequest) (*v2.ProjectServiceInviteResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.ProjectService.Invite is not implemented")) +func (h projectServiceHandler) invite(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.ProjectServiceInviteRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Invite(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } -func (UnimplementedProjectServiceHandler) InviteAccept(context.Context, *v2.ProjectServiceInviteAcceptRequest) (*v2.ProjectServiceInviteAcceptResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.ProjectService.InviteAccept is not implemented")) +func (h projectServiceHandler) inviteAccept(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.ProjectServiceInviteAcceptRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.InviteAccept(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } -func (UnimplementedProjectServiceHandler) InviteDelete(context.Context, *v2.ProjectServiceInviteDeleteRequest) (*v2.ProjectServiceInviteDeleteResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.ProjectService.InviteDelete is not implemented")) +func (h projectServiceHandler) inviteDelete(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.ProjectServiceInviteDeleteRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.InviteDelete(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } -func (UnimplementedProjectServiceHandler) InvitesList(context.Context, *v2.ProjectServiceInvitesListRequest) (*v2.ProjectServiceInvitesListResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.ProjectService.InvitesList is not implemented")) +func (h projectServiceHandler) invitesList(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.ProjectServiceInvitesListRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.InvitesList(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } -func (UnimplementedProjectServiceHandler) InviteGet(context.Context, *v2.ProjectServiceInviteGetRequest) (*v2.ProjectServiceInviteGetResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.ProjectService.InviteGet is not implemented")) +func (h projectServiceHandler) inviteGet(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.ProjectServiceInviteGetRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.InviteGet(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } diff --git a/go/metalstack/api/v2/apiv2connect/size.connect.go b/go/metalstack/api/v2/apiv2connect/size.connect.go index 3c77a5df..b063f80c 100644 --- a/go/metalstack/api/v2/apiv2connect/size.connect.go +++ b/go/metalstack/api/v2/apiv2connect/size.connect.go @@ -5,40 +5,48 @@ package apiv2connect import ( - connect "connectrpc.com/connect" + connect "connectrpc.com/connect/v2" context "context" - errors "errors" v2 "github.com/metal-stack/api/go/metalstack/api/v2" - http "net/http" - strings "strings" + sync "sync" ) -// 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 ( // SizeServiceName is the fully-qualified name of the SizeService service. SizeServiceName = "metalstack.api.v2.SizeService" ) -// 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. +// These constants are the procedure 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 ( - // SizeServiceGetProcedure is the fully-qualified name of the SizeService's Get RPC. + // SizeServiceGetProcedure is the procedure name of the SizeService's Get RPC. SizeServiceGetProcedure = "/metalstack.api.v2.SizeService/Get" - // SizeServiceListProcedure is the fully-qualified name of the SizeService's List RPC. + // SizeServiceListProcedure is the procedure name of the SizeService's List RPC. SizeServiceListProcedure = "/metalstack.api.v2.SizeService/List" ) +var ( + sizeServiceGetSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_size_proto.Services().ByName("SizeService").Methods().ByName("Get"), + Procedure: SizeServiceGetProcedure, + } + }) + sizeServiceListSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_size_proto.Services().ByName("SizeService").Methods().ByName("List"), + Procedure: SizeServiceListProcedure, + } + }) +) + // SizeServiceClient is a client for the metalstack.api.v2.SizeService service. type SizeServiceClient interface { // Returns the size with the specified ID. @@ -47,54 +55,10 @@ type SizeServiceClient interface { List(context.Context, *v2.SizeServiceListRequest) (*v2.SizeServiceListResponse, error) } -// NewSizeServiceClient constructs a client for the metalstack.api.v2.SizeService 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 NewSizeServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) SizeServiceClient { - baseURL = strings.TrimRight(baseURL, "/") - sizeServiceMethods := v2.File_metalstack_api_v2_size_proto.Services().ByName("SizeService").Methods() - return &sizeServiceClient{ - get: connect.NewClient[v2.SizeServiceGetRequest, v2.SizeServiceGetResponse]( - httpClient, - baseURL+SizeServiceGetProcedure, - connect.WithSchema(sizeServiceMethods.ByName("Get")), - connect.WithClientOptions(opts...), - ), - list: connect.NewClient[v2.SizeServiceListRequest, v2.SizeServiceListResponse]( - httpClient, - baseURL+SizeServiceListProcedure, - connect.WithSchema(sizeServiceMethods.ByName("List")), - connect.WithClientOptions(opts...), - ), - } -} - -// sizeServiceClient implements SizeServiceClient. -type sizeServiceClient struct { - get *connect.Client[v2.SizeServiceGetRequest, v2.SizeServiceGetResponse] - list *connect.Client[v2.SizeServiceListRequest, v2.SizeServiceListResponse] -} - -// Get calls metalstack.api.v2.SizeService.Get. -func (c *sizeServiceClient) Get(ctx context.Context, req *v2.SizeServiceGetRequest) (*v2.SizeServiceGetResponse, error) { - response, err := c.get.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err -} - -// List calls metalstack.api.v2.SizeService.List. -func (c *sizeServiceClient) List(ctx context.Context, req *v2.SizeServiceListRequest) (*v2.SizeServiceListResponse, error) { - response, err := c.list.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err +// NewSizeServiceClient constructs a client for the metalstack.api.v2.SizeService service. Multiple +// service clients may share a single connect.Client. +func NewSizeServiceClient(client *connect.Client) SizeServiceClient { + return &sizeServiceClient{client: client} } // SizeServiceHandler is an implementation of the metalstack.api.v2.SizeService service. @@ -105,44 +69,69 @@ type SizeServiceHandler interface { List(context.Context, *v2.SizeServiceListRequest) (*v2.SizeServiceListResponse, error) } -// NewSizeServiceHandler 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 NewSizeServiceHandler(svc SizeServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) { - sizeServiceMethods := v2.File_metalstack_api_v2_size_proto.Services().ByName("SizeService").Methods() - sizeServiceGetHandler := connect.NewUnaryHandlerSimple( - SizeServiceGetProcedure, - svc.Get, - connect.WithSchema(sizeServiceMethods.ByName("Get")), - connect.WithHandlerOptions(opts...), - ) - sizeServiceListHandler := connect.NewUnaryHandlerSimple( - SizeServiceListProcedure, - svc.List, - connect.WithSchema(sizeServiceMethods.ByName("List")), - connect.WithHandlerOptions(opts...), +// RegisterSizeServiceHandler registers svc as the metalstack.api.v2.SizeService implementation on +// server. +func RegisterSizeServiceHandler(server *connect.Server, svc SizeServiceHandler) { + adapter := sizeServiceHandler{svc: svc} + server.Register( + connect.Method{Spec: sizeServiceGetSpec(), Handler: adapter.get}, + connect.Method{Spec: sizeServiceListSpec(), Handler: adapter.list}, ) - return "/metalstack.api.v2.SizeService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - switch r.URL.Path { - case SizeServiceGetProcedure: - sizeServiceGetHandler.ServeHTTP(w, r) - case SizeServiceListProcedure: - sizeServiceListHandler.ServeHTTP(w, r) - default: - http.NotFound(w, r) - } - }) } // UnimplementedSizeServiceHandler returns CodeUnimplemented from all methods. type UnimplementedSizeServiceHandler struct{} func (UnimplementedSizeServiceHandler) Get(context.Context, *v2.SizeServiceGetRequest) (*v2.SizeServiceGetResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.SizeService.Get is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.SizeService.Get is not implemented") } func (UnimplementedSizeServiceHandler) List(context.Context, *v2.SizeServiceListRequest) (*v2.SizeServiceListResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.SizeService.List is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.SizeService.List is not implemented") +} + +type sizeServiceClient struct { + client *connect.Client +} + +func (c *sizeServiceClient) Get(ctx context.Context, req *v2.SizeServiceGetRequest) (*v2.SizeServiceGetResponse, error) { + var res v2.SizeServiceGetResponse + if err := c.client.CallUnary(ctx, sizeServiceGetSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *sizeServiceClient) List(ctx context.Context, req *v2.SizeServiceListRequest) (*v2.SizeServiceListResponse, error) { + var res v2.SizeServiceListResponse + if err := c.client.CallUnary(ctx, sizeServiceListSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +type sizeServiceHandler struct{ svc SizeServiceHandler } + +func (h sizeServiceHandler) get(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.SizeServiceGetRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Get(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) +} + +func (h sizeServiceHandler) list(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.SizeServiceListRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.List(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } diff --git a/go/metalstack/api/v2/apiv2connect/size_imageconstraint.connect.go b/go/metalstack/api/v2/apiv2connect/size_imageconstraint.connect.go index c67d7f09..2b4876d0 100644 --- a/go/metalstack/api/v2/apiv2connect/size_imageconstraint.connect.go +++ b/go/metalstack/api/v2/apiv2connect/size_imageconstraint.connect.go @@ -5,40 +5,41 @@ package apiv2connect import ( - connect "connectrpc.com/connect" + connect "connectrpc.com/connect/v2" context "context" - errors "errors" v2 "github.com/metal-stack/api/go/metalstack/api/v2" - http "net/http" - strings "strings" + sync "sync" ) -// 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 ( // SizeImageConstraintServiceName is the fully-qualified name of the SizeImageConstraintService // service. SizeImageConstraintServiceName = "metalstack.api.v2.SizeImageConstraintService" ) -// 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. +// These constants are the procedure 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 ( - // SizeImageConstraintServiceTryProcedure is the fully-qualified name of the - // SizeImageConstraintService's Try RPC. + // SizeImageConstraintServiceTryProcedure is the procedure name of the SizeImageConstraintService's + // Try RPC. SizeImageConstraintServiceTryProcedure = "/metalstack.api.v2.SizeImageConstraintService/Try" ) +var ( + sizeImageConstraintServiceTrySpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_size_imageconstraint_proto.Services().ByName("SizeImageConstraintService").Methods().ByName("Try"), + Procedure: SizeImageConstraintServiceTryProcedure, + } + }) +) + // SizeImageConstraintServiceClient is a client for the metalstack.api.v2.SizeImageConstraintService // service. type SizeImageConstraintServiceClient interface { @@ -47,38 +48,10 @@ type SizeImageConstraintServiceClient interface { } // NewSizeImageConstraintServiceClient constructs a client for the -// metalstack.api.v2.SizeImageConstraintService 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 NewSizeImageConstraintServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) SizeImageConstraintServiceClient { - baseURL = strings.TrimRight(baseURL, "/") - sizeImageConstraintServiceMethods := v2.File_metalstack_api_v2_size_imageconstraint_proto.Services().ByName("SizeImageConstraintService").Methods() - return &sizeImageConstraintServiceClient{ - try: connect.NewClient[v2.SizeImageConstraintServiceTryRequest, v2.SizeImageConstraintServiceTryResponse]( - httpClient, - baseURL+SizeImageConstraintServiceTryProcedure, - connect.WithSchema(sizeImageConstraintServiceMethods.ByName("Try")), - connect.WithClientOptions(opts...), - ), - } -} - -// sizeImageConstraintServiceClient implements SizeImageConstraintServiceClient. -type sizeImageConstraintServiceClient struct { - try *connect.Client[v2.SizeImageConstraintServiceTryRequest, v2.SizeImageConstraintServiceTryResponse] -} - -// Try calls metalstack.api.v2.SizeImageConstraintService.Try. -func (c *sizeImageConstraintServiceClient) Try(ctx context.Context, req *v2.SizeImageConstraintServiceTryRequest) (*v2.SizeImageConstraintServiceTryResponse, error) { - response, err := c.try.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err +// metalstack.api.v2.SizeImageConstraintService service. Multiple service clients may share a single +// connect.Client. +func NewSizeImageConstraintServiceClient(client *connect.Client) SizeImageConstraintServiceClient { + return &sizeImageConstraintServiceClient{client: client} } // SizeImageConstraintServiceHandler is an implementation of the @@ -88,32 +61,46 @@ type SizeImageConstraintServiceHandler interface { Try(context.Context, *v2.SizeImageConstraintServiceTryRequest) (*v2.SizeImageConstraintServiceTryResponse, error) } -// NewSizeImageConstraintServiceHandler 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 NewSizeImageConstraintServiceHandler(svc SizeImageConstraintServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) { - sizeImageConstraintServiceMethods := v2.File_metalstack_api_v2_size_imageconstraint_proto.Services().ByName("SizeImageConstraintService").Methods() - sizeImageConstraintServiceTryHandler := connect.NewUnaryHandlerSimple( - SizeImageConstraintServiceTryProcedure, - svc.Try, - connect.WithSchema(sizeImageConstraintServiceMethods.ByName("Try")), - connect.WithHandlerOptions(opts...), +// RegisterSizeImageConstraintServiceHandler registers svc as the +// metalstack.api.v2.SizeImageConstraintService implementation on server. +func RegisterSizeImageConstraintServiceHandler(server *connect.Server, svc SizeImageConstraintServiceHandler) { + adapter := sizeImageConstraintServiceHandler{svc: svc} + server.Register( + connect.Method{Spec: sizeImageConstraintServiceTrySpec(), Handler: adapter.try}, ) - return "/metalstack.api.v2.SizeImageConstraintService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - switch r.URL.Path { - case SizeImageConstraintServiceTryProcedure: - sizeImageConstraintServiceTryHandler.ServeHTTP(w, r) - default: - http.NotFound(w, r) - } - }) } // UnimplementedSizeImageConstraintServiceHandler returns CodeUnimplemented from all methods. type UnimplementedSizeImageConstraintServiceHandler struct{} func (UnimplementedSizeImageConstraintServiceHandler) Try(context.Context, *v2.SizeImageConstraintServiceTryRequest) (*v2.SizeImageConstraintServiceTryResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.SizeImageConstraintService.Try is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.SizeImageConstraintService.Try is not implemented") +} + +type sizeImageConstraintServiceClient struct { + client *connect.Client +} + +func (c *sizeImageConstraintServiceClient) Try(ctx context.Context, req *v2.SizeImageConstraintServiceTryRequest) (*v2.SizeImageConstraintServiceTryResponse, error) { + var res v2.SizeImageConstraintServiceTryResponse + if err := c.client.CallUnary(ctx, sizeImageConstraintServiceTrySpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +type sizeImageConstraintServiceHandler struct { + svc SizeImageConstraintServiceHandler +} + +func (h sizeImageConstraintServiceHandler) try(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.SizeImageConstraintServiceTryRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Try(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } diff --git a/go/metalstack/api/v2/apiv2connect/size_reservation.connect.go b/go/metalstack/api/v2/apiv2connect/size_reservation.connect.go index 39240adf..0d3fc303 100644 --- a/go/metalstack/api/v2/apiv2connect/size_reservation.connect.go +++ b/go/metalstack/api/v2/apiv2connect/size_reservation.connect.go @@ -5,42 +5,49 @@ package apiv2connect import ( - connect "connectrpc.com/connect" + connect "connectrpc.com/connect/v2" context "context" - errors "errors" v2 "github.com/metal-stack/api/go/metalstack/api/v2" - http "net/http" - strings "strings" + sync "sync" ) -// 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 ( // SizeReservationServiceName is the fully-qualified name of the SizeReservationService service. SizeReservationServiceName = "metalstack.api.v2.SizeReservationService" ) -// 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. +// These constants are the procedure 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 ( - // SizeReservationServiceGetProcedure is the fully-qualified name of the SizeReservationService's - // Get RPC. + // SizeReservationServiceGetProcedure is the procedure name of the SizeReservationService's Get RPC. SizeReservationServiceGetProcedure = "/metalstack.api.v2.SizeReservationService/Get" - // SizeReservationServiceListProcedure is the fully-qualified name of the SizeReservationService's - // List RPC. + // SizeReservationServiceListProcedure is the procedure name of the SizeReservationService's List + // RPC. SizeReservationServiceListProcedure = "/metalstack.api.v2.SizeReservationService/List" ) +var ( + sizeReservationServiceGetSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_size_reservation_proto.Services().ByName("SizeReservationService").Methods().ByName("Get"), + Procedure: SizeReservationServiceGetProcedure, + } + }) + sizeReservationServiceListSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_size_reservation_proto.Services().ByName("SizeReservationService").Methods().ByName("List"), + Procedure: SizeReservationServiceListProcedure, + } + }) +) + // SizeReservationServiceClient is a client for the metalstack.api.v2.SizeReservationService // service. type SizeReservationServiceClient interface { @@ -51,53 +58,10 @@ type SizeReservationServiceClient interface { } // NewSizeReservationServiceClient constructs a client for the -// metalstack.api.v2.SizeReservationService 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 NewSizeReservationServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) SizeReservationServiceClient { - baseURL = strings.TrimRight(baseURL, "/") - sizeReservationServiceMethods := v2.File_metalstack_api_v2_size_reservation_proto.Services().ByName("SizeReservationService").Methods() - return &sizeReservationServiceClient{ - get: connect.NewClient[v2.SizeReservationServiceGetRequest, v2.SizeReservationServiceGetResponse]( - httpClient, - baseURL+SizeReservationServiceGetProcedure, - connect.WithSchema(sizeReservationServiceMethods.ByName("Get")), - connect.WithClientOptions(opts...), - ), - list: connect.NewClient[v2.SizeReservationServiceListRequest, v2.SizeReservationServiceListResponse]( - httpClient, - baseURL+SizeReservationServiceListProcedure, - connect.WithSchema(sizeReservationServiceMethods.ByName("List")), - connect.WithClientOptions(opts...), - ), - } -} - -// sizeReservationServiceClient implements SizeReservationServiceClient. -type sizeReservationServiceClient struct { - get *connect.Client[v2.SizeReservationServiceGetRequest, v2.SizeReservationServiceGetResponse] - list *connect.Client[v2.SizeReservationServiceListRequest, v2.SizeReservationServiceListResponse] -} - -// Get calls metalstack.api.v2.SizeReservationService.Get. -func (c *sizeReservationServiceClient) Get(ctx context.Context, req *v2.SizeReservationServiceGetRequest) (*v2.SizeReservationServiceGetResponse, error) { - response, err := c.get.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err -} - -// List calls metalstack.api.v2.SizeReservationService.List. -func (c *sizeReservationServiceClient) List(ctx context.Context, req *v2.SizeReservationServiceListRequest) (*v2.SizeReservationServiceListResponse, error) { - response, err := c.list.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err +// metalstack.api.v2.SizeReservationService service. Multiple service clients may share a single +// connect.Client. +func NewSizeReservationServiceClient(client *connect.Client) SizeReservationServiceClient { + return &sizeReservationServiceClient{client: client} } // SizeReservationServiceHandler is an implementation of the @@ -109,44 +73,69 @@ type SizeReservationServiceHandler interface { List(context.Context, *v2.SizeReservationServiceListRequest) (*v2.SizeReservationServiceListResponse, error) } -// NewSizeReservationServiceHandler 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 NewSizeReservationServiceHandler(svc SizeReservationServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) { - sizeReservationServiceMethods := v2.File_metalstack_api_v2_size_reservation_proto.Services().ByName("SizeReservationService").Methods() - sizeReservationServiceGetHandler := connect.NewUnaryHandlerSimple( - SizeReservationServiceGetProcedure, - svc.Get, - connect.WithSchema(sizeReservationServiceMethods.ByName("Get")), - connect.WithHandlerOptions(opts...), - ) - sizeReservationServiceListHandler := connect.NewUnaryHandlerSimple( - SizeReservationServiceListProcedure, - svc.List, - connect.WithSchema(sizeReservationServiceMethods.ByName("List")), - connect.WithHandlerOptions(opts...), +// RegisterSizeReservationServiceHandler registers svc as the +// metalstack.api.v2.SizeReservationService implementation on server. +func RegisterSizeReservationServiceHandler(server *connect.Server, svc SizeReservationServiceHandler) { + adapter := sizeReservationServiceHandler{svc: svc} + server.Register( + connect.Method{Spec: sizeReservationServiceGetSpec(), Handler: adapter.get}, + connect.Method{Spec: sizeReservationServiceListSpec(), Handler: adapter.list}, ) - return "/metalstack.api.v2.SizeReservationService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - switch r.URL.Path { - case SizeReservationServiceGetProcedure: - sizeReservationServiceGetHandler.ServeHTTP(w, r) - case SizeReservationServiceListProcedure: - sizeReservationServiceListHandler.ServeHTTP(w, r) - default: - http.NotFound(w, r) - } - }) } // UnimplementedSizeReservationServiceHandler returns CodeUnimplemented from all methods. type UnimplementedSizeReservationServiceHandler struct{} func (UnimplementedSizeReservationServiceHandler) Get(context.Context, *v2.SizeReservationServiceGetRequest) (*v2.SizeReservationServiceGetResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.SizeReservationService.Get is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.SizeReservationService.Get is not implemented") } func (UnimplementedSizeReservationServiceHandler) List(context.Context, *v2.SizeReservationServiceListRequest) (*v2.SizeReservationServiceListResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.SizeReservationService.List is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.SizeReservationService.List is not implemented") +} + +type sizeReservationServiceClient struct { + client *connect.Client +} + +func (c *sizeReservationServiceClient) Get(ctx context.Context, req *v2.SizeReservationServiceGetRequest) (*v2.SizeReservationServiceGetResponse, error) { + var res v2.SizeReservationServiceGetResponse + if err := c.client.CallUnary(ctx, sizeReservationServiceGetSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *sizeReservationServiceClient) List(ctx context.Context, req *v2.SizeReservationServiceListRequest) (*v2.SizeReservationServiceListResponse, error) { + var res v2.SizeReservationServiceListResponse + if err := c.client.CallUnary(ctx, sizeReservationServiceListSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +type sizeReservationServiceHandler struct{ svc SizeReservationServiceHandler } + +func (h sizeReservationServiceHandler) get(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.SizeReservationServiceGetRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Get(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) +} + +func (h sizeReservationServiceHandler) list(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.SizeReservationServiceListRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.List(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } diff --git a/go/metalstack/api/v2/apiv2connect/tenant.connect.go b/go/metalstack/api/v2/apiv2connect/tenant.connect.go index 9b99279a..32358e9c 100644 --- a/go/metalstack/api/v2/apiv2connect/tenant.connect.go +++ b/go/metalstack/api/v2/apiv2connect/tenant.connect.go @@ -5,69 +5,156 @@ package apiv2connect import ( - connect "connectrpc.com/connect" + connect "connectrpc.com/connect/v2" context "context" - errors "errors" v2 "github.com/metal-stack/api/go/metalstack/api/v2" - http "net/http" - strings "strings" + sync "sync" ) -// 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 ( // TenantServiceName is the fully-qualified name of the TenantService service. TenantServiceName = "metalstack.api.v2.TenantService" ) -// 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. +// These constants are the procedure 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 ( - // TenantServiceCreateProcedure is the fully-qualified name of the TenantService's Create RPC. + // TenantServiceCreateProcedure is the procedure name of the TenantService's Create RPC. TenantServiceCreateProcedure = "/metalstack.api.v2.TenantService/Create" - // TenantServiceListProcedure is the fully-qualified name of the TenantService's List RPC. + // TenantServiceListProcedure is the procedure name of the TenantService's List RPC. TenantServiceListProcedure = "/metalstack.api.v2.TenantService/List" - // TenantServiceGetProcedure is the fully-qualified name of the TenantService's Get RPC. + // TenantServiceGetProcedure is the procedure name of the TenantService's Get RPC. TenantServiceGetProcedure = "/metalstack.api.v2.TenantService/Get" - // TenantServiceUpdateProcedure is the fully-qualified name of the TenantService's Update RPC. + // TenantServiceUpdateProcedure is the procedure name of the TenantService's Update RPC. TenantServiceUpdateProcedure = "/metalstack.api.v2.TenantService/Update" - // TenantServiceDeleteProcedure is the fully-qualified name of the TenantService's Delete RPC. + // TenantServiceDeleteProcedure is the procedure name of the TenantService's Delete RPC. TenantServiceDeleteProcedure = "/metalstack.api.v2.TenantService/Delete" - // TenantServiceLeaveProcedure is the fully-qualified name of the TenantService's Leave RPC. + // TenantServiceLeaveProcedure is the procedure name of the TenantService's Leave RPC. TenantServiceLeaveProcedure = "/metalstack.api.v2.TenantService/Leave" - // TenantServiceAddMemberProcedure is the fully-qualified name of the TenantService's AddMember RPC. + // TenantServiceAddMemberProcedure is the procedure name of the TenantService's AddMember RPC. TenantServiceAddMemberProcedure = "/metalstack.api.v2.TenantService/AddMember" - // TenantServiceRemoveMemberProcedure is the fully-qualified name of the TenantService's - // RemoveMember RPC. + // TenantServiceRemoveMemberProcedure is the procedure name of the TenantService's RemoveMember RPC. TenantServiceRemoveMemberProcedure = "/metalstack.api.v2.TenantService/RemoveMember" - // TenantServiceUpdateMemberProcedure is the fully-qualified name of the TenantService's - // UpdateMember RPC. + // TenantServiceUpdateMemberProcedure is the procedure name of the TenantService's UpdateMember RPC. TenantServiceUpdateMemberProcedure = "/metalstack.api.v2.TenantService/UpdateMember" - // TenantServiceInviteProcedure is the fully-qualified name of the TenantService's Invite RPC. + // TenantServiceInviteProcedure is the procedure name of the TenantService's Invite RPC. TenantServiceInviteProcedure = "/metalstack.api.v2.TenantService/Invite" - // TenantServiceInviteAcceptProcedure is the fully-qualified name of the TenantService's - // InviteAccept RPC. + // TenantServiceInviteAcceptProcedure is the procedure name of the TenantService's InviteAccept RPC. TenantServiceInviteAcceptProcedure = "/metalstack.api.v2.TenantService/InviteAccept" - // TenantServiceInviteDeleteProcedure is the fully-qualified name of the TenantService's - // InviteDelete RPC. + // TenantServiceInviteDeleteProcedure is the procedure name of the TenantService's InviteDelete RPC. TenantServiceInviteDeleteProcedure = "/metalstack.api.v2.TenantService/InviteDelete" - // TenantServiceInvitesListProcedure is the fully-qualified name of the TenantService's InvitesList - // RPC. + // TenantServiceInvitesListProcedure is the procedure name of the TenantService's InvitesList RPC. TenantServiceInvitesListProcedure = "/metalstack.api.v2.TenantService/InvitesList" - // TenantServiceInviteGetProcedure is the fully-qualified name of the TenantService's InviteGet RPC. + // TenantServiceInviteGetProcedure is the procedure name of the TenantService's InviteGet RPC. TenantServiceInviteGetProcedure = "/metalstack.api.v2.TenantService/InviteGet" ) +var ( + tenantServiceCreateSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_tenant_proto.Services().ByName("TenantService").Methods().ByName("Create"), + Procedure: TenantServiceCreateProcedure, + } + }) + tenantServiceListSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_tenant_proto.Services().ByName("TenantService").Methods().ByName("List"), + Procedure: TenantServiceListProcedure, + } + }) + tenantServiceGetSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_tenant_proto.Services().ByName("TenantService").Methods().ByName("Get"), + Procedure: TenantServiceGetProcedure, + } + }) + tenantServiceUpdateSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_tenant_proto.Services().ByName("TenantService").Methods().ByName("Update"), + Procedure: TenantServiceUpdateProcedure, + } + }) + tenantServiceDeleteSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_tenant_proto.Services().ByName("TenantService").Methods().ByName("Delete"), + Procedure: TenantServiceDeleteProcedure, + } + }) + tenantServiceLeaveSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_tenant_proto.Services().ByName("TenantService").Methods().ByName("Leave"), + Procedure: TenantServiceLeaveProcedure, + } + }) + tenantServiceAddMemberSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_tenant_proto.Services().ByName("TenantService").Methods().ByName("AddMember"), + Procedure: TenantServiceAddMemberProcedure, + } + }) + tenantServiceRemoveMemberSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_tenant_proto.Services().ByName("TenantService").Methods().ByName("RemoveMember"), + Procedure: TenantServiceRemoveMemberProcedure, + } + }) + tenantServiceUpdateMemberSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_tenant_proto.Services().ByName("TenantService").Methods().ByName("UpdateMember"), + Procedure: TenantServiceUpdateMemberProcedure, + } + }) + tenantServiceInviteSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_tenant_proto.Services().ByName("TenantService").Methods().ByName("Invite"), + Procedure: TenantServiceInviteProcedure, + } + }) + tenantServiceInviteAcceptSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_tenant_proto.Services().ByName("TenantService").Methods().ByName("InviteAccept"), + Procedure: TenantServiceInviteAcceptProcedure, + } + }) + tenantServiceInviteDeleteSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_tenant_proto.Services().ByName("TenantService").Methods().ByName("InviteDelete"), + Procedure: TenantServiceInviteDeleteProcedure, + } + }) + tenantServiceInvitesListSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_tenant_proto.Services().ByName("TenantService").Methods().ByName("InvitesList"), + Procedure: TenantServiceInvitesListProcedure, + } + }) + tenantServiceInviteGetSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_tenant_proto.Services().ByName("TenantService").Methods().ByName("InviteGet"), + Procedure: TenantServiceInviteGetProcedure, + } + }) +) + // TenantServiceClient is a client for the metalstack.api.v2.TenantService service. type TenantServiceClient interface { // Creates a new tenant. @@ -100,462 +187,407 @@ type TenantServiceClient interface { InviteGet(context.Context, *v2.TenantServiceInviteGetRequest) (*v2.TenantServiceInviteGetResponse, error) } -// NewTenantServiceClient constructs a client for the metalstack.api.v2.TenantService 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 NewTenantServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) TenantServiceClient { - baseURL = strings.TrimRight(baseURL, "/") - tenantServiceMethods := v2.File_metalstack_api_v2_tenant_proto.Services().ByName("TenantService").Methods() - return &tenantServiceClient{ - create: connect.NewClient[v2.TenantServiceCreateRequest, v2.TenantServiceCreateResponse]( - httpClient, - baseURL+TenantServiceCreateProcedure, - connect.WithSchema(tenantServiceMethods.ByName("Create")), - connect.WithClientOptions(opts...), - ), - list: connect.NewClient[v2.TenantServiceListRequest, v2.TenantServiceListResponse]( - httpClient, - baseURL+TenantServiceListProcedure, - connect.WithSchema(tenantServiceMethods.ByName("List")), - connect.WithClientOptions(opts...), - ), - get: connect.NewClient[v2.TenantServiceGetRequest, v2.TenantServiceGetResponse]( - httpClient, - baseURL+TenantServiceGetProcedure, - connect.WithSchema(tenantServiceMethods.ByName("Get")), - connect.WithClientOptions(opts...), - ), - update: connect.NewClient[v2.TenantServiceUpdateRequest, v2.TenantServiceUpdateResponse]( - httpClient, - baseURL+TenantServiceUpdateProcedure, - connect.WithSchema(tenantServiceMethods.ByName("Update")), - connect.WithClientOptions(opts...), - ), - delete: connect.NewClient[v2.TenantServiceDeleteRequest, v2.TenantServiceDeleteResponse]( - httpClient, - baseURL+TenantServiceDeleteProcedure, - connect.WithSchema(tenantServiceMethods.ByName("Delete")), - connect.WithClientOptions(opts...), - ), - leave: connect.NewClient[v2.TenantServiceLeaveRequest, v2.TenantServiceLeaveResponse]( - httpClient, - baseURL+TenantServiceLeaveProcedure, - connect.WithSchema(tenantServiceMethods.ByName("Leave")), - connect.WithClientOptions(opts...), - ), - addMember: connect.NewClient[v2.TenantServiceAddMemberRequest, v2.TenantServiceAddMemberResponse]( - httpClient, - baseURL+TenantServiceAddMemberProcedure, - connect.WithSchema(tenantServiceMethods.ByName("AddMember")), - connect.WithClientOptions(opts...), - ), - removeMember: connect.NewClient[v2.TenantServiceRemoveMemberRequest, v2.TenantServiceRemoveMemberResponse]( - httpClient, - baseURL+TenantServiceRemoveMemberProcedure, - connect.WithSchema(tenantServiceMethods.ByName("RemoveMember")), - connect.WithClientOptions(opts...), - ), - updateMember: connect.NewClient[v2.TenantServiceUpdateMemberRequest, v2.TenantServiceUpdateMemberResponse]( - httpClient, - baseURL+TenantServiceUpdateMemberProcedure, - connect.WithSchema(tenantServiceMethods.ByName("UpdateMember")), - connect.WithClientOptions(opts...), - ), - invite: connect.NewClient[v2.TenantServiceInviteRequest, v2.TenantServiceInviteResponse]( - httpClient, - baseURL+TenantServiceInviteProcedure, - connect.WithSchema(tenantServiceMethods.ByName("Invite")), - connect.WithClientOptions(opts...), - ), - inviteAccept: connect.NewClient[v2.TenantServiceInviteAcceptRequest, v2.TenantServiceInviteAcceptResponse]( - httpClient, - baseURL+TenantServiceInviteAcceptProcedure, - connect.WithSchema(tenantServiceMethods.ByName("InviteAccept")), - connect.WithClientOptions(opts...), - ), - inviteDelete: connect.NewClient[v2.TenantServiceInviteDeleteRequest, v2.TenantServiceInviteDeleteResponse]( - httpClient, - baseURL+TenantServiceInviteDeleteProcedure, - connect.WithSchema(tenantServiceMethods.ByName("InviteDelete")), - connect.WithClientOptions(opts...), - ), - invitesList: connect.NewClient[v2.TenantServiceInvitesListRequest, v2.TenantServiceInvitesListResponse]( - httpClient, - baseURL+TenantServiceInvitesListProcedure, - connect.WithSchema(tenantServiceMethods.ByName("InvitesList")), - connect.WithClientOptions(opts...), - ), - inviteGet: connect.NewClient[v2.TenantServiceInviteGetRequest, v2.TenantServiceInviteGetResponse]( - httpClient, - baseURL+TenantServiceInviteGetProcedure, - connect.WithSchema(tenantServiceMethods.ByName("InviteGet")), - connect.WithClientOptions(opts...), - ), - } -} - -// tenantServiceClient implements TenantServiceClient. +// NewTenantServiceClient constructs a client for the metalstack.api.v2.TenantService service. +// Multiple service clients may share a single connect.Client. +func NewTenantServiceClient(client *connect.Client) TenantServiceClient { + return &tenantServiceClient{client: client} +} + +// TenantServiceHandler is an implementation of the metalstack.api.v2.TenantService service. +type TenantServiceHandler interface { + // Creates a new tenant. + Create(context.Context, *v2.TenantServiceCreateRequest) (*v2.TenantServiceCreateResponse, error) + // Returns the list of tenants. + List(context.Context, *v2.TenantServiceListRequest) (*v2.TenantServiceListResponse, error) + // Get a tenant. + Get(context.Context, *v2.TenantServiceGetRequest) (*v2.TenantServiceGetResponse, error) + // Update a tenant. + Update(context.Context, *v2.TenantServiceUpdateRequest) (*v2.TenantServiceUpdateResponse, error) + // Delete a tenant. + Delete(context.Context, *v2.TenantServiceDeleteRequest) (*v2.TenantServiceDeleteResponse, error) + // Leave removes a member from a tenant. + Leave(context.Context, *v2.TenantServiceLeaveRequest) (*v2.TenantServiceLeaveResponse, error) + // AddMember adds a member to a tenant. + AddMember(context.Context, *v2.TenantServiceAddMemberRequest) (*v2.TenantServiceAddMemberResponse, error) + // RemoveMember removes a member from a tenant. + RemoveMember(context.Context, *v2.TenantServiceRemoveMemberRequest) (*v2.TenantServiceRemoveMemberResponse, error) + // UpdateMember update a member of a tenant. + UpdateMember(context.Context, *v2.TenantServiceUpdateMemberRequest) (*v2.TenantServiceUpdateMemberResponse, error) + // Invite a user to a tenant. + Invite(context.Context, *v2.TenantServiceInviteRequest) (*v2.TenantServiceInviteResponse, error) + // InviteAccept is called from a user to accept an invitation. + InviteAccept(context.Context, *v2.TenantServiceInviteAcceptRequest) (*v2.TenantServiceInviteAcceptResponse, error) + // InviteDelete deletes a pending invitation. + InviteDelete(context.Context, *v2.TenantServiceInviteDeleteRequest) (*v2.TenantServiceInviteDeleteResponse, error) + // InvitesList list all invites to a tenant. + InvitesList(context.Context, *v2.TenantServiceInvitesListRequest) (*v2.TenantServiceInvitesListResponse, error) + // InviteGet get an invite. + InviteGet(context.Context, *v2.TenantServiceInviteGetRequest) (*v2.TenantServiceInviteGetResponse, error) +} + +// RegisterTenantServiceHandler registers svc as the metalstack.api.v2.TenantService implementation +// on server. +func RegisterTenantServiceHandler(server *connect.Server, svc TenantServiceHandler) { + adapter := tenantServiceHandler{svc: svc} + server.Register( + connect.Method{Spec: tenantServiceCreateSpec(), Handler: adapter.create}, + connect.Method{Spec: tenantServiceListSpec(), Handler: adapter.list}, + connect.Method{Spec: tenantServiceGetSpec(), Handler: adapter.get}, + connect.Method{Spec: tenantServiceUpdateSpec(), Handler: adapter.update}, + connect.Method{Spec: tenantServiceDeleteSpec(), Handler: adapter.delete}, + connect.Method{Spec: tenantServiceLeaveSpec(), Handler: adapter.leave}, + connect.Method{Spec: tenantServiceAddMemberSpec(), Handler: adapter.addMember}, + connect.Method{Spec: tenantServiceRemoveMemberSpec(), Handler: adapter.removeMember}, + connect.Method{Spec: tenantServiceUpdateMemberSpec(), Handler: adapter.updateMember}, + connect.Method{Spec: tenantServiceInviteSpec(), Handler: adapter.invite}, + connect.Method{Spec: tenantServiceInviteAcceptSpec(), Handler: adapter.inviteAccept}, + connect.Method{Spec: tenantServiceInviteDeleteSpec(), Handler: adapter.inviteDelete}, + connect.Method{Spec: tenantServiceInvitesListSpec(), Handler: adapter.invitesList}, + connect.Method{Spec: tenantServiceInviteGetSpec(), Handler: adapter.inviteGet}, + ) +} + +// UnimplementedTenantServiceHandler returns CodeUnimplemented from all methods. +type UnimplementedTenantServiceHandler struct{} + +func (UnimplementedTenantServiceHandler) Create(context.Context, *v2.TenantServiceCreateRequest) (*v2.TenantServiceCreateResponse, error) { + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.TenantService.Create is not implemented") +} + +func (UnimplementedTenantServiceHandler) List(context.Context, *v2.TenantServiceListRequest) (*v2.TenantServiceListResponse, error) { + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.TenantService.List is not implemented") +} + +func (UnimplementedTenantServiceHandler) Get(context.Context, *v2.TenantServiceGetRequest) (*v2.TenantServiceGetResponse, error) { + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.TenantService.Get is not implemented") +} + +func (UnimplementedTenantServiceHandler) Update(context.Context, *v2.TenantServiceUpdateRequest) (*v2.TenantServiceUpdateResponse, error) { + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.TenantService.Update is not implemented") +} + +func (UnimplementedTenantServiceHandler) Delete(context.Context, *v2.TenantServiceDeleteRequest) (*v2.TenantServiceDeleteResponse, error) { + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.TenantService.Delete is not implemented") +} + +func (UnimplementedTenantServiceHandler) Leave(context.Context, *v2.TenantServiceLeaveRequest) (*v2.TenantServiceLeaveResponse, error) { + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.TenantService.Leave is not implemented") +} + +func (UnimplementedTenantServiceHandler) AddMember(context.Context, *v2.TenantServiceAddMemberRequest) (*v2.TenantServiceAddMemberResponse, error) { + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.TenantService.AddMember is not implemented") +} + +func (UnimplementedTenantServiceHandler) RemoveMember(context.Context, *v2.TenantServiceRemoveMemberRequest) (*v2.TenantServiceRemoveMemberResponse, error) { + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.TenantService.RemoveMember is not implemented") +} + +func (UnimplementedTenantServiceHandler) UpdateMember(context.Context, *v2.TenantServiceUpdateMemberRequest) (*v2.TenantServiceUpdateMemberResponse, error) { + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.TenantService.UpdateMember is not implemented") +} + +func (UnimplementedTenantServiceHandler) Invite(context.Context, *v2.TenantServiceInviteRequest) (*v2.TenantServiceInviteResponse, error) { + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.TenantService.Invite is not implemented") +} + +func (UnimplementedTenantServiceHandler) InviteAccept(context.Context, *v2.TenantServiceInviteAcceptRequest) (*v2.TenantServiceInviteAcceptResponse, error) { + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.TenantService.InviteAccept is not implemented") +} + +func (UnimplementedTenantServiceHandler) InviteDelete(context.Context, *v2.TenantServiceInviteDeleteRequest) (*v2.TenantServiceInviteDeleteResponse, error) { + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.TenantService.InviteDelete is not implemented") +} + +func (UnimplementedTenantServiceHandler) InvitesList(context.Context, *v2.TenantServiceInvitesListRequest) (*v2.TenantServiceInvitesListResponse, error) { + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.TenantService.InvitesList is not implemented") +} + +func (UnimplementedTenantServiceHandler) InviteGet(context.Context, *v2.TenantServiceInviteGetRequest) (*v2.TenantServiceInviteGetResponse, error) { + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.TenantService.InviteGet is not implemented") +} + type tenantServiceClient struct { - create *connect.Client[v2.TenantServiceCreateRequest, v2.TenantServiceCreateResponse] - list *connect.Client[v2.TenantServiceListRequest, v2.TenantServiceListResponse] - get *connect.Client[v2.TenantServiceGetRequest, v2.TenantServiceGetResponse] - update *connect.Client[v2.TenantServiceUpdateRequest, v2.TenantServiceUpdateResponse] - delete *connect.Client[v2.TenantServiceDeleteRequest, v2.TenantServiceDeleteResponse] - leave *connect.Client[v2.TenantServiceLeaveRequest, v2.TenantServiceLeaveResponse] - addMember *connect.Client[v2.TenantServiceAddMemberRequest, v2.TenantServiceAddMemberResponse] - removeMember *connect.Client[v2.TenantServiceRemoveMemberRequest, v2.TenantServiceRemoveMemberResponse] - updateMember *connect.Client[v2.TenantServiceUpdateMemberRequest, v2.TenantServiceUpdateMemberResponse] - invite *connect.Client[v2.TenantServiceInviteRequest, v2.TenantServiceInviteResponse] - inviteAccept *connect.Client[v2.TenantServiceInviteAcceptRequest, v2.TenantServiceInviteAcceptResponse] - inviteDelete *connect.Client[v2.TenantServiceInviteDeleteRequest, v2.TenantServiceInviteDeleteResponse] - invitesList *connect.Client[v2.TenantServiceInvitesListRequest, v2.TenantServiceInvitesListResponse] - inviteGet *connect.Client[v2.TenantServiceInviteGetRequest, v2.TenantServiceInviteGetResponse] -} - -// Create calls metalstack.api.v2.TenantService.Create. + client *connect.Client +} + func (c *tenantServiceClient) Create(ctx context.Context, req *v2.TenantServiceCreateRequest) (*v2.TenantServiceCreateResponse, error) { - response, err := c.create.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err + var res v2.TenantServiceCreateResponse + if err := c.client.CallUnary(ctx, tenantServiceCreateSpec(), req, &res); err != nil { + return nil, err } - return nil, err + return &res, nil } -// List calls metalstack.api.v2.TenantService.List. func (c *tenantServiceClient) List(ctx context.Context, req *v2.TenantServiceListRequest) (*v2.TenantServiceListResponse, error) { - response, err := c.list.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err + var res v2.TenantServiceListResponse + if err := c.client.CallUnary(ctx, tenantServiceListSpec(), req, &res); err != nil { + return nil, err } - return nil, err + return &res, nil } -// Get calls metalstack.api.v2.TenantService.Get. func (c *tenantServiceClient) Get(ctx context.Context, req *v2.TenantServiceGetRequest) (*v2.TenantServiceGetResponse, error) { - response, err := c.get.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err + var res v2.TenantServiceGetResponse + if err := c.client.CallUnary(ctx, tenantServiceGetSpec(), req, &res); err != nil { + return nil, err } - return nil, err + return &res, nil } -// Update calls metalstack.api.v2.TenantService.Update. func (c *tenantServiceClient) Update(ctx context.Context, req *v2.TenantServiceUpdateRequest) (*v2.TenantServiceUpdateResponse, error) { - response, err := c.update.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err + var res v2.TenantServiceUpdateResponse + if err := c.client.CallUnary(ctx, tenantServiceUpdateSpec(), req, &res); err != nil { + return nil, err } - return nil, err + return &res, nil } -// Delete calls metalstack.api.v2.TenantService.Delete. func (c *tenantServiceClient) Delete(ctx context.Context, req *v2.TenantServiceDeleteRequest) (*v2.TenantServiceDeleteResponse, error) { - response, err := c.delete.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err + var res v2.TenantServiceDeleteResponse + if err := c.client.CallUnary(ctx, tenantServiceDeleteSpec(), req, &res); err != nil { + return nil, err } - return nil, err + return &res, nil } -// Leave calls metalstack.api.v2.TenantService.Leave. func (c *tenantServiceClient) Leave(ctx context.Context, req *v2.TenantServiceLeaveRequest) (*v2.TenantServiceLeaveResponse, error) { - response, err := c.leave.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err + var res v2.TenantServiceLeaveResponse + if err := c.client.CallUnary(ctx, tenantServiceLeaveSpec(), req, &res); err != nil { + return nil, err } - return nil, err + return &res, nil } -// AddMember calls metalstack.api.v2.TenantService.AddMember. func (c *tenantServiceClient) AddMember(ctx context.Context, req *v2.TenantServiceAddMemberRequest) (*v2.TenantServiceAddMemberResponse, error) { - response, err := c.addMember.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err + var res v2.TenantServiceAddMemberResponse + if err := c.client.CallUnary(ctx, tenantServiceAddMemberSpec(), req, &res); err != nil { + return nil, err } - return nil, err + return &res, nil } -// RemoveMember calls metalstack.api.v2.TenantService.RemoveMember. func (c *tenantServiceClient) RemoveMember(ctx context.Context, req *v2.TenantServiceRemoveMemberRequest) (*v2.TenantServiceRemoveMemberResponse, error) { - response, err := c.removeMember.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err + var res v2.TenantServiceRemoveMemberResponse + if err := c.client.CallUnary(ctx, tenantServiceRemoveMemberSpec(), req, &res); err != nil { + return nil, err } - return nil, err + return &res, nil } -// UpdateMember calls metalstack.api.v2.TenantService.UpdateMember. func (c *tenantServiceClient) UpdateMember(ctx context.Context, req *v2.TenantServiceUpdateMemberRequest) (*v2.TenantServiceUpdateMemberResponse, error) { - response, err := c.updateMember.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err + var res v2.TenantServiceUpdateMemberResponse + if err := c.client.CallUnary(ctx, tenantServiceUpdateMemberSpec(), req, &res); err != nil { + return nil, err } - return nil, err + return &res, nil } -// Invite calls metalstack.api.v2.TenantService.Invite. func (c *tenantServiceClient) Invite(ctx context.Context, req *v2.TenantServiceInviteRequest) (*v2.TenantServiceInviteResponse, error) { - response, err := c.invite.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err + var res v2.TenantServiceInviteResponse + if err := c.client.CallUnary(ctx, tenantServiceInviteSpec(), req, &res); err != nil { + return nil, err } - return nil, err + return &res, nil } -// InviteAccept calls metalstack.api.v2.TenantService.InviteAccept. func (c *tenantServiceClient) InviteAccept(ctx context.Context, req *v2.TenantServiceInviteAcceptRequest) (*v2.TenantServiceInviteAcceptResponse, error) { - response, err := c.inviteAccept.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err + var res v2.TenantServiceInviteAcceptResponse + if err := c.client.CallUnary(ctx, tenantServiceInviteAcceptSpec(), req, &res); err != nil { + return nil, err } - return nil, err + return &res, nil } -// InviteDelete calls metalstack.api.v2.TenantService.InviteDelete. func (c *tenantServiceClient) InviteDelete(ctx context.Context, req *v2.TenantServiceInviteDeleteRequest) (*v2.TenantServiceInviteDeleteResponse, error) { - response, err := c.inviteDelete.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err + var res v2.TenantServiceInviteDeleteResponse + if err := c.client.CallUnary(ctx, tenantServiceInviteDeleteSpec(), req, &res); err != nil { + return nil, err } - return nil, err + return &res, nil } -// InvitesList calls metalstack.api.v2.TenantService.InvitesList. func (c *tenantServiceClient) InvitesList(ctx context.Context, req *v2.TenantServiceInvitesListRequest) (*v2.TenantServiceInvitesListResponse, error) { - response, err := c.invitesList.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err + var res v2.TenantServiceInvitesListResponse + if err := c.client.CallUnary(ctx, tenantServiceInvitesListSpec(), req, &res); err != nil { + return nil, err } - return nil, err + return &res, nil } -// InviteGet calls metalstack.api.v2.TenantService.InviteGet. func (c *tenantServiceClient) InviteGet(ctx context.Context, req *v2.TenantServiceInviteGetRequest) (*v2.TenantServiceInviteGetResponse, error) { - response, err := c.inviteGet.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err + var res v2.TenantServiceInviteGetResponse + if err := c.client.CallUnary(ctx, tenantServiceInviteGetSpec(), req, &res); err != nil { + return nil, err } - return nil, err + return &res, nil } -// TenantServiceHandler is an implementation of the metalstack.api.v2.TenantService service. -type TenantServiceHandler interface { - // Creates a new tenant. - Create(context.Context, *v2.TenantServiceCreateRequest) (*v2.TenantServiceCreateResponse, error) - // Returns the list of tenants. - List(context.Context, *v2.TenantServiceListRequest) (*v2.TenantServiceListResponse, error) - // Get a tenant. - Get(context.Context, *v2.TenantServiceGetRequest) (*v2.TenantServiceGetResponse, error) - // Update a tenant. - Update(context.Context, *v2.TenantServiceUpdateRequest) (*v2.TenantServiceUpdateResponse, error) - // Delete a tenant. - Delete(context.Context, *v2.TenantServiceDeleteRequest) (*v2.TenantServiceDeleteResponse, error) - // Leave removes a member from a tenant. - Leave(context.Context, *v2.TenantServiceLeaveRequest) (*v2.TenantServiceLeaveResponse, error) - // AddMember adds a member to a tenant. - AddMember(context.Context, *v2.TenantServiceAddMemberRequest) (*v2.TenantServiceAddMemberResponse, error) - // RemoveMember removes a member from a tenant. - RemoveMember(context.Context, *v2.TenantServiceRemoveMemberRequest) (*v2.TenantServiceRemoveMemberResponse, error) - // UpdateMember update a member of a tenant. - UpdateMember(context.Context, *v2.TenantServiceUpdateMemberRequest) (*v2.TenantServiceUpdateMemberResponse, error) - // Invite a user to a tenant. - Invite(context.Context, *v2.TenantServiceInviteRequest) (*v2.TenantServiceInviteResponse, error) - // InviteAccept is called from a user to accept an invitation. - InviteAccept(context.Context, *v2.TenantServiceInviteAcceptRequest) (*v2.TenantServiceInviteAcceptResponse, error) - // InviteDelete deletes a pending invitation. - InviteDelete(context.Context, *v2.TenantServiceInviteDeleteRequest) (*v2.TenantServiceInviteDeleteResponse, error) - // InvitesList list all invites to a tenant. - InvitesList(context.Context, *v2.TenantServiceInvitesListRequest) (*v2.TenantServiceInvitesListResponse, error) - // InviteGet get an invite. - InviteGet(context.Context, *v2.TenantServiceInviteGetRequest) (*v2.TenantServiceInviteGetResponse, error) -} +type tenantServiceHandler struct{ svc TenantServiceHandler } -// NewTenantServiceHandler 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 NewTenantServiceHandler(svc TenantServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) { - tenantServiceMethods := v2.File_metalstack_api_v2_tenant_proto.Services().ByName("TenantService").Methods() - tenantServiceCreateHandler := connect.NewUnaryHandlerSimple( - TenantServiceCreateProcedure, - svc.Create, - connect.WithSchema(tenantServiceMethods.ByName("Create")), - connect.WithHandlerOptions(opts...), - ) - tenantServiceListHandler := connect.NewUnaryHandlerSimple( - TenantServiceListProcedure, - svc.List, - connect.WithSchema(tenantServiceMethods.ByName("List")), - connect.WithHandlerOptions(opts...), - ) - tenantServiceGetHandler := connect.NewUnaryHandlerSimple( - TenantServiceGetProcedure, - svc.Get, - connect.WithSchema(tenantServiceMethods.ByName("Get")), - connect.WithHandlerOptions(opts...), - ) - tenantServiceUpdateHandler := connect.NewUnaryHandlerSimple( - TenantServiceUpdateProcedure, - svc.Update, - connect.WithSchema(tenantServiceMethods.ByName("Update")), - connect.WithHandlerOptions(opts...), - ) - tenantServiceDeleteHandler := connect.NewUnaryHandlerSimple( - TenantServiceDeleteProcedure, - svc.Delete, - connect.WithSchema(tenantServiceMethods.ByName("Delete")), - connect.WithHandlerOptions(opts...), - ) - tenantServiceLeaveHandler := connect.NewUnaryHandlerSimple( - TenantServiceLeaveProcedure, - svc.Leave, - connect.WithSchema(tenantServiceMethods.ByName("Leave")), - connect.WithHandlerOptions(opts...), - ) - tenantServiceAddMemberHandler := connect.NewUnaryHandlerSimple( - TenantServiceAddMemberProcedure, - svc.AddMember, - connect.WithSchema(tenantServiceMethods.ByName("AddMember")), - connect.WithHandlerOptions(opts...), - ) - tenantServiceRemoveMemberHandler := connect.NewUnaryHandlerSimple( - TenantServiceRemoveMemberProcedure, - svc.RemoveMember, - connect.WithSchema(tenantServiceMethods.ByName("RemoveMember")), - connect.WithHandlerOptions(opts...), - ) - tenantServiceUpdateMemberHandler := connect.NewUnaryHandlerSimple( - TenantServiceUpdateMemberProcedure, - svc.UpdateMember, - connect.WithSchema(tenantServiceMethods.ByName("UpdateMember")), - connect.WithHandlerOptions(opts...), - ) - tenantServiceInviteHandler := connect.NewUnaryHandlerSimple( - TenantServiceInviteProcedure, - svc.Invite, - connect.WithSchema(tenantServiceMethods.ByName("Invite")), - connect.WithHandlerOptions(opts...), - ) - tenantServiceInviteAcceptHandler := connect.NewUnaryHandlerSimple( - TenantServiceInviteAcceptProcedure, - svc.InviteAccept, - connect.WithSchema(tenantServiceMethods.ByName("InviteAccept")), - connect.WithHandlerOptions(opts...), - ) - tenantServiceInviteDeleteHandler := connect.NewUnaryHandlerSimple( - TenantServiceInviteDeleteProcedure, - svc.InviteDelete, - connect.WithSchema(tenantServiceMethods.ByName("InviteDelete")), - connect.WithHandlerOptions(opts...), - ) - tenantServiceInvitesListHandler := connect.NewUnaryHandlerSimple( - TenantServiceInvitesListProcedure, - svc.InvitesList, - connect.WithSchema(tenantServiceMethods.ByName("InvitesList")), - connect.WithHandlerOptions(opts...), - ) - tenantServiceInviteGetHandler := connect.NewUnaryHandlerSimple( - TenantServiceInviteGetProcedure, - svc.InviteGet, - connect.WithSchema(tenantServiceMethods.ByName("InviteGet")), - connect.WithHandlerOptions(opts...), - ) - return "/metalstack.api.v2.TenantService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - switch r.URL.Path { - case TenantServiceCreateProcedure: - tenantServiceCreateHandler.ServeHTTP(w, r) - case TenantServiceListProcedure: - tenantServiceListHandler.ServeHTTP(w, r) - case TenantServiceGetProcedure: - tenantServiceGetHandler.ServeHTTP(w, r) - case TenantServiceUpdateProcedure: - tenantServiceUpdateHandler.ServeHTTP(w, r) - case TenantServiceDeleteProcedure: - tenantServiceDeleteHandler.ServeHTTP(w, r) - case TenantServiceLeaveProcedure: - tenantServiceLeaveHandler.ServeHTTP(w, r) - case TenantServiceAddMemberProcedure: - tenantServiceAddMemberHandler.ServeHTTP(w, r) - case TenantServiceRemoveMemberProcedure: - tenantServiceRemoveMemberHandler.ServeHTTP(w, r) - case TenantServiceUpdateMemberProcedure: - tenantServiceUpdateMemberHandler.ServeHTTP(w, r) - case TenantServiceInviteProcedure: - tenantServiceInviteHandler.ServeHTTP(w, r) - case TenantServiceInviteAcceptProcedure: - tenantServiceInviteAcceptHandler.ServeHTTP(w, r) - case TenantServiceInviteDeleteProcedure: - tenantServiceInviteDeleteHandler.ServeHTTP(w, r) - case TenantServiceInvitesListProcedure: - tenantServiceInvitesListHandler.ServeHTTP(w, r) - case TenantServiceInviteGetProcedure: - tenantServiceInviteGetHandler.ServeHTTP(w, r) - default: - http.NotFound(w, r) - } - }) -} - -// UnimplementedTenantServiceHandler returns CodeUnimplemented from all methods. -type UnimplementedTenantServiceHandler struct{} - -func (UnimplementedTenantServiceHandler) Create(context.Context, *v2.TenantServiceCreateRequest) (*v2.TenantServiceCreateResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.TenantService.Create is not implemented")) +func (h tenantServiceHandler) create(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.TenantServiceCreateRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Create(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } -func (UnimplementedTenantServiceHandler) List(context.Context, *v2.TenantServiceListRequest) (*v2.TenantServiceListResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.TenantService.List is not implemented")) +func (h tenantServiceHandler) list(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.TenantServiceListRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.List(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } -func (UnimplementedTenantServiceHandler) Get(context.Context, *v2.TenantServiceGetRequest) (*v2.TenantServiceGetResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.TenantService.Get is not implemented")) +func (h tenantServiceHandler) get(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.TenantServiceGetRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Get(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } -func (UnimplementedTenantServiceHandler) Update(context.Context, *v2.TenantServiceUpdateRequest) (*v2.TenantServiceUpdateResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.TenantService.Update is not implemented")) +func (h tenantServiceHandler) update(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.TenantServiceUpdateRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Update(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } -func (UnimplementedTenantServiceHandler) Delete(context.Context, *v2.TenantServiceDeleteRequest) (*v2.TenantServiceDeleteResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.TenantService.Delete is not implemented")) +func (h tenantServiceHandler) delete(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.TenantServiceDeleteRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Delete(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } -func (UnimplementedTenantServiceHandler) Leave(context.Context, *v2.TenantServiceLeaveRequest) (*v2.TenantServiceLeaveResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.TenantService.Leave is not implemented")) +func (h tenantServiceHandler) leave(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.TenantServiceLeaveRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Leave(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } -func (UnimplementedTenantServiceHandler) AddMember(context.Context, *v2.TenantServiceAddMemberRequest) (*v2.TenantServiceAddMemberResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.TenantService.AddMember is not implemented")) +func (h tenantServiceHandler) addMember(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.TenantServiceAddMemberRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.AddMember(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } -func (UnimplementedTenantServiceHandler) RemoveMember(context.Context, *v2.TenantServiceRemoveMemberRequest) (*v2.TenantServiceRemoveMemberResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.TenantService.RemoveMember is not implemented")) +func (h tenantServiceHandler) removeMember(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.TenantServiceRemoveMemberRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.RemoveMember(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } -func (UnimplementedTenantServiceHandler) UpdateMember(context.Context, *v2.TenantServiceUpdateMemberRequest) (*v2.TenantServiceUpdateMemberResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.TenantService.UpdateMember is not implemented")) +func (h tenantServiceHandler) updateMember(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.TenantServiceUpdateMemberRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.UpdateMember(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } -func (UnimplementedTenantServiceHandler) Invite(context.Context, *v2.TenantServiceInviteRequest) (*v2.TenantServiceInviteResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.TenantService.Invite is not implemented")) +func (h tenantServiceHandler) invite(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.TenantServiceInviteRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Invite(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } -func (UnimplementedTenantServiceHandler) InviteAccept(context.Context, *v2.TenantServiceInviteAcceptRequest) (*v2.TenantServiceInviteAcceptResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.TenantService.InviteAccept is not implemented")) +func (h tenantServiceHandler) inviteAccept(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.TenantServiceInviteAcceptRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.InviteAccept(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } -func (UnimplementedTenantServiceHandler) InviteDelete(context.Context, *v2.TenantServiceInviteDeleteRequest) (*v2.TenantServiceInviteDeleteResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.TenantService.InviteDelete is not implemented")) +func (h tenantServiceHandler) inviteDelete(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.TenantServiceInviteDeleteRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.InviteDelete(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } -func (UnimplementedTenantServiceHandler) InvitesList(context.Context, *v2.TenantServiceInvitesListRequest) (*v2.TenantServiceInvitesListResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.TenantService.InvitesList is not implemented")) +func (h tenantServiceHandler) invitesList(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.TenantServiceInvitesListRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.InvitesList(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } -func (UnimplementedTenantServiceHandler) InviteGet(context.Context, *v2.TenantServiceInviteGetRequest) (*v2.TenantServiceInviteGetResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.TenantService.InviteGet is not implemented")) +func (h tenantServiceHandler) inviteGet(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.TenantServiceInviteGetRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.InviteGet(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } diff --git a/go/metalstack/api/v2/apiv2connect/token.connect.go b/go/metalstack/api/v2/apiv2connect/token.connect.go index b5eb7d0b..5baa0c31 100644 --- a/go/metalstack/api/v2/apiv2connect/token.connect.go +++ b/go/metalstack/api/v2/apiv2connect/token.connect.go @@ -5,48 +5,84 @@ package apiv2connect import ( - connect "connectrpc.com/connect" + connect "connectrpc.com/connect/v2" context "context" - errors "errors" v2 "github.com/metal-stack/api/go/metalstack/api/v2" - http "net/http" - strings "strings" + sync "sync" ) -// 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 ( // TokenServiceName is the fully-qualified name of the TokenService service. TokenServiceName = "metalstack.api.v2.TokenService" ) -// 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. +// These constants are the procedure 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 ( - // TokenServiceGetProcedure is the fully-qualified name of the TokenService's Get RPC. + // TokenServiceGetProcedure is the procedure name of the TokenService's Get RPC. TokenServiceGetProcedure = "/metalstack.api.v2.TokenService/Get" - // TokenServiceCreateProcedure is the fully-qualified name of the TokenService's Create RPC. + // TokenServiceCreateProcedure is the procedure name of the TokenService's Create RPC. TokenServiceCreateProcedure = "/metalstack.api.v2.TokenService/Create" - // TokenServiceUpdateProcedure is the fully-qualified name of the TokenService's Update RPC. + // TokenServiceUpdateProcedure is the procedure name of the TokenService's Update RPC. TokenServiceUpdateProcedure = "/metalstack.api.v2.TokenService/Update" - // TokenServiceListProcedure is the fully-qualified name of the TokenService's List RPC. + // TokenServiceListProcedure is the procedure name of the TokenService's List RPC. TokenServiceListProcedure = "/metalstack.api.v2.TokenService/List" - // TokenServiceRevokeProcedure is the fully-qualified name of the TokenService's Revoke RPC. + // TokenServiceRevokeProcedure is the procedure name of the TokenService's Revoke RPC. TokenServiceRevokeProcedure = "/metalstack.api.v2.TokenService/Revoke" - // TokenServiceRefreshProcedure is the fully-qualified name of the TokenService's Refresh RPC. + // TokenServiceRefreshProcedure is the procedure name of the TokenService's Refresh RPC. TokenServiceRefreshProcedure = "/metalstack.api.v2.TokenService/Refresh" ) +var ( + tokenServiceGetSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_token_proto.Services().ByName("TokenService").Methods().ByName("Get"), + Procedure: TokenServiceGetProcedure, + } + }) + tokenServiceCreateSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_token_proto.Services().ByName("TokenService").Methods().ByName("Create"), + Procedure: TokenServiceCreateProcedure, + } + }) + tokenServiceUpdateSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_token_proto.Services().ByName("TokenService").Methods().ByName("Update"), + Procedure: TokenServiceUpdateProcedure, + } + }) + tokenServiceListSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_token_proto.Services().ByName("TokenService").Methods().ByName("List"), + Procedure: TokenServiceListProcedure, + } + }) + tokenServiceRevokeSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_token_proto.Services().ByName("TokenService").Methods().ByName("Revoke"), + Procedure: TokenServiceRevokeProcedure, + } + }) + tokenServiceRefreshSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_token_proto.Services().ByName("TokenService").Methods().ByName("Refresh"), + Procedure: TokenServiceRefreshProcedure, + } + }) +) + // TokenServiceClient is a client for the metalstack.api.v2.TokenService service. type TokenServiceClient interface { // Returns the token with the specified UUID. @@ -63,118 +99,10 @@ type TokenServiceClient interface { Refresh(context.Context, *v2.TokenServiceRefreshRequest) (*v2.TokenServiceRefreshResponse, error) } -// NewTokenServiceClient constructs a client for the metalstack.api.v2.TokenService 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 NewTokenServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) TokenServiceClient { - baseURL = strings.TrimRight(baseURL, "/") - tokenServiceMethods := v2.File_metalstack_api_v2_token_proto.Services().ByName("TokenService").Methods() - return &tokenServiceClient{ - get: connect.NewClient[v2.TokenServiceGetRequest, v2.TokenServiceGetResponse]( - httpClient, - baseURL+TokenServiceGetProcedure, - connect.WithSchema(tokenServiceMethods.ByName("Get")), - connect.WithClientOptions(opts...), - ), - create: connect.NewClient[v2.TokenServiceCreateRequest, v2.TokenServiceCreateResponse]( - httpClient, - baseURL+TokenServiceCreateProcedure, - connect.WithSchema(tokenServiceMethods.ByName("Create")), - connect.WithClientOptions(opts...), - ), - update: connect.NewClient[v2.TokenServiceUpdateRequest, v2.TokenServiceUpdateResponse]( - httpClient, - baseURL+TokenServiceUpdateProcedure, - connect.WithSchema(tokenServiceMethods.ByName("Update")), - connect.WithClientOptions(opts...), - ), - list: connect.NewClient[v2.TokenServiceListRequest, v2.TokenServiceListResponse]( - httpClient, - baseURL+TokenServiceListProcedure, - connect.WithSchema(tokenServiceMethods.ByName("List")), - connect.WithClientOptions(opts...), - ), - revoke: connect.NewClient[v2.TokenServiceRevokeRequest, v2.TokenServiceRevokeResponse]( - httpClient, - baseURL+TokenServiceRevokeProcedure, - connect.WithSchema(tokenServiceMethods.ByName("Revoke")), - connect.WithClientOptions(opts...), - ), - refresh: connect.NewClient[v2.TokenServiceRefreshRequest, v2.TokenServiceRefreshResponse]( - httpClient, - baseURL+TokenServiceRefreshProcedure, - connect.WithSchema(tokenServiceMethods.ByName("Refresh")), - connect.WithClientOptions(opts...), - ), - } -} - -// tokenServiceClient implements TokenServiceClient. -type tokenServiceClient struct { - get *connect.Client[v2.TokenServiceGetRequest, v2.TokenServiceGetResponse] - create *connect.Client[v2.TokenServiceCreateRequest, v2.TokenServiceCreateResponse] - update *connect.Client[v2.TokenServiceUpdateRequest, v2.TokenServiceUpdateResponse] - list *connect.Client[v2.TokenServiceListRequest, v2.TokenServiceListResponse] - revoke *connect.Client[v2.TokenServiceRevokeRequest, v2.TokenServiceRevokeResponse] - refresh *connect.Client[v2.TokenServiceRefreshRequest, v2.TokenServiceRefreshResponse] -} - -// Get calls metalstack.api.v2.TokenService.Get. -func (c *tokenServiceClient) Get(ctx context.Context, req *v2.TokenServiceGetRequest) (*v2.TokenServiceGetResponse, error) { - response, err := c.get.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err -} - -// Create calls metalstack.api.v2.TokenService.Create. -func (c *tokenServiceClient) Create(ctx context.Context, req *v2.TokenServiceCreateRequest) (*v2.TokenServiceCreateResponse, error) { - response, err := c.create.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err -} - -// Update calls metalstack.api.v2.TokenService.Update. -func (c *tokenServiceClient) Update(ctx context.Context, req *v2.TokenServiceUpdateRequest) (*v2.TokenServiceUpdateResponse, error) { - response, err := c.update.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err -} - -// List calls metalstack.api.v2.TokenService.List. -func (c *tokenServiceClient) List(ctx context.Context, req *v2.TokenServiceListRequest) (*v2.TokenServiceListResponse, error) { - response, err := c.list.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err -} - -// Revoke calls metalstack.api.v2.TokenService.Revoke. -func (c *tokenServiceClient) Revoke(ctx context.Context, req *v2.TokenServiceRevokeRequest) (*v2.TokenServiceRevokeResponse, error) { - response, err := c.revoke.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err -} - -// Refresh calls metalstack.api.v2.TokenService.Refresh. -func (c *tokenServiceClient) Refresh(ctx context.Context, req *v2.TokenServiceRefreshRequest) (*v2.TokenServiceRefreshResponse, error) { - response, err := c.refresh.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err +// NewTokenServiceClient constructs a client for the metalstack.api.v2.TokenService service. +// Multiple service clients may share a single connect.Client. +func NewTokenServiceClient(client *connect.Client) TokenServiceClient { + return &tokenServiceClient{client: client} } // TokenServiceHandler is an implementation of the metalstack.api.v2.TokenService service. @@ -193,92 +121,169 @@ type TokenServiceHandler interface { Refresh(context.Context, *v2.TokenServiceRefreshRequest) (*v2.TokenServiceRefreshResponse, error) } -// NewTokenServiceHandler 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 NewTokenServiceHandler(svc TokenServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) { - tokenServiceMethods := v2.File_metalstack_api_v2_token_proto.Services().ByName("TokenService").Methods() - tokenServiceGetHandler := connect.NewUnaryHandlerSimple( - TokenServiceGetProcedure, - svc.Get, - connect.WithSchema(tokenServiceMethods.ByName("Get")), - connect.WithHandlerOptions(opts...), - ) - tokenServiceCreateHandler := connect.NewUnaryHandlerSimple( - TokenServiceCreateProcedure, - svc.Create, - connect.WithSchema(tokenServiceMethods.ByName("Create")), - connect.WithHandlerOptions(opts...), +// RegisterTokenServiceHandler registers svc as the metalstack.api.v2.TokenService implementation on +// server. +func RegisterTokenServiceHandler(server *connect.Server, svc TokenServiceHandler) { + adapter := tokenServiceHandler{svc: svc} + server.Register( + connect.Method{Spec: tokenServiceGetSpec(), Handler: adapter.get}, + connect.Method{Spec: tokenServiceCreateSpec(), Handler: adapter.create}, + connect.Method{Spec: tokenServiceUpdateSpec(), Handler: adapter.update}, + connect.Method{Spec: tokenServiceListSpec(), Handler: adapter.list}, + connect.Method{Spec: tokenServiceRevokeSpec(), Handler: adapter.revoke}, + connect.Method{Spec: tokenServiceRefreshSpec(), Handler: adapter.refresh}, ) - tokenServiceUpdateHandler := connect.NewUnaryHandlerSimple( - TokenServiceUpdateProcedure, - svc.Update, - connect.WithSchema(tokenServiceMethods.ByName("Update")), - connect.WithHandlerOptions(opts...), - ) - tokenServiceListHandler := connect.NewUnaryHandlerSimple( - TokenServiceListProcedure, - svc.List, - connect.WithSchema(tokenServiceMethods.ByName("List")), - connect.WithHandlerOptions(opts...), - ) - tokenServiceRevokeHandler := connect.NewUnaryHandlerSimple( - TokenServiceRevokeProcedure, - svc.Revoke, - connect.WithSchema(tokenServiceMethods.ByName("Revoke")), - connect.WithHandlerOptions(opts...), - ) - tokenServiceRefreshHandler := connect.NewUnaryHandlerSimple( - TokenServiceRefreshProcedure, - svc.Refresh, - connect.WithSchema(tokenServiceMethods.ByName("Refresh")), - connect.WithHandlerOptions(opts...), - ) - return "/metalstack.api.v2.TokenService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - switch r.URL.Path { - case TokenServiceGetProcedure: - tokenServiceGetHandler.ServeHTTP(w, r) - case TokenServiceCreateProcedure: - tokenServiceCreateHandler.ServeHTTP(w, r) - case TokenServiceUpdateProcedure: - tokenServiceUpdateHandler.ServeHTTP(w, r) - case TokenServiceListProcedure: - tokenServiceListHandler.ServeHTTP(w, r) - case TokenServiceRevokeProcedure: - tokenServiceRevokeHandler.ServeHTTP(w, r) - case TokenServiceRefreshProcedure: - tokenServiceRefreshHandler.ServeHTTP(w, r) - default: - http.NotFound(w, r) - } - }) } // UnimplementedTokenServiceHandler returns CodeUnimplemented from all methods. type UnimplementedTokenServiceHandler struct{} func (UnimplementedTokenServiceHandler) Get(context.Context, *v2.TokenServiceGetRequest) (*v2.TokenServiceGetResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.TokenService.Get is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.TokenService.Get is not implemented") } func (UnimplementedTokenServiceHandler) Create(context.Context, *v2.TokenServiceCreateRequest) (*v2.TokenServiceCreateResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.TokenService.Create is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.TokenService.Create is not implemented") } func (UnimplementedTokenServiceHandler) Update(context.Context, *v2.TokenServiceUpdateRequest) (*v2.TokenServiceUpdateResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.TokenService.Update is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.TokenService.Update is not implemented") } func (UnimplementedTokenServiceHandler) List(context.Context, *v2.TokenServiceListRequest) (*v2.TokenServiceListResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.TokenService.List is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.TokenService.List is not implemented") } func (UnimplementedTokenServiceHandler) Revoke(context.Context, *v2.TokenServiceRevokeRequest) (*v2.TokenServiceRevokeResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.TokenService.Revoke is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.TokenService.Revoke is not implemented") } func (UnimplementedTokenServiceHandler) Refresh(context.Context, *v2.TokenServiceRefreshRequest) (*v2.TokenServiceRefreshResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.TokenService.Refresh is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.TokenService.Refresh is not implemented") +} + +type tokenServiceClient struct { + client *connect.Client +} + +func (c *tokenServiceClient) Get(ctx context.Context, req *v2.TokenServiceGetRequest) (*v2.TokenServiceGetResponse, error) { + var res v2.TokenServiceGetResponse + if err := c.client.CallUnary(ctx, tokenServiceGetSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *tokenServiceClient) Create(ctx context.Context, req *v2.TokenServiceCreateRequest) (*v2.TokenServiceCreateResponse, error) { + var res v2.TokenServiceCreateResponse + if err := c.client.CallUnary(ctx, tokenServiceCreateSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *tokenServiceClient) Update(ctx context.Context, req *v2.TokenServiceUpdateRequest) (*v2.TokenServiceUpdateResponse, error) { + var res v2.TokenServiceUpdateResponse + if err := c.client.CallUnary(ctx, tokenServiceUpdateSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *tokenServiceClient) List(ctx context.Context, req *v2.TokenServiceListRequest) (*v2.TokenServiceListResponse, error) { + var res v2.TokenServiceListResponse + if err := c.client.CallUnary(ctx, tokenServiceListSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *tokenServiceClient) Revoke(ctx context.Context, req *v2.TokenServiceRevokeRequest) (*v2.TokenServiceRevokeResponse, error) { + var res v2.TokenServiceRevokeResponse + if err := c.client.CallUnary(ctx, tokenServiceRevokeSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *tokenServiceClient) Refresh(ctx context.Context, req *v2.TokenServiceRefreshRequest) (*v2.TokenServiceRefreshResponse, error) { + var res v2.TokenServiceRefreshResponse + if err := c.client.CallUnary(ctx, tokenServiceRefreshSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +type tokenServiceHandler struct{ svc TokenServiceHandler } + +func (h tokenServiceHandler) get(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.TokenServiceGetRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Get(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) +} + +func (h tokenServiceHandler) create(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.TokenServiceCreateRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Create(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) +} + +func (h tokenServiceHandler) update(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.TokenServiceUpdateRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Update(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) +} + +func (h tokenServiceHandler) list(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.TokenServiceListRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.List(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) +} + +func (h tokenServiceHandler) revoke(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.TokenServiceRevokeRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Revoke(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) +} + +func (h tokenServiceHandler) refresh(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.TokenServiceRefreshRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Refresh(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } diff --git a/go/metalstack/api/v2/apiv2connect/user.connect.go b/go/metalstack/api/v2/apiv2connect/user.connect.go index 4e862fd0..508ff966 100644 --- a/go/metalstack/api/v2/apiv2connect/user.connect.go +++ b/go/metalstack/api/v2/apiv2connect/user.connect.go @@ -5,76 +5,49 @@ package apiv2connect import ( - connect "connectrpc.com/connect" + connect "connectrpc.com/connect/v2" context "context" - errors "errors" v2 "github.com/metal-stack/api/go/metalstack/api/v2" - http "net/http" - strings "strings" + sync "sync" ) -// 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 ( // UserServiceName is the fully-qualified name of the UserService service. UserServiceName = "metalstack.api.v2.UserService" ) -// 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. +// These constants are the procedure 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 ( - // UserServiceGetProcedure is the fully-qualified name of the UserService's Get RPC. + // UserServiceGetProcedure is the procedure name of the UserService's Get RPC. UserServiceGetProcedure = "/metalstack.api.v2.UserService/Get" ) +var ( + userServiceGetSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_user_proto.Services().ByName("UserService").Methods().ByName("Get"), + Procedure: UserServiceGetProcedure, + } + }) +) + // UserServiceClient is a client for the metalstack.api.v2.UserService service. type UserServiceClient interface { // Returns the authenticated user. Get(context.Context, *v2.UserServiceGetRequest) (*v2.UserServiceGetResponse, error) } -// NewUserServiceClient constructs a client for the metalstack.api.v2.UserService 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 NewUserServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) UserServiceClient { - baseURL = strings.TrimRight(baseURL, "/") - userServiceMethods := v2.File_metalstack_api_v2_user_proto.Services().ByName("UserService").Methods() - return &userServiceClient{ - get: connect.NewClient[v2.UserServiceGetRequest, v2.UserServiceGetResponse]( - httpClient, - baseURL+UserServiceGetProcedure, - connect.WithSchema(userServiceMethods.ByName("Get")), - connect.WithClientOptions(opts...), - ), - } -} - -// userServiceClient implements UserServiceClient. -type userServiceClient struct { - get *connect.Client[v2.UserServiceGetRequest, v2.UserServiceGetResponse] -} - -// Get calls metalstack.api.v2.UserService.Get. -func (c *userServiceClient) Get(ctx context.Context, req *v2.UserServiceGetRequest) (*v2.UserServiceGetResponse, error) { - response, err := c.get.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err +// NewUserServiceClient constructs a client for the metalstack.api.v2.UserService service. Multiple +// service clients may share a single connect.Client. +func NewUserServiceClient(client *connect.Client) UserServiceClient { + return &userServiceClient{client: client} } // UserServiceHandler is an implementation of the metalstack.api.v2.UserService service. @@ -83,32 +56,44 @@ type UserServiceHandler interface { Get(context.Context, *v2.UserServiceGetRequest) (*v2.UserServiceGetResponse, error) } -// NewUserServiceHandler 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 NewUserServiceHandler(svc UserServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) { - userServiceMethods := v2.File_metalstack_api_v2_user_proto.Services().ByName("UserService").Methods() - userServiceGetHandler := connect.NewUnaryHandlerSimple( - UserServiceGetProcedure, - svc.Get, - connect.WithSchema(userServiceMethods.ByName("Get")), - connect.WithHandlerOptions(opts...), +// RegisterUserServiceHandler registers svc as the metalstack.api.v2.UserService implementation on +// server. +func RegisterUserServiceHandler(server *connect.Server, svc UserServiceHandler) { + adapter := userServiceHandler{svc: svc} + server.Register( + connect.Method{Spec: userServiceGetSpec(), Handler: adapter.get}, ) - return "/metalstack.api.v2.UserService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - switch r.URL.Path { - case UserServiceGetProcedure: - userServiceGetHandler.ServeHTTP(w, r) - default: - http.NotFound(w, r) - } - }) } // UnimplementedUserServiceHandler returns CodeUnimplemented from all methods. type UnimplementedUserServiceHandler struct{} func (UnimplementedUserServiceHandler) Get(context.Context, *v2.UserServiceGetRequest) (*v2.UserServiceGetResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.UserService.Get is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.UserService.Get is not implemented") +} + +type userServiceClient struct { + client *connect.Client +} + +func (c *userServiceClient) Get(ctx context.Context, req *v2.UserServiceGetRequest) (*v2.UserServiceGetResponse, error) { + var res v2.UserServiceGetResponse + if err := c.client.CallUnary(ctx, userServiceGetSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +type userServiceHandler struct{ svc UserServiceHandler } + +func (h userServiceHandler) get(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.UserServiceGetRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Get(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } diff --git a/go/metalstack/api/v2/apiv2connect/version.connect.go b/go/metalstack/api/v2/apiv2connect/version.connect.go index cf1a81bf..ad47e59d 100644 --- a/go/metalstack/api/v2/apiv2connect/version.connect.go +++ b/go/metalstack/api/v2/apiv2connect/version.connect.go @@ -5,76 +5,49 @@ package apiv2connect import ( - connect "connectrpc.com/connect" + connect "connectrpc.com/connect/v2" context "context" - errors "errors" v2 "github.com/metal-stack/api/go/metalstack/api/v2" - http "net/http" - strings "strings" + sync "sync" ) -// 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 ( // VersionServiceName is the fully-qualified name of the VersionService service. VersionServiceName = "metalstack.api.v2.VersionService" ) -// 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. +// These constants are the procedure 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 ( - // VersionServiceGetProcedure is the fully-qualified name of the VersionService's Get RPC. + // VersionServiceGetProcedure is the procedure name of the VersionService's Get RPC. VersionServiceGetProcedure = "/metalstack.api.v2.VersionService/Get" ) +var ( + versionServiceGetSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_api_v2_version_proto.Services().ByName("VersionService").Methods().ByName("Get"), + Procedure: VersionServiceGetProcedure, + } + }) +) + // VersionServiceClient is a client for the metalstack.api.v2.VersionService service. type VersionServiceClient interface { // Returns the version of the application. Get(context.Context, *v2.VersionServiceGetRequest) (*v2.VersionServiceGetResponse, error) } -// NewVersionServiceClient constructs a client for the metalstack.api.v2.VersionService 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 NewVersionServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) VersionServiceClient { - baseURL = strings.TrimRight(baseURL, "/") - versionServiceMethods := v2.File_metalstack_api_v2_version_proto.Services().ByName("VersionService").Methods() - return &versionServiceClient{ - get: connect.NewClient[v2.VersionServiceGetRequest, v2.VersionServiceGetResponse]( - httpClient, - baseURL+VersionServiceGetProcedure, - connect.WithSchema(versionServiceMethods.ByName("Get")), - connect.WithClientOptions(opts...), - ), - } -} - -// versionServiceClient implements VersionServiceClient. -type versionServiceClient struct { - get *connect.Client[v2.VersionServiceGetRequest, v2.VersionServiceGetResponse] -} - -// Get calls metalstack.api.v2.VersionService.Get. -func (c *versionServiceClient) Get(ctx context.Context, req *v2.VersionServiceGetRequest) (*v2.VersionServiceGetResponse, error) { - response, err := c.get.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err +// NewVersionServiceClient constructs a client for the metalstack.api.v2.VersionService service. +// Multiple service clients may share a single connect.Client. +func NewVersionServiceClient(client *connect.Client) VersionServiceClient { + return &versionServiceClient{client: client} } // VersionServiceHandler is an implementation of the metalstack.api.v2.VersionService service. @@ -83,32 +56,44 @@ type VersionServiceHandler interface { Get(context.Context, *v2.VersionServiceGetRequest) (*v2.VersionServiceGetResponse, error) } -// NewVersionServiceHandler 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 NewVersionServiceHandler(svc VersionServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) { - versionServiceMethods := v2.File_metalstack_api_v2_version_proto.Services().ByName("VersionService").Methods() - versionServiceGetHandler := connect.NewUnaryHandlerSimple( - VersionServiceGetProcedure, - svc.Get, - connect.WithSchema(versionServiceMethods.ByName("Get")), - connect.WithHandlerOptions(opts...), +// RegisterVersionServiceHandler registers svc as the metalstack.api.v2.VersionService +// implementation on server. +func RegisterVersionServiceHandler(server *connect.Server, svc VersionServiceHandler) { + adapter := versionServiceHandler{svc: svc} + server.Register( + connect.Method{Spec: versionServiceGetSpec(), Handler: adapter.get}, ) - return "/metalstack.api.v2.VersionService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - switch r.URL.Path { - case VersionServiceGetProcedure: - versionServiceGetHandler.ServeHTTP(w, r) - default: - http.NotFound(w, r) - } - }) } // UnimplementedVersionServiceHandler returns CodeUnimplemented from all methods. type UnimplementedVersionServiceHandler struct{} func (UnimplementedVersionServiceHandler) Get(context.Context, *v2.VersionServiceGetRequest) (*v2.VersionServiceGetResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.api.v2.VersionService.Get is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.api.v2.VersionService.Get is not implemented") +} + +type versionServiceClient struct { + client *connect.Client +} + +func (c *versionServiceClient) Get(ctx context.Context, req *v2.VersionServiceGetRequest) (*v2.VersionServiceGetResponse, error) { + var res v2.VersionServiceGetResponse + if err := c.client.CallUnary(ctx, versionServiceGetSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +type versionServiceHandler struct{ svc VersionServiceHandler } + +func (h versionServiceHandler) get(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.VersionServiceGetRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Get(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } diff --git a/go/metalstack/infra/v2/infrav2connect/bmc.connect.go b/go/metalstack/infra/v2/infrav2connect/bmc.connect.go index 9200e995..12ca45da 100644 --- a/go/metalstack/infra/v2/infrav2connect/bmc.connect.go +++ b/go/metalstack/infra/v2/infrav2connect/bmc.connect.go @@ -5,115 +5,93 @@ package infrav2connect import ( - connect "connectrpc.com/connect" + connect "connectrpc.com/connect/v2" context "context" - errors "errors" v2 "github.com/metal-stack/api/go/metalstack/infra/v2" - http "net/http" - strings "strings" + sync "sync" ) -// 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 ( // BMCServiceName is the fully-qualified name of the BMCService service. BMCServiceName = "metalstack.infra.v2.BMCService" ) -// 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. +// These constants are the procedure 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 ( - // BMCServiceUpdateBMCInfoProcedure is the fully-qualified name of the BMCService's UpdateBMCInfo - // RPC. + // BMCServiceUpdateBMCInfoProcedure is the procedure name of the BMCService's UpdateBMCInfo RPC. BMCServiceUpdateBMCInfoProcedure = "/metalstack.infra.v2.BMCService/UpdateBMCInfo" - // BMCServiceWaitForBMCCommandProcedure is the fully-qualified name of the BMCService's - // WaitForBMCCommand RPC. - BMCServiceWaitForBMCCommandProcedure = "/metalstack.infra.v2.BMCService/WaitForBMCCommand" - // BMCServiceBMCCommandDoneProcedure is the fully-qualified name of the BMCService's BMCCommandDone + // BMCServiceWaitForBMCCommandProcedure is the procedure name of the BMCService's WaitForBMCCommand // RPC. + BMCServiceWaitForBMCCommandProcedure = "/metalstack.infra.v2.BMCService/WaitForBMCCommand" + // BMCServiceBMCCommandDoneProcedure is the procedure name of the BMCService's BMCCommandDone RPC. BMCServiceBMCCommandDoneProcedure = "/metalstack.infra.v2.BMCService/BMCCommandDone" ) +var ( + bMCServiceUpdateBMCInfoSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_infra_v2_bmc_proto.Services().ByName("BMCService").Methods().ByName("UpdateBMCInfo"), + Procedure: BMCServiceUpdateBMCInfoProcedure, + } + }) + bMCServiceWaitForBMCCommandSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeServer, + Schema: v2.File_metalstack_infra_v2_bmc_proto.Services().ByName("BMCService").Methods().ByName("WaitForBMCCommand"), + Procedure: BMCServiceWaitForBMCCommandProcedure, + } + }) + bMCServiceBMCCommandDoneSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_infra_v2_bmc_proto.Services().ByName("BMCService").Methods().ByName("BMCCommandDone"), + Procedure: BMCServiceBMCCommandDoneProcedure, + } + }) +) + // BMCServiceClient is a client for the metalstack.infra.v2.BMCService service. type BMCServiceClient interface { // Updates BMC information. UpdateBMCInfo(context.Context, *v2.UpdateBMCInfoRequest) (*v2.UpdateBMCInfoResponse, error) // WaitForBMCCommand is called by the metal-bmc and returns a BMC command to execute. - WaitForBMCCommand(context.Context, *v2.WaitForBMCCommandRequest) (*connect.ServerStreamForClient[v2.WaitForBMCCommandResponse], error) + WaitForBMCCommand(context.Context, *v2.WaitForBMCCommandRequest) (BMCServiceWaitForBMCCommandClientStream, error) // BMCCommandDone must be called from metal-bmc after the command execution. BMCCommandDone(context.Context, *v2.BMCCommandDoneRequest) (*v2.BMCCommandDoneResponse, error) } -// NewBMCServiceClient constructs a client for the metalstack.infra.v2.BMCService 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 NewBMCServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) BMCServiceClient { - baseURL = strings.TrimRight(baseURL, "/") - bMCServiceMethods := v2.File_metalstack_infra_v2_bmc_proto.Services().ByName("BMCService").Methods() - return &bMCServiceClient{ - updateBMCInfo: connect.NewClient[v2.UpdateBMCInfoRequest, v2.UpdateBMCInfoResponse]( - httpClient, - baseURL+BMCServiceUpdateBMCInfoProcedure, - connect.WithSchema(bMCServiceMethods.ByName("UpdateBMCInfo")), - connect.WithClientOptions(opts...), - ), - waitForBMCCommand: connect.NewClient[v2.WaitForBMCCommandRequest, v2.WaitForBMCCommandResponse]( - httpClient, - baseURL+BMCServiceWaitForBMCCommandProcedure, - connect.WithSchema(bMCServiceMethods.ByName("WaitForBMCCommand")), - connect.WithClientOptions(opts...), - ), - bMCCommandDone: connect.NewClient[v2.BMCCommandDoneRequest, v2.BMCCommandDoneResponse]( - httpClient, - baseURL+BMCServiceBMCCommandDoneProcedure, - connect.WithSchema(bMCServiceMethods.ByName("BMCCommandDone")), - connect.WithClientOptions(opts...), - ), - } +// NewBMCServiceClient constructs a client for the metalstack.infra.v2.BMCService service. Multiple +// service clients may share a single connect.Client. +func NewBMCServiceClient(client *connect.Client) BMCServiceClient { + return &bMCServiceClient{client: client} } -// bMCServiceClient implements BMCServiceClient. -type bMCServiceClient struct { - updateBMCInfo *connect.Client[v2.UpdateBMCInfoRequest, v2.UpdateBMCInfoResponse] - waitForBMCCommand *connect.Client[v2.WaitForBMCCommandRequest, v2.WaitForBMCCommandResponse] - bMCCommandDone *connect.Client[v2.BMCCommandDoneRequest, v2.BMCCommandDoneResponse] +// BMCServiceWaitForBMCCommandClientStream is the client stream for the BMCService's +// WaitForBMCCommand RPC. +type BMCServiceWaitForBMCCommandClientStream struct { + stream connect.ClientStream } -// UpdateBMCInfo calls metalstack.infra.v2.BMCService.UpdateBMCInfo. -func (c *bMCServiceClient) UpdateBMCInfo(ctx context.Context, req *v2.UpdateBMCInfoRequest) (*v2.UpdateBMCInfoResponse, error) { - response, err := c.updateBMCInfo.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err +// Receive returns the next response message from the server. +func (s BMCServiceWaitForBMCCommandClientStream) Receive() (*v2.WaitForBMCCommandResponse, error) { + var res v2.WaitForBMCCommandResponse + if err := s.stream.Receive(&res); err != nil { + return nil, err } - return nil, err + return &res, nil } -// WaitForBMCCommand calls metalstack.infra.v2.BMCService.WaitForBMCCommand. -func (c *bMCServiceClient) WaitForBMCCommand(ctx context.Context, req *v2.WaitForBMCCommandRequest) (*connect.ServerStreamForClient[v2.WaitForBMCCommandResponse], error) { - return c.waitForBMCCommand.CallServerStream(ctx, connect.NewRequest(req)) -} - -// BMCCommandDone calls metalstack.infra.v2.BMCService.BMCCommandDone. -func (c *bMCServiceClient) BMCCommandDone(ctx context.Context, req *v2.BMCCommandDoneRequest) (*v2.BMCCommandDoneResponse, error) { - response, err := c.bMCCommandDone.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err +// Close releases the stream's resources. It is idempotent and is typically deferred to clean up a +// stream abandoned before io.EOF. +func (s BMCServiceWaitForBMCCommandClientStream) Close() error { + return s.stream.Close() } // BMCServiceHandler is an implementation of the metalstack.infra.v2.BMCService service. @@ -121,61 +99,111 @@ type BMCServiceHandler interface { // Updates BMC information. UpdateBMCInfo(context.Context, *v2.UpdateBMCInfoRequest) (*v2.UpdateBMCInfoResponse, error) // WaitForBMCCommand is called by the metal-bmc and returns a BMC command to execute. - WaitForBMCCommand(context.Context, *v2.WaitForBMCCommandRequest, *connect.ServerStream[v2.WaitForBMCCommandResponse]) error + WaitForBMCCommand(context.Context, *v2.WaitForBMCCommandRequest, BMCServiceWaitForBMCCommandServerStream) error // BMCCommandDone must be called from metal-bmc after the command execution. BMCCommandDone(context.Context, *v2.BMCCommandDoneRequest) (*v2.BMCCommandDoneResponse, error) } -// NewBMCServiceHandler 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 NewBMCServiceHandler(svc BMCServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) { - bMCServiceMethods := v2.File_metalstack_infra_v2_bmc_proto.Services().ByName("BMCService").Methods() - bMCServiceUpdateBMCInfoHandler := connect.NewUnaryHandlerSimple( - BMCServiceUpdateBMCInfoProcedure, - svc.UpdateBMCInfo, - connect.WithSchema(bMCServiceMethods.ByName("UpdateBMCInfo")), - connect.WithHandlerOptions(opts...), - ) - bMCServiceWaitForBMCCommandHandler := connect.NewServerStreamHandlerSimple( - BMCServiceWaitForBMCCommandProcedure, - svc.WaitForBMCCommand, - connect.WithSchema(bMCServiceMethods.ByName("WaitForBMCCommand")), - connect.WithHandlerOptions(opts...), +// RegisterBMCServiceHandler registers svc as the metalstack.infra.v2.BMCService implementation on +// server. +func RegisterBMCServiceHandler(server *connect.Server, svc BMCServiceHandler) { + adapter := bMCServiceHandler{svc: svc} + server.Register( + connect.Method{Spec: bMCServiceUpdateBMCInfoSpec(), Handler: adapter.updateBMCInfo}, + connect.Method{Spec: bMCServiceWaitForBMCCommandSpec(), Handler: adapter.waitForBMCCommand}, + connect.Method{Spec: bMCServiceBMCCommandDoneSpec(), Handler: adapter.bMCCommandDone}, ) - bMCServiceBMCCommandDoneHandler := connect.NewUnaryHandlerSimple( - BMCServiceBMCCommandDoneProcedure, - svc.BMCCommandDone, - connect.WithSchema(bMCServiceMethods.ByName("BMCCommandDone")), - connect.WithHandlerOptions(opts...), - ) - return "/metalstack.infra.v2.BMCService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - switch r.URL.Path { - case BMCServiceUpdateBMCInfoProcedure: - bMCServiceUpdateBMCInfoHandler.ServeHTTP(w, r) - case BMCServiceWaitForBMCCommandProcedure: - bMCServiceWaitForBMCCommandHandler.ServeHTTP(w, r) - case BMCServiceBMCCommandDoneProcedure: - bMCServiceBMCCommandDoneHandler.ServeHTTP(w, r) - default: - http.NotFound(w, r) - } - }) +} + +// BMCServiceWaitForBMCCommandServerStream is the server stream for the BMCService's +// WaitForBMCCommand RPC. +type BMCServiceWaitForBMCCommandServerStream struct { + stream connect.ServerStream +} + +// SendHeaders flushes the response headers without a message. The first Send does this implicitly. +func (s BMCServiceWaitForBMCCommandServerStream) SendHeaders() error { + return s.stream.SendHeaders() +} + +// Send sends a response message to the client. +func (s BMCServiceWaitForBMCCommandServerStream) Send(res *v2.WaitForBMCCommandResponse) error { + return s.stream.Send(res) } // UnimplementedBMCServiceHandler returns CodeUnimplemented from all methods. type UnimplementedBMCServiceHandler struct{} func (UnimplementedBMCServiceHandler) UpdateBMCInfo(context.Context, *v2.UpdateBMCInfoRequest) (*v2.UpdateBMCInfoResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.infra.v2.BMCService.UpdateBMCInfo is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.infra.v2.BMCService.UpdateBMCInfo is not implemented") } -func (UnimplementedBMCServiceHandler) WaitForBMCCommand(context.Context, *v2.WaitForBMCCommandRequest, *connect.ServerStream[v2.WaitForBMCCommandResponse]) error { - return connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.infra.v2.BMCService.WaitForBMCCommand is not implemented")) +func (UnimplementedBMCServiceHandler) WaitForBMCCommand(context.Context, *v2.WaitForBMCCommandRequest, BMCServiceWaitForBMCCommandServerStream) error { + return connect.NewError(connect.CodeUnimplemented, "metalstack.infra.v2.BMCService.WaitForBMCCommand is not implemented") } func (UnimplementedBMCServiceHandler) BMCCommandDone(context.Context, *v2.BMCCommandDoneRequest) (*v2.BMCCommandDoneResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.infra.v2.BMCService.BMCCommandDone is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.infra.v2.BMCService.BMCCommandDone is not implemented") +} + +type bMCServiceClient struct { + client *connect.Client +} + +func (c *bMCServiceClient) UpdateBMCInfo(ctx context.Context, req *v2.UpdateBMCInfoRequest) (*v2.UpdateBMCInfoResponse, error) { + var res v2.UpdateBMCInfoResponse + if err := c.client.CallUnary(ctx, bMCServiceUpdateBMCInfoSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *bMCServiceClient) WaitForBMCCommand(ctx context.Context, req *v2.WaitForBMCCommandRequest) (BMCServiceWaitForBMCCommandClientStream, error) { + stream, err := c.client.CallServerStream(ctx, bMCServiceWaitForBMCCommandSpec(), req) + if err != nil { + return BMCServiceWaitForBMCCommandClientStream{}, err + } + return BMCServiceWaitForBMCCommandClientStream{stream: stream}, nil +} + +func (c *bMCServiceClient) BMCCommandDone(ctx context.Context, req *v2.BMCCommandDoneRequest) (*v2.BMCCommandDoneResponse, error) { + var res v2.BMCCommandDoneResponse + if err := c.client.CallUnary(ctx, bMCServiceBMCCommandDoneSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +type bMCServiceHandler struct{ svc BMCServiceHandler } + +func (h bMCServiceHandler) updateBMCInfo(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.UpdateBMCInfoRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.UpdateBMCInfo(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) +} + +func (h bMCServiceHandler) waitForBMCCommand(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.WaitForBMCCommandRequest + if err := stream.Receive(&req); err != nil { + return err + } + return h.svc.WaitForBMCCommand(ctx, &req, BMCServiceWaitForBMCCommandServerStream{stream: stream}) +} + +func (h bMCServiceHandler) bMCCommandDone(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.BMCCommandDoneRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.BMCCommandDone(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } diff --git a/go/metalstack/infra/v2/infrav2connect/boot.connect.go b/go/metalstack/infra/v2/infrav2connect/boot.connect.go index ea23d3af..43f07d58 100644 --- a/go/metalstack/infra/v2/infrav2connect/boot.connect.go +++ b/go/metalstack/infra/v2/infrav2connect/boot.connect.go @@ -5,55 +5,104 @@ package infrav2connect import ( - connect "connectrpc.com/connect" + connect "connectrpc.com/connect/v2" context "context" - errors "errors" v2 "github.com/metal-stack/api/go/metalstack/infra/v2" - http "net/http" - strings "strings" + sync "sync" ) -// 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 ( // BootServiceName is the fully-qualified name of the BootService service. BootServiceName = "metalstack.infra.v2.BootService" ) -// 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. +// These constants are the procedure 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 ( - // BootServiceDhcpProcedure is the fully-qualified name of the BootService's Dhcp RPC. + // BootServiceDhcpProcedure is the procedure name of the BootService's Dhcp RPC. BootServiceDhcpProcedure = "/metalstack.infra.v2.BootService/Dhcp" - // BootServiceBootProcedure is the fully-qualified name of the BootService's Boot RPC. + // BootServiceBootProcedure is the procedure name of the BootService's Boot RPC. BootServiceBootProcedure = "/metalstack.infra.v2.BootService/Boot" - // BootServiceMachineTokenProcedure is the fully-qualified name of the BootService's MachineToken - // RPC. + // BootServiceMachineTokenProcedure is the procedure name of the BootService's MachineToken RPC. BootServiceMachineTokenProcedure = "/metalstack.infra.v2.BootService/MachineToken" - // BootServiceSuperUserPasswordProcedure is the fully-qualified name of the BootService's + // BootServiceSuperUserPasswordProcedure is the procedure name of the BootService's // SuperUserPassword RPC. BootServiceSuperUserPasswordProcedure = "/metalstack.infra.v2.BootService/SuperUserPassword" - // BootServiceRegisterProcedure is the fully-qualified name of the BootService's Register RPC. + // BootServiceRegisterProcedure is the procedure name of the BootService's Register RPC. BootServiceRegisterProcedure = "/metalstack.infra.v2.BootService/Register" - // BootServiceWaitProcedure is the fully-qualified name of the BootService's Wait RPC. + // BootServiceWaitProcedure is the procedure name of the BootService's Wait RPC. BootServiceWaitProcedure = "/metalstack.infra.v2.BootService/Wait" - // BootServiceInstallationSucceededProcedure is the fully-qualified name of the BootService's + // BootServiceInstallationSucceededProcedure is the procedure name of the BootService's // InstallationSucceeded RPC. BootServiceInstallationSucceededProcedure = "/metalstack.infra.v2.BootService/InstallationSucceeded" - // BootServiceSendEventProcedure is the fully-qualified name of the BootService's SendEvent RPC. + // BootServiceSendEventProcedure is the procedure name of the BootService's SendEvent RPC. BootServiceSendEventProcedure = "/metalstack.infra.v2.BootService/SendEvent" ) +var ( + bootServiceDhcpSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_infra_v2_boot_proto.Services().ByName("BootService").Methods().ByName("Dhcp"), + Procedure: BootServiceDhcpProcedure, + } + }) + bootServiceBootSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_infra_v2_boot_proto.Services().ByName("BootService").Methods().ByName("Boot"), + Procedure: BootServiceBootProcedure, + } + }) + bootServiceMachineTokenSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_infra_v2_boot_proto.Services().ByName("BootService").Methods().ByName("MachineToken"), + Procedure: BootServiceMachineTokenProcedure, + } + }) + bootServiceSuperUserPasswordSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_infra_v2_boot_proto.Services().ByName("BootService").Methods().ByName("SuperUserPassword"), + Procedure: BootServiceSuperUserPasswordProcedure, + } + }) + bootServiceRegisterSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_infra_v2_boot_proto.Services().ByName("BootService").Methods().ByName("Register"), + Procedure: BootServiceRegisterProcedure, + } + }) + bootServiceWaitSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeServer, + Schema: v2.File_metalstack_infra_v2_boot_proto.Services().ByName("BootService").Methods().ByName("Wait"), + Procedure: BootServiceWaitProcedure, + } + }) + bootServiceInstallationSucceededSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_infra_v2_boot_proto.Services().ByName("BootService").Methods().ByName("InstallationSucceeded"), + Procedure: BootServiceInstallationSucceededProcedure, + } + }) + bootServiceSendEventSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_infra_v2_boot_proto.Services().ByName("BootService").Methods().ByName("SendEvent"), + Procedure: BootServiceSendEventProcedure, + } + }) +) + // BootServiceClient is a client for the metalstack.infra.v2.BootService service. type BootServiceClient interface { // Dhcp handles the first DHCP request (option 97). A ProvisioningEventPXEBooting is fired. @@ -67,153 +116,37 @@ type BootServiceClient interface { // Register is called from metal-hammer after hardware inventory is finished, tells metal-apiserver all details about that machine. Register(context.Context, *v2.BootServiceRegisterRequest) (*v2.BootServiceRegisterResponse, error) // Wait is a hanging call that waits until the machine gets allocated by a user. - Wait(context.Context, *v2.BootServiceWaitRequest) (*connect.ServerStreamForClient[v2.BootServiceWaitResponse], error) + Wait(context.Context, *v2.BootServiceWaitRequest) (BootServiceWaitClientStream, error) // InstallationSucceeded tells metal-apiserver that installation was successful. InstallationSucceeded(context.Context, *v2.BootServiceInstallationSucceededRequest) (*v2.BootServiceInstallationSucceededResponse, error) // SendEvent is used to send provisioning events to the metal-apiserver. SendEvent(context.Context, *v2.BootServiceSendEventRequest) (*v2.BootServiceSendEventResponse, error) } -// NewBootServiceClient constructs a client for the metalstack.infra.v2.BootService 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 NewBootServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) BootServiceClient { - baseURL = strings.TrimRight(baseURL, "/") - bootServiceMethods := v2.File_metalstack_infra_v2_boot_proto.Services().ByName("BootService").Methods() - return &bootServiceClient{ - dhcp: connect.NewClient[v2.BootServiceDhcpRequest, v2.BootServiceDhcpResponse]( - httpClient, - baseURL+BootServiceDhcpProcedure, - connect.WithSchema(bootServiceMethods.ByName("Dhcp")), - connect.WithClientOptions(opts...), - ), - boot: connect.NewClient[v2.BootServiceBootRequest, v2.BootServiceBootResponse]( - httpClient, - baseURL+BootServiceBootProcedure, - connect.WithSchema(bootServiceMethods.ByName("Boot")), - connect.WithClientOptions(opts...), - ), - machineToken: connect.NewClient[v2.BootServiceMachineTokenRequest, v2.BootServiceMachineTokenResponse]( - httpClient, - baseURL+BootServiceMachineTokenProcedure, - connect.WithSchema(bootServiceMethods.ByName("MachineToken")), - connect.WithClientOptions(opts...), - ), - superUserPassword: connect.NewClient[v2.BootServiceSuperUserPasswordRequest, v2.BootServiceSuperUserPasswordResponse]( - httpClient, - baseURL+BootServiceSuperUserPasswordProcedure, - connect.WithSchema(bootServiceMethods.ByName("SuperUserPassword")), - connect.WithClientOptions(opts...), - ), - register: connect.NewClient[v2.BootServiceRegisterRequest, v2.BootServiceRegisterResponse]( - httpClient, - baseURL+BootServiceRegisterProcedure, - connect.WithSchema(bootServiceMethods.ByName("Register")), - connect.WithClientOptions(opts...), - ), - wait: connect.NewClient[v2.BootServiceWaitRequest, v2.BootServiceWaitResponse]( - httpClient, - baseURL+BootServiceWaitProcedure, - connect.WithSchema(bootServiceMethods.ByName("Wait")), - connect.WithClientOptions(opts...), - ), - installationSucceeded: connect.NewClient[v2.BootServiceInstallationSucceededRequest, v2.BootServiceInstallationSucceededResponse]( - httpClient, - baseURL+BootServiceInstallationSucceededProcedure, - connect.WithSchema(bootServiceMethods.ByName("InstallationSucceeded")), - connect.WithClientOptions(opts...), - ), - sendEvent: connect.NewClient[v2.BootServiceSendEventRequest, v2.BootServiceSendEventResponse]( - httpClient, - baseURL+BootServiceSendEventProcedure, - connect.WithSchema(bootServiceMethods.ByName("SendEvent")), - connect.WithClientOptions(opts...), - ), - } -} - -// bootServiceClient implements BootServiceClient. -type bootServiceClient struct { - dhcp *connect.Client[v2.BootServiceDhcpRequest, v2.BootServiceDhcpResponse] - boot *connect.Client[v2.BootServiceBootRequest, v2.BootServiceBootResponse] - machineToken *connect.Client[v2.BootServiceMachineTokenRequest, v2.BootServiceMachineTokenResponse] - superUserPassword *connect.Client[v2.BootServiceSuperUserPasswordRequest, v2.BootServiceSuperUserPasswordResponse] - register *connect.Client[v2.BootServiceRegisterRequest, v2.BootServiceRegisterResponse] - wait *connect.Client[v2.BootServiceWaitRequest, v2.BootServiceWaitResponse] - installationSucceeded *connect.Client[v2.BootServiceInstallationSucceededRequest, v2.BootServiceInstallationSucceededResponse] - sendEvent *connect.Client[v2.BootServiceSendEventRequest, v2.BootServiceSendEventResponse] -} - -// Dhcp calls metalstack.infra.v2.BootService.Dhcp. -func (c *bootServiceClient) Dhcp(ctx context.Context, req *v2.BootServiceDhcpRequest) (*v2.BootServiceDhcpResponse, error) { - response, err := c.dhcp.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err +// NewBootServiceClient constructs a client for the metalstack.infra.v2.BootService service. +// Multiple service clients may share a single connect.Client. +func NewBootServiceClient(client *connect.Client) BootServiceClient { + return &bootServiceClient{client: client} } -// Boot calls metalstack.infra.v2.BootService.Boot. -func (c *bootServiceClient) Boot(ctx context.Context, req *v2.BootServiceBootRequest) (*v2.BootServiceBootResponse, error) { - response, err := c.boot.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err +// BootServiceWaitClientStream is the client stream for the BootService's Wait RPC. +type BootServiceWaitClientStream struct { + stream connect.ClientStream } -// MachineToken calls metalstack.infra.v2.BootService.MachineToken. -func (c *bootServiceClient) MachineToken(ctx context.Context, req *v2.BootServiceMachineTokenRequest) (*v2.BootServiceMachineTokenResponse, error) { - response, err := c.machineToken.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err +// Receive returns the next response message from the server. +func (s BootServiceWaitClientStream) Receive() (*v2.BootServiceWaitResponse, error) { + var res v2.BootServiceWaitResponse + if err := s.stream.Receive(&res); err != nil { + return nil, err } - return nil, err + return &res, nil } -// SuperUserPassword calls metalstack.infra.v2.BootService.SuperUserPassword. -func (c *bootServiceClient) SuperUserPassword(ctx context.Context, req *v2.BootServiceSuperUserPasswordRequest) (*v2.BootServiceSuperUserPasswordResponse, error) { - response, err := c.superUserPassword.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err -} - -// Register calls metalstack.infra.v2.BootService.Register. -func (c *bootServiceClient) Register(ctx context.Context, req *v2.BootServiceRegisterRequest) (*v2.BootServiceRegisterResponse, error) { - response, err := c.register.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err -} - -// Wait calls metalstack.infra.v2.BootService.Wait. -func (c *bootServiceClient) Wait(ctx context.Context, req *v2.BootServiceWaitRequest) (*connect.ServerStreamForClient[v2.BootServiceWaitResponse], error) { - return c.wait.CallServerStream(ctx, connect.NewRequest(req)) -} - -// InstallationSucceeded calls metalstack.infra.v2.BootService.InstallationSucceeded. -func (c *bootServiceClient) InstallationSucceeded(ctx context.Context, req *v2.BootServiceInstallationSucceededRequest) (*v2.BootServiceInstallationSucceededResponse, error) { - response, err := c.installationSucceeded.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err -} - -// SendEvent calls metalstack.infra.v2.BootService.SendEvent. -func (c *bootServiceClient) SendEvent(ctx context.Context, req *v2.BootServiceSendEventRequest) (*v2.BootServiceSendEventResponse, error) { - response, err := c.sendEvent.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err +// Close releases the stream's resources. It is idempotent and is typically deferred to clean up a +// stream abandoned before io.EOF. +func (s BootServiceWaitClientStream) Close() error { + return s.stream.Close() } // BootServiceHandler is an implementation of the metalstack.infra.v2.BootService service. @@ -229,123 +162,237 @@ type BootServiceHandler interface { // Register is called from metal-hammer after hardware inventory is finished, tells metal-apiserver all details about that machine. Register(context.Context, *v2.BootServiceRegisterRequest) (*v2.BootServiceRegisterResponse, error) // Wait is a hanging call that waits until the machine gets allocated by a user. - Wait(context.Context, *v2.BootServiceWaitRequest, *connect.ServerStream[v2.BootServiceWaitResponse]) error + Wait(context.Context, *v2.BootServiceWaitRequest, BootServiceWaitServerStream) error // InstallationSucceeded tells metal-apiserver that installation was successful. InstallationSucceeded(context.Context, *v2.BootServiceInstallationSucceededRequest) (*v2.BootServiceInstallationSucceededResponse, error) // SendEvent is used to send provisioning events to the metal-apiserver. SendEvent(context.Context, *v2.BootServiceSendEventRequest) (*v2.BootServiceSendEventResponse, error) } -// NewBootServiceHandler 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 NewBootServiceHandler(svc BootServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) { - bootServiceMethods := v2.File_metalstack_infra_v2_boot_proto.Services().ByName("BootService").Methods() - bootServiceDhcpHandler := connect.NewUnaryHandlerSimple( - BootServiceDhcpProcedure, - svc.Dhcp, - connect.WithSchema(bootServiceMethods.ByName("Dhcp")), - connect.WithHandlerOptions(opts...), - ) - bootServiceBootHandler := connect.NewUnaryHandlerSimple( - BootServiceBootProcedure, - svc.Boot, - connect.WithSchema(bootServiceMethods.ByName("Boot")), - connect.WithHandlerOptions(opts...), +// RegisterBootServiceHandler registers svc as the metalstack.infra.v2.BootService implementation on +// server. +func RegisterBootServiceHandler(server *connect.Server, svc BootServiceHandler) { + adapter := bootServiceHandler{svc: svc} + server.Register( + connect.Method{Spec: bootServiceDhcpSpec(), Handler: adapter.dhcp}, + connect.Method{Spec: bootServiceBootSpec(), Handler: adapter.boot}, + connect.Method{Spec: bootServiceMachineTokenSpec(), Handler: adapter.machineToken}, + connect.Method{Spec: bootServiceSuperUserPasswordSpec(), Handler: adapter.superUserPassword}, + connect.Method{Spec: bootServiceRegisterSpec(), Handler: adapter.register}, + connect.Method{Spec: bootServiceWaitSpec(), Handler: adapter.wait}, + connect.Method{Spec: bootServiceInstallationSucceededSpec(), Handler: adapter.installationSucceeded}, + connect.Method{Spec: bootServiceSendEventSpec(), Handler: adapter.sendEvent}, ) - bootServiceMachineTokenHandler := connect.NewUnaryHandlerSimple( - BootServiceMachineTokenProcedure, - svc.MachineToken, - connect.WithSchema(bootServiceMethods.ByName("MachineToken")), - connect.WithHandlerOptions(opts...), - ) - bootServiceSuperUserPasswordHandler := connect.NewUnaryHandlerSimple( - BootServiceSuperUserPasswordProcedure, - svc.SuperUserPassword, - connect.WithSchema(bootServiceMethods.ByName("SuperUserPassword")), - connect.WithHandlerOptions(opts...), - ) - bootServiceRegisterHandler := connect.NewUnaryHandlerSimple( - BootServiceRegisterProcedure, - svc.Register, - connect.WithSchema(bootServiceMethods.ByName("Register")), - connect.WithHandlerOptions(opts...), - ) - bootServiceWaitHandler := connect.NewServerStreamHandlerSimple( - BootServiceWaitProcedure, - svc.Wait, - connect.WithSchema(bootServiceMethods.ByName("Wait")), - connect.WithHandlerOptions(opts...), - ) - bootServiceInstallationSucceededHandler := connect.NewUnaryHandlerSimple( - BootServiceInstallationSucceededProcedure, - svc.InstallationSucceeded, - connect.WithSchema(bootServiceMethods.ByName("InstallationSucceeded")), - connect.WithHandlerOptions(opts...), - ) - bootServiceSendEventHandler := connect.NewUnaryHandlerSimple( - BootServiceSendEventProcedure, - svc.SendEvent, - connect.WithSchema(bootServiceMethods.ByName("SendEvent")), - connect.WithHandlerOptions(opts...), - ) - return "/metalstack.infra.v2.BootService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - switch r.URL.Path { - case BootServiceDhcpProcedure: - bootServiceDhcpHandler.ServeHTTP(w, r) - case BootServiceBootProcedure: - bootServiceBootHandler.ServeHTTP(w, r) - case BootServiceMachineTokenProcedure: - bootServiceMachineTokenHandler.ServeHTTP(w, r) - case BootServiceSuperUserPasswordProcedure: - bootServiceSuperUserPasswordHandler.ServeHTTP(w, r) - case BootServiceRegisterProcedure: - bootServiceRegisterHandler.ServeHTTP(w, r) - case BootServiceWaitProcedure: - bootServiceWaitHandler.ServeHTTP(w, r) - case BootServiceInstallationSucceededProcedure: - bootServiceInstallationSucceededHandler.ServeHTTP(w, r) - case BootServiceSendEventProcedure: - bootServiceSendEventHandler.ServeHTTP(w, r) - default: - http.NotFound(w, r) - } - }) +} + +// BootServiceWaitServerStream is the server stream for the BootService's Wait RPC. +type BootServiceWaitServerStream struct { + stream connect.ServerStream +} + +// SendHeaders flushes the response headers without a message. The first Send does this implicitly. +func (s BootServiceWaitServerStream) SendHeaders() error { + return s.stream.SendHeaders() +} + +// Send sends a response message to the client. +func (s BootServiceWaitServerStream) Send(res *v2.BootServiceWaitResponse) error { + return s.stream.Send(res) } // UnimplementedBootServiceHandler returns CodeUnimplemented from all methods. type UnimplementedBootServiceHandler struct{} func (UnimplementedBootServiceHandler) Dhcp(context.Context, *v2.BootServiceDhcpRequest) (*v2.BootServiceDhcpResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.infra.v2.BootService.Dhcp is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.infra.v2.BootService.Dhcp is not implemented") } func (UnimplementedBootServiceHandler) Boot(context.Context, *v2.BootServiceBootRequest) (*v2.BootServiceBootResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.infra.v2.BootService.Boot is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.infra.v2.BootService.Boot is not implemented") } func (UnimplementedBootServiceHandler) MachineToken(context.Context, *v2.BootServiceMachineTokenRequest) (*v2.BootServiceMachineTokenResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.infra.v2.BootService.MachineToken is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.infra.v2.BootService.MachineToken is not implemented") } func (UnimplementedBootServiceHandler) SuperUserPassword(context.Context, *v2.BootServiceSuperUserPasswordRequest) (*v2.BootServiceSuperUserPasswordResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.infra.v2.BootService.SuperUserPassword is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.infra.v2.BootService.SuperUserPassword is not implemented") } func (UnimplementedBootServiceHandler) Register(context.Context, *v2.BootServiceRegisterRequest) (*v2.BootServiceRegisterResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.infra.v2.BootService.Register is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.infra.v2.BootService.Register is not implemented") } -func (UnimplementedBootServiceHandler) Wait(context.Context, *v2.BootServiceWaitRequest, *connect.ServerStream[v2.BootServiceWaitResponse]) error { - return connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.infra.v2.BootService.Wait is not implemented")) +func (UnimplementedBootServiceHandler) Wait(context.Context, *v2.BootServiceWaitRequest, BootServiceWaitServerStream) error { + return connect.NewError(connect.CodeUnimplemented, "metalstack.infra.v2.BootService.Wait is not implemented") } func (UnimplementedBootServiceHandler) InstallationSucceeded(context.Context, *v2.BootServiceInstallationSucceededRequest) (*v2.BootServiceInstallationSucceededResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.infra.v2.BootService.InstallationSucceeded is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.infra.v2.BootService.InstallationSucceeded is not implemented") } func (UnimplementedBootServiceHandler) SendEvent(context.Context, *v2.BootServiceSendEventRequest) (*v2.BootServiceSendEventResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.infra.v2.BootService.SendEvent is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.infra.v2.BootService.SendEvent is not implemented") +} + +type bootServiceClient struct { + client *connect.Client +} + +func (c *bootServiceClient) Dhcp(ctx context.Context, req *v2.BootServiceDhcpRequest) (*v2.BootServiceDhcpResponse, error) { + var res v2.BootServiceDhcpResponse + if err := c.client.CallUnary(ctx, bootServiceDhcpSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *bootServiceClient) Boot(ctx context.Context, req *v2.BootServiceBootRequest) (*v2.BootServiceBootResponse, error) { + var res v2.BootServiceBootResponse + if err := c.client.CallUnary(ctx, bootServiceBootSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *bootServiceClient) MachineToken(ctx context.Context, req *v2.BootServiceMachineTokenRequest) (*v2.BootServiceMachineTokenResponse, error) { + var res v2.BootServiceMachineTokenResponse + if err := c.client.CallUnary(ctx, bootServiceMachineTokenSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *bootServiceClient) SuperUserPassword(ctx context.Context, req *v2.BootServiceSuperUserPasswordRequest) (*v2.BootServiceSuperUserPasswordResponse, error) { + var res v2.BootServiceSuperUserPasswordResponse + if err := c.client.CallUnary(ctx, bootServiceSuperUserPasswordSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *bootServiceClient) Register(ctx context.Context, req *v2.BootServiceRegisterRequest) (*v2.BootServiceRegisterResponse, error) { + var res v2.BootServiceRegisterResponse + if err := c.client.CallUnary(ctx, bootServiceRegisterSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *bootServiceClient) Wait(ctx context.Context, req *v2.BootServiceWaitRequest) (BootServiceWaitClientStream, error) { + stream, err := c.client.CallServerStream(ctx, bootServiceWaitSpec(), req) + if err != nil { + return BootServiceWaitClientStream{}, err + } + return BootServiceWaitClientStream{stream: stream}, nil +} + +func (c *bootServiceClient) InstallationSucceeded(ctx context.Context, req *v2.BootServiceInstallationSucceededRequest) (*v2.BootServiceInstallationSucceededResponse, error) { + var res v2.BootServiceInstallationSucceededResponse + if err := c.client.CallUnary(ctx, bootServiceInstallationSucceededSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *bootServiceClient) SendEvent(ctx context.Context, req *v2.BootServiceSendEventRequest) (*v2.BootServiceSendEventResponse, error) { + var res v2.BootServiceSendEventResponse + if err := c.client.CallUnary(ctx, bootServiceSendEventSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +type bootServiceHandler struct{ svc BootServiceHandler } + +func (h bootServiceHandler) dhcp(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.BootServiceDhcpRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Dhcp(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) +} + +func (h bootServiceHandler) boot(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.BootServiceBootRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Boot(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) +} + +func (h bootServiceHandler) machineToken(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.BootServiceMachineTokenRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.MachineToken(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) +} + +func (h bootServiceHandler) superUserPassword(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.BootServiceSuperUserPasswordRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.SuperUserPassword(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) +} + +func (h bootServiceHandler) register(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.BootServiceRegisterRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Register(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) +} + +func (h bootServiceHandler) wait(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.BootServiceWaitRequest + if err := stream.Receive(&req); err != nil { + return err + } + return h.svc.Wait(ctx, &req, BootServiceWaitServerStream{stream: stream}) +} + +func (h bootServiceHandler) installationSucceeded(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.BootServiceInstallationSucceededRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.InstallationSucceeded(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) +} + +func (h bootServiceHandler) sendEvent(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.BootServiceSendEventRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.SendEvent(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } diff --git a/go/metalstack/infra/v2/infrav2connect/component.connect.go b/go/metalstack/infra/v2/infrav2connect/component.connect.go index ecd34208..6f4717f9 100644 --- a/go/metalstack/infra/v2/infrav2connect/component.connect.go +++ b/go/metalstack/infra/v2/infrav2connect/component.connect.go @@ -5,38 +5,39 @@ package infrav2connect import ( - connect "connectrpc.com/connect" + connect "connectrpc.com/connect/v2" context "context" - errors "errors" v2 "github.com/metal-stack/api/go/metalstack/infra/v2" - http "net/http" - strings "strings" + sync "sync" ) -// 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 ( // ComponentServiceName is the fully-qualified name of the ComponentService service. ComponentServiceName = "metalstack.infra.v2.ComponentService" ) -// 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. +// These constants are the procedure 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 ( - // ComponentServicePingProcedure is the fully-qualified name of the ComponentService's Ping RPC. + // ComponentServicePingProcedure is the procedure name of the ComponentService's Ping RPC. ComponentServicePingProcedure = "/metalstack.infra.v2.ComponentService/Ping" ) +var ( + componentServicePingSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_infra_v2_component_proto.Services().ByName("ComponentService").Methods().ByName("Ping"), + Procedure: ComponentServicePingProcedure, + } + }) +) + // ComponentServiceClient is a client for the metalstack.infra.v2.ComponentService service. type ComponentServiceClient interface { // Returns the ping response to register or report the microservice state. @@ -44,37 +45,9 @@ type ComponentServiceClient interface { } // NewComponentServiceClient constructs a client for the metalstack.infra.v2.ComponentService -// 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 NewComponentServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) ComponentServiceClient { - baseURL = strings.TrimRight(baseURL, "/") - componentServiceMethods := v2.File_metalstack_infra_v2_component_proto.Services().ByName("ComponentService").Methods() - return &componentServiceClient{ - ping: connect.NewClient[v2.ComponentServicePingRequest, v2.ComponentServicePingResponse]( - httpClient, - baseURL+ComponentServicePingProcedure, - connect.WithSchema(componentServiceMethods.ByName("Ping")), - connect.WithClientOptions(opts...), - ), - } -} - -// componentServiceClient implements ComponentServiceClient. -type componentServiceClient struct { - ping *connect.Client[v2.ComponentServicePingRequest, v2.ComponentServicePingResponse] -} - -// Ping calls metalstack.infra.v2.ComponentService.Ping. -func (c *componentServiceClient) Ping(ctx context.Context, req *v2.ComponentServicePingRequest) (*v2.ComponentServicePingResponse, error) { - response, err := c.ping.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err +// service. Multiple service clients may share a single connect.Client. +func NewComponentServiceClient(client *connect.Client) ComponentServiceClient { + return &componentServiceClient{client: client} } // ComponentServiceHandler is an implementation of the metalstack.infra.v2.ComponentService service. @@ -83,32 +56,44 @@ type ComponentServiceHandler interface { Ping(context.Context, *v2.ComponentServicePingRequest) (*v2.ComponentServicePingResponse, error) } -// NewComponentServiceHandler 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 NewComponentServiceHandler(svc ComponentServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) { - componentServiceMethods := v2.File_metalstack_infra_v2_component_proto.Services().ByName("ComponentService").Methods() - componentServicePingHandler := connect.NewUnaryHandlerSimple( - ComponentServicePingProcedure, - svc.Ping, - connect.WithSchema(componentServiceMethods.ByName("Ping")), - connect.WithHandlerOptions(opts...), +// RegisterComponentServiceHandler registers svc as the metalstack.infra.v2.ComponentService +// implementation on server. +func RegisterComponentServiceHandler(server *connect.Server, svc ComponentServiceHandler) { + adapter := componentServiceHandler{svc: svc} + server.Register( + connect.Method{Spec: componentServicePingSpec(), Handler: adapter.ping}, ) - return "/metalstack.infra.v2.ComponentService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - switch r.URL.Path { - case ComponentServicePingProcedure: - componentServicePingHandler.ServeHTTP(w, r) - default: - http.NotFound(w, r) - } - }) } // UnimplementedComponentServiceHandler returns CodeUnimplemented from all methods. type UnimplementedComponentServiceHandler struct{} func (UnimplementedComponentServiceHandler) Ping(context.Context, *v2.ComponentServicePingRequest) (*v2.ComponentServicePingResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.infra.v2.ComponentService.Ping is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.infra.v2.ComponentService.Ping is not implemented") +} + +type componentServiceClient struct { + client *connect.Client +} + +func (c *componentServiceClient) Ping(ctx context.Context, req *v2.ComponentServicePingRequest) (*v2.ComponentServicePingResponse, error) { + var res v2.ComponentServicePingResponse + if err := c.client.CallUnary(ctx, componentServicePingSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +type componentServiceHandler struct{ svc ComponentServiceHandler } + +func (h componentServiceHandler) ping(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.ComponentServicePingRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Ping(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } diff --git a/go/metalstack/infra/v2/infrav2connect/event.connect.go b/go/metalstack/infra/v2/infrav2connect/event.connect.go index 24284b51..7e570e44 100644 --- a/go/metalstack/infra/v2/infrav2connect/event.connect.go +++ b/go/metalstack/infra/v2/infrav2connect/event.connect.go @@ -5,76 +5,49 @@ package infrav2connect import ( - connect "connectrpc.com/connect" + connect "connectrpc.com/connect/v2" context "context" - errors "errors" v2 "github.com/metal-stack/api/go/metalstack/infra/v2" - http "net/http" - strings "strings" + sync "sync" ) -// 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 ( // EventServiceName is the fully-qualified name of the EventService service. EventServiceName = "metalstack.infra.v2.EventService" ) -// 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. +// These constants are the procedure 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 ( - // EventServiceSendProcedure is the fully-qualified name of the EventService's Send RPC. + // EventServiceSendProcedure is the procedure name of the EventService's Send RPC. EventServiceSendProcedure = "/metalstack.infra.v2.EventService/Send" ) +var ( + eventServiceSendSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_infra_v2_event_proto.Services().ByName("EventService").Methods().ByName("Send"), + Procedure: EventServiceSendProcedure, + } + }) +) + // EventServiceClient is a client for the metalstack.infra.v2.EventService service. type EventServiceClient interface { // Sends a series of machine provisioning events. Send(context.Context, *v2.EventServiceSendRequest) (*v2.EventServiceSendResponse, error) } -// NewEventServiceClient constructs a client for the metalstack.infra.v2.EventService 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 NewEventServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) EventServiceClient { - baseURL = strings.TrimRight(baseURL, "/") - eventServiceMethods := v2.File_metalstack_infra_v2_event_proto.Services().ByName("EventService").Methods() - return &eventServiceClient{ - send: connect.NewClient[v2.EventServiceSendRequest, v2.EventServiceSendResponse]( - httpClient, - baseURL+EventServiceSendProcedure, - connect.WithSchema(eventServiceMethods.ByName("Send")), - connect.WithClientOptions(opts...), - ), - } -} - -// eventServiceClient implements EventServiceClient. -type eventServiceClient struct { - send *connect.Client[v2.EventServiceSendRequest, v2.EventServiceSendResponse] -} - -// Send calls metalstack.infra.v2.EventService.Send. -func (c *eventServiceClient) Send(ctx context.Context, req *v2.EventServiceSendRequest) (*v2.EventServiceSendResponse, error) { - response, err := c.send.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err +// NewEventServiceClient constructs a client for the metalstack.infra.v2.EventService service. +// Multiple service clients may share a single connect.Client. +func NewEventServiceClient(client *connect.Client) EventServiceClient { + return &eventServiceClient{client: client} } // EventServiceHandler is an implementation of the metalstack.infra.v2.EventService service. @@ -83,32 +56,44 @@ type EventServiceHandler interface { Send(context.Context, *v2.EventServiceSendRequest) (*v2.EventServiceSendResponse, error) } -// NewEventServiceHandler 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 NewEventServiceHandler(svc EventServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) { - eventServiceMethods := v2.File_metalstack_infra_v2_event_proto.Services().ByName("EventService").Methods() - eventServiceSendHandler := connect.NewUnaryHandlerSimple( - EventServiceSendProcedure, - svc.Send, - connect.WithSchema(eventServiceMethods.ByName("Send")), - connect.WithHandlerOptions(opts...), +// RegisterEventServiceHandler registers svc as the metalstack.infra.v2.EventService implementation +// on server. +func RegisterEventServiceHandler(server *connect.Server, svc EventServiceHandler) { + adapter := eventServiceHandler{svc: svc} + server.Register( + connect.Method{Spec: eventServiceSendSpec(), Handler: adapter.send}, ) - return "/metalstack.infra.v2.EventService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - switch r.URL.Path { - case EventServiceSendProcedure: - eventServiceSendHandler.ServeHTTP(w, r) - default: - http.NotFound(w, r) - } - }) } // UnimplementedEventServiceHandler returns CodeUnimplemented from all methods. type UnimplementedEventServiceHandler struct{} func (UnimplementedEventServiceHandler) Send(context.Context, *v2.EventServiceSendRequest) (*v2.EventServiceSendResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.infra.v2.EventService.Send is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.infra.v2.EventService.Send is not implemented") +} + +type eventServiceClient struct { + client *connect.Client +} + +func (c *eventServiceClient) Send(ctx context.Context, req *v2.EventServiceSendRequest) (*v2.EventServiceSendResponse, error) { + var res v2.EventServiceSendResponse + if err := c.client.CallUnary(ctx, eventServiceSendSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +type eventServiceHandler struct{ svc EventServiceHandler } + +func (h eventServiceHandler) send(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.EventServiceSendRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Send(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } diff --git a/go/metalstack/infra/v2/infrav2connect/switch.connect.go b/go/metalstack/infra/v2/infrav2connect/switch.connect.go index 89020b05..2008a661 100644 --- a/go/metalstack/infra/v2/infrav2connect/switch.connect.go +++ b/go/metalstack/infra/v2/infrav2connect/switch.connect.go @@ -5,42 +5,57 @@ package infrav2connect import ( - connect "connectrpc.com/connect" + connect "connectrpc.com/connect/v2" context "context" - errors "errors" v2 "github.com/metal-stack/api/go/metalstack/infra/v2" - http "net/http" - strings "strings" + sync "sync" ) -// 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 ( // SwitchServiceName is the fully-qualified name of the SwitchService service. SwitchServiceName = "metalstack.infra.v2.SwitchService" ) -// 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. +// These constants are the procedure 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 ( - // SwitchServiceGetProcedure is the fully-qualified name of the SwitchService's Get RPC. + // SwitchServiceGetProcedure is the procedure name of the SwitchService's Get RPC. SwitchServiceGetProcedure = "/metalstack.infra.v2.SwitchService/Get" - // SwitchServiceRegisterProcedure is the fully-qualified name of the SwitchService's Register RPC. + // SwitchServiceRegisterProcedure is the procedure name of the SwitchService's Register RPC. SwitchServiceRegisterProcedure = "/metalstack.infra.v2.SwitchService/Register" - // SwitchServiceHeartbeatProcedure is the fully-qualified name of the SwitchService's Heartbeat RPC. + // SwitchServiceHeartbeatProcedure is the procedure name of the SwitchService's Heartbeat RPC. SwitchServiceHeartbeatProcedure = "/metalstack.infra.v2.SwitchService/Heartbeat" ) +var ( + switchServiceGetSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_infra_v2_switch_proto.Services().ByName("SwitchService").Methods().ByName("Get"), + Procedure: SwitchServiceGetProcedure, + } + }) + switchServiceRegisterSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_infra_v2_switch_proto.Services().ByName("SwitchService").Methods().ByName("Register"), + Procedure: SwitchServiceRegisterProcedure, + } + }) + switchServiceHeartbeatSpec = sync.OnceValue(func() connect.Spec { + return connect.Spec{ + StreamType: connect.StreamTypeUnary, + Schema: v2.File_metalstack_infra_v2_switch_proto.Services().ByName("SwitchService").Methods().ByName("Heartbeat"), + Procedure: SwitchServiceHeartbeatProcedure, + } + }) +) + // SwitchServiceClient is a client for the metalstack.infra.v2.SwitchService service. type SwitchServiceClient interface { // Returns the switch with the specified ID. @@ -51,70 +66,10 @@ type SwitchServiceClient interface { Heartbeat(context.Context, *v2.SwitchServiceHeartbeatRequest) (*v2.SwitchServiceHeartbeatResponse, error) } -// NewSwitchServiceClient constructs a client for the metalstack.infra.v2.SwitchService 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 NewSwitchServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) SwitchServiceClient { - baseURL = strings.TrimRight(baseURL, "/") - switchServiceMethods := v2.File_metalstack_infra_v2_switch_proto.Services().ByName("SwitchService").Methods() - return &switchServiceClient{ - get: connect.NewClient[v2.SwitchServiceGetRequest, v2.SwitchServiceGetResponse]( - httpClient, - baseURL+SwitchServiceGetProcedure, - connect.WithSchema(switchServiceMethods.ByName("Get")), - connect.WithClientOptions(opts...), - ), - register: connect.NewClient[v2.SwitchServiceRegisterRequest, v2.SwitchServiceRegisterResponse]( - httpClient, - baseURL+SwitchServiceRegisterProcedure, - connect.WithSchema(switchServiceMethods.ByName("Register")), - connect.WithClientOptions(opts...), - ), - heartbeat: connect.NewClient[v2.SwitchServiceHeartbeatRequest, v2.SwitchServiceHeartbeatResponse]( - httpClient, - baseURL+SwitchServiceHeartbeatProcedure, - connect.WithSchema(switchServiceMethods.ByName("Heartbeat")), - connect.WithClientOptions(opts...), - ), - } -} - -// switchServiceClient implements SwitchServiceClient. -type switchServiceClient struct { - get *connect.Client[v2.SwitchServiceGetRequest, v2.SwitchServiceGetResponse] - register *connect.Client[v2.SwitchServiceRegisterRequest, v2.SwitchServiceRegisterResponse] - heartbeat *connect.Client[v2.SwitchServiceHeartbeatRequest, v2.SwitchServiceHeartbeatResponse] -} - -// Get calls metalstack.infra.v2.SwitchService.Get. -func (c *switchServiceClient) Get(ctx context.Context, req *v2.SwitchServiceGetRequest) (*v2.SwitchServiceGetResponse, error) { - response, err := c.get.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err -} - -// Register calls metalstack.infra.v2.SwitchService.Register. -func (c *switchServiceClient) Register(ctx context.Context, req *v2.SwitchServiceRegisterRequest) (*v2.SwitchServiceRegisterResponse, error) { - response, err := c.register.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err -} - -// Heartbeat calls metalstack.infra.v2.SwitchService.Heartbeat. -func (c *switchServiceClient) Heartbeat(ctx context.Context, req *v2.SwitchServiceHeartbeatRequest) (*v2.SwitchServiceHeartbeatResponse, error) { - response, err := c.heartbeat.CallUnary(ctx, connect.NewRequest(req)) - if response != nil { - return response.Msg, err - } - return nil, err +// NewSwitchServiceClient constructs a client for the metalstack.infra.v2.SwitchService service. +// Multiple service clients may share a single connect.Client. +func NewSwitchServiceClient(client *connect.Client) SwitchServiceClient { + return &switchServiceClient{client: client} } // SwitchServiceHandler is an implementation of the metalstack.infra.v2.SwitchService service. @@ -127,56 +82,94 @@ type SwitchServiceHandler interface { Heartbeat(context.Context, *v2.SwitchServiceHeartbeatRequest) (*v2.SwitchServiceHeartbeatResponse, error) } -// NewSwitchServiceHandler 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 NewSwitchServiceHandler(svc SwitchServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) { - switchServiceMethods := v2.File_metalstack_infra_v2_switch_proto.Services().ByName("SwitchService").Methods() - switchServiceGetHandler := connect.NewUnaryHandlerSimple( - SwitchServiceGetProcedure, - svc.Get, - connect.WithSchema(switchServiceMethods.ByName("Get")), - connect.WithHandlerOptions(opts...), +// RegisterSwitchServiceHandler registers svc as the metalstack.infra.v2.SwitchService +// implementation on server. +func RegisterSwitchServiceHandler(server *connect.Server, svc SwitchServiceHandler) { + adapter := switchServiceHandler{svc: svc} + server.Register( + connect.Method{Spec: switchServiceGetSpec(), Handler: adapter.get}, + connect.Method{Spec: switchServiceRegisterSpec(), Handler: adapter.register}, + connect.Method{Spec: switchServiceHeartbeatSpec(), Handler: adapter.heartbeat}, ) - switchServiceRegisterHandler := connect.NewUnaryHandlerSimple( - SwitchServiceRegisterProcedure, - svc.Register, - connect.WithSchema(switchServiceMethods.ByName("Register")), - connect.WithHandlerOptions(opts...), - ) - switchServiceHeartbeatHandler := connect.NewUnaryHandlerSimple( - SwitchServiceHeartbeatProcedure, - svc.Heartbeat, - connect.WithSchema(switchServiceMethods.ByName("Heartbeat")), - connect.WithHandlerOptions(opts...), - ) - return "/metalstack.infra.v2.SwitchService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - switch r.URL.Path { - case SwitchServiceGetProcedure: - switchServiceGetHandler.ServeHTTP(w, r) - case SwitchServiceRegisterProcedure: - switchServiceRegisterHandler.ServeHTTP(w, r) - case SwitchServiceHeartbeatProcedure: - switchServiceHeartbeatHandler.ServeHTTP(w, r) - default: - http.NotFound(w, r) - } - }) } // UnimplementedSwitchServiceHandler returns CodeUnimplemented from all methods. type UnimplementedSwitchServiceHandler struct{} func (UnimplementedSwitchServiceHandler) Get(context.Context, *v2.SwitchServiceGetRequest) (*v2.SwitchServiceGetResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.infra.v2.SwitchService.Get is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.infra.v2.SwitchService.Get is not implemented") } func (UnimplementedSwitchServiceHandler) Register(context.Context, *v2.SwitchServiceRegisterRequest) (*v2.SwitchServiceRegisterResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.infra.v2.SwitchService.Register is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.infra.v2.SwitchService.Register is not implemented") } func (UnimplementedSwitchServiceHandler) Heartbeat(context.Context, *v2.SwitchServiceHeartbeatRequest) (*v2.SwitchServiceHeartbeatResponse, error) { - return nil, connect.NewError(connect.CodeUnimplemented, errors.New("metalstack.infra.v2.SwitchService.Heartbeat is not implemented")) + return nil, connect.NewError(connect.CodeUnimplemented, "metalstack.infra.v2.SwitchService.Heartbeat is not implemented") +} + +type switchServiceClient struct { + client *connect.Client +} + +func (c *switchServiceClient) Get(ctx context.Context, req *v2.SwitchServiceGetRequest) (*v2.SwitchServiceGetResponse, error) { + var res v2.SwitchServiceGetResponse + if err := c.client.CallUnary(ctx, switchServiceGetSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *switchServiceClient) Register(ctx context.Context, req *v2.SwitchServiceRegisterRequest) (*v2.SwitchServiceRegisterResponse, error) { + var res v2.SwitchServiceRegisterResponse + if err := c.client.CallUnary(ctx, switchServiceRegisterSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +func (c *switchServiceClient) Heartbeat(ctx context.Context, req *v2.SwitchServiceHeartbeatRequest) (*v2.SwitchServiceHeartbeatResponse, error) { + var res v2.SwitchServiceHeartbeatResponse + if err := c.client.CallUnary(ctx, switchServiceHeartbeatSpec(), req, &res); err != nil { + return nil, err + } + return &res, nil +} + +type switchServiceHandler struct{ svc SwitchServiceHandler } + +func (h switchServiceHandler) get(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.SwitchServiceGetRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Get(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) +} + +func (h switchServiceHandler) register(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.SwitchServiceRegisterRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Register(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) +} + +func (h switchServiceHandler) heartbeat(ctx context.Context, _ connect.Spec, stream connect.ServerStream) error { + var req v2.SwitchServiceHeartbeatRequest + if err := stream.Receive(&req); err != nil { + return err + } + res, err := h.svc.Heartbeat(ctx, &req) + if err != nil { + return err + } + return stream.Send(res) } diff --git a/go/permissions/servicepermissions.go b/go/permissions/servicepermissions.go index bf4d19eb..0da3ba58 100755 --- a/go/permissions/servicepermissions.go +++ b/go/permissions/servicepermissions.go @@ -2,8 +2,9 @@ package permissions import ( - "connectrpc.com/connect" + "connectrpc.com/connect/v2" apiv2 "github.com/metal-stack/api/go/metalstack/api/v2" + "google.golang.org/protobuf/proto" ) func GetServices() []string { @@ -764,73 +765,73 @@ func GetServicePermissions() *ServicePermissions { } } -func IsPublicScope(req connect.AnyRequest) bool { - _, ok := GetServicePermissions().Visibility.Public[req.Spec().Procedure] +func IsPublicScope(spec connect.Spec) bool { + _, ok := GetServicePermissions().Visibility.Public[spec.Procedure] return ok } -func IsSelfScope(req connect.AnyRequest) bool { - _, ok := GetServicePermissions().Visibility.Self[req.Spec().Procedure] +func IsSelfScope(spec connect.Spec) bool { + _, ok := GetServicePermissions().Visibility.Self[spec.Procedure] return ok } -func IsAdminScope(req connect.AnyRequest) bool { - _, ok := GetServicePermissions().Visibility.Admin[req.Spec().Procedure] +func IsAdminScope(spec connect.Spec) bool { + _, ok := GetServicePermissions().Visibility.Admin[spec.Procedure] return ok } -func IsInfraScope(req connect.AnyRequest) bool { - _, ok := GetServicePermissions().Visibility.Infra[req.Spec().Procedure] +func IsInfraScope(spec connect.Spec) bool { + _, ok := GetServicePermissions().Visibility.Infra[spec.Procedure] return ok } -func IsMachineScope(req connect.AnyRequest) bool { - _, ok := GetServicePermissions().Visibility.Machine[req.Spec().Procedure] +func IsMachineScope(spec connect.Spec) bool { + _, ok := GetServicePermissions().Visibility.Machine[spec.Procedure] return ok } -func IsTenantScope(req connect.AnyRequest) bool { - _, ok := GetServicePermissions().Visibility.Tenant[req.Spec().Procedure] +func IsTenantScope(spec connect.Spec) bool { + _, ok := GetServicePermissions().Visibility.Tenant[spec.Procedure] return ok } -func IsProjectScope(req connect.AnyRequest) bool { - _, ok := GetServicePermissions().Visibility.Project[req.Spec().Procedure] +func IsProjectScope(spec connect.Spec) bool { + _, ok := GetServicePermissions().Visibility.Project[spec.Procedure] return ok } -func IsAuditable(req connect.AnyRequest) bool { - _, ok := GetServicePermissions().Auditable[req.Spec().Procedure] +func IsAuditable(spec connect.Spec) bool { + _, ok := GetServicePermissions().Auditable[spec.Procedure] return ok } -func GetTenantFromRequest(req connect.AnyRequest) (string, bool) { - if !IsTenantScope(req) { +func GetTenantFromRequest(spec connect.Spec, req proto.Message) (string, bool) { + if !IsTenantScope(spec) { return "", false } - switch rq := req.Any().(type) { + switch rq := req.(type) { case interface{ GetLogin() string }: return rq.GetLogin(), true } return "", false } -func GetProjectFromRequest(req connect.AnyRequest) (string, bool) { - if !IsProjectScope(req) { +func GetProjectFromRequest(spec connect.Spec, req proto.Message) (string, bool) { + if !IsProjectScope(spec) { return "", false } - switch rq := req.Any().(type) { + switch rq := req.(type) { case interface{ GetProject() string }: return rq.GetProject(), true } return "", false } -func GetMachineIdFromRequest(req connect.AnyRequest) (string, bool) { - if !IsMachineScope(req) { +func GetMachineIdFromRequest(spec connect.Spec, req proto.Message) (string, bool) { + if !IsMachineScope(spec) { return "", false } - switch rq := req.Any().(type) { + switch rq := req.(type) { case interface{ GetUuid() string }: return rq.GetUuid(), true } diff --git a/proto/buf.gen.yaml b/proto/buf.gen.yaml index 6cf0f034..3029f2d8 100644 --- a/proto/buf.gen.yaml +++ b/proto/buf.gen.yaml @@ -16,9 +16,9 @@ plugins: - remote: buf.build/protocolbuffers/go:v1.36.12 out: ../go opt: paths=source_relative - - remote: buf.build/connectrpc/go:v1.21.0 + - remote: buf.build/connectrpc/go:v2.0.0 out: ../go - opt: paths=source_relative,simple + opt: paths=source_relative # python - remote: buf.build/protocolbuffers/python:v36.2 out: ../python