Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit 699a576

Browse files
Merge branch 'master' into fixes/934-inspector-disabled
2 parents 84c543f + 4e09bfc commit 699a576

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1739
-411
lines changed

octorun/bin/octorun-meta

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env node
2+
3+
require('../src/bin/app-meta.js');

octorun/bin/octorun-token

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env node
2+
3+
require('../src/bin/app-token.js');

octorun/src/api.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
var config = require("./configuration");
22
var octokitWrapper = require("./octokit");
33

4-
function ApiWrapper() {
4+
function ApiWrapper(host) {
55
if (!config.appName) {
66
throw "appName missing";
77
}
@@ -10,7 +10,7 @@ function ApiWrapper() {
1010
throw "token missing";
1111
}
1212

13-
this.octokit = octokitWrapper.createOctokit(config.appName);
13+
this.octokit = octokitWrapper.createOctokit(config.appName, host);
1414

1515
this.octokit.authenticate({
1616
type: "oauth",

octorun/src/authentication.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var twoFactorRegex = new RegExp("must specify two-factor authentication otp code
55

66
var scopes = ["user", "repo"];
77

8-
var handleAuthentication = function (username, password, onSuccess, onFailure, twoFactor) {
8+
var handleAuthentication = function (username, password, onSuccess, onFailure, twoFactor, host) {
99
if (!config.clientId || !config.clientSecret) {
1010
throw "clientId and/or clientSecret missing";
1111
}
@@ -14,7 +14,7 @@ var handleAuthentication = function (username, password, onSuccess, onFailure, t
1414
throw "appName missing";
1515
}
1616

17-
var octokit = octokitWrapper.createOctokit(config.appName);
17+
var octokit = octokitWrapper.createOctokit(config.appName, host);
1818

1919
octokit.authenticate({
2020
type: "basic",

octorun/src/bin/app-login.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ var output = require('../output');
66
commander
77
.version(package.version)
88
.option('-t, --twoFactor')
9+
.option('-h, --host <host>')
910
.parse(process.argv);
1011

1112
var handleAuthentication = function (username, password, twoFactor) {
@@ -18,7 +19,7 @@ var handleAuthentication = function (username, password, twoFactor) {
1819
}
1920
}, function (error) {
2021
output.error(error);
21-
}, twoFactor);
22+
}, twoFactor, commander.host);
2223
}
2324

2425
var encoding = 'utf-8';

octorun/src/bin/app-meta.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
var commander = require('commander');
2+
var package = require('../../package.json');
3+
var output = require('../output');
4+
5+
commander
6+
.version(package.version)
7+
.option('-h, --host <host>')
8+
.parse(process.argv);
9+
10+
var host = commander.host;
11+
var port = 443;
12+
var scheme = 'https';
13+
14+
if (host) {
15+
var https = require(scheme);
16+
var options = {
17+
protocol: scheme + ':',
18+
hostname: host,
19+
port: port,
20+
path: '/api/v3/meta',
21+
method: 'GET',
22+
headers: {
23+
'Content-Type': 'application/json'
24+
}
25+
};
26+
27+
var req = https.request(options, function (res) {
28+
var success = res.statusCode == 200;
29+
30+
if(!success) {
31+
output.error(res.statusCode);
32+
} else {
33+
res.on('data', function (d) {
34+
output.custom("success", d, true);
35+
});
36+
37+
res.on('end', function (d) {
38+
process.exit();
39+
});
40+
}
41+
});
42+
43+
req.on('error', function (error) {
44+
output.error(error);
45+
});
46+
47+
req.end();
48+
}
49+
else {
50+
commander.help();
51+
process.exit(-1);
52+
}

octorun/src/bin/app-organizations.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ var output = require('../output');
55

66
commander
77
.version(package.version)
8+
.option('-h, --host <host>')
89
.parse(process.argv);
910

1011
try {
11-
12-
var apiWrapper = new ApiWrapper();
12+
var apiWrapper = new ApiWrapper(commander.host);
1313
apiWrapper.getOrgs(function (error, result) {
1414
if (error) {
1515
output.error(error);

octorun/src/bin/app-publish.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ commander
99
.option('-d, --description <description>')
1010
.option('-o, --organization <organization>')
1111
.option('-p, --private')
12+
.option('-h, --host <host>')
1213
.parse(process.argv);
1314

1415
if(!commander.repository)
@@ -23,7 +24,7 @@ if (commander.private) {
2324
}
2425

2526
try {
26-
var apiWrapper = new ApiWrapper();
27+
var apiWrapper = new ApiWrapper(commander.host);
2728

2829
apiWrapper.publish(commander.repository, commander.description, private, commander.organization,
2930
function (error, result) {

octorun/src/bin/app-token.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
2+
var commander = require('commander');
3+
var package = require('../../package.json');
4+
var output = require('../output');
5+
var config = require("../configuration");
6+
var querystring = require('querystring');
7+
8+
commander
9+
.version(package.version)
10+
.option('-h, --host <host>')
11+
.parse(process.argv);
12+
13+
var host = commander.host;
14+
var port = 443;
15+
var scheme = 'https';
16+
17+
var valid = host && config.clientId && config.clientSecret && config.token;
18+
if (valid) {
19+
var https = require(scheme);
20+
21+
var postData = querystring.stringify({
22+
client_id: config.clientId,
23+
client_secret: config.clientSecret,
24+
code: config.token
25+
});
26+
27+
var options = {
28+
protocol: scheme + ':',
29+
hostname: host,
30+
port: port,
31+
path: '/login/oauth/access_token',
32+
method: 'POST',
33+
headers: {
34+
'Content-Type': 'application/x-www-form-urlencoded',
35+
'Content-Length': postData.length
36+
}
37+
};
38+
39+
var req = https.request(options, function (res) {
40+
var success = res.statusCode == 200;
41+
42+
if(!success) {
43+
output.error(res.statusCode);
44+
} else {
45+
res.on('data', function (d) {
46+
output.custom("success", d, true);
47+
});
48+
49+
res.on('end', function (d) {
50+
process.exit();
51+
});
52+
}
53+
});
54+
55+
req.on('error', function (error) {
56+
output.error(error);
57+
});
58+
59+
req.write(postData);
60+
61+
req.end();
62+
}
63+
else {
64+
commander.help();
65+
process.exit(-1);
66+
}

octorun/src/bin/app-validate.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ var output = require('../output');
55

66
commander
77
.version(package.version)
8+
.option('-h, --host <host>')
89
.parse(process.argv);
910

1011
try {
11-
var apiWrapper = new ApiWrapper();
12+
var apiWrapper = new ApiWrapper(commander.host);
1213

1314
apiWrapper.verifyUser(function (error, result) {
1415
if (error) {

octorun/src/bin/app.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@ commander
99
.command('organizations', 'Get Organizations')
1010
.command('publish', 'Publish')
1111
.command('usage', 'Usage')
12+
.command('token', 'Create OAuth Token')
13+
.command('meta', 'Get Server Meta Data')
1214
.parse(process.argv);

octorun/src/octokit.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
var Octokit = require('octokit-rest-for-node-v0.12');
22

3-
var createOctokit = function (appName) {
4-
return Octokit({
3+
var createOctokit = function (appName, host) {
4+
var octokitConfiguration = {
55
timeout: 0,
66
requestMedia: 'application/vnd.github.v3+json',
77
headers: {
88
'user-agent': appName
99
}
10-
});
10+
};
11+
12+
if (host) {
13+
octokitConfiguration.host = host;
14+
octokitConfiguration.pathPrefix = 'api/v3';
15+
}
16+
17+
return Octokit(octokitConfiguration);
1118
};
1219

1320
module.exports = { createOctokit: createOctokit };

octorun/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
902910f4
1+
902910f48

script

0 commit comments

Comments
 (0)