Skip to content
This repository was archived by the owner on Feb 24, 2023. It is now read-only.

Commit ce275b3

Browse files
committed
Feature flag added to deps. Changed edge to handle data from GET request - ?d= first before post. Added method for sending posts via data manager
1 parent 880742f commit ce275b3

File tree

5 files changed

+65
-33
lines changed

5 files changed

+65
-33
lines changed

api/src/backends/configuration/abstractions/BaseConfig.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,10 @@ export default abstract class BaseConfig {
250250
return await this.getConfigEntryThrows('SMTP_PASSWORD');
251251
}
252252

253+
public async trackDependencies(): Promise<boolean> {
254+
return (await this.getConfigEntryOrElse('TRACK_DEPENDENCIES', 'false')) === 'true';
255+
}
256+
253257
public async isCaptchaEnabled(): Promise<boolean> {
254258
return (await this.getConfigEntryOrElse('CAPTCHA_ENABLED', 'true')) === 'true';
255259
}

api/src/managers/tag/ActionManager.ts

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -358,26 +358,28 @@ export default class ActionManager extends Manager<Action> {
358358
};
359359

360360
private async registerAllDeps(actor: User, action: Action, checks: DataMapSchemaCheck[]) {
361-
const repoFactory = container.get<RepoFromModelFactory>(TYPES.RepoFromModelFactory);
362-
await Promise.all(
363-
checks
364-
.map((_) =>
365-
_.model_links?.map(
366-
async (modelLink) =>
367-
await repoFactory(Dependency).save(
368-
new Dependency(
369-
action.id,
370-
action.constructor.name,
371-
modelLink.id,
372-
modelLink.name,
361+
if (await this.config.trackDependencies()) {
362+
const repoFactory = container.get<RepoFromModelFactory>(TYPES.RepoFromModelFactory);
363+
await Promise.all(
364+
checks
365+
.map((_) =>
366+
_.model_links?.map(
367+
async (modelLink) =>
368+
await repoFactory(Dependency).save(
369+
new Dependency(
370+
action.id,
371+
action.constructor.name,
372+
modelLink.id,
373+
modelLink.name,
374+
),
375+
actor,
373376
),
374-
actor,
375-
),
376-
),
377-
)
378-
.filter((_): _ is Promise<Dependency>[] => _ !== undefined)
379-
.flat(),
380-
);
377+
),
378+
)
379+
.filter((_): _ is Promise<Dependency>[] => _ !== undefined)
380+
.flat(),
381+
);
382+
}
381383
}
382384

383385
private async removeAllDeps(actor: User, action: Action) {

edge/src/main/java/com/scale8/extended/ExtendedRequest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,13 @@ public Map<String, String> getAllParameters() {
9191
}
9292

9393
public Optional<JsonObject> getJSONPayload() {
94-
if (request.getMethodName().equals("POST")) {
94+
String data = request.getParameters().get("d");
95+
if(data != null){
96+
return Optional.of(new Gson().fromJson(data, JsonObject.class));
97+
} else if(request.getMethodName().equals("POST")){
9598
return asJsonObject();
9699
} else {
97-
String data = request.getParameters().get("d");
98-
return data == null
99-
? Optional.empty()
100-
: Optional.of(new Gson().fromJson(data, JsonObject.class));
100+
return Optional.empty();
101101
}
102102
}
103103

platforms/build.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,19 @@ const PUBLIC_PATH = `http://127.0.0.1:${SERVER_PORT}`;
1414

1515
const runTests = (projectName) => {
1616
return new Promise((resolve, reject) => {
17-
const jest = spawn('jest', [
17+
const opts = [
1818
'--testEnvironment=node',
1919
"--transform='" + JSON.stringify({
2020
'\\.tsx?$': 'ts-jest',
2121
}) + "'",
2222
`--moduleFileExtensions=js`,
2323
`--moduleFileExtensions=ts`,
2424
`--testRegex='providers/${projectName}/tests/.+?spec\\.ts$'`,
25-
], { shell: true, stdio: 'inherit' });
25+
];
26+
27+
console.log(`Jest opts: ${opts.join(' ')}`);
28+
29+
const jest = spawn('yarn jest', opts, { shell: true, stdio: 'inherit' });
2630

2731
jest.on('close', (code) => {
2832
if(code === 0){
@@ -32,7 +36,7 @@ const runTests = (projectName) => {
3236
}
3337
});
3438

35-
},);
39+
});
3640
}
3741

3842
const runBuild = async (projectName) => {
Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,43 @@
11
import { InputType } from '../../../../../common/enums/InputType';
22
import { PlatformActionData } from '../../../../common/types/Types';
3-
import Logger from '../../../../common/lib/util/Logger';
43

54
export const dataManager = {
65
persistence_id: 's8-data-manager',
76
name: 'Data Manager',
8-
description: 'Send to data manager',
7+
description: 'Construct the data payload to be sent to the specified Data Manager endpoint.',
98
data: [
109
{
1110
key: 'payload',
1211
input_type: InputType.INGEST_ENDPOINT_PAYLOAD_DESIGNER,
13-
description: 'Lorum ipsum',
12+
description: 'Use the above input to help define the payload to be sent.',
1413
optional: false,
1514
},
1615
],
17-
run: (data: PlatformActionData, log: (msg: string) => void): void => {
18-
Logger.info(data.props);
19-
//navigator.sendBeacon('');
16+
run: (
17+
data: PlatformActionData,
18+
log: (msg: string) => void,
19+
err: (msg: string) => void,
20+
): void => {
21+
const config = JSON.parse(data.props.payload);
22+
const payload: { [k: string]: string } = config.payload;
23+
if (typeof payload === 'object') {
24+
const macroReplacedPayload = Object.keys(payload).reduce((previousValue, key) => {
25+
const value = data.macroReplace(payload[key]);
26+
if (value !== undefined) {
27+
previousValue[key] = value;
28+
} else {
29+
log(`Skipping payload value for ${key} as it is undefined`);
30+
}
31+
return previousValue;
32+
}, {} as { [k: string]: string });
33+
navigator.sendBeacon(
34+
`${config.endpoint}`,
35+
new Blob([JSON.stringify(macroReplacedPayload)], {
36+
type: 'application/json',
37+
}),
38+
);
39+
} else {
40+
err('No payload has been defined');
41+
}
2042
},
2143
};

0 commit comments

Comments
 (0)