コード例 #1
0
        protected override void ApplicationStartup(ILifetimeScope container, IPipelines pipelines)
        {
            pipelines.OnError.AddItemToEndOfPipeline((ctx, ex) =>
            {
                AddCorsHeaders(ctx.Response);

                return(ctx.Response);
            });
            pipelines.AfterRequest += (ctx) =>
            {
                AddCorsHeaders(ctx.Response);
            };
            pipelines.SetupTokenAuthentication(container);
            _exceptionHandler = container.Resolve <IExceptionHandler>();
            var tasks        = container.Resolve <IEnumerable <ITask> >();
            var tasksHandler = container.Resolve <ITaskHandler>();

            Task.Factory.StartNew(async() =>
            {
                //Wait till Storage Service is ready.
                await Task.Delay(5000);
                await tasksHandler.ExecuteTasksAsync(tasks);
            }, TaskCreationOptions.LongRunning);

            Logger.Info("Warden API has started.");
        }
コード例 #2
0
        protected override void RequestStartup(ILifetimeScope container, IPipelines pipelines, NancyContext context)
        {
            pipelines.SetupTokenAuthentication(container.Resolve <IJwtTokenHandler>());
            pipelines.OnError.AddItemToEndOfPipeline((ctx, ex) =>
            {
                _exceptionHandler.Handle(ex, ctx.ToExceptionData(),
                                         "Request details", "Collectively", "Service", "Users");

                return(ctx.Response);
            });
        }
コード例 #3
0
 protected override void ApplicationStartup(ILifetimeScope container, IPipelines pipelines)
 {
     pipelines.AfterRequest += (ctx) =>
     {
         ctx.Response.Headers.Add("Access-Control-Allow-Origin", "*");
         ctx.Response.Headers.Add("Access-Control-Allow-Headers", "Authorization, Origin, X-Requested-With, Content-Type, Accept");
     };
     _exceptionHandler = container.Resolve <IExceptionHandler>();
     pipelines.SetupTokenAuthentication(container);
     Logger.Info("Warden.Services.Spawn API has started.");
 }
コード例 #4
0
 protected override void ApplicationStartup(ILifetimeScope container, IPipelines pipelines)
 {
     pipelines.AfterRequest += (ctx) =>
     {
         ctx.Response.Headers.Add("Access-Control-Allow-Origin", "*");
         ctx.Response.Headers.Add("Access-Control-Allow-Methods", "POST,PUT,GET,OPTIONS,DELETE");
         ctx.Response.Headers.Add("Access-Control-Allow-Headers",
                                  "Authorization, Origin, X-Requested-With, Content-Type, Accept");
     };
     pipelines.SetupTokenAuthentication(container);
     _exceptionHandler = container.Resolve <IExceptionHandler>();
     Logger.Info("Collectively.Services.Identity API has started.");
 }
コード例 #5
0
        protected override void ApplicationStartup(ILifetimeScope container, IPipelines pipelines)
        {
            var databaseSettings    = container.Resolve <MongoDbSettings>();
            var databaseInitializer = container.Resolve <IDatabaseInitializer>();

            databaseInitializer.InitializeAsync();
            pipelines.AfterRequest += (ctx) =>
            {
                ctx.Response.Headers.Add("Access-Control-Allow-Origin", "*");
                ctx.Response.Headers.Add("Access-Control-Allow-Headers", "Authorization, Origin, X-Requested-With, Content-Type, Accept");
            };
            pipelines.SetupTokenAuthentication(container);
            _exceptionHandler = container.Resolve <IExceptionHandler>();
            Logger.Info("Warden.Services.WardenChecks API has started.");
        }
コード例 #6
0
        protected override void RequestStartup(ILifetimeScope container, IPipelines pipelines, NancyContext context)
        {
            pipelines.SetupTokenAuthentication(container.Resolve <IJwtTokenHandler>());
            pipelines.OnError.AddItemToEndOfPipeline((ctx, ex) =>
            {
                ctx.Response = ErrorResponse.FromException(ex, context.Environment);
                AddCorsHeaders(ctx.Response);
                _exceptionHandler.Handle(ex, ctx.ToExceptionData(),
                                         "Request details", "Collectively", "API");

                return(ctx.Response);
            });
            if (_validateAccountState)
            {
                pipelines.BeforeRequest += async(ctx, token) => {
                    var nancyContext = ctx as NancyContext;
                    if (nancyContext.CurrentUser == null)
                    {
                        return(null);
                    }
                    var userId = nancyContext.CurrentUser.Identity.Name;
                    var accountStateProvider = container.Resolve <IAccountStateProvider>();
                    var state = await accountStateProvider.GetAsync(userId);

                    if (state == "unconfirmed" && nancyContext.Request.Method == "GET")
                    {
                        return(null);
                    }
                    if (state.Empty() || ForbiddenAccountStates.Contains(state))
                    {
                        return(HttpStatusCode.Forbidden);
                    }
                    return(null);
                };
            }
        }
コード例 #7
0
 protected override void RequestStartup(ILifetimeScope container, IPipelines pipelines, NancyContext context)
 {
     pipelines.SetupTokenAuthentication(container.Resolve <IJwtTokenHandler>());
 }