Skip to content

Commit

Permalink
Add a disallow_fetch protected environment key.
Browse files Browse the repository at this point in the history
If set to true, fetch will fail.

Part of #53. Part of #45.
  • Loading branch information
jkomoros committed Jul 22, 2023
1 parent 61ccbb8 commit e663485
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 1 deletion.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ Parameters:
Environment:
- `mock` - If true, will return a string representation of the request that would have been sent.
- `disallow_fetch` - If true, then any fetches will fail. This is useful to disable dangerous behaviors in sub-graphs.
#### property
Expand Down Expand Up @@ -903,6 +904,12 @@ If true, then `dynamic` seed references that are to a remote seed will fail, eve
Note that you may never use `let` or `let-multi` to set this to false, only to true. This prevents sub-seeds from un-setting mock if a parent has turned it on.
#### disallow_fetch
If true, then `fetch` seed_types will fail.
Note that you may never use `let` or `let-multi` to set this to false, only to true. This prevents sub-seeds from un-setting mock if a parent has turned it on.
### CLI
The CLI can output a mermaid diagram. By default it prints the mermaid diagram definition to the console and exits.
Expand Down
3 changes: 3 additions & 0 deletions config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
"disallow_remote": {
"type": "boolean"
},
"disallow_fetch": {
"type": "boolean"
},
"completion_model": {
"type": "string",
"enum": [
Expand Down
1 change: 1 addition & 0 deletions environment.SAMPLE.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"memory": "_default_memory",
"store": "_default_store",
"disallow_remote": false,
"disallow_fetch": false,
"mock": false,
"namespace": "",
"key": 0,
Expand Down
4 changes: 4 additions & 0 deletions seed-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
"disallow_remote": {
"type": "boolean"
},
"disallow_fetch": {
"type": "boolean"
},
"completion_model": {
"type": "string",
"enum": [
Expand Down Expand Up @@ -2372,6 +2375,7 @@
"profile",
"mock",
"disallow_remote",
"disallow_fetch",
"completion_model",
"embedding_model",
"default_model_provider",
Expand Down
3 changes: 3 additions & 0 deletions src/grow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,9 @@ const growDynamic = async (seed : Seed<SeedDataDynamic>, env : Environment) : Pr

const growFetch = async (seed : Seed<SeedDataFetch>, env : Environment) : Promise<string> => {
const data = seed.data;

if (env.getKnownProtectedKey('disallow_fetch')) throw new Error('Fetch is disabled because disallow_fetch is set to true');

const resource = extractString(await getProperty(seed, env, data.resource, ''));
if (!resource) throw new Error('no resource passed');
const rawMethod = extractString(await getProperty(seed, env, data.method, 'GET'));
Expand Down
3 changes: 2 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ export const knownSecretEnvironmentData = z.object({

const knownEnvironmentProtectedData = z.object({
mock: z.optional(z.boolean()),
disallow_remote: z.optional(z.boolean())
disallow_remote: z.optional(z.boolean()),
disallow_fetch: z.optional(z.boolean())
});

const knownEnvironmentNonSecretData = z.object({
Expand Down
1 change: 1 addition & 0 deletions test/base/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ const loadTestGarden = (files?: string[], skipFetcher = false) : Garden => {
mock: true,
verbose: false,
disallow_remote: false,
disallow_fetch: false,
key: 0,
value: ''
};
Expand Down

0 comments on commit e663485

Please sign in to comment.