Skip to content
This repository has been archived by the owner on Mar 15, 2024. It is now read-only.

Commit

Permalink
feat: allow extra root properties in configuration file
Browse files Browse the repository at this point in the history
This enables other tools to store data in the configuration file. Nonetheless, the user will see a message (at the INFO level) for configuration fields which are not understood by the agent. This is to help diagnose unexpected outcomes while applying the agent.
  • Loading branch information
lachrist committed Jun 7, 2022
1 parent a1c95b1 commit 3cbcec0
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 6 deletions.
1 change: 0 additions & 1 deletion build/schema/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,6 @@

- $id: config
type: object
additionalProperties: false
properties:
# server
agent: {$ref: agent}
Expand Down
2 changes: 1 addition & 1 deletion components/setup/node/index.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ global.GLOBAL_PROMPTS = () => ({ value: false });
{
await writeFileAsync(
new URL(`${directory}/appmap.yml`),
"{valid: yaml}",
"invalid configuration type",
"utf8",
);
assertEqual(await mainAsync({ ...process, cwd }), false);
Expand Down
1 change: 1 addition & 0 deletions components/validate/ajv/.build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
branches: [test, node, browser]
dependencies:
- util
- log
- expect
17 changes: 15 additions & 2 deletions components/validate/ajv/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import Treeify from "treeify";
import AjvErrorTree from "ajv-error-tree";
import { schema } from "../../../dist/schema.mjs";

const {ownKeys} = Reflect;
const _Map = Map;
const { asTree } = Treeify;

export default (dependencies) => {
const {
util: { assert, coalesce },
util: { hasOwnProperty, assert, coalesce },
expect: { expect },
log: {logGuardInfo},
} = dependencies;
const naming = new _Map([
["config", "configuration"],
Expand Down Expand Up @@ -39,9 +41,20 @@ export default (dependencies) => {
}
};
};
const validateConfig = generateValidate("config");
const config_schema = schema.find(({$id}) => $id === "config");
return {
validateMessage: generateValidate("message"),
validateConfig: generateValidate("config"),
validateConfig: (config) => {
validateConfig(config);
for (const key of ownKeys(config)) {
logGuardInfo(
!hasOwnProperty(config_schema.properties, key),
"Configuration property not recognized by the agent: %j",
key,
);
}
},
validateConfiguration: generateValidate("configuration"),
validateSourceMap: generateValidate("source-map"),
};
Expand Down
11 changes: 9 additions & 2 deletions components/validate/ajv/index.test.mjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import { assertThrow } from "../../__fixture__.mjs";
import { assertEqual, assertThrow } from "../../__fixture__.mjs";
import { buildTestDependenciesAsync } from "../../build.mjs";
import Validation from "./index.mjs";

const { validateConfig } = Validation(
await buildTestDependenciesAsync(import.meta.url),
);

assertEqual(
validateConfig({ extra: "extra-root-property" }),
undefined,
);

assertThrow(() => {
validateConfig({ mode: "invalid-mode" });
validateConfig("invalid-configuration-type");
}, /^AppmapError: invalid configuration\n/u);

assertThrow(() => {
validateConfig({ engine: "invalid-engine-format" });
}, /^AppmapError: invalid configuration\n/u);

0 comments on commit 3cbcec0

Please sign in to comment.