Refactor gRPC definitions into seperate repo

The protobuf files and the generated golang code has been moved into
git.ohea.xyz/cursorius/pipeline-api. The generated code is now imported
from that location. The version of the API has also been bumped to v2 to
avoid unsupported v1 modules in golang.
This commit is contained in:
2023-01-02 01:59:51 -07:00
parent fc117cef39
commit f95a5f9ae5
11 changed files with 16 additions and 778 deletions
+12 -12
View File
@@ -7,8 +7,8 @@ import (
"strings"
"sync"
apiv1 "git.ohea.xyz/cursorius/server/proto/gen/api/v1"
"git.ohea.xyz/cursorius/server/proto/gen/api/v1/apiv1connect"
apiv2 "git.ohea.xyz/cursorius/pipeline-api/go/api/v2"
"git.ohea.xyz/cursorius/pipeline-api/go/api/v2/apiv2connect"
"git.ohea.xyz/cursorius/server/runnermanager"
"github.com/bufbuild/connect-go"
"github.com/google/uuid"
@@ -47,8 +47,8 @@ func (s *ApiServer) GetRunnerFromMap(uuid uuid) *RunnerWrapper {
func (s *ApiServer) GetRunner(
ctx context.Context,
req *connect.Request[apiv1.GetRunnerRequest],
) (*connect.Response[apiv1.GetRunnerResponse], error) {
req *connect.Request[apiv2.GetRunnerRequest],
) (*connect.Response[apiv2.GetRunnerResponse], error) {
respChan := make(chan runnermanager.GetRunnerResponse)
s.getRunnerCh <- runnermanager.GetRunnerRequest{
@@ -76,17 +76,17 @@ func (s *ApiServer) GetRunner(
s.allocatedRunners[runnerUuid] = &RunnerWrapper{runner: response.Runner}
s.allocatedRunnersMutex.Unlock()
res := connect.NewResponse(&apiv1.GetRunnerResponse{
res := connect.NewResponse(&apiv2.GetRunnerResponse{
Id: runnerUuid.String(),
})
res.Header().Set("GetRunner-Version", "v1")
res.Header().Set("GetRunner-Version", "v2")
return res, nil
}
func (s *ApiServer) RunCommand(
ctx context.Context,
req *connect.Request[apiv1.RunCommandRequest],
) (*connect.Response[apiv1.RunCommandResponse], error) {
req *connect.Request[apiv2.RunCommandRequest],
) (*connect.Response[apiv2.RunCommandResponse], error) {
uuid, err := uuid.Parse(req.Msg.Id)
if err != nil {
@@ -101,12 +101,12 @@ func (s *ApiServer) RunCommand(
return nil, connect.NewError(connect.CodeInternal, fmt.Errorf("Could not run command"))
}
res := connect.NewResponse(&apiv1.RunCommandResponse{
res := connect.NewResponse(&apiv2.RunCommandResponse{
ReturnCode: return_code,
Stdout: stdout,
Stderr: stderr,
})
res.Header().Set("RunCommand-Version", "v1")
res.Header().Set("RunCommand-Version", "v2")
return res, nil
}
@@ -115,8 +115,8 @@ func CreateHandler(mux *http.ServeMux, getRunnerCh chan runnermanager.GetRunnerR
getRunnerCh: getRunnerCh,
allocatedRunners: make(map[uuid.UUID]*RunnerWrapper),
}
path, handler := apiv1connect.NewGetRunnerServiceHandler(api_server)
path, handler := apiv2connect.NewGetRunnerServiceHandler(api_server)
mux.Handle(path, handler)
path, handler = apiv1connect.NewRunCommandServiceHandler(api_server)
path, handler = apiv2connect.NewRunCommandServiceHandler(api_server)
mux.Handle(path, handler)
}