/// <inheritdoc />
            protected override void Generate(IMethodVariables variables, GeneratedMethod method, IMethodSourceWriter writer, Action next)
            {
                var apiOperationContextVariable = variables.FindVariable(typeof(ApiOperationContext));
                var activityVariable            = apiOperationContextVariable.GetProperty(nameof(ApiOperationContext.Activity));

                var operationTypeKey = ReflectionUtilities.PrettyTypeName(this._context.Descriptor.OperationType);

                writer.BlankLine();

                // 2. For every property of the operation output a value to the exception.Data dictionary. All properties that are
                // not considered sensitive
                foreach (var prop in this._context.Descriptor.Properties)
                {
                    if (SensitiveProperties.IsSensitive(prop))
                    {
                        continue;
                    }

                    // Only support, for now, primitive values, strings and GUIDs to avoid pushing complex types as tags
                    if (!prop.PropertyType.IsPrimitive &&
                        !prop.PropertyType.IsEnum &&
                        prop.PropertyType.GetNonNullableType() != typeof(string) &&
                        prop.PropertyType.GetNonNullableType() != typeof(Guid))
                    {
                        continue;
                    }

                    writer.WriteLine(
                        $"{activityVariable}?.{nameof(Activity.SetTag)}(\"{operationTypeKey}.{prop.Name}\", {variables.FindVariable(this._context.Descriptor.OperationType)}.{prop.Name});");
                }

                next();
            }
Exemplo n.º 2
0
        public object GetValue(object target)
        {
            var value = Inner.GetValue(target);

            if (value != null && value is string)
            {
                var name = this.Member.Name.ToLowerInvariant();
                if (SensitiveProperties?.FirstOrDefault(p => name.Contains(p)) != null)
                {
                    return(MaskValue(value as string, true));
                }
            }
            return(value);
        }
Exemplo n.º 3
0
        /// <inheritdoc />
        protected override void Generate(IMethodVariables variables, GeneratedMethod method, IMethodSourceWriter writer, Action next)
        {
            var contextVariable = variables.FindVariable(typeof(ApiOperationContext));

            writer.WriteLine($"var userAuthorisationContext = {contextVariable}.UserAuthorisationContext;");
            writer.WriteLine($"var identifier = new {typeof(UserExceptionIdentifier).FullNameInCode()}(userAuthorisationContext);");

            writer.BlankLine();

            // 1. Allow user context to populate metadata to the error data dictionary if it exists
            writer.WriteLine($"userAuthorisationContext?.PopulateMetadata((k, v) => {this._exceptionVariable}.Data[k] = v?.ToString());");

            var operationTypeKey = ReflectionUtilities.PrettyTypeName(this._context.Descriptor.OperationType);

            // 2. For every property of the operation output a value to the exception.Data dictionary. ALl properties that are
            // not considered sensitive
            foreach (var prop in this._context.Descriptor.Properties)
            {
                if (SensitiveProperties.IsSensitive(prop))
                {
                    continue;
                }

                // If the type is primitive we need to leave off the '?' null-coalesce method call operator
                var shouldHandleNull = !prop.PropertyType.IsValueType;

                writer.WriteLine($"{this._exceptionVariable}.Data[\"{operationTypeKey}.{prop.Name}\"] = " +
                                 $"{variables.FindVariable(this._context.Descriptor.OperationType)}.{prop.Name}{(shouldHandleNull ? "?" : string.Empty)}.ToString();");
            }

            // 3. Use IErrorLogger to push all details to exception sinks
            writer.BlankLine();

            // We use an inline MethodCall here to enable it to ensure surrounding method is marked as async as necessary
            var methodCall = MethodCall.For <IErrorLogger>(e => e.LogAsync(default(Exception), default(object), default(UserExceptionIdentifier)));

            methodCall.Arguments[0] = this._exceptionVariable;
            methodCall.Arguments[1] = new Variable(typeof(object), "null");
            methodCall.Arguments[2] = new Variable(typeof(UserExceptionIdentifier), "identifier");

            writer.Write(methodCall);

            writer.BlankLine();
        }
Exemplo n.º 4
0
 protected override List <MemberInfo> GetSerializableMembers(Type objectType)
 {
     return(base.GetSerializableMembers(objectType)
            .Where(p => !SensitiveProperties.IsSensitive(p))
            .ToList());
 }