diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..51fbfcc --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,5 @@ +{ + "recommendations": [ + "johnpapa.vscode-peacock" + ] +} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..c535165 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,21 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Launch", + "type": "go", + "request": "launch", + "mode": "debug", + "program": "${workspaceRoot}/cmd/main.go", + "env": { + "DB_HOST": "127.0.0.1", + "DB_PORT":"9995", + "APP_PORT":"9994", + }, + "args": [] + } + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..bf19f1d --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,25 @@ +{ + "workbench.colorCustomizations": { + "activityBar.activeBackground": "#0bba5d", + "activityBar.activeBorder": "#eee1fd", + "activityBar.background": "#0bba5d", + "activityBarBadge.background": "#eee1fd", + "activityBarBadge.foreground": "#15202b", + "statusBar.background": "#088a45", + "statusBarItem.hoverBackground": "#0bba5d", + "titleBar.activeBackground": "#088a45", + "titleBar.inactiveBackground": "#088a4599", + "activityBar.foreground": "#e7e7e7", + "activityBar.inactiveForeground": "#e7e7e799", + "statusBar.foreground": "#e7e7e7", + "titleBar.activeForeground": "#e7e7e7", + "titleBar.inactiveForeground": "#e7e7e799", + "statusBarItem.remoteBackground": "#088a45", + "statusBarItem.remoteForeground": "#e7e7e7", + "sash.hoverBorder": "#0bba5d", + "commandCenter.border": "#e7e7e799" + }, + "peacock.color": "#088a45", + "todo-tree.tree.disableCompactFolders": false, + "todo-tree.tree.showBadges": true +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..cd64240 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,55 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "label": "build linux", + "type": "shell", + "group": { + "kind": "build", + "isDefault": true + }, + "presentation": { + "echo": true, + "panel": "new" + }, + "options": { + "cwd": "${workspaceRoot}", + "env": { + "APP": "pakitara", + "GOOS": "linux", + "GOARCH": "amd64", + "GOBIN": "${env:GOPATH}/bin" + }, + "args": [ + "ldflags '-s -w'" + ] + }, + "command": "go build -o $GOBIN/$APP-$GOOS-$GOARCH -ldflags \"-s -w\" $APP.go", + "problemMatcher": [] + }, + { + "label": "build windows", + "type": "shell", + "group": "build", + "presentation": { + "echo": true, + "panel": "new" + }, + "options": { + "cwd": "${workspaceRoot}", + "env": { + "APP": "pakitara", + "GOOS": "windows", + "GOARCH": "amd64", + "GOBIN": "${env:GOPATH}/bin" + }, + "args": [ + "ldflags '-s -w'" + ] + }, + "command": "go build -o $GOBIN\\$APP-$GOOS-$GOARCH.exe -ldflags \"-s -w\" $APP.go" + } + ] +} \ No newline at end of file diff --git a/authService b/authService new file mode 100755 index 0000000..b44bf3e Binary files /dev/null and b/authService differ diff --git a/cmd/main.go b/cmd/main.go index f537841..9bd8c9a 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -1,9 +1,98 @@ package main import ( - api "bugbucketr.org/test3k/authDB" + "context" + "fmt" + "log" + "net/http" + "os" + "os/signal" + "syscall" + "test3k/auth/internal/config" + server "test3k/auth/internal/transport/rest" ) func main() { - s := api.NewServer() + config := config.NewConfig() + ctx, _ := context.WithCancel(context.Background()) + s := server.NewServer(ctx, config) + + // + signalChannel := make(chan os.Signal, 1) + signal.Notify(signalChannel, syscall.SIGINT) + signal.Notify(signalChannel, syscall.SIGTERM) + defer stop(signalChannel, s) + + // Запуск сервера + go start(ctx, config, s) + + // + for { + select { + case <-signalChannel: + fmt.Println("authServer stopping ...") + + return + case <-ctx.Done(): + fmt.Println("authServer stopping ...") + + return + } + } + + // connStr := fmt.Sprintf("%s:%d", config.Db.Host, config.Db.Port) + // conn, erc := grpc.Dial(connStr, grpc.WithInsecure()) + // if erc != nil { + // log.Fatal(erc) + // } + // defer conn.Close() + + // // + // ctx := context.Background() + // cli := api.NewAuthDBClient(conn) + // fmt.Printf("Connect to DB on %v\n", connStr) + + // // + // _, era := cli.Login(ctx, &api.LoginRequest{Login: "vasya", Password: "123"}) + // if era != nil { + // status := status.Convert(era) + // if status.Message() == "login unknown" { + // reg, err := cli.Registration(ctx, &api.RegistrationRequest{ + // Login: "vasya", + // Email: "vasya@mail.ru", + // }) + // if err != nil { + // log.Fatal(err) + // } + + // fmt.Println(reg) + // } else if status.Message() == "login unconfirmed" { + // code := "283164522" + // _, erc := cli.Confirmation(ctx, &api.ConfirmationRequest{Code: code}) + // if erc != nil { + // log.Fatal(erc) + // } + // } + // } +} + +// Остановка сервера +func stop(signalChannel chan os.Signal, s *server.AuthServer) { + defer s.Close() + + signal.Stop(signalChannel) +} + +// Запуск сервера +func start(ctx context.Context, config *config.Config, s *server.AuthServer) { + connStr := fmt.Sprintf(":%d", config.App.Port) + + // + log.Printf("authServer up (%s)\n", connStr) + + // + err := http.ListenAndServe(connStr, s.Router) // router + if err != nil { + log.Fatal("Failed starting server") + } } diff --git a/go.mod b/go.mod index ee60627..ba806b6 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,15 @@ module test3k/auth go 1.19 + +require ( + github.com/go-chi/chi/v5 v5.0.8 // indirect + github.com/golang/protobuf v1.5.2 // indirect + github.com/kelseyhightower/envconfig v1.4.0 // indirect + golang.org/x/net v0.4.0 // indirect + golang.org/x/sys v0.3.0 // indirect + golang.org/x/text v0.5.0 // indirect + google.golang.org/genproto v0.0.0-20221118155620-16455021b5e6 // indirect + google.golang.org/grpc v1.52.3 // indirect + google.golang.org/protobuf v1.28.1 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..e8ae8df --- /dev/null +++ b/go.sum @@ -0,0 +1,23 @@ +github.com/go-chi/chi/v5 v5.0.8 h1:lD+NLqFcAi1ovnVZpsnObHGW4xb4J8lNmoYVfECH1Y0= +github.com/go-chi/chi/v5 v5.0.8/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= +github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/kelseyhightower/envconfig v1.4.0 h1:Im6hONhd3pLkfDFsbRgu68RDNkGF1r3dvMUtDTo2cv8= +github.com/kelseyhightower/envconfig v1.4.0/go.mod h1:cccZRl6mQpaq41TPp5QxidR+Sa3axMbJDNb//FQX6Gg= +golang.org/x/net v0.4.0 h1:Q5QPcMlvfxFTAPV0+07Xz/MpK9NTXu2VDUuy0FeMfaU= +golang.org/x/net v0.4.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE= +golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ= +golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/text v0.5.0 h1:OLmvp0KP+FVG99Ct/qFiL/Fhk4zp4QQnZ7b2U+5piUM= +golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/genproto v0.0.0-20221118155620-16455021b5e6 h1:a2S6M0+660BgMNl++4JPlcAO/CjkqYItDEZwkoDQK7c= +google.golang.org/genproto v0.0.0-20221118155620-16455021b5e6/go.mod h1:rZS5c/ZVYMaOGBfO68GWtjOw/eLaZM1X6iVtgjZ+EWg= +google.golang.org/grpc v1.52.3 h1:pf7sOysg4LdgBqduXveGKrcEwbStiK2rtfghdzlUYDQ= +google.golang.org/grpc v1.52.3/go.mod h1:pu6fVzoFb+NBYNAvQL08ic+lvB2IojljRYuun5vorUY= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w= +google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= diff --git a/internal/config/config.go b/internal/config/config.go new file mode 100644 index 0000000..61e060b --- /dev/null +++ b/internal/config/config.go @@ -0,0 +1,32 @@ +package config + +import ( + "log" + + "github.com/kelseyhightower/envconfig" +) + +type DbConfig struct { + Host string `envconfig:"DB_HOST"` + Port int `envconfig:"DB_PORT"` +} + +type AppConfig struct { + Port int `envconfig:"APP_PORT"` +} + +// ... +type Config struct { + Db DbConfig + App AppConfig +} + +func NewConfig() *Config { + c := Config{} + err := envconfig.Process("", &c) + if err != nil { + log.Fatal(err.Error()) + } + + return &c +} diff --git a/internal/transport/grpc/db.go b/internal/transport/grpc/db.go new file mode 100644 index 0000000..d697b00 --- /dev/null +++ b/internal/transport/grpc/db.go @@ -0,0 +1,78 @@ +package db + +import ( + "context" + "fmt" + "log" + "test3k/auth/internal/config" + api "test3k/auth/pkg/api" + + "google.golang.org/grpc" +) + +type AuthDBClient struct { + config *config.Config + client *grpc.ClientConn + db api.AuthDBClient + ctx context.Context +} + +func NewDBClient(ctx context.Context, config *config.Config) *AuthDBClient { + connStr := fmt.Sprintf("%s:%d", config.Db.Host, config.Db.Port) + client, err := grpc.Dial(connStr, grpc.WithInsecure()) + if err != nil { + log.Fatal(err) + } + + return &AuthDBClient{ + config: config, + client: client, + db: api.NewAuthDBClient(client), + ctx: ctx, + } +} + +func (s *AuthDBClient) Close() { + s.client.Close() +} + +func (s *AuthDBClient) Login(uid string, password string) error { + _, err := s.db.Login(s.ctx, &api.LoginRequest{ + Login: uid, + Password: password, + }) + + // + if err != nil { + return err + } + + return err +} + +func (s *AuthDBClient) Registration(uid string, email string) (string, error) { + res, err := s.db.Registration(s.ctx, &api.RegistrationRequest{ + Login: uid, + Email: email, + }) + + // + if err != nil { + return "", err + } + + return res.GetCode(), err +} + +func (s *AuthDBClient) Confirmation(code string) error { + _, err := s.db.Confirmation(s.ctx, &api.ConfirmationRequest{ + Code: code, + }) + + // + if err != nil { + return err + } + + return err +} diff --git a/internal/transport/rest/server.go b/internal/transport/rest/server.go new file mode 100644 index 0000000..704528e --- /dev/null +++ b/internal/transport/rest/server.go @@ -0,0 +1,89 @@ +package rest + +import ( + "context" + "fmt" + "net/http" + "test3k/auth/internal/config" + db "test3k/auth/internal/transport/grpc" + + mux "github.com/go-chi/chi/v5" + "google.golang.org/grpc/status" +) + +// ... +type AuthServer struct { + db *db.AuthDBClient + Router *mux.Mux + config *config.Config + ctx context.Context +} + +func NewServer(ctx context.Context, config *config.Config) *AuthServer { + s := &AuthServer{ + db: db.NewDBClient(ctx, config), + Router: mux.NewMux(), + config: config, + ctx: ctx, + } + + // + s.Router.Post("/api/v1/login", login(s)) + s.Router.Post("/api/v1/registration", registration(s)) + s.Router.Post("/api/v1/confirmation", confirmation(s)) + + return s +} + +func (s *AuthServer) Close() { + s.db.Close() +} + +func login(s *AuthServer) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + uid := r.FormValue("uid") + password := r.FormValue("password") + err := s.db.Login(uid, password) + if err != nil { + status := status.Convert(err) + w.Write([]byte(status.Message())) + + return + } + + w.Write([]byte(fmt.Sprintf("Success login for %s", uid))) + } +} + +func registration(s *AuthServer) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + uid := r.FormValue("uid") + email := r.FormValue("email") + code, err := s.db.Registration(uid, email) + if err != nil { + status := status.Convert(err) + message := fmt.Sprintf("%s for %q", status.Message(), uid) + + w.Write([]byte(message)) + + return + } + + w.Write([]byte(fmt.Sprintf("Success registration for %s with code %s", uid, code))) + } +} + +func confirmation(s *AuthServer) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + code := r.FormValue("code") + err := s.db.Confirmation(code) + if err != nil { + status := status.Convert(err) + w.Write([]byte(status.Message())) + + return + } + + w.Write([]byte(fmt.Sprintf("Success confirmation for %s", code))) + } +} diff --git a/pkg/api/auth.pb.go b/pkg/api/auth.pb.go new file mode 100644 index 0000000..466638f --- /dev/null +++ b/pkg/api/auth.pb.go @@ -0,0 +1,504 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.28.1 +// protoc v3.6.1 +// source: auth.proto + +package __ + +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 LoginRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Login string `protobuf:"bytes,1,opt,name=Login,proto3" json:"Login,omitempty"` + Password string `protobuf:"bytes,2,opt,name=Password,proto3" json:"Password,omitempty"` +} + +func (x *LoginRequest) Reset() { + *x = LoginRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_auth_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *LoginRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*LoginRequest) ProtoMessage() {} + +func (x *LoginRequest) ProtoReflect() protoreflect.Message { + mi := &file_auth_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use LoginRequest.ProtoReflect.Descriptor instead. +func (*LoginRequest) Descriptor() ([]byte, []int) { + return file_auth_proto_rawDescGZIP(), []int{0} +} + +func (x *LoginRequest) GetLogin() string { + if x != nil { + return x.Login + } + return "" +} + +func (x *LoginRequest) GetPassword() string { + if x != nil { + return x.Password + } + return "" +} + +type LoginResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + ID int32 `protobuf:"varint,1,opt,name=ID,proto3" json:"ID,omitempty"` +} + +func (x *LoginResponse) Reset() { + *x = LoginResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_auth_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *LoginResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*LoginResponse) ProtoMessage() {} + +func (x *LoginResponse) ProtoReflect() protoreflect.Message { + mi := &file_auth_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use LoginResponse.ProtoReflect.Descriptor instead. +func (*LoginResponse) Descriptor() ([]byte, []int) { + return file_auth_proto_rawDescGZIP(), []int{1} +} + +func (x *LoginResponse) GetID() int32 { + if x != nil { + return x.ID + } + return 0 +} + +// Регистрация пользователя +type RegistrationRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Login string `protobuf:"bytes,1,opt,name=Login,proto3" json:"Login,omitempty"` + Email string `protobuf:"bytes,2,opt,name=Email,proto3" json:"Email,omitempty"` +} + +func (x *RegistrationRequest) Reset() { + *x = RegistrationRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_auth_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *RegistrationRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*RegistrationRequest) ProtoMessage() {} + +func (x *RegistrationRequest) ProtoReflect() protoreflect.Message { + mi := &file_auth_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use RegistrationRequest.ProtoReflect.Descriptor instead. +func (*RegistrationRequest) Descriptor() ([]byte, []int) { + return file_auth_proto_rawDescGZIP(), []int{2} +} + +func (x *RegistrationRequest) GetLogin() string { + if x != nil { + return x.Login + } + return "" +} + +func (x *RegistrationRequest) GetEmail() string { + if x != nil { + return x.Email + } + return "" +} + +type RegistrationResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code string `protobuf:"bytes,1,opt,name=Code,proto3" json:"Code,omitempty"` + Email string `protobuf:"bytes,2,opt,name=Email,proto3" json:"Email,omitempty"` +} + +func (x *RegistrationResponse) Reset() { + *x = RegistrationResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_auth_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *RegistrationResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*RegistrationResponse) ProtoMessage() {} + +func (x *RegistrationResponse) ProtoReflect() protoreflect.Message { + mi := &file_auth_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use RegistrationResponse.ProtoReflect.Descriptor instead. +func (*RegistrationResponse) Descriptor() ([]byte, []int) { + return file_auth_proto_rawDescGZIP(), []int{3} +} + +func (x *RegistrationResponse) GetCode() string { + if x != nil { + return x.Code + } + return "" +} + +func (x *RegistrationResponse) GetEmail() string { + if x != nil { + return x.Email + } + return "" +} + +// Подтверждение пользователя +type ConfirmationRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code string `protobuf:"bytes,1,opt,name=Code,proto3" json:"Code,omitempty"` +} + +func (x *ConfirmationRequest) Reset() { + *x = ConfirmationRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_auth_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ConfirmationRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ConfirmationRequest) ProtoMessage() {} + +func (x *ConfirmationRequest) ProtoReflect() protoreflect.Message { + mi := &file_auth_proto_msgTypes[4] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ConfirmationRequest.ProtoReflect.Descriptor instead. +func (*ConfirmationRequest) Descriptor() ([]byte, []int) { + return file_auth_proto_rawDescGZIP(), []int{4} +} + +func (x *ConfirmationRequest) GetCode() string { + if x != nil { + return x.Code + } + return "" +} + +type ConfirmationResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + ID int32 `protobuf:"varint,1,opt,name=ID,proto3" json:"ID,omitempty"` +} + +func (x *ConfirmationResponse) Reset() { + *x = ConfirmationResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_auth_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ConfirmationResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ConfirmationResponse) ProtoMessage() {} + +func (x *ConfirmationResponse) ProtoReflect() protoreflect.Message { + mi := &file_auth_proto_msgTypes[5] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ConfirmationResponse.ProtoReflect.Descriptor instead. +func (*ConfirmationResponse) Descriptor() ([]byte, []int) { + return file_auth_proto_rawDescGZIP(), []int{5} +} + +func (x *ConfirmationResponse) GetID() int32 { + if x != nil { + return x.ID + } + return 0 +} + +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, 0x04, 0x61, 0x75, + 0x74, 0x68, 0x22, 0x40, 0x0a, 0x0c, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x05, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x12, 0x1a, 0x0a, 0x08, 0x50, 0x61, 0x73, 0x73, + 0x77, 0x6f, 0x72, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x50, 0x61, 0x73, 0x73, + 0x77, 0x6f, 0x72, 0x64, 0x22, 0x1f, 0x0a, 0x0d, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x49, 0x44, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x05, 0x52, 0x02, 0x49, 0x44, 0x22, 0x41, 0x0a, 0x13, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x72, + 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, + 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x4c, 0x6f, 0x67, + 0x69, 0x6e, 0x12, 0x14, 0x0a, 0x05, 0x45, 0x6d, 0x61, 0x69, 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x05, 0x45, 0x6d, 0x61, 0x69, 0x6c, 0x22, 0x40, 0x0a, 0x14, 0x52, 0x65, 0x67, 0x69, + 0x73, 0x74, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, + 0x12, 0x12, 0x0a, 0x04, 0x43, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, + 0x43, 0x6f, 0x64, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x45, 0x6d, 0x61, 0x69, 0x6c, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x05, 0x45, 0x6d, 0x61, 0x69, 0x6c, 0x22, 0x29, 0x0a, 0x13, 0x43, 0x6f, + 0x6e, 0x66, 0x69, 0x72, 0x6d, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x12, 0x12, 0x0a, 0x04, 0x43, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x04, 0x43, 0x6f, 0x64, 0x65, 0x22, 0x26, 0x0a, 0x14, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x72, 0x6d, + 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x0e, 0x0a, + 0x02, 0x49, 0x44, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x02, 0x49, 0x44, 0x32, 0xce, 0x01, + 0x0a, 0x06, 0x41, 0x75, 0x74, 0x68, 0x44, 0x42, 0x12, 0x32, 0x0a, 0x05, 0x4c, 0x6f, 0x67, 0x69, + 0x6e, 0x12, 0x12, 0x2e, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x13, 0x2e, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x4c, 0x6f, 0x67, + 0x69, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x47, 0x0a, 0x0c, + 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x19, 0x2e, 0x61, + 0x75, 0x74, 0x68, 0x2e, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1a, 0x2e, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x52, + 0x65, 0x67, 0x69, 0x73, 0x74, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x47, 0x0a, 0x0c, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x72, 0x6d, + 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x19, 0x2e, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x43, 0x6f, 0x6e, + 0x66, 0x69, 0x72, 0x6d, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x1a, 0x2e, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x72, 0x6d, 0x61, + 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x04, + 0x5a, 0x02, 0x2e, 0x2f, 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, 6) +var file_auth_proto_goTypes = []interface{}{ + (*LoginRequest)(nil), // 0: auth.LoginRequest + (*LoginResponse)(nil), // 1: auth.LoginResponse + (*RegistrationRequest)(nil), // 2: auth.RegistrationRequest + (*RegistrationResponse)(nil), // 3: auth.RegistrationResponse + (*ConfirmationRequest)(nil), // 4: auth.ConfirmationRequest + (*ConfirmationResponse)(nil), // 5: auth.ConfirmationResponse +} +var file_auth_proto_depIdxs = []int32{ + 0, // 0: auth.AuthDB.Login:input_type -> auth.LoginRequest + 2, // 1: auth.AuthDB.Registration:input_type -> auth.RegistrationRequest + 4, // 2: auth.AuthDB.Confirmation:input_type -> auth.ConfirmationRequest + 1, // 3: auth.AuthDB.Login:output_type -> auth.LoginResponse + 3, // 4: auth.AuthDB.Registration:output_type -> auth.RegistrationResponse + 5, // 5: auth.AuthDB.Confirmation:output_type -> auth.ConfirmationResponse + 3, // [3:6] is the sub-list for method output_type + 0, // [0:3] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] 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 + } + if !protoimpl.UnsafeEnabled { + file_auth_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*LoginRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_auth_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*LoginResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_auth_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*RegistrationRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_auth_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*RegistrationResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_auth_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ConfirmationRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_auth_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ConfirmationResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_auth_proto_rawDesc, + NumEnums: 0, + NumMessages: 6, + 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 +} diff --git a/pkg/api/auth_grpc.pb.go b/pkg/api/auth_grpc.pb.go new file mode 100644 index 0000000..672adc5 --- /dev/null +++ b/pkg/api/auth_grpc.pb.go @@ -0,0 +1,177 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.2.0 +// - protoc v3.6.1 +// source: auth.proto + +package __ + +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.32.0 or later. +const _ = grpc.SupportPackageIsVersion7 + +// AuthDBClient is the client API for AuthDB 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 AuthDBClient interface { + Login(ctx context.Context, in *LoginRequest, opts ...grpc.CallOption) (*LoginResponse, error) + Registration(ctx context.Context, in *RegistrationRequest, opts ...grpc.CallOption) (*RegistrationResponse, error) + Confirmation(ctx context.Context, in *ConfirmationRequest, opts ...grpc.CallOption) (*ConfirmationResponse, error) +} + +type authDBClient struct { + cc grpc.ClientConnInterface +} + +func NewAuthDBClient(cc grpc.ClientConnInterface) AuthDBClient { + return &authDBClient{cc} +} + +func (c *authDBClient) Login(ctx context.Context, in *LoginRequest, opts ...grpc.CallOption) (*LoginResponse, error) { + out := new(LoginResponse) + err := c.cc.Invoke(ctx, "/auth.AuthDB/Login", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *authDBClient) Registration(ctx context.Context, in *RegistrationRequest, opts ...grpc.CallOption) (*RegistrationResponse, error) { + out := new(RegistrationResponse) + err := c.cc.Invoke(ctx, "/auth.AuthDB/Registration", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *authDBClient) Confirmation(ctx context.Context, in *ConfirmationRequest, opts ...grpc.CallOption) (*ConfirmationResponse, error) { + out := new(ConfirmationResponse) + err := c.cc.Invoke(ctx, "/auth.AuthDB/Confirmation", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// AuthDBServer is the server API for AuthDB service. +// All implementations must embed UnimplementedAuthDBServer +// for forward compatibility +type AuthDBServer interface { + Login(context.Context, *LoginRequest) (*LoginResponse, error) + Registration(context.Context, *RegistrationRequest) (*RegistrationResponse, error) + Confirmation(context.Context, *ConfirmationRequest) (*ConfirmationResponse, error) + mustEmbedUnimplementedAuthDBServer() +} + +// UnimplementedAuthDBServer must be embedded to have forward compatible implementations. +type UnimplementedAuthDBServer struct { +} + +func (UnimplementedAuthDBServer) Login(context.Context, *LoginRequest) (*LoginResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Login not implemented") +} +func (UnimplementedAuthDBServer) Registration(context.Context, *RegistrationRequest) (*RegistrationResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Registration not implemented") +} +func (UnimplementedAuthDBServer) Confirmation(context.Context, *ConfirmationRequest) (*ConfirmationResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Confirmation not implemented") +} +func (UnimplementedAuthDBServer) mustEmbedUnimplementedAuthDBServer() {} + +// UnsafeAuthDBServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to AuthDBServer will +// result in compilation errors. +type UnsafeAuthDBServer interface { + mustEmbedUnimplementedAuthDBServer() +} + +func RegisterAuthDBServer(s grpc.ServiceRegistrar, srv AuthDBServer) { + s.RegisterService(&AuthDB_ServiceDesc, srv) +} + +func _AuthDB_Login_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(LoginRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(AuthDBServer).Login(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/auth.AuthDB/Login", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(AuthDBServer).Login(ctx, req.(*LoginRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _AuthDB_Registration_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(RegistrationRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(AuthDBServer).Registration(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/auth.AuthDB/Registration", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(AuthDBServer).Registration(ctx, req.(*RegistrationRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _AuthDB_Confirmation_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ConfirmationRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(AuthDBServer).Confirmation(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/auth.AuthDB/Confirmation", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(AuthDBServer).Confirmation(ctx, req.(*ConfirmationRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// AuthDB_ServiceDesc is the grpc.ServiceDesc for AuthDB service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var AuthDB_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "auth.AuthDB", + HandlerType: (*AuthDBServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Login", + Handler: _AuthDB_Login_Handler, + }, + { + MethodName: "Registration", + Handler: _AuthDB_Registration_Handler, + }, + { + MethodName: "Confirmation", + Handler: _AuthDB_Confirmation_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "auth.proto", +}