Skip to content

Instantly share code, notes, and snippets.

@huskercane
Created January 28, 2016 20:42
Show Gist options
  • Save huskercane/091e0324be3d36d30b81 to your computer and use it in GitHub Desktop.
Save huskercane/091e0324be3d36d30b81 to your computer and use it in GitHub Desktop.
const http = require ('https')
var options = {
host: '127.0.0.1',
port: 443,
path: '/admin/resources/fix_packs',
// path: '/admin/resources/change_plans',
auth: 'admin:admin',
method: 'GET',
headers: {
'X-IBM-Workload-Deployer-API-Version': '5.0',
'X-IBM-PureSystem-API-Version': '2.1'
}
};
// ignore certs
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
var cookie;
function get (map, key) {
// mmap = JSON.parse(map)
// return mmap[key]
return map[key]
}
http.request(options, function(res) {
console.log('STATUS: ' + res.statusCode);
// console.log('Headers: ' + JSON.stringify(res.headers));
// console.log(res.headers)
// console.log(res.headers['set-cookie'])
cookie = get(res.headers, "set-cookie")
// console.log(cookie);
res.setEncoding('utf8');
res.on('data', function(chunk) {
// console.log('BODY: ' + chunk);
response = JSON.parse(chunk);
if (cookie) {
cookie = (cookie + "").split(";").shift();
// set(opts.headers, "Cookie", cookie)
options['Cookie'] = cookie;
}
response.forEach(function(value){
// set cookie
// change path to id
options['path'] = value['id'];
options['method'] = 'DELETE';
// send delete
console.log(options);
http.request(options, function(delRes){
console.log('Delete STATUS: ' + delRes.statusCode);
}, function(err){
console.log(err);
});
});
}
);
}).end();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment