Skip to content

Commit fbc8594

Browse files
stevejgordongithub-actions[bot]
authored andcommitted
Support network direction processor additions (#5603)
1 parent a30f7fa commit fbc8594

File tree

2 files changed

+48
-3
lines changed

2 files changed

+48
-3
lines changed

src/Nest/Ingest/Processors/NetworkDirectionProcessor.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ public interface INetworkDirectionProcessor : IProcessor
1717

1818
[DataMember(Name = "internal_networks")]
1919
IEnumerable<string> InternalNetworks { get; set; }
20-
20+
21+
[DataMember(Name = "internal_networks_field")]
22+
Field InternalNetworksField { get; set; }
23+
2124
[DataMember(Name = "source_ip")]
2225
Field SourceIp { get; set; }
2326

@@ -36,6 +39,8 @@ public class NetworkDirectionProcessor : ProcessorBase, INetworkDirectionProcess
3639
/// <inheritdoc />
3740
public IEnumerable<string> InternalNetworks { get; set; }
3841
/// <inheritdoc />
42+
public Field InternalNetworksField { get; set; }
43+
/// <inheritdoc />
3944
public Field SourceIp { get; set; }
4045
/// <inheritdoc />
4146
public Field TargetField { get; set; }
@@ -51,6 +56,7 @@ public class NetworkDirectionProcessorDescriptor<T>
5156
Field INetworkDirectionProcessor.DestinationIp { get; set; }
5257
bool? INetworkDirectionProcessor.IgnoreMissing { get; set; }
5358
IEnumerable<string> INetworkDirectionProcessor.InternalNetworks { get; set; }
59+
Field INetworkDirectionProcessor.InternalNetworksField { get; set; }
5460
Field INetworkDirectionProcessor.SourceIp { get; set; }
5561
Field INetworkDirectionProcessor.TargetField { get; set; }
5662

@@ -70,6 +76,13 @@ public NetworkDirectionProcessorDescriptor<T> DestinationIp<TValue>(Expression<F
7076
/// <inheritdoc cref="INetworkDirectionProcessor.InternalNetworks" />
7177
public NetworkDirectionProcessorDescriptor<T> InternalNetworks(params string[] internalNetworks) => Assign(internalNetworks, (a, v) => a.InternalNetworks = v);
7278

79+
/// <inheritdoc cref="INetworkDirectionProcessor.InternalNetworksField" />
80+
public NetworkDirectionProcessorDescriptor<T> InternalNetworksField(Field internalNetworksField) => Assign(internalNetworksField, (a, v) => a.InternalNetworksField = v);
81+
82+
/// <inheritdoc cref="INetworkDirectionProcessor.InternalNetworksField" />
83+
public NetworkDirectionProcessorDescriptor<T> InternalNetworksField<TValue>(Expression<Func<T, TValue>> objectPath) =>
84+
Assign(objectPath, (a, v) => a.InternalNetworksField = v);
85+
7386
/// <inheritdoc cref="INetworkDirectionProcessor.SourceIp" />
7487
public NetworkDirectionProcessorDescriptor<T> SourceIp(Field field) => Assign(field, (a, v) => a.SourceIp = v);
7588

tests/Tests/Ingest/ProcessorAssertions.cs

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
using Elastic.Elasticsearch.Xunit.XunitPlumbing;
1010
using Nest;
1111
using Tests.Core.Client;
12-
using Tests.Core.Extensions;
13-
using Tests.Core.Xunit;
1412
using Tests.Domain;
1513
using static Nest.Infer;
1614

@@ -818,5 +816,39 @@ public class NetworkDirection : ProcessorAssertion
818816

819817
public override string Key => "network_direction";
820818
}
819+
820+
[SkipVersion("<7.13.0", "Uses internal_networks_field added in 7.13.0")]
821+
public class NetworkDirectionWithField : ProcessorAssertion
822+
{
823+
// for testing, we use the developer first name field for the network field
824+
825+
public override ProcFunc Fluent => d => d
826+
.NetworkDirection<Project>(ud => ud
827+
.DestinationIp(f => f.LeadDeveloper.IpAddress)
828+
.SourceIp(f => f.LeadDeveloper.IpAddress)
829+
.InternalNetworksField(f=> f.LeadDeveloper.FirstName)
830+
.TargetField(p => p.Description)
831+
.IgnoreMissing());
832+
833+
public override IProcessor Initializer => new NetworkDirectionProcessor
834+
{
835+
DestinationIp = Field<Project>(f => f.LeadDeveloper.IpAddress),
836+
SourceIp = Field<Project>(f => f.LeadDeveloper.IpAddress),
837+
InternalNetworksField = Field<Project>(f => f.LeadDeveloper.FirstName),
838+
TargetField = "description",
839+
IgnoreMissing = true
840+
};
841+
842+
public override object Json => new
843+
{
844+
destination_ip = "leadDeveloper.ipAddress",
845+
internal_networks_field = "leadDeveloper.firstName",
846+
source_ip = "leadDeveloper.ipAddress",
847+
target_field = "description",
848+
ignore_missing = true
849+
};
850+
851+
public override string Key => "network_direction";
852+
}
821853
}
822854
}

0 commit comments

Comments
 (0)