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

@@ -10,6 +10,8 @@ import (
log "github.com/micro/micro/v3/service/logger"
"github.com/micro/micro/v3/service/store"
file "github.com/micro/services/file/proto"
pauth "github.com/micro/services/pkg/auth"
adminpb "github.com/micro/services/pkg/service/proto"
"github.com/micro/services/pkg/tenant"
)
@@ -150,3 +152,32 @@ func (e *File) List(ctx context.Context, req *file.ListRequest, rsp *file.ListRe
return nil
}
func (e *File) 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")
}
path := filepath.Join("file", request.TenantId)
// read all the files for the project
records, err := store.List(store.ListPrefix(path))
if err != nil {
return err
}
for _, file := range records {
if err := store.Delete(file); err != nil {
return err
}
}
log.Infof("Deleted %d records for %s", len(records), request.TenantId)
return nil
}