Cannot get gitHub API to work in javascript. Specifically gitdata.getCommit - javascript

var GitHubApi = require("github");
var github = new GitHubApi({
// required
version: "3.0.0",
// optional
debug: true,
protocol: "https",
host: "github.com",
//pathPrefix: "/joyent/node", // for some GHEs
timeout: 5000
});
github.gitdata.getCommit({
user: "bnoordhuis",
repo: "/joyent/node",
sha: "c30cc4e3a5ead3ca5b48e8eec445740775888ed8"
}, function(err, res) {
console.log(JSON.stringify(res));
});
I posted the code above. I found a random branch in github for testing. I also found a random user as well as that user's commit randomly. I read information about the API here: http://mikedeboer.github.io/node-github/#gitdata.prototype.getCommit
When I run the code above, I get error code 404, null bnoordhuis
undefined
Any help would be awesome! I am a noob to using github api.
Here is the repo I am trying to use: https://github.com/joyent/node/

Your repository should just be 'node'. Joyent is the user.

Related

node-oracledb TNS:listener does not currently know of service requested in connect descriptor

I recently moved from on prem DBs where I used Oracle 11g to Cloud where I needed to connect to Oracle 12c. My nodejs app worked okay on prem but in the cloud, threw the error below
error: ORA-12514: TNS:listener does not currently know of service requested in connect descriptor
Below is the code snippet that my app was using.
oracledb.createPool({
user: config.DB_USER,
password: config.DB_PASS,
connectString: config.DB_HOST + ':' +
config.DB_PORT + '/' +
config.DB_NAME,
poolMin: 20,
poolIncrement: 0,
poolMax: 20
}
After searching around and trying multiple options including swapping : with / nothing seemed to work. I finally managed to get a working solution and I have answered this question below. I hope it helps someone
For whoever is receiving this error while using oracledb package in NodeJS, this is how I fix the issue.
Before, I used this code below, which was producing this error:
ORA-12514: TNS:listener does not currently know of service requested in connect descriptor
//Old Code Which was producing the error
connection = await oracledb.getConnection({
user: "YOUR_USER_NAME_HERE",
password: "YOUR_PASSWORD_HERE",
connectString: "YOUR_DB_IP_HERE:YOUR_DB_PORT_HERE/YOUR_SERVICE_NAME_HERE"
});
Then, after that, I found out that we need to change the value of connectString to give more details. Use the below code:
//NEW Code After fixing
connection = await oracledb.getConnection({
user: "YOUR_USER_NAME_HERE",
password: "YOUR_PASSWORD_HERE",
connectString:"(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=YOUR_DB_IP_HERE"+")(Port=YOUR_DB_PORT_HERE"+"))(CONNECT_DATA=(SID=YOUR_SERVICE_NAME_HERE"+")))",
});
And then the issue got fixed!.
The solution to this problem was changing the connection string as shown in the code snippet below
oracledb.createPool({
user: config.DB_USER,
password: config.DB_PASS,
connectString:"(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host="+config.DB_HOST+")(Port="+config.DB_PORT+"))(CONNECT_DATA=(SID="+config.DB_NAME+")))",
poolMin: 20,
poolIncrement: 0,
poolMax: 20
},

How to use credentials to work with nodegit.push on Windows

Edit: I'm changing the question to suit my current understanding of the problem which has changed significantly.
Original Title: Nodegit seems to be asking for wrong credentials on push
When trying to push using nodegit nothing seems to work on Windows (while they work fine on Linux).
Using SSH
sshKeyFromAgent - error authenticating: failed connecting agent
sshKeyNew - credentials callback is repeatedly (looks like an infinite loop
but I can't be sure)
sshKeyMemoryNew: credentials is called twice and then node exits with no diagnostic (the exit and beforeExit events on process aren't signalled)
Using HTTPS
userpassPlaintextNew: [Error: unknown certificate check failure] errno: -17
Original question follows.
I'm trying to get nodegit to push and the following question seems to address this situation. However I'm not able to get it to work.
I've cloned a repository using SSH and when I try to push, my credentials callback is being called with user git and not motti (which is the actual git user).
try {
const remote = await repository.getRemote("origin");
await remote.push(["refs/head/master:refs/heads/master"], {
callbacks: {
credentials: (url, user) => {
console.log(`Push asked for credentials for '${user}' on ${url}`);
return git.Cred.sshKeyFromAgent(user);
}
}
});
}
catch(err) {
console.log("Error:", err);
}
I get the following output:
Push asked for credentials for 'git' on git#github.[redacted].net:motti/tmp.git
Error: { Error: error authenticating: failed connecting agent errno: -1, errorFunction: 'Remote.push' }
If I try to hardcode motti to the sshKeyFromAgent function the error changes to:
Error: { Error: username does not match previous request errno: -1, errorFunction: 'Remote.push' }
This my first time trying to programmatically use git so I may be missing something basic...
Answer for some questions from comments:
I'm running on windows 10
node v8.9.4
git version 2.15.0.windows.1
nodegit version 0.24.1
the user running node is my primary user which when I use for git in command line works correctly
Instead of using git.Cred.sshKeyFromAgent - you could use git.Cred.sshKeyNew and pass your username / keys along.
const fs = require('fs');
// ...
const username = "git";
const publickey = fs.readFileSync("PATH TO PUBLIC KEY").toString();
const privatekey = fs.readFileSync("PATH TO PRIVATE KEY").toString();
const passphrase = "YOUR PASSPHRASE IF THE KEY HAS ONE";
const cred = await Git.Cred.sshKeyMemoryNew(username, publickey, privatekey, passphrase);
const remote = await repository.getRemote("origin");
await remote.push(["refs/head/master:refs/heads/master"], {
callbacks: {
credentials: (url, user) => cred
}
});
You need to run an ssh agent locally and save your password there. Follow these steps to make it work:
Enable the ssh agent locally (automatically runs on OS X): https://code.visualstudio.com/docs/remote/troubleshooting#_setting-up-the-ssh-agent
Run 'ssh-add' in the same CLI as you're running your nodegit actions and enter your passphrase
I hope this helps because I also struggled a lot with it and it can be very frustrating.

JavaScript file looks OK to me but getting a syntax error

When I run my coffeescript test application I get this error"
2018-12-06 02:19:24,681 <NodeTest> [ERROR] [MainThread] node_test.run - NodeJS test for Node v7.9.0 did not pass. Exit status: 1
Std Out:
Std Error: /opt/node_js/conf.js:25
osVersion: 'MyOS 1.10.1.21
^^^^^^^^^^^^^^^^^
SyntaxError: Invalid or unexpected token
This is the contents of conf.js:
const require('https');
module.exports = {
// Endpoint
endpoint: 'https://123.456.789.876',
// creds
access: 'accessblablabla',
secret: 'secret blablabla',
// Other options
s3BucketEndpoint: false,
s3ForcePathStyle: true,
httpOptions: {
agent: new https.Agent({ca: '-----BEGIN CERTIFICATE-----'})
},
// OS version
myOsVersion: 'MyOS 1.10.1.21'
}
I can't understand why myOsVersion: '%s is any different compared with anything else in the file. Can anybody spot what I'm doing wrong?
I do not use MacOS at all but from my view, I think you should declare:
const https = require('https');
At the top of your code, because I see you use the instance of this (the new keyword). Hope this can help you a bit!
It turns out the problem was the space in the string.
As with #phix's comment, if I manually create the file there is no issue. I have a Python application which generates it. Perhaps it's including some hidden character or something.
Anyway, I only need the version number from the string so edited my Python code to look like this:
version = std_out.split()[1]

Node JS VPN connect to endpoint

I hope you can help!
I have setup and Amazon echo applcation, the application makes a request to and AWS EC2 instance and gets JSON data as a response, this is working as expected however the use case for the final application is to connect to a private IP sending paramaters to an API to return the same JSON DATA.
for many reasons sadly I cannot share any of the endpoint information.
I need my NODE.js Application to make a request to the private IP over a VPN connection, Im currently using OPENVPN to make local requests to the endpoint.
I have looked at node packages to see if this is possible but I cannot seem to find one, except for this package here
https://www.npmjs.com/package/node-openvpn
This package is has a dependancy thats fails to download, so i got the node_module manually but Im getting an error when i try to execute the code
var openvpnmanager = require('node-openvpn');
var opts = {
host: 'xx.xx.xx.xx', // normally '127.0.0.1', will default to if undefined
port: 443, //port openvpn management console
timeout: 1500, //timeout for connection - optional, will default to 1500ms if undefined
logpath: 'log.txt' //optional write openvpn console output to file, can be relative path or absolute
};
var auth = {
user: '*******',
pass: '*******',
};
var openvpn = openvpnmanager.connect(opts)
openvpn.on('connected', function() { //will be emited on successful interfacing with openvpn instance
openvpnmanager.authorize(auth);
});
openvpn.on('console-output', function(output) { //emits console output of openvpn instance as a line
console.log(output)
});
openvpn.on('state-change', function(state) { //emits console output of openvpn state as a array
console.log(output)
});
// openvpnmanager.getLog(console.log) //get all console logs up to this point
// and finally when/if you want to
// openvpnmanager.disconnect();
openvpn.on('disconnected', function() { //emits on disconnect
openvpnmanager.destroy() //finally destroy the disconnected manager
});
this just gives me an error
Unhandled rejection TypeError: Cannot read property 'writable' of undefined
at Telnet.exec (C:\Users\user\Desktop\alexa- po\node_modules\node-openvpn\node_modules\telnet-client\lib\telnet- client.js:90:24)
If anybody has any suggetions on how to make this possible I would be very grateful.

Configuring mqttConnect Options in Meteor for CloudMQTT

I'm trying to use the Meteor package perak:meteor-mqtt-collection to connect to CloudMQTT, but am unsure about how to interpret the syntax for the mqttConnect function:
Collection.mqttConnect(uri, topics, options, mqttOptions)
"where mqttOptions is an object that is supplied to mqtt.connect([url],options) in the MQTT.js library for configuring the underlying options of the MQTT.js-client. See the docs."
So far my Meteor test-code looks like this:
Goals = new Meteor.Collection('dbGoals');
if (Meteor.isClient) {
Goals.insert({
topic: "goals",
message: "Hello world from Meteor Web Client",
broadcast: true
});
}
if (Meteor.isServer) {
Meteor.startup(function () {
Goals.mqttConnect("m10.cloudmqtt.com", ["goals"], {
insert: true,
raw: true
},
{ servers: [{ host: 'm10.cloudmqtt.com', port: 12310 }],
clientId:"uniqueIdforEachMqttClient",
username: "myMqttUserName",
password: "myMqttUserPass",
clean:false
});
And gets the following error:
C:\Users\user\AppData\Local\.meteor\packages\meteor-tool\1.1.10\mt-os.windows.x86_32\dev_bundle\server-lib\node_modules\fibers\future.js:245
throw(ex);
^
TypeError: Cannot call method 'replace' of null
at Object.connect (C:\Users\user\AppData\Local\.meteor\packages\perak_mqtt-collection\1.0.4\npm\node_modules\mqtt\lib\connect\index.js:62:35)
at [object Object].Mongo.Collection.mqttConnect (packages/perak_mqtt-collection/packages/perak_mqtt-collection.js:37:1)
at E:\Data\Projects\Project2016\design\sw\mqttColl\.meteor\local\build\programs\server\boot.js:249:5
at mqttColl.js:25:11
=> Exited with code: 8
=> Your application is crashing.
The line mqttColl.js:25:11 is:
Goals.mqttConnect("m10.cloudmqtt.com", "goals", {
I know the object with my servers: options works with MQTT.js running on Node and CloudMQTT, but I'm not sure that I've got the mqttConnect() function parameters entered correctly for the perak Meteor package. For starters, it seems unlikely that the MQTT broker's URL would be needed in multiple places nor that the topic goals should be in brackets, but I'm just not clear on the parameter syntax.
Any suggestions?
You should add protocol into the URL: mqtt://m10.cloudmqtt.com.

Categories

Resources