diff --git a/codes/.gitignore b/codes/.gitignore deleted file mode 100644 index 086c401..0000000 --- a/codes/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ - -codes diff --git a/codes/Makefile b/codes/Makefile deleted file mode 100644 index 31491db..0000000 --- a/codes/Makefile +++ /dev/null @@ -1,27 +0,0 @@ - -GOPATH:=$(shell go env GOPATH) -.PHONY: init -init: - go get -u github.com/golang/protobuf/proto - go get -u github.com/golang/protobuf/protoc-gen-go - go get github.com/micro/micro/v3/cmd/protoc-gen-micro -.PHONY: proto -proto: - protoc --openapi_out=. --proto_path=. --micro_out=. --go_out=:. proto/codes.proto - -.PHONY: build -build: - go build -o codes *.go - -.PHONY: docs -docs: - protoc --openapi_out=. --proto_path=. --micro_out=. --go_out=:. proto/codes.proto - @redoc-cli bundle api-codes.json - -.PHONY: test -test: - go test -v ./... -cover - -.PHONY: docker -docker: - docker build . -t codes:latest diff --git a/codes/README.md b/codes/README.md deleted file mode 100644 index 1384a9e..0000000 --- a/codes/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# Codes Service - -The codes service generates codes for use with email / sms verification diff --git a/codes/handler/create.go b/codes/handler/create.go deleted file mode 100644 index b1b87d6..0000000 --- a/codes/handler/create.go +++ /dev/null @@ -1,52 +0,0 @@ -package handler - -import ( - "context" - "math/rand" - "strconv" - - "github.com/micro/micro/v3/service/auth" - "github.com/micro/micro/v3/service/errors" - "github.com/micro/micro/v3/service/logger" - pb "github.com/micro/services/codes/proto" -) - -func (c *Codes) Create(ctx context.Context, req *pb.CreateRequest, rsp *pb.CreateResponse) error { - _, ok := auth.AccountFromContext(ctx) - if !ok { - errors.Unauthorized("UNAUTHORIZED", "Unauthorized") - } - // validate the request - if len(req.Identity) == 0 { - return ErrMissingIdentity - } - - // construct the code - code := Code{Code: generateCode(), Identity: req.Identity} - if req.ExpiresAt != nil { - code.ExpiresAt = req.ExpiresAt.AsTime() - } else { - code.ExpiresAt = c.Time().Add(DefaultTTL) - } - - db, err := c.GetDBConn(ctx) - if err != nil { - logger.Errorf("Error connecting to DB: %v", err) - return errors.InternalServerError("DB_ERROR", "Error connecting to DB") - } - // write to the database - if err := db.Create(&code).Error; err != nil { - logger.Errorf("Error creating code in database: %v", err) - return errors.InternalServerError("DATABASE_ERORR", "Error connecting to database") - } - - // return the code - rsp.Code = code.Code - return nil -} - -// generateCode generates a random 8 digit code -func generateCode() string { - v := rand.Intn(89999999) + 10000000 - return strconv.Itoa(v) -} diff --git a/codes/handler/create_test.go b/codes/handler/create_test.go deleted file mode 100644 index 57379eb..0000000 --- a/codes/handler/create_test.go +++ /dev/null @@ -1,46 +0,0 @@ -package handler_test - -import ( - "context" - "testing" - - "github.com/micro/micro/v3/service/auth" - "github.com/micro/services/codes/handler" - pb "github.com/micro/services/codes/proto" - "github.com/stretchr/testify/assert" - "google.golang.org/protobuf/types/known/timestamppb" -) - -func TestCreate(t *testing.T) { - h := testHandler(t) - - t.Run("MissingIdentity", func(t *testing.T) { - var rsp pb.CreateResponse - err := h.Create(microAccountCtx(), &pb.CreateRequest{}, &rsp) - assert.Equal(t, handler.ErrMissingIdentity, err) - assert.Empty(t, rsp.Code) - }) - - t.Run("NoExpiry", func(t *testing.T) { - var rsp pb.CreateResponse - err := h.Create(microAccountCtx(), &pb.CreateRequest{Identity: "07503196715"}, &rsp) - assert.NoError(t, err) - assert.NotEmpty(t, rsp.Code) - }) - - t.Run("WithExpiry", func(t *testing.T) { - var rsp pb.CreateResponse - err := h.Create(microAccountCtx(), &pb.CreateRequest{ - Identity: "demo@m3o.com", - ExpiresAt: timestamppb.Now(), - }, &rsp) - assert.NoError(t, err) - assert.NotEmpty(t, rsp.Code) - }) -} - -func microAccountCtx() context.Context { - return auth.ContextWithAccount(context.TODO(), &auth.Account{ - Issuer: "micro", - }) -} diff --git a/codes/handler/handler.go b/codes/handler/handler.go deleted file mode 100644 index 9cb4153..0000000 --- a/codes/handler/handler.go +++ /dev/null @@ -1,28 +0,0 @@ -package handler - -import ( - "time" - - "github.com/micro/micro/v3/service/errors" - "github.com/micro/services/pkg/gorm" -) - -var ( - ErrMissingCode = errors.BadRequest("MISSING_CODE", "Missing code") - ErrMissingIdentity = errors.BadRequest("MISSING_IDENTITY", "Missing identity") - ErrInvalidCode = errors.BadRequest("INVALID_CODE", "Invalid code") - ErrExpiredCode = errors.BadRequest("EXPIRED_CODE", "Expired code") - - DefaultTTL = time.Minute * 5 -) - -type Codes struct { - gorm.Helper - Time func() time.Time -} - -type Code struct { - Code string `gorm:"index:codeIdentity"` - Identity string `gorm:"index:codeIdentity"` - ExpiresAt time.Time -} diff --git a/codes/handler/handler_test.go b/codes/handler/handler_test.go deleted file mode 100644 index 207e30b..0000000 --- a/codes/handler/handler_test.go +++ /dev/null @@ -1,32 +0,0 @@ -package handler_test - -import ( - "database/sql" - "os" - "testing" - "time" - - "github.com/micro/services/codes/handler" -) - -func testHandler(t *testing.T) *handler.Codes { - // connect to the database - addr := os.Getenv("POSTGRES_URL") - if len(addr) == 0 { - addr = "postgresql://postgres@localhost:5432/postgres?sslmode=disable" - } - - sqlDB, err := sql.Open("pgx", addr) - if err != nil { - t.Fatalf("Failed to open connection to DB %s", err) - } - - // clean any data from a previous run - if _, err := sqlDB.Exec("DROP TABLE IF EXISTS micro_codes CASCADE"); err != nil { - t.Fatalf("Error cleaning database: %v", err) - } - - h := &handler.Codes{Time: time.Now} - h.DBConn(sqlDB).Migrations(&handler.Code{}) - return h -} diff --git a/codes/handler/verify.go b/codes/handler/verify.go deleted file mode 100644 index 1abb537..0000000 --- a/codes/handler/verify.go +++ /dev/null @@ -1,46 +0,0 @@ -package handler - -import ( - "context" - - "github.com/micro/micro/v3/service/auth" - "github.com/micro/micro/v3/service/errors" - "github.com/micro/micro/v3/service/logger" - pb "github.com/micro/services/codes/proto" - "gorm.io/gorm" -) - -func (c *Codes) Verify(ctx context.Context, req *pb.VerifyRequest, rsp *pb.VerifyResponse) error { - _, ok := auth.AccountFromContext(ctx) - if !ok { - errors.Unauthorized("UNAUTHORIZED", "Unauthorized") - } - // validate the request - if len(req.Code) == 0 { - return ErrMissingCode - } - if len(req.Identity) == 0 { - return ErrMissingIdentity - } - - db, err := c.GetDBConn(ctx) - if err != nil { - logger.Errorf("Error connecting to DB: %v", err) - return errors.InternalServerError("DB_ERROR", "Error connecting to DB") - } - // lookup the code - var code Code - if err := db.Where(&Code{Code: req.Code, Identity: req.Identity}).First(&code).Error; err == gorm.ErrRecordNotFound { - return ErrInvalidCode - } else if err != nil { - logger.Errorf("Error reading code from database: %v", err) - return errors.InternalServerError("DATABASE_ERORR", "Error connecting to database") - } - - // check the invite hasn't expired - if code.ExpiresAt.Before(c.Time()) { - return ErrExpiredCode - } - - return nil -} diff --git a/codes/handler/verify_test.go b/codes/handler/verify_test.go deleted file mode 100644 index 2222d93..0000000 --- a/codes/handler/verify_test.go +++ /dev/null @@ -1,59 +0,0 @@ -package handler_test - -import ( - "testing" - "time" - - "github.com/micro/services/codes/handler" - pb "github.com/micro/services/codes/proto" - "github.com/stretchr/testify/assert" -) - -func TestVerify(t *testing.T) { - h := testHandler(t) - - t.Run("MissingIdentity", func(t *testing.T) { - var rsp pb.VerifyResponse - err := h.Verify(microAccountCtx(), &pb.VerifyRequest{Code: "123456"}, &rsp) - assert.Equal(t, handler.ErrMissingIdentity, err) - }) - - t.Run("MissingCode", func(t *testing.T) { - var rsp pb.VerifyResponse - err := h.Verify(microAccountCtx(), &pb.VerifyRequest{Identity: "demo@m3o.com"}, &rsp) - assert.Equal(t, handler.ErrMissingCode, err) - }) - - // generate a code to test - var cRsp pb.CreateResponse - err := h.Create(microAccountCtx(), &pb.CreateRequest{Identity: "demo@m3o.com"}, &cRsp) - assert.NoError(t, err) - - t.Run("IncorrectCode", func(t *testing.T) { - var rsp pb.VerifyResponse - err := h.Verify(microAccountCtx(), &pb.VerifyRequest{Identity: "demo@m3o.com", Code: "12345"}, &rsp) - assert.Equal(t, handler.ErrInvalidCode, err) - }) - - t.Run("IncorrectEmail", func(t *testing.T) { - var rsp pb.VerifyResponse - err := h.Verify(microAccountCtx(), &pb.VerifyRequest{Identity: "john@m3o.com", Code: cRsp.Code}, &rsp) - assert.Equal(t, handler.ErrInvalidCode, err) - }) - - t.Run("ExpiredCode", func(t *testing.T) { - ot := h.Time - h.Time = func() time.Time { return time.Now().Add(handler.DefaultTTL * 2) } - defer func() { h.Time = ot }() - - var rsp pb.VerifyResponse - err := h.Verify(microAccountCtx(), &pb.VerifyRequest{Identity: "demo@m3o.com", Code: cRsp.Code}, &rsp) - assert.Equal(t, handler.ErrExpiredCode, err) - }) - - t.Run("ValidCode", func(t *testing.T) { - var rsp pb.VerifyResponse - err := h.Verify(microAccountCtx(), &pb.VerifyRequest{Identity: "demo@m3o.com", Code: cRsp.Code}, &rsp) - assert.NoError(t, err) - }) -} diff --git a/codes/main.go b/codes/main.go deleted file mode 100644 index 386fbe5..0000000 --- a/codes/main.go +++ /dev/null @@ -1,46 +0,0 @@ -package main - -import ( - "database/sql" - "time" - - "github.com/micro/services/codes/handler" - pb "github.com/micro/services/codes/proto" - - "github.com/micro/micro/v3/service" - "github.com/micro/micro/v3/service/config" - "github.com/micro/micro/v3/service/logger" - - _ "github.com/jackc/pgx/v4/stdlib" -) - -var dbAddress = "postgresql://postgres:postgres@localhost:5432/codes?sslmode=disable" - -func main() { - // Create service - srv := service.New( - service.Name("codes"), - service.Version("latest"), - ) - - // Connect to the database - cfg, err := config.Get("codes.database") - if err != nil { - logger.Fatalf("Error loading config: %v", err) - } - addr := cfg.String(dbAddress) - sqlDB, err := sql.Open("pgx", addr) - if err != nil { - logger.Fatalf("Failed to open connection to DB %s", err) - } - - h := &handler.Codes{Time: time.Now} - h.DBConn(sqlDB).Migrations(&handler.Code{}) - // Register handler - pb.RegisterCodesHandler(srv.Server(), h) - - // Run service - if err := srv.Run(); err != nil { - logger.Fatal(err) - } -} diff --git a/codes/micro.mu b/codes/micro.mu deleted file mode 100644 index 653d211..0000000 --- a/codes/micro.mu +++ /dev/null @@ -1 +0,0 @@ -service codes diff --git a/codes/proto/codes.pb.go b/codes/proto/codes.pb.go deleted file mode 100644 index ca38923..0000000 --- a/codes/proto/codes.pb.go +++ /dev/null @@ -1,357 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.26.0 -// protoc v3.15.5 -// source: proto/codes.proto - -package codes - -import ( - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - timestamppb "google.golang.org/protobuf/types/known/timestamppb" - 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 CreateRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Identity string `protobuf:"bytes,1,opt,name=identity,proto3" json:"identity,omitempty"` // e.g. phone number or email being verified - ExpiresAt *timestamppb.Timestamp `protobuf:"bytes,2,opt,name=expires_at,json=expiresAt,proto3" json:"expires_at,omitempty"` // expiry time for the code, default 5 minutes -} - -func (x *CreateRequest) Reset() { - *x = CreateRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_proto_codes_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *CreateRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*CreateRequest) ProtoMessage() {} - -func (x *CreateRequest) ProtoReflect() protoreflect.Message { - mi := &file_proto_codes_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 CreateRequest.ProtoReflect.Descriptor instead. -func (*CreateRequest) Descriptor() ([]byte, []int) { - return file_proto_codes_proto_rawDescGZIP(), []int{0} -} - -func (x *CreateRequest) GetIdentity() string { - if x != nil { - return x.Identity - } - return "" -} - -func (x *CreateRequest) GetExpiresAt() *timestamppb.Timestamp { - if x != nil { - return x.ExpiresAt - } - return nil -} - -type CreateResponse struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Code string `protobuf:"bytes,1,opt,name=code,proto3" json:"code,omitempty"` -} - -func (x *CreateResponse) Reset() { - *x = CreateResponse{} - if protoimpl.UnsafeEnabled { - mi := &file_proto_codes_proto_msgTypes[1] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *CreateResponse) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*CreateResponse) ProtoMessage() {} - -func (x *CreateResponse) ProtoReflect() protoreflect.Message { - mi := &file_proto_codes_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 CreateResponse.ProtoReflect.Descriptor instead. -func (*CreateResponse) Descriptor() ([]byte, []int) { - return file_proto_codes_proto_rawDescGZIP(), []int{1} -} - -func (x *CreateResponse) GetCode() string { - if x != nil { - return x.Code - } - return "" -} - -type VerifyRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Code string `protobuf:"bytes,1,opt,name=code,proto3" json:"code,omitempty"` - Identity string `protobuf:"bytes,2,opt,name=identity,proto3" json:"identity,omitempty"` -} - -func (x *VerifyRequest) Reset() { - *x = VerifyRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_proto_codes_proto_msgTypes[2] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *VerifyRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*VerifyRequest) ProtoMessage() {} - -func (x *VerifyRequest) ProtoReflect() protoreflect.Message { - mi := &file_proto_codes_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 VerifyRequest.ProtoReflect.Descriptor instead. -func (*VerifyRequest) Descriptor() ([]byte, []int) { - return file_proto_codes_proto_rawDescGZIP(), []int{2} -} - -func (x *VerifyRequest) GetCode() string { - if x != nil { - return x.Code - } - return "" -} - -func (x *VerifyRequest) GetIdentity() string { - if x != nil { - return x.Identity - } - return "" -} - -type VerifyResponse struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields -} - -func (x *VerifyResponse) Reset() { - *x = VerifyResponse{} - if protoimpl.UnsafeEnabled { - mi := &file_proto_codes_proto_msgTypes[3] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *VerifyResponse) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*VerifyResponse) ProtoMessage() {} - -func (x *VerifyResponse) ProtoReflect() protoreflect.Message { - mi := &file_proto_codes_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 VerifyResponse.ProtoReflect.Descriptor instead. -func (*VerifyResponse) Descriptor() ([]byte, []int) { - return file_proto_codes_proto_rawDescGZIP(), []int{3} -} - -var File_proto_codes_proto protoreflect.FileDescriptor - -var file_proto_codes_proto_rawDesc = []byte{ - 0x0a, 0x11, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x63, 0x6f, 0x64, 0x65, 0x73, 0x2e, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x12, 0x05, 0x63, 0x6f, 0x64, 0x65, 0x73, 0x1a, 0x1f, 0x67, 0x6f, 0x6f, 0x67, - 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x74, 0x69, 0x6d, 0x65, - 0x73, 0x74, 0x61, 0x6d, 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x66, 0x0a, 0x0d, 0x43, - 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x08, - 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, - 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x12, 0x39, 0x0a, 0x0a, 0x65, 0x78, 0x70, 0x69, - 0x72, 0x65, 0x73, 0x5f, 0x61, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, - 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, - 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x09, 0x65, 0x78, 0x70, 0x69, 0x72, 0x65, - 0x73, 0x41, 0x74, 0x22, 0x24, 0x0a, 0x0e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, - 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x22, 0x3f, 0x0a, 0x0d, 0x56, 0x65, 0x72, - 0x69, 0x66, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, - 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x1a, - 0x0a, 0x08, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x08, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x22, 0x10, 0x0a, 0x0e, 0x56, 0x65, - 0x72, 0x69, 0x66, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x32, 0x75, 0x0a, 0x05, - 0x43, 0x6f, 0x64, 0x65, 0x73, 0x12, 0x35, 0x0a, 0x06, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x12, - 0x14, 0x2e, 0x63, 0x6f, 0x64, 0x65, 0x73, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x15, 0x2e, 0x63, 0x6f, 0x64, 0x65, 0x73, 0x2e, 0x43, 0x72, - 0x65, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x35, 0x0a, 0x06, - 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x12, 0x14, 0x2e, 0x63, 0x6f, 0x64, 0x65, 0x73, 0x2e, 0x56, - 0x65, 0x72, 0x69, 0x66, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x15, 0x2e, 0x63, - 0x6f, 0x64, 0x65, 0x73, 0x2e, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, - 0x6e, 0x73, 0x65, 0x42, 0x0f, 0x5a, 0x0d, 0x2e, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x3b, 0x63, - 0x6f, 0x64, 0x65, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, -} - -var ( - file_proto_codes_proto_rawDescOnce sync.Once - file_proto_codes_proto_rawDescData = file_proto_codes_proto_rawDesc -) - -func file_proto_codes_proto_rawDescGZIP() []byte { - file_proto_codes_proto_rawDescOnce.Do(func() { - file_proto_codes_proto_rawDescData = protoimpl.X.CompressGZIP(file_proto_codes_proto_rawDescData) - }) - return file_proto_codes_proto_rawDescData -} - -var file_proto_codes_proto_msgTypes = make([]protoimpl.MessageInfo, 4) -var file_proto_codes_proto_goTypes = []interface{}{ - (*CreateRequest)(nil), // 0: codes.CreateRequest - (*CreateResponse)(nil), // 1: codes.CreateResponse - (*VerifyRequest)(nil), // 2: codes.VerifyRequest - (*VerifyResponse)(nil), // 3: codes.VerifyResponse - (*timestamppb.Timestamp)(nil), // 4: google.protobuf.Timestamp -} -var file_proto_codes_proto_depIdxs = []int32{ - 4, // 0: codes.CreateRequest.expires_at:type_name -> google.protobuf.Timestamp - 0, // 1: codes.Codes.Create:input_type -> codes.CreateRequest - 2, // 2: codes.Codes.Verify:input_type -> codes.VerifyRequest - 1, // 3: codes.Codes.Create:output_type -> codes.CreateResponse - 3, // 4: codes.Codes.Verify:output_type -> codes.VerifyResponse - 3, // [3:5] is the sub-list for method output_type - 1, // [1:3] is the sub-list for method input_type - 1, // [1:1] is the sub-list for extension type_name - 1, // [1:1] is the sub-list for extension extendee - 0, // [0:1] is the sub-list for field type_name -} - -func init() { file_proto_codes_proto_init() } -func file_proto_codes_proto_init() { - if File_proto_codes_proto != nil { - return - } - if !protoimpl.UnsafeEnabled { - file_proto_codes_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*CreateRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_proto_codes_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*CreateResponse); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_proto_codes_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*VerifyRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_proto_codes_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*VerifyResponse); 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_proto_codes_proto_rawDesc, - NumEnums: 0, - NumMessages: 4, - NumExtensions: 0, - NumServices: 1, - }, - GoTypes: file_proto_codes_proto_goTypes, - DependencyIndexes: file_proto_codes_proto_depIdxs, - MessageInfos: file_proto_codes_proto_msgTypes, - }.Build() - File_proto_codes_proto = out.File - file_proto_codes_proto_rawDesc = nil - file_proto_codes_proto_goTypes = nil - file_proto_codes_proto_depIdxs = nil -} diff --git a/codes/proto/codes.pb.micro.go b/codes/proto/codes.pb.micro.go deleted file mode 100644 index b5b7ed2..0000000 --- a/codes/proto/codes.pb.micro.go +++ /dev/null @@ -1,111 +0,0 @@ -// Code generated by protoc-gen-micro. DO NOT EDIT. -// source: proto/codes.proto - -package codes - -import ( - fmt "fmt" - proto "github.com/golang/protobuf/proto" - _ "google.golang.org/protobuf/types/known/timestamppb" - math "math" -) - -import ( - context "context" - api "github.com/micro/micro/v3/service/api" - client "github.com/micro/micro/v3/service/client" - server "github.com/micro/micro/v3/service/server" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package - -// Reference imports to suppress errors if they are not otherwise used. -var _ api.Endpoint -var _ context.Context -var _ client.Option -var _ server.Option - -// Api Endpoints for Codes service - -func NewCodesEndpoints() []*api.Endpoint { - return []*api.Endpoint{} -} - -// Client API for Codes service - -type CodesService interface { - Create(ctx context.Context, in *CreateRequest, opts ...client.CallOption) (*CreateResponse, error) - Verify(ctx context.Context, in *VerifyRequest, opts ...client.CallOption) (*VerifyResponse, error) -} - -type codesService struct { - c client.Client - name string -} - -func NewCodesService(name string, c client.Client) CodesService { - return &codesService{ - c: c, - name: name, - } -} - -func (c *codesService) Create(ctx context.Context, in *CreateRequest, opts ...client.CallOption) (*CreateResponse, error) { - req := c.c.NewRequest(c.name, "Codes.Create", in) - out := new(CreateResponse) - err := c.c.Call(ctx, req, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *codesService) Verify(ctx context.Context, in *VerifyRequest, opts ...client.CallOption) (*VerifyResponse, error) { - req := c.c.NewRequest(c.name, "Codes.Verify", in) - out := new(VerifyResponse) - err := c.c.Call(ctx, req, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// Server API for Codes service - -type CodesHandler interface { - Create(context.Context, *CreateRequest, *CreateResponse) error - Verify(context.Context, *VerifyRequest, *VerifyResponse) error -} - -func RegisterCodesHandler(s server.Server, hdlr CodesHandler, opts ...server.HandlerOption) error { - type codes interface { - Create(ctx context.Context, in *CreateRequest, out *CreateResponse) error - Verify(ctx context.Context, in *VerifyRequest, out *VerifyResponse) error - } - type Codes struct { - codes - } - h := &codesHandler{hdlr} - return s.Handle(s.NewHandler(&Codes{h}, opts...)) -} - -type codesHandler struct { - CodesHandler -} - -func (h *codesHandler) Create(ctx context.Context, in *CreateRequest, out *CreateResponse) error { - return h.CodesHandler.Create(ctx, in, out) -} - -func (h *codesHandler) Verify(ctx context.Context, in *VerifyRequest, out *VerifyResponse) error { - return h.CodesHandler.Verify(ctx, in, out) -} diff --git a/codes/proto/codes.proto b/codes/proto/codes.proto deleted file mode 100644 index c5a9e55..0000000 --- a/codes/proto/codes.proto +++ /dev/null @@ -1,26 +0,0 @@ -syntax = "proto3"; - -package codes; -option go_package = "./proto;codes"; -import "google/protobuf/timestamp.proto"; - -service Codes { - rpc Create(CreateRequest) returns (CreateResponse); - rpc Verify(VerifyRequest) returns (VerifyResponse); -} - -message CreateRequest { - string identity = 1; // e.g. phone number or email being verified - google.protobuf.Timestamp expires_at = 2; // expiry time for the code, default 5 minutes -} - -message CreateResponse { - string code = 1; -} - -message VerifyRequest { - string code = 1; - string identity = 2; -} - -message VerifyResponse {}