Broadcast event

This commit is contained in:
LittleSheep 2024-10-21 00:05:40 +08:00
parent 799bfcc263
commit 80ad9399a3
28 changed files with 1330 additions and 48 deletions

View File

@ -1,7 +1,11 @@
package directory package directory
import ( import (
"context"
"git.solsynth.dev/hypernet/nexus/pkg/nex"
"git.solsynth.dev/hypernet/nexus/pkg/proto"
"sync" "sync"
"time"
) )
// In services, we use sync.Map because it will be both often read and write // In services, we use sync.Map because it will be both often read and write
@ -55,3 +59,20 @@ func AddServiceInstance(in *ServiceInstance) {
func RemoveServiceInstance(id string) { func RemoveServiceInstance(id string) {
serviceDirectory.Delete(id) serviceDirectory.Delete(id)
} }
func BroadcastEvent(event string, data any) {
serviceDirectory.Range(func(key, value any) bool {
conn, err := value.(*ServiceInstance).GetGrpcConn()
if err != nil {
return true
}
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
_, _ = proto.NewServiceDirectoryClient(conn).BroadcastEvent(ctx, &proto.EventInfo{
Event: event,
Data: nex.EncodeMap(data),
})
return true
})
}

View File

@ -1,9 +1,9 @@
package grpc package grpc
import ( import (
directory2 "git.solsynth.dev/hypernet/nexus/pkg/internal/directory"
"net" "net"
"git.solsynth.dev/hypernet/nexus/pkg/directory"
"git.solsynth.dev/hypernet/nexus/pkg/proto" "git.solsynth.dev/hypernet/nexus/pkg/proto"
"google.golang.org/grpc/reflection" "google.golang.org/grpc/reflection"
@ -27,8 +27,8 @@ func NewServer() *Server {
srv: grpc.NewServer(), srv: grpc.NewServer(),
} }
proto.RegisterServiceDirectoryServer(server.srv, &directory.ServiceRpcServer{}) proto.RegisterServiceDirectoryServer(server.srv, &directory2.ServiceRpcServer{})
proto.RegisterCommandControllerServer(server.srv, &directory.CommandRpcServer{}) proto.RegisterCommandControllerServer(server.srv, &directory2.CommandRpcServer{})
proto.RegisterDatabaseControllerServer(server.srv, server) proto.RegisterDatabaseControllerServer(server.srv, server)
proto.RegisterStreamControllerServer(server.srv, server) proto.RegisterStreamControllerServer(server.srv, server)
health.RegisterHealthServer(server.srv, server) health.RegisterHealthServer(server.srv, server)

View File

@ -3,7 +3,7 @@ package grpc
import ( import (
"context" "context"
"fmt" "fmt"
"git.solsynth.dev/hypernet/nexus/pkg/http/ws" "git.solsynth.dev/hypernet/nexus/pkg/internal/http/ws"
"git.solsynth.dev/hypernet/nexus/pkg/proto" "git.solsynth.dev/hypernet/nexus/pkg/proto"
"github.com/samber/lo" "github.com/samber/lo"

View File

@ -3,7 +3,7 @@ package api
import ( import (
"context" "context"
"fmt" "fmt"
"git.solsynth.dev/hypernet/nexus/pkg/directory" "git.solsynth.dev/hypernet/nexus/pkg/internal/directory"
"git.solsynth.dev/hypernet/nexus/pkg/proto" "git.solsynth.dev/hypernet/nexus/pkg/proto"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"

View File

@ -1,15 +1,15 @@
package api package api
import ( import (
"git.solsynth.dev/hypernet/nexus/pkg/directory" directory2 "git.solsynth.dev/hypernet/nexus/pkg/internal/directory"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
"github.com/samber/lo" "github.com/samber/lo"
) )
func listExistsService(c *fiber.Ctx) error { func listExistsService(c *fiber.Ctx) error {
services := directory.ListServiceInstance() services := directory2.ListServiceInstance()
return c.JSON(lo.Map(services, func(item *directory.ServiceInstance, index int) map[string]any { return c.JSON(lo.Map(services, func(item *directory2.ServiceInstance, index int) map[string]any {
return map[string]any{ return map[string]any{
"id": item.ID, "id": item.ID,
"type": item.Type, "type": item.Type,

View File

@ -0,0 +1,41 @@
package api
import (
"git.solsynth.dev/hypernet/nexus/pkg/internal/directory"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/proxy"
"github.com/rs/zerolog/log"
"github.com/spf13/viper"
"strings"
)
func forwardService(c *fiber.Ctx) error {
serviceType := c.Params("service")
ogKeyword := serviceType
aliasingMap := viper.GetStringMapString("services.aliases")
if val, ok := aliasingMap[serviceType]; ok {
serviceType = val
}
service := directory.GetServiceInstanceByType(serviceType)
if service == nil || service.HttpAddr == nil {
return fiber.NewError(fiber.StatusNotFound, "service not found")
}
ogUrl := c.Request().URI().String()
url := c.OriginalURL()
url = strings.Replace(url, "/cgi/"+ogKeyword, "", 1)
url = *service.HttpAddr + url
log.Debug().
Str("from", ogUrl).
Str("to", url).
Str("service", serviceType).
Str("id", service.ID).
Msg("Forwarding request for service...")
return proxy.Do(c, url)
}

View File

@ -1,7 +1,7 @@
package api package api
import ( import (
"git.solsynth.dev/hypernet/nexus/pkg/http/ws" "git.solsynth.dev/hypernet/nexus/pkg/internal/http/ws"
"github.com/gofiber/contrib/websocket" "github.com/gofiber/contrib/websocket"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
) )
@ -25,5 +25,6 @@ func MapAPIs(app *fiber.App) {
return c.Next() return c.Next()
}).Get("/ws", websocket.New(ws.Listen)) }).Get("/ws", websocket.New(ws.Listen))
app.All("/cgi/:command", invokeCommand) app.All("/inv/:command", invokeCommand)
app.All("/cgi/:service/*", forwardService)
} }

View File

@ -1,7 +1,7 @@
package server package server
import ( import (
"git.solsynth.dev/hypernet/nexus/pkg/http/api" "git.solsynth.dev/hypernet/nexus/pkg/internal/http/api"
"github.com/goccy/go-json" "github.com/goccy/go-json"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors" "github.com/gofiber/fiber/v2/middleware/cors"

View File

@ -1,6 +1,7 @@
package ws package ws
import ( import (
"git.solsynth.dev/hypernet/nexus/pkg/internal/directory"
"math/rand" "math/rand"
"sync" "sync"
@ -22,6 +23,11 @@ func ClientRegister(user models.Account, conn *websocket.Conn) uint64 {
wsConn[user.ID][clientId] = conn wsConn[user.ID][clientId] = conn
wsMutex.Unlock() wsMutex.Unlock()
directory.BroadcastEvent("ws.client.register", map[string]any{
"user": user.ID,
"id": clientId,
})
return clientId return clientId
} }
@ -32,6 +38,11 @@ func ClientUnregister(user models.Account, id uint64) {
} }
delete(wsConn[user.ID], id) delete(wsConn[user.ID], id)
wsMutex.Unlock() wsMutex.Unlock()
directory.BroadcastEvent("ws.client.unregister", map[string]any{
"user": user.ID,
"id": id,
})
} }
func ClientCount(uid uint) int { func ClientCount(uid uint) int {

View File

@ -3,12 +3,12 @@ package main
import ( import (
"fmt" "fmt"
"git.solsynth.dev/hypernet/nexus/pkg/internal/database" "git.solsynth.dev/hypernet/nexus/pkg/internal/database"
"git.solsynth.dev/hypernet/nexus/pkg/internal/http"
"github.com/fatih/color" "github.com/fatih/color"
"os" "os"
"os/signal" "os/signal"
"syscall" "syscall"
server "git.solsynth.dev/hypernet/nexus/pkg/http"
pkg "git.solsynth.dev/hypernet/nexus/pkg/internal" pkg "git.solsynth.dev/hypernet/nexus/pkg/internal"
"git.solsynth.dev/hypernet/nexus/pkg/internal/grpc" "git.solsynth.dev/hypernet/nexus/pkg/internal/grpc"
"github.com/robfig/cron/v3" "github.com/robfig/cron/v3"

View File

@ -2,8 +2,8 @@ package nex
import jsoniter "github.com/json-iterator/go" import jsoniter "github.com/json-iterator/go"
func EncodeMap(policy map[string]any) []byte { func EncodeMap(data any) []byte {
raw, _ := jsoniter.Marshal(policy) raw, _ := jsoniter.Marshal(data)
return raw return raw
} }

755
pkg/proto/auth.pb.go Normal file
View File

@ -0,0 +1,755 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.35.1
// protoc v5.28.2
// source: auth.proto
package proto
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
type UserInfo struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Id uint64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
Metadata []byte `protobuf:"bytes,3,opt,name=metadata,proto3,oneof" json:"metadata,omitempty"`
}
func (x *UserInfo) Reset() {
*x = UserInfo{}
mi := &file_auth_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *UserInfo) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*UserInfo) ProtoMessage() {}
func (x *UserInfo) ProtoReflect() protoreflect.Message {
mi := &file_auth_proto_msgTypes[0]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use UserInfo.ProtoReflect.Descriptor instead.
func (*UserInfo) Descriptor() ([]byte, []int) {
return file_auth_proto_rawDescGZIP(), []int{0}
}
func (x *UserInfo) GetId() uint64 {
if x != nil {
return x.Id
}
return 0
}
func (x *UserInfo) GetName() string {
if x != nil {
return x.Name
}
return ""
}
func (x *UserInfo) GetMetadata() []byte {
if x != nil {
return x.Metadata
}
return nil
}
type AuthInfo struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Info *UserInfo `protobuf:"bytes,1,opt,name=info,proto3" json:"info,omitempty"`
PermNodes []byte `protobuf:"bytes,2,opt,name=perm_nodes,json=permNodes,proto3" json:"perm_nodes,omitempty"`
SessionId uint64 `protobuf:"varint,3,opt,name=session_id,json=sessionId,proto3" json:"session_id,omitempty"`
NewAccessToken *string `protobuf:"bytes,4,opt,name=new_access_token,json=newAccessToken,proto3,oneof" json:"new_access_token,omitempty"`
NewRefreshToken *string `protobuf:"bytes,5,opt,name=new_refresh_token,json=newRefreshToken,proto3,oneof" json:"new_refresh_token,omitempty"`
}
func (x *AuthInfo) Reset() {
*x = AuthInfo{}
mi := &file_auth_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *AuthInfo) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*AuthInfo) ProtoMessage() {}
func (x *AuthInfo) ProtoReflect() protoreflect.Message {
mi := &file_auth_proto_msgTypes[1]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use AuthInfo.ProtoReflect.Descriptor instead.
func (*AuthInfo) Descriptor() ([]byte, []int) {
return file_auth_proto_rawDescGZIP(), []int{1}
}
func (x *AuthInfo) GetInfo() *UserInfo {
if x != nil {
return x.Info
}
return nil
}
func (x *AuthInfo) GetPermNodes() []byte {
if x != nil {
return x.PermNodes
}
return nil
}
func (x *AuthInfo) GetSessionId() uint64 {
if x != nil {
return x.SessionId
}
return 0
}
func (x *AuthInfo) GetNewAccessToken() string {
if x != nil && x.NewAccessToken != nil {
return *x.NewAccessToken
}
return ""
}
func (x *AuthInfo) GetNewRefreshToken() string {
if x != nil && x.NewRefreshToken != nil {
return *x.NewRefreshToken
}
return ""
}
type AuthRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
AccessToken string `protobuf:"bytes,1,opt,name=access_token,json=accessToken,proto3" json:"access_token,omitempty"`
RefreshToken *string `protobuf:"bytes,2,opt,name=refresh_token,json=refreshToken,proto3,oneof" json:"refresh_token,omitempty"`
}
func (x *AuthRequest) Reset() {
*x = AuthRequest{}
mi := &file_auth_proto_msgTypes[2]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *AuthRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*AuthRequest) ProtoMessage() {}
func (x *AuthRequest) ProtoReflect() protoreflect.Message {
mi := &file_auth_proto_msgTypes[2]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use AuthRequest.ProtoReflect.Descriptor instead.
func (*AuthRequest) Descriptor() ([]byte, []int) {
return file_auth_proto_rawDescGZIP(), []int{2}
}
func (x *AuthRequest) GetAccessToken() string {
if x != nil {
return x.AccessToken
}
return ""
}
func (x *AuthRequest) GetRefreshToken() string {
if x != nil && x.RefreshToken != nil {
return *x.RefreshToken
}
return ""
}
type AuthReply struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
IsValid bool `protobuf:"varint,1,opt,name=is_valid,json=isValid,proto3" json:"is_valid,omitempty"`
Info *AuthInfo `protobuf:"bytes,2,opt,name=info,proto3,oneof" json:"info,omitempty"`
}
func (x *AuthReply) Reset() {
*x = AuthReply{}
mi := &file_auth_proto_msgTypes[3]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *AuthReply) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*AuthReply) ProtoMessage() {}
func (x *AuthReply) ProtoReflect() protoreflect.Message {
mi := &file_auth_proto_msgTypes[3]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use AuthReply.ProtoReflect.Descriptor instead.
func (*AuthReply) Descriptor() ([]byte, []int) {
return file_auth_proto_rawDescGZIP(), []int{3}
}
func (x *AuthReply) GetIsValid() bool {
if x != nil {
return x.IsValid
}
return false
}
func (x *AuthReply) GetInfo() *AuthInfo {
if x != nil {
return x.Info
}
return nil
}
type CheckPermRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Token string `protobuf:"bytes,1,opt,name=token,proto3" json:"token,omitempty"`
Key string `protobuf:"bytes,2,opt,name=key,proto3" json:"key,omitempty"`
Value []byte `protobuf:"bytes,3,opt,name=value,proto3" json:"value,omitempty"`
}
func (x *CheckPermRequest) Reset() {
*x = CheckPermRequest{}
mi := &file_auth_proto_msgTypes[4]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *CheckPermRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*CheckPermRequest) ProtoMessage() {}
func (x *CheckPermRequest) ProtoReflect() protoreflect.Message {
mi := &file_auth_proto_msgTypes[4]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use CheckPermRequest.ProtoReflect.Descriptor instead.
func (*CheckPermRequest) Descriptor() ([]byte, []int) {
return file_auth_proto_rawDescGZIP(), []int{4}
}
func (x *CheckPermRequest) GetToken() string {
if x != nil {
return x.Token
}
return ""
}
func (x *CheckPermRequest) GetKey() string {
if x != nil {
return x.Key
}
return ""
}
func (x *CheckPermRequest) GetValue() []byte {
if x != nil {
return x.Value
}
return nil
}
type CheckPermResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
IsValid bool `protobuf:"varint,1,opt,name=is_valid,json=isValid,proto3" json:"is_valid,omitempty"`
}
func (x *CheckPermResponse) Reset() {
*x = CheckPermResponse{}
mi := &file_auth_proto_msgTypes[5]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *CheckPermResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*CheckPermResponse) ProtoMessage() {}
func (x *CheckPermResponse) ProtoReflect() protoreflect.Message {
mi := &file_auth_proto_msgTypes[5]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use CheckPermResponse.ProtoReflect.Descriptor instead.
func (*CheckPermResponse) Descriptor() ([]byte, []int) {
return file_auth_proto_rawDescGZIP(), []int{5}
}
func (x *CheckPermResponse) GetIsValid() bool {
if x != nil {
return x.IsValid
}
return false
}
type CheckUserPermRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
UserId uint64 `protobuf:"varint,1,opt,name=user_id,json=userId,proto3" json:"user_id,omitempty"`
OtherId uint64 `protobuf:"varint,2,opt,name=other_id,json=otherId,proto3" json:"other_id,omitempty"`
Key string `protobuf:"bytes,3,opt,name=key,proto3" json:"key,omitempty"`
Value []byte `protobuf:"bytes,4,opt,name=value,proto3" json:"value,omitempty"`
}
func (x *CheckUserPermRequest) Reset() {
*x = CheckUserPermRequest{}
mi := &file_auth_proto_msgTypes[6]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *CheckUserPermRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*CheckUserPermRequest) ProtoMessage() {}
func (x *CheckUserPermRequest) ProtoReflect() protoreflect.Message {
mi := &file_auth_proto_msgTypes[6]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use CheckUserPermRequest.ProtoReflect.Descriptor instead.
func (*CheckUserPermRequest) Descriptor() ([]byte, []int) {
return file_auth_proto_rawDescGZIP(), []int{6}
}
func (x *CheckUserPermRequest) GetUserId() uint64 {
if x != nil {
return x.UserId
}
return 0
}
func (x *CheckUserPermRequest) GetOtherId() uint64 {
if x != nil {
return x.OtherId
}
return 0
}
func (x *CheckUserPermRequest) GetKey() string {
if x != nil {
return x.Key
}
return ""
}
func (x *CheckUserPermRequest) GetValue() []byte {
if x != nil {
return x.Value
}
return nil
}
type CheckUserPermResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
IsValid bool `protobuf:"varint,1,opt,name=is_valid,json=isValid,proto3" json:"is_valid,omitempty"`
}
func (x *CheckUserPermResponse) Reset() {
*x = CheckUserPermResponse{}
mi := &file_auth_proto_msgTypes[7]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *CheckUserPermResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*CheckUserPermResponse) ProtoMessage() {}
func (x *CheckUserPermResponse) ProtoReflect() protoreflect.Message {
mi := &file_auth_proto_msgTypes[7]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use CheckUserPermResponse.ProtoReflect.Descriptor instead.
func (*CheckUserPermResponse) Descriptor() ([]byte, []int) {
return file_auth_proto_rawDescGZIP(), []int{7}
}
func (x *CheckUserPermResponse) GetIsValid() bool {
if x != nil {
return x.IsValid
}
return false
}
type ListUserRelativeRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
UserId uint64 `protobuf:"varint,1,opt,name=user_id,json=userId,proto3" json:"user_id,omitempty"`
Status int32 `protobuf:"varint,2,opt,name=status,proto3" json:"status,omitempty"`
IsRelated bool `protobuf:"varint,3,opt,name=is_related,json=isRelated,proto3" json:"is_related,omitempty"`
}
func (x *ListUserRelativeRequest) Reset() {
*x = ListUserRelativeRequest{}
mi := &file_auth_proto_msgTypes[8]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *ListUserRelativeRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*ListUserRelativeRequest) ProtoMessage() {}
func (x *ListUserRelativeRequest) ProtoReflect() protoreflect.Message {
mi := &file_auth_proto_msgTypes[8]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use ListUserRelativeRequest.ProtoReflect.Descriptor instead.
func (*ListUserRelativeRequest) Descriptor() ([]byte, []int) {
return file_auth_proto_rawDescGZIP(), []int{8}
}
func (x *ListUserRelativeRequest) GetUserId() uint64 {
if x != nil {
return x.UserId
}
return 0
}
func (x *ListUserRelativeRequest) GetStatus() int32 {
if x != nil {
return x.Status
}
return 0
}
func (x *ListUserRelativeRequest) GetIsRelated() bool {
if x != nil {
return x.IsRelated
}
return false
}
type ListUserRelativeResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Data []*UserInfo `protobuf:"bytes,1,rep,name=data,proto3" json:"data,omitempty"`
}
func (x *ListUserRelativeResponse) Reset() {
*x = ListUserRelativeResponse{}
mi := &file_auth_proto_msgTypes[9]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *ListUserRelativeResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*ListUserRelativeResponse) ProtoMessage() {}
func (x *ListUserRelativeResponse) ProtoReflect() protoreflect.Message {
mi := &file_auth_proto_msgTypes[9]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use ListUserRelativeResponse.ProtoReflect.Descriptor instead.
func (*ListUserRelativeResponse) Descriptor() ([]byte, []int) {
return file_auth_proto_rawDescGZIP(), []int{9}
}
func (x *ListUserRelativeResponse) GetData() []*UserInfo {
if x != nil {
return x.Data
}
return nil
}
var File_auth_proto protoreflect.FileDescriptor
var file_auth_proto_rawDesc = []byte{
0x0a, 0x0a, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x05, 0x70, 0x72,
0x6f, 0x74, 0x6f, 0x22, 0x5c, 0x0a, 0x08, 0x55, 0x73, 0x65, 0x72, 0x49, 0x6e, 0x66, 0x6f, 0x12,
0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x02, 0x69, 0x64, 0x12,
0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e,
0x61, 0x6d, 0x65, 0x12, 0x1f, 0x0a, 0x08, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x18,
0x03, 0x20, 0x01, 0x28, 0x0c, 0x48, 0x00, 0x52, 0x08, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74,
0x61, 0x88, 0x01, 0x01, 0x42, 0x0b, 0x0a, 0x09, 0x5f, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74,
0x61, 0x22, 0xf8, 0x01, 0x0a, 0x08, 0x41, 0x75, 0x74, 0x68, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x23,
0x0a, 0x04, 0x69, 0x6e, 0x66, 0x6f, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x70,
0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x04, 0x69,
0x6e, 0x66, 0x6f, 0x12, 0x1d, 0x0a, 0x0a, 0x70, 0x65, 0x72, 0x6d, 0x5f, 0x6e, 0x6f, 0x64, 0x65,
0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x09, 0x70, 0x65, 0x72, 0x6d, 0x4e, 0x6f, 0x64,
0x65, 0x73, 0x12, 0x1d, 0x0a, 0x0a, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x5f, 0x69, 0x64,
0x18, 0x03, 0x20, 0x01, 0x28, 0x04, 0x52, 0x09, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49,
0x64, 0x12, 0x2d, 0x0a, 0x10, 0x6e, 0x65, 0x77, 0x5f, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x5f,
0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x48, 0x00, 0x52, 0x0e, 0x6e,
0x65, 0x77, 0x41, 0x63, 0x63, 0x65, 0x73, 0x73, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x88, 0x01, 0x01,
0x12, 0x2f, 0x0a, 0x11, 0x6e, 0x65, 0x77, 0x5f, 0x72, 0x65, 0x66, 0x72, 0x65, 0x73, 0x68, 0x5f,
0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x48, 0x01, 0x52, 0x0f, 0x6e,
0x65, 0x77, 0x52, 0x65, 0x66, 0x72, 0x65, 0x73, 0x68, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x88, 0x01,
0x01, 0x42, 0x13, 0x0a, 0x11, 0x5f, 0x6e, 0x65, 0x77, 0x5f, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73,
0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x42, 0x14, 0x0a, 0x12, 0x5f, 0x6e, 0x65, 0x77, 0x5f, 0x72,
0x65, 0x66, 0x72, 0x65, 0x73, 0x68, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x22, 0x6c, 0x0a, 0x0b,
0x41, 0x75, 0x74, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x21, 0x0a, 0x0c, 0x61,
0x63, 0x63, 0x65, 0x73, 0x73, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28,
0x09, 0x52, 0x0b, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x28,
0x0a, 0x0d, 0x72, 0x65, 0x66, 0x72, 0x65, 0x73, 0x68, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18,
0x02, 0x20, 0x01, 0x28, 0x09, 0x48, 0x00, 0x52, 0x0c, 0x72, 0x65, 0x66, 0x72, 0x65, 0x73, 0x68,
0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x88, 0x01, 0x01, 0x42, 0x10, 0x0a, 0x0e, 0x5f, 0x72, 0x65, 0x66,
0x72, 0x65, 0x73, 0x68, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x22, 0x59, 0x0a, 0x09, 0x41, 0x75,
0x74, 0x68, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x19, 0x0a, 0x08, 0x69, 0x73, 0x5f, 0x76, 0x61,
0x6c, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x69, 0x73, 0x56, 0x61, 0x6c,
0x69, 0x64, 0x12, 0x28, 0x0a, 0x04, 0x69, 0x6e, 0x66, 0x6f, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b,
0x32, 0x0f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x41, 0x75, 0x74, 0x68, 0x49, 0x6e, 0x66,
0x6f, 0x48, 0x00, 0x52, 0x04, 0x69, 0x6e, 0x66, 0x6f, 0x88, 0x01, 0x01, 0x42, 0x07, 0x0a, 0x05,
0x5f, 0x69, 0x6e, 0x66, 0x6f, 0x22, 0x50, 0x0a, 0x10, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x50, 0x65,
0x72, 0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, 0x6b,
0x65, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x12,
0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65,
0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c,
0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x2e, 0x0a, 0x11, 0x43, 0x68, 0x65, 0x63, 0x6b,
0x50, 0x65, 0x72, 0x6d, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x19, 0x0a, 0x08,
0x69, 0x73, 0x5f, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07,
0x69, 0x73, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x22, 0x72, 0x0a, 0x14, 0x43, 0x68, 0x65, 0x63, 0x6b,
0x55, 0x73, 0x65, 0x72, 0x50, 0x65, 0x72, 0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12,
0x17, 0x0a, 0x07, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04,
0x52, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x19, 0x0a, 0x08, 0x6f, 0x74, 0x68, 0x65,
0x72, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x07, 0x6f, 0x74, 0x68, 0x65,
0x72, 0x49, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09,
0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x04,
0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x32, 0x0a, 0x15, 0x43,
0x68, 0x65, 0x63, 0x6b, 0x55, 0x73, 0x65, 0x72, 0x50, 0x65, 0x72, 0x6d, 0x52, 0x65, 0x73, 0x70,
0x6f, 0x6e, 0x73, 0x65, 0x12, 0x19, 0x0a, 0x08, 0x69, 0x73, 0x5f, 0x76, 0x61, 0x6c, 0x69, 0x64,
0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x69, 0x73, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x22,
0x69, 0x0a, 0x17, 0x4c, 0x69, 0x73, 0x74, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x6c, 0x61, 0x74,
0x69, 0x76, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x17, 0x0a, 0x07, 0x75, 0x73,
0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x06, 0x75, 0x73, 0x65,
0x72, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x02, 0x20,
0x01, 0x28, 0x05, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x1d, 0x0a, 0x0a, 0x69,
0x73, 0x5f, 0x72, 0x65, 0x6c, 0x61, 0x74, 0x65, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52,
0x09, 0x69, 0x73, 0x52, 0x65, 0x6c, 0x61, 0x74, 0x65, 0x64, 0x22, 0x3f, 0x0a, 0x18, 0x4c, 0x69,
0x73, 0x74, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x76, 0x65, 0x52, 0x65,
0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x23, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01,
0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x55, 0x73, 0x65,
0x72, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x32, 0xb5, 0x02, 0x0a, 0x04,
0x41, 0x75, 0x74, 0x68, 0x12, 0x36, 0x0a, 0x0c, 0x41, 0x75, 0x74, 0x68, 0x65, 0x6e, 0x74, 0x69,
0x63, 0x61, 0x74, 0x65, 0x12, 0x12, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x41, 0x75, 0x74,
0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x10, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x2e, 0x41, 0x75, 0x74, 0x68, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x12, 0x48, 0x0a, 0x11,
0x45, 0x6e, 0x73, 0x75, 0x72, 0x65, 0x50, 0x65, 0x72, 0x6d, 0x47, 0x72, 0x61, 0x6e, 0x74, 0x65,
0x64, 0x12, 0x17, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x50,
0x65, 0x72, 0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x70, 0x72, 0x6f,
0x74, 0x6f, 0x2e, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x50, 0x65, 0x72, 0x6d, 0x52, 0x65, 0x73, 0x70,
0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x54, 0x0a, 0x15, 0x45, 0x6e, 0x73, 0x75, 0x72, 0x65,
0x55, 0x73, 0x65, 0x72, 0x50, 0x65, 0x72, 0x6d, 0x47, 0x72, 0x61, 0x6e, 0x74, 0x65, 0x64, 0x12,
0x1b, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x55, 0x73, 0x65,
0x72, 0x50, 0x65, 0x72, 0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1c, 0x2e, 0x70,
0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x55, 0x73, 0x65, 0x72, 0x50, 0x65,
0x72, 0x6d, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x55, 0x0a, 0x10,
0x4c, 0x69, 0x73, 0x74, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x76, 0x65,
0x12, 0x1e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x55, 0x73, 0x65,
0x72, 0x52, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x76, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74,
0x1a, 0x1f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x55, 0x73, 0x65,
0x72, 0x52, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x76, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73,
0x65, 0x22, 0x00, 0x42, 0x09, 0x5a, 0x07, 0x2e, 0x3b, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
file_auth_proto_rawDescOnce sync.Once
file_auth_proto_rawDescData = file_auth_proto_rawDesc
)
func file_auth_proto_rawDescGZIP() []byte {
file_auth_proto_rawDescOnce.Do(func() {
file_auth_proto_rawDescData = protoimpl.X.CompressGZIP(file_auth_proto_rawDescData)
})
return file_auth_proto_rawDescData
}
var file_auth_proto_msgTypes = make([]protoimpl.MessageInfo, 10)
var file_auth_proto_goTypes = []any{
(*UserInfo)(nil), // 0: proto.UserInfo
(*AuthInfo)(nil), // 1: proto.AuthInfo
(*AuthRequest)(nil), // 2: proto.AuthRequest
(*AuthReply)(nil), // 3: proto.AuthReply
(*CheckPermRequest)(nil), // 4: proto.CheckPermRequest
(*CheckPermResponse)(nil), // 5: proto.CheckPermResponse
(*CheckUserPermRequest)(nil), // 6: proto.CheckUserPermRequest
(*CheckUserPermResponse)(nil), // 7: proto.CheckUserPermResponse
(*ListUserRelativeRequest)(nil), // 8: proto.ListUserRelativeRequest
(*ListUserRelativeResponse)(nil), // 9: proto.ListUserRelativeResponse
}
var file_auth_proto_depIdxs = []int32{
0, // 0: proto.AuthInfo.info:type_name -> proto.UserInfo
1, // 1: proto.AuthReply.info:type_name -> proto.AuthInfo
0, // 2: proto.ListUserRelativeResponse.data:type_name -> proto.UserInfo
2, // 3: proto.Auth.Authenticate:input_type -> proto.AuthRequest
4, // 4: proto.Auth.EnsurePermGranted:input_type -> proto.CheckPermRequest
6, // 5: proto.Auth.EnsureUserPermGranted:input_type -> proto.CheckUserPermRequest
8, // 6: proto.Auth.ListUserRelative:input_type -> proto.ListUserRelativeRequest
3, // 7: proto.Auth.Authenticate:output_type -> proto.AuthReply
5, // 8: proto.Auth.EnsurePermGranted:output_type -> proto.CheckPermResponse
7, // 9: proto.Auth.EnsureUserPermGranted:output_type -> proto.CheckUserPermResponse
9, // 10: proto.Auth.ListUserRelative:output_type -> proto.ListUserRelativeResponse
7, // [7:11] is the sub-list for method output_type
3, // [3:7] is the sub-list for method input_type
3, // [3:3] is the sub-list for extension type_name
3, // [3:3] is the sub-list for extension extendee
0, // [0:3] is the sub-list for field type_name
}
func init() { file_auth_proto_init() }
func file_auth_proto_init() {
if File_auth_proto != nil {
return
}
file_auth_proto_msgTypes[0].OneofWrappers = []any{}
file_auth_proto_msgTypes[1].OneofWrappers = []any{}
file_auth_proto_msgTypes[2].OneofWrappers = []any{}
file_auth_proto_msgTypes[3].OneofWrappers = []any{}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_auth_proto_rawDesc,
NumEnums: 0,
NumMessages: 10,
NumExtensions: 0,
NumServices: 1,
},
GoTypes: file_auth_proto_goTypes,
DependencyIndexes: file_auth_proto_depIdxs,
MessageInfos: file_auth_proto_msgTypes,
}.Build()
File_auth_proto = out.File
file_auth_proto_rawDesc = nil
file_auth_proto_goTypes = nil
file_auth_proto_depIdxs = nil
}

67
pkg/proto/auth.proto Normal file
View File

@ -0,0 +1,67 @@
syntax = "proto3";
option go_package = ".;proto";
package proto;
service Auth {
rpc Authenticate(AuthRequest) returns (AuthReply) {}
rpc EnsurePermGranted(CheckPermRequest) returns (CheckPermResponse) {}
rpc EnsureUserPermGranted(CheckUserPermRequest) returns (CheckUserPermResponse) {}
rpc ListUserRelative(ListUserRelativeRequest) returns (ListUserRelativeResponse) {}
}
message UserInfo {
uint64 id = 1;
string name = 2;
optional bytes metadata = 3;
}
message AuthInfo {
UserInfo info = 1;
bytes perm_nodes = 2;
uint64 session_id = 3;
optional string new_access_token = 4;
optional string new_refresh_token = 5;
}
message AuthRequest {
string access_token = 1;
optional string refresh_token = 2;
}
message AuthReply {
bool is_valid = 1;
optional AuthInfo info = 2;
}
message CheckPermRequest {
string token = 1;
string key = 2;
bytes value = 3;
}
message CheckPermResponse {
bool is_valid = 1;
}
message CheckUserPermRequest {
uint64 user_id = 1;
uint64 other_id = 2;
string key = 3;
bytes value = 4;
}
message CheckUserPermResponse {
bool is_valid = 1;
}
message ListUserRelativeRequest {
uint64 user_id = 1;
int32 status = 2;
bool is_related = 3;
}
message ListUserRelativeResponse {
repeated UserInfo data = 1;
}

235
pkg/proto/auth_grpc.pb.go Normal file
View File

@ -0,0 +1,235 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.5.1
// - protoc v5.28.2
// source: auth.proto
package proto
import (
context "context"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
)
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
// Requires gRPC-Go v1.64.0 or later.
const _ = grpc.SupportPackageIsVersion9
const (
Auth_Authenticate_FullMethodName = "/proto.Auth/Authenticate"
Auth_EnsurePermGranted_FullMethodName = "/proto.Auth/EnsurePermGranted"
Auth_EnsureUserPermGranted_FullMethodName = "/proto.Auth/EnsureUserPermGranted"
Auth_ListUserRelative_FullMethodName = "/proto.Auth/ListUserRelative"
)
// AuthClient is the client API for Auth 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 AuthClient interface {
Authenticate(ctx context.Context, in *AuthRequest, opts ...grpc.CallOption) (*AuthReply, error)
EnsurePermGranted(ctx context.Context, in *CheckPermRequest, opts ...grpc.CallOption) (*CheckPermResponse, error)
EnsureUserPermGranted(ctx context.Context, in *CheckUserPermRequest, opts ...grpc.CallOption) (*CheckUserPermResponse, error)
ListUserRelative(ctx context.Context, in *ListUserRelativeRequest, opts ...grpc.CallOption) (*ListUserRelativeResponse, error)
}
type authClient struct {
cc grpc.ClientConnInterface
}
func NewAuthClient(cc grpc.ClientConnInterface) AuthClient {
return &authClient{cc}
}
func (c *authClient) Authenticate(ctx context.Context, in *AuthRequest, opts ...grpc.CallOption) (*AuthReply, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(AuthReply)
err := c.cc.Invoke(ctx, Auth_Authenticate_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *authClient) EnsurePermGranted(ctx context.Context, in *CheckPermRequest, opts ...grpc.CallOption) (*CheckPermResponse, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(CheckPermResponse)
err := c.cc.Invoke(ctx, Auth_EnsurePermGranted_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *authClient) EnsureUserPermGranted(ctx context.Context, in *CheckUserPermRequest, opts ...grpc.CallOption) (*CheckUserPermResponse, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(CheckUserPermResponse)
err := c.cc.Invoke(ctx, Auth_EnsureUserPermGranted_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *authClient) ListUserRelative(ctx context.Context, in *ListUserRelativeRequest, opts ...grpc.CallOption) (*ListUserRelativeResponse, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(ListUserRelativeResponse)
err := c.cc.Invoke(ctx, Auth_ListUserRelative_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
// AuthServer is the server API for Auth service.
// All implementations must embed UnimplementedAuthServer
// for forward compatibility.
type AuthServer interface {
Authenticate(context.Context, *AuthRequest) (*AuthReply, error)
EnsurePermGranted(context.Context, *CheckPermRequest) (*CheckPermResponse, error)
EnsureUserPermGranted(context.Context, *CheckUserPermRequest) (*CheckUserPermResponse, error)
ListUserRelative(context.Context, *ListUserRelativeRequest) (*ListUserRelativeResponse, error)
mustEmbedUnimplementedAuthServer()
}
// UnimplementedAuthServer must be embedded to have
// forward compatible implementations.
//
// NOTE: this should be embedded by value instead of pointer to avoid a nil
// pointer dereference when methods are called.
type UnimplementedAuthServer struct{}
func (UnimplementedAuthServer) Authenticate(context.Context, *AuthRequest) (*AuthReply, error) {
return nil, status.Errorf(codes.Unimplemented, "method Authenticate not implemented")
}
func (UnimplementedAuthServer) EnsurePermGranted(context.Context, *CheckPermRequest) (*CheckPermResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method EnsurePermGranted not implemented")
}
func (UnimplementedAuthServer) EnsureUserPermGranted(context.Context, *CheckUserPermRequest) (*CheckUserPermResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method EnsureUserPermGranted not implemented")
}
func (UnimplementedAuthServer) ListUserRelative(context.Context, *ListUserRelativeRequest) (*ListUserRelativeResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method ListUserRelative not implemented")
}
func (UnimplementedAuthServer) mustEmbedUnimplementedAuthServer() {}
func (UnimplementedAuthServer) testEmbeddedByValue() {}
// UnsafeAuthServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to AuthServer will
// result in compilation errors.
type UnsafeAuthServer interface {
mustEmbedUnimplementedAuthServer()
}
func RegisterAuthServer(s grpc.ServiceRegistrar, srv AuthServer) {
// If the following call pancis, it indicates UnimplementedAuthServer was
// embedded by pointer and is nil. This will cause panics if an
// unimplemented method is ever invoked, so we test this at initialization
// time to prevent it from happening at runtime later due to I/O.
if t, ok := srv.(interface{ testEmbeddedByValue() }); ok {
t.testEmbeddedByValue()
}
s.RegisterService(&Auth_ServiceDesc, srv)
}
func _Auth_Authenticate_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(AuthRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(AuthServer).Authenticate(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Auth_Authenticate_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(AuthServer).Authenticate(ctx, req.(*AuthRequest))
}
return interceptor(ctx, in, info, handler)
}
func _Auth_EnsurePermGranted_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(CheckPermRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(AuthServer).EnsurePermGranted(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Auth_EnsurePermGranted_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(AuthServer).EnsurePermGranted(ctx, req.(*CheckPermRequest))
}
return interceptor(ctx, in, info, handler)
}
func _Auth_EnsureUserPermGranted_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(CheckUserPermRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(AuthServer).EnsureUserPermGranted(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Auth_EnsureUserPermGranted_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(AuthServer).EnsureUserPermGranted(ctx, req.(*CheckUserPermRequest))
}
return interceptor(ctx, in, info, handler)
}
func _Auth_ListUserRelative_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(ListUserRelativeRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(AuthServer).ListUserRelative(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Auth_ListUserRelative_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(AuthServer).ListUserRelative(ctx, req.(*ListUserRelativeRequest))
}
return interceptor(ctx, in, info, handler)
}
// Auth_ServiceDesc is the grpc.ServiceDesc for Auth service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
var Auth_ServiceDesc = grpc.ServiceDesc{
ServiceName: "proto.Auth",
HandlerType: (*AuthServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "Authenticate",
Handler: _Auth_Authenticate_Handler,
},
{
MethodName: "EnsurePermGranted",
Handler: _Auth_EnsurePermGranted_Handler,
},
{
MethodName: "EnsureUserPermGranted",
Handler: _Auth_EnsureUserPermGranted_Handler,
},
{
MethodName: "ListUserRelative",
Handler: _Auth_ListUserRelative_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "auth.proto",
}

View File

@ -420,6 +420,95 @@ func (x *RemoveServiceResponse) GetIsSuccess() bool {
return false return false
} }
type EventInfo struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Event string `protobuf:"bytes,1,opt,name=event,proto3" json:"event,omitempty"`
Data []byte `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"`
}
func (x *EventInfo) Reset() {
*x = EventInfo{}
mi := &file_services_proto_msgTypes[8]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *EventInfo) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*EventInfo) ProtoMessage() {}
func (x *EventInfo) ProtoReflect() protoreflect.Message {
mi := &file_services_proto_msgTypes[8]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use EventInfo.ProtoReflect.Descriptor instead.
func (*EventInfo) Descriptor() ([]byte, []int) {
return file_services_proto_rawDescGZIP(), []int{8}
}
func (x *EventInfo) GetEvent() string {
if x != nil {
return x.Event
}
return ""
}
func (x *EventInfo) GetData() []byte {
if x != nil {
return x.Data
}
return nil
}
type EventResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
}
func (x *EventResponse) Reset() {
*x = EventResponse{}
mi := &file_services_proto_msgTypes[9]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *EventResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*EventResponse) ProtoMessage() {}
func (x *EventResponse) ProtoReflect() protoreflect.Message {
mi := &file_services_proto_msgTypes[9]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use EventResponse.ProtoReflect.Descriptor instead.
func (*EventResponse) Descriptor() ([]byte, []int) {
return file_services_proto_rawDescGZIP(), []int{9}
}
var File_services_proto protoreflect.FileDescriptor var File_services_proto protoreflect.FileDescriptor
var file_services_proto_rawDesc = []byte{ var file_services_proto_rawDesc = []byte{
@ -459,27 +548,36 @@ var file_services_proto_rawDesc = []byte{
0x02, 0x69, 0x64, 0x22, 0x36, 0x0a, 0x15, 0x52, 0x65, 0x6d, 0x6f, 0x76, 0x65, 0x53, 0x65, 0x72, 0x02, 0x69, 0x64, 0x22, 0x36, 0x0a, 0x15, 0x52, 0x65, 0x6d, 0x6f, 0x76, 0x65, 0x53, 0x65, 0x72,
0x76, 0x69, 0x63, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1d, 0x0a, 0x0a, 0x76, 0x69, 0x63, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1d, 0x0a, 0x0a,
0x69, 0x73, 0x5f, 0x73, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x69, 0x73, 0x5f, 0x73, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08,
0x52, 0x09, 0x69, 0x73, 0x53, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x32, 0xac, 0x02, 0x0a, 0x10, 0x52, 0x09, 0x69, 0x73, 0x53, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x22, 0x35, 0x0a, 0x09, 0x45,
0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x44, 0x69, 0x72, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x79, 0x76, 0x65, 0x6e, 0x74, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x76, 0x65, 0x6e,
0x12, 0x43, 0x0a, 0x0a, 0x47, 0x65, 0x74, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x18, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x12,
0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x47, 0x65, 0x74, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x64, 0x61,
0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x19, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x74, 0x61, 0x22, 0x0f, 0x0a, 0x0d, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f,
0x2e, 0x47, 0x65, 0x74, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x32, 0xe8, 0x02, 0x0a, 0x10, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x44,
0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x46, 0x0a, 0x0b, 0x4c, 0x69, 0x73, 0x74, 0x53, 0x65, 0x72, 0x69, 0x72, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x79, 0x12, 0x43, 0x0a, 0x0a, 0x47, 0x65, 0x74, 0x53,
0x76, 0x69, 0x63, 0x65, 0x12, 0x19, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x4c, 0x69, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x18, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x47,
0x74, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x65, 0x74, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74,
0x1a, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x53, 0x65, 0x72, 0x76, 0x1a, 0x19, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x47, 0x65, 0x74, 0x53, 0x65, 0x72, 0x76,
0x69, 0x63, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x3d, 0x0a, 0x69, 0x63, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x46, 0x0a,
0x0a, 0x41, 0x64, 0x64, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x12, 0x2e, 0x70, 0x72, 0x0b, 0x4c, 0x69, 0x73, 0x74, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x19, 0x2e, 0x70,
0x6f, 0x74, 0x6f, 0x2e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x1a, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65,
0x19, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x41, 0x64, 0x64, 0x53, 0x65, 0x72, 0x76, 0x69, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1a, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e,
0x63, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x4c, 0x0a, 0x0d, 0x4c, 0x69, 0x73, 0x74, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f,
0x52, 0x65, 0x6d, 0x6f, 0x76, 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x1b, 0x2e, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x3d, 0x0a, 0x0a, 0x41, 0x64, 0x64, 0x53, 0x65, 0x72, 0x76,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x52, 0x65, 0x6d, 0x6f, 0x76, 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x12, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x53, 0x65, 0x72, 0x76,
0x69, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1c, 0x2e, 0x70, 0x72, 0x6f, 0x69, 0x63, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x1a, 0x19, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e,
0x74, 0x6f, 0x2e, 0x52, 0x65, 0x6d, 0x6f, 0x76, 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x41, 0x64, 0x64, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e,
0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x09, 0x5a, 0x07, 0x2e, 0x3b, 0x73, 0x65, 0x22, 0x00, 0x12, 0x4c, 0x0a, 0x0d, 0x52, 0x65, 0x6d, 0x6f, 0x76, 0x65, 0x53, 0x65,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x1b, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x52, 0x65,
0x6d, 0x6f, 0x76, 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65,
0x73, 0x74, 0x1a, 0x1c, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x52, 0x65, 0x6d, 0x6f, 0x76,
0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65,
0x22, 0x00, 0x12, 0x3a, 0x0a, 0x0e, 0x42, 0x72, 0x6f, 0x61, 0x64, 0x63, 0x61, 0x73, 0x74, 0x45,
0x76, 0x65, 0x6e, 0x74, 0x12, 0x10, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x45, 0x76, 0x65,
0x6e, 0x74, 0x49, 0x6e, 0x66, 0x6f, 0x1a, 0x14, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x45,
0x76, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x09,
0x5a, 0x07, 0x2e, 0x3b, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x33,
} }
var ( var (
@ -494,7 +592,7 @@ func file_services_proto_rawDescGZIP() []byte {
return file_services_proto_rawDescData return file_services_proto_rawDescData
} }
var file_services_proto_msgTypes = make([]protoimpl.MessageInfo, 8) var file_services_proto_msgTypes = make([]protoimpl.MessageInfo, 10)
var file_services_proto_goTypes = []any{ var file_services_proto_goTypes = []any{
(*ServiceInfo)(nil), // 0: proto.ServiceInfo (*ServiceInfo)(nil), // 0: proto.ServiceInfo
(*GetServiceRequest)(nil), // 1: proto.GetServiceRequest (*GetServiceRequest)(nil), // 1: proto.GetServiceRequest
@ -504,6 +602,8 @@ var file_services_proto_goTypes = []any{
(*AddServiceResponse)(nil), // 5: proto.AddServiceResponse (*AddServiceResponse)(nil), // 5: proto.AddServiceResponse
(*RemoveServiceRequest)(nil), // 6: proto.RemoveServiceRequest (*RemoveServiceRequest)(nil), // 6: proto.RemoveServiceRequest
(*RemoveServiceResponse)(nil), // 7: proto.RemoveServiceResponse (*RemoveServiceResponse)(nil), // 7: proto.RemoveServiceResponse
(*EventInfo)(nil), // 8: proto.EventInfo
(*EventResponse)(nil), // 9: proto.EventResponse
} }
var file_services_proto_depIdxs = []int32{ var file_services_proto_depIdxs = []int32{
0, // 0: proto.GetServiceResponse.data:type_name -> proto.ServiceInfo 0, // 0: proto.GetServiceResponse.data:type_name -> proto.ServiceInfo
@ -512,12 +612,14 @@ var file_services_proto_depIdxs = []int32{
3, // 3: proto.ServiceDirectory.ListService:input_type -> proto.ListServiceRequest 3, // 3: proto.ServiceDirectory.ListService:input_type -> proto.ListServiceRequest
0, // 4: proto.ServiceDirectory.AddService:input_type -> proto.ServiceInfo 0, // 4: proto.ServiceDirectory.AddService:input_type -> proto.ServiceInfo
6, // 5: proto.ServiceDirectory.RemoveService:input_type -> proto.RemoveServiceRequest 6, // 5: proto.ServiceDirectory.RemoveService:input_type -> proto.RemoveServiceRequest
2, // 6: proto.ServiceDirectory.GetService:output_type -> proto.GetServiceResponse 8, // 6: proto.ServiceDirectory.BroadcastEvent:input_type -> proto.EventInfo
4, // 7: proto.ServiceDirectory.ListService:output_type -> proto.ListServiceResponse 2, // 7: proto.ServiceDirectory.GetService:output_type -> proto.GetServiceResponse
5, // 8: proto.ServiceDirectory.AddService:output_type -> proto.AddServiceResponse 4, // 8: proto.ServiceDirectory.ListService:output_type -> proto.ListServiceResponse
7, // 9: proto.ServiceDirectory.RemoveService:output_type -> proto.RemoveServiceResponse 5, // 9: proto.ServiceDirectory.AddService:output_type -> proto.AddServiceResponse
6, // [6:10] is the sub-list for method output_type 7, // 10: proto.ServiceDirectory.RemoveService:output_type -> proto.RemoveServiceResponse
2, // [2:6] is the sub-list for method input_type 9, // 11: proto.ServiceDirectory.BroadcastEvent:output_type -> proto.EventResponse
7, // [7:12] is the sub-list for method output_type
2, // [2:7] is the sub-list for method input_type
2, // [2:2] is the sub-list for extension type_name 2, // [2:2] is the sub-list for extension type_name
2, // [2:2] is the sub-list for extension extendee 2, // [2:2] is the sub-list for extension extendee
0, // [0:2] is the sub-list for field type_name 0, // [0:2] is the sub-list for field type_name
@ -537,7 +639,7 @@ func file_services_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(), GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_services_proto_rawDesc, RawDescriptor: file_services_proto_rawDesc,
NumEnums: 0, NumEnums: 0,
NumMessages: 8, NumMessages: 10,
NumExtensions: 0, NumExtensions: 0,
NumServices: 1, NumServices: 1,
}, },

View File

@ -9,6 +9,7 @@ service ServiceDirectory {
rpc ListService(ListServiceRequest) returns (ListServiceResponse) {} rpc ListService(ListServiceRequest) returns (ListServiceResponse) {}
rpc AddService(ServiceInfo) returns (AddServiceResponse) {} rpc AddService(ServiceInfo) returns (AddServiceResponse) {}
rpc RemoveService(RemoveServiceRequest) returns (RemoveServiceResponse) {} rpc RemoveService(RemoveServiceRequest) returns (RemoveServiceResponse) {}
rpc BroadcastEvent(EventInfo) returns (EventResponse) {}
} }
message ServiceInfo { message ServiceInfo {
@ -41,10 +42,17 @@ message AddServiceResponse {
} }
message RemoveServiceRequest { message RemoveServiceRequest {
string id =1; string id = 1;
} }
message RemoveServiceResponse { message RemoveServiceResponse {
bool is_success = 1; bool is_success = 1;
} }
message EventInfo {
string event = 1;
bytes data = 2;
}
message EventResponse {
}

View File

@ -23,6 +23,7 @@ const (
ServiceDirectory_ListService_FullMethodName = "/proto.ServiceDirectory/ListService" ServiceDirectory_ListService_FullMethodName = "/proto.ServiceDirectory/ListService"
ServiceDirectory_AddService_FullMethodName = "/proto.ServiceDirectory/AddService" ServiceDirectory_AddService_FullMethodName = "/proto.ServiceDirectory/AddService"
ServiceDirectory_RemoveService_FullMethodName = "/proto.ServiceDirectory/RemoveService" ServiceDirectory_RemoveService_FullMethodName = "/proto.ServiceDirectory/RemoveService"
ServiceDirectory_BroadcastEvent_FullMethodName = "/proto.ServiceDirectory/BroadcastEvent"
) )
// ServiceDirectoryClient is the client API for ServiceDirectory service. // ServiceDirectoryClient is the client API for ServiceDirectory service.
@ -33,6 +34,7 @@ type ServiceDirectoryClient interface {
ListService(ctx context.Context, in *ListServiceRequest, opts ...grpc.CallOption) (*ListServiceResponse, error) ListService(ctx context.Context, in *ListServiceRequest, opts ...grpc.CallOption) (*ListServiceResponse, error)
AddService(ctx context.Context, in *ServiceInfo, opts ...grpc.CallOption) (*AddServiceResponse, error) AddService(ctx context.Context, in *ServiceInfo, opts ...grpc.CallOption) (*AddServiceResponse, error)
RemoveService(ctx context.Context, in *RemoveServiceRequest, opts ...grpc.CallOption) (*RemoveServiceResponse, error) RemoveService(ctx context.Context, in *RemoveServiceRequest, opts ...grpc.CallOption) (*RemoveServiceResponse, error)
BroadcastEvent(ctx context.Context, in *EventInfo, opts ...grpc.CallOption) (*EventResponse, error)
} }
type serviceDirectoryClient struct { type serviceDirectoryClient struct {
@ -83,6 +85,16 @@ func (c *serviceDirectoryClient) RemoveService(ctx context.Context, in *RemoveSe
return out, nil return out, nil
} }
func (c *serviceDirectoryClient) BroadcastEvent(ctx context.Context, in *EventInfo, opts ...grpc.CallOption) (*EventResponse, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(EventResponse)
err := c.cc.Invoke(ctx, ServiceDirectory_BroadcastEvent_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
// ServiceDirectoryServer is the server API for ServiceDirectory service. // ServiceDirectoryServer is the server API for ServiceDirectory service.
// All implementations must embed UnimplementedServiceDirectoryServer // All implementations must embed UnimplementedServiceDirectoryServer
// for forward compatibility. // for forward compatibility.
@ -91,6 +103,7 @@ type ServiceDirectoryServer interface {
ListService(context.Context, *ListServiceRequest) (*ListServiceResponse, error) ListService(context.Context, *ListServiceRequest) (*ListServiceResponse, error)
AddService(context.Context, *ServiceInfo) (*AddServiceResponse, error) AddService(context.Context, *ServiceInfo) (*AddServiceResponse, error)
RemoveService(context.Context, *RemoveServiceRequest) (*RemoveServiceResponse, error) RemoveService(context.Context, *RemoveServiceRequest) (*RemoveServiceResponse, error)
BroadcastEvent(context.Context, *EventInfo) (*EventResponse, error)
mustEmbedUnimplementedServiceDirectoryServer() mustEmbedUnimplementedServiceDirectoryServer()
} }
@ -113,6 +126,9 @@ func (UnimplementedServiceDirectoryServer) AddService(context.Context, *ServiceI
func (UnimplementedServiceDirectoryServer) RemoveService(context.Context, *RemoveServiceRequest) (*RemoveServiceResponse, error) { func (UnimplementedServiceDirectoryServer) RemoveService(context.Context, *RemoveServiceRequest) (*RemoveServiceResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method RemoveService not implemented") return nil, status.Errorf(codes.Unimplemented, "method RemoveService not implemented")
} }
func (UnimplementedServiceDirectoryServer) BroadcastEvent(context.Context, *EventInfo) (*EventResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method BroadcastEvent not implemented")
}
func (UnimplementedServiceDirectoryServer) mustEmbedUnimplementedServiceDirectoryServer() {} func (UnimplementedServiceDirectoryServer) mustEmbedUnimplementedServiceDirectoryServer() {}
func (UnimplementedServiceDirectoryServer) testEmbeddedByValue() {} func (UnimplementedServiceDirectoryServer) testEmbeddedByValue() {}
@ -206,6 +222,24 @@ func _ServiceDirectory_RemoveService_Handler(srv interface{}, ctx context.Contex
return interceptor(ctx, in, info, handler) return interceptor(ctx, in, info, handler)
} }
func _ServiceDirectory_BroadcastEvent_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(EventInfo)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(ServiceDirectoryServer).BroadcastEvent(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: ServiceDirectory_BroadcastEvent_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(ServiceDirectoryServer).BroadcastEvent(ctx, req.(*EventInfo))
}
return interceptor(ctx, in, info, handler)
}
// ServiceDirectory_ServiceDesc is the grpc.ServiceDesc for ServiceDirectory service. // ServiceDirectory_ServiceDesc is the grpc.ServiceDesc for ServiceDirectory service.
// It's only intended for direct use with grpc.RegisterService, // It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy) // and not to be introspected or modified (even as a copy)
@ -229,6 +263,10 @@ var ServiceDirectory_ServiceDesc = grpc.ServiceDesc{
MethodName: "RemoveService", MethodName: "RemoveService",
Handler: _ServiceDirectory_RemoveService_Handler, Handler: _ServiceDirectory_RemoveService_Handler,
}, },
{
MethodName: "BroadcastEvent",
Handler: _ServiceDirectory_BroadcastEvent_Handler,
},
}, },
Streams: []grpc.StreamDesc{}, Streams: []grpc.StreamDesc{},
Metadata: "services.proto", Metadata: "services.proto",

View File

@ -20,6 +20,9 @@ cookie_samesite = "Lax"
access_token_duration = 300 access_token_duration = 300
refresh_token_duration = 2592000 refresh_token_duration = 2592000
[services]
aliases = { id = "auth", uc = "files", co = "interactive", im = "messaging" }
[database] [database]
dsn = "host=localhost user=postgres dbname=postgres password=password port=5432 sslmode=disable" dsn = "host=localhost user=postgres dbname=postgres password=password port=5432 sslmode=disable"
prefix = "sn_" prefix = "sn_"