-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/regex
- Loading branch information
Showing
14 changed files
with
225 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`Parsers > should be written to the file 1`] = ` | ||
"test: | ||
lib: test | ||
type: test | ||
fields: | ||
- test1 | ||
- test2 | ||
" | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`Pipelines > should only write the pipelines/$PIPELINE/conf.yml 1`] = ` | ||
"{} | ||
" | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import {it, expect, vi, beforeEach, describe} from 'vitest'; | ||
import {vol} from 'memfs' | ||
import {Cribl} from "../index"; | ||
import {Parser} from "../objects"; | ||
|
||
vi.mock('node:fs'); | ||
vi.mock('node:fs/promises'); | ||
|
||
let cribl: Cribl; | ||
|
||
beforeEach(() => { | ||
// reset the state of in-memory fs | ||
vol.reset() | ||
|
||
cribl = new Cribl({outdir: '/tmp'}); | ||
}); | ||
|
||
describe('Parsers', () => { | ||
it('should be written to the file', () => { | ||
new Parser(cribl, 'test', {lib: 'test', type: 'test', fields: ['test1', 'test2']}); | ||
cribl.synth(); | ||
|
||
const volume = vol.toJSON(); | ||
expect(Object.keys(volume)).toEqual(['/tmp/local/cribl/parsers.yml']); | ||
expect(volume['/tmp/local/cribl/parsers.yml']).toMatchSnapshot(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import {it, expect, vi, beforeEach, describe} from 'vitest'; | ||
import {vol} from 'memfs' | ||
import {Cribl} from "../index"; | ||
import {Pipeline} from "../objects/pipeline"; | ||
|
||
vi.mock('node:fs'); | ||
vi.mock('node:fs/promises'); | ||
|
||
let cribl: Cribl; | ||
|
||
beforeEach(() => { | ||
// reset the state of in-memory fs | ||
vol.reset() | ||
|
||
cribl = new Cribl({outdir: '/tmp'}); | ||
}); | ||
|
||
describe('Pipelines', () => { | ||
it('should only write the pipelines/$PIPELINE/conf.yml', () => { | ||
new Pipeline(cribl, 'test', {}); | ||
cribl.synth(); | ||
|
||
const volume = vol.toJSON(); | ||
expect(Object.keys(volume)).toStrictEqual(['/tmp/local/cribl/pipelines/test/conf.yml']); | ||
expect(volume['/tmp/local/cribl/pipelines/test/conf.yml']).toMatchSnapshot(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import {describe, it, expect, vi, beforeEach} from 'vitest'; | ||
import {Cribl, Variable} from '../index'; | ||
import {vol} from "memfs"; | ||
import {WorkerGroup} from "../objects/group"; | ||
|
||
vi.mock('node:fs'); | ||
vi.mock('node:fs/promises'); | ||
|
||
let cribl: Cribl; | ||
|
||
beforeEach(() => { | ||
// reset the state of in-memory fs | ||
vol.reset() | ||
|
||
cribl = new Cribl({outdir: '/tmp'}); | ||
}); | ||
|
||
describe('Cribl', () => { | ||
it('without configs should generate nothing', () => { | ||
cribl.synth(); | ||
|
||
const volume = vol.toJSON(); | ||
expect(Object.keys(volume)).toEqual([]); | ||
}); | ||
|
||
it('configs not in a worker group should be at in $CRIBL_HOME/local', () => { | ||
new Variable(cribl, 'test', {value: 'test'}); | ||
|
||
cribl.synth(); | ||
|
||
const volume = vol.toJSON(); | ||
expect(Object.keys(volume)).toEqual(['/tmp/local/cribl/vars.yml']); | ||
}); | ||
|
||
it('configs in a worker group should be at in $CRIBL_HOME/groups/$GROUP/local', () => { | ||
const group = new WorkerGroup(cribl, 'goat'); | ||
new Variable(group, 'test', {value: 'test'}); | ||
|
||
cribl.synth(); | ||
|
||
const volume = vol.toJSON(); | ||
expect(Object.keys(volume)).toEqual(['/tmp/groups/goat/local/cribl/vars.yml']); | ||
}); | ||
|
||
it('should place configs in the correct scopes', () => { | ||
new Variable(cribl, 'test', {value: 'test'}); | ||
const group = new WorkerGroup(cribl, 'goat'); | ||
new Variable(group, 'test', {value: 'test'}); | ||
|
||
cribl.synth(); | ||
|
||
const volume = vol.toJSON(); | ||
expect(Object.keys(volume)).toEqual(expect.arrayContaining([ | ||
'/tmp/local/cribl/vars.yml', | ||
'/tmp/groups/goat/local/cribl/vars.yml' | ||
])); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import {ConfigConstruct} from "../config"; | ||
import {Construct} from "constructs"; | ||
import Registry from "../registry"; | ||
|
||
export interface ParserProps { | ||
/** | ||
* Parser library | ||
*/ | ||
lib: string; | ||
|
||
/** | ||
* Brief description of this parser. | ||
* | ||
* Optional. | ||
*/ | ||
description?: string; | ||
|
||
/** | ||
* One or more tags related to this parser. | ||
* | ||
* Optional. | ||
*/ | ||
tags?: string; | ||
|
||
/** | ||
* Parser/Formatter type to use. | ||
*/ | ||
type: string; | ||
|
||
/** | ||
* Fields expected to be extracted, in order. If not specified parser will auto-generate. | ||
*/ | ||
fields: string[]; | ||
} | ||
|
||
export class Parser extends ConfigConstruct { | ||
constructor(scope: Construct, id: string, props: ParserProps) { | ||
super(scope, id, props); | ||
} | ||
|
||
get kind() { | ||
return 'parsers'; | ||
} | ||
|
||
static dump(config: ConfigConstruct[]): Record<string, unknown> { | ||
return Object.fromEntries(config.map(c => [c.node.id, c.config])); | ||
} | ||
} | ||
|
||
Registry.register('parsers', Parser); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import {ConfigConstruct} from "../config"; | ||
import {Construct} from "constructs"; | ||
import {File} from "../private/fs"; | ||
import Registry from "../registry"; | ||
|
||
interface PipelineProps { | ||
|
||
} | ||
|
||
export class Pipeline extends ConfigConstruct { | ||
constructor(scope: Construct, id: string, props: PipelineProps) { | ||
super(scope, id, props); | ||
} | ||
|
||
get kind() { | ||
return 'pipelines'; | ||
} | ||
|
||
synth(): void { | ||
const config = this.toYaml(this.config); | ||
|
||
new File(this.path('local', 'cribl', 'pipelines', this.node.id, 'conf.yml')).write(config); | ||
} | ||
|
||
static dump(config: ConfigConstruct[]): undefined { | ||
return undefined; | ||
} | ||
} | ||
|
||
Registry.register('pipelines', Pipeline); |