Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
exports.start = function(options, cb) {
var url = UPLOAD_SERVER + '?uploadID=' + options.file_id;
// Make a call to get the last byte processed by the upload server
// in order to resume the upload from that position.
needle.request('get', url, null, function(err, res) {
if (err) {
console.log(err);
return;
}
if (res.statusCode == 404) {
files.del(options.file_id);
return;
}
var data = JSON.parse(res.body);
var file_status = JSON.parse(res.body).Status
options.total = data.Total;
if (file_status == 0 || file_status == 4) { // File in progress(0) or Pending(4)
files.exist(options.file_id, function(err, exist) {
if (!exist) {
options.resumable = false;
function retrieve_file(file, cb) {
if (file.resumable == 'true') {
console.log("Resumable file:", file.id);
var url = UPLOAD_SERVER + '?uploadID=' + file.id;
// Make a call to get the last byte processed by the upload server
// in order to resume the upload from that position.
needle.request('get', url, null, function(err, res) {
if (err) {
console.log(err);
cb(err);
return;
}
var data = JSON.parse(res.body);
file.total = data.Total;
get_file(file, cb);
})
return;
}
get_file(file, cb);
}
exports.request = function request(method, url, data, opts, cb) {
needle.request(method, url, data, opts, function(err, resp) {
if (err) hooks.trigger('error', err);
// hooks.trigger('response', err, resp, data);
cb && cb(err, resp);
})
}
if(self.config.network.port != null)
{
fullUrl = fullUrl + ":" + self.config.network.port;
}
fullUrl = fullUrl + "/about";
var needle = require('needle');
if(self.config.debug.check_connection_output)
{
console.log("Checking connection to Dendro Recommender instance at: " + fullUrl);
}
needle.request("get",
fullUrl,
null,
{
accept: "application/json"
},
function(err, response, body)
{
if(!err)
{
if(body.result == "ok" && body.message == "Dendro Recommender Online")
{
if(self.config.debug.check_connection_output)
{
console.log("SUCCESS connecting to Dendro Recommender instance at: " + fullUrl);
}
server.log([blueWazuh, 'Wazuh agents monitoring', 'error'], 'You must provide a max size');
}
var payload = {
'offset': offset ? offset : 0,
'limit': (250 < maxSize) ? 250 : maxSize
};
var options = {
headers: { 'wazuh-app-version': appVersion },
username: apiEntry.user,
password: apiEntry.password,
rejectUnauthorized: !apiEntry.insecure
};
needle.request('get', getPath(apiEntry) + '/agents', payload, options, function (error, response) {
if (!error && !response.error && response.body.data.items) {
agentsArray = agentsArray.concat(response.body.data.items);
if ((payload.limit + payload.offset) < maxSize) {
checkStatus(apiEntry, response.body.data.totalItems, payload.limit + payload.offset);
} else {
saveStatus();
}
} else {
server.log([blueWazuh, 'Wazuh agents monitoring', 'error'], 'Can not access Wazuh API');
return;
}
});
};
authenticate(options, (err, accessToken) => {
if (err) {
return next(err);
}
const queryString = {
fileUri: options.fileUri
};
const reqDetails = {
headers: { Authorization: `Bearer ${accessToken}` }
};
needle.request('get', `${BASE_URL}/files-api/v2/projects/${options.projectId}/file/status`, queryString, reqDetails, (err, response, body) => {
const status = _.get(body, 'response.data');
if (err || !status || response.statusCode !== 200) {
return next(new Error(`Error when retrieving translation status for ${options.fileUri}`));
}
next(null, status);
});
});
},
var deferred = Q.defer();
var options = jQuery.extend({ compressed: true }, options);
if (options.dataType === 'json')
{
options.json = true;
}
if (options.dataType === 'multipart')
{
options.multipart = true;
}
needle.request(options.type, options.url, options.data, options, function (error, response, body)
{
if (error || response.statusCode !== 200)
{
deferred.reject(body);
}
else
{
deferred.resolve(body);
}
});
return deferred.promise;
};
export function request (method: INeedleMethod, uri: string, data: any, options: any,
callback: INeedleCallback): INeedleRequest {
if (isOffline()) { return closeConnection(callback); }
return needle.request(method, uri, data, withProxy(options), callback);
}
var deferred = Q.defer();
var options = jQuery.extend({ compressed: true }, options);
if (options.dataType === 'json')
{
options.json = true;
}
if (options.dataType === 'multipart')
{
options.multipart = true;
}
needle.request(options.type, options.url, options.data, options, function (error, response, body)
{
if (error || response.statusCode !== 200)
{
deferred.reject(body);
}
else
{
deferred.resolve(body);
}
});
return deferred.promise;
};