2020-10-29 22:43:02 +00:00
|
|
|
package authorizer
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"io"
|
|
|
|
|
|
|
|
"github.com/influxdata/influxdb/v2"
|
2021-09-13 19:12:35 +00:00
|
|
|
"github.com/influxdata/influxdb/v2/kit/platform"
|
2020-10-29 22:43:02 +00:00
|
|
|
"github.com/influxdata/influxdb/v2/kit/tracing"
|
|
|
|
)
|
|
|
|
|
|
|
|
var _ influxdb.RestoreService = (*RestoreService)(nil)
|
|
|
|
|
|
|
|
// RestoreService wraps a influxdb.RestoreService and authorizes actions
|
|
|
|
// against it appropriately.
|
|
|
|
type RestoreService struct {
|
|
|
|
s influxdb.RestoreService
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewRestoreService constructs an instance of an authorizing restore service.
|
|
|
|
func NewRestoreService(s influxdb.RestoreService) *RestoreService {
|
|
|
|
return &RestoreService{
|
|
|
|
s: s,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-03 23:36:28 +00:00
|
|
|
func (b RestoreService) RestoreKVStore(ctx context.Context, r io.Reader) error {
|
|
|
|
span, ctx := tracing.StartSpanFromContext(ctx)
|
|
|
|
defer span.Finish()
|
|
|
|
|
|
|
|
if err := IsAllowedAll(ctx, influxdb.OperPermissions()); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return b.s.RestoreKVStore(ctx, r)
|
|
|
|
}
|
|
|
|
|
2021-03-30 18:10:02 +00:00
|
|
|
func (b RestoreService) RestoreBucket(ctx context.Context, id platform.ID, dbi []byte) (shardIDMap map[uint64]uint64, err error) {
|
2020-10-29 22:43:02 +00:00
|
|
|
span, ctx := tracing.StartSpanFromContext(ctx)
|
|
|
|
defer span.Finish()
|
|
|
|
|
2020-11-02 17:10:09 +00:00
|
|
|
if err := IsAllowedAll(ctx, influxdb.OperPermissions()); err != nil {
|
2020-10-29 22:43:02 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return b.s.RestoreBucket(ctx, id, dbi)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b RestoreService) RestoreShard(ctx context.Context, shardID uint64, r io.Reader) error {
|
|
|
|
span, ctx := tracing.StartSpanFromContext(ctx)
|
|
|
|
defer span.Finish()
|
|
|
|
|
2020-11-02 17:10:09 +00:00
|
|
|
if err := IsAllowedAll(ctx, influxdb.OperPermissions()); err != nil {
|
2020-10-29 22:43:02 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
return b.s.RestoreShard(ctx, shardID, r)
|
|
|
|
}
|