Răsfoiți Sursa

refactor: Moved proto files into own folder (#537)

James Read 1 an în urmă
părinte
comite
270f20ec75

+ 32 - 0
.github/workflows/build-buf.yml

@@ -0,0 +1,32 @@
+name: Buf CI
+on:
+  push:
+  pull_request:
+    types: [opened, synchronize, reopened, labeled, unlabeled]
+  delete:
+permissions:
+  contents: read
+  pull-requests: write
+jobs:
+  buf:
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/checkout@v4
+
+      - name: Setup Go
+        uses: actions/setup-go@v5
+        with:
+          go-version-file: 'go.mod'
+          cache: true
+
+      - name: grpc
+        run: make -w grpc
+
+      - uses: bufbuild/buf-action@v1
+        with:
+          token: ${{ secrets.BUF_TOKEN }}
+          # Change setup_only to true if you only want to set up the Action and not execute other commands.
+          # Otherwise, you can delete this line--the default is false.
+          setup_only: false
+          # Optional GitHub token for API requests. Ensures requests aren't rate limited.
+          github_token: ${{ secrets.GITHUB_TOKEN }}

+ 1 - 0
.github/workflows/build-snapshot.yml

@@ -71,6 +71,7 @@ jobs:
 
       - name: Archive integration tests
         uses: actions/upload-artifact@v4.3.1
+        if: always()
         with:
           name: "OliveTin-integration-tests-${{ env.DATE }}-${{ github.sha }}"
           path: |

+ 1 - 1
Makefile

@@ -50,7 +50,7 @@ go-tools:
 	go install "google.golang.org/protobuf/cmd/protoc-gen-go"
 
 grpc: go-tools
-	buf generate
+	$(MAKE) -wC proto
 
 dist: protoc
 

+ 0 - 7
buf.lock

@@ -1,7 +0,0 @@
-# Generated by buf. DO NOT EDIT.
-version: v1
-deps:
-  - remote: buf.build
-    owner: googleapis
-    repository: googleapis
-    commit: e9fcfb66f77242e5b8fd4564d7a01033

+ 4 - 0
integration-tests/lib/elements.js

@@ -19,6 +19,10 @@ export function takeScreenshotOnFailure (test, webdriver) {
 export function takeScreenshot (webdriver, title) {
   return webdriver.takeScreenshot().then((img) => {
     fs.mkdirSync('screenshots', { recursive: true });
+
+	title = title.replaceAll(/[\(\)\|\*\<\>\:]/g, "_")
+	title = 'failed-test.' + title
+
     fs.writeFileSync('screenshots/' + title + '.png', img, 'base64')
   })
 }

Fișier diff suprimat deoarece este prea mare
+ 431 - 200
integration-tests/package-lock.json


+ 5 - 5
integration-tests/package.json

@@ -11,12 +11,12 @@
   "author": "",
   "license": "AGPL-3.0-only",
   "devDependencies": {
-    "chai": "^5.1.0",
-    "eslint": "^8.51.0",
-    "mocha": "^10.8.2",
-    "selenium-webdriver": "^4.19.0"
+    "chai": "^5.2.0",
+    "eslint": "^9.22.0",
+    "mocha": "^11.1.0",
+    "selenium-webdriver": "^4.29.0"
   },
   "dependencies": {
-    "wait-on": "^7.2.0"
+    "wait-on": "^8.0.3"
   }
 }

+ 3 - 2
integration-tests/test/general.mjs

@@ -2,8 +2,8 @@ import { describe, it, before, after } from 'mocha'
 import { expect } from 'chai'
 import { By, until, Condition } from 'selenium-webdriver'
 //import * as waitOn from 'wait-on'
-import { 
-  getRootAndWait, 
+import {
+  getRootAndWait,
   getActionButtons,
   takeScreenshotOnFailure,
 } from '../lib/elements.js'
@@ -96,6 +96,7 @@ describe('config: general', function () {
     expect(await title.getAttribute('innerText')).to.be.equal('?')
 
     const dialogErr = await webdriver.findElement(By.id('big-error'))
+	console.log("big error is: " + dialogErr.innerHTML)
     expect(dialogErr).to.not.be.null
     expect(await dialogErr.isDisplayed()).to.be.false
   })

+ 39 - 39
internal/grpcapi/grpcApi.go

@@ -3,7 +3,7 @@ package grpcapi
 import (
 	ctx "context"
 
-	pb "github.com/OliveTin/OliveTin/gen/grpc"
+	apiv1 "github.com/OliveTin/OliveTin/gen/grpc/olivetin/api/v1"
 	"github.com/google/uuid"
 	log "github.com/sirupsen/logrus"
 	"google.golang.org/genproto/googleapis/api/httpbody"
@@ -28,13 +28,13 @@ var (
 
 type oliveTinAPI struct {
 	// Uncomment this if you want to allow undefined methods during dev.
-	//	pb.UnimplementedOliveTinApiServiceServer
+	//	apiv1.UnimplementedOliveTinApiServiceServer
 
 	executor *executor.Executor
 }
 
-func (api *oliveTinAPI) KillAction(ctx ctx.Context, req *pb.KillActionRequest) (*pb.KillActionResponse, error) {
-	ret := &pb.KillActionResponse{
+func (api *oliveTinAPI) KillAction(ctx ctx.Context, req *apiv1.KillActionRequest) (*apiv1.KillActionResponse, error) {
+	ret := &apiv1.KillActionResponse{
 		ExecutionTrackingId: req.ExecutionTrackingId,
 	}
 
@@ -61,7 +61,7 @@ func (api *oliveTinAPI) KillAction(ctx ctx.Context, req *pb.KillActionRequest) (
 	return ret, nil
 }
 
-func (api *oliveTinAPI) StartAction(ctx ctx.Context, req *pb.StartActionRequest) (*pb.StartActionResponse, error) {
+func (api *oliveTinAPI) StartAction(ctx ctx.Context, req *apiv1.StartActionRequest) (*apiv1.StartActionResponse, error) {
 	args := make(map[string]string)
 
 	for _, arg := range req.Arguments {
@@ -89,12 +89,12 @@ func (api *oliveTinAPI) StartAction(ctx ctx.Context, req *pb.StartActionRequest)
 
 	api.executor.ExecRequest(&execReq)
 
-	return &pb.StartActionResponse{
+	return &apiv1.StartActionResponse{
 		ExecutionTrackingId: execReq.TrackingID,
 	}, nil
 }
 
-func (api *oliveTinAPI) PasswordHash(ctx ctx.Context, req *pb.PasswordHashRequest) (*httpbody.HttpBody, error) {
+func (api *oliveTinAPI) PasswordHash(ctx ctx.Context, req *apiv1.PasswordHashRequest) (*httpbody.HttpBody, error) {
 	hash, err := createHash(req.Password)
 
 	if err != nil {
@@ -109,7 +109,7 @@ func (api *oliveTinAPI) PasswordHash(ctx ctx.Context, req *pb.PasswordHashReques
 	return ret, nil
 }
 
-func (api *oliveTinAPI) LocalUserLogin(ctx ctx.Context, req *pb.LocalUserLoginRequest) (*pb.LocalUserLoginResponse, error) {
+func (api *oliveTinAPI) LocalUserLogin(ctx ctx.Context, req *apiv1.LocalUserLoginRequest) (*apiv1.LocalUserLoginResponse, error) {
 	match := checkUserPassword(cfg, req.Username, req.Password)
 
 	if match {
@@ -124,12 +124,12 @@ func (api *oliveTinAPI) LocalUserLogin(ctx ctx.Context, req *pb.LocalUserLoginRe
 		}).Warn("LocalUserLogin: User login failed.")
 	}
 
-	return &pb.LocalUserLoginResponse{
+	return &apiv1.LocalUserLoginResponse{
 		Success: match,
 	}, nil
 }
 
-func (api *oliveTinAPI) StartActionAndWait(ctx ctx.Context, req *pb.StartActionAndWaitRequest) (*pb.StartActionAndWaitResponse, error) {
+func (api *oliveTinAPI) StartActionAndWait(ctx ctx.Context, req *apiv1.StartActionAndWaitRequest) (*apiv1.StartActionAndWaitResponse, error) {
 	args := make(map[string]string)
 
 	for _, arg := range req.Arguments {
@@ -150,7 +150,7 @@ func (api *oliveTinAPI) StartActionAndWait(ctx ctx.Context, req *pb.StartActionA
 	internalLogEntry, ok := api.executor.GetLog(execReq.TrackingID)
 
 	if ok {
-		return &pb.StartActionAndWaitResponse{
+		return &apiv1.StartActionAndWaitResponse{
 			LogEntry: internalLogEntryToPb(internalLogEntry),
 		}, nil
 	} else {
@@ -158,7 +158,7 @@ func (api *oliveTinAPI) StartActionAndWait(ctx ctx.Context, req *pb.StartActionA
 	}
 }
 
-func (api *oliveTinAPI) StartActionByGet(ctx ctx.Context, req *pb.StartActionByGetRequest) (*pb.StartActionByGetResponse, error) {
+func (api *oliveTinAPI) StartActionByGet(ctx ctx.Context, req *apiv1.StartActionByGetRequest) (*apiv1.StartActionByGetResponse, error) {
 	args := make(map[string]string)
 
 	execReq := executor.ExecutionRequest{
@@ -171,12 +171,12 @@ func (api *oliveTinAPI) StartActionByGet(ctx ctx.Context, req *pb.StartActionByG
 
 	_, uniqueTrackingId := api.executor.ExecRequest(&execReq)
 
-	return &pb.StartActionByGetResponse{
+	return &apiv1.StartActionByGetResponse{
 		ExecutionTrackingId: uniqueTrackingId,
 	}, nil
 }
 
-func (api *oliveTinAPI) StartActionByGetAndWait(ctx ctx.Context, req *pb.StartActionByGetAndWaitRequest) (*pb.StartActionByGetAndWaitResponse, error) {
+func (api *oliveTinAPI) StartActionByGetAndWait(ctx ctx.Context, req *apiv1.StartActionByGetAndWaitRequest) (*apiv1.StartActionByGetAndWaitResponse, error) {
 	args := make(map[string]string)
 
 	execReq := executor.ExecutionRequest{
@@ -193,7 +193,7 @@ func (api *oliveTinAPI) StartActionByGetAndWait(ctx ctx.Context, req *pb.StartAc
 	internalLogEntry, ok := api.executor.GetLog(execReq.TrackingID)
 
 	if ok {
-		return &pb.StartActionByGetAndWaitResponse{
+		return &apiv1.StartActionByGetAndWaitResponse{
 			LogEntry: internalLogEntryToPb(internalLogEntry),
 		}, nil
 	} else {
@@ -201,8 +201,8 @@ func (api *oliveTinAPI) StartActionByGetAndWait(ctx ctx.Context, req *pb.StartAc
 	}
 }
 
-func internalLogEntryToPb(logEntry *executor.InternalLogEntry) *pb.LogEntry {
-	return &pb.LogEntry{
+func internalLogEntryToPb(logEntry *executor.InternalLogEntry) *apiv1.LogEntry {
+	return &apiv1.LogEntry{
 		ActionTitle:         logEntry.ActionTitle,
 		ActionIcon:          logEntry.ActionIcon,
 		ActionId:            logEntry.ActionId,
@@ -246,8 +246,8 @@ func getMostRecentExecutionStatusById(api *oliveTinAPI, actionId string) *execut
 	return ile
 }
 
-func (api *oliveTinAPI) ExecutionStatus(ctx ctx.Context, req *pb.ExecutionStatusRequest) (*pb.ExecutionStatusResponse, error) {
-	res := &pb.ExecutionStatusResponse{}
+func (api *oliveTinAPI) ExecutionStatus(ctx ctx.Context, req *apiv1.ExecutionStatusRequest) (*apiv1.ExecutionStatusResponse, error) {
+	res := &apiv1.ExecutionStatusResponse{}
 
 	var ile *executor.InternalLogEntry
 
@@ -268,7 +268,7 @@ func (api *oliveTinAPI) ExecutionStatus(ctx ctx.Context, req *pb.ExecutionStatus
 }
 
 /**
-func (api *oliveTinAPI) WatchExecution(req *pb.WatchExecutionRequest, srv pb.OliveTinApi_WatchExecutionServer) error {
+func (api *oliveTinAPI) WatchExecution(req *apiv1.WatchExecutionRequest, srv apiv1.OliveTinApi_WatchExecutionServer) error {
 	log.Infof("Watch")
 
 	if logEntry, ok := api.executor.Logs[req.ExecutionUuid]; !ok {
@@ -284,7 +284,7 @@ func (api *oliveTinAPI) WatchExecution(req *pb.WatchExecutionRequest, srv pb.Oli
 
 				log.Infof("%v %v", red, err)
 
-				srv.Send(&pb.WatchExecutionUpdate{
+				srv.Send(&apiv1.WatchExecutionUpdate{
 					Update: string(tmp),
 				})
 			}
@@ -295,7 +295,7 @@ func (api *oliveTinAPI) WatchExecution(req *pb.WatchExecutionRequest, srv pb.Oli
 }
 */
 
-func (api *oliveTinAPI) Logout(ctx ctx.Context, req *pb.LogoutRequest) (*httpbody.HttpBody, error) {
+func (api *oliveTinAPI) Logout(ctx ctx.Context, req *apiv1.LogoutRequest) (*httpbody.HttpBody, error) {
 	user := acl.UserFromContext(ctx, cfg)
 
 	grpc.SendHeader(ctx, metadata.Pairs("logout-provider", user.Provider))
@@ -304,7 +304,7 @@ func (api *oliveTinAPI) Logout(ctx ctx.Context, req *pb.LogoutRequest) (*httpbod
 	return nil, nil
 }
 
-func (api *oliveTinAPI) GetDashboardComponents(ctx ctx.Context, req *pb.GetDashboardComponentsRequest) (*pb.GetDashboardComponentsResponse, error) {
+func (api *oliveTinAPI) GetDashboardComponents(ctx ctx.Context, req *apiv1.GetDashboardComponentsRequest) (*apiv1.GetDashboardComponentsResponse, error) {
 	user := acl.UserFromContext(ctx, cfg)
 
 	if user.IsGuest() && cfg.AuthRequireGuestsToLogin {
@@ -330,10 +330,10 @@ func (api *oliveTinAPI) GetDashboardComponents(ctx ctx.Context, req *pb.GetDashb
 	return res, nil
 }
 
-func (api *oliveTinAPI) GetLogs(ctx ctx.Context, req *pb.GetLogsRequest) (*pb.GetLogsResponse, error) {
+func (api *oliveTinAPI) GetLogs(ctx ctx.Context, req *apiv1.GetLogsRequest) (*apiv1.GetLogsResponse, error) {
 	user := acl.UserFromContext(ctx, cfg)
 
-	ret := &pb.GetLogsResponse{}
+	ret := &apiv1.GetLogsResponse{}
 
 	logEntries, countRemaining := api.executor.GetLogTrackingIds(req.StartOffset, cfg.LogHistoryPageSize)
 
@@ -358,7 +358,7 @@ This function is ONLY a helper for the UI - the arguments are validated properly
 on the StartAction -> Executor chain. This is here basically to provide helpful
 error messages more quickly before starting the action.
 */
-func (api *oliveTinAPI) ValidateArgumentType(ctx ctx.Context, req *pb.ValidateArgumentTypeRequest) (*pb.ValidateArgumentTypeResponse, error) {
+func (api *oliveTinAPI) ValidateArgumentType(ctx ctx.Context, req *apiv1.ValidateArgumentTypeRequest) (*apiv1.ValidateArgumentTypeResponse, error) {
 	err := executor.TypeSafetyCheck("", req.Value, req.Type)
 	desc := ""
 
@@ -366,16 +366,16 @@ func (api *oliveTinAPI) ValidateArgumentType(ctx ctx.Context, req *pb.ValidateAr
 		desc = err.Error()
 	}
 
-	return &pb.ValidateArgumentTypeResponse{
+	return &apiv1.ValidateArgumentTypeResponse{
 		Valid:       err == nil,
 		Description: desc,
 	}, nil
 }
 
-func (api *oliveTinAPI) WhoAmI(ctx ctx.Context, req *pb.WhoAmIRequest) (*pb.WhoAmIResponse, error) {
+func (api *oliveTinAPI) WhoAmI(ctx ctx.Context, req *apiv1.WhoAmIRequest) (*apiv1.WhoAmIResponse, error) {
 	user := acl.UserFromContext(ctx, cfg)
 
-	res := &pb.WhoAmIResponse{
+	res := &apiv1.WhoAmIResponse{
 		AuthenticatedUser: user.Username,
 		Usergroup:         user.Usergroup,
 		Provider:          user.Provider,
@@ -388,7 +388,7 @@ func (api *oliveTinAPI) WhoAmI(ctx ctx.Context, req *pb.WhoAmIRequest) (*pb.WhoA
 	return res, nil
 }
 
-func (api *oliveTinAPI) SosReport(ctx ctx.Context, req *pb.SosReportRequest) (*httpbody.HttpBody, error) {
+func (api *oliveTinAPI) SosReport(ctx ctx.Context, req *apiv1.SosReportRequest) (*httpbody.HttpBody, error) {
 	sos := installationinfo.GetSosReport()
 
 	if !cfg.InsecureAllowDumpSos {
@@ -404,8 +404,8 @@ func (api *oliveTinAPI) SosReport(ctx ctx.Context, req *pb.SosReportRequest) (*h
 	return ret, nil
 }
 
-func (api *oliveTinAPI) DumpVars(ctx ctx.Context, req *pb.DumpVarsRequest) (*pb.DumpVarsResponse, error) {
-	res := &pb.DumpVarsResponse{}
+func (api *oliveTinAPI) DumpVars(ctx ctx.Context, req *apiv1.DumpVarsRequest) (*apiv1.DumpVarsResponse, error) {
+	res := &apiv1.DumpVarsResponse{}
 
 	if !cfg.InsecureAllowDumpVars {
 		res.Alert = "Dumping variables is not allowed by default because it is insecure."
@@ -419,9 +419,9 @@ func (api *oliveTinAPI) DumpVars(ctx ctx.Context, req *pb.DumpVarsRequest) (*pb.
 	return res, nil
 }
 
-func (api *oliveTinAPI) DumpPublicIdActionMap(ctx ctx.Context, req *pb.DumpPublicIdActionMapRequest) (*pb.DumpPublicIdActionMapResponse, error) {
-	res := &pb.DumpPublicIdActionMapResponse{}
-	res.Contents = make(map[string]*pb.ActionEntityPair)
+func (api *oliveTinAPI) DumpPublicIdActionMap(ctx ctx.Context, req *apiv1.DumpPublicIdActionMapRequest) (*apiv1.DumpPublicIdActionMapResponse, error) {
+	res := &apiv1.DumpPublicIdActionMapResponse{}
+	res.Contents = make(map[string]*apiv1.ActionEntityPair)
 
 	if !cfg.InsecureAllowDumpActionMap {
 		res.Alert = "Dumping Public IDs is disallowed."
@@ -432,7 +432,7 @@ func (api *oliveTinAPI) DumpPublicIdActionMap(ctx ctx.Context, req *pb.DumpPubli
 	api.executor.MapActionIdToBindingLock.RLock()
 
 	for k, v := range api.executor.MapActionIdToBinding {
-		res.Contents[k] = &pb.ActionEntityPair{
+		res.Contents[k] = &apiv1.ActionEntityPair{
 			ActionTitle:  v.Action.Title,
 			EntityPrefix: v.EntityPrefix,
 		}
@@ -445,8 +445,8 @@ func (api *oliveTinAPI) DumpPublicIdActionMap(ctx ctx.Context, req *pb.DumpPubli
 	return res, nil
 }
 
-func (api *oliveTinAPI) GetReadyz(ctx ctx.Context, req *pb.GetReadyzRequest) (*pb.GetReadyzResponse, error) {
-	res := &pb.GetReadyzResponse{
+func (api *oliveTinAPI) GetReadyz(ctx ctx.Context, req *apiv1.GetReadyzRequest) (*apiv1.GetReadyzResponse, error) {
+	res := &apiv1.GetReadyzResponse{
 		Status: "OK",
 	}
 
@@ -468,7 +468,7 @@ func Start(globalConfig *config.Config, ex *executor.Executor) {
 	}
 
 	grpcServer := grpc.NewServer()
-	pb.RegisterOliveTinApiServiceServer(grpcServer, newServer(ex))
+	apiv1.RegisterOliveTinApiServiceServer(grpcServer, newServer(ex))
 
 	err = grpcServer.Serve(lis)
 

+ 13 - 13
internal/grpcapi/grpcApiActions.go

@@ -1,7 +1,7 @@
 package grpcapi
 
 import (
-	pb "github.com/OliveTin/OliveTin/gen/grpc"
+	apiv1 "github.com/OliveTin/OliveTin/gen/grpc/olivetin/api/v1"
 	acl "github.com/OliveTin/OliveTin/internal/acl"
 	config "github.com/OliveTin/OliveTin/internal/config"
 	executor "github.com/OliveTin/OliveTin/internal/executor"
@@ -9,8 +9,8 @@ import (
 	"sort"
 )
 
-func buildDashboardResponse(ex *executor.Executor, cfg *config.Config, user *acl.AuthenticatedUser) *pb.GetDashboardComponentsResponse {
-	res := &pb.GetDashboardComponentsResponse{
+func buildDashboardResponse(ex *executor.Executor, cfg *config.Config, user *acl.AuthenticatedUser) *apiv1.GetDashboardComponentsResponse {
+	res := &apiv1.GetDashboardComponentsResponse{
 		AuthenticatedUser:         user.Username,
 		AuthenticatedUserProvider: user.Provider,
 	}
@@ -38,10 +38,10 @@ func buildDashboardResponse(ex *executor.Executor, cfg *config.Config, user *acl
 	return res
 }
 
-func buildAction(actionId string, actionBinding *executor.ActionBinding, user *acl.AuthenticatedUser) *pb.Action {
+func buildAction(actionId string, actionBinding *executor.ActionBinding, user *acl.AuthenticatedUser) *apiv1.Action {
 	action := actionBinding.Action
 
-	btn := pb.Action{
+	btn := apiv1.Action{
 		Id:           actionId,
 		Title:        sv.ReplaceEntityVars(actionBinding.EntityPrefix, action.Title),
 		Icon:         action.Icon,
@@ -51,7 +51,7 @@ func buildAction(actionId string, actionBinding *executor.ActionBinding, user *a
 	}
 
 	for _, cfgArg := range action.Arguments {
-		pbArg := pb.ActionArgument{
+		pbArg := apiv1.ActionArgument{
 			Name:         cfgArg.Name,
 			Title:        cfgArg.Title,
 			Type:         cfgArg.Type,
@@ -67,7 +67,7 @@ func buildAction(actionId string, actionBinding *executor.ActionBinding, user *a
 	return &btn
 }
 
-func buildChoices(arg config.ActionArgument) []*pb.ActionArgumentChoice {
+func buildChoices(arg config.ActionArgument) []*apiv1.ActionArgumentChoice {
 	if arg.Entity != "" && len(arg.Choices) == 1 {
 		return buildChoicesEntity(arg.Choices[0], arg.Entity)
 	} else {
@@ -75,15 +75,15 @@ func buildChoices(arg config.ActionArgument) []*pb.ActionArgumentChoice {
 	}
 }
 
-func buildChoicesEntity(firstChoice config.ActionArgumentChoice, entityTitle string) []*pb.ActionArgumentChoice {
-	ret := []*pb.ActionArgumentChoice{}
+func buildChoicesEntity(firstChoice config.ActionArgumentChoice, entityTitle string) []*apiv1.ActionArgumentChoice {
+	ret := []*apiv1.ActionArgumentChoice{}
 
 	entityCount := sv.GetEntityCount(entityTitle)
 
 	for i := 0; i < entityCount; i++ {
 		prefix := sv.GetEntityPrefix(entityTitle, i)
 
-		ret = append(ret, &pb.ActionArgumentChoice{
+		ret = append(ret, &apiv1.ActionArgumentChoice{
 			Value: sv.ReplaceEntityVars(prefix, firstChoice.Value),
 			Title: sv.ReplaceEntityVars(prefix, firstChoice.Title),
 		})
@@ -92,11 +92,11 @@ func buildChoicesEntity(firstChoice config.ActionArgumentChoice, entityTitle str
 	return ret
 }
 
-func buildChoicesSimple(choices []config.ActionArgumentChoice) []*pb.ActionArgumentChoice {
-	ret := []*pb.ActionArgumentChoice{}
+func buildChoicesSimple(choices []config.ActionArgumentChoice) []*apiv1.ActionArgumentChoice {
+	ret := []*apiv1.ActionArgumentChoice{}
 
 	for _, cfgChoice := range choices {
-		pbChoice := pb.ActionArgumentChoice{
+		pbChoice := apiv1.ActionArgumentChoice{
 			Value: cfgChoice.Value,
 			Title: cfgChoice.Title,
 		}

+ 6 - 6
internal/grpcapi/grpcApiDashboard.go

@@ -1,14 +1,14 @@
 package grpcapi
 
 import (
-	pb "github.com/OliveTin/OliveTin/gen/grpc"
+	apiv1 "github.com/OliveTin/OliveTin/gen/grpc/olivetin/api/v1"
 	config "github.com/OliveTin/OliveTin/internal/config"
 	"golang.org/x/exp/slices"
 )
 
-func dashboardCfgToPb(res *pb.GetDashboardComponentsResponse, dashboards []*config.DashboardComponent, cfg *config.Config) {
+func dashboardCfgToPb(res *apiv1.GetDashboardComponentsResponse, dashboards []*config.DashboardComponent, cfg *config.Config) {
 	for _, dashboard := range dashboards {
-		res.Dashboards = append(res.Dashboards, &pb.DashboardComponent{
+		res.Dashboards = append(res.Dashboards, &apiv1.DashboardComponent{
 			Type:     "dashboard",
 			Title:    dashboard.Title,
 			Contents: getDashboardComponentContents(dashboard, cfg),
@@ -16,8 +16,8 @@ func dashboardCfgToPb(res *pb.GetDashboardComponentsResponse, dashboards []*conf
 	}
 }
 
-func getDashboardComponentContents(dashboard *config.DashboardComponent, cfg *config.Config) []*pb.DashboardComponent {
-	ret := make([]*pb.DashboardComponent, 0)
+func getDashboardComponentContents(dashboard *config.DashboardComponent, cfg *config.Config) []*apiv1.DashboardComponent {
+	ret := make([]*apiv1.DashboardComponent, 0)
 
 	for _, subitem := range dashboard.Contents {
 		if subitem.Type == "fieldset" && subitem.Entity != "" {
@@ -25,7 +25,7 @@ func getDashboardComponentContents(dashboard *config.DashboardComponent, cfg *co
 			continue
 		}
 
-		newitem := &pb.DashboardComponent{
+		newitem := &apiv1.DashboardComponent{
 			Title:    subitem.Title,
 			Type:     getDashboardComponentType(&subitem),
 			Contents: getDashboardComponentContents(&subitem, cfg),

+ 8 - 8
internal/grpcapi/grpcApiDashboardEntities.go

@@ -1,13 +1,13 @@
 package grpcapi
 
 import (
-	pb "github.com/OliveTin/OliveTin/gen/grpc"
+	apiv1 "github.com/OliveTin/OliveTin/gen/grpc/olivetin/api/v1"
 	config "github.com/OliveTin/OliveTin/internal/config"
 	sv "github.com/OliveTin/OliveTin/internal/stringvariables"
 )
 
-func buildEntityFieldsets(entityTitle string, tpl *config.DashboardComponent) []*pb.DashboardComponent {
-	ret := make([]*pb.DashboardComponent, 0)
+func buildEntityFieldsets(entityTitle string, tpl *config.DashboardComponent) []*apiv1.DashboardComponent {
+	ret := make([]*apiv1.DashboardComponent, 0)
 
 	entityCount := sv.GetEntityCount(entityTitle)
 
@@ -18,10 +18,10 @@ func buildEntityFieldsets(entityTitle string, tpl *config.DashboardComponent) []
 	return ret
 }
 
-func buildEntityFieldset(tpl *config.DashboardComponent, entityTitle string, entityIndex int) *pb.DashboardComponent {
+func buildEntityFieldset(tpl *config.DashboardComponent, entityTitle string, entityIndex int) *apiv1.DashboardComponent {
 	prefix := sv.GetEntityPrefix(entityTitle, entityIndex)
 
-	return &pb.DashboardComponent{
+	return &apiv1.DashboardComponent{
 		Title:    sv.ReplaceEntityVars(prefix, tpl.Title),
 		Type:     "fieldset",
 		Contents: buildEntityFieldsetContents(tpl.Contents, prefix),
@@ -29,11 +29,11 @@ func buildEntityFieldset(tpl *config.DashboardComponent, entityTitle string, ent
 	}
 }
 
-func buildEntityFieldsetContents(contents []config.DashboardComponent, prefix string) []*pb.DashboardComponent {
-	ret := make([]*pb.DashboardComponent, 0)
+func buildEntityFieldsetContents(contents []config.DashboardComponent, prefix string) []*apiv1.DashboardComponent {
+	ret := make([]*apiv1.DashboardComponent, 0)
 
 	for _, subitem := range contents {
-		clone := &pb.DashboardComponent{}
+		clone := &apiv1.DashboardComponent{}
 		clone.CssClass = sv.ReplaceEntityVars(prefix, subitem.CssClass)
 
 		if subitem.Type == "" || subitem.Type == "link" {

+ 6 - 6
internal/grpcapi/grpcApi_test.go

@@ -12,7 +12,7 @@ import (
 
 	log "github.com/sirupsen/logrus"
 
-	pb "github.com/OliveTin/OliveTin/gen/grpc"
+	apiv1 "github.com/OliveTin/OliveTin/gen/grpc/olivetin/api/v1"
 	config "github.com/OliveTin/OliveTin/internal/config"
 	"github.com/OliveTin/OliveTin/internal/executor"
 )
@@ -26,7 +26,7 @@ func initServer(cfg *config.Config) *executor.Executor {
 
 	lis = bufconn.Listen(bufSize)
 	s := grpc.NewServer()
-	pb.RegisterOliveTinApiServiceServer(s, newServer(ex))
+	apiv1.RegisterOliveTinApiServiceServer(s, newServer(ex))
 
 	go func() {
 		if err := s.Serve(lis); err != nil {
@@ -41,7 +41,7 @@ func bufDialer(context.Context, string) (net.Conn, error) {
 	return lis.Dial()
 }
 
-func getNewTestServerAndClient(t *testing.T, injectedConfig *config.Config) (*grpc.ClientConn, pb.OliveTinApiServiceClient) {
+func getNewTestServerAndClient(t *testing.T, injectedConfig *config.Config) (*grpc.ClientConn, apiv1.OliveTinApiServiceClient) {
 	cfg = injectedConfig
 
 	ctx := context.Background()
@@ -52,7 +52,7 @@ func getNewTestServerAndClient(t *testing.T, injectedConfig *config.Config) (*gr
 		t.Fatalf("Failed to dial bufnet: %v", err)
 	}
 
-	client := pb.NewOliveTinApiServiceClient(conn)
+	client := apiv1.NewOliveTinApiServiceClient(conn)
 
 	return conn, client
 }
@@ -72,7 +72,7 @@ func TestGetActionsAndStart(t *testing.T) {
 
 	conn, client := getNewTestServerAndClient(t, cfg)
 
-	respGb, err := client.GetDashboardComponents(context.Background(), &pb.GetDashboardComponentsRequest{})
+	respGb, err := client.GetDashboardComponents(context.Background(), &apiv1.GetDashboardComponentsRequest{})
 
 	if err != nil {
 		t.Errorf("GetDashboardComponentsRequest: %v", err)
@@ -84,7 +84,7 @@ func TestGetActionsAndStart(t *testing.T) {
 
 	log.Printf("Response: %+v", respGb)
 
-	respSa, err := client.StartAction(context.Background(), &pb.StartActionRequest{ActionId: "blat"})
+	respSa, err := client.StartAction(context.Background(), &apiv1.StartActionRequest{ActionId: "blat"})
 
 	assert.Nil(t, err, "Empty err after start action")
 	assert.NotNil(t, respSa, "Empty err after start action")

+ 2 - 2
internal/httpservers/restapi.go

@@ -10,7 +10,7 @@ import (
 	"google.golang.org/protobuf/reflect/protoreflect"
 	"net/http"
 
-	gw "github.com/OliveTin/OliveTin/gen/grpc"
+	apiv1 "github.com/OliveTin/OliveTin/gen/grpc/olivetin/api/v1"
 
 	config "github.com/OliveTin/OliveTin/internal/config"
 	cors "github.com/OliveTin/OliveTin/internal/cors"
@@ -181,7 +181,7 @@ func newMux() *runtime.ServeMux {
 
 	opts := []grpc.DialOption{grpc.WithInsecure()}
 
-	err := gw.RegisterOliveTinApiServiceHandlerFromEndpoint(ctx, mux, cfg.ListenAddressGrpcActions, opts)
+	err := apiv1.RegisterOliveTinApiServiceHandlerFromEndpoint(ctx, mux, cfg.ListenAddressGrpcActions, opts)
 
 	if err != nil {
 		log.Panicf("Could not register REST API Handler %v", err)

+ 8 - 8
internal/websocket/websocket.go

@@ -4,7 +4,7 @@ import (
 	"net/http"
 	"sync"
 
-	pb "github.com/OliveTin/OliveTin/gen/grpc"
+	apiv1 "github.com/OliveTin/OliveTin/gen/grpc/olivetin/api/v1"
 	"github.com/OliveTin/OliveTin/internal/executor"
 	ws "github.com/gorilla/websocket"
 	log "github.com/sirupsen/logrus"
@@ -36,17 +36,17 @@ var ExecutionListener WebsocketExecutionListener
 type WebsocketExecutionListener struct{}
 
 func (WebsocketExecutionListener) OnExecutionStarted(ile *executor.InternalLogEntry) {
-	broadcast(&pb.EventExecutionStarted{
+	broadcast(&apiv1.EventExecutionStarted{
 		LogEntry: internalLogEntryToPb(ile),
 	})
 }
 
 func OnEntityChanged() {
-	broadcast(&pb.EventEntityChanged{})
+	broadcast(&apiv1.EventEntityChanged{})
 }
 
 func (WebsocketExecutionListener) OnActionMapRebuilt() {
-	broadcast(&pb.EventConfigChanged{})
+	broadcast(&apiv1.EventConfigChanged{})
 }
 
 /*
@@ -69,7 +69,7 @@ func checkOriginPermissive(r *http.Request) bool {
 func (WebsocketExecutionListener) OnOutputChunk(chunk []byte, executionTrackingId string) {
 	log.Tracef("outputchunk: %s", string(chunk))
 
-	oc := &pb.EventOutputChunk{
+	oc := &apiv1.EventOutputChunk{
 		Output:              string(chunk),
 		ExecutionTrackingId: executionTrackingId,
 	}
@@ -78,7 +78,7 @@ func (WebsocketExecutionListener) OnOutputChunk(chunk []byte, executionTrackingI
 }
 
 func (WebsocketExecutionListener) OnExecutionFinished(logEntry *executor.InternalLogEntry) {
-	evt := &pb.EventExecutionFinished{
+	evt := &apiv1.EventExecutionFinished{
 		LogEntry: internalLogEntryToPb(logEntry),
 	}
 
@@ -161,8 +161,8 @@ func HandleWebsocket(w http.ResponseWriter, r *http.Request) bool {
 	return true
 }
 
-func internalLogEntryToPb(logEntry *executor.InternalLogEntry) *pb.LogEntry {
-	return &pb.LogEntry{
+func internalLogEntryToPb(logEntry *executor.InternalLogEntry) *apiv1.LogEntry {
+	return &apiv1.LogEntry{
 		ActionTitle:         logEntry.ActionTitle,
 		ActionIcon:          logEntry.ActionIcon,
 		ActionId:            logEntry.ActionId,

+ 4 - 0
proto/Makefile

@@ -0,0 +1,4 @@
+buf:
+	buf generate
+
+.PHONY: buf

+ 3 - 3
buf.gen.yaml → proto/buf.gen.yaml

@@ -1,15 +1,15 @@
 version: v1
 plugins:
   - name: go
-    out: gen/grpc/
+    out: ../gen/grpc/
     opt: paths=source_relative
 
   - name: go-grpc
-    out: gen/grpc/
+    out: ../gen/grpc/
     opt: paths=source_relative,require_unimplemented_servers=false
 
   - name: grpc-gateway
-    out: gen/grpc/
+    out: ../gen/grpc/
     opt: paths=source_relative
 
 #  - name: swagger

+ 6 - 0
proto/buf.lock

@@ -0,0 +1,6 @@
+# Generated by buf. DO NOT EDIT.
+version: v2
+deps:
+  - name: buf.build/googleapis/googleapis
+    commit: 751cbe31638d43a9bfb6162cd2352e67
+    digest: b5:51ba5c31f244fd74420f0e66d13f2b5dd6024dcfe1a29dc45bd8f6e61c1444c828b9add9e7dd25a4513ebbee8097a970e0712a2e2cd955c2d60cf8905204f51a

+ 2 - 3
buf.yaml → proto/buf.yaml

@@ -1,10 +1,9 @@
-version: v1
+version: v2
 deps:
   - buf.build/googleapis/googleapis
 lint:
   use:
-    - DEFAULT
-build:
+    - STANDARD
 breaking:
   use:
     - FILE

+ 3 - 1
OliveTin.proto → proto/olivetin/api/v1/olivetin.proto

@@ -1,6 +1,8 @@
 syntax = "proto3";
 
-option go_package = "gen/grpc";
+package olivetin.api.v1;
+
+option go_package = "github.com/jamesread/OliveTin/gen/grpc/olivetin/api/v1;apiv1";
 
 import "google/api/annotations.proto";
 import "google/api/httpbody.proto";

+ 1 - 0
webui.dev/js/websocket.js

@@ -46,6 +46,7 @@ function websocketOnOpen (evt) {
 function websocketOnMessage (msg) {
   // FIXME check msg status is OK
   const j = JSON.parse(msg.data)
+  j.type = j.type.replace('olivetin.api.v1.', '')
 
   const e = new Event(j.type)
   e.payload = j.payload

Unele fișiere nu au fost afișate deoarece prea multe fișiere au fost modificate în acest diff