EAI_AGAIN error while making SMTP connection in Loopback - email

datasource.json:
"emailDs": {
"name": "emailDs",
"connector": "mail",
"transports": [{
"type": "smtp",
"host": "smtp.myapp.in",
"secure": true,
"secureConnection": true,
"port": 587,
"tls": {
"rejectUnauthorized": false
},
"auth": {
"user": "name#myapp.in",
"pass": "pwd"
}
}]
}
model-config.json
"Email": {
"dataSource": "emailDs"
}
mymodel.js (Extends default loopbacl's user model)
var options = {
type: 'email',
to: myUser.email,
from: 'name#myapp.in',
subject: 'Thanks for registering.',
template: path.resolve(__dirname, '../../server/views/verify.ejs'),
redirect: '/verified',
entrepreneur: entrepreneur
};
myUser.verify(options, function(err, response) {
if (err) {
next(err);
return;
}
When I am creating new user, this afterRemote 'create' code is running but while sending mail it is giving following error:
{
"error": {
"name": "Error",
"status": 500,
"message": "getaddrinfo EAI_AGAIN",
"code": "EAI_AGAIN",
"errno": "EAI_AGAIN",
"syscall": "getaddrinfo",
"hostname": "smtp.myapp.in",
"stack": "Error: getaddrinfo EAI_AGAIN\n at Object.exports._errnoException (util.js:746:11)\n at errnoException (dns.js:49:15)\n at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:94:26)"
}
}
I have created a new domain in Bigrock and using the free email service provided by them. Please suggest what am I doing wrong here.

Related

OTP Verification using API in swift and mvvm method

I have a sign-in, sign-up and forgot password field. I need to verify the login with a 2fa code. How do I verify this using MVVM method.
here's my API and parameters.
Send OTP:
{
"email": "string",
"phoneNumber": "string",
"callingCode": "string",
"otpType": 1
}
Response:
{
"data": {
"otp": "968785",
"status": true
},
"success": true,
"successCode": 1009,
"httpstatusCode": 200,
"developerMessage": "Please use this code for verification ",
"userMessage": "Please use this one-time code for verification",
"header": "Alert"
}
Verify OTP Request:
{
"email": "string",
"otp": "string"
}
response
{
"data": {
"status": true
},
"success": true,
"successCode": 1010,
"httpstatusCode": 200,
"developerMessage": "Account has been verified successfully",
"userMessage": "Account verified",
"header": "Alert"
}

Cypress Connecting to postgres database issue

running into a issue using cypress-postgres connecting to the database. Server has multiple databases along with multiple schemas. Tried multiple plugins, but can find a solution that will allow me to specify a particular schema in a database. Server is reachable over the vpn.
Will need to do this with sql database. Any help, better method suggestions welcomed.
Thank You! - Michael Frazier
IE: Database Example.
Error that is returned
no relation for home
Package.json has following dependencies:
name": "tests",
"version": "1.0.0",
"description": "Automated Tests",
"main": "index.js",
"scripts": {
"cypress:open": "cypress open",
"test": "cypress open"
},
"repository": {
"type": "git",
"url":
},
"author": "Michael Frazier
"license": "ISC",
"dependencies": {
"#testing-library/cypress": "^8.0.2",
"#testing-library/vue": "^5.8.2",
"#vue/test-utils": "^1.3.0",
"cypress-commands": "^2.0.1",
"cypress-downloadfile": "^1.2.1",
"cypress-postgres": "^1.1.1",
"cypress-postgresql": "^1.0.8",
"cypress-real-events": "^1.6.0",
"pg": "^8.7.1",
"pg-promise": "^10.5.8",
"yarn": "^1.22.17"
},
"devDependencies": {
"#4tw/cypress-drag-drop": "^2.1.0",
"#babel/core": "^7.15.0",
"#babel/preset-env": "^7.15.0",
"#cypress/skip-test": "^2.6.1",
"#cypress/webpack-preprocessor": "^5.9.1",
"#testing-library/dom": "^8.11.2",
"#types/chai": "^4.2.21",
"#types/jest": "^27.0.1",
"#types/mocha": "^9.0.0",
"cy-mobile-commands": "^0.3.0",
"cypress": "^9.5.3",
"cypress-file-upload": "^5.0.8",
"cypress-fill-command": "^1.0.2",
"cypress-iframe": "^1.0.1",
"cypress-mailosaur": "^2.6.0",
"cypress-mochawesome-reporter": "^2.4.0",
"cypress-msteams-reporter": "^1.0.3",
"cypress-plugin-tab": "^1.0.5",
"cypress-wait-until": "^1.7.2",
"dayjs": "^1.10.6",
"faker": "^5.5.3",
"mysql": "^2.18.1",
"pdf-parse": "^1.1.1",
"webpack": "^5.51.1"
}
}
Cypress.json has DB credentials in following format:
{
"trashAssetsBeforeRuns": true,
"responseTimeout": 30000,
"requestTimeout": 50000,
"defaultCommandTimeout": 4000,
"experimentalSourceRewriting": true,
"experimentalStudio": true,
"projectId": "aycmk8",
"reporter": "cypress-mochawesome-reporter",
"reporterOptions": {
"reportDir": "cypress/report",
"charts": true,
"reportPageTitle": "Melos Report"
},
"db":
{"user": "postgres",
"host": "",
"database": "",
"password": "",
"schemas": "sct",
"port": 5432
}
}
Plugin in cypress\plugins\index.js file:
module.exports = async (on, config) => {
on('task',
{dbQuery: (query)=> require('cypress-postgres')(query.query,query.connection)})
Spec file has following test:
describe("Database Health Tests", function () {
it('should ping the database to ensure its active ', function () {
cy.task("dbQuery", {"query":"select * from home"})
});
Your dbQuery is missing the connection string:
cy.task("dbQuery",
{
query: "select * from home",
connection: "your connection string"
})
If you focusing on description of cypress-postgres in npm, they provided 2-ways to use :
The first way : load your database connection via cypress.json by require('cypress-postgres').
The seconds way : set your database connection by yourself in cy.task.
The first way
This way may make you mistake, the example shows unclear parameter to you :
// In cypress\plugins\index.js
module.exports = on => {
on("task", {
dbQuery:(query)=> require("cypress-postgres")(query.query,query.connection)
});
};
I'm not sure query.connection come from. If you access to the dependency, you will see :
// In require('cypress-postgres')
const pgp = require('pg-promise')();
const postgressConfig = require(require('path').resolve('cypress.json'));
module.exports = function(query,userDefineConnection) {
let connection = postgressConfig.db
if (userDefineConnection!=undefined){
connection=userDefineConnection
}
const db = pgp(connection);
return db.any(query)
}
So you can change query.connection to your variable.
Normally, module in cypress\plugins\index.js received 2-arguments on and config. The config will refer to cypress.json, you can get your database connection via config.env.db :
{
"env": {
"db": {
"user": "postgres",
"host": "localhost",
"database": "postgres",
"password": "mysecretpassword",
"port":5432
}
}
}
Now cypress\plugins\index.js should be :
module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
on("task", {
dbQuery: (query) => require("cypress-postgres")(query.query, config.env.db)
})
}
In your *.spec.js :
// ...
it('set "Y" to db', () => {
cy.task("dbQuery", { "query": "select count(*) as num_row from home"
}).then(result => {
expect(result[0].num_row).to.equal('1')
})
})
// ...
The seconds way
This way assign database connection directly in your *.spec.js :
// ...
it('set "Y" to db', () => {
cy.task("dbQuery", {
"query": "select count(*) as num_row from home",
"connection": {
"user": "postgres",
"host": "localhost",
"database": "postgres",
"password": "mysecretpassword",
"port":5432
}
}).then(result => {
expect(result[0].num_row).to.equal('1')
})
})
// ...

Hyperledger Explorer starting fails with database authentication

I'm facing an issue when trying to bring up the Hyperledger Explorer app. I followed instructions stated in here but I'm still unsuccessful on trying to bring up the app.
My config.json file looks like this:
{
"network-configs": {
"network-1": {
"version": "1.0",
"clients": {
"client-1": {
"tlsEnable": true,
"organization": "Org1MSP",
"channel": "mychannel",
"credentialStore": {
"path": "./tmp/credentialStore_Org1/credential",
"cryptoStore": {
"path": "./tmp/credentialStore_Org1/crypto"
}
}
}
},
"channels": {
"mychannel": {
"peers": {
"peer0.org1.example.com": {}
},
"connection": {
"timeout": {
"peer": {
"endorser": "6000",
"eventHub": "6000",
"eventReg": "6000"
}
}
}
}
},
"certificateAuthorities":{
"ca_peerOrg1":{},
"ca_peerOrg2":{}
},
"organizations": {
"Org1MSP": {
"mspid": "Org1MSP",
"fullpath": false,
"adminPrivateKey": {
"path": "/home/rodolfo/fabric-sample-with-kafka/first-network/crypto-config/peerOrganizations/org1.example.com/users/Admin#org1.example.com/msp/keystore"
},
"signedCert": {
"path": "/home/rodolfo/fabric-sample-with-kafka/first-network/crypto-config/peerOrganizations/org1.example.com/users/Admin#org1.example.com/msp/signcerts"
},
"certificateAuthorities": {
"ca_peerOrg1":{
"url":"grpcs://localhost:7054"
}
}
},
"Org2MSP": {
"mspid": "Org2MSP",
"adminPrivateKey": {
"path": "/home/rodolfo/fabric-sample-with-kafka/first-network/crypto-config/peerOrganizations/org2.example.com/users/Admin#org2.example.com/msp/keystore"
},
"certificateAuthorities": {
"ca_peerOrg2":{
"url":"grpcs://localhost:8054"
}
}
},
"OrdererMSP": {
"mspid": "OrdererMSP",
"adminPrivateKey": {
"path": "/home/rodolfo/fabric-sample-with-kafka/first-network/crypto-config/ordererOrganizations/example.com/users/Admin#example.com/msp/keystore"
}
}
},
"peers": {
"peer0.org1.example.com": {
"tlsCACerts": {
"path": "/home/rodolfo/fabric-sample-with-kafka/first-network/crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt"
},
"url": "grpcs://localhost:7051",
"eventUrl": "grpcs://localhost:7053",
"grpcOptions": {
"ssl-target-name-override": "peer0.org1.example.com"
}
},
"peer1.org1.example.com": {
"url": "grpcs://localhost:8051"
},
"peer0.org2.example.com": {
"url": "grpcs://localhost:9051"
},
"peer1.org2.example.com": {
"url": "grpcs://localhost:10051"
}
},
"orderers": {
"orderer0.example.com": {
"url": "grpcs://localhost:7050"
},
"orderer1.example.com": {
"url": "grpcs://localhost:8050"
}
}
},
"network-2": {}
},
"configtxgenToolPath": "/home/rodolfo/fabric-sample-with-kafka/bin",
"license": "Apache-2.0"
}
My explorerconfig.json file:
{
"persistence": "postgreSQL",
"platforms": ["fabric"],
"postgreSQL": {
"host": "127.0.0.1",
"port": "5432",
"database": "fabricexplorer",
"username": "rodolfo",
"passwd": ""
},
"sync": {
"type": "local",
"platform": "fabric",
"blocksSyncTime": "3"
}
}
The errors I'm getting in the logs are:
postgres://rodolfo:#127.0.0.1:5432/fabricexplorer
error when connecting to db: { error: password authentication failed
for user "rodolfo"...
<<<<<<<<<<<<<<<<<<<<<<<<<< Explorer Error >>>>>>>>>>>>>>>>>>>>>
TypeError: Cannot read property 'port' of undefined
at Timeout.handleDisconnect [as _onTimeout] (/home/rodolfo/blockchain-
explorer/app/persistence/postgreSQL/pgservice.js:48:32)
at ontimeout (timers.js:475:11)
at tryOnTimeout (timers.js:310:5)
at Timer.listOnTimeout (timers.js:270:5)
Please open web browser to access :http://localhost:8080/
pid is 10774
TypeError: Cannot read property 'port' of undefined
at Timeout.handleDisconnect [as _onTimeout] (/home/rodolfo/blockchain-
explorer/app/persistence/postgreSQL/pgservice.js:48:32)
at ontimeout (timers.js:475:11)
at tryOnTimeout (timers.js:310:5)
at Timer.listOnTimeout (timers.js:270:5)
<<<<<<<<<<<<<<<<<<<<<<<<<< Closing client processor
>>>>>>>>>>>>>>>>>>>>>
Already tried changing the password for my user on PSQL and modify it on the explorerconfig.json but same error shows up. Tried using blank password and still error shows. Any guidance would be greatly appreciated.

Problems to POST chaincode (smart contract) to hyperledger-fabric using API

I've deployed the hyperledger-fabric service on Bluemix and obtained the credentials from there, one line looks like this:
{"enrollId":"user_type1_0","enrollSecret":"XXXXX","group":"group1","affiliation":"0001","username":"user_type1_0","secret":"XXXXX"}
I post the following to the "registrar" REST endpoint:
Secret: { "enrollId": "user_type1_0", "enrollSecret": "xxxxx" }
I get this response:
{ "OK": "Login successful for user 'user_type1_0'." }
Then I try to register some chaincode using POSTing the following to the chaincode REST endpoint:
QuerySpec {
"jsonrpc": "2.0",
"method": "deploy",
"params": {
"type": 1,
"chaincodeID": {
"path": "https://github.com/ibm-blockchain/learn-chaincode/finished"
},
"ctorMsg": {
"function": "init",
"args": [
"hi there"
]
},
"secureContext": "user_type1_0_xxxxx"
},
"id": 1 }
I get this reponse:
{ "jsonrpc": "2.0", "error": {
"code": -32000,
"message": "Registration missing",
"data": "User not logged in. Use the '/registrar' endpoint to obtain a security token." }, "id": 1 }
Any idea?
Fabric expects that you will provide EnrolmentID as a security context but you are trying to use "ID+Pass".
Can you try to run your deploy command with another SecurityContext value ?
QuerySpec { "jsonrpc": "2.0", "method": "deploy", "params": { "type": 1, "chaincodeID": { "path": "https://github.com/ibm-blockchain/learn-chaincode/finished" }, "ctorMsg": { "function": "init", "args": [ "hi there" ] }, "secureContext": "user_type1_0" }, "id": 1 }

how to access postgresql database view using strongloop

Please help in accessing postgresql database view using strongloop.
im able to access table
{"name": "test",
"options": {
"idInjection": false,
"postgresql": {
"schema": "public",
"table": "test_data_v"
}
},
"properties": {
"assetid": {
"type": "String",
"required": false,
"length": 40,
"precision": null,
"scale": null,
"id": 1,
"postgresql": {
"columnName": "asset_id",
"dataType": "character varying",
"dataLength": 40,
"dataPrecision": null,
"dataScale": null,
"nullable": "YES"
}
}
}}
in same way please suggest me how to access view
Thanks
Divya
I am not installed postgresql but I tried in mysql, Its working fine.
IN your model you can do directly see this Example
In database I have created view that is
CREATE VIEW shareviews AS
SELECT id,name
FROM share where id = 1;
In model you can call viewname directly like this example
module.exports = function(Share) {
var server = require('../../server/server');
var ds = server.dataSources.MySQL; // use server.dataSources.postgres;
Share.list = function(optionalparam, cb) {
var sql = 'select * from shareviews';
ds.connector.execute(sql, function(err, data)
{
if(err) return err;
console.log(err);
console.log("data",data);
cb(null, data);
});
}
Share.remoteMethod(
'list',
{
accepts: {arg: 'param', type: 'string'},
returns: {arg: 'result', type: 'object'},
http: {path: '/list', verb: 'get'}
}
);
};
You need to set data source in datasource.json
{
"db": {
"name": "db",
"connector": "memory"
},
"postgres": {
"host": "localhost",
"port": 5432,
"database": "postgres",
"username": "postgres",
"password": "*******",
"name": "postgres",
"connector": "postgresql"
}
}
Then in model-config.json you need to assign data source name to each
model.
That is
{
"_meta": {
"sources": [
"loopback/common/models",
"loopback/server/models",
"../common/models",
"./models"
],
"mixins": [
"loopback/common/mixins",
"loopback/server/mixins",
"../common/mixins",
"./mixins"
]
},
"User": {
"dataSource": "db"
},
"AccessToken": {
"dataSource": "db",
"public": false
},
"ACL": {
"dataSource": "db",
"public": false
},
"RoleMapping": {
"dataSource": "db",
"public": false
},
"Role": {
"dataSource": "db",
"public": false
},
"yourmodelname": {
"dataSource": "postgres",
"public": true
},
"yourmodelname": {
"dataSource": "postgres",
"public": true
}
}
then you can access database in you model.js or Rest call(example localhost:3000/explorer) For Example my
model name Grocerylist
module.exports = function(Grocerylist) {
Grocerylist.beforeRemote('create', function(context, user, next) {
var req = context.req;
req.body.date = Date.now();
req.body.shopperId = req.accessToken.userId;
next();
});
Grocerylist.complete = function(shopperId, cb) {
Grocerylist.find({
where: {
purchased:false,
shopperId: shopperId,
}
}, function(err, list) {
var response;
if (typeof list === 'undefined' || list.length === 0) {
response = "All done shopping!"
}
else {
response = "Shopping is not done.";
}
cb(null, response);
});
};
Grocerylist.remoteMethod(
'complete',
{
accepts: {
arg: 'shopperId', type: 'string'
},
http: {
path: '/complete',
verb: 'get'
},
returns: {
arg: 'complete',
type: 'string'
}
}
);
};