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.
20 * restconf api module. Provides API functions to interact with RESTCONF
21 * @module framework/core/modules/api/restconf
22 * @author Kiran Kashalkar <kiran.kashalkar@riftio.com>
25 var Promise
= require('bluebird');
26 var constants
= require('../../api_utils/constants');
27 var utils
= require('../../api_utils/utils');
28 var request
= utils
.request
;
30 var _
= require('lodash');
31 restconfAPI
['streams'] = {};
34 * Get the RESTCONF/Netconf streams from the RESTCONF endpoint
35 * @param {Object} req - the Express request object with or without a plugin_id
36 * @return {Function} Promise that resolves with success object or rejects
39 restconfAPI
['streams'].get = function(req
) {
40 var api_server
= req
.query
["api_server"];
41 var uri
= utils
.confdPort(api_server
);
43 return new Promise(function(resolve
, reject
) {
45 url
: uri
+ url
+ '?deep',
47 headers
: _
.extend({}, constants
.HTTP_HEADERS
.accept
.data
, {
48 'Authorization': req
.get('Authorization')
50 forever
: constants
.FOREVER_ON
,
51 rejectUnauthorized
: false,
52 }, function(error
, response
, body
) {
53 if (utils
.validateResponse('restconfAPI.streams', error
, response
, body
, resolve
, reject
)) {
54 // resolve(JSON.parse(response.body))
56 statusCode
: response
.statusCode
,
57 data
: JSON
.parse(response
.body
)
65 module
.exports
= restconfAPI
;