mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Add v2 /flows api and deploy-overwrite protection
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright 2014, 2015 IBM Corp.
|
||||
* Copyright 2014, 2016 IBM Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -25,13 +25,23 @@ module.exports = {
|
||||
log = runtime.log;
|
||||
},
|
||||
get: function(req,res) {
|
||||
log.audit({event: "flows.get"},req);
|
||||
res.json(redNodes.getFlows());
|
||||
var version = req.get("Node-RED-API-Version")||"v1";
|
||||
if (version === "v1") {
|
||||
log.audit({event: "flows.get",version:"v1"},req);
|
||||
res.json(redNodes.getFlows().flows);
|
||||
} else if (version === "v2") {
|
||||
log.audit({event: "flows.get",version:"v2"},req);
|
||||
res.json(redNodes.getFlows());
|
||||
} else {
|
||||
log.audit({event: "flows.get",version:version,error:"bad_api_version"},req);
|
||||
res.status(400).json({error:"bad_api_version"});
|
||||
}
|
||||
},
|
||||
post: function(req,res) {
|
||||
var version = req.get("Node-RED-API-Version")||"v1";
|
||||
var flows = req.body;
|
||||
var deploymentType = req.get("Node-RED-Deployment-Type")||"full";
|
||||
log.audit({event: "flows.set",type:deploymentType},req);
|
||||
log.audit({event: "flows.set",type:deploymentType,version:version},req);
|
||||
if (deploymentType === 'reload') {
|
||||
redNodes.loadFlows().then(function() {
|
||||
res.status(204).end();
|
||||
@@ -41,8 +51,28 @@ module.exports = {
|
||||
res.status(500).json({error:"unexpected_error", message:err.message});
|
||||
});
|
||||
} else {
|
||||
redNodes.setFlows(flows,deploymentType).then(function() {
|
||||
res.status(204).end();
|
||||
var flowConfig = flows;
|
||||
if (version === "v2") {
|
||||
flowConfig = flows.flows;
|
||||
if (flows.hasOwnProperty('rev')) {
|
||||
var currentVersion = redNodes.getFlows().rev;
|
||||
if (currentVersion !== flows.rev) {
|
||||
//TODO: log warning
|
||||
return res.status(409).json({error:"version_mismatch"});
|
||||
}
|
||||
}
|
||||
} else if (version !== 'v1') {
|
||||
log.audit({event: "flows.set",version:version,error:"bad_api_version"},req);
|
||||
return res.status(400).json({error:"bad_api_version"});
|
||||
}
|
||||
redNodes.setFlows(flowConfig,deploymentType).then(function(flowId) {
|
||||
if (version === "v1") {
|
||||
res.status(204).end();
|
||||
} else if (version === "v2") {
|
||||
res.json({rev:flowId});
|
||||
} else {
|
||||
// TODO: invalid version
|
||||
}
|
||||
}).otherwise(function(err) {
|
||||
log.warn(log._("api.flows.error-save",{message:err.message}));
|
||||
log.warn(err.stack);
|
||||
|
@@ -121,12 +121,15 @@
|
||||
"confirm": {
|
||||
"button": {
|
||||
"confirm": "Confirm deploy",
|
||||
"cancel": "Cancel"
|
||||
"review": "Review differences",
|
||||
"cancel": "Cancel",
|
||||
"merge": "Merge changes"
|
||||
},
|
||||
"undeployedChanges": "You have undeployed changes.\n\nLeaving this page will lose these changes.",
|
||||
"improperlyConfigured": "The workspace contains some nodes that are not properly configured:",
|
||||
"unknown": "The workspace contains some unknown node types:",
|
||||
"confirm": "Are you sure you want to deploy?"
|
||||
"confirm": "Are you sure you want to deploy?",
|
||||
"conflict": "The server is running a more recent set of flows."
|
||||
}
|
||||
},
|
||||
"subflow": {
|
||||
|
Reference in New Issue
Block a user