mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-11 19:04:35 +00:00
More admin data delete endpoints (#361)
This commit is contained in:
@@ -9,9 +9,12 @@ import (
|
||||
"github.com/google/uuid"
|
||||
"github.com/micro/micro/v3/service/client"
|
||||
"github.com/micro/micro/v3/service/errors"
|
||||
"github.com/micro/micro/v3/service/logger"
|
||||
"github.com/micro/micro/v3/service/store"
|
||||
streamPb "github.com/micro/services/mq/proto"
|
||||
pb "github.com/micro/services/notes/proto"
|
||||
pauth "github.com/micro/services/pkg/auth"
|
||||
adminpb "github.com/micro/services/pkg/service/proto"
|
||||
"github.com/micro/services/pkg/tenant"
|
||||
"google.golang.org/protobuf/types/known/structpb"
|
||||
)
|
||||
@@ -292,3 +295,29 @@ func (h *Notes) List(ctx context.Context, req *pb.ListRequest, rsp *pb.ListRespo
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *Notes) DeleteData(ctx context.Context, request *adminpb.DeleteDataRequest, response *adminpb.DeleteDataResponse) error {
|
||||
method := "admin.DeleteData"
|
||||
_, err := pauth.VerifyMicroAdmin(ctx, method)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(request.TenantId) == 0 {
|
||||
return errors.BadRequest(method, "Missing tenant ID")
|
||||
}
|
||||
|
||||
keys, err := store.List(store.ListPrefix(request.TenantId))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, k := range keys {
|
||||
if err := store.Delete(k); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
logger.Infof("Deleted %d keys for %s", len(keys), request.TenantId)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
log "github.com/micro/micro/v3/service/logger"
|
||||
"github.com/micro/services/notes/handler"
|
||||
pb "github.com/micro/services/notes/proto"
|
||||
admin "github.com/micro/services/pkg/service/proto"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -17,8 +18,10 @@ func main() {
|
||||
// Initialise service
|
||||
srv.Init()
|
||||
|
||||
h := handler.New(srv.Client())
|
||||
// Register Handler
|
||||
pb.RegisterNotesHandler(srv.Server(), handler.New(srv.Client()))
|
||||
pb.RegisterNotesHandler(srv.Server(), h)
|
||||
admin.RegisterAdminHandler(srv.Server(), h)
|
||||
|
||||
// Run service
|
||||
if err := srv.Run(); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user