Programmatically create issue in Mantis - node.js

I am writing small node.js script that will run multiple command & if any one fails, it will report an issue on the mentis. I am using following code to report issue in mantis bugtracker. Mantis bug tracker comes with an bunch of SOAP api to do stuffs like this. http://www.mantisbt.org/bugs/api/soap/mantisconnect.php?wsdl#op.idp90022480
var soap = require('soap');
var url = 'http://localhost/mantisbt-1.2.19/api/soap/mantisconnect.php?wsdl';
var user = 'administrator';
var password = 'root';
var args = {
username: user,
password: password,
project: {
id: 1
},
category: 'General',
summary: 'Test summary',
description: 'test description'
};
soap.createClient(url, function(err, client) {
client.mc_issue_add(args, function(err1, result) {
if(err1)
console.log( err1 );
else
console.log('Issue successfully created');
});
});
But I am getting following error log:
<faultstring>Project \'\' does not exist.</faultstring>
I have a project with id 1, & I can create an issue with same data using php. My understanding is project id is not being send properly. Equivalent php code is as follow.
$c = new SoapClientDebug("http://localhost/mantisbt-1.2.19/api/soap/mantisconnect.php?wsdl", ['trace' => true]);
$username = 'administrator';
$password = 'root';
$issue = array (
'summary' => 'PHP test issue',
'description' => 'PHP test description',
'project'=> array(
'id'=>1
),
'category'=>'General',
);
$c->mc_issue_add($username, $password, $issue);
The php code is functional.

Your args should be like this:
var args = {
username: user,
password: password,
issue: {
project: {
id: 1
},
category: 'General',
summary: 'Test summary',
description: 'test description'
}
};

Related

Not able to get the value of a custom attribute in hyperledger-fabric using cid.getAttributeValue function

Other than the 3 attributes hf.EnrollmentId, hf.type and hf.Affiliation, I've created a custom attribute named email and added it as attrs:[{name: 'email', value: rahul18#gmail.com, ecert: true}] and it was successfully added to the attribute list.
In my chaincode, i'm able to get the enrollmentId by using the following command : cid.GetAttributeValue(ctx.GetStub(), "hf.EnrollmentID") but i'm not able to get the email using the same method cid.GetAttributeValue(ctx.GetStub(), "email")
Any help would be appreciated regarding why the first one is working and the second isn't
Does getAttributeValue not support custom made attributes?
Here is an example that may be helpful. A previous stackoverflow contribution helped me with a similar situation. I don't have the link for it right now, but thanks anyway.
First of all, you state that you have added attributes successfully. Here is some code as an example which I had placed in the code file for registering users.
//create user attr array
let registerAttrs = [];
let registerAttribute = {
name: "recycler",
value: config.recycler,
ecert: true,
};
registerAttrs.push(registerAttribute);
const secret = await ca.register({
affiliation: config.affiliation,
enrollmentID: config.recycler,
role: "client",
attrs: registerAttrs,
},
adminUser
);
The contract code is able to find the value of "recycler" using the following code. Of particular importance is the getCurrentUserId() function.
async getCurrentUserId(ctx) {
let id = [];
id.push(ctx.clientIdentity.getID());
var begin = id[0].indexOf("/CN=");
var end = id[0].lastIndexOf("::/C=");
let userid = id[0].substring(begin + 4, end);
return userid;}
async getCurrentUserType(ctx) {
let userid = await this.getCurrentUserId(ctx);
// check user id; if admin, return type = admin;
// else return value set for attribute "type" in certificate;
if (userid == "admin") {
return userid;
}
return ctx.clientIdentity.getAttributeValue(userid);}
The user type returned from the getCurrentUserType function is subsequently examined further up in the contract code, as shown in the following example.
async readTheAsset(ctx, id) {
let userType = await this.getCurrentUserType(ctx);
const buffer = await ctx.stub.getState(id);
const asset = JSON.parse(buffer.toString());
asset.userType = userType;
asset.userID = ctx.clientIdentity.getID();
if (asset.userType === "recycler") {
throw new Error(`The record cannot be read by ${asset.userType} `);
}
return asset;}
I feel sure that this code should solve your issue, as there is a lot of similarity.
const updateObj = {
enrollmentID : userName,
type:'client',
affiliation:'' ,
attrs: [{name: 'email', value: email, ecert: true}, {name: 'orgId', value: orgId, ecert: true}, {name: 'userId', value: userName, ecert: true}] ,
}
const response = await identityService.update(userName, updateObj ,adminUser)
const clientUser = await provider.getUserContext(userIdentity, userName);
const reenrollment = await caClient.reenroll(clientUser,
[{
name: 'email',
optional: false
},
{
name: 'orgId',
optional: false
},
{
name: 'userId',
optional: false
}
]);

Undefined error on simple firebase auth function

Strange issue, I have a function that trigger by Firebase newUser auth
if the user uses Google or Facebook provider the function works but if it email/password signup the function returns an undefined error.
what I'm missing here?
The function code:
exports.newUser = functions.auth.user().onCreate((user) => {
const docRef = admin.firestore().collection('Users').doc(user.uid)
return docRef.set({
email: user.email,
name: '',
photo: '',
signupDate: admin.firestore.FieldValue.serverTimestamp()
},{merge: true});
});
The documentation for the email property of UserRecord suggests that it is not always available. So, you should check for that in your code.
user.email field appears under provider and not like in the Firebase Example directly under user.
here how it should look like:
var email = user.email; // The email of the user.
if (email == undefined) {
for (var provider of user.providerData) {
if (provider.email) {
email = provider.email;
break;
}
}
}
return docRef.set({
email: email,
name: '',
photo: '',
signupDate: admin.firestore.FieldValue.serverTimestamp()
},{merge: true});
});

Generate GUID at runtime without using form in NetSuite

Hye there,
I'm trying to prepare a scheduled script in NetSuite which will pick a particular directory from file cabinet and deploy it on SFTP server. I'm using 2.0 module and here is my code -
require(["N/sftp",'N/record','N/file'], function(sftp,record,file) {
function onRequest() {
var myPwdGuid = "13139ac567b14f74bdaXXXXXXX";
var myHostKey = "AAAAB3NzaC1ycXXXXX";
var connection = sftp.createConnection({
username: 'Your user name',
passwordGuid: myPwdGuid,
url: 'Your host name',
directory: '/directory to upload files/',
hostKey: myHostKey
});
var myFileToUpload = file.create({
name: 'originalname.js',
fileType: file.fileType.PLAINTEXT,
contents: 'I am a test file. Hear me roar.'
});
connection.upload({
directory: 'relative/path/to/remote/dir',
filename: 'newFileNameOnServer.js',
file: myFileToUpload,
replaceExisting: true
});
var downloadedFile = connection.download({
directory: 'relative/path/to/file',
filename: 'downloadMe.js'
});
}
onRequest();
return {
onRequest: onRequest
};
});
Now the issue is when i try to run these lines of code i get an error saying "AN_ERROR_OCCURRED_WHILE_DECRYPT_PASSWORDGUID".
What i've found so far through my research is GUID can only be generated by SuitLet form having credential field which will again require GET and POST method. However i Dont want to create a suitelet and invoke it manually in order to generate GUID. All i want to to do is - Run a scheduled script which will Establish connection to SFTP. Pick a directory in file cabinet and upload it on SFTP.
Any help would be greatly appreciated! Thanks in advance!
Its easier and faster than you might think. Take the below code and load it to NetSuite. Create a script file and deployment quick, run the SUITElet to get your GUID, paste that value into your Scheduled Script and don't mess with it again unless the password changes.
/**
*#NApiVersion 2.x
*#NScriptType Suitelet
*/
define([
'N/ui/serverWidget',
'N/https'
],
function (
ui,
https
) {
var HOST_KEY_TOOL_URL = 'https://ursuscode.com/tools/sshkeyscan.php?url=';
function getFormTemplate() {
var form;
form = ui.createForm({
title: 'Password Form'
});
form.addSubmitButton({
label: 'Submit'
});
return form;
}
function addSelectorFields(form) {
var select = form.addField({
id: 'selectaction',
type: ui.FieldType.SELECT,
label: 'Select Action'
});
select.addSelectOption({
value: 'getpasswordguid',
text: 'Get Password GUID'
});
select.addSelectOption({
value: 'gethostkey',
text: 'Get Host Key'
});
return form;
}
function addPasswordGUID1Fields(form) {
var frm = form;
frm.addField({
id: 'restricttoscriptids',
type: ui.FieldType.TEXT,
label: 'Restrict To Script Ids'
}).isMandatory = true;
frm.addField({
id: 'restricttodomains',
type: ui.FieldType.TEXT,
label: 'Restrict To Domains'
}).isMandatory = true;
return frm;
}
function addPasswordGUID2Fields(form, restrictToScriptIds, restrictToDomains) {
form.addCredentialField({
id: 'password',
label: 'Password',
restrictToScriptIds: restrictToScriptIds.replace(' ', '').split(','),
restrictToDomains: restrictToDomains.replace(' ', '').split(',')
});
return form;
}
function addHostKeyFields(form) {
form.addField({
id: 'url',
type: ui.FieldType.TEXT,
label: 'URL (Required)'
});
form.addField({
id: 'port',
type: ui.FieldType.INTEGER,
label: 'Port (Optional)'
});
form.addField({
id: 'hostkeytype',
type: ui.FieldType.TEXT,
label: 'Type (Optional)'
});
return form;
}
function onRequest(option) {
var method;
var form;
var selectAction;
var port;
var hostKeyType;
var restricttoscriptids;
var restricttodomains;
var password;
var theResponse;
var myUrl;
var url;
method = option.request.method;
form = getFormTemplate(method);
if (method === 'GET') {
form = addSelectorFields(form);
}
if (method === 'POST') {
selectAction = option.request.parameters.selectaction;
if (selectAction === 'getpasswordguid') {
form = addPasswordGUID1Fields(form);
} else if (selectAction === 'gethostkey') {
form = addHostKeyFields(form);
} else {
password = option.request.parameters.password;
url = option.request.parameters.url;
port = option.request.parameters.port;
hostKeyType = option.request.parameters.hostkeytype;
restricttoscriptids = option.request.parameters.restricttoscriptids;
restricttodomains = option.request.parameters.restricttodomains;
if (restricttoscriptids && restricttodomains) {
form = addPasswordGUID2Fields(form, restricttoscriptids, restricttodomains);
}
if (password) {
form.addField({
id: 'passwordguidresponse',
type: ui.FieldType.LONGTEXT,
label: 'PasswordGUID Response',
displayType: ui.FieldDisplayType.INLINE
}).defaultValue = password;
}
if (url) {
myUrl = HOST_KEY_TOOL_URL + url + '&port=' + port + '&type=' + hostKeyType;
theResponse = https.get({ url: myUrl }).body;
form.addField({
id: 'hostkeyresponse',
type: ui.FieldType.LONGTEXT,
label: 'Host Key Response',
displayType: ui.FieldDisplayType.INLINE
}).defaultValue = theResponse;
}
}
}
option.response.writePage(form);
}
return {
onRequest: onRequest
};
});
The ability to directly hard-code an SFTP password is not supported in NetSuite. NetSuite uses password tokenization in order to prevent scripts from having access to user credentials. For this reason, only an authenticated user may store a password, and a script may only access it via an identifier (GUID/Token).

Node.JS cradle and couchDB assistance

I am a noob with Node.JS.
I am using CouchDB and Cradle.
In couchDB I have a database named 'test' and inside it I have a document named 'exercise'.
The document has 2 fields: "FullName" and "Age".
The code in order to save the data is as follows:
var cradle = require('cradle');
var connection = new(cradle.Connection)('http://127.0.0.1', 5984, {
auth: { username: 'toto_finish', password: 'password' }
});
var db = connection.database('test');
db.save('exercise', {
FullName: param_name, Age: param_age
}, function (err, res) {
if (err) {
// Handle error
response += ' SAVE ERROR: Could not save record!!\n';
} else {
// Handle success
response += ' SUCESSFUL SAVE: The record was saved in CouchDB!\n';
}
http_res.end(response);
});
this code works well and it saves the data to the CouchDB.
My problem is when I want to read the data.
The code that I wrote is:
var cradle = require('cradle');
var connection = new(cradle.Connection)('http://127.0.0.1', 5984, {
auth: { username: 'toto_finish', password: 'password' }
});
var db = connection.database('test');
db.view('exercise/all', {descending: true}, function(err, res)
{
console.log(res);
res.forEach(function (row) {
response = 'FullName: ' + row.FullName + '\n Age: ' + row.Age + '\n';
});
});
http_res.end(response);
when I am trying to print response, response is empty and I don't know what I am doing wrong. I know that it does not go inside the forEach loop but I don't understand why.
the console output is:
[ { id: 'exercise',
key: null,
value:
{ _id: 'exercise',
_rev: '1-7042e6f49a3156d2099e8ccb3cc7d937',
FullName: 'Toto Finish',
Age: '30' } } ]
Thanks in advance for any response or answer.
Try moving the http_res.send() call inside the callback provided to db.view - the anonymous function( err, res ) { }.
I'm not sure however about the .forEach statement, you'll only get the last value from your query in the response variable, you should look into that as well.
spotirca is right
The db.view function is async so http_res.end(response) gets called before the view returns any data.
You can prove this by returning the date in both the console.log and http_res.end
console.log(res, new Date())
and
http_res.end(response, new Date());
The http response will have the earlier date/Time.

Retrieve roster in node-xmpp

I'm having trouble understanding how to retrieve an XMPP roster (and eventually the presence state of each contact) in node-xmpp (GTalk account).
My example code can login and connect, but I'm a bit lost as to what to send and listen for:
var xmpp = require('node-xmpp')
jid = 'example#gmail.com'
password = 'xxxxxxxxxxxxxx'
// Establish a connection
var conn = new xmpp.Client({
jid: jid,
password: password,
host: 'talk.google.com',
port: 5222
})
conn.on('online', function() {
console.log('ONLINE')
var roster = new xmpp.Element('iq', {
type: 'get',
from: jid,
id: new Date().getTime()
}).c('query', { xmlns: 'jabber:iq:roster' })
conn.send(roster) // Now what?
})
conn.on('error', function(e) {
console.log(e)
})
Looks like the structure of my roster query was wrong, this works correctly:
conn.on('online', function() {
console.log('ONLINE')
var roster = new xmpp.Element('iq', {
id: 'roster_0',
type: 'get'
}).c('query', {
xmlns: 'jabber:iq:roster'
})
conn.send(roster)
})

Resources