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)
21 var ProjectManagement
= {};
22 var Promise
= require('bluebird');
23 var rp
= require('request-promise');
24 var Promise
= require('promise');
25 var constants
= require('../../api_utils/constants');
26 var utils
= require('../../api_utils/utils');
27 var _
= require('lodash');
29 ProjectManagement
.get = function(req
) {
31 var api_server
= req
.query
['api_server'];
33 return new Promise(function(resolve
, reject
) {
36 uri
: utils
.confdPort(api_server
) + '/api/operational/project',
38 headers
: _
.extend({}, constants
.HTTP_HEADERS
.accept
.data
, {
39 'Authorization': req
.session
&& req
.session
.authorization
41 forever
: constants
.FOREVER_ON
,
42 rejectUnauthorized
: false,
43 resolveWithFullResponse
: true
45 ]).then(function(result
) {
47 response
['data'] = {};
49 response
['data']['project'] = JSON
.parse(result
[0].body
)['rw-project:project'];
51 response
.statusCode
= constants
.HTTP_RESPONSE_CODES
.SUCCESS
.OK
54 }).catch(function(error
) {
56 console
.log('Problem with ProjectManagement.get', error
);
57 response
.statusCode
= error
.statusCode
|| 500;
58 response
.errorMessage
= {
59 error
: 'Failed to get ProjectManagement' + error
65 ProjectManagement
.create = function(req
) {
67 var api_server
= req
.query
['api_server'];
72 return new Promise(function(resolve
, reject
) {
75 uri
: utils
.confdPort(api_server
) + '/api/config/project',
77 headers
: _
.extend({}, constants
.HTTP_HEADERS
.accept
.data
, {
78 'Authorization': req
.session
&& req
.session
.authorization
80 forever
: constants
.FOREVER_ON
,
82 rejectUnauthorized
: false,
83 resolveWithFullResponse
: true
85 ]).then(function(result
) {
87 response
['data'] = {};
89 response
['data'] = result
[0].body
;
91 response
.statusCode
= constants
.HTTP_RESPONSE_CODES
.SUCCESS
.OK
94 }).catch(function(error
) {
96 console
.log('Problem with ProjectManagement.create', error
);
97 response
.statusCode
= error
.statusCode
|| 500;
98 response
.errorMessage
= {
99 error
: 'Failed to create user' + error
105 ProjectManagement
.update = function(req
) {
107 var api_server
= req
.query
['api_server'];
108 var bodyData
= req
.body
;
112 var updateTasks
= [];
114 var updateUser
= rp({
115 uri
: utils
.confdPort(api_server
) + '/api/config/project',
117 headers
: _
.extend({}, constants
.HTTP_HEADERS
.accept
.data
, {
118 'Authorization': req
.session
&& req
.session
.authorization
120 forever
: constants
.FOREVER_ON
,
122 rejectUnauthorized
: false,
123 resolveWithFullResponse
: true
125 updateTasks
.push(updateUser
)
126 return new Promise(function(resolve
, reject
) {
129 ]).then(function(result
) {
131 response
['data'] = {};
132 if (result
[0].body
) {
133 response
['data'] = result
[0].body
;
135 response
.statusCode
= constants
.HTTP_RESPONSE_CODES
.SUCCESS
.OK
138 }).catch(function(error
) {
140 console
.log('Problem with ProjectManagement.update', error
);
141 response
.statusCode
= error
.statusCode
|| 500;
142 response
.errorMessage
= {
143 error
: 'Failed to passwordChange user' + error
150 ProjectManagement
.delete = function(req
) {
152 var projectname
= req
.params
.projectname
;
153 var api_server
= req
.query
["api_server"];
154 var requestHeaders
= {};
155 var url
= `${utils.confdPort(api_server)}/api/config/project/${projectname}`
156 return new Promise(function(resolve
, reject
) {
157 _
.extend(requestHeaders
,
158 constants
.HTTP_HEADERS
.accept
.data
,
159 constants
.HTTP_HEADERS
.content_type
.data
, {
160 'Authorization': req
.session
&& req
.session
.authorization
165 headers
: requestHeaders
,
166 forever
: constants
.FOREVER_ON
,
167 rejectUnauthorized
: false,
168 }, function(error
, response
, body
) {
169 if (utils
.validateResponse('ProjectManagement.DELETE', error
, response
, body
, resolve
, reject
)) {
171 statusCode
: response
.statusCode
,
172 data
: JSON
.stringify(response
.body
)
178 module
.exports
= ProjectManagement
;