Agent check gRPC version against server (#1653)

close #1114

As long as the `VersionResponse` type is not changed the check will
fail/pass gracefully

example output:
```
{"level":"error","error":"GRPC version mismatch","time":"2023-03-19T19:49:09+01:00","message":"Server version next-6923e7ab does report grpc version 2 but we only understand 1"}
GRPC version mismatch
```
This commit is contained in:
6543 2023-03-19 22:42:21 +01:00 committed by GitHub
parent f582ad3159
commit 92614dfb1e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 632 additions and 353 deletions

View file

@ -1,3 +1,17 @@
// Copyright 2023 Woodpecker Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package rpc
import (
@ -18,6 +32,9 @@ import (
var backoff = time.Second
// set grpc version on compile time to compare against server version response
const ClientGrpcVersion int32 = proto.Version
type client struct {
client proto.WoodpeckerClient
conn *grpc.ClientConn
@ -35,9 +52,21 @@ func (c *client) Close() error {
return c.conn.Close()
}
// Version returns the server- & grpc-version
func (c *client) Version(ctx context.Context) (*rpc.Version, error) {
res, err := c.client.Version(ctx, &proto.Empty{})
if err != nil {
return nil, err
}
return &rpc.Version{
GrpcVersion: res.GrpcVersion,
ServerVersion: res.ServerVersion,
}, nil
}
// Next returns the next pipeline in the queue.
func (c *client) Next(ctx context.Context, f rpc.Filter) (*rpc.Pipeline, error) {
var res *proto.NextReply
var res *proto.NextResponse
var err error
req := new(proto.NextRequest)
req.Filter = new(proto.Filter)

View file

@ -1,3 +1,4 @@
// Copyright 2023 Woodpecker Authors
// Copyright 2018 Drone.IO Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
@ -17,6 +18,7 @@ package main
import (
"context"
"crypto/tls"
"errors"
"net/http"
"os"
"runtime"
@ -154,6 +156,21 @@ func loop(c *cli.Context) error {
sigterm.Set()
})
// check if grpc server version is compatible with agent
grpcServerVersion, err := client.Version(ctx)
if err != nil {
log.Error().Err(err).Msg("could not get grpc server version")
return err
}
if grpcServerVersion.GrpcVersion != agentRpc.ClientGrpcVersion {
err := errors.New("GRPC version mismatch")
log.Error().Err(err).Msgf("Server version %s does report grpc version %d but we only understand %d",
grpcServerVersion.ServerVersion,
grpcServerVersion.GrpcVersion,
agentRpc.ClientGrpcVersion)
return err
}
backendCtx := context.WithValue(ctx, types.CliContext, c)
backend.Init(backendCtx)

View file

@ -1 +0,0 @@
package pipeline

View file

@ -1,3 +1,18 @@
// Copyright 2022 Woodpecker Authors
// Copyright 2011 Drone.IO Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package rpc
import (

View file

@ -1,3 +1,17 @@
// Copyright 2019 Woodpecker Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package rpc
import (

View file

@ -1,3 +1,18 @@
// Copyright 2021 Woodpecker Authors
// Copyright 2011 Drone.IO Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package rpc
import (
@ -39,10 +54,18 @@ type (
Data []byte `json:"data"`
Meta map[string]string `json:"meta"`
}
Version struct {
GrpcVersion int32 `json:"grpc_version,omitempty"`
ServerVersion string `json:"server_version,omitempty"`
}
)
// Peer defines a peer-to-peer connection.
type Peer interface {
// Version returns the server- & grpc-version
Version(c context.Context) (*Version, error)
// Next returns the next pipeline in the queue.
Next(c context.Context, f Filter) (*Pipeline, error)

View file

@ -0,0 +1,19 @@
// Copyright 2023 Woodpecker Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package proto
// Version is the version of the woodpecker.proto file,
// !IMPORTANT! increased by 1 each time it get changed !IMPORTANT!
const Version int32 = 1

File diff suppressed because it is too large Load diff

View file

@ -1,10 +1,31 @@
// Copyright 2021 Woodpecker Authors
// Copyright 2011 Drone.IO Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
syntax = "proto3";
option go_package = "github.com/woodpecker-ci/woodpecker/pipeline/rpc/proto";
package proto;
// !IMPORTANT!
// Increased Version in version.go by 1 if you change something here!
// !IMPORTANT!
// Woodpecker Server Service
service Woodpecker {
rpc Next (NextRequest) returns (NextReply) {}
rpc Version (Empty) returns (VersionResponse) {}
rpc Next (NextRequest) returns (NextResponse) {}
rpc Init (InitRequest) returns (Empty) {}
rpc Wait (WaitRequest) returns (Empty) {}
rpc Done (DoneRequest) returns (Empty) {}
@ -16,6 +37,10 @@ service Woodpecker {
rpc ReportHealth (ReportHealthRequest) returns (Empty) {}
}
//
// Basic Types
//
message File {
string name = 1;
string step = 2;
@ -52,14 +77,14 @@ message Pipeline {
bytes payload = 3;
}
//
// Request types
//
message NextRequest {
Filter filter = 1;
}
message NextReply {
Pipeline pipeline = 1;
}
message InitRequest {
string id = 1;
State state = 2;
@ -107,6 +132,19 @@ message RegisterAgentRequest {
string version = 4;
}
//
// Response types
//
message VersionResponse {
int32 grpc_version = 1;
string server_version = 2;
}
message NextResponse {
Pipeline pipeline = 1;
}
message RegisterAgentResponse {
int64 agent_id = 1;
}
@ -114,7 +152,7 @@ message RegisterAgentResponse {
// Woodpecker auth service is a simple service to authenticate agents and aquire a token
service WoodpeckerAuth {
rpc Auth (AuthRequest) returns (AuthReply) {}
rpc Auth (AuthRequest) returns (AuthResponse) {}
}
message AuthRequest {
@ -122,7 +160,7 @@ message AuthRequest {
int64 agent_id = 2;
}
message AuthReply {
message AuthResponse {
string status = 1;
int64 agent_id = 2;
string access_token = 3;

View file

@ -1,6 +1,6 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.3.0
// - protoc-gen-go-grpc v1.2.0
// - protoc v3.21.12
// source: woodpecker.proto
@ -8,7 +8,6 @@ package proto
import (
context "context"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
@ -19,24 +18,12 @@ import (
// Requires gRPC-Go v1.32.0 or later.
const _ = grpc.SupportPackageIsVersion7
const (
Woodpecker_Next_FullMethodName = "/proto.Woodpecker/Next"
Woodpecker_Init_FullMethodName = "/proto.Woodpecker/Init"
Woodpecker_Wait_FullMethodName = "/proto.Woodpecker/Wait"
Woodpecker_Done_FullMethodName = "/proto.Woodpecker/Done"
Woodpecker_Extend_FullMethodName = "/proto.Woodpecker/Extend"
Woodpecker_Update_FullMethodName = "/proto.Woodpecker/Update"
Woodpecker_Upload_FullMethodName = "/proto.Woodpecker/Upload"
Woodpecker_Log_FullMethodName = "/proto.Woodpecker/Log"
Woodpecker_RegisterAgent_FullMethodName = "/proto.Woodpecker/RegisterAgent"
Woodpecker_ReportHealth_FullMethodName = "/proto.Woodpecker/ReportHealth"
)
// WoodpeckerClient is the client API for Woodpecker service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
type WoodpeckerClient interface {
Next(ctx context.Context, in *NextRequest, opts ...grpc.CallOption) (*NextReply, error)
Version(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*VersionResponse, error)
Next(ctx context.Context, in *NextRequest, opts ...grpc.CallOption) (*NextResponse, error)
Init(ctx context.Context, in *InitRequest, opts ...grpc.CallOption) (*Empty, error)
Wait(ctx context.Context, in *WaitRequest, opts ...grpc.CallOption) (*Empty, error)
Done(ctx context.Context, in *DoneRequest, opts ...grpc.CallOption) (*Empty, error)
@ -56,9 +43,18 @@ func NewWoodpeckerClient(cc grpc.ClientConnInterface) WoodpeckerClient {
return &woodpeckerClient{cc}
}
func (c *woodpeckerClient) Next(ctx context.Context, in *NextRequest, opts ...grpc.CallOption) (*NextReply, error) {
out := new(NextReply)
err := c.cc.Invoke(ctx, Woodpecker_Next_FullMethodName, in, out, opts...)
func (c *woodpeckerClient) Version(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*VersionResponse, error) {
out := new(VersionResponse)
err := c.cc.Invoke(ctx, "/proto.Woodpecker/Version", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *woodpeckerClient) Next(ctx context.Context, in *NextRequest, opts ...grpc.CallOption) (*NextResponse, error) {
out := new(NextResponse)
err := c.cc.Invoke(ctx, "/proto.Woodpecker/Next", in, out, opts...)
if err != nil {
return nil, err
}
@ -67,7 +63,7 @@ func (c *woodpeckerClient) Next(ctx context.Context, in *NextRequest, opts ...gr
func (c *woodpeckerClient) Init(ctx context.Context, in *InitRequest, opts ...grpc.CallOption) (*Empty, error) {
out := new(Empty)
err := c.cc.Invoke(ctx, Woodpecker_Init_FullMethodName, in, out, opts...)
err := c.cc.Invoke(ctx, "/proto.Woodpecker/Init", in, out, opts...)
if err != nil {
return nil, err
}
@ -76,7 +72,7 @@ func (c *woodpeckerClient) Init(ctx context.Context, in *InitRequest, opts ...gr
func (c *woodpeckerClient) Wait(ctx context.Context, in *WaitRequest, opts ...grpc.CallOption) (*Empty, error) {
out := new(Empty)
err := c.cc.Invoke(ctx, Woodpecker_Wait_FullMethodName, in, out, opts...)
err := c.cc.Invoke(ctx, "/proto.Woodpecker/Wait", in, out, opts...)
if err != nil {
return nil, err
}
@ -85,7 +81,7 @@ func (c *woodpeckerClient) Wait(ctx context.Context, in *WaitRequest, opts ...gr
func (c *woodpeckerClient) Done(ctx context.Context, in *DoneRequest, opts ...grpc.CallOption) (*Empty, error) {
out := new(Empty)
err := c.cc.Invoke(ctx, Woodpecker_Done_FullMethodName, in, out, opts...)
err := c.cc.Invoke(ctx, "/proto.Woodpecker/Done", in, out, opts...)
if err != nil {
return nil, err
}
@ -94,7 +90,7 @@ func (c *woodpeckerClient) Done(ctx context.Context, in *DoneRequest, opts ...gr
func (c *woodpeckerClient) Extend(ctx context.Context, in *ExtendRequest, opts ...grpc.CallOption) (*Empty, error) {
out := new(Empty)
err := c.cc.Invoke(ctx, Woodpecker_Extend_FullMethodName, in, out, opts...)
err := c.cc.Invoke(ctx, "/proto.Woodpecker/Extend", in, out, opts...)
if err != nil {
return nil, err
}
@ -103,7 +99,7 @@ func (c *woodpeckerClient) Extend(ctx context.Context, in *ExtendRequest, opts .
func (c *woodpeckerClient) Update(ctx context.Context, in *UpdateRequest, opts ...grpc.CallOption) (*Empty, error) {
out := new(Empty)
err := c.cc.Invoke(ctx, Woodpecker_Update_FullMethodName, in, out, opts...)
err := c.cc.Invoke(ctx, "/proto.Woodpecker/Update", in, out, opts...)
if err != nil {
return nil, err
}
@ -112,7 +108,7 @@ func (c *woodpeckerClient) Update(ctx context.Context, in *UpdateRequest, opts .
func (c *woodpeckerClient) Upload(ctx context.Context, in *UploadRequest, opts ...grpc.CallOption) (*Empty, error) {
out := new(Empty)
err := c.cc.Invoke(ctx, Woodpecker_Upload_FullMethodName, in, out, opts...)
err := c.cc.Invoke(ctx, "/proto.Woodpecker/Upload", in, out, opts...)
if err != nil {
return nil, err
}
@ -121,7 +117,7 @@ func (c *woodpeckerClient) Upload(ctx context.Context, in *UploadRequest, opts .
func (c *woodpeckerClient) Log(ctx context.Context, in *LogRequest, opts ...grpc.CallOption) (*Empty, error) {
out := new(Empty)
err := c.cc.Invoke(ctx, Woodpecker_Log_FullMethodName, in, out, opts...)
err := c.cc.Invoke(ctx, "/proto.Woodpecker/Log", in, out, opts...)
if err != nil {
return nil, err
}
@ -130,7 +126,7 @@ func (c *woodpeckerClient) Log(ctx context.Context, in *LogRequest, opts ...grpc
func (c *woodpeckerClient) RegisterAgent(ctx context.Context, in *RegisterAgentRequest, opts ...grpc.CallOption) (*RegisterAgentResponse, error) {
out := new(RegisterAgentResponse)
err := c.cc.Invoke(ctx, Woodpecker_RegisterAgent_FullMethodName, in, out, opts...)
err := c.cc.Invoke(ctx, "/proto.Woodpecker/RegisterAgent", in, out, opts...)
if err != nil {
return nil, err
}
@ -139,7 +135,7 @@ func (c *woodpeckerClient) RegisterAgent(ctx context.Context, in *RegisterAgentR
func (c *woodpeckerClient) ReportHealth(ctx context.Context, in *ReportHealthRequest, opts ...grpc.CallOption) (*Empty, error) {
out := new(Empty)
err := c.cc.Invoke(ctx, Woodpecker_ReportHealth_FullMethodName, in, out, opts...)
err := c.cc.Invoke(ctx, "/proto.Woodpecker/ReportHealth", in, out, opts...)
if err != nil {
return nil, err
}
@ -150,7 +146,8 @@ func (c *woodpeckerClient) ReportHealth(ctx context.Context, in *ReportHealthReq
// All implementations must embed UnimplementedWoodpeckerServer
// for forward compatibility
type WoodpeckerServer interface {
Next(context.Context, *NextRequest) (*NextReply, error)
Version(context.Context, *Empty) (*VersionResponse, error)
Next(context.Context, *NextRequest) (*NextResponse, error)
Init(context.Context, *InitRequest) (*Empty, error)
Wait(context.Context, *WaitRequest) (*Empty, error)
Done(context.Context, *DoneRequest) (*Empty, error)
@ -164,44 +161,39 @@ type WoodpeckerServer interface {
}
// UnimplementedWoodpeckerServer must be embedded to have forward compatible implementations.
type UnimplementedWoodpeckerServer struct{}
func (UnimplementedWoodpeckerServer) Next(context.Context, *NextRequest) (*NextReply, error) {
return nil, status.Errorf(codes.Unimplemented, "method Next not implemented")
type UnimplementedWoodpeckerServer struct {
}
func (UnimplementedWoodpeckerServer) Version(context.Context, *Empty) (*VersionResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method Version not implemented")
}
func (UnimplementedWoodpeckerServer) Next(context.Context, *NextRequest) (*NextResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method Next not implemented")
}
func (UnimplementedWoodpeckerServer) Init(context.Context, *InitRequest) (*Empty, error) {
return nil, status.Errorf(codes.Unimplemented, "method Init not implemented")
}
func (UnimplementedWoodpeckerServer) Wait(context.Context, *WaitRequest) (*Empty, error) {
return nil, status.Errorf(codes.Unimplemented, "method Wait not implemented")
}
func (UnimplementedWoodpeckerServer) Done(context.Context, *DoneRequest) (*Empty, error) {
return nil, status.Errorf(codes.Unimplemented, "method Done not implemented")
}
func (UnimplementedWoodpeckerServer) Extend(context.Context, *ExtendRequest) (*Empty, error) {
return nil, status.Errorf(codes.Unimplemented, "method Extend not implemented")
}
func (UnimplementedWoodpeckerServer) Update(context.Context, *UpdateRequest) (*Empty, error) {
return nil, status.Errorf(codes.Unimplemented, "method Update not implemented")
}
func (UnimplementedWoodpeckerServer) Upload(context.Context, *UploadRequest) (*Empty, error) {
return nil, status.Errorf(codes.Unimplemented, "method Upload not implemented")
}
func (UnimplementedWoodpeckerServer) Log(context.Context, *LogRequest) (*Empty, error) {
return nil, status.Errorf(codes.Unimplemented, "method Log not implemented")
}
func (UnimplementedWoodpeckerServer) RegisterAgent(context.Context, *RegisterAgentRequest) (*RegisterAgentResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method RegisterAgent not implemented")
}
func (UnimplementedWoodpeckerServer) ReportHealth(context.Context, *ReportHealthRequest) (*Empty, error) {
return nil, status.Errorf(codes.Unimplemented, "method ReportHealth not implemented")
}
@ -218,6 +210,24 @@ func RegisterWoodpeckerServer(s grpc.ServiceRegistrar, srv WoodpeckerServer) {
s.RegisterService(&Woodpecker_ServiceDesc, srv)
}
func _Woodpecker_Version_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(Empty)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(WoodpeckerServer).Version(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/proto.Woodpecker/Version",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(WoodpeckerServer).Version(ctx, req.(*Empty))
}
return interceptor(ctx, in, info, handler)
}
func _Woodpecker_Next_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(NextRequest)
if err := dec(in); err != nil {
@ -228,7 +238,7 @@ func _Woodpecker_Next_Handler(srv interface{}, ctx context.Context, dec func(int
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Woodpecker_Next_FullMethodName,
FullMethod: "/proto.Woodpecker/Next",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(WoodpeckerServer).Next(ctx, req.(*NextRequest))
@ -246,7 +256,7 @@ func _Woodpecker_Init_Handler(srv interface{}, ctx context.Context, dec func(int
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Woodpecker_Init_FullMethodName,
FullMethod: "/proto.Woodpecker/Init",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(WoodpeckerServer).Init(ctx, req.(*InitRequest))
@ -264,7 +274,7 @@ func _Woodpecker_Wait_Handler(srv interface{}, ctx context.Context, dec func(int
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Woodpecker_Wait_FullMethodName,
FullMethod: "/proto.Woodpecker/Wait",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(WoodpeckerServer).Wait(ctx, req.(*WaitRequest))
@ -282,7 +292,7 @@ func _Woodpecker_Done_Handler(srv interface{}, ctx context.Context, dec func(int
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Woodpecker_Done_FullMethodName,
FullMethod: "/proto.Woodpecker/Done",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(WoodpeckerServer).Done(ctx, req.(*DoneRequest))
@ -300,7 +310,7 @@ func _Woodpecker_Extend_Handler(srv interface{}, ctx context.Context, dec func(i
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Woodpecker_Extend_FullMethodName,
FullMethod: "/proto.Woodpecker/Extend",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(WoodpeckerServer).Extend(ctx, req.(*ExtendRequest))
@ -318,7 +328,7 @@ func _Woodpecker_Update_Handler(srv interface{}, ctx context.Context, dec func(i
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Woodpecker_Update_FullMethodName,
FullMethod: "/proto.Woodpecker/Update",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(WoodpeckerServer).Update(ctx, req.(*UpdateRequest))
@ -336,7 +346,7 @@ func _Woodpecker_Upload_Handler(srv interface{}, ctx context.Context, dec func(i
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Woodpecker_Upload_FullMethodName,
FullMethod: "/proto.Woodpecker/Upload",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(WoodpeckerServer).Upload(ctx, req.(*UploadRequest))
@ -354,7 +364,7 @@ func _Woodpecker_Log_Handler(srv interface{}, ctx context.Context, dec func(inte
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Woodpecker_Log_FullMethodName,
FullMethod: "/proto.Woodpecker/Log",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(WoodpeckerServer).Log(ctx, req.(*LogRequest))
@ -372,7 +382,7 @@ func _Woodpecker_RegisterAgent_Handler(srv interface{}, ctx context.Context, dec
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Woodpecker_RegisterAgent_FullMethodName,
FullMethod: "/proto.Woodpecker/RegisterAgent",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(WoodpeckerServer).RegisterAgent(ctx, req.(*RegisterAgentRequest))
@ -390,7 +400,7 @@ func _Woodpecker_ReportHealth_Handler(srv interface{}, ctx context.Context, dec
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Woodpecker_ReportHealth_FullMethodName,
FullMethod: "/proto.Woodpecker/ReportHealth",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(WoodpeckerServer).ReportHealth(ctx, req.(*ReportHealthRequest))
@ -405,6 +415,10 @@ var Woodpecker_ServiceDesc = grpc.ServiceDesc{
ServiceName: "proto.Woodpecker",
HandlerType: (*WoodpeckerServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "Version",
Handler: _Woodpecker_Version_Handler,
},
{
MethodName: "Next",
Handler: _Woodpecker_Next_Handler,
@ -450,15 +464,11 @@ var Woodpecker_ServiceDesc = grpc.ServiceDesc{
Metadata: "woodpecker.proto",
}
const (
WoodpeckerAuth_Auth_FullMethodName = "/proto.WoodpeckerAuth/Auth"
)
// WoodpeckerAuthClient is the client API for WoodpeckerAuth service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
type WoodpeckerAuthClient interface {
Auth(ctx context.Context, in *AuthRequest, opts ...grpc.CallOption) (*AuthReply, error)
Auth(ctx context.Context, in *AuthRequest, opts ...grpc.CallOption) (*AuthResponse, error)
}
type woodpeckerAuthClient struct {
@ -469,9 +479,9 @@ func NewWoodpeckerAuthClient(cc grpc.ClientConnInterface) WoodpeckerAuthClient {
return &woodpeckerAuthClient{cc}
}
func (c *woodpeckerAuthClient) Auth(ctx context.Context, in *AuthRequest, opts ...grpc.CallOption) (*AuthReply, error) {
out := new(AuthReply)
err := c.cc.Invoke(ctx, WoodpeckerAuth_Auth_FullMethodName, in, out, opts...)
func (c *woodpeckerAuthClient) Auth(ctx context.Context, in *AuthRequest, opts ...grpc.CallOption) (*AuthResponse, error) {
out := new(AuthResponse)
err := c.cc.Invoke(ctx, "/proto.WoodpeckerAuth/Auth", in, out, opts...)
if err != nil {
return nil, err
}
@ -482,14 +492,15 @@ func (c *woodpeckerAuthClient) Auth(ctx context.Context, in *AuthRequest, opts .
// All implementations must embed UnimplementedWoodpeckerAuthServer
// for forward compatibility
type WoodpeckerAuthServer interface {
Auth(context.Context, *AuthRequest) (*AuthReply, error)
Auth(context.Context, *AuthRequest) (*AuthResponse, error)
mustEmbedUnimplementedWoodpeckerAuthServer()
}
// UnimplementedWoodpeckerAuthServer must be embedded to have forward compatible implementations.
type UnimplementedWoodpeckerAuthServer struct{}
type UnimplementedWoodpeckerAuthServer struct {
}
func (UnimplementedWoodpeckerAuthServer) Auth(context.Context, *AuthRequest) (*AuthReply, error) {
func (UnimplementedWoodpeckerAuthServer) Auth(context.Context, *AuthRequest) (*AuthResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method Auth not implemented")
}
func (UnimplementedWoodpeckerAuthServer) mustEmbedUnimplementedWoodpeckerAuthServer() {}
@ -515,7 +526,7 @@ func _WoodpeckerAuth_Auth_Handler(srv interface{}, ctx context.Context, dec func
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: WoodpeckerAuth_Auth_FullMethodName,
FullMethod: "/proto.WoodpeckerAuth/Auth",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(WoodpeckerAuthServer).Auth(ctx, req.(*AuthRequest))

View file

@ -34,7 +34,7 @@ func (_m *Forge) Activate(ctx context.Context, u *model.User, r *model.Repo, lin
}
// Auth provides a mock function with given fields: ctx, token, secret
func (_m *Forge) Auth(ctx context.Context, token, secret string) (string, error) {
func (_m *Forge) Auth(ctx context.Context, token string, secret string) (string, error) {
ret := _m.Called(ctx, token, secret)
var r0 string
@ -353,7 +353,7 @@ func (_m *Forge) PullRequests(ctx context.Context, u *model.User, r *model.Repo,
}
// Repo provides a mock function with given fields: ctx, u, remoteID, owner, name
func (_m *Forge) Repo(ctx context.Context, u *model.User, remoteID model.ForgeRemoteID, owner, name string) (*model.Repo, error) {
func (_m *Forge) Repo(ctx context.Context, u *model.User, remoteID model.ForgeRemoteID, owner string, name string) (*model.Repo, error) {
ret := _m.Called(ctx, u, remoteID, owner, name)
var r0 *model.Repo

View file

@ -1,3 +1,17 @@
// Copyright 2023 Woodpecker Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package grpc
import (
@ -22,7 +36,7 @@ func NewWoodpeckerAuthServer(jwtManager *JWTManager, agentMasterToken string, st
return &WoodpeckerAuthServer{jwtManager: jwtManager, agentMasterToken: agentMasterToken, store: store}
}
func (s *WoodpeckerAuthServer) Auth(_ context.Context, req *proto.AuthRequest) (*proto.AuthReply, error) {
func (s *WoodpeckerAuthServer) Auth(_ context.Context, req *proto.AuthRequest) (*proto.AuthResponse, error) {
agent, err := s.getAgent(req.AgentId, req.AgentToken)
if err != nil {
return nil, err
@ -33,7 +47,7 @@ func (s *WoodpeckerAuthServer) Auth(_ context.Context, req *proto.AuthRequest) (
return nil, err
}
return &proto.AuthReply{
return &proto.AuthResponse{
Status: "ok",
AgentId: agent.ID,
AccessToken: accessToken,

View file

@ -28,6 +28,7 @@ import (
"github.com/woodpecker-ci/woodpecker/server/pubsub"
"github.com/woodpecker-ci/woodpecker/server/queue"
"github.com/woodpecker-ci/woodpecker/server/store"
"github.com/woodpecker-ci/woodpecker/version"
)
// WoodpeckerServer is a grpc server implementation.
@ -36,7 +37,7 @@ type WoodpeckerServer struct {
peer RPC
}
func NewWoodpeckerServer(forge forge.Forge, queue queue.Queue, logger logging.Log, pubsub pubsub.Publisher, store store.Store, host string) *WoodpeckerServer {
func NewWoodpeckerServer(forge forge.Forge, queue queue.Queue, logger logging.Log, pubsub pubsub.Publisher, store store.Store, host string) proto.WoodpeckerServer {
pipelineTime := promauto.NewGaugeVec(prometheus.GaugeOpts{
Namespace: "woodpecker",
Name: "pipeline_time",
@ -60,12 +61,19 @@ func NewWoodpeckerServer(forge forge.Forge, queue queue.Queue, logger logging.Lo
return &WoodpeckerServer{peer: peer}
}
func (s *WoodpeckerServer) Next(c context.Context, req *proto.NextRequest) (*proto.NextReply, error) {
func (s *WoodpeckerServer) Version(_ context.Context, _ *proto.Empty) (*proto.VersionResponse, error) {
return &proto.VersionResponse{
GrpcVersion: proto.Version,
ServerVersion: version.String(),
}, nil
}
func (s *WoodpeckerServer) Next(c context.Context, req *proto.NextRequest) (*proto.NextResponse, error) {
filter := rpc.Filter{
Labels: req.GetFilter().GetLabels(),
}
res := new(proto.NextReply)
res := new(proto.NextResponse)
pipeline, err := s.peer.Next(c, filter)
if err != nil {
return res, err

View file

@ -406,7 +406,7 @@ func (_m *Store) CronList(_a0 *model.Repo) ([]*model.Cron, error) {
}
// CronListNextExecute provides a mock function with given fields: _a0, _a1
func (_m *Store) CronListNextExecute(_a0, _a1 int64) ([]*model.Cron, error) {
func (_m *Store) CronListNextExecute(_a0 int64, _a1 int64) ([]*model.Cron, error) {
ret := _m.Called(_a0, _a1)
var r0 []*model.Cron
@ -618,7 +618,7 @@ func (_m *Store) GetPipeline(_a0 int64) (*model.Pipeline, error) {
}
// GetPipelineCommit provides a mock function with given fields: _a0, _a1, _a2
func (_m *Store) GetPipelineCommit(_a0 *model.Repo, _a1, _a2 string) (*model.Pipeline, error) {
func (_m *Store) GetPipelineCommit(_a0 *model.Repo, _a1 string, _a2 string) (*model.Pipeline, error) {
ret := _m.Called(_a0, _a1, _a2)
var r0 *model.Pipeline
@ -1210,7 +1210,7 @@ func (_m *Store) Migrate() error {
}
// OrgSecretFind provides a mock function with given fields: _a0, _a1
func (_m *Store) OrgSecretFind(_a0, _a1 string) (*model.Secret, error) {
func (_m *Store) OrgSecretFind(_a0 string, _a1 string) (*model.Secret, error) {
ret := _m.Called(_a0, _a1)
var r0 *model.Secret
@ -1676,7 +1676,7 @@ func (_m *Store) ServerConfigGet(_a0 string) (string, error) {
}
// ServerConfigSet provides a mock function with given fields: _a0, _a1
func (_m *Store) ServerConfigSet(_a0, _a1 string) error {
func (_m *Store) ServerConfigSet(_a0 string, _a1 string) error {
ret := _m.Called(_a0, _a1)
var r0 error