Added minor fix to app generation

This commit is contained in:
frikky
2022-06-28 18:14:02 +02:00
parent b25a216058
commit ab5b35532b
7 changed files with 119 additions and 40 deletions
+23 -3
View File
@@ -2714,6 +2714,8 @@ class AppBase:
if parameter["name"] == "body":
bodyindex = counter
#self.logger.info("PARAM: %s" % parameter)
# FIXMe: This should also happen after liquid & param parsing..
try:
values = parameter["value_replace"]
if values != None:
@@ -2721,16 +2723,24 @@ class AppBase:
for val in values:
replace_value = val["value"]
replace_key = val["key"]
if (val["value"].startswith("{") and val["value"].endswith("}")) or (val["value"].startswith("[") and val["value"].endswith("]")):
self.logger.info(f"""Trying to parse as JSON: {val["value"]}""")
try:
value_replace = json.loads(val["value"])
# If it gets here, remove the "" infront and behind the key as well since this is preventing the JSON from being loaded
newval = val["value"]
# If it gets here, remove the "" infront and behind the key as well
# since this is preventing the JSON from being loaded
tmpvalue = json.loads(newval)
replace_key = f"\"{replace_key}\""
except json.decoder.JSONDecodeError as e:
self.logger.info("Failed JSON replacement for OpenAPI %s", val["key"])
self.logger.info("[WARNING] Failed JSON replacement for OpenAPI %s", val["key"])
elif val["value"].lower() == "true" or val["value"].lower() == "false":
replace_key = f"\"{replace_key}\""
else:
if "\"" in replace_value and not "\\\"" in replace_value:
replace_value = replace_value.replace("\"", "\\\"", -1)
action["parameters"][counter]["value"] = action["parameters"][counter]["value"].replace(replace_key, replace_value, 1)
@@ -2787,6 +2797,9 @@ class AppBase:
"exception": f"Value Error: {check}",
}))
if parameter["name"] == "body":
self.logger.info("[INFO] Should debug field with liquid and other checks as it's BODY: %s" % value)
# Custom format for ${name[0,1,2,...]}$
#submatch = "([${]{2}([0-9a-zA-Z_-]+)(\[.*\])[}$]{2})"
#self.logger.info(f"Returnedvalue: {value}")
@@ -3126,6 +3139,13 @@ class AppBase:
# FIXME: add this to Multi exec as well.
try:
for key, value in params.items():
if "-" in key:
try:
newkey = key.replace("-", "_", -1).lower()
params[newkey] = params[key]
except Exception as e:
self.logger.info("[DEBUG] Failed updating key with dash in it: %s" % e)
try:
if isinstance(value, str) and ((value.startswith("{") and value.endswith("}")) or (value.startswith("[") and value.endswith("]"))):
params[key] = json.loads(value)
+1 -1
View File
@@ -2,7 +2,7 @@
### DEFAULT
NAME=shuffle-app_sdk
VERSION=1.0.2
VERSION=1.0.4
docker rmi docker.pkg.github.com/frikky/shuffle/$NAME:$VERSION --force
docker build . -f Dockerfile -t frikky/shuffle:app_sdk -t frikky/$NAME:$VERSION -t docker.pkg.github.com/frikky/shuffle/$NAME:$VERSION -t ghcr.io/frikky/$NAME:$VERSION -t ghcr.io/frikky/$NAME:nightly
+2 -2
View File
@@ -2,7 +2,7 @@ module main
go 1.16
//replace github.com/shuffle/shuffle-shared => ../../../shuffle-shared
replace github.com/shuffle/shuffle-shared => ../../../shuffle-shared
//replace github.com/frikky/kin-openapi => ../../../../git/kin-openapi
//replace github.com/frikky/go-elasticsearch => ../../../../git/go-elasticsearch
@@ -24,7 +24,7 @@ require (
github.com/h2non/filetype v1.1.3
github.com/nirasan/go-oauth-pkce-code-verifier v0.0.0-20170819232839-0fbfe93532da // indirect
github.com/satori/go.uuid v1.2.0
github.com/shuffle/shuffle-shared v0.2.52
github.com/shuffle/shuffle-shared v0.2.53
go4.org v0.0.0-20201209231011-d4a079459e60 // indirect
golang.org/x/crypto v0.0.0-20220112180741-5e0467b6c7ce
google.golang.org/api v0.65.0
+1 -2
View File
@@ -91,8 +91,7 @@ const WorkflowPaper = (props) => {
}
//console.log("IMG: ", data)
var parsedUrl = `workflows/${data.objectID}`
var parsedUrl = `/workflows/${data.objectID}`
if (data.__queryID !== undefined && data.__queryID !== null) {
parsedUrl += `?queryID=${data.__queryID}`
}
+2 -2
View File
@@ -163,8 +163,8 @@ const data = [
selector: "node[?isSuggestion]",
css: {
shape: "ellipse",
width: "30px",
height: "30px",
width: "50px",
height: "50px",
"z-index": "5002",
"font-size": "0px",
border: "1px solid rgba(255,255,255,0.9)",
+66 -21
View File
@@ -3752,6 +3752,7 @@ const AngularWorkflow = (defaultprops) => {
) {
cy.getElementById(currentNode.data.id).remove();
}
}
}
@@ -3892,7 +3893,7 @@ const AngularWorkflow = (defaultprops) => {
if (parentNode.data("isButton") || parentNode.data("buttonId")) return;
const px = parentNode.position("x") + 300;
const py = parentNode.position("y") + 0;
const py = parentNode.position("y") + 100;
const circleId = (newNodeId = uuidv4());
parentNode.data("circleId", circleId);
@@ -3920,8 +3921,51 @@ const AngularWorkflow = (defaultprops) => {
position: { x: px, y: py },
locked: true,
});
//suggestions[0].id = uuidv4()
//cy.add({
// group: "nodes",
// data: suggestions[0],
// position: { x: parentNode.position("x") + 300, y: parentNode.position("y") - 100},
// locked: true,
//});
}
const addDeleteButton2 = (event) => {
var parentNode = cy.$("#" + event.target.data("id"));
if (parentNode.data("isButton") || parentNode.data("buttonId")) return;
const px = parentNode.position("x") + 100;
const py = parentNode.position("y") + 35;
const circleId = (newNodeId = uuidv4());
parentNode.data("circleId", circleId);
const iconInfo = {
icon: "M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z",
iconColor: buttonColor,
iconBackgroundColor: buttonBackgroundColor,
};
const svg_pin = `<svg width="${svgSize}" height="${svgSize}" viewBox="0 0 ${svgSize} ${svgSize}" version="1.1" xmlns="http://www.w3.org/2000/svg"><path d="${iconInfo.icon}" fill="${iconInfo.iconColor}"></path></svg>`;
const svgpin_Url = encodeURI("data:image/svg+xml;utf-8," + svg_pin);
cy.add({
group: "nodes",
data: {
weight: 30,
id: circleId,
name: "This is autocomplete",
buttonType: "delete",
attachedTo: event.target.data("id"),
icon: svgpin_Url,
iconBackground: iconInfo.iconBackgroundColor,
is_valid: true,
},
position: { x: px, y: py },
locked: true,
});
};
const addDeleteButton = (event) => {
var parentNode = cy.$("#" + event.target.data("id"));
if (parentNode.data("isButton") || parentNode.data("buttonId")) return;
@@ -3981,12 +4025,19 @@ const AngularWorkflow = (defaultprops) => {
for (var key in allNodes) {
const currentNode = allNodes[key];
if (
currentNode.data.isButton &&
(currentNode.data.isButton || currentNode.data.isSuggestion) &&
currentNode.data.attachedTo !== nodedata.id
) {
cy.getElementById(currentNode.data.id).remove();
}
/*if (
currentNode.data.isSuggestion &&
currentNode.data.attachedTo !== nodedata.id
) {
cy.getElementById(currentNode.data.id).remove();
}*/
if (
currentNode.data.isButton &&
currentNode.data.attachedTo === nodedata.id
@@ -4007,7 +4058,10 @@ const AngularWorkflow = (defaultprops) => {
addStartnodeButton(event);
}
//addSuggestionButtons(event)
// autocomplete
// right click
// suggestions
//addSuggestionButtons(event);
}
}
@@ -5037,7 +5091,7 @@ const AngularWorkflow = (defaultprops) => {
var thisview = (
<AppView
allApps={apps}
extraApps={ExtraApps}
extraApps={[]}
prioritizedApps={prioritizedApps}
filteredApps={filteredApps}
/>
@@ -5825,15 +5879,10 @@ const AngularWorkflow = (defaultprops) => {
if (value.length > 0) {
var newApps = allApps.filter(
(app) =>
app.name
.toLowerCase()
.includes(
value.trim().toLowerCase() ||
app.description
.toLowerCase()
.includes(value.trim().toLowerCase())
) && !(!app.activated && app.generated)
);
app.name.toLowerCase().includes(value.trim().toLowerCase())
||
app.description.toLowerCase().includes(value.trim().toLowerCase())
)
// Extend search
if (newApps.length === 0) {
@@ -6914,7 +6963,7 @@ const AngularWorkflow = (defaultprops) => {
>
contains any of
</MenuItem>
<MenuItem
{/*<MenuItem
style={menuItemStyle}
onClick={(e) => {
conditionValue.value = "matches regex";
@@ -6924,7 +6973,7 @@ const AngularWorkflow = (defaultprops) => {
key={"matches regex"}
>
matches regex
</MenuItem>
</MenuItem>*/}
<MenuItem
style={menuItemStyle}
onClick={(e) => {
@@ -10665,11 +10714,7 @@ const AngularWorkflow = (defaultprops) => {
};
const BottomCytoscapeBar = () => {
if (
workflow.id === undefined ||
workflow.id === null ||
apps.length === 0
) {
if (workflow.id === undefined || workflow.id === null || (!workflow.public && apps.length === 0)) {
return null;
}
@@ -11333,7 +11378,7 @@ const AngularWorkflow = (defaultprops) => {
</div>
: null}
{userdata.avatar === creatorProfile.github_avatar ?
{userdata.avatar === creatorProfile.github_avatar && userdata.avatar !== undefined ?
<div style={{marginTop: 50, }}>
<Button
color="primary"
+24 -9
View File
@@ -1421,14 +1421,15 @@ const AppCreator = (defaultprops) => {
//console.log("SECURITYSCHEMES: ", securitySchemes)
if (securitySchemes !== undefined) {
console.log("NEWAUTH: ", securitySchemes)
var valueset = false
// FIXME: Should add Oauth2 (Microsoft) and JWT (Wazuh)
//console.log("SECURITY: ", securitySchemes)
//if (Object.entries(securitySchemes) > 1 &&
var newauth = [];
try {
var optionset = false
for (const [key, value] of Object.entries(securitySchemes)) {
console.log(key, value);
if (key === "jwt") {
setAuthenticationOption("JWT");
setAuthenticationRequired(true);
@@ -1439,19 +1440,21 @@ const AppCreator = (defaultprops) => {
value.in.length > 0
) {
setParameterName(value.in);
optionset = true
}
} else if (value.scheme === "bearer") {
setAuthenticationOption("Bearer auth");
setAuthenticationRequired(true);
optionset = true
} else if (key === "ApiKeyAuth" || key === "Token" || ((value.in === "header" || value.in === "query") && value.name !== undefined)) {
if (authenticationOption === "" || authenticationOption === "No authentication") {
setAuthenticationOption("API key");
}
//if (optionset === false) {
// optionset = true
//}
if (valueset === false) {
valueset = true
if (optionset === false) {
optionset = true
value.in = value.in.charAt(0).toUpperCase() + value.in.slice(1)
setParameterLocation(value.in);
@@ -1461,8 +1464,16 @@ const AppCreator = (defaultprops) => {
}
console.log("PARAM NAME: ", value.name);
setAuthenticationOption("API key");
setParameterName(value.name);
setAuthenticationRequired(true);
newauth.push({
"name": key,
"type": value.in.toLowerCase(),
"in": value.in.toLowerCase(),
"example": "",
})
} else {
newauth.push({
"name": key,
@@ -1482,15 +1493,18 @@ const AppCreator = (defaultprops) => {
} else if (value.scheme === "basic") {
setAuthenticationOption("Basic auth");
setAuthenticationRequired(true);
optionset = true
} else if (value.scheme === "oauth2") {
setAuthenticationOption("Oauth2");
setAuthenticationRequired(true);
optionset = true
} else if (value.type === "oauth2" || key === "Oauth2" || key === "Oauth2c" || (key !== undefined && key !== null && key.toLowerCase().includes("oauth2"))) {
//alert.info("Can't handle Oauth2 auth yet.")
setAuthenticationOption("Oauth2");
setAuthenticationRequired(true);
optionset = true
//console.log("FLOW-1: ", value)
const flowkey = value.flow === undefined ? "flows" : "flow";
@@ -1573,6 +1587,7 @@ const AppCreator = (defaultprops) => {
}
if (newauth.length > 0) {
newauth = newauth.filter(data => data.name != "ApiKeyAuth")
setExtraAuth(newauth);
}
}
@@ -1645,9 +1660,9 @@ const AppCreator = (defaultprops) => {
data.info["contact"] = basedata.info.contact;
} else if (contact === "") {
data.info["contact"] = {
name: "@frikkylikeme",
url: "https://twitter.com/frikkylikeme",
email: "frikky@shuffler.io",
name: "@shuffle_platform",
url: "https://twitter.com/shuffleio",
email: "support@shuffler.io",
};
} else {
data.info["contact"] = contact;