diff --git a/flow/cmd/handler.go b/flow/cmd/handler.go index b3e8d9c29a..431f897f2e 100644 --- a/flow/cmd/handler.go +++ b/flow/cmd/handler.go @@ -5,6 +5,7 @@ import ( "fmt" "time" + "github.com/PeerDB-io/peer-flow/connectors" "github.com/PeerDB-io/peer-flow/generated/protos" "github.com/PeerDB-io/peer-flow/shared" peerflow "github.com/PeerDB-io/peer-flow/workflows" @@ -275,3 +276,99 @@ func (h *FlowRequestHandler) ListPeers( Peers: peers, }, nil } + +func (h *FlowRequestHandler) ValidatePeer( + ctx context.Context, + req *protos.ValidatePeerRequest, +) (*protos.ValidatePeerResponse, error) { + if req.Peer == nil { + return &protos.ValidatePeerResponse{ + Status: protos.ValidatePeerStatus_INVALID, + Message: "no peer provided", + }, nil + } + + if len(req.Peer.Name) == 0 { + return &protos.ValidatePeerResponse{ + Status: protos.ValidatePeerStatus_INVALID, + Message: "no peer name provided", + }, nil + } + + conn, err := connectors.GetConnector(ctx, req.Peer) + if err != nil { + return &protos.ValidatePeerResponse{ + Status: protos.ValidatePeerStatus_INVALID, + Message: fmt.Sprintf("invalid peer: %s", err), + }, nil + } + + status := conn.ConnectionActive() + if !status { + return &protos.ValidatePeerResponse{ + Status: protos.ValidatePeerStatus_INVALID, + Message: fmt.Sprintf("failed to establish connection to peer: %s", err), + }, nil + } + + return &protos.ValidatePeerResponse{ + Status: protos.ValidatePeerStatus_VALID, + Message: "valid peer", + }, nil +} + +func (h *FlowRequestHandler) CreatePeer( + ctx context.Context, + req *protos.CreatePeerRequest, +) (*protos.CreatePeerResponse, error) { + status, validateErr := h.ValidatePeer(ctx, &protos.ValidatePeerRequest{Peer: req.Peer}) + if validateErr != nil { + return nil, validateErr + } + if status.Status != protos.ValidatePeerStatus_VALID { + return &protos.CreatePeerResponse{ + Status: protos.CreatePeerStatus_FAILED, + Message: status.Message, + }, nil + } + + config := req.Peer.Config + wrongConfigResponse := &protos.CreatePeerResponse{ + Status: protos.CreatePeerStatus_FAILED, + Message: "wrong config for connector", + } + var encodedConfig []byte + var encodingErr error + peerType := req.Peer.Type + switch peerType { + case protos.DBType_POSTGRES: + pgConfig := config.(*protos.Peer_PostgresConfig).PostgresConfig + encodedConfig, encodingErr = proto.Marshal(pgConfig) + + case protos.DBType_SNOWFLAKE: + sfConfig := config.(*protos.Peer_SnowflakeConfig).SnowflakeConfig + encodedConfig, encodingErr = proto.Marshal(sfConfig) + + default: + return wrongConfigResponse, nil + } + if encodingErr != nil { + log.Errorf("failed to encode peer config: %v", encodingErr) + return nil, encodingErr + } + + _, err := h.pool.Exec(ctx, "INSERT INTO peers (name, type, options) VALUES ($1, $2, $3)", + req.Peer.Name, peerType, encodedConfig, + ) + if err != nil { + return &protos.CreatePeerResponse{ + Status: protos.CreatePeerStatus_FAILED, + Message: err.Error(), + }, nil + } + + return &protos.CreatePeerResponse{ + Status: protos.CreatePeerStatus_CREATED, + Message: "", + }, nil +} diff --git a/flow/connectors/core.go b/flow/connectors/core.go index 9810fe6672..d6c1364cb1 100644 --- a/flow/connectors/core.go +++ b/flow/connectors/core.go @@ -15,6 +15,7 @@ import ( ) var ErrUnsupportedFunctionality = errors.New("requested connector does not support functionality") +var ErrWrongConfig = errors.New("wrong config for connector") type Connector interface { Close() error @@ -190,6 +191,39 @@ func GetQRepSyncConnector(ctx context.Context, config *protos.Peer) (QRepSyncCon } } +func GetConnector(ctx context.Context, config *protos.Peer) (Connector, error) { + inner := config.Type + switch inner { + case protos.DBType_POSTGRES: + pgConfig := config.GetPostgresConfig() + if pgConfig == nil { + return nil, ErrWrongConfig + } + return connpostgres.NewPostgresConnector(ctx, pgConfig) + case protos.DBType_BIGQUERY: + bqConfig := config.GetBigqueryConfig() + if bqConfig == nil { + return nil, ErrWrongConfig + } + return connbigquery.NewBigQueryConnector(ctx, bqConfig) + + case protos.DBType_SNOWFLAKE: + sfConfig := config.GetSnowflakeConfig() + if sfConfig == nil { + return nil, ErrWrongConfig + } + return connsnowflake.NewSnowflakeConnector(ctx, sfConfig) + // case protos.DBType_S3: + // return conns3.NewS3Connector(ctx, config.GetS3Config()) + // case protos.DBType_EVENTHUB: + // return connsqlserver.NewSQLServerConnector(ctx, config.GetSqlserverConfig()) + // case protos.DBType_SQLSERVER: + // return conneventhub.NewEventHubConnector(ctx, config.GetEventhubConfig()) + default: + return nil, ErrUnsupportedFunctionality + } +} + func GetQRepConsolidateConnector(ctx context.Context, config *protos.Peer) (QRepConsolidateConnector, error) { inner := config.Config diff --git a/flow/generated/protos/route.pb.go b/flow/generated/protos/route.pb.go index 6a9c13a3e3..cca1b89dea 100644 --- a/flow/generated/protos/route.pb.go +++ b/flow/generated/protos/route.pb.go @@ -24,10 +24,8 @@ const ( type ValidatePeerStatus int32 const ( - ValidatePeerStatus_VALID ValidatePeerStatus = 0 - ValidatePeerStatus_INVALID ValidatePeerStatus = 1 - ValidatePeerStatus_VALIDATING ValidatePeerStatus = 2 - ValidatePeerStatus_ERROR ValidatePeerStatus = 3 + ValidatePeerStatus_VALID ValidatePeerStatus = 0 + ValidatePeerStatus_INVALID ValidatePeerStatus = 1 ) // Enum value maps for ValidatePeerStatus. @@ -35,14 +33,10 @@ var ( ValidatePeerStatus_name = map[int32]string{ 0: "VALID", 1: "INVALID", - 2: "VALIDATING", - 3: "ERROR", } ValidatePeerStatus_value = map[string]int32{ - "VALID": 0, - "INVALID": 1, - "VALIDATING": 2, - "ERROR": 3, + "VALID": 0, + "INVALID": 1, } ) @@ -77,21 +71,18 @@ type CreatePeerStatus int32 const ( CreatePeerStatus_CREATED CreatePeerStatus = 0 - CreatePeerStatus_PENDING CreatePeerStatus = 1 - CreatePeerStatus_FAILED CreatePeerStatus = 2 + CreatePeerStatus_FAILED CreatePeerStatus = 1 ) // Enum value maps for CreatePeerStatus. var ( CreatePeerStatus_name = map[int32]string{ 0: "CREATED", - 1: "PENDING", - 2: "FAILED", + 1: "FAILED", } CreatePeerStatus_value = map[string]int32{ "CREATED": 0, - "PENDING": 1, - "FAILED": 2, + "FAILED": 1, } ) @@ -526,7 +517,7 @@ type ValidatePeerRequest struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + Peer *Peer `protobuf:"bytes,1,opt,name=peer,proto3" json:"peer,omitempty"` } func (x *ValidatePeerRequest) Reset() { @@ -561,11 +552,11 @@ func (*ValidatePeerRequest) Descriptor() ([]byte, []int) { return file_route_proto_rawDescGZIP(), []int{8} } -func (x *ValidatePeerRequest) GetName() string { +func (x *ValidatePeerRequest) GetPeer() *Peer { if x != nil { - return x.Name + return x.Peer } - return "" + return nil } type CreatePeerRequest struct { @@ -573,7 +564,7 @@ type CreatePeerRequest struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + Peer *Peer `protobuf:"bytes,1,opt,name=peer,proto3" json:"peer,omitempty"` } func (x *CreatePeerRequest) Reset() { @@ -608,11 +599,11 @@ func (*CreatePeerRequest) Descriptor() ([]byte, []int) { return file_route_proto_rawDescGZIP(), []int{9} } -func (x *CreatePeerRequest) GetName() string { +func (x *CreatePeerRequest) GetPeer() *Peer { if x != nil { - return x.Name + return x.Peer } - return "" + return nil } type ValidatePeerResponse struct { @@ -774,34 +765,34 @@ var file_route_proto_rawDesc = []byte{ 0x0a, 0x11, 0x4c, 0x69, 0x73, 0x74, 0x50, 0x65, 0x65, 0x72, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x28, 0x0a, 0x05, 0x70, 0x65, 0x65, 0x72, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x70, 0x65, 0x65, 0x72, 0x64, 0x62, 0x5f, 0x70, 0x65, 0x65, 0x72, - 0x73, 0x2e, 0x50, 0x65, 0x65, 0x72, 0x52, 0x05, 0x70, 0x65, 0x65, 0x72, 0x73, 0x22, 0x29, 0x0a, + 0x73, 0x2e, 0x50, 0x65, 0x65, 0x72, 0x52, 0x05, 0x70, 0x65, 0x65, 0x72, 0x73, 0x22, 0x3d, 0x0a, 0x13, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x50, 0x65, 0x65, 0x72, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x27, 0x0a, 0x11, 0x43, 0x72, 0x65, 0x61, - 0x74, 0x65, 0x50, 0x65, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, - 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, - 0x65, 0x22, 0x6a, 0x0a, 0x14, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x50, 0x65, 0x65, - 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x38, 0x0a, 0x06, 0x73, 0x74, 0x61, - 0x74, 0x75, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x20, 0x2e, 0x70, 0x65, 0x65, 0x72, - 0x64, 0x62, 0x5f, 0x72, 0x6f, 0x75, 0x74, 0x65, 0x2e, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, - 0x65, 0x50, 0x65, 0x65, 0x72, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x06, 0x73, 0x74, 0x61, - 0x74, 0x75, 0x73, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x02, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x66, 0x0a, - 0x12, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x50, 0x65, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, - 0x6e, 0x73, 0x65, 0x12, 0x36, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x0e, 0x32, 0x1e, 0x2e, 0x70, 0x65, 0x65, 0x72, 0x64, 0x62, 0x5f, 0x72, 0x6f, 0x75, - 0x74, 0x65, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x50, 0x65, 0x65, 0x72, 0x53, 0x74, 0x61, + 0x75, 0x65, 0x73, 0x74, 0x12, 0x26, 0x0a, 0x04, 0x70, 0x65, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x70, 0x65, 0x65, 0x72, 0x64, 0x62, 0x5f, 0x70, 0x65, 0x65, 0x72, + 0x73, 0x2e, 0x50, 0x65, 0x65, 0x72, 0x52, 0x04, 0x70, 0x65, 0x65, 0x72, 0x22, 0x3b, 0x0a, 0x11, + 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x50, 0x65, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x12, 0x26, 0x0a, 0x04, 0x70, 0x65, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, + 0x12, 0x2e, 0x70, 0x65, 0x65, 0x72, 0x64, 0x62, 0x5f, 0x70, 0x65, 0x65, 0x72, 0x73, 0x2e, 0x50, + 0x65, 0x65, 0x72, 0x52, 0x04, 0x70, 0x65, 0x65, 0x72, 0x22, 0x6a, 0x0a, 0x14, 0x56, 0x61, 0x6c, + 0x69, 0x64, 0x61, 0x74, 0x65, 0x50, 0x65, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x12, 0x38, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x0e, 0x32, 0x20, 0x2e, 0x70, 0x65, 0x65, 0x72, 0x64, 0x62, 0x5f, 0x72, 0x6f, 0x75, 0x74, 0x65, + 0x2e, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x50, 0x65, 0x65, 0x72, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, - 0x73, 0x73, 0x61, 0x67, 0x65, 0x2a, 0x47, 0x0a, 0x12, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, - 0x65, 0x50, 0x65, 0x65, 0x72, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x09, 0x0a, 0x05, 0x56, - 0x41, 0x4c, 0x49, 0x44, 0x10, 0x00, 0x12, 0x0b, 0x0a, 0x07, 0x49, 0x4e, 0x56, 0x41, 0x4c, 0x49, - 0x44, 0x10, 0x01, 0x12, 0x0e, 0x0a, 0x0a, 0x56, 0x41, 0x4c, 0x49, 0x44, 0x41, 0x54, 0x49, 0x4e, - 0x47, 0x10, 0x02, 0x12, 0x09, 0x0a, 0x05, 0x45, 0x52, 0x52, 0x4f, 0x52, 0x10, 0x03, 0x2a, 0x38, - 0x0a, 0x10, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x50, 0x65, 0x65, 0x72, 0x53, 0x74, 0x61, 0x74, - 0x75, 0x73, 0x12, 0x0b, 0x0a, 0x07, 0x43, 0x52, 0x45, 0x41, 0x54, 0x45, 0x44, 0x10, 0x00, 0x12, - 0x0b, 0x0a, 0x07, 0x50, 0x45, 0x4e, 0x44, 0x49, 0x4e, 0x47, 0x10, 0x01, 0x12, 0x0a, 0x0a, 0x06, - 0x46, 0x41, 0x49, 0x4c, 0x45, 0x44, 0x10, 0x02, 0x32, 0x95, 0x04, 0x0a, 0x0b, 0x46, 0x6c, 0x6f, + 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x66, 0x0a, 0x12, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x50, + 0x65, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x36, 0x0a, 0x06, 0x73, + 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x1e, 0x2e, 0x70, 0x65, + 0x65, 0x72, 0x64, 0x62, 0x5f, 0x72, 0x6f, 0x75, 0x74, 0x65, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, + 0x65, 0x50, 0x65, 0x65, 0x72, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x06, 0x73, 0x74, 0x61, + 0x74, 0x75, 0x73, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2a, 0x2c, 0x0a, + 0x12, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x50, 0x65, 0x65, 0x72, 0x53, 0x74, 0x61, + 0x74, 0x75, 0x73, 0x12, 0x09, 0x0a, 0x05, 0x56, 0x41, 0x4c, 0x49, 0x44, 0x10, 0x00, 0x12, 0x0b, + 0x0a, 0x07, 0x49, 0x4e, 0x56, 0x41, 0x4c, 0x49, 0x44, 0x10, 0x01, 0x2a, 0x2b, 0x0a, 0x10, 0x43, + 0x72, 0x65, 0x61, 0x74, 0x65, 0x50, 0x65, 0x65, 0x72, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, + 0x0b, 0x0a, 0x07, 0x43, 0x52, 0x45, 0x41, 0x54, 0x45, 0x44, 0x10, 0x00, 0x12, 0x0a, 0x0a, 0x06, + 0x46, 0x41, 0x49, 0x4c, 0x45, 0x44, 0x10, 0x01, 0x32, 0x95, 0x04, 0x0a, 0x0b, 0x46, 0x6c, 0x6f, 0x77, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x4e, 0x0a, 0x09, 0x4c, 0x69, 0x73, 0x74, 0x50, 0x65, 0x65, 0x72, 0x73, 0x12, 0x1e, 0x2e, 0x70, 0x65, 0x65, 0x72, 0x64, 0x62, 0x5f, 0x72, 0x6f, 0x75, 0x74, 0x65, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x50, 0x65, 0x65, 0x72, 0x73, 0x52, 0x65, @@ -885,25 +876,27 @@ var file_route_proto_depIdxs = []int32{ 16, // 2: peerdb_route.ShutdownRequest.source_peer:type_name -> peerdb_peers.Peer 16, // 3: peerdb_route.ShutdownRequest.destination_peer:type_name -> peerdb_peers.Peer 16, // 4: peerdb_route.ListPeersResponse.peers:type_name -> peerdb_peers.Peer - 0, // 5: peerdb_route.ValidatePeerResponse.status:type_name -> peerdb_route.ValidatePeerStatus - 1, // 6: peerdb_route.CreatePeerResponse.status:type_name -> peerdb_route.CreatePeerStatus - 8, // 7: peerdb_route.FlowService.ListPeers:input_type -> peerdb_route.ListPeersRequest - 10, // 8: peerdb_route.FlowService.ValidatePeer:input_type -> peerdb_route.ValidatePeerRequest - 11, // 9: peerdb_route.FlowService.CreatePeer:input_type -> peerdb_route.CreatePeerRequest - 2, // 10: peerdb_route.FlowService.CreateCDCFlow:input_type -> peerdb_route.CreateCDCFlowRequest - 4, // 11: peerdb_route.FlowService.CreateQRepFlow:input_type -> peerdb_route.CreateQRepFlowRequest - 6, // 12: peerdb_route.FlowService.ShutdownFlow:input_type -> peerdb_route.ShutdownRequest - 9, // 13: peerdb_route.FlowService.ListPeers:output_type -> peerdb_route.ListPeersResponse - 12, // 14: peerdb_route.FlowService.ValidatePeer:output_type -> peerdb_route.ValidatePeerResponse - 13, // 15: peerdb_route.FlowService.CreatePeer:output_type -> peerdb_route.CreatePeerResponse - 3, // 16: peerdb_route.FlowService.CreateCDCFlow:output_type -> peerdb_route.CreateCDCFlowResponse - 5, // 17: peerdb_route.FlowService.CreateQRepFlow:output_type -> peerdb_route.CreateQRepFlowResponse - 7, // 18: peerdb_route.FlowService.ShutdownFlow:output_type -> peerdb_route.ShutdownResponse - 13, // [13:19] is the sub-list for method output_type - 7, // [7:13] is the sub-list for method input_type - 7, // [7:7] is the sub-list for extension type_name - 7, // [7:7] is the sub-list for extension extendee - 0, // [0:7] is the sub-list for field type_name + 16, // 5: peerdb_route.ValidatePeerRequest.peer:type_name -> peerdb_peers.Peer + 16, // 6: peerdb_route.CreatePeerRequest.peer:type_name -> peerdb_peers.Peer + 0, // 7: peerdb_route.ValidatePeerResponse.status:type_name -> peerdb_route.ValidatePeerStatus + 1, // 8: peerdb_route.CreatePeerResponse.status:type_name -> peerdb_route.CreatePeerStatus + 8, // 9: peerdb_route.FlowService.ListPeers:input_type -> peerdb_route.ListPeersRequest + 10, // 10: peerdb_route.FlowService.ValidatePeer:input_type -> peerdb_route.ValidatePeerRequest + 11, // 11: peerdb_route.FlowService.CreatePeer:input_type -> peerdb_route.CreatePeerRequest + 2, // 12: peerdb_route.FlowService.CreateCDCFlow:input_type -> peerdb_route.CreateCDCFlowRequest + 4, // 13: peerdb_route.FlowService.CreateQRepFlow:input_type -> peerdb_route.CreateQRepFlowRequest + 6, // 14: peerdb_route.FlowService.ShutdownFlow:input_type -> peerdb_route.ShutdownRequest + 9, // 15: peerdb_route.FlowService.ListPeers:output_type -> peerdb_route.ListPeersResponse + 12, // 16: peerdb_route.FlowService.ValidatePeer:output_type -> peerdb_route.ValidatePeerResponse + 13, // 17: peerdb_route.FlowService.CreatePeer:output_type -> peerdb_route.CreatePeerResponse + 3, // 18: peerdb_route.FlowService.CreateCDCFlow:output_type -> peerdb_route.CreateCDCFlowResponse + 5, // 19: peerdb_route.FlowService.CreateQRepFlow:output_type -> peerdb_route.CreateQRepFlowResponse + 7, // 20: peerdb_route.FlowService.ShutdownFlow:output_type -> peerdb_route.ShutdownResponse + 15, // [15:21] is the sub-list for method output_type + 9, // [9:15] is the sub-list for method input_type + 9, // [9:9] is the sub-list for extension type_name + 9, // [9:9] is the sub-list for extension extendee + 0, // [0:9] is the sub-list for field type_name } func init() { file_route_proto_init() } diff --git a/nexus/pt/src/peerdb_route.rs b/nexus/pt/src/peerdb_route.rs index 48f3cf9b31..d641537892 100644 --- a/nexus/pt/src/peerdb_route.rs +++ b/nexus/pt/src/peerdb_route.rs @@ -56,14 +56,14 @@ pub struct ListPeersResponse { #[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] pub struct ValidatePeerRequest { - #[prost(string, tag="1")] - pub name: ::prost::alloc::string::String, + #[prost(message, optional, tag="1")] + pub peer: ::core::option::Option, } #[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] pub struct CreatePeerRequest { - #[prost(string, tag="1")] - pub name: ::prost::alloc::string::String, + #[prost(message, optional, tag="1")] + pub peer: ::core::option::Option, } #[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] @@ -86,8 +86,6 @@ pub struct CreatePeerResponse { pub enum ValidatePeerStatus { Valid = 0, Invalid = 1, - Validating = 2, - Error = 3, } impl ValidatePeerStatus { /// String value of the enum field names used in the ProtoBuf definition. @@ -98,8 +96,6 @@ impl ValidatePeerStatus { match self { ValidatePeerStatus::Valid => "VALID", ValidatePeerStatus::Invalid => "INVALID", - ValidatePeerStatus::Validating => "VALIDATING", - ValidatePeerStatus::Error => "ERROR", } } /// Creates an enum from field names used in the ProtoBuf definition. @@ -107,8 +103,6 @@ impl ValidatePeerStatus { match value { "VALID" => Some(Self::Valid), "INVALID" => Some(Self::Invalid), - "VALIDATING" => Some(Self::Validating), - "ERROR" => Some(Self::Error), _ => None, } } @@ -117,8 +111,7 @@ impl ValidatePeerStatus { #[repr(i32)] pub enum CreatePeerStatus { Created = 0, - Pending = 1, - Failed = 2, + Failed = 1, } impl CreatePeerStatus { /// String value of the enum field names used in the ProtoBuf definition. @@ -128,7 +121,6 @@ impl CreatePeerStatus { pub fn as_str_name(&self) -> &'static str { match self { CreatePeerStatus::Created => "CREATED", - CreatePeerStatus::Pending => "PENDING", CreatePeerStatus::Failed => "FAILED", } } @@ -136,7 +128,6 @@ impl CreatePeerStatus { pub fn from_str_name(value: &str) -> ::core::option::Option { match value { "CREATED" => Some(Self::Created), - "PENDING" => Some(Self::Pending), "FAILED" => Some(Self::Failed), _ => None, } diff --git a/nexus/pt/src/peerdb_route.serde.rs b/nexus/pt/src/peerdb_route.serde.rs index ce79422c4a..cd6e2e3ec1 100644 --- a/nexus/pt/src/peerdb_route.serde.rs +++ b/nexus/pt/src/peerdb_route.serde.rs @@ -199,12 +199,12 @@ impl serde::Serialize for CreatePeerRequest { { use serde::ser::SerializeStruct; let mut len = 0; - if !self.name.is_empty() { + if self.peer.is_some() { len += 1; } let mut struct_ser = serializer.serialize_struct("peerdb_route.CreatePeerRequest", len)?; - if !self.name.is_empty() { - struct_ser.serialize_field("name", &self.name)?; + if let Some(v) = self.peer.as_ref() { + struct_ser.serialize_field("peer", v)?; } struct_ser.end() } @@ -216,12 +216,12 @@ impl<'de> serde::Deserialize<'de> for CreatePeerRequest { D: serde::Deserializer<'de>, { const FIELDS: &[&str] = &[ - "name", + "peer", ]; #[allow(clippy::enum_variant_names)] enum GeneratedField { - Name, + Peer, __SkipField__, } impl<'de> serde::Deserialize<'de> for GeneratedField { @@ -244,7 +244,7 @@ impl<'de> serde::Deserialize<'de> for CreatePeerRequest { E: serde::de::Error, { match value { - "name" => Ok(GeneratedField::Name), + "peer" => Ok(GeneratedField::Peer), _ => Ok(GeneratedField::__SkipField__), } } @@ -264,14 +264,14 @@ impl<'de> serde::Deserialize<'de> for CreatePeerRequest { where V: serde::de::MapAccess<'de>, { - let mut name__ = None; + let mut peer__ = None; while let Some(k) = map.next_key()? { match k { - GeneratedField::Name => { - if name__.is_some() { - return Err(serde::de::Error::duplicate_field("name")); + GeneratedField::Peer => { + if peer__.is_some() { + return Err(serde::de::Error::duplicate_field("peer")); } - name__ = Some(map.next_value()?); + peer__ = map.next_value()?; } GeneratedField::__SkipField__ => { let _ = map.next_value::()?; @@ -279,7 +279,7 @@ impl<'de> serde::Deserialize<'de> for CreatePeerRequest { } } Ok(CreatePeerRequest { - name: name__.unwrap_or_default(), + peer: peer__, }) } } @@ -408,7 +408,6 @@ impl serde::Serialize for CreatePeerStatus { { let variant = match self { Self::Created => "CREATED", - Self::Pending => "PENDING", Self::Failed => "FAILED", }; serializer.serialize_str(variant) @@ -422,7 +421,6 @@ impl<'de> serde::Deserialize<'de> for CreatePeerStatus { { const FIELDS: &[&str] = &[ "CREATED", - "PENDING", "FAILED", ]; @@ -467,7 +465,6 @@ impl<'de> serde::Deserialize<'de> for CreatePeerStatus { { match value { "CREATED" => Ok(CreatePeerStatus::Created), - "PENDING" => Ok(CreatePeerStatus::Pending), "FAILED" => Ok(CreatePeerStatus::Failed), _ => Err(serde::de::Error::unknown_variant(value, FIELDS)), } @@ -1106,12 +1103,12 @@ impl serde::Serialize for ValidatePeerRequest { { use serde::ser::SerializeStruct; let mut len = 0; - if !self.name.is_empty() { + if self.peer.is_some() { len += 1; } let mut struct_ser = serializer.serialize_struct("peerdb_route.ValidatePeerRequest", len)?; - if !self.name.is_empty() { - struct_ser.serialize_field("name", &self.name)?; + if let Some(v) = self.peer.as_ref() { + struct_ser.serialize_field("peer", v)?; } struct_ser.end() } @@ -1123,12 +1120,12 @@ impl<'de> serde::Deserialize<'de> for ValidatePeerRequest { D: serde::Deserializer<'de>, { const FIELDS: &[&str] = &[ - "name", + "peer", ]; #[allow(clippy::enum_variant_names)] enum GeneratedField { - Name, + Peer, __SkipField__, } impl<'de> serde::Deserialize<'de> for GeneratedField { @@ -1151,7 +1148,7 @@ impl<'de> serde::Deserialize<'de> for ValidatePeerRequest { E: serde::de::Error, { match value { - "name" => Ok(GeneratedField::Name), + "peer" => Ok(GeneratedField::Peer), _ => Ok(GeneratedField::__SkipField__), } } @@ -1171,14 +1168,14 @@ impl<'de> serde::Deserialize<'de> for ValidatePeerRequest { where V: serde::de::MapAccess<'de>, { - let mut name__ = None; + let mut peer__ = None; while let Some(k) = map.next_key()? { match k { - GeneratedField::Name => { - if name__.is_some() { - return Err(serde::de::Error::duplicate_field("name")); + GeneratedField::Peer => { + if peer__.is_some() { + return Err(serde::de::Error::duplicate_field("peer")); } - name__ = Some(map.next_value()?); + peer__ = map.next_value()?; } GeneratedField::__SkipField__ => { let _ = map.next_value::()?; @@ -1186,7 +1183,7 @@ impl<'de> serde::Deserialize<'de> for ValidatePeerRequest { } } Ok(ValidatePeerRequest { - name: name__.unwrap_or_default(), + peer: peer__, }) } } @@ -1316,8 +1313,6 @@ impl serde::Serialize for ValidatePeerStatus { let variant = match self { Self::Valid => "VALID", Self::Invalid => "INVALID", - Self::Validating => "VALIDATING", - Self::Error => "ERROR", }; serializer.serialize_str(variant) } @@ -1331,8 +1326,6 @@ impl<'de> serde::Deserialize<'de> for ValidatePeerStatus { const FIELDS: &[&str] = &[ "VALID", "INVALID", - "VALIDATING", - "ERROR", ]; struct GeneratedVisitor; @@ -1377,8 +1370,6 @@ impl<'de> serde::Deserialize<'de> for ValidatePeerStatus { match value { "VALID" => Ok(ValidatePeerStatus::Valid), "INVALID" => Ok(ValidatePeerStatus::Invalid), - "VALIDATING" => Ok(ValidatePeerStatus::Validating), - "ERROR" => Ok(ValidatePeerStatus::Error), _ => Err(serde::de::Error::unknown_variant(value, FIELDS)), } } diff --git a/protos/route.proto b/protos/route.proto index 920e6c753d..d8bee11d59 100644 --- a/protos/route.proto +++ b/protos/route.proto @@ -42,24 +42,21 @@ message ListPeersResponse { } message ValidatePeerRequest { - string name = 1; + peerdb_peers.Peer peer = 1; } message CreatePeerRequest { - string name = 1; + peerdb_peers.Peer peer = 1; } enum ValidatePeerStatus { VALID = 0; INVALID = 1; - VALIDATING = 2; - ERROR = 3; } enum CreatePeerStatus { CREATED = 0; - PENDING = 1; - FAILED = 2; + FAILED = 1; } message ValidatePeerResponse { diff --git a/ui/grpc_generated/route.ts b/ui/grpc_generated/route.ts index 1a076580b0..02d6947f92 100644 --- a/ui/grpc_generated/route.ts +++ b/ui/grpc_generated/route.ts @@ -20,8 +20,6 @@ export const protobufPackage = "peerdb_route"; export enum ValidatePeerStatus { VALID = 0, INVALID = 1, - VALIDATING = 2, - ERROR = 3, UNRECOGNIZED = -1, } @@ -33,12 +31,6 @@ export function validatePeerStatusFromJSON(object: any): ValidatePeerStatus { case 1: case "INVALID": return ValidatePeerStatus.INVALID; - case 2: - case "VALIDATING": - return ValidatePeerStatus.VALIDATING; - case 3: - case "ERROR": - return ValidatePeerStatus.ERROR; case -1: case "UNRECOGNIZED": default: @@ -52,10 +44,6 @@ export function validatePeerStatusToJSON(object: ValidatePeerStatus): string { return "VALID"; case ValidatePeerStatus.INVALID: return "INVALID"; - case ValidatePeerStatus.VALIDATING: - return "VALIDATING"; - case ValidatePeerStatus.ERROR: - return "ERROR"; case ValidatePeerStatus.UNRECOGNIZED: default: return "UNRECOGNIZED"; @@ -64,8 +52,7 @@ export function validatePeerStatusToJSON(object: ValidatePeerStatus): string { export enum CreatePeerStatus { CREATED = 0, - PENDING = 1, - FAILED = 2, + FAILED = 1, UNRECOGNIZED = -1, } @@ -75,9 +62,6 @@ export function createPeerStatusFromJSON(object: any): CreatePeerStatus { case "CREATED": return CreatePeerStatus.CREATED; case 1: - case "PENDING": - return CreatePeerStatus.PENDING; - case 2: case "FAILED": return CreatePeerStatus.FAILED; case -1: @@ -91,8 +75,6 @@ export function createPeerStatusToJSON(object: CreatePeerStatus): string { switch (object) { case CreatePeerStatus.CREATED: return "CREATED"; - case CreatePeerStatus.PENDING: - return "PENDING"; case CreatePeerStatus.FAILED: return "FAILED"; case CreatePeerStatus.UNRECOGNIZED: @@ -137,11 +119,11 @@ export interface ListPeersResponse { } export interface ValidatePeerRequest { - name: string; + peer: Peer | undefined; } export interface CreatePeerRequest { - name: string; + peer: Peer | undefined; } export interface ValidatePeerResponse { @@ -673,13 +655,13 @@ export const ListPeersResponse = { }; function createBaseValidatePeerRequest(): ValidatePeerRequest { - return { name: "" }; + return { peer: undefined }; } export const ValidatePeerRequest = { encode(message: ValidatePeerRequest, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { - if (message.name !== "") { - writer.uint32(10).string(message.name); + if (message.peer !== undefined) { + Peer.encode(message.peer, writer.uint32(10).fork()).ldelim(); } return writer; }, @@ -696,7 +678,7 @@ export const ValidatePeerRequest = { break; } - message.name = reader.string(); + message.peer = Peer.decode(reader, reader.uint32()); continue; } if ((tag & 7) === 4 || tag === 0) { @@ -708,13 +690,13 @@ export const ValidatePeerRequest = { }, fromJSON(object: any): ValidatePeerRequest { - return { name: isSet(object.name) ? String(object.name) : "" }; + return { peer: isSet(object.peer) ? Peer.fromJSON(object.peer) : undefined }; }, toJSON(message: ValidatePeerRequest): unknown { const obj: any = {}; - if (message.name !== "") { - obj.name = message.name; + if (message.peer !== undefined) { + obj.peer = Peer.toJSON(message.peer); } return obj; }, @@ -724,19 +706,19 @@ export const ValidatePeerRequest = { }, fromPartial, I>>(object: I): ValidatePeerRequest { const message = createBaseValidatePeerRequest(); - message.name = object.name ?? ""; + message.peer = (object.peer !== undefined && object.peer !== null) ? Peer.fromPartial(object.peer) : undefined; return message; }, }; function createBaseCreatePeerRequest(): CreatePeerRequest { - return { name: "" }; + return { peer: undefined }; } export const CreatePeerRequest = { encode(message: CreatePeerRequest, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { - if (message.name !== "") { - writer.uint32(10).string(message.name); + if (message.peer !== undefined) { + Peer.encode(message.peer, writer.uint32(10).fork()).ldelim(); } return writer; }, @@ -753,7 +735,7 @@ export const CreatePeerRequest = { break; } - message.name = reader.string(); + message.peer = Peer.decode(reader, reader.uint32()); continue; } if ((tag & 7) === 4 || tag === 0) { @@ -765,13 +747,13 @@ export const CreatePeerRequest = { }, fromJSON(object: any): CreatePeerRequest { - return { name: isSet(object.name) ? String(object.name) : "" }; + return { peer: isSet(object.peer) ? Peer.fromJSON(object.peer) : undefined }; }, toJSON(message: CreatePeerRequest): unknown { const obj: any = {}; - if (message.name !== "") { - obj.name = message.name; + if (message.peer !== undefined) { + obj.peer = Peer.toJSON(message.peer); } return obj; }, @@ -781,7 +763,7 @@ export const CreatePeerRequest = { }, fromPartial, I>>(object: I): CreatePeerRequest { const message = createBaseCreatePeerRequest(); - message.name = object.name ?? ""; + message.peer = (object.peer !== undefined && object.peer !== null) ? Peer.fromPartial(object.peer) : undefined; return message; }, };