예제 #1
0
 /// <summary>
 /// Applies a simple value replacement for a target header key. If it does not exist, no actions will be taken.
 /// </summary>
 /// <param name="key">The name of the header we're operating against.</param>
 /// <param name="target">A target string. This could contain special regex characters like "?()+*" but they will be treated as a literal.</param>
 /// <param name="value">The substitution value.</param>
 /// <param name="condition">
 /// A condition that dictates when this sanitizer applies to a request/response pair. The content of this key should be a JSON object that contains configuration keys.
 /// Currently, that only includes the key "uriRegex". This translates to an object that looks like '{ "uriRegex": "when this regex matches, apply the sanitizer" }'. Defaults to "apply always."
 /// </param>
 public HeaderStringSanitizer(string key, string target, string value = "Sanitized", ApplyCondition condition = null)
 {
     _targetKey   = key;
     _newValue    = value;
     _targetValue = target;
     Condition    = condition;
 }
예제 #2
0
        public async Task ApplyFlightEstimate(BillingNOC noc, Models.ExponentPortalEntities db)
        {
            String SQL =
                $@"SELECT 
          {CalculateField} * {CostMultipliedBy} / {_CostDividedBy} 
        FROM #NOC_Details";

            if (!String.IsNullOrWhiteSpace(ApplyCondition))
            {
                String _ACondition = ApplyCondition.Replace("DroneFlight.", "#NOC_Details.");
                SQL += $" WHERE ({_ACondition})";
            }

            using (var cmd = db.Database.Connection.CreateCommand()) {
                cmd.CommandText = SQL;
                var Result = await cmd.ExecuteScalarAsync();

                if (Result == null)
                {
                    _CalculatedCost = 0;
                }
                else
                {
                    Decimal.TryParse(Result.ToString(), out _CalculatedCost);
                }
            }//using ctx.Database.Connection.CreateCommand
        }
        /// <summary>
        /// This sanitizer offers regex replace within a returned body. Specifically, this means regex applying to the raw JSON. If you are attempting to simply
        /// replace a specific key, the BodyKeySanitizer is probably the way to go. Regardless, there are examples present in SanitizerTests.cs.
        /// to
        /// </summary>
        /// <param name="value">The substitution value.</param>
        /// <param name="regex">A regex. Can be defined as a simple regex replace OR if groupForReplace is set, a subsitution operation.</param>
        /// <param name="groupForReplace">The capture group that needs to be operated upon. Do not set if you're invoking a simple replacement operation.</param>
        /// <param name="condition">
        /// A condition that dictates when this sanitizer applies to a request/response pair. The content of this key should be a JSON object that contains configuration keys.
        /// Currently, that only includes the key "uriRegex". This translates to an object that looks like '{ "uriRegex": "when this regex matches, apply the sanitizer" }'. Defaults to "apply always."
        /// </param>
        public BodyRegexSanitizer(string value = "Sanitized", string regex = null, string groupForReplace = null, ApplyCondition condition = null)
        {
            _newValue        = value;
            _regexValue      = regex;
            _groupForReplace = groupForReplace;
            Condition        = condition;

            StringSanitizer.ConfirmValidRegex(regex);
        }
예제 #4
0
        /// <summary>
        /// This sanitizer offers a value replace across request/response Body, Headers, and URI. For the body, this means a string replacement applied directly to the raw JSON.
        /// </summary>
        /// <param name="value">The substitution value.</param>
        /// <param name="target">A target string. This could contain special regex characters like "?()+*" but they will be treated as a literal.</param>
        /// <param name="condition">
        /// A condition that dictates when this sanitizer applies to a request/response pair. The content of this key should be a JSON object that contains configuration keys.
        /// Currently, that only includes the key "uriRegex". This translates to an object that looks like '{ "uriRegex": "when this regex matches, apply the sanitizer" }'. Defaults to "apply always."
        /// </param>
        public GeneralStringSanitizer(string target, string value = "Sanitized", ApplyCondition condition = null)
        {
            _targetValue = target;
            _newValue    = value;
            Condition    = condition;

            _bodySanitizer = new BodyStringSanitizer(target, value, condition);
            _uriSanitizer  = new UriStringSanitizer(target, value, condition);
        }
예제 #5
0
        /// <summary>
        /// Can be used for multiple purposes:
        ///     1) To replace a key with a specific value, do not set "regex" value.
        ///     2) To do a simple regex replace operation, define arguments "key", "value", and "regex"
        ///     3) To do a targeted substitution of a specific group, define all arguments "key", "value", and "regex"
        /// </summary>
        /// <param name="key">The name of the header we're operating against.</param>
        /// <param name="value">The substitution or whole new header value, depending on "regex" setting.</param>
        /// <param name="regex">A regex. Can be defined as a simple regex replace OR if groupForReplace is set, a subsitution operation.</param>
        /// <param name="groupForReplace">The capture group that needs to be operated upon. Do not set if you're invoking a simple replacement operation.</param>
        /// <param name="condition">
        /// A condition that dictates when this sanitizer applies to a request/response pair. The content of this key should be a JSON object that contains configuration keys.
        /// Currently, that only includes the key "uriRegex". This translates to an object that looks like '{ "uriRegex": "when this regex matches, apply the sanitizer" }'. Defaults to "apply always."
        /// </param>
        public HeaderRegexSanitizer(string key, string value = "Sanitized", string regex = ".+", string groupForReplace = null, ApplyCondition condition = null)
        {
            _targetKey       = key;
            _newValue        = value;
            _regexValue      = regex;
            _groupForReplace = groupForReplace;
            Condition        = condition;

            StringSanitizer.ConfirmValidRegex(regex);
        }
예제 #6
0
        /// <summary>
        /// This sanitizer offers regex update of a specific JTokenPath. EG: "TableName" within a json response body having its value replaced by
        /// whatever substitution is offered. This simply means that if you are attempting to replace a specific key wholesale, this sanitizer will be
        /// simpler than configuring a BodyRegexSanitizer that has to match against the full "KeyName": "Value" that is part of the json structure. Further reading is available
        /// <a href="https://www.newtonsoft.com/json/help/html/SelectToken.htm#SelectTokenJSONPath">here.</a> If the body is NOT a JSON object, this sanitizer will NOT be applied.
        /// </summary>
        /// <param name="jsonPath">The SelectToken path (which could possibly match multiple entries) that will be used to select JTokens for value replacement.</param>
        /// <param name="value">The substitution value.</param>
        /// <param name="regex">A regex. Can be defined as a simple regex replace OR if groupForReplace is set, a subsitution operation. Defaults to replacing the entire string.</param>
        /// <param name="groupForReplace">The regex capture group that needs to be operated upon. Do not set if you're invoking a simple replacement operation.</param>
        /// <param name="condition">
        /// A condition that dictates when this sanitizer applies to a request/response pair. The content of this key should be a JSON object that contains various configuration keys.
        /// Currently, that only includes the key "uriRegex". This translates to an object that looks like '{ "uriRegex": "when this regex matches, apply the sanitizer" }'. Defaults to "apply always."
        /// </param>
        public BodyKeySanitizer(string jsonPath, string value = "Sanitized", string regex = ".+", string groupForReplace = null, ApplyCondition condition = null)
        {
            _jsonPath        = jsonPath;
            _newValue        = value;
            _regexValue      = regex;
            _groupForReplace = groupForReplace;
            Condition        = condition;

            StringSanitizer.ConfirmValidRegex(regex);
        }
예제 #7
0
        /// <summary>
        /// This sanitizer offers a general regex replace across request/response Body, Headers, and URI. For the body, this means regex applying to the raw JSON.
        /// to
        /// </summary>
        /// <param name="value">The substitution value.</param>
        /// <param name="regex">A regex. Can be defined as a simple regex replace OR if groupForReplace is set, a subsitution operation.</param>
        /// <param name="groupForReplace">The capture group that needs to be operated upon. Do not set if you're invoking a simple replacement operation.</param>
        /// <param name="condition">
        /// A condition that dictates when this sanitizer applies to a request/response pair. The content of this key should be a JSON object that contains configuration keys.
        /// Currently, that only includes the key "uriRegex". This translates to an object that looks like '{ "uriRegex": "when this regex matches, apply the sanitizer" }'. Defaults to "apply always."
        /// </param>
        public GeneralRegexSanitizer(string value = "Sanitized", string regex = ".+", string groupForReplace = null, ApplyCondition condition = null)
        {
            _newValue        = value;
            _regexValue      = regex;
            _groupForReplace = groupForReplace;
            Condition        = condition;

            StringSanitizer.ConfirmValidRegex(regex);

            _bodySanitizer = new BodyRegexSanitizer(value, regex, groupForReplace);
            _uriSanitizer  = new UriRegexSanitizer(value, regex, groupForReplace);
        }
예제 #8
0
 public StorageRequestIdTransform(ApplyCondition condition = null)
 {
     Condition = condition;
 }
예제 #9
0
 /// <summary>
 /// Constructs a new HeaderTransform instance.
 /// </summary>
 /// <param name="key">The header key for the header.</param>
 /// <param name="value">The value for the header.</param>
 /// <param name="condition">
 /// A condition that dictates when this transform applies to a request/response pair. The content of this key should be a JSON object that contains configuration keys.
 /// Currently, that only includes the key "uriRegex". This translates to an object that looks like '{ "uriRegex": "when this regex matches, apply the sanitizer" }'.
 /// Defaults to "apply always."
 /// </param>
 /// <remarks>
 /// By default, the header will be set in the response whether or not the header key is already
 /// present.
 /// If the header should only be set if the header key is already present in the response,
 /// include a Condition populated with a ResponseHeader in the HeaderTransform JSON.
 /// </remarks>
 public HeaderTransform(string key, string value, ApplyCondition condition = null)
 {
     _key      = key;
     _value    = value;
     Condition = condition;
 }
예제 #10
0
 public ApiVersionTransform(ApplyCondition condition = null)
 {
     Condition = condition;
 }
예제 #11
0
 /// <summary>
 /// Runs a simple string replacement against the request/response URIs.
 /// </summary>
 /// <param name="value">The substitution value.</param>
 /// <param name="target">A target string. This could contain special regex characters like "?()+*" but they will be treated as a literal.</param>
 /// <param name="condition">
 /// A condition that dictates when this sanitizer applies to a request/response pair. The content of this key should be a JSON object that contains configuration keys.
 /// Currently, that only includes the key "uriRegex". This translates to an object that looks like '{ "uriRegex": "when this regex matches, apply the sanitizer" }'. Defaults to "apply always."
 /// </param>
 public UriStringSanitizer(string target, string value = "Sanitized", ApplyCondition condition = null)
 {
     _targetValue = target;
     _newValue    = value;
     Condition    = condition;
 }
예제 #12
0
 public BusinessRuleAttribute(ApplyCondition applyTo)
 {
     ApplyTo = applyTo;
     Order = 999;
 }
예제 #13
0
        /// <summary>
        /// This sanitizer is targeted using the regex "/subscriptions/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})". This is not a setting
        /// that can be changed for this sanitizer. For full regex support, take a look at UriRegexSanitizer. You CAN modify the value
        /// that the subscriptionId is replaced WITH however.
        /// </summary>
        /// <param name="value">The fake subscriptionId that will be placed where the real one is in the real request. The default replacement value is "00000000-0000-0000-0000-000000000000".</param>
        /// <param name="condition">
        /// A condition that dictates when this sanitizer applies to a request/response pair. The content of this key should be a JSON object that contains configuration keys.
        /// Currently, that only includes the key "uriRegex". This translates to an object that looks like '{ "uriRegex": "when this regex matches, apply the sanitizer" }'. Defaults to "apply always."
        /// </param>
        public UriSubscriptionIdSanitizer(string value = "00000000-0000-0000-0000-000000000000", ApplyCondition condition = null) : base(value: value, regex: _regex, groupForReplace: _groupForReplace)
        {
            Condition = condition;

            _value = value;
        }
예제 #14
0
 public AbstractArgs(ApplyDomain domain, ApplyCondition condition) : base(domain, condition)
 {
 }
예제 #15
0
        /// <summary>
        /// Removes headers from before saving a recording.
        /// </summary>
        /// <param name="headersForRemoval">A comma separated list. Should look like "Location, Transfer-Encoding" or something along those lines! Don't worry about whitespace
        /// between the commas separating each key. They will be ignored.</param>
        /// <param name="condition">
        /// A condition that dictates when this sanitizer applies to a request/response pair. The content of this key should be a JSON object that contains configuration keys.
        /// Currently, that only includes the key "uriRegex". This translates to an object that looks like '{ "uriRegex": "when this regex matches, apply the sanitizer" }'. Defaults to "apply always."
        /// </param>
        public RemoveHeaderSanitizer(string headersForRemoval, ApplyCondition condition = null)
        {
            Condition = condition;

            _keysForRemoval = headersForRemoval.Split(",").Select(x => x.Trim()).ToArray();
        }
예제 #16
0
 public PFuncAttribute(Type format, ApplyDomain domain = ApplyDomain.NetMultiple, ApplyCondition condition = ApplyCondition.All)
 {
     this.Format    = format;
     this.Domain    = domain;
     this.Condition = condition;
 }
예제 #17
0
 public PPropAttribute(Type format, object defaultValue = null, ApplyDomain domain = ApplyDomain.NetMultiple, ApplyCondition condition = ApplyCondition.All)
 {
     this.Format       = format;
     this.DefaultValue = defaultValue;
     this.Domain       = domain;
     this.Condition    = condition;
 }
예제 #18
0
 public ClientIdTransform(ApplyCondition condition = null)
 {
     Condition = condition;
 }
예제 #19
0
        /// <summary>
        /// Gets the named set rules for the model type where the apply conditions are met and the rule is enabled.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <param name="applyCondition">The apply condition.</param>
        /// <param name="namedSet">The named set.</param>
        /// <returns></returns>
        public IEnumerable<Type> GetRulesFor(Type model, ApplyCondition applyCondition, string namedSet)
        {
            if (model == null)
            {
                throw Error.ArgumentNull("model");
            }

            if (namedSet.IsNullOrEmpty())
            {
                throw Error.ArgumentNullOrEmpty("namedSet");
            }

            ThrowIfModelTypeIsInvalid(model);

            return GetRulesStorageForModel(CreateKey(model, namedSet))
                .Where(ruleValue => ruleValue.SatisfiesApplyCondition(applyCondition) && ruleValue.Enabled)
                .OrderBy(x => x.Order)
                .Select(x => x.BusinessRuleType);
        }
예제 #20
0
 private bool CanInvoke(ulong authorityOwnerId, ApplyCondition condition)
 {
     return((ApplyCondition.All == condition) ||
            (ApplyCondition.OwnerOnly == condition && authorityOwnerId == ((Creator)this.Actor.Creator).Id) ||
            (ApplyCondition.SkipOwner == condition && authorityOwnerId != ((Creator)this.Actor.Creator).Id));
 }
예제 #21
0
        public PMeta(object defaultValue, PropertyInfo property, object target, ApplyDomain domain, ApplyCondition condition) : base(domain, condition)
        {
            this.defaultValue = (null != defaultValue ? (T)defaultValue : default(T));

            var getMethod = property.GetGetMethod();

            if (null != getMethod)
            {
                this.getFunc = (Func <T>)Delegate.CreateDelegate(typeof(Func <T>), target, getMethod);
            }

            var setMethod = property.GetSetMethod();

            if (null != setMethod)
            {
                this.setFunc = (Method <T>)Delegate.CreateDelegate(typeof(Method <T>), target, setMethod);
                Reset();
            }
        }
예제 #22
0
 public AbstractMeta(ApplyDomain domain, ApplyCondition condition)
 {
     this.Domain    = domain;
     this.Condition = condition;
 }
예제 #23
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="method"></param>
 /// <param name="domain"></param>
 /// <param name="condition"></param>
 public PArgs(Delegate method, ApplyDomain domain, ApplyCondition condition) : base(domain, condition)
 {
     this.method = (Method)method;
 }
예제 #24
0
 public BusinessRuleAttribute(ApplyCondition applyTo, int order)
 {
     ApplyTo = applyTo;
     Order = order;
 }
예제 #25
0
 /// <summary>
 /// Gets the rules where the apply conditions are met and the rule is enabled.
 /// </summary>
 /// <param name="applyCondition">The apply condition.</param>
 /// <returns></returns>
 public IEnumerable<Type> GetRules(ApplyCondition applyCondition)
 {
     return Rules.SelectMany(x => x.Value)
         .Where(x => x.SatisfiesApplyCondition(applyCondition) && x.Enabled)
         .Select(x => x.BusinessRuleType)
         .Distinct();
 }