Пример #1
0
        private void ConfigureGlobalRules()
        {
            var builder = Environment.Host.RouteBuilder;

            //
            // Use conditional hal to provide global rules only at webserver level
            var hal = Environment.Hal as IConditionalHalService;

            builder.MapWebApiRoute(Defines.GlobalRulesSectionResource.Guid, $"{Defines.GLOBAL_RULES_SECTION_PATH}/{{id?}}", new { controller = "GlobalRulesSection" });
            builder.MapWebApiRoute(Defines.GlobalRulesResource.Guid, $"{Defines.GLOBAL_RULES_PATH}/{{id?}}", new { controller = "GlobalRules" });

            if (hal != null)
            {
                hal.ProvideLink(Defines.GlobalRulesSectionResource.Guid, "self", ir => new { href = GlobalRulesHelper.GetSectionLocation(ir.id) });
                hal.ProvideLink(Defines.GlobalRulesResource.Guid, "self", ir => new { href = GlobalRulesHelper.GetRuleLocation(ir.id) });

                // Rewrite -> Section
                hal.ProvideLink(
                    Defines.Resource.Guid,
                    Defines.GlobalRulesSectionResource.Name,
                    rewrite => new { href = GlobalRulesHelper.GetSectionLocation(rewrite.id) },
                    rewrite => string.IsNullOrEmpty(rewrite.scope));

                // Section -> Rules
                hal.ProvideLink(Defines.GlobalRulesSectionResource.Guid, Defines.GlobalRulesResource.Name, globalRulesSection => new { href = $"/{Defines.GLOBAL_RULES_PATH}?{Defines.IDENTIFIER}={globalRulesSection.id}" });
            }
        }
Пример #2
0
        public object Post([FromBody] dynamic model)
        {
            if (model == null)
            {
                throw new ApiArgumentException("model");
            }

            RewriteId parentId = RewriteHelper.GetRewriteIdFromBody(model);

            if (parentId == null)
            {
                throw new ApiArgumentException("url_rewrite");
            }

            Site site = parentId.SiteId == null ? null : SiteHelper.GetSite(parentId.SiteId.Value);

            string configPath           = ManagementUnit.ResolveConfigScope(model);
            InboundRulesSection section = GlobalRulesHelper.GetSection(site, parentId.Path, configPath);

            InboundRule rule = GlobalRulesHelper.CreateRule(model, section);

            GlobalRulesHelper.AddRule(rule, section, model);

            ManagementUnit.Current.Commit();

            dynamic r = GlobalRulesHelper.RuleToJsonModel(rule, site, parentId.Path, Context.Request.GetFields(), true);

            return(Created(GlobalRulesHelper.GetRuleLocation(r.id), r));
        }
Пример #3
0
        public object Patch([FromBody] dynamic model, string id)
        {
            var globalRuleId = new InboundRuleId(id);

            Site site = globalRuleId.SiteId == null ? null : SiteHelper.GetSite(globalRuleId.SiteId.Value);

            if (globalRuleId.SiteId != null && site == null)
            {
                return(NotFound());
            }

            InboundRulesSection section = GlobalRulesHelper.GetSection(site, globalRuleId.Path);
            InboundRule         rule    = (InboundRule)section.InboundRules.FirstOrDefault(r => r.Name.Equals(globalRuleId.Name, StringComparison.OrdinalIgnoreCase));

            if (rule == null)
            {
                return(NotFound());
            }

            GlobalRulesHelper.UpdateRule(model, rule, section);

            ManagementUnit.Current.Commit();

            dynamic updatedRule = GlobalRulesHelper.RuleToJsonModel(rule, site, globalRuleId.Path, Context.Request.GetFields(), true);

            if (updatedRule.id != id)
            {
                return(LocationChanged(GlobalRulesHelper.GetRuleLocation(updatedRule.id), updatedRule));
            }

            return(updatedRule);
        }
        public object Get()
        {
            RewriteHelper.ResolveRewrite(Context, out Site site, out string path);

            if (path == null)
            {
                return(NotFound());
            }

            dynamic d = GlobalRulesHelper.SectionToJsonModel(site, path);

            return(LocationChanged(GlobalRulesHelper.GetSectionLocation(d.id), d));
        }
        public object Get(string id)
        {
            var rewriteId = new RewriteId(id);

            Site site = rewriteId.SiteId == null ? null : SiteHelper.GetSite(rewriteId.SiteId.Value);

            if (rewriteId.SiteId != null && site == null)
            {
                Context.Response.StatusCode = (int)HttpStatusCode.NotFound;
                return(null);
            }

            return(GlobalRulesHelper.SectionToJsonModel(site, rewriteId.Path));
        }
        public void Delete(string id)
        {
            var globalRulesId = new RewriteId(id);

            Context.Response.StatusCode = (int)HttpStatusCode.NoContent;

            Site site = (globalRulesId.SiteId != null) ? SiteHelper.GetSite(globalRulesId.SiteId.Value) : null;

            if (site != null)
            {
                var section = GlobalRulesHelper.GetSection(site, globalRulesId.Path, ManagementUnit.ResolveConfigScope());
                section.RevertToParent();
                ManagementUnit.Current.Commit();
            }
        }
Пример #7
0
        public object Get(string id)
        {
            var inboundRuleId = new InboundRuleId(id);

            Site site = inboundRuleId.SiteId == null ? null : SiteHelper.GetSite(inboundRuleId.SiteId.Value);

            if (inboundRuleId.SiteId != null && site == null)
            {
                return(NotFound());
            }

            InboundRule rule = (InboundRule)GlobalRulesHelper.GetSection(site, inboundRuleId.Path).InboundRules.FirstOrDefault(r => r.Name.Equals(inboundRuleId.Name, StringComparison.OrdinalIgnoreCase));

            if (rule == null)
            {
                return(NotFound());
            }

            return(GlobalRulesHelper.RuleToJsonModel(rule, site, inboundRuleId.Path, Context.Request.GetFields()));
        }
Пример #8
0
        public object Get()
        {
            string globalRulesId = Context.Request.Query[Defines.IDENTIFIER];

            if (string.IsNullOrEmpty(globalRulesId))
            {
                return(NotFound());
            }

            var sectionId = new RewriteId(globalRulesId);

            Site site = sectionId.SiteId == null ? null : SiteHelper.GetSite(sectionId.SiteId.Value);

            InboundRuleCollection rules = GlobalRulesHelper.GetSection(site, sectionId.Path).InboundRules;

            this.Context.Response.SetItemsCount(rules.Count());

            return(new {
                rules = rules.Select(rule => GlobalRulesHelper.RuleToJsonModelRef((InboundRule)rule, site, sectionId.Path, Context.Request.GetFields()))
            });
        }
Пример #9
0
        public void Delete(string id)
        {
            InboundRule rule         = null;
            var         globalRuleId = new InboundRuleId(id);

            Site site = globalRuleId.SiteId == null ? null : SiteHelper.GetSite(globalRuleId.SiteId.Value);

            if (globalRuleId.SiteId == null || site != null)
            {
                rule = (InboundRule)GlobalRulesHelper.GetSection(site, globalRuleId.Path).InboundRules.FirstOrDefault(r => r.Name.Equals(globalRuleId.Name, StringComparison.OrdinalIgnoreCase));
            }

            if (rule != null)
            {
                var section = GlobalRulesHelper.GetSection(site, globalRuleId.Path, ManagementUnit.ResolveConfigScope());

                GlobalRulesHelper.DeleteRule(rule, section);
                ManagementUnit.Current.Commit();
            }

            Context.Response.StatusCode = (int)HttpStatusCode.NoContent;
        }
        public object Patch(string id, [FromBody] dynamic model)
        {
            if (model == null)
            {
                throw new ApiArgumentException("model");
            }

            RewriteId globalRulesId = new RewriteId(id);

            Site site = globalRulesId.SiteId == null ? null : SiteHelper.GetSite(globalRulesId.SiteId.Value);

            if (globalRulesId.SiteId != null && site == null)
            {
                return(NotFound());
            }

            string configPath = model == null ? null : ManagementUnit.ResolveConfigScope(model);

            GlobalRulesHelper.UpdateSection(model, site, globalRulesId.Path, configPath);

            ManagementUnit.Current.Commit();

            return(GlobalRulesHelper.SectionToJsonModel(site, globalRulesId.Path));
        }