34c83be2667a539700b62e25711da23a1448b21d
3 * Copyright 2016 RIFT.IO Inc
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 // DescriptorModelMeta API (NSD + VNFD)
22 var rp
= require('request-promise');
23 var Promise
= require('promise');
24 var constants
= require('../../api_utils/constants');
25 var utils
= require('../../api_utils/utils');
26 var _
= require('lodash');
27 var cors
= require('cors');
28 var bodyParser
= require('body-parser');
29 var utils
= require('../../api_utils/utils');
30 var configuration
= require('./configuration');
32 var router
= require('express').Router();
35 router
.use(bodyParser
.json());
37 router
.use(bodyParser
.urlencoded({
41 router
.get('/schema', cors(), function (req
, res
) {
42 getSchema(req
).then(function (response
) {
43 utils
.sendSuccessResponse(response
, res
);
45 utils
.sendErrorResponse(error
, res
);
50 getRouter: function () {
56 getSchema = function (req
) {
57 var schemaURI
= configuration
.getBackendURL() + '/api/schema/';
58 var schemaPaths
= req
.query
['request'];
59 var paths
= schemaPaths
.split(',');
61 function getSchemaRequest(path
) {
63 uri
: schemaURI
+ path
,
65 headers
: _
.extend({}, constants
.HTTP_HEADERS
.accept
.collection
, {
66 'Authorization': req
.session
&& req
.session
.authorization
68 forever
: constants
.FOREVER_ON
,
69 rejectUnauthorized
: false,
70 resolveWithFullResponse
: true
74 var requests
= _
.map(paths
, getSchemaRequest
);
76 return new Promise(function (resolve
, reject
) {
77 Promise
.all(requests
).then(
82 _
.forEach(results
, function (result
, index
) {
83 data
.schema
[paths
[index
]] = JSON
.parse(result
.body
);
87 statusCode
: constants
.HTTP_RESPONSE_CODES
.SUCCESS
.OK
92 console
.log('Problem with schema.get', error
);
93 response
.statusCode
= error
.statusCode
|| 500;
94 response
.errorMessage
= {
95 error
: 'Failed to get schema' + error