forked from apigee/apigeelint
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction.js
More file actions
123 lines (108 loc) · 3.01 KB
/
Copy pathfunction.js
File metadata and controls
123 lines (108 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/**
* Responds to any HTTP request that can provide a "message" field in the body.
*
* @param {!Object} req Cloud Function request context.
* @param {!Object} res Cloud Function response context.
*
* gcloud beta functions deploy lints --trigger-http --stage-bucket lintresults --memory 2048
*/
exports.lints = function lintResults(req, res) {
const util = require("util");
var customer,
org,
api,
revision,
authorization = req.get("Authorization"),
formatter;
if (req.method === "GET") {
customer = req.query.customer;
org = req.query.org;
api = req.query.api;
revision = req.query.revision;
formatter = req.query.formatter;
} else if (req.method === "POST") {
customer = req.body.customer;
org = req.body.organization;
api = req.body.api;
revision = req.body.revision;
formatter = req.body.formatter;
}
//interpret the accepts header if the formatter was not explicitly supplied
if (!formatter) {
if (req.accepts("json")) {
formatter = "json.js";
} else if (req.accepts("xml")) {
formatter = "jslint-xml.js";
} else if (req.accepts("text")) {
formatter = "unix.js";
} else {
formatter = "html.js";
}
}
if (!org && customer) {
//populate from the customer if supplied
var str = '';
var options = {
host: 'nucleus-api-test.apigee.com',
path: '/sfdc/account_orgs'
};
var callback = function(response) {
response.on('data', function (chunk) {
str += chunk;
});
response.on('end', function () {
console.log(str);
//str contains the payload from the account_orgs - parse to get the orgs to lint
res.send(str); // SEND ACTUAL RESPONSE HERE
});
}
var req = http.request(options, callback);
req.end();
}else{
}
if (!org || !api || !revision || !req.get("Authorization")) {
// This is an error case, as "message" is required.
res
.status(400)
.send(
"org(" +
org +
"), api(" +
api +
"), and revision(" +
revision +
") are required parameters and authorization header is required"
);
} else {
// Everything is okay.
const configuration = {
source: {
type: "ManagementServer",
org,
api,
revision,
authorization
},
output: function(report) {
if (req.query.debug) {
console.log(report);
}
},
apiUpload: {
destPath: "https://csdata-test.apigee.net/v1/lintresults",
authorization,
organization: org
},
formatter
};
var bl = require("./lib/package/bundleLinter.js");
bl.lint(configuration, function(result, err) {
if (err) {
console.log(util.inspect(err, { showHidden: false, depth: 3 }));
res.status(err.status).send(err.message);
} else {
res.status(200).send(result.apiUploadResponse);
}
});
}
};