public override async Task <EnableResp> Enable(EnableReq request, ServerCallContext context)
        {
            var enableSource = new TaskCompletionSource <bool>();

            var options = request.Options;

            var user = await GetUser(_authenticationProvider, context.RequestHeaders);

            var name  = options.Name;
            var runAs = new ProjectionManagementMessage.RunAs(user);

            var envelope = new CallbackEnvelope(OnMessage);

            _queue.Publish(new ProjectionManagementMessage.Command.Enable(envelope, name, runAs));

            await enableSource.Task;

            return(new EnableResp());

            void OnMessage(Message message)
            {
                if (!(message is ProjectionManagementMessage.Updated))
                {
                    enableSource.TrySetException(UnknownMessage <ProjectionManagementMessage.Updated>(message));
                    return;
                }

                enableSource.TrySetResult(true);
            }
        }
예제 #2
0
        public override async Task <ResetResp> Reset(ResetReq request, ServerCallContext context)
        {
            var resetSource = new TaskCompletionSource <bool>();

            var options = request.Options;

            var user = context.GetHttpContext().User;

            if (!await _authorizationProvider.CheckAccessAsync(user, ResetOperation, context.CancellationToken)
                .ConfigureAwait(false))
            {
                throw AccessDenied();
            }
            var name  = options.Name;
            var runAs = new ProjectionManagementMessage.RunAs(user);

            var envelope = new CallbackEnvelope(OnMessage);

            _queue.Publish(new ProjectionManagementMessage.Command.Reset(envelope, name, runAs));

            await resetSource.Task.ConfigureAwait(false);

            return(new ResetResp());

            void OnMessage(Message message)
            {
                if (!(message is ProjectionManagementMessage.Updated))
                {
                    resetSource.TrySetException(UnknownMessage <ProjectionManagementMessage.Updated>(message));
                    return;
                }

                resetSource.TrySetResult(true);
            }
        }
예제 #3
0
            public NewProjectionInitializer(
                int projectionId,
                string name,
                ProjectionMode projectionMode,
                string handlerType,
                string query,
                bool enabled,
                bool emitEnabled,
                bool checkpointsEnabled,
                bool enableRunAs,
                ProjectionManagementMessage.RunAs runAs,
                IEnvelope replyEnvelope)
            {
                if (projectionMode >= ProjectionMode.Continuous && !checkpointsEnabled)
                {
                    throw new InvalidOperationException("Continuous mode requires checkpoints");
                }

                if (emitEnabled && !checkpointsEnabled)
                {
                    throw new InvalidOperationException("Emit requires checkpoints");
                }

                _projectionId       = projectionId;
                _enabled            = enabled;
                _handlerType        = handlerType;
                _query              = query;
                _projectionMode     = projectionMode;
                _emitEnabled        = emitEnabled;
                _checkpointsEnabled = checkpointsEnabled;
                _enableRunAs        = enableRunAs;
                _runAs              = runAs;
                _replyEnvelope      = replyEnvelope;
                _name = name;
            }
예제 #4
0
        public static SerializedRunAs SerializePrincipal(ProjectionManagementMessage.RunAs runAs)
        {
            if (runAs == null)
            {
                return(null);
            }
            if (runAs.Principal == null)
            {
                return(null); // anonymous
            }
            if (runAs.Principal == SystemAccount.Principal)
            {
                return new SerializedRunAs {
                           Name = "$system"
                }
            }
            ;

            var genericPrincipal = runAs.Principal as OpenGenericPrincipal;

            if (genericPrincipal == null)
            {
                throw new ArgumentException(
                          "OpenGenericPrincipal is the only supported principal type in projections", "runAs");
            }
            return(new SerializedRunAs {
                Name = runAs.Principal.Identity.Name, Roles = genericPrincipal.Roles
            });
        }
예제 #5
0
        public override async Task <DisableResp> Disable(DisableReq request, ServerCallContext context)
        {
            var disableSource = new TaskCompletionSource <bool>();

            var options = request.Options;

            var user = context.GetHttpContext().User;

            var name  = options.Name;
            var runAs = new ProjectionManagementMessage.RunAs(user);

            var envelope = new CallbackEnvelope(OnMessage);

            _queue.Publish(options.WriteCheckpoint
                                ? (Message) new ProjectionManagementMessage.Command.Abort(envelope, name, runAs)
                                : new ProjectionManagementMessage.Command.Disable(envelope, name, runAs));

            await disableSource.Task.ConfigureAwait(false);

            return(new DisableResp());

            void OnMessage(Message message)
            {
                if (!(message is ProjectionManagementMessage.Updated))
                {
                    disableSource.TrySetException(UnknownMessage <ProjectionManagementMessage.Updated>(message));
                    return;
                }

                disableSource.TrySetResult(true);
            }
        }
예제 #6
0
 protected override void Given()
 {
     _name  = "name";
     _runAs = ProjectionManagementMessage.RunAs.System;
     _deleteCheckpointStream = true;
     _deleteStateStream      = true;
 }
        public override async Task <DeleteResp> Delete(DeleteReq request, ServerCallContext context)
        {
            var deletedSource = new TaskCompletionSource <bool>();
            var options       = request.Options;

            var user = await GetUser(_authenticationProvider, context.RequestHeaders).ConfigureAwait(false);

            var name = options.Name;
            var deleteCheckpointStream = options.DeleteCheckpointStream;
            var deleteStateStream      = options.DeleteStateStream;
            var deleteEmittedStreams   = options.DeleteEmittedStreams;
            var runAs = new ProjectionManagementMessage.RunAs(user);

            var envelope = new CallbackEnvelope(OnMessage);

            _queue.Publish(new ProjectionManagementMessage.Command.Delete(envelope, name, runAs,
                                                                          deleteCheckpointStream, deleteStateStream, deleteEmittedStreams));

            await deletedSource.Task.ConfigureAwait(false);

            return(new DeleteResp());

            void OnMessage(Message message)
            {
                if (!(message is ProjectionManagementMessage.Updated))
                {
                    deletedSource.TrySetException(UnknownMessage <ProjectionManagementMessage.Updated>(message));
                    return;
                }

                deletedSource.TrySetResult(true);
            }
        }
        public override async Task <CreateResp> Create(CreateReq request, ServerCallContext context)
        {
            var createdSource = new TaskCompletionSource <bool>();
            var options       = request.Options;

            var user = await GetUser(_authenticationProvider, context.RequestHeaders).ConfigureAwait(false);

            const string handlerType = "JS";
            var          name        = options.ModeCase switch {
                ModeOneofCase.Continuous => options.Continuous.Name,
                ModeOneofCase.Transient => options.Transient.Name,
                ModeOneofCase.OneTime => Guid.NewGuid().ToString("D"),
                _ => throw new InvalidOperationException()
            };
            var projectionMode = options.ModeCase switch {
                ModeOneofCase.Continuous => ProjectionMode.Continuous,
                ModeOneofCase.Transient => ProjectionMode.Transient,
                ModeOneofCase.OneTime => ProjectionMode.OneTime,
                _ => throw new InvalidOperationException()
            };
            var emitEnabled = options.ModeCase switch {
                ModeOneofCase.Continuous => options.Continuous.TrackEmittedStreams,
                _ => false
            };
            var checkpointsEnables = options.ModeCase switch {
                ModeOneofCase.Continuous => true,
                ModeOneofCase.OneTime => false,
                ModeOneofCase.Transient => false,
                _ => throw new InvalidOperationException()
            };
            var enabled             = true;
            var trackEmittedStreams = (options.ModeCase, emitEnabled) switch {
                (ModeOneofCase.Continuous, false) => true,
                _ => false
            };
            var runAs = new ProjectionManagementMessage.RunAs(user);

            var envelope = new CallbackEnvelope(OnMessage);

            _queue.Publish(new ProjectionManagementMessage.Command.Post(envelope, projectionMode, name, runAs,
                                                                        handlerType, options.Query, enabled, checkpointsEnables, emitEnabled, trackEmittedStreams, true));

            await createdSource.Task.ConfigureAwait(false);

            return(new CreateResp());

            void OnMessage(Message message)
            {
                if (!(message is ProjectionManagementMessage.Updated))
                {
                    createdSource.TrySetException(UnknownMessage <ProjectionManagementMessage.Updated>(message));
                    return;
                }

                createdSource.TrySetResult(true);
            }
        }
    }
}
예제 #9
0
 protected override void Given()
 {
     _name        = "name";
     _runAs       = ProjectionManagementMessage.RunAs.System;
     _handlerType = "JS";
     _query       = "fromAll()";
     _emitEnabled = true;
 }
예제 #10
0
 protected override void Given()
 {
     _name               = "name";
     _runAs              = ProjectionManagementMessage.RunAs.System;
     _mode               = ProjectionMode.Continuous;
     _handlerType        = "JS";
     _query              = "fromAll();";
     _enabled            = true;
     _checkpointsEnabled = true;
     _emitEnabled        = true;
     _enableRunAs        = true;
 }
 protected override void Given()
 {
     _name  = "name";
     _runAs = ProjectionManagementMessage.RunAs.System;
     _masterCorrelationId = Guid.NewGuid();
     _masterWorkerId      = Guid.NewGuid();
     _definition          =
         new SlaveProjectionDefinitions(
             new SlaveProjectionDefinitions.Definition(
                 "sl1",
                 "JS",
                 "fromAll()",
                 SlaveProjectionDefinitions.SlaveProjectionRequestedNumber.OnePerThread,
                 ProjectionMode.Transient,
                 true,
                 true,
                 true,
                 ProjectionManagementMessage.RunAs.System));
 }
예제 #12
0
        public override async Task <DeleteResp> Delete(DeleteReq request, ServerCallContext context)
        {
            var deletedSource = new TaskCompletionSource <bool>();
            var options       = request.Options;

            var user = context.GetHttpContext().User;

            if (!await _authorizationProvider.CheckAccessAsync(user, DeleteOperation, context.CancellationToken)
                .ConfigureAwait(false))
            {
                throw RpcExceptions.AccessDenied();
            }
            var name = options.Name;
            var deleteCheckpointStream = options.DeleteCheckpointStream;
            var deleteStateStream      = options.DeleteStateStream;
            var deleteEmittedStreams   = options.DeleteEmittedStreams;
            var runAs = new ProjectionManagementMessage.RunAs(user);

            var envelope = new CallbackEnvelope(OnMessage);

            _queue.Publish(new ProjectionManagementMessage.Command.Delete(envelope, name, runAs,
                                                                          deleteCheckpointStream, deleteStateStream, deleteEmittedStreams));

            await deletedSource.Task.ConfigureAwait(false);

            return(new DeleteResp());

            void OnMessage(Message message)
            {
                if (!(message is ProjectionManagementMessage.Updated))
                {
                    deletedSource.TrySetException(UnknownMessage <ProjectionManagementMessage.Updated>(message));
                    return;
                }

                deletedSource.TrySetResult(true);
            }
        }
예제 #13
0
 protected override void Given()
 {
     _name  = "name";
     _runAs = ProjectionManagementMessage.RunAs.System;
 }
 protected override void Given()
 {
     _name      = "name";
     _runAs     = ProjectionManagementMessage.RunAs.System;
     _setRemove = ProjectionManagementMessage.Command.SetRunAs.SetRemove.Remove;
 }