Hi,
I am trying to call curl command in nodejs proxy in Apigee to add API Proxy to custom role but I am getting error:
Here is the code:
var http = require('http'); var util = require('util'); var exec = require('child_process').exec; var output; var command; var child; var express = require('express'); var app = express(); var access = require('apigee-access'); var password= 'XXX'; console.log('node.js application starting...'); app.get('/', function (req, resp) { console.log(req.method, req.url); resp.setHeader("Content-Type", "application/json"); resp.setHeader('Access-Control-Allow-Origin','*'); resp.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE'); resp.setHeader('Access-Control-Allow-Headers', 'Content-Type,Access-Control-Allow-Origin'); resp.setHeader('Access-Control-Expose-Headers','*'); resp.setHeader('Access-Control-Allow-Credentials', true); var apiproxy =req.query.apiName; var custom_role =req.query.role; console.log('API PROXY NAME:' + apiproxy); console.log('ROLE:' + custom_role); command = 'curl -X POST --header "Content-Type: application/json" -d "{\\\"resourcePermission\\\" : [ {\\\"path\\\" : \\\"/applications/'+apiproxy+'\\\",\\\"permissions\\\" : [ \\\"get\\\",\\\"put\\\", \\\"delete\\\" ]}]}" "https://api.enterprise.apigee.com/v1/organizations/XXX/userroles/'+custom_role+'/resourcepermissions" -u email:password'; console.log('COMMAND:' + command); child = exec(command, function(error, stdout, stderr) { output=stdout; console.log('OUTPUT: ' + stdout); if(error !== null) { output=stderr; console.log('ERROR: ' + error); } }); resp.end("OUTPUT:" + output); }); //Create Server app.listen(3000);
The curl command works fine on console. The same nodejs works fine if it is a stand alone app. I am not sure what is wrong but I am getting this error:
EPERM
That means Operation not permitted.
This is the URL: https://XXX-dev.apigee.net/et-ia-automationrole?newAPI_role=XXX≠wAPI_apiName=XXX
you can't do that from within a nodejs target. you cannot create new processes.
You can try a "hosted target". That uses "real" nodejs. There are fewer restrictions for what you can do at runtime.
I was using HostedTarget previously but that feature has bugs.
User | Count |
---|---|
3 | |
2 | |
1 | |
1 | |
1 |