From 62de83d9c24b252108684fe0aeb3616422f438a5 Mon Sep 17 00:00:00 2001 From: Kevin Chen Date: Sat, 6 Jan 2024 16:31:03 -0500 Subject: [PATCH] feat: REST Annotations (#88) --- Makefile | 12 ++-- README.md | 4 +- go.mod | 4 +- go.sum | 8 +-- idl/licenseapis/buf.lock | 5 ++ idl/licenseapis/buf.yaml | 1 + idl/licenseapis/license/v1beta1/api.proto | 7 ++- idl/orgapis/buf.lock | 5 ++ idl/orgapis/buf.yaml | 1 + idl/orgapis/org/v1beta1/api.proto | 7 ++- idl/profileapis/buf.lock | 5 ++ idl/profileapis/buf.yaml | 1 + idl/profileapis/profile/v1beta1/api.proto | 7 ++- pkg/fxmod/connect/connect.go | 2 +- taskfiles/run.yml | 70 +++++++++++++---------- 15 files changed, 89 insertions(+), 50 deletions(-) diff --git a/Makefile b/Makefile index 551f03e..2c60ea1 100644 --- a/Makefile +++ b/Makefile @@ -19,12 +19,16 @@ check_pkgx: exit 1; \ fi @echo "pkgx is installed." + pkgx --sync .PHONY: all -all: check_pkgx - pkgx --sync - pkgx killport@latest 7233 - sleep 1 +all: check_pkgx stop pkgx temporal@latest server start-dev & sleep 2 pkgx task@latest run:all + +.PHONY: stop +stop: + pkgx killport@latest 7233 + sleep 1 + pkgx docker-clean stop diff --git a/README.md b/README.md index ba0d427..f9373a3 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ curl -v http://localhost:8081/temporal.v1beta1.TemporalService/CreateOnboardingW "name": "Org 1" }, "profile": { - "name": "Kevin Chen" + "full_name": "Kevin Chen" } } EOF @@ -95,7 +95,7 @@ pkgx http POST \ "name": "Org 1" }, "profile": { - "name": "Kevin Chen" + "full_name": "Kevin Chen" } } ' diff --git a/go.mod b/go.mod index c513de6..3abeb4c 100644 --- a/go.mod +++ b/go.mod @@ -3,8 +3,8 @@ module github.com/kevinmichaelchen/temporal-saga-grpc go 1.21.5 require ( - buf.build/gen/go/kevinmichaelchen/licenseapis/connectrpc/go v1.14.0-20240106023353-b0ccffe2bf81.1 - buf.build/gen/go/kevinmichaelchen/licenseapis/protocolbuffers/go v1.32.0-20240106023353-b0ccffe2bf81.1 + buf.build/gen/go/kevinmichaelchen/licenseapis/connectrpc/go v1.14.0-20240106205504-60998e437501.1 + buf.build/gen/go/kevinmichaelchen/licenseapis/protocolbuffers/go v1.32.0-20240106205504-60998e437501.1 buf.build/gen/go/kevinmichaelchen/orgapis/connectrpc/go v1.14.0-20240106023354-7971463d1bab.1 buf.build/gen/go/kevinmichaelchen/orgapis/protocolbuffers/go v1.32.0-20240106023354-7971463d1bab.1 buf.build/gen/go/kevinmichaelchen/profileapis/connectrpc/go v1.14.0-20240106023355-4074133bf516.1 diff --git a/go.sum b/go.sum index a587a32..91be034 100644 --- a/go.sum +++ b/go.sum @@ -1,9 +1,9 @@ buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.32.0-20231115204500-e097f827e652.1 h1:u0olL4yf2p7Tl5jfsAK5keaFi+JFJuv1CDHrbiXkxkk= buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.32.0-20231115204500-e097f827e652.1/go.mod h1:tiTMKD8j6Pd/D2WzREoweufjzaJKHZg35f/VGcZ2v3I= -buf.build/gen/go/kevinmichaelchen/licenseapis/connectrpc/go v1.14.0-20240106023353-b0ccffe2bf81.1 h1:HXlREx5iasiZ7RLIcM+Sa9KXLfznGMzfRUvtFJPa3pA= -buf.build/gen/go/kevinmichaelchen/licenseapis/connectrpc/go v1.14.0-20240106023353-b0ccffe2bf81.1/go.mod h1:bH7/XrbxIE+ZFdY12NEIikndXo36yoc7AV6sJDLR/M0= -buf.build/gen/go/kevinmichaelchen/licenseapis/protocolbuffers/go v1.32.0-20240106023353-b0ccffe2bf81.1 h1:Bhg6zySqAAGMy8+lw+EhV1iIU/vDoUekSnFKlvFWX3s= -buf.build/gen/go/kevinmichaelchen/licenseapis/protocolbuffers/go v1.32.0-20240106023353-b0ccffe2bf81.1/go.mod h1:f0zTv4+cZ3+O0fQx7E6JKpPLhQuUJMkl+M7Ott4b4wo= +buf.build/gen/go/kevinmichaelchen/licenseapis/connectrpc/go v1.14.0-20240106205504-60998e437501.1 h1:0TszGVkPTm7U/g4gSxpaMpTP69VE8rPTEChk70Qz4sQ= +buf.build/gen/go/kevinmichaelchen/licenseapis/connectrpc/go v1.14.0-20240106205504-60998e437501.1/go.mod h1:G1rlmkINw1TUjL1oRwMxXtp4njBMAXx+N9X0DxVySoA= +buf.build/gen/go/kevinmichaelchen/licenseapis/protocolbuffers/go v1.32.0-20240106205504-60998e437501.1 h1:WxWQri+vLlodmxpDZz7nj91vIHeLgStvg5NtOXn/Bg8= +buf.build/gen/go/kevinmichaelchen/licenseapis/protocolbuffers/go v1.32.0-20240106205504-60998e437501.1/go.mod h1:f0zTv4+cZ3+O0fQx7E6JKpPLhQuUJMkl+M7Ott4b4wo= buf.build/gen/go/kevinmichaelchen/orgapis/connectrpc/go v1.14.0-20240106023354-7971463d1bab.1 h1:AcL7ufchnekd8PUAipa2TUv93Xo07XOExmoL8Ae5J+4= buf.build/gen/go/kevinmichaelchen/orgapis/connectrpc/go v1.14.0-20240106023354-7971463d1bab.1/go.mod h1:tq6x6ypkRXOLfa/pojKOaoAtdiwaNhK520RwZdnYRMU= buf.build/gen/go/kevinmichaelchen/orgapis/protocolbuffers/go v1.32.0-20240106023354-7971463d1bab.1 h1:XGdlUgsatFaPXeMj+KSSIBxC+esBQMK6vLvaSV71iYA= diff --git a/idl/licenseapis/buf.lock b/idl/licenseapis/buf.lock index 3ce75d9..2b71cee 100644 --- a/idl/licenseapis/buf.lock +++ b/idl/licenseapis/buf.lock @@ -6,3 +6,8 @@ deps: repository: protovalidate commit: e097f827e65240ac9fd4b1158849a8fc digest: shake256:f19252436fd9ded945631e2ffaaed28247a92c9015ccf55ae99db9fb3d9600c4fdb00fd2d3bd7701026ec2fd4715c5129e6ae517c25a59ba690020cfe80bf8ad + - remote: buf.build + owner: googleapis + repository: googleapis + commit: a86849a25cc04f4dbe9b15ddddfbc488 + digest: shake256:e19143328f8cbfe13fc226aeee5e63773ca494693a72740a7560664270039a380d94a1344234b88c7691311460df9a9b1c2982190d0a2612eae80368718e1943 diff --git a/idl/licenseapis/buf.yaml b/idl/licenseapis/buf.yaml index 2817d80..050f22b 100644 --- a/idl/licenseapis/buf.yaml +++ b/idl/licenseapis/buf.yaml @@ -2,6 +2,7 @@ version: v1 name: buf.build/kevinmichaelchen/licenseapis deps: - buf.build/bufbuild/protovalidate:e097f827e65240ac9fd4b1158849a8fc + - buf.build/googleapis/googleapis breaking: use: - FILE diff --git a/idl/licenseapis/license/v1beta1/api.proto b/idl/licenseapis/license/v1beta1/api.proto index 35aa663..11e81c3 100644 --- a/idl/licenseapis/license/v1beta1/api.proto +++ b/idl/licenseapis/license/v1beta1/api.proto @@ -3,6 +3,7 @@ syntax = "proto3"; package license.v1beta1; import "buf/validate/validate.proto"; +import "google/api/annotations.proto"; import "google/protobuf/timestamp.proto"; // Service for managing licenses. @@ -13,11 +14,13 @@ service LicenseService { } // Get a License. rpc GetLicense(GetLicenseRequest) returns (GetLicenseResponse) { - option idempotency_level = IDEMPOTENT; + option (google.api.http).get = "/licenses/{id}"; + option idempotency_level = NO_SIDE_EFFECTS; } // ListLicenses - Lists Licenses. rpc ListLicenses(ListLicensesRequest) returns (ListLicensesResponse) { - option idempotency_level = IDEMPOTENT; + option (google.api.http).get = "/licenses"; + option idempotency_level = NO_SIDE_EFFECTS; } } diff --git a/idl/orgapis/buf.lock b/idl/orgapis/buf.lock index 3ce75d9..2b71cee 100644 --- a/idl/orgapis/buf.lock +++ b/idl/orgapis/buf.lock @@ -6,3 +6,8 @@ deps: repository: protovalidate commit: e097f827e65240ac9fd4b1158849a8fc digest: shake256:f19252436fd9ded945631e2ffaaed28247a92c9015ccf55ae99db9fb3d9600c4fdb00fd2d3bd7701026ec2fd4715c5129e6ae517c25a59ba690020cfe80bf8ad + - remote: buf.build + owner: googleapis + repository: googleapis + commit: a86849a25cc04f4dbe9b15ddddfbc488 + digest: shake256:e19143328f8cbfe13fc226aeee5e63773ca494693a72740a7560664270039a380d94a1344234b88c7691311460df9a9b1c2982190d0a2612eae80368718e1943 diff --git a/idl/orgapis/buf.yaml b/idl/orgapis/buf.yaml index baca7dc..9719c4e 100644 --- a/idl/orgapis/buf.yaml +++ b/idl/orgapis/buf.yaml @@ -2,6 +2,7 @@ version: v1 name: buf.build/kevinmichaelchen/orgapis deps: - buf.build/bufbuild/protovalidate:e097f827e65240ac9fd4b1158849a8fc + - buf.build/googleapis/googleapis breaking: use: - FILE diff --git a/idl/orgapis/org/v1beta1/api.proto b/idl/orgapis/org/v1beta1/api.proto index 872fa21..54172e7 100644 --- a/idl/orgapis/org/v1beta1/api.proto +++ b/idl/orgapis/org/v1beta1/api.proto @@ -3,6 +3,7 @@ syntax = "proto3"; package org.v1beta1; import "buf/validate/validate.proto"; +import "google/api/annotations.proto"; // Service for managing Orgs. service OrgService { @@ -12,11 +13,13 @@ service OrgService { } // GetOrg - Gets an Organization. rpc GetOrg(GetOrgRequest) returns (GetOrgResponse) { - option idempotency_level = IDEMPOTENT; + option (google.api.http).get = "/orgs/{id}"; + option idempotency_level = NO_SIDE_EFFECTS; } // ListOrgs - Lists Organizations. rpc ListOrgs(ListOrgsRequest) returns (ListOrgsResponse) { - option idempotency_level = IDEMPOTENT; + option (google.api.http).get = "/orgs"; + option idempotency_level = NO_SIDE_EFFECTS; } } diff --git a/idl/profileapis/buf.lock b/idl/profileapis/buf.lock index 3ce75d9..2b71cee 100644 --- a/idl/profileapis/buf.lock +++ b/idl/profileapis/buf.lock @@ -6,3 +6,8 @@ deps: repository: protovalidate commit: e097f827e65240ac9fd4b1158849a8fc digest: shake256:f19252436fd9ded945631e2ffaaed28247a92c9015ccf55ae99db9fb3d9600c4fdb00fd2d3bd7701026ec2fd4715c5129e6ae517c25a59ba690020cfe80bf8ad + - remote: buf.build + owner: googleapis + repository: googleapis + commit: a86849a25cc04f4dbe9b15ddddfbc488 + digest: shake256:e19143328f8cbfe13fc226aeee5e63773ca494693a72740a7560664270039a380d94a1344234b88c7691311460df9a9b1c2982190d0a2612eae80368718e1943 diff --git a/idl/profileapis/buf.yaml b/idl/profileapis/buf.yaml index 139d48a..72a5981 100644 --- a/idl/profileapis/buf.yaml +++ b/idl/profileapis/buf.yaml @@ -2,6 +2,7 @@ version: v1 name: buf.build/kevinmichaelchen/profileapis deps: - buf.build/bufbuild/protovalidate:e097f827e65240ac9fd4b1158849a8fc + - buf.build/googleapis/googleapis breaking: use: - FILE diff --git a/idl/profileapis/profile/v1beta1/api.proto b/idl/profileapis/profile/v1beta1/api.proto index e9b5144..541c3ca 100644 --- a/idl/profileapis/profile/v1beta1/api.proto +++ b/idl/profileapis/profile/v1beta1/api.proto @@ -3,6 +3,7 @@ syntax = "proto3"; package profile.v1beta1; import "buf/validate/validate.proto"; +import "google/api/annotations.proto"; // Service for managing Profiles. service ProfileService { @@ -12,11 +13,13 @@ service ProfileService { } // GetProfile - Gets a Profile. rpc GetProfile(GetProfileRequest) returns (GetProfileResponse) { - option idempotency_level = IDEMPOTENT; + option (google.api.http).get = "/profiles/{id}"; + option idempotency_level = NO_SIDE_EFFECTS; } // ListProfiles - Lists Profiles. rpc ListProfiles(ListProfilesRequest) returns (ListProfilesResponse) { - option idempotency_level = IDEMPOTENT; + option (google.api.http).get = "/profiles"; + option idempotency_level = NO_SIDE_EFFECTS; } } diff --git a/pkg/fxmod/connect/connect.go b/pkg/fxmod/connect/connect.go index 2f72187..e03a1d9 100644 --- a/pkg/fxmod/connect/connect.go +++ b/pkg/fxmod/connect/connect.go @@ -24,7 +24,7 @@ import ( // CreateModule - The primary function for building an FX module for Connect Go // APIs. func CreateModule(opts *ModuleOptions) fx.Option { - return fx.Module("grpc", + return fx.Module("connect", fx.Provide( opts.HandlerProvider, func() *ModuleOptions { diff --git a/taskfiles/run.yml b/taskfiles/run.yml index a79f963..4f13c8c 100644 --- a/taskfiles/run.yml +++ b/taskfiles/run.yml @@ -1,9 +1,12 @@ version: '3' vars: - PORT_ORG: 15432 - PORT_PROFILE: 15433 - PORT_LICENSE: 15434 + PORT_API_ORG: 9091 + PORT_API_LICENSE: 9090 + PORT_API_PROFILE: 9092 + PORT_DB_ORG: 15432 + PORT_DB_PROFILE: 15433 + PORT_DB_LICENSE: 15434 SCHEMA_ORG: org.hcl SCHEMA_PROFILE: profile.hcl SCHEMA_LICENSE: license.hcl @@ -44,54 +47,59 @@ tasks: env: GRPC_CONNECT_PORT: 8081 - service-license: - run: once + int-run-service: + internal: true deps: - task: infra - desc: "Runs license service" cmds: - - pkgx killport 9090 - - go run cmd/svc/license/main.go + - "pkgx killport {{ .PORT_API }}" + - "go run cmd/svc/{{ .NAME }}/main.go" env: - GRPC_CONNECT_PORT: 9090 - DB_CONN_STRING: "postgres://postgres:postgrespassword@localhost:{{ .PORT_LICENSE }}/postgres?sslmode=disable" + GRPC_CONNECT_PORT: "{{ .PORT_API }}" + DB_CONN_STRING: "postgres://postgres:postgrespassword@localhost:{{ .PORT_DB }}/postgres?sslmode=disable" + + service-license: + run: once + desc: "Runs license service" + cmds: + - task: int-run-service + vars: + PORT_API: "{{ .PORT_API_LICENSE }}" + PORT_DB: "{{ .PORT_DB_LICENSE }}" + NAME: license service-org: run: once - deps: - - task: infra - desc: "Runs Org service" + desc: "Runs org service" cmds: - - pkgx killport 9091 - - go run cmd/svc/org/main.go - env: - GRPC_CONNECT_PORT: 9091 - DB_CONN_STRING: "postgres://postgres:postgrespassword@localhost:{{ .PORT_ORG }}/postgres?sslmode=disable" + - task: int-run-service + vars: + PORT_API: "{{ .PORT_API_ORG }}" + PORT_DB: "{{ .PORT_DB_ORG }}" + NAME: org service-profile: run: once - deps: - - task: infra desc: "Runs profile service" cmds: - - pkgx killport 9092 - - go run cmd/svc/profile/main.go - env: - GRPC_CONNECT_PORT: 9092 - DB_CONN_STRING: "postgres://postgres:postgrespassword@localhost:{{ .PORT_PROFILE }}/postgres?sslmode=disable" + - task: int-run-service + vars: + PORT_API: "{{ .PORT_API_PROFILE }}" + PORT_DB: "{{ .PORT_DB_PROFILE }}" + NAME: profile inspect: desc: "Inspect" cmds: - task: int-inspect vars: - PORT: "{{ .PORT_ORG }}" + PORT: "{{ .PORT_DB_ORG }}" - task: int-inspect vars: - PORT: "{{ .PORT_PROFILE }}" + PORT: "{{ .PORT_DB_PROFILE }}" - task: int-inspect vars: - PORT: "{{ .PORT_LICENSE }}" + PORT: "{{ .PORT_DB_LICENSE }}" int-inspect: internal: true @@ -106,15 +114,15 @@ tasks: cmds: - task: int-migrate vars: - PORT: "{{ .PORT_ORG }}" + PORT: "{{ .PORT_DB_ORG }}" SCHEMA_FILE: "{{ .SCHEMA_ORG }}" - task: int-migrate vars: - PORT: "{{ .PORT_PROFILE }}" + PORT: "{{ .PORT_DB_PROFILE }}" SCHEMA_FILE: "{{ .SCHEMA_PROFILE }}" - task: int-migrate vars: - PORT: "{{ .PORT_LICENSE }}" + PORT: "{{ .PORT_DB_LICENSE }}" SCHEMA_FILE: "{{ .SCHEMA_LICENSE }}" int-migrate: