Changed to URL Rewrite API surface.
This commit is contained in:
Родитель
9c17c82be9
Коммит
63867cb53e
|
@ -2,12 +2,42 @@
|
|||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
|
||||
using Microsoft.IIS.Administration.Core;
|
||||
using System;
|
||||
|
||||
namespace Microsoft.IIS.Administration.WebServer.UrlRewrite
|
||||
{
|
||||
// Keep public for resolution of enums from 'dynamic' types in helper classes i.e. DynamicHelper
|
||||
public enum OutboundRuleMatchType {
|
||||
ServerVariable,
|
||||
HtmlTags
|
||||
Tags
|
||||
}
|
||||
|
||||
static class OutboundMatchTypeHelper
|
||||
{
|
||||
public static string ToJsonModel(OutboundRuleMatchType matchType)
|
||||
{
|
||||
switch (matchType) {
|
||||
case OutboundRuleMatchType.ServerVariable:
|
||||
return "server_variable";
|
||||
case OutboundRuleMatchType.Tags:
|
||||
return "tags";
|
||||
default:
|
||||
throw new ArgumentException(nameof(matchType));
|
||||
}
|
||||
}
|
||||
|
||||
public static OutboundRuleMatchType FromJsonModel(string model)
|
||||
{
|
||||
switch (model.ToLowerInvariant()) {
|
||||
case "server_variable":
|
||||
return OutboundRuleMatchType.ServerVariable;
|
||||
case "tags":
|
||||
return OutboundRuleMatchType.Tags;
|
||||
default:
|
||||
throw new ApiArgumentException("match_type");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,12 +20,7 @@ namespace Microsoft.IIS.Administration.WebServer.UrlRewrite
|
|||
[ResourceInfo(Name = Defines.CustomTagsName)]
|
||||
public object Get()
|
||||
{
|
||||
string outboundRulesId = Context.Request.Query[Defines.OUTBOUND_RULES_SECTION_IDENTIFIER];
|
||||
|
||||
if (string.IsNullOrEmpty(outboundRulesId))
|
||||
{
|
||||
outboundRulesId = Context.Request.Query[Defines.IDENTIFIER];
|
||||
}
|
||||
string outboundRulesId = Context.Request.Query[Defines.IDENTIFIER];
|
||||
|
||||
if (string.IsNullOrEmpty(outboundRulesId))
|
||||
{
|
||||
|
@ -115,7 +110,11 @@ namespace Microsoft.IIS.Administration.WebServer.UrlRewrite
|
|||
throw new ApiArgumentException("model");
|
||||
}
|
||||
|
||||
RewriteId parentId = RewriteHelper.GetRewriteIdFromBody(model) ?? OutboundRulesHelper.GetSectionIdFromBody(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);
|
||||
|
||||
|
|
|
@ -20,11 +20,7 @@ namespace Microsoft.IIS.Administration.WebServer.UrlRewrite
|
|||
[ResourceInfo(Name = Defines.GlobalRulesName)]
|
||||
public object Get()
|
||||
{
|
||||
string globalRulesId = Context.Request.Query[Defines.GLOBAL_RULES_SECTION_IDENTIFIER];
|
||||
|
||||
if (string.IsNullOrEmpty(globalRulesId)) {
|
||||
globalRulesId = Context.Request.Query[Defines.IDENTIFIER];
|
||||
}
|
||||
string globalRulesId = Context.Request.Query[Defines.IDENTIFIER];
|
||||
|
||||
if (string.IsNullOrEmpty(globalRulesId)) {
|
||||
return NotFound();
|
||||
|
@ -106,7 +102,11 @@ namespace Microsoft.IIS.Administration.WebServer.UrlRewrite
|
|||
throw new ApiArgumentException("model");
|
||||
}
|
||||
|
||||
RewriteId parentId = RewriteHelper.GetRewriteIdFromBody(model) ?? GlobalRulesHelper.GetSectionIdFromBody(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);
|
||||
|
||||
|
|
|
@ -20,11 +20,7 @@ namespace Microsoft.IIS.Administration.WebServer.UrlRewrite
|
|||
[ResourceInfo(Name = Defines.InboundRulesName)]
|
||||
public object Get()
|
||||
{
|
||||
string inboundRulesId = Context.Request.Query[Defines.INBOUND_RULES_SECTION_IDENTIFIER];
|
||||
|
||||
if (string.IsNullOrEmpty(inboundRulesId)) {
|
||||
inboundRulesId = Context.Request.Query[Defines.IDENTIFIER];
|
||||
}
|
||||
string inboundRulesId = Context.Request.Query[Defines.IDENTIFIER];
|
||||
|
||||
if (string.IsNullOrEmpty(inboundRulesId)) {
|
||||
return NotFound();
|
||||
|
@ -108,7 +104,11 @@ namespace Microsoft.IIS.Administration.WebServer.UrlRewrite
|
|||
throw new ApiArgumentException("model");
|
||||
}
|
||||
|
||||
RewriteId parentId = RewriteHelper.GetRewriteIdFromBody(model) ?? InboundRulesHelper.GetSectionIdFromBody(model);
|
||||
RewriteId parentId = RewriteHelper.GetRewriteIdFromBody(model);
|
||||
|
||||
if (parentId == null) {
|
||||
throw new ApiArgumentException("url_rewrite");
|
||||
}
|
||||
|
||||
// Get site the rule is for if applicable
|
||||
Site site = parentId.SiteId == null ? null : SiteHelper.GetSite(parentId.SiteId.Value);
|
||||
|
|
|
@ -20,11 +20,7 @@ namespace Microsoft.IIS.Administration.WebServer.UrlRewrite
|
|||
[ResourceInfo(Name = Defines.OutboundRulesName)]
|
||||
public object Get()
|
||||
{
|
||||
string outboundRulesId = Context.Request.Query[Defines.OUTBOUND_RULES_SECTION_IDENTIFIER];
|
||||
|
||||
if (string.IsNullOrEmpty(outboundRulesId)) {
|
||||
outboundRulesId = Context.Request.Query[Defines.IDENTIFIER];
|
||||
}
|
||||
string outboundRulesId = Context.Request.Query[Defines.IDENTIFIER];
|
||||
|
||||
if (string.IsNullOrEmpty(outboundRulesId)) {
|
||||
return NotFound();
|
||||
|
@ -109,7 +105,11 @@ namespace Microsoft.IIS.Administration.WebServer.UrlRewrite
|
|||
throw new ApiArgumentException("model");
|
||||
}
|
||||
|
||||
RewriteId parentId = RewriteHelper.GetRewriteIdFromBody(model) ?? OutboundRulesHelper.GetSectionIdFromBody(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);
|
||||
|
||||
|
|
|
@ -21,11 +21,7 @@ namespace Microsoft.IIS.Administration.WebServer.UrlRewrite
|
|||
[ResourceInfo(Name = Defines.PreConditionsName)]
|
||||
public object Get()
|
||||
{
|
||||
string outboundRulesId = Context.Request.Query[Defines.OUTBOUND_RULES_SECTION_IDENTIFIER];
|
||||
|
||||
if (string.IsNullOrEmpty(outboundRulesId)) {
|
||||
outboundRulesId = Context.Request.Query[Defines.IDENTIFIER];
|
||||
}
|
||||
string outboundRulesId = Context.Request.Query[Defines.IDENTIFIER];
|
||||
|
||||
if (string.IsNullOrEmpty(outboundRulesId)) {
|
||||
return NotFound();
|
||||
|
@ -108,7 +104,7 @@ namespace Microsoft.IIS.Administration.WebServer.UrlRewrite
|
|||
throw new ApiArgumentException("model");
|
||||
}
|
||||
|
||||
RewriteId parentId = RewriteHelper.GetRewriteIdFromBody(model) ?? OutboundRulesHelper.GetSectionIdFromBody(model);
|
||||
RewriteId parentId = RewriteHelper.GetRewriteIdFromBody(model);
|
||||
|
||||
Site site = parentId.SiteId == null ? null : SiteHelper.GetSite(parentId.SiteId.Value);
|
||||
|
||||
|
|
|
@ -20,11 +20,7 @@ namespace Microsoft.IIS.Administration.WebServer.UrlRewrite
|
|||
[ResourceInfo(Name = Defines.ProvidersName)]
|
||||
public object Get()
|
||||
{
|
||||
string providersId = Context.Request.Query[Defines.PROVIDERS_SECTION_IDENTIFIER];
|
||||
|
||||
if (string.IsNullOrEmpty(providersId)) {
|
||||
providersId = Context.Request.Query[Defines.IDENTIFIER];
|
||||
}
|
||||
string providersId = Context.Request.Query[Defines.IDENTIFIER];
|
||||
|
||||
if (string.IsNullOrEmpty(providersId)) {
|
||||
return NotFound();
|
||||
|
@ -107,7 +103,11 @@ namespace Microsoft.IIS.Administration.WebServer.UrlRewrite
|
|||
throw new ApiArgumentException("model");
|
||||
}
|
||||
|
||||
RewriteId parentId = RewriteHelper.GetRewriteIdFromBody(model) ?? ProvidersHelper.GetSectionIdFromBody(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);
|
||||
|
||||
|
|
|
@ -20,11 +20,7 @@ namespace Microsoft.IIS.Administration.WebServer.UrlRewrite
|
|||
[ResourceInfo(Name = Defines.RewriteMapsName)]
|
||||
public object Get()
|
||||
{
|
||||
string rewriteMapsId = Context.Request.Query[Defines.REWRITE_MAPS_SECTION_IDENTIFIER];
|
||||
|
||||
if (string.IsNullOrEmpty(rewriteMapsId)) {
|
||||
rewriteMapsId = Context.Request.Query[Defines.IDENTIFIER];
|
||||
}
|
||||
string rewriteMapsId = Context.Request.Query[Defines.IDENTIFIER];
|
||||
|
||||
if (string.IsNullOrEmpty(rewriteMapsId)) {
|
||||
return NotFound();
|
||||
|
@ -39,7 +35,7 @@ namespace Microsoft.IIS.Administration.WebServer.UrlRewrite
|
|||
this.Context.Response.SetItemsCount(maps.Count());
|
||||
|
||||
return new {
|
||||
maps = maps.Select(map => RewriteMapsHelper.MapToJsonModelRef(map, site, sectionId.Path, Context.Request.GetFields()))
|
||||
entries = maps.Select(map => RewriteMapsHelper.MapToJsonModelRef(map, site, sectionId.Path, Context.Request.GetFields()))
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -106,7 +102,11 @@ namespace Microsoft.IIS.Administration.WebServer.UrlRewrite
|
|||
throw new ApiArgumentException("model");
|
||||
}
|
||||
|
||||
RewriteId parentId = RewriteHelper.GetRewriteIdFromBody(model) ?? RewriteMapsHelper.GetSectionIdFromBody(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);
|
||||
|
||||
|
|
|
@ -14,12 +14,12 @@ namespace Microsoft.IIS.Administration.WebServer.UrlRewrite
|
|||
private const string PROVIDERS_SECTION_ENDPOINT = "providers";
|
||||
private const string PROVIDERS_ENDPOINT = "entries";
|
||||
private const string REWRITE_MAPS_SECTION_ENDPOINT = "rewrite-maps";
|
||||
private const string REWRITE_MAPS_ENDPOINT = "maps";
|
||||
private const string REWRITE_MAPS_ENDPOINT = "entries";
|
||||
private const string GLOBAL_RULES_SECTION_ENDPOINT = "global-rules";
|
||||
private const string GLOBAL_RULES_ENDPOINT = "rules";
|
||||
private const string INBOUND_RULES_SECTION_ENDPOINT = "inbound-rules";
|
||||
private const string INBOUND_RULES_SECTION_ENDPOINT = "inbound";
|
||||
private const string INBOUND_RULES_ENDPOINT = "rules";
|
||||
private const string OUTBOUND_RULES_SECTION_ENDPOINT = "outbound-rules";
|
||||
private const string OUTBOUND_RULES_SECTION_ENDPOINT = "outbound";
|
||||
private const string OUTBOUND_RULES_ENDPOINT = "rules";
|
||||
private const string PRECONDITIONS_ENDPOINT = "preconditions";
|
||||
private const string CUSTOM_TAGS_ENDPOINT = "custom_tags";
|
||||
|
@ -40,33 +40,30 @@ namespace Microsoft.IIS.Administration.WebServer.UrlRewrite
|
|||
public const string ProvidersSectionName = "Microsoft.WebServer.UrlRewrite.Providers";
|
||||
public static ResDef ProvidersSectionResource = new ResDef("providers", new Guid("87E8C244-4329-48E1-9905-561C38CFBB0C"), PROVIDERS_SECTION_ENDPOINT);
|
||||
public static readonly string PROVIDERS_SECTION_PATH = $"{PATH}/{PROVIDERS_SECTION_ENDPOINT}";
|
||||
public const string PROVIDERS_SECTION_IDENTIFIER = "providers.id";
|
||||
|
||||
// Providers
|
||||
public const string ProvidersName = "Microsoft.WebServer.UrlRewrite.Providers.entries";
|
||||
public const string ProviderName = "Microsoft.WebServer.UrlRewrite.Provider.Entry";
|
||||
public static ResDef ProvidersResource = new ResDef("entries", new Guid("C055EFAF-4968-4E9F-8FF0-51793BA04A65"), PROVIDERS_ENDPOINT);
|
||||
public static readonly string PROVIDERS_PATH = $"{PROVIDERS_SECTION_PATH}/{PROVIDERS_ENDPOINT}";
|
||||
public const string PROVIDER_IDENTIFIER = "provider.id";
|
||||
public const string PROVIDER_IDENTIFIER = "entry.id";
|
||||
|
||||
// Rewrite Maps Section
|
||||
public const string RewriteMapsSectionName = "Microsoft.WebServer.UrlRewrite.RewriteMaps";
|
||||
public static ResDef RewriteMapsSectionResource = new ResDef("rewrite_maps", new Guid("F5F65122-BF1A-4A5B-9734-FCF35F2131B5"), REWRITE_MAPS_SECTION_ENDPOINT);
|
||||
public static readonly string REWRITE_MAPS_SECTION_PATH = $"{PATH}/{REWRITE_MAPS_SECTION_ENDPOINT}";
|
||||
public const string REWRITE_MAPS_SECTION_IDENTIFIER = "rewrite_maps.id";
|
||||
|
||||
// Rewrite Maps Section
|
||||
public const string RewriteMapsName = "Microsoft.WebServer.UrlRewrite.RewriteMaps.Maps";
|
||||
public const string RewriteMapName = "Microsoft.WebServer.UrlRewrite.RewriteMaps.Maps";
|
||||
public static ResDef RewriteMapsResource = new ResDef("maps", new Guid("EA768756-34B7-4664-AE88-E5E888860139"), REWRITE_MAPS_ENDPOINT);
|
||||
public const string RewriteMapsName = "Microsoft.WebServer.UrlRewrite.RewriteMaps.Entries";
|
||||
public const string RewriteMapName = "Microsoft.WebServer.UrlRewrite.RewriteMaps.Entry";
|
||||
public static ResDef RewriteMapsResource = new ResDef("entries", new Guid("EA768756-34B7-4664-AE88-E5E888860139"), REWRITE_MAPS_ENDPOINT);
|
||||
public static readonly string REWRITE_MAPS_PATH = $"{REWRITE_MAPS_SECTION_PATH}/{REWRITE_MAPS_ENDPOINT}";
|
||||
public const string REWRITE_MAPS_IDENTIFIER = "map.id";
|
||||
public const string REWRITE_MAPS_IDENTIFIER = "entry.id";
|
||||
|
||||
// Global Rules Section
|
||||
public const string GlobalRulesSectionName = "Microsoft.WebServer.UrlRewrite.GlobalRules";
|
||||
public static ResDef GlobalRulesSectionResource = new ResDef("global_rules", new Guid("59F0C4C2-B7E9-456C-92DE-CFDB4D313991"), GLOBAL_RULES_SECTION_ENDPOINT);
|
||||
public static readonly string GLOBAL_RULES_SECTION_PATH = $"{PATH}/{GLOBAL_RULES_SECTION_ENDPOINT}";
|
||||
public const string GLOBAL_RULES_SECTION_IDENTIFIER = "global_rules.id";
|
||||
|
||||
// Global Rules
|
||||
public const string GlobalRulesName = "Microsoft.WebServer.UrlRewrite.GlobalRules.Rules";
|
||||
|
@ -77,9 +74,8 @@ namespace Microsoft.IIS.Administration.WebServer.UrlRewrite
|
|||
|
||||
// Inbound Rules Section
|
||||
public const string InboundRulesSectionName = "Microsoft.WebServer.UrlRewrite.InboundRules";
|
||||
public static ResDef InboundRulesSectionResource = new ResDef("inbound_rules", new Guid("DA8765E5-42BA-4282-9D06-016191EAE4A5"), INBOUND_RULES_SECTION_ENDPOINT);
|
||||
public static ResDef InboundRulesSectionResource = new ResDef("inbound", new Guid("DA8765E5-42BA-4282-9D06-016191EAE4A5"), INBOUND_RULES_SECTION_ENDPOINT);
|
||||
public static readonly string INBOUND_RULES_SECTION_PATH = $"{PATH}/{INBOUND_RULES_SECTION_ENDPOINT}";
|
||||
public const string INBOUND_RULES_SECTION_IDENTIFIER = "inbound_rules.id";
|
||||
|
||||
// Inbound Rules
|
||||
public const string InboundRulesName = "Microsoft.WebServer.UrlRewrite.InboundRules.Rules";
|
||||
|
@ -90,9 +86,8 @@ namespace Microsoft.IIS.Administration.WebServer.UrlRewrite
|
|||
|
||||
// Outbound Rules Section
|
||||
public const string OutboundRulesSectionName = "Microsoft.WebServer.UrlRewrite.OutboundRoules";
|
||||
public static ResDef OutboundRulesSectionResource = new ResDef("outbound_rules", new Guid("3b6491d8-81db-493b-8597-190273682f73"), OUTBOUND_RULES_SECTION_ENDPOINT);
|
||||
public static ResDef OutboundRulesSectionResource = new ResDef("outbound", new Guid("3b6491d8-81db-493b-8597-190273682f73"), OUTBOUND_RULES_SECTION_ENDPOINT);
|
||||
public static readonly string OUTBOUND_RULES_SECTION_PATH = $"{PATH}/{OUTBOUND_RULES_SECTION_ENDPOINT}";
|
||||
public const string OUTBOUND_RULES_SECTION_IDENTIFIER = "outbound_rules.id";
|
||||
|
||||
// Outbound Rules
|
||||
public const string OutboundRulesName = "Microsoft.WebServer.UrlRewrite.OutboundRules.Rules";
|
||||
|
|
|
@ -29,25 +29,6 @@ namespace Microsoft.IIS.Administration.WebServer.UrlRewrite
|
|||
return $"/{Defines.GLOBAL_RULES_PATH}/{id}";
|
||||
}
|
||||
|
||||
public static RewriteId GetSectionIdFromBody(dynamic model)
|
||||
{
|
||||
if (model.global_rules == null) {
|
||||
throw new ApiArgumentException("global_rules");
|
||||
}
|
||||
|
||||
if (!(model.global_rules is JObject)) {
|
||||
throw new ApiArgumentException("global_rules", ApiArgumentException.EXPECTED_OBJECT);
|
||||
}
|
||||
|
||||
string rewriteId = DynamicHelper.Value(model.global_rules.id);
|
||||
|
||||
if (rewriteId == null) {
|
||||
throw new ApiArgumentException("global_rules.id");
|
||||
}
|
||||
|
||||
return new RewriteId(rewriteId);
|
||||
}
|
||||
|
||||
public static InboundRulesSection GetSection(Site site, string path, string configPath = null)
|
||||
{
|
||||
return (InboundRulesSection)ManagementUnit.GetConfigSection(site?.Id,
|
||||
|
@ -227,9 +208,9 @@ namespace Microsoft.IIS.Administration.WebServer.UrlRewrite
|
|||
}
|
||||
|
||||
//
|
||||
// global_rules
|
||||
if (fields.Exists("global_rules")) {
|
||||
obj.global_rules = SectionToJsonModelRef(site, path);
|
||||
// url_rewrite
|
||||
if (fields.Exists("url_rewrite")) {
|
||||
obj.url_rewrite = RewriteHelper.ToJsonModelRef(site, path, fields.Filter("url_rewrite"));
|
||||
}
|
||||
|
||||
return Core.Environment.Hal.Apply(Defines.GlobalRulesResource.Guid, obj);
|
||||
|
|
|
@ -192,9 +192,9 @@ namespace Microsoft.IIS.Administration.WebServer.UrlRewrite
|
|||
}
|
||||
|
||||
//
|
||||
// inbound_rules
|
||||
if (fields.Exists("inbound_rules")) {
|
||||
obj.inbound_rules = SectionToJsonModelRef(site, path);
|
||||
// url_rewrite
|
||||
if (fields.Exists("url_rewrite")) {
|
||||
obj.url_rewrite = RewriteHelper.ToJsonModelRef(site, path, fields.Filter("url_rewrite"));
|
||||
}
|
||||
|
||||
return Core.Environment.Hal.Apply(Defines.InboundRulesResource.Guid, obj);
|
||||
|
@ -304,25 +304,6 @@ namespace Microsoft.IIS.Administration.WebServer.UrlRewrite
|
|||
}
|
||||
}
|
||||
|
||||
public static RewriteId GetSectionIdFromBody(dynamic model)
|
||||
{
|
||||
if (model.inbound_rules == null) {
|
||||
throw new ApiArgumentException("inbound_rules");
|
||||
}
|
||||
|
||||
if (!(model.inbound_rules is JObject)) {
|
||||
throw new ApiArgumentException("inbound_rules", ApiArgumentException.EXPECTED_OBJECT);
|
||||
}
|
||||
|
||||
string rewriteId = DynamicHelper.Value(model.inbound_rules.id);
|
||||
|
||||
if (rewriteId == null) {
|
||||
throw new ApiArgumentException("inbound_rules.id");
|
||||
}
|
||||
|
||||
return new RewriteId(rewriteId);
|
||||
}
|
||||
|
||||
public static InboundRulesSection GetSection(Site site, string path, string configPath = null)
|
||||
{
|
||||
return (InboundRulesSection)ManagementUnit.GetConfigSection(site?.Id,
|
||||
|
|
|
@ -162,10 +162,9 @@ namespace Microsoft.IIS.Administration.WebServer.UrlRewrite
|
|||
}
|
||||
|
||||
//
|
||||
// outbound_rules
|
||||
if (fields.Exists("outbound_rules"))
|
||||
{
|
||||
obj.outbound_rules = SectionToJsonModelRef(site, path);
|
||||
// url_rewrite
|
||||
if (fields.Exists("url_rewrite")) {
|
||||
obj.url_rewrite = RewriteHelper.ToJsonModelRef(site, path, fields.Filter("url_rewrite"));
|
||||
}
|
||||
|
||||
return Core.Environment.Hal.Apply(Defines.CustomTagsResource.Guid, obj, full);
|
||||
|
@ -229,9 +228,9 @@ namespace Microsoft.IIS.Administration.WebServer.UrlRewrite
|
|||
}
|
||||
|
||||
//
|
||||
// outbound_rules
|
||||
if (fields.Exists("outbound_rules")) {
|
||||
obj.outbound_rules = SectionToJsonModelRef(site, path);
|
||||
// url_rewrite
|
||||
if (fields.Exists("url_rewrite")) {
|
||||
obj.url_rewrite = RewriteHelper.ToJsonModelRef(site, path, fields.Filter("url_rewrite"));
|
||||
}
|
||||
|
||||
return Core.Environment.Hal.Apply(Defines.PreConditionsResource.Guid, obj, full);
|
||||
|
@ -283,7 +282,7 @@ namespace Microsoft.IIS.Administration.WebServer.UrlRewrite
|
|||
|
||||
// match_type
|
||||
if (fields.Exists("match_type")) {
|
||||
obj.match_type = Enum.GetName(typeof(OutboundRuleMatchType), matchType).ToLower();
|
||||
obj.match_type = OutboundMatchTypeHelper.ToJsonModel(matchType);
|
||||
}
|
||||
|
||||
// server_variable
|
||||
|
@ -291,16 +290,17 @@ namespace Microsoft.IIS.Administration.WebServer.UrlRewrite
|
|||
obj.server_variable = string.IsNullOrEmpty(rule.Match.ServerVariable) ? null : rule.Match.ServerVariable;
|
||||
}
|
||||
|
||||
// html_tags
|
||||
if (fields.Exists("html_tags") && matchType == OutboundRuleMatchType.HtmlTags) {
|
||||
obj.html_tags = new ExpandoObject();
|
||||
obj.html_tags.standard = TagsToDict(rule.Match.FilterByTags);
|
||||
// tags
|
||||
if (fields.Exists("tags") && matchType == OutboundRuleMatchType.Tags) {
|
||||
//
|
||||
// dynamic ExpandoObject
|
||||
obj.tags = CreateTagsModel(rule.Match.FilterByTags);
|
||||
|
||||
TagsElement customTags = rule.Match.FilterByTags.HasFlag(FilterByTags.CustomTags) ?
|
||||
section.Tags.FirstOrDefault(t => t.Name.Equals(rule.Match.CustomTags, StringComparison.OrdinalIgnoreCase)) :
|
||||
null;
|
||||
|
||||
obj.html_tags.custom = customTags == null ? null : TagsToJsonModelRef(customTags, site, path, fields.Filter("html_tags.custom"));
|
||||
obj.tags.custom = customTags == null ? null : TagsToJsonModelRef(customTags, site, path, fields.Filter("tags.custom"));
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -358,9 +358,9 @@ namespace Microsoft.IIS.Administration.WebServer.UrlRewrite
|
|||
}
|
||||
|
||||
//
|
||||
// outbound_rules
|
||||
if (fields.Exists("outbound_rules")) {
|
||||
obj.outbound_rules = SectionToJsonModelRef(site, path);
|
||||
// url_rewrite
|
||||
if (fields.Exists("url_rewrite")) {
|
||||
obj.url_rewrite = RewriteHelper.ToJsonModelRef(site, path, fields.Filter("url_rewrite"));
|
||||
}
|
||||
|
||||
return Core.Environment.Hal.Apply(Defines.OutboundRulesResource.Guid, obj, full);
|
||||
|
@ -414,7 +414,7 @@ namespace Microsoft.IIS.Administration.WebServer.UrlRewrite
|
|||
throw new ApiArgumentException("pattern_syntax");
|
||||
}
|
||||
|
||||
if (DynamicHelper.To<OutboundRuleMatchType>(model.match_type) == null) {
|
||||
if (string.IsNullOrEmpty(DynamicHelper.Value(model.match_type))) {
|
||||
throw new ApiArgumentException("match_type");
|
||||
}
|
||||
|
||||
|
@ -620,46 +620,28 @@ namespace Microsoft.IIS.Administration.WebServer.UrlRewrite
|
|||
}
|
||||
}
|
||||
|
||||
public static RewriteId GetSectionIdFromBody(dynamic model)
|
||||
private static dynamic CreateTagsModel(FilterByTags tags)
|
||||
{
|
||||
if (model.outbound_rules == null) {
|
||||
throw new ApiArgumentException("outbound_rules");
|
||||
}
|
||||
dynamic tagObj = new ExpandoObject();
|
||||
|
||||
if (!(model.outbound_rules is JObject)) {
|
||||
throw new ApiArgumentException("outbound_rules", ApiArgumentException.EXPECTED_OBJECT);
|
||||
}
|
||||
tagObj.a = tags.HasFlag(FilterByTags.A);
|
||||
tagObj.area = tags.HasFlag(FilterByTags.Area);
|
||||
tagObj.@base = tags.HasFlag(FilterByTags.Base);
|
||||
tagObj.form = tags.HasFlag(FilterByTags.Form);
|
||||
tagObj.frame = tags.HasFlag(FilterByTags.Frame);
|
||||
tagObj.head = tags.HasFlag(FilterByTags.Head);
|
||||
tagObj.iframe = tags.HasFlag(FilterByTags.IFrame);
|
||||
tagObj.img = tags.HasFlag(FilterByTags.Img);
|
||||
tagObj.input = tags.HasFlag(FilterByTags.Input);
|
||||
tagObj.link = tags.HasFlag(FilterByTags.Link);
|
||||
tagObj.script = tags.HasFlag(FilterByTags.Script);
|
||||
|
||||
string rewriteId = DynamicHelper.Value(model.outbound_rules.id);
|
||||
|
||||
if (rewriteId == null) {
|
||||
throw new ApiArgumentException("outbound_rules.id");
|
||||
}
|
||||
|
||||
return new RewriteId(rewriteId);
|
||||
}
|
||||
|
||||
private static Dictionary<string, bool> TagsToDict(FilterByTags tags)
|
||||
{
|
||||
Dictionary<string, bool> dict = new Dictionary<string, bool>();
|
||||
dict.Add("a", tags.HasFlag(FilterByTags.A));
|
||||
dict.Add("area", tags.HasFlag(FilterByTags.Area));
|
||||
dict.Add("base", tags.HasFlag(FilterByTags.Base));
|
||||
dict.Add("form", tags.HasFlag(FilterByTags.Form));
|
||||
dict.Add("frame", tags.HasFlag(FilterByTags.Frame));
|
||||
dict.Add("head", tags.HasFlag(FilterByTags.Head));
|
||||
dict.Add("iframe", tags.HasFlag(FilterByTags.IFrame));
|
||||
dict.Add("img", tags.HasFlag(FilterByTags.Img));
|
||||
dict.Add("input", tags.HasFlag(FilterByTags.Input));
|
||||
dict.Add("link", tags.HasFlag(FilterByTags.Link));
|
||||
dict.Add("script", tags.HasFlag(FilterByTags.Script));
|
||||
|
||||
return dict;
|
||||
return tagObj;
|
||||
}
|
||||
|
||||
private static OutboundRuleMatchType GetMatchType(OutboundRule rule)
|
||||
{
|
||||
return string.IsNullOrEmpty(rule.Match.ServerVariable) ? OutboundRuleMatchType.HtmlTags : OutboundRuleMatchType.ServerVariable;
|
||||
return string.IsNullOrEmpty(rule.Match.ServerVariable) ? OutboundRuleMatchType.Tags : OutboundRuleMatchType.ServerVariable;
|
||||
}
|
||||
|
||||
private static void SetRule(dynamic model, OutboundRule rule, OutboundRulesSection section)
|
||||
|
@ -707,66 +689,58 @@ namespace Microsoft.IIS.Administration.WebServer.UrlRewrite
|
|||
|
||||
//
|
||||
// Html Tags
|
||||
dynamic htmlTags = null;
|
||||
dynamic standardTags = null;
|
||||
dynamic tags = null;
|
||||
dynamic customTags = null;
|
||||
|
||||
if (model.html_tags != null) {
|
||||
if (!(model.html_tags is JObject)) {
|
||||
throw new ApiArgumentException("html_tags", ApiArgumentException.EXPECTED_OBJECT);
|
||||
if (model.tags != null) {
|
||||
tags = model.tags;
|
||||
|
||||
if (!(tags is JObject)) {
|
||||
throw new ApiArgumentException("tags", ApiArgumentException.EXPECTED_OBJECT);
|
||||
}
|
||||
htmlTags = model.html_tags;
|
||||
|
||||
customTags = tags.custom;
|
||||
|
||||
// Clear custom tags
|
||||
rule.Match.CustomTags = null;
|
||||
rule.Match.FilterByTags &= ~FilterByTags.CustomTags;
|
||||
}
|
||||
|
||||
if (htmlTags != null) {
|
||||
standardTags = htmlTags.standard;
|
||||
|
||||
if (standardTags != null && !(standardTags is JObject)) {
|
||||
throw new ApiArgumentException("html_tags.standard", ApiArgumentException.EXPECTED_OBJECT);
|
||||
}
|
||||
|
||||
customTags = htmlTags.custom;
|
||||
|
||||
if (customTags != null && !(customTags is JObject)) {
|
||||
throw new ApiArgumentException("html_tags.custom", ApiArgumentException.EXPECTED_OBJECT);
|
||||
}
|
||||
}
|
||||
|
||||
// Set standard tags
|
||||
if (standardTags != null) {
|
||||
if (tags != null) {
|
||||
FilterByTags ruleTags = rule.Match.FilterByTags;
|
||||
|
||||
DynamicHelper.If<bool>((object)standardTags.a, v => SetTagFlag(ref ruleTags, FilterByTags.A, v));
|
||||
DynamicHelper.If<bool>((object)standardTags.area, v => SetTagFlag(ref ruleTags, FilterByTags.Area, v));
|
||||
DynamicHelper.If<bool>((object)standardTags.@base, v => SetTagFlag(ref ruleTags, FilterByTags.Base, v));
|
||||
DynamicHelper.If<bool>((object)standardTags.form, v => SetTagFlag(ref ruleTags, FilterByTags.Form, v));
|
||||
DynamicHelper.If<bool>((object)standardTags.frame, v => SetTagFlag(ref ruleTags, FilterByTags.Frame, v));
|
||||
DynamicHelper.If<bool>((object)standardTags.head, v => SetTagFlag(ref ruleTags, FilterByTags.Head, v));
|
||||
DynamicHelper.If<bool>((object)standardTags.iframe, v => SetTagFlag(ref ruleTags, FilterByTags.IFrame, v));
|
||||
DynamicHelper.If<bool>((object)standardTags.img, v => SetTagFlag(ref ruleTags, FilterByTags.Img, v));
|
||||
DynamicHelper.If<bool>((object)standardTags.input, v => SetTagFlag(ref ruleTags, FilterByTags.Input, v));
|
||||
DynamicHelper.If<bool>((object)standardTags.link, v => SetTagFlag(ref ruleTags, FilterByTags.Link, v));
|
||||
DynamicHelper.If<bool>((object)standardTags.script, v => SetTagFlag(ref ruleTags, FilterByTags.Script, v));
|
||||
DynamicHelper.If<bool>((object)tags.a, v => SetTagFlag(ref ruleTags, FilterByTags.A, v));
|
||||
DynamicHelper.If<bool>((object)tags.area, v => SetTagFlag(ref ruleTags, FilterByTags.Area, v));
|
||||
DynamicHelper.If<bool>((object)tags.@base, v => SetTagFlag(ref ruleTags, FilterByTags.Base, v));
|
||||
DynamicHelper.If<bool>((object)tags.form, v => SetTagFlag(ref ruleTags, FilterByTags.Form, v));
|
||||
DynamicHelper.If<bool>((object)tags.frame, v => SetTagFlag(ref ruleTags, FilterByTags.Frame, v));
|
||||
DynamicHelper.If<bool>((object)tags.head, v => SetTagFlag(ref ruleTags, FilterByTags.Head, v));
|
||||
DynamicHelper.If<bool>((object)tags.iframe, v => SetTagFlag(ref ruleTags, FilterByTags.IFrame, v));
|
||||
DynamicHelper.If<bool>((object)tags.img, v => SetTagFlag(ref ruleTags, FilterByTags.Img, v));
|
||||
DynamicHelper.If<bool>((object)tags.input, v => SetTagFlag(ref ruleTags, FilterByTags.Input, v));
|
||||
DynamicHelper.If<bool>((object)tags.link, v => SetTagFlag(ref ruleTags, FilterByTags.Link, v));
|
||||
DynamicHelper.If<bool>((object)tags.script, v => SetTagFlag(ref ruleTags, FilterByTags.Script, v));
|
||||
|
||||
rule.Match.FilterByTags = ruleTags;
|
||||
}
|
||||
|
||||
// Set custom tags
|
||||
if (customTags != null) {
|
||||
if (!(customTags is JObject)) {
|
||||
throw new ApiArgumentException("tags.custom", ApiArgumentException.EXPECTED_OBJECT);
|
||||
}
|
||||
|
||||
string ctId = DynamicHelper.Value(customTags.id);
|
||||
|
||||
if (string.IsNullOrEmpty(ctId)) {
|
||||
throw new ArgumentException("html_tags.custom.id", "required");
|
||||
throw new ArgumentException("tags.custom.id", "required");
|
||||
}
|
||||
|
||||
TagsElement targetCustomTags = section.Tags.FirstOrDefault(t => t.Name.Equals(new CustomTagsId(ctId).Name, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
if (targetCustomTags == null) {
|
||||
throw new NotFoundException("html_tags.custom");
|
||||
throw new NotFoundException("tags.custom");
|
||||
}
|
||||
|
||||
rule.Match.FilterByTags |= FilterByTags.CustomTags;
|
||||
|
@ -835,9 +809,10 @@ namespace Microsoft.IIS.Administration.WebServer.UrlRewrite
|
|||
|
||||
//
|
||||
// Set match type
|
||||
OutboundRuleMatchType matchType = DynamicHelper.To<OutboundRuleMatchType>(model.match_type) ?? GetMatchType(rule);
|
||||
string type = DynamicHelper.Value(model.match_type);
|
||||
OutboundRuleMatchType matchType = string.IsNullOrEmpty(type) ? GetMatchType(rule) : OutboundMatchTypeHelper.FromJsonModel(type);
|
||||
|
||||
if (matchType == OutboundRuleMatchType.HtmlTags) {
|
||||
if (matchType == OutboundRuleMatchType.Tags) {
|
||||
rule.Match.ServerVariable = null;
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -147,9 +147,9 @@ namespace Microsoft.IIS.Administration.WebServer.UrlRewrite
|
|||
}
|
||||
|
||||
//
|
||||
// providers
|
||||
if (fields.Exists("providers")) {
|
||||
obj.providers = SectionToJsonModelRef(site, path);
|
||||
// url_rewrite
|
||||
if (fields.Exists("url_rewrite")) {
|
||||
obj.url_rewrite = RewriteHelper.ToJsonModelRef(site, path, fields.Filter("url_rewrite"));
|
||||
}
|
||||
|
||||
return Core.Environment.Hal.Apply(Defines.ProvidersResource.Guid, obj);
|
||||
|
@ -255,25 +255,6 @@ namespace Microsoft.IIS.Administration.WebServer.UrlRewrite
|
|||
}
|
||||
}
|
||||
|
||||
public static RewriteId GetSectionIdFromBody(dynamic model)
|
||||
{
|
||||
if (model.providers == null) {
|
||||
throw new ApiArgumentException("providers");
|
||||
}
|
||||
|
||||
if (!(model.providers is JObject)) {
|
||||
throw new ApiArgumentException("providers", ApiArgumentException.EXPECTED_OBJECT);
|
||||
}
|
||||
|
||||
string rewriteId = DynamicHelper.Value(model.providers.id);
|
||||
|
||||
if (rewriteId == null) {
|
||||
throw new ApiArgumentException("providers.id");
|
||||
}
|
||||
|
||||
return new RewriteId(rewriteId);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static void SetProvider(dynamic model, Provider provider, ProvidersSection section)
|
||||
|
|
|
@ -45,25 +45,6 @@ namespace Microsoft.IIS.Administration.WebServer.UrlRewrite
|
|||
Globals.RewriteMapSectionName);
|
||||
}
|
||||
|
||||
public static RewriteId GetSectionIdFromBody(dynamic model)
|
||||
{
|
||||
if (model.rewrite_maps == null) {
|
||||
throw new ApiArgumentException("rewrite_maps");
|
||||
}
|
||||
|
||||
if (!(model.rewrite_maps is JObject)) {
|
||||
throw new ApiArgumentException("rewrite_maps", ApiArgumentException.EXPECTED_OBJECT);
|
||||
}
|
||||
|
||||
string rewriteId = DynamicHelper.Value(model.rewrite_maps.id);
|
||||
|
||||
if (rewriteId == null) {
|
||||
throw new ApiArgumentException("rewrite_maps.id");
|
||||
}
|
||||
|
||||
return new RewriteId(rewriteId);
|
||||
}
|
||||
|
||||
public static object SectionToJsonModelRef(Site site, string path, Fields fields = null)
|
||||
{
|
||||
if (fields == null || !fields.HasFields) {
|
||||
|
@ -162,18 +143,18 @@ namespace Microsoft.IIS.Administration.WebServer.UrlRewrite
|
|||
}
|
||||
|
||||
//
|
||||
// entries
|
||||
if (fields.Exists("entries")) {
|
||||
obj.entries = map.KeyValuePairCollection.Select(kvp => new {
|
||||
key = kvp.Key,
|
||||
// mappings
|
||||
if (fields.Exists("mappings")) {
|
||||
obj.mappings = map.KeyValuePairCollection.Select(kvp => new {
|
||||
name = kvp.Key,
|
||||
value = kvp.Value
|
||||
});
|
||||
}
|
||||
|
||||
//
|
||||
// rewrite_maps
|
||||
if (fields.Exists("rewrite_maps")) {
|
||||
obj.rewrite_maps = SectionToJsonModelRef(site, path);
|
||||
// url_rewrite
|
||||
if (fields.Exists("url_rewrite")) {
|
||||
obj.url_rewrite = RewriteHelper.ToJsonModelRef(site, path, fields.Filter("url_rewrite"));
|
||||
}
|
||||
|
||||
return Core.Environment.Hal.Apply(Defines.RewriteMapsResource.Guid, obj, full);
|
||||
|
@ -293,35 +274,35 @@ namespace Microsoft.IIS.Administration.WebServer.UrlRewrite
|
|||
DynamicHelper.If<bool>((object)model.ignore_case, v => map.IgnoreCase = v);
|
||||
|
||||
//
|
||||
// entries
|
||||
if (model.entries != null) {
|
||||
// mappings
|
||||
if (model.mappings != null) {
|
||||
|
||||
IEnumerable<dynamic> entries = model.entries as IEnumerable<dynamic>;
|
||||
IEnumerable<dynamic> mappings = model.mappings as IEnumerable<dynamic>;
|
||||
|
||||
if (entries == null) {
|
||||
throw new ApiArgumentException("entries", ApiArgumentException.EXPECTED_ARRAY);
|
||||
if (mappings == null) {
|
||||
throw new ApiArgumentException("mappings", ApiArgumentException.EXPECTED_ARRAY);
|
||||
}
|
||||
|
||||
map.KeyValuePairCollection.Clear();
|
||||
|
||||
foreach (dynamic entry in entries) {
|
||||
if (!(entry is JObject)) {
|
||||
throw new ApiArgumentException("entries.item");
|
||||
foreach (dynamic item in mappings) {
|
||||
if (!(item is JObject)) {
|
||||
throw new ApiArgumentException("mappings.item");
|
||||
}
|
||||
|
||||
string key = DynamicHelper.Value(entry.key);
|
||||
string value = DynamicHelper.Value(entry.value);
|
||||
string itemName = DynamicHelper.Value(item.name);
|
||||
string value = DynamicHelper.Value(item.value);
|
||||
|
||||
if (string.IsNullOrEmpty(key)) {
|
||||
throw new ApiArgumentException("entries.item.name", "Required");
|
||||
if (string.IsNullOrEmpty(itemName)) {
|
||||
throw new ApiArgumentException("mappings.item.name", "Required");
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(value)) {
|
||||
throw new ApiArgumentException("entries.item.value", "Required");
|
||||
throw new ApiArgumentException("mappings.item.value", "Required");
|
||||
}
|
||||
|
||||
KeyValueElement kvp = map.KeyValuePairCollection.CreateElement();
|
||||
kvp.Key = key;
|
||||
kvp.Key = itemName;
|
||||
kvp.Value = value;
|
||||
|
||||
map.KeyValuePairCollection.Add(kvp);
|
||||
|
|
|
@ -85,7 +85,7 @@ namespace Microsoft.IIS.Administration.WebServer.UrlRewrite
|
|||
hal.ProvideLink(Defines.Resource.Guid, Defines.RewriteMapsSectionResource.Name, rewrite => new { href = RewriteMapsHelper.GetSectionLocation(rewrite.id) });
|
||||
|
||||
// Section -> Maps
|
||||
hal.ProvideLink(Defines.RewriteMapsSectionResource.Guid, Defines.RewriteMapsResource.Name, section => new { href = $"/{Defines.REWRITE_MAPS_PATH}?{Defines.REWRITE_MAPS_SECTION_IDENTIFIER}={section.id}" });
|
||||
hal.ProvideLink(Defines.RewriteMapsSectionResource.Guid, Defines.RewriteMapsResource.Name, section => new { href = $"/{Defines.REWRITE_MAPS_PATH}?{Defines.IDENTIFIER}={section.id}" });
|
||||
}
|
||||
|
||||
private void ConfigureProviders()
|
||||
|
@ -103,7 +103,7 @@ namespace Microsoft.IIS.Administration.WebServer.UrlRewrite
|
|||
hal.ProvideLink(Defines.Resource.Guid, Defines.ProvidersSectionResource.Name, rewrite => new { href = ProvidersHelper.GetSectionLocation(rewrite.id) });
|
||||
|
||||
// Section -> providers
|
||||
hal.ProvideLink(Defines.ProvidersSectionResource.Guid, Defines.ProvidersResource.Name, providersSection => new { href = $"/{Defines.PROVIDERS_PATH}?{Defines.PROVIDERS_SECTION_IDENTIFIER}={providersSection.id}" });
|
||||
hal.ProvideLink(Defines.ProvidersSectionResource.Guid, Defines.ProvidersResource.Name, providersSection => new { href = $"/{Defines.PROVIDERS_PATH}?{Defines.IDENTIFIER}={providersSection.id}" });
|
||||
}
|
||||
|
||||
private void ConfigureGlobalRules()
|
||||
|
@ -129,7 +129,7 @@ namespace Microsoft.IIS.Administration.WebServer.UrlRewrite
|
|||
rewrite => string.IsNullOrEmpty(rewrite.scope));
|
||||
|
||||
// Section -> Rules
|
||||
hal.ProvideLink(Defines.GlobalRulesSectionResource.Guid, Defines.GlobalRulesResource.Name, globalRulesSection => new { href = $"/{Defines.GLOBAL_RULES_PATH}?{Defines.GLOBAL_RULES_SECTION_IDENTIFIER}={globalRulesSection.id}" });
|
||||
hal.ProvideLink(Defines.GlobalRulesSectionResource.Guid, Defines.GlobalRulesResource.Name, globalRulesSection => new { href = $"/{Defines.GLOBAL_RULES_PATH}?{Defines.IDENTIFIER}={globalRulesSection.id}" });
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -148,7 +148,7 @@ namespace Microsoft.IIS.Administration.WebServer.UrlRewrite
|
|||
hal.ProvideLink(Defines.Resource.Guid, Defines.InboundRulesSectionResource.Name, rewrite => new { href = InboundRulesHelper.GetSectionLocation(rewrite.id) });
|
||||
|
||||
// Section -> Rules
|
||||
hal.ProvideLink(Defines.InboundRulesSectionResource.Guid, Defines.InboundRulesResource.Name, inboundRulesSection => new { href = $"/{Defines.INBOUND_RULES_PATH}?{Defines.INBOUND_RULES_SECTION_IDENTIFIER}={inboundRulesSection.id}" });
|
||||
hal.ProvideLink(Defines.InboundRulesSectionResource.Guid, Defines.InboundRulesResource.Name, inboundRulesSection => new { href = $"/{Defines.INBOUND_RULES_PATH}?{Defines.IDENTIFIER}={inboundRulesSection.id}" });
|
||||
}
|
||||
|
||||
private void ConfigureOutboundRules()
|
||||
|
@ -171,13 +171,13 @@ namespace Microsoft.IIS.Administration.WebServer.UrlRewrite
|
|||
hal.ProvideLink(Defines.Resource.Guid, Defines.OutboundRulesSectionResource.Name, rewrite => new { href = OutboundRulesHelper.GetSectionLocation(rewrite.id) });
|
||||
|
||||
// Section -> Rules
|
||||
hal.ProvideLink(Defines.OutboundRulesSectionResource.Guid, Defines.OutboundRulesResource.Name, outboundRulesSection => new { href = $"/{Defines.OUTBOUND_RULES_PATH}?{Defines.OUTBOUND_RULES_SECTION_IDENTIFIER}={outboundRulesSection.id}" });
|
||||
hal.ProvideLink(Defines.OutboundRulesSectionResource.Guid, Defines.OutboundRulesResource.Name, outboundRulesSection => new { href = $"/{Defines.OUTBOUND_RULES_PATH}?{Defines.IDENTIFIER}={outboundRulesSection.id}" });
|
||||
|
||||
// Section -> PreConditions
|
||||
hal.ProvideLink(Defines.OutboundRulesSectionResource.Guid, Defines.PreConditionsResource.Name, outboundRulesSection => new { href = $"/{Defines.PRECONDITIONS_PATH}?{Defines.OUTBOUND_RULES_SECTION_IDENTIFIER}={outboundRulesSection.id}" });
|
||||
hal.ProvideLink(Defines.OutboundRulesSectionResource.Guid, Defines.PreConditionsResource.Name, outboundRulesSection => new { href = $"/{Defines.PRECONDITIONS_PATH}?{Defines.IDENTIFIER}={outboundRulesSection.id}" });
|
||||
|
||||
// Section -> CustomTags
|
||||
hal.ProvideLink(Defines.OutboundRulesSectionResource.Guid, Defines.CustomTagsResource.Name, outboundRulesSection => new { href = $"/{Defines.CUSTOM_TAGS_PATH}?{Defines.OUTBOUND_RULES_SECTION_IDENTIFIER}={outboundRulesSection.id}" });
|
||||
hal.ProvideLink(Defines.OutboundRulesSectionResource.Guid, Defines.CustomTagsResource.Name, outboundRulesSection => new { href = $"/{Defines.CUSTOM_TAGS_PATH}?{Defines.IDENTIFIER}={outboundRulesSection.id}" });
|
||||
}
|
||||
|
||||
private RewriteId GetRewriteId(Site s, string path)
|
||||
|
|
|
@ -36,7 +36,7 @@ namespace Microsoft.IIS.Administration.Tests
|
|||
const string updatedTestRuleName = testRuleName + "2";
|
||||
const string testServerVariable1 = "abc", testServerVariable2 = "def";
|
||||
|
||||
JObject inboundRulesSection = Utils.FollowLink(client, siteFeature, "inbound_rules");
|
||||
JObject inboundRulesSection = Utils.FollowLink(client, siteFeature, "inbound");
|
||||
string inboundRulesLink = Utils.GetLink(inboundRulesSection, "rules");
|
||||
|
||||
IEnumerable<JObject> rules = client.Get(inboundRulesLink)["rules"].ToObject<IEnumerable<JObject>>();
|
||||
|
@ -82,7 +82,7 @@ namespace Microsoft.IIS.Administration.Tests
|
|||
match_type = "isfile"
|
||||
}
|
||||
},
|
||||
inbound_rules = inboundRulesSection
|
||||
url_rewrite = siteFeature
|
||||
});
|
||||
|
||||
JObject result = client.Post(inboundRulesLink, rule);
|
||||
|
@ -188,7 +188,7 @@ namespace Microsoft.IIS.Administration.Tests
|
|||
match_type = "pattern"
|
||||
}
|
||||
},
|
||||
global_rules = globalRulesSection
|
||||
url_rewrite = webserverFeature
|
||||
});
|
||||
|
||||
JObject result = client.Post(globalRulesLink, rule);
|
||||
|
@ -285,9 +285,9 @@ namespace Microsoft.IIS.Administration.Tests
|
|||
Assert.NotNull(webserverFeature);
|
||||
|
||||
JObject rewriteMaps = Utils.FollowLink(client, webserverFeature, "rewrite_maps");
|
||||
string mapsLink = Utils.GetLink(rewriteMaps, "maps");
|
||||
string mapsLink = Utils.GetLink(rewriteMaps, "entries");
|
||||
|
||||
foreach (var m in client.Get(mapsLink)["maps"].ToObject<IEnumerable<JObject>>()) {
|
||||
foreach (var m in client.Get(mapsLink)["entries"].ToObject<IEnumerable<JObject>>()) {
|
||||
if (m.Value<string>("name").Equals(testMapName, StringComparison.OrdinalIgnoreCase)
|
||||
|| m.Value<string>("name").Equals(updatedTestMapName, StringComparison.OrdinalIgnoreCase)) {
|
||||
Assert.True(client.Delete(Utils.Self(m)));
|
||||
|
@ -298,17 +298,17 @@ namespace Microsoft.IIS.Administration.Tests
|
|||
name = testMapName,
|
||||
default_value = "def1",
|
||||
ignore_case = false,
|
||||
entries = new object[] {
|
||||
mappings = new object[] {
|
||||
new {
|
||||
key = "abc",
|
||||
name = "abc",
|
||||
value = "def"
|
||||
},
|
||||
new {
|
||||
key = "zyx",
|
||||
name = "zyx",
|
||||
value = "wvu"
|
||||
}
|
||||
},
|
||||
rewrite_maps = rewriteMaps
|
||||
url_rewrite = webserverFeature
|
||||
});
|
||||
|
||||
JObject result = client.Post(mapsLink, map);
|
||||
|
@ -321,21 +321,20 @@ namespace Microsoft.IIS.Administration.Tests
|
|||
name = updatedTestMapName,
|
||||
default_value = "def2",
|
||||
ignore_case = true,
|
||||
entries = new object[] {
|
||||
mappings = new object[] {
|
||||
new {
|
||||
key = "igloo",
|
||||
name = "igloo",
|
||||
value = "anonymous"
|
||||
},
|
||||
new {
|
||||
key = "tea",
|
||||
name = "tea",
|
||||
value = "coffee"
|
||||
},
|
||||
new {
|
||||
key = "record",
|
||||
name = "record",
|
||||
value = "paper"
|
||||
}
|
||||
},
|
||||
rewrite_maps = rewriteMaps
|
||||
}
|
||||
});
|
||||
|
||||
result = client.Patch(Utils.Self(result), updateMap);
|
||||
|
@ -361,7 +360,7 @@ namespace Microsoft.IIS.Administration.Tests
|
|||
JObject webserverFeature = Utils.GetFeature(client, REWRITE_URL, "", null);
|
||||
Assert.NotNull(webserverFeature);
|
||||
|
||||
JObject outboundRules = Utils.FollowLink(client, webserverFeature, "outbound_rules");
|
||||
JObject outboundRules = Utils.FollowLink(client, webserverFeature, "outbound");
|
||||
string preConditionsLink = Utils.GetLink(outboundRules, "preconditions");
|
||||
|
||||
foreach (var p in client.Get(preConditionsLink)["preconditions"].ToObject<IEnumerable<JObject>>()) {
|
||||
|
@ -389,7 +388,7 @@ namespace Microsoft.IIS.Administration.Tests
|
|||
ignore_case = false
|
||||
}
|
||||
},
|
||||
outbound_rules = outboundRules
|
||||
url_rewrite = webserverFeature
|
||||
});
|
||||
|
||||
JObject result = client.Post(preConditionsLink, precondition);
|
||||
|
@ -415,7 +414,7 @@ namespace Microsoft.IIS.Administration.Tests
|
|||
negate = true,
|
||||
ignore_case = true
|
||||
}
|
||||
},
|
||||
}
|
||||
});
|
||||
|
||||
result = client.Patch(Utils.Self(result), updatePrecondition);
|
||||
|
@ -441,7 +440,7 @@ namespace Microsoft.IIS.Administration.Tests
|
|||
JObject webserverFeature = Utils.GetFeature(client, REWRITE_URL, "", null);
|
||||
Assert.NotNull(webserverFeature);
|
||||
|
||||
JObject outboundRules = Utils.FollowLink(client, webserverFeature, "outbound_rules");
|
||||
JObject outboundRules = Utils.FollowLink(client, webserverFeature, "outbound");
|
||||
string customTagsLink = Utils.GetLink(outboundRules, "custom_tags");
|
||||
|
||||
foreach (var p in client.Get(customTagsLink)["custom_tags"].ToObject<IEnumerable<JObject>>()) {
|
||||
|
@ -463,7 +462,7 @@ namespace Microsoft.IIS.Administration.Tests
|
|||
attribute = "anotherHtmlAttribute"
|
||||
}
|
||||
},
|
||||
outbound_rules = outboundRules
|
||||
url_rewrite = webserverFeature
|
||||
});
|
||||
|
||||
JObject result = client.Post(customTagsLink, customTags);
|
||||
|
@ -483,8 +482,7 @@ namespace Microsoft.IIS.Administration.Tests
|
|||
name = "TestTag",
|
||||
attribute = "TestAttribute"
|
||||
}
|
||||
},
|
||||
outbound_rules = outboundRules
|
||||
}
|
||||
});
|
||||
|
||||
result = client.Patch(Utils.Self(result), updateCustomTags);
|
||||
|
@ -510,7 +508,7 @@ namespace Microsoft.IIS.Administration.Tests
|
|||
JObject webserverFeature = Utils.GetFeature(client, REWRITE_URL, "", null);
|
||||
Assert.NotNull(webserverFeature);
|
||||
|
||||
JObject outboundRules = Utils.FollowLink(client, webserverFeature, "outbound_rules");
|
||||
JObject outboundRules = Utils.FollowLink(client, webserverFeature, "outbound");
|
||||
string customTagsLink = Utils.GetLink(outboundRules, "rules");
|
||||
|
||||
foreach (var p in client.Get(customTagsLink)["rules"].ToObject<IEnumerable<JObject>>()) {
|
||||
|
@ -525,21 +523,19 @@ namespace Microsoft.IIS.Administration.Tests
|
|||
|
||||
JObject outboundRule = JObject.FromObject(new {
|
||||
name = testName,
|
||||
match_type = "htmltags",
|
||||
html_tags = new {
|
||||
standard = new {
|
||||
a = true,
|
||||
area = true,
|
||||
@base = true,
|
||||
form = true,
|
||||
frame = true,
|
||||
head = true,
|
||||
iframe = true,
|
||||
img = true,
|
||||
input = true,
|
||||
link = true,
|
||||
script = true
|
||||
},
|
||||
match_type = "tags",
|
||||
tags = new {
|
||||
a = true,
|
||||
area = true,
|
||||
@base = true,
|
||||
form = true,
|
||||
frame = true,
|
||||
head = true,
|
||||
iframe = true,
|
||||
img = true,
|
||||
input = true,
|
||||
link = true,
|
||||
script = true,
|
||||
custom = customTags
|
||||
},
|
||||
pattern = "abc.aspx?a=b&c=d",
|
||||
|
@ -558,7 +554,7 @@ namespace Microsoft.IIS.Administration.Tests
|
|||
},
|
||||
},
|
||||
precondition = precondition,
|
||||
outbound_rules = outboundRules
|
||||
url_rewrite = webserverFeature
|
||||
});
|
||||
|
||||
JObject result = client.Post(customTagsLink, outboundRule);
|
||||
|
@ -571,7 +567,7 @@ namespace Microsoft.IIS.Administration.Tests
|
|||
|
||||
JObject updateOutboundRule = JObject.FromObject(new {
|
||||
name = updatedName,
|
||||
match_type = "servervariable",
|
||||
match_type = "server_variable",
|
||||
server_variable = "abcdefg",
|
||||
pattern = "abc.aspx",
|
||||
pattern_syntax = "wildcard",
|
||||
|
@ -588,8 +584,7 @@ namespace Microsoft.IIS.Administration.Tests
|
|||
match_type = "pattern"
|
||||
},
|
||||
},
|
||||
precondition = updatedPrecondition,
|
||||
outbound_rules = outboundRules
|
||||
precondition = updatedPrecondition
|
||||
});
|
||||
|
||||
result = client.Patch(Utils.Self(result), updateOutboundRule);
|
||||
|
@ -638,7 +633,7 @@ namespace Microsoft.IIS.Administration.Tests
|
|||
value = "wvu"
|
||||
}
|
||||
},
|
||||
providers = providers
|
||||
url_rewrite = webserverFeature
|
||||
});
|
||||
|
||||
JObject result = client.Post(providersLink, provider);
|
||||
|
@ -663,8 +658,7 @@ namespace Microsoft.IIS.Administration.Tests
|
|||
key = "record",
|
||||
value = "paper"
|
||||
}
|
||||
},
|
||||
providers = providers
|
||||
}
|
||||
});
|
||||
|
||||
result = client.Patch(Utils.Self(result), updateProvider);
|
||||
|
@ -683,8 +677,8 @@ namespace Microsoft.IIS.Administration.Tests
|
|||
string[] sections = {
|
||||
"allowed-server-variables",
|
||||
"global-rules",
|
||||
"inbound-rules",
|
||||
"outbound-rules",
|
||||
"inbound",
|
||||
"outbound",
|
||||
"providers",
|
||||
"rewrite-maps"
|
||||
};
|
||||
|
@ -781,15 +775,15 @@ namespace Microsoft.IIS.Administration.Tests
|
|||
Assert.Equal(a.Value<string>("default_value"), b.Value<string>("default_value"));
|
||||
Assert.Equal(a.Value<bool>("ignore_case"), b.Value<bool>("ignore_case"));
|
||||
|
||||
JObject[] aMaps = a["entries"].ToObject<JObject[]>();
|
||||
JObject[] bMaps = b["entries"].ToObject<JObject[]>();
|
||||
JObject[] aMaps = a["mappings"].ToObject<JObject[]>();
|
||||
JObject[] bMaps = b["mappings"].ToObject<JObject[]>();
|
||||
|
||||
Assert.True(aMaps.Length == bMaps.Length);
|
||||
for (int i = 0; i < aMaps.Length; i++) {
|
||||
JObject m = aMaps[i];
|
||||
JObject rm = bMaps[i];
|
||||
|
||||
Assert.Equal(m.Value<string>("key"), rm.Value<string>("key"));
|
||||
Assert.Equal(m.Value<string>("name"), rm.Value<string>("name"));
|
||||
Assert.Equal(m.Value<string>("value"), rm.Value<string>("value"));
|
||||
}
|
||||
}
|
||||
|
@ -883,24 +877,24 @@ namespace Microsoft.IIS.Administration.Tests
|
|||
|
||||
//
|
||||
// Html Tags
|
||||
if (a["html_tags"] != null || b["html_tags"] != null) {
|
||||
JObject aStandard = a["html_tags"].Value<JObject>("standard");
|
||||
JObject bStandard = b["html_tags"].Value<JObject>("standard");
|
||||
if (a["tags"] != null || b["tags"] != null) {
|
||||
JObject aTags = a.Value<JObject>("tags");
|
||||
JObject bTags = b.Value<JObject>("tags");
|
||||
|
||||
Assert.Equal(aStandard.Value<bool>("a"), bStandard.Value<bool>("a"));
|
||||
Assert.Equal(aStandard.Value<bool>("area"), bStandard.Value<bool>("area"));
|
||||
Assert.Equal(aStandard.Value<bool>("base"), bStandard.Value<bool>("base"));
|
||||
Assert.Equal(aStandard.Value<bool>("form"), bStandard.Value<bool>("form"));
|
||||
Assert.Equal(aStandard.Value<bool>("frame"), bStandard.Value<bool>("frame"));
|
||||
Assert.Equal(aStandard.Value<bool>("head"), bStandard.Value<bool>("head"));
|
||||
Assert.Equal(aStandard.Value<bool>("iframe"), bStandard.Value<bool>("iframe"));
|
||||
Assert.Equal(aStandard.Value<bool>("img"), bStandard.Value<bool>("img"));
|
||||
Assert.Equal(aStandard.Value<bool>("input"), bStandard.Value<bool>("input"));
|
||||
Assert.Equal(aStandard.Value<bool>("link"), bStandard.Value<bool>("link"));
|
||||
Assert.Equal(aStandard.Value<bool>("script"), bStandard.Value<bool>("script"));
|
||||
Assert.Equal(aTags.Value<bool>("a"), bTags.Value<bool>("a"));
|
||||
Assert.Equal(aTags.Value<bool>("area"), bTags.Value<bool>("area"));
|
||||
Assert.Equal(aTags.Value<bool>("base"), bTags.Value<bool>("base"));
|
||||
Assert.Equal(aTags.Value<bool>("form"), bTags.Value<bool>("form"));
|
||||
Assert.Equal(aTags.Value<bool>("frame"), bTags.Value<bool>("frame"));
|
||||
Assert.Equal(aTags.Value<bool>("head"), bTags.Value<bool>("head"));
|
||||
Assert.Equal(aTags.Value<bool>("iframe"), bTags.Value<bool>("iframe"));
|
||||
Assert.Equal(aTags.Value<bool>("img"), bTags.Value<bool>("img"));
|
||||
Assert.Equal(aTags.Value<bool>("input"), bTags.Value<bool>("input"));
|
||||
Assert.Equal(aTags.Value<bool>("link"), bTags.Value<bool>("link"));
|
||||
Assert.Equal(aTags.Value<bool>("script"), bTags.Value<bool>("script"));
|
||||
|
||||
if (a["html_tags"]["custom"] != null || b["html_tags"]["custom"] != null) {
|
||||
Assert.Equal(a["html_tags"]["custom"].Value<string>("id"), b["html_tags"]["custom"].Value<string>("id"));
|
||||
if (a["tags"]["custom"] != null || b["tags"]["custom"] != null) {
|
||||
Assert.Equal(a["tags"]["custom"].Value<string>("id"), b["tags"]["custom"].Value<string>("id"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -913,7 +907,7 @@ namespace Microsoft.IIS.Administration.Tests
|
|||
|
||||
private JObject CreateCustomTags(HttpClient client, JObject feature, string name)
|
||||
{
|
||||
JObject outboundRules = Utils.FollowLink(client, feature, "outbound_rules");
|
||||
JObject outboundRules = Utils.FollowLink(client, feature, "outbound");
|
||||
string customTagsLink = Utils.GetLink(outboundRules, "custom_tags");
|
||||
|
||||
foreach (var p in client.Get(customTagsLink)["custom_tags"].ToObject<IEnumerable<JObject>>()) {
|
||||
|
@ -938,7 +932,7 @@ namespace Microsoft.IIS.Administration.Tests
|
|||
attribute = $"{{{name}}}"
|
||||
}
|
||||
},
|
||||
outbound_rules = outboundRules
|
||||
url_rewrite = feature
|
||||
});
|
||||
|
||||
return client.Post(customTagsLink, customTags);
|
||||
|
@ -946,7 +940,7 @@ namespace Microsoft.IIS.Administration.Tests
|
|||
|
||||
private JObject CreatePrecondition(HttpClient client, JObject feature, string name)
|
||||
{
|
||||
JObject outboundRules = Utils.FollowLink(client, feature, "outbound_rules");
|
||||
JObject outboundRules = Utils.FollowLink(client, feature, "outbound");
|
||||
string preConditionsLink = Utils.GetLink(outboundRules, "preconditions");
|
||||
|
||||
foreach (var p in client.Get(preConditionsLink)["preconditions"].ToObject<IEnumerable<JObject>>()) {
|
||||
|
@ -979,7 +973,7 @@ namespace Microsoft.IIS.Administration.Tests
|
|||
ignore_case = false
|
||||
}
|
||||
},
|
||||
outbound_rules = outboundRules
|
||||
url_rewrite = feature
|
||||
});
|
||||
|
||||
return client.Post(preConditionsLink, precondition);
|
||||
|
|
Загрузка…
Ссылка в новой задаче