Skip to content

Commit

Permalink
build: configs
Browse files Browse the repository at this point in the history
  • Loading branch information
jshlbrd committed Sep 26, 2023
1 parent 89d875a commit 611bc2c
Show file tree
Hide file tree
Showing 17 changed files with 182 additions and 90 deletions.
144 changes: 101 additions & 43 deletions build/config/substation.libsonnet

Large diffs are not rendered by default.

20 changes: 7 additions & 13 deletions build/config/substation_test.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,24 @@ local inspector = sub.condition.format.json();
get_element: sub.helpers.key.get_element(key, 1),
},
},
patterns: {
pattern: {
condition: {
obj: sub.patterns.condition.obj(key),
negate: sub.patterns.condition.negate(inspector),
obj: sub.pattern.condition.obj(key),
negate: sub.pattern.condition.negate(inspector),
network: {
ip: {
internal: sub.patterns.condition.network.ip.internal(key),
internal: sub.pattern.condition.network.ip.internal(key),
},
},
logic: {
len: {
eq_zero: sub.patterns.condition.number.length.eq_zero(key),
gt_zero: sub.patterns.condition.number.length.gt_zero(key),
eq_zero: sub.pattern.condition.number.length.eq_zero(key),
gt_zero: sub.pattern.condition.number.length.gt_zero(key),
},
},
string: {
eq: sub.patterns.condition.string.equal_to('x', key),
contains: sub.patterns.condition.string.contains('x', key),
starts_with: sub.patterns.condition.string.starts_with('x', key),
ends_with: sub.patterns.condition.string.ends_with('x', key),
},
},
transform: {
conditional: sub.patterns.transform.conditional(inspector, transform),
conditional: sub.pattern.transform.conditional(inspector, transform),
},
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ local sub = import '../../../../../../../build/config/substation.libsonnet';
type: 'aws_cloudwatch_embedded_metrics',
},
transforms: [
sub.transform.send.stdout(),
sub.tf.send.stdout(),
],
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ local sub = import '../../../../../../../build/config/substation.libsonnet';
type: 'aws_cloudwatch_embedded_metrics',
},
transforms: [
sub.transform.object.insert(
sub.tf.object.insert(
settings={ object: { set_key: 'transformed' }, value: true }
),
// Appending a newline is required so that the S3 object is line delimited.
sub.transform.string.append(
sub.tf.string.append(
settings={ string: '\n' }
),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ local sub = import '../../../../../../../build/config/substation.libsonnet';
type: 'aws_cloudwatch_embedded_metrics',
},
transforms: [
sub.transform.send.aws.kinesis_data_stream(
sub.tf.send.aws.kinesis_data_stream(
settings={ stream_name: 'dst' },
),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ local sub = import '../../../../../../../build/config/substation.libsonnet';
type: 'aws_cloudwatch_embedded_metrics',
},
transforms: [
sub.transform.send.stdout(),
sub.tf.send.stdout(),
],
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@ local sub = import '../../../../../../../build/config/substation.libsonnet';
{
transforms: [
// Dynamically handles input from either Lambda URL or synchronous invocation.
sub.patterns.transform.conditional(
transform=sub.transform.object.copy(
settings={ object: { key: 'body' } }
),
condition=sub.condition.all([
sub.condition.number.length.greater_than(
sub.pattern.tf.conditional(
condition=sub.cnd.all([
sub.cnd.number.length.greater_than(
settings={ object: { key: 'body' }, length: 0 }
),
]),
transform=sub.tf.object.copy(
settings={ object: { key: 'body' } }
),
),
// Performs a reverse DNS lookup on the 'addr' field if it is a public IP address.
sub.patterns.transform.conditional(
condition=sub.condition.none(sub.patterns.condition.network.ip.internal(key='addr')),
transform=sub.transform.enrich.dns.ip_lookup(
sub.pattern.tf.conditional(
condition=sub.cnd.none(sub.pattern.cnd.network.ip.internal(key='addr')),
transform=sub.tf.enrich.dns.ip_lookup(
settings={ object: { key: 'addr', set_key: 'domain' } },
),
),
// The DNS response is copied so that it is the only value returned in the object.
sub.transform.object.copy(
sub.tf.object.copy(
settings={ object: { key: 'domain' } },
),
sub.transform.object.copy(
sub.tf.object.copy(
settings={ object: { set_key: 'domain' } },
),
],
Expand Down
6 changes: 3 additions & 3 deletions examples/aws/lambda/s3/data_lake/config/node/config.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ local bucket = 'd7c66938-6b96-21a3-7e59-62cb40e4627f-substation';
type: 'aws_cloudwatch_embedded_metrics',
},
transforms: [
sub.transform.send.aws.s3(
sub.tf.send.aws.s3(
settings={ bucket_name: bucket, file_path: { prefix: 'original' } }
),
sub.transform.object.insert(
sub.tf.object.insert(
settings={ object: { set_key: 'transformed' }, value: true }
),
sub.transform.send.aws.s3(
sub.tf.send.aws.s3(
settings={ bucket_name: bucket, file_path: { prefix: 'transformed' } }
),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ local sub = import '../../../../../../../build/config/substation.libsonnet';
type: 'aws_cloudwatch_embedded_metrics',
},
transforms: [
sub.transform.send.aws.sns(
sub.tf.send.aws.sns(
// This is a placeholder that must be replaced with the SNS ARN produced by Terraform.
settings={ arn: 'arn:aws:sns:us-east-1:123456789012:substation' },
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ local sub = import '../../../../../../../build/config/substation.libsonnet';
type: 'aws_cloudwatch_embedded_metrics',
},
transforms: [
sub.transform.send.stdout(),
sub.tf.send.stdout(),
],
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ local sub = import '../../../../../../../build/config/substation.libsonnet';
type: 'aws_cloudwatch_embedded_metrics',
},
transforms: [
sub.transform.send.stdout(),
sub.tf.send.stdout(),
],
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ local sub = import '../../../../../../../build/config/substation.libsonnet';
type: 'aws_cloudwatch_embedded_metrics',
},
transforms: [
sub.transform.send.stdout(),
sub.tf.send.stdout(),
],
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ local sub = import '../../../../../../../build/config/substation.libsonnet';
{
transforms: [
// Dynamically handles input from either Lambda URL or synchronous invocation.
sub.patterns.transform.conditional(
sub.pattern.transform.conditional(
transform=sub.transform.object.copy(
settings={ object: { key: 'body' } }
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ local sub = import '../../../../../../../build/config/substation.libsonnet';
},
transforms: [
// Remove any events that do not have a 'uuid' field.
sub.patterns.transform.conditional(
condition=sub.condition.all(sub.patterns.condition.number.length.eq_zero(key='uuid')),
sub.pattern.transform.conditional(
condition=sub.condition.all(sub.pattern.condition.number.length.eq_zero(key='uuid')),
transform=sub.transform.utility.drop(),
),
// Performs a reverse DNS lookup on the 'addr' field if it is a public IP address.
sub.patterns.transform.conditional(
condition=sub.condition.none(sub.patterns.condition.network.ip.internal(key='addr')),
sub.pattern.transform.conditional(
condition=sub.condition.none(sub.pattern.condition.network.ip.internal(key='addr')),
transform=sub.transform.enrich.dns.ip_lookup(
settings={ object: { key: 'addr', set_key: 'domain' } },
),
Expand Down
10 changes: 5 additions & 5 deletions examples/client/file/event.libsonnet
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
local sub = import '../../../build/config/substation.libsonnet';

local match = sub.condition.any(
sub.condition.string.equal_to(
local match = sub.cnd.any(
sub.cnd.string.equal_to(
settings={ object: { key: 'foo' }, string: 'baz' }
),
);

local copy = sub.transform.object.copy(
local copy = sub.tf.object.copy(
settings={ object: { key: 'foo', set_key: 'bar' } },
);

{
transforms: [
sub.patterns.transform.conditional(
sub.pattern.tf.conditional(
condition=match, transform=copy,
),
sub.transform.object.insert(
sub.tf.object.insert(
settings={ object: { set_key: 'qux' }, value: 'quux' },
),
],
Expand Down
2 changes: 1 addition & 1 deletion examples/client/file/send.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ local sub = import '../../../build/config/substation.libsonnet';

{
transforms: [
sub.transform.send.stdout(),
sub.tf.send.stdout(),
],
}
40 changes: 40 additions & 0 deletions examples/config/config.jsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
local sub = import '../../build/config/substation.libsonnet';

{
// Substation application configs always contain an array named `transforms`.
transforms: [
// Each transform function is defined in the `substation` library.
sub.transform.object.insert(
settings={ object: { set_key: 'a' }, value: 'b' },
),
// Transform functions can be conditionally applied using the
// `meta.switch` function.
sub.transform.meta.switch(settings={
switch: [
{
condition: sub.condition.any(
sub.condition.string.equal_to(
settings={ object: { key: 'a' }, string: 'z' }
)
),
transform: sub.transform.object.insert(
settings={ object: { set_key: 'c' }, value: 'd' },
),
},
],
}),
// This is identical to the previous example, but uses a pre-defined
// pattern and library abbreviations.
sub.pattern.tf.conditional(
condition=sub.cnd.str.eq(
settings={ object: { key: 'a' }, string: 'z' }
),
transform=sub.tf.obj.insert(
settings={ object: { set_key: 'c' }, value: 'd' },
),
),
// Applications usually rely on a `send` transform to send results
// to a destination. These can be defined anywhere in the config.
sub.tf.send.stdout(),
],
}

0 comments on commit 611bc2c

Please sign in to comment.