Example #1
0
        public override async Task <TombstoneResp> Tombstone(TombstoneReq request, ServerCallContext context)
        {
            var options    = request.Options;
            var streamName = options.StreamName;

            var expectedVersion = options.ExpectedStreamRevisionCase switch {
                TombstoneReq.Types.Options.ExpectedStreamRevisionOneofCase.Revision =>
                new StreamRevision(options.Revision).ToInt64(),
                TombstoneReq.Types.Options.ExpectedStreamRevisionOneofCase.Any =>
                AnyStreamRevision.Any.ToInt64(),
                TombstoneReq.Types.Options.ExpectedStreamRevisionOneofCase.NoStream =>
                AnyStreamRevision.NoStream.ToInt64(),
                TombstoneReq.Types.Options.ExpectedStreamRevisionOneofCase.StreamExists =>
                AnyStreamRevision.StreamExists.ToInt64(),
                _ => throw new InvalidOperationException()
            };

            var requiresLeader = GetRequiresLeader(context.RequestHeaders);

            var user = context.GetHttpContext().User;
            var op   = DeleteOperation.WithParameter(Plugins.Authorization.Operations.Streams.Parameters.StreamId(streamName));

            if (!await _provider.CheckAccessAsync(user, op, context.CancellationToken).ConfigureAwait(false))
            {
                throw AccessDenied();
            }

            var position = await DeleteInternal(streamName, expectedVersion, user, true, requiresLeader,
                                                context.CancellationToken).ConfigureAwait(false);

            return(position.HasValue
                                ? new TombstoneResp {
                Position = new TombstoneResp.Types.Position {
                    CommitPosition = position.Value.CommitPosition,
                    PreparePosition = position.Value.PreparePosition
                }
            }
                                : new TombstoneResp {
                NoPosition = new Empty()
            });
        }