コード例 #1
0
        private static (string, string, string) ParseRulesRequestArgs(dynamic args, Request request,
                                                                      bool parsePathPattern = true)
        {
            var dbid  = (string)args.dbid;
            var path  = (string)request.Query.path;
            var keyid = (string)request.Query.keyid;
            var wc    = (string)request.Query.wc == "1"; // whether to parse as a wildcard

            if (string.IsNullOrWhiteSpace(dbid))
            {
                dbid = null;
            }
            if (string.IsNullOrWhiteSpace(path))
            {
                path = parsePathPattern ? WildcardMatcher.ToRegex("/*") : "/";
            }
            if (wc)
            {
                // convert wildcard to regex
                path = WildcardMatcher.ToRegex(path);
            }
            else
            {
                if (parsePathPattern)
                {
                    try
                    {
                        Regex.IsMatch("", path);
                    }
                    catch
                    {
                        // Path regex was invalid, parse as wildcard
                        path = WildcardMatcher.ToRegex(path);
                    }
                }
            }
            return(dbid, path, keyid);
        }
コード例 #2
0
 /// <summary>
 ///     Creates a new security rule
 /// </summary>
 /// <param name="pathWildcard"></param>
 /// <param name="actions">The action flags to grant or restrict access to</param>
 /// <param name="allow">whether the rule should allow or deny</param>
 /// <param name="priority">If less than 0, the default priority calculation will be used</param>
 public SecurityRule(string pathWildcard, DatabaseAction actions = 0, bool allow = true,
                     int priority = -1) : this(
         new Regex(WildcardMatcher.ToRegex(pathWildcard)), actions, allow, priority)
 {
 }