More admin data delete endpoints (#361)

This commit is contained in:
Dominic Wong
2022-02-02 12:09:24 +00:00
committed by GitHub
parent e3a83152fe
commit e0bb9a8765
10 changed files with 152 additions and 4 deletions

View File

@@ -111,7 +111,6 @@ func Search(ctx context.Context, typ string, entity *Entity, radius float64, num
// get the index
index := getIndex(ctx)
points := index.KNearest(entity, numEntities, geo.Meters(radius), func(p geo.Point) bool {
e, ok := p.(*Entity)
if !ok || e.Type != typ {
@@ -132,3 +131,11 @@ func Search(ctx context.Context, typ string, entity *Entity, radius float64, num
return entities
}
func DeleteIndex(tenantID string) error {
mtx.Lock()
defer mtx.Unlock()
delete(indexes, tenantID)
return nil
}

View File

@@ -6,9 +6,12 @@ import (
"github.com/micro/micro/v3/service"
"github.com/micro/micro/v3/service/errors"
"github.com/micro/micro/v3/service/logger"
"github.com/micro/services/location/domain"
loc "github.com/micro/services/location/proto"
"github.com/micro/services/location/subscriber"
pauth "github.com/micro/services/pkg/auth"
adminpb "github.com/micro/services/pkg/service/proto"
)
type Location struct{}
@@ -70,3 +73,21 @@ func (l *Location) Search(ctx context.Context, req *loc.SearchRequest, rsp *loc.
return nil
}
func (l *Location) 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")
}
if err := domain.DeleteIndex(request.TenantId); err != nil {
return err
}
logger.Infof("Deleted index for %s", request.TenantId)
return nil
}

View File

@@ -6,6 +6,7 @@ import (
"github.com/micro/micro/v3/service"
"github.com/micro/services/location/handler"
pb "github.com/micro/services/location/proto"
admin "github.com/micro/services/pkg/service/proto"
"github.com/micro/services/pkg/tracing"
)
@@ -14,7 +15,9 @@ func main() {
service.Name("location"),
)
pb.RegisterLocationHandler(location.Server(), new(handler.Location))
h := new(handler.Location)
pb.RegisterLocationHandler(location.Server(), h)
admin.RegisterAdminHandler(location.Server(), h)
// TODO reinstate me
//service.Subscribe(subscriber.Topic, new(subscriber.Location))