Skip to content

Commit d4ceb0c

Browse files
author
Panagis Tselentis
committed
ref
1 parent 474f7a6 commit d4ceb0c

File tree

13 files changed

+259
-219
lines changed

13 files changed

+259
-219
lines changed

api/base/KongController.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
'use strict';
2-
var KongService = require('../services/KongService')
32

3+
var KongService = require('../services/KongService')
4+
var unirest = require("unirest")
45

56
module.exports = {
7+
68
create : function(req,res) {
79
return KongService.create(req,res)
810
},

api/controllers/ApiController.js renamed to api/controllers/KongProxyController.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* ApiController
2+
* RemoteApiController
33
*/
44

55
var unirest = require("unirest")
@@ -14,8 +14,7 @@ module.exports = {
1414
*/
1515
proxy : function(req,res) {
1616

17-
18-
req.url = req.url.replace('/api','') // Remove the /api prefix
17+
req.url = req.url.replace('/kong','') // Remove the /api prefix
1918

2019
sails.log("req.url",req.url)
2120

api/controllers/SettingsController.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ var _ = require('lodash');
1010
*/
1111
module.exports = _.merge(_.cloneDeep(require('../base/Controller')), {
1212

13-
initial : function(req,res) {
13+
find : function(req,res) {
1414

1515
// ToDo cache settings to memory
1616
//if(sails.KONGA_CONFIG) {

assets/js/app/apis/add-api-plugin-modal-controller.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,20 @@
111111
fetchPlugins()
112112
})
113113

114+
function getApiPlugins() {
115+
ApiService.plugins($scope.api.id)
116+
.then(function(response){
117+
$scope.existingPlugins = response.data.data.map(function(item){
118+
return item.name
119+
})
120+
})
121+
.catch(function(err){
122+
123+
})
124+
}
125+
114126

127+
getApiPlugins();
115128

116129
}
117130
])

assets/js/app/apis/add-api-plugin-modal.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,20 @@ <h4><i class="material-icons pull-left">{{group.icon}}</i>&nbsp;{{group.name}}</
3131
</div>
3232

3333
<div class="col-md-4" data-ng-repeat="(key,value) in group.plugins">
34-
<div class="panel panel-default" iln-match-height>
34+
<div class="panel"
35+
ng-class="{'panel-success' : existingPlugins.indexOf(key) > -1, 'panel-default' : existingPlugins.indexOf(key) <0}"
36+
iln-match-height>
3537
<div class="panel-heading">
3638
<div class="panel-title">
3739
<span class="capitalize">{{key.split('-').join(" ")}}</span>
3840
<div class="pull-right">
3941
<button
42+
data-ng-if="existingPlugins.indexOf(key) < 0"
4043
class="btn btn-primary btn-link btn-icon"
4144
angular-ripple data-ng-click="onAddPlugin(key)">
4245
<i class="material-icons">add</i>
4346
</button>
47+
<i class="mdi mdi-check-all" data-ng-if="existingPlugins.indexOf(key) > -1"></i>
4448
</div>
4549
</div>
4650
</div>

assets/js/app/core/models/DataModel.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646

4747
// Subscribe to specified endpoint
4848
if (endpoint) {
49-
this.endpoint = endpoint;
49+
this.endpoint = 'api/' + endpoint;
5050

5151
this._subscribe();
5252
} else {

assets/js/app/plugins/add-plugin-controller.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88

99
angular.module('frontend.plugins')
1010
.controller('AddPluginController', [
11-
'_','$scope','$rootScope','$log','$state','ListConfig',
11+
'_','$scope','$rootScope','$log','$state','ListConfig','ApiService',
1212
'MessageService','ConsumerModel','SocketHelperService','PluginHelperService',
1313
'KongPluginsService','$uibModalInstance','PluginsService','_pluginName','_schema','_api',
14-
function controller(_,$scope,$rootScope,$log,$state,ListConfig,
14+
function controller(_,$scope,$rootScope,$log,$state,ListConfig,ApiService,
1515
MessageService,ConsumerModel,SocketHelperService,PluginHelperService,
1616
KongPluginsService,$uibModalInstance,PluginsService,_pluginName,_schema,_api ) {
1717

@@ -120,10 +120,20 @@
120120
$scope.busy = false;
121121
$log.error("create plugin",err)
122122
var errors = {}
123-
Object.keys(err.data.customMessage).forEach(function(key){
124-
errors[key.replace('config.','')] = err.data.customMessage[key]
125-
MessageService.error(key + " : " + err.data.customMessage[key])
126-
})
123+
124+
if(err.data.customMessage) {
125+
Object.keys(err.data.customMessage).forEach(function(key){
126+
errors[key.replace('config.','')] = err.data.customMessage[key]
127+
MessageService.error(key + " : " + err.data.customMessage[key])
128+
})
129+
}
130+
131+
if(err.data.body) {
132+
Object.keys(err.data.body).forEach(function(key){
133+
errors[key] = err.data.body[key]
134+
MessageService.error(key + " : " + err.data.body[key])
135+
})
136+
}
127137
$scope.errors = errors
128138
},function evt(event){
129139
// Only used for ssl plugin certs upload

assets/styles/_panels.scss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
$pbrands: primary $brand-primary, success $brand-success, warning $brand-warning, danger $brand-danger, info $brand-info;
2+
3+
@each $brand in $pbrands {
4+
$key: nth($brand, 1);
5+
$value: nth($brand, 2);
6+
.panel-#{$key} {
7+
border: 1px solid $value;
8+
}
9+
}

assets/styles/importer.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
@import "animloader";
1010
@import "mdi";
1111
@import "login";
12+
@import "panels";
1213

1314

1415
$color-footer-text: #999;

config/blueprints.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ module.exports.blueprints = {
9292
* `sails.config.routes`) *
9393
* *
9494
***************************************************************************/
95-
//prefix: '/api',
95+
prefix: '/api',
9696

9797
/***************************************************************************
9898
* *

config/policies.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ module.exports.policies = {
120120
},
121121

122122
SettingsController : {
123-
'initial' : true
123+
'find' : true,
124+
'*': ['authenticated','isAdmin'],
124125
}
125126

126127

config/routes.js

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -73,44 +73,45 @@ module.exports.routes = {
7373
'DELETE /kong/cluster' : 'KongInfoController.deleteCluster',
7474

7575
// Api routes
76-
'POST /kong/apis' : 'KongApiController.create',
77-
'GET /kong/apis/:id' : 'KongApiController.retrieve',
78-
'GET /kong/apis' : 'KongApiController.list',
79-
'PATCH /kong/apis/:id' : 'KongApiController.update',
80-
'PUT /kong/apis/' : 'KongApiController.updateOrCreate',
81-
'DELETE /kong/apis/:id' : 'KongApiController.delete',
82-
83-
84-
'POST /kong/consumers' : 'KongConsumerController.create',
85-
'POST /kong/consumers/:id/acls' : 'KongConsumerController.addAcl',
86-
'GET /kong/consumers/:id' : 'KongConsumerController.retrieve',
87-
'GET /kong/consumers/:id/acls' : 'KongConsumerController.retrieveAcls',
88-
'GET /kong/consumers' : 'KongConsumerController.list',
89-
'PATCH /kong/consumers/:id' : 'KongConsumerController.update',
90-
'PUT /kong/consumers' : 'KongConsumerController.updateOrCreate',
91-
'DELETE /kong/consumers/:id' : 'KongConsumerController.delete',
76+
//'POST /kong/apis' : 'KongApiController.create',
77+
//'GET /kong/apis/:id' : 'KongApiController.retrieve',
78+
'GET /kong/apis' : 'KongApiController.list',
79+
//'PATCH /kong/apis/:id' : 'KongApiController.update',
80+
//'PUT /kong/apis/' : 'KongApiController.updateOrCreate',
81+
//'DELETE /kong/apis/:id' : 'KongApiController.delete',
9282

9383

94-
'GET /kong/consumers/:id/credentials' : 'KongConsumerController.listCredentials',
95-
'GET /kong/consumers/:id/:credential' : 'KongConsumerController.retrieveCredentials',
96-
'POST /kong/consumers/:id/:credential' : 'KongConsumerController.createCredential',
97-
'DELETE /kong/consumers/:id/:credential/:credential_id' : 'KongConsumerController.removeCredential',
84+
'GET /kong/consumers' : 'KongConsumerController.list',
9885

99-
// Plugin routes
100-
'POST /kong/plugins' : 'KongPluginController.create',
101-
'DELETE /kong/plugins/:id' : 'KongPluginController.delete',
102-
'PATCH /kong/plugins/:id' : 'KongPluginController.update',
86+
//'POST /kong/consumers' : 'KongConsumerController.create',
87+
//'POST /kong/consumers/:id/acls' : 'KongConsumerController.addAcl',
88+
//'GET /kong/consumers/:id' : 'KongConsumerController.retrieve',
89+
//'GET /kong/consumers/:id/acls' : 'KongConsumerController.retrieveAcls',
90+
//'PATCH /kong/consumers/:id' : 'KongConsumerController.update',
91+
//'PUT /kong/consumers' : 'KongConsumerController.updateOrCreate',
92+
//'DELETE /kong/consumers/:id' : 'KongConsumerController.delete',
10393

10494

105-
'POST /kong/apis/:api/plugins' : 'KongPluginController.create',
106-
'GET /kong/plugins/:id' : 'KongPluginController.retrieve',
107-
'GET /kong/plugins/enabled' : 'KongPluginController.retrieveEnabled',
108-
'GET /kong/plugins/schema/:plugin' : 'KongPluginController.retrieveSchema',
95+
//'GET /kong/consumers/:id/credentials' : 'KongConsumerController.listCredentials',
96+
//'GET /kong/consumers/:id/:credential' : 'KongConsumerController.retrieveCredentials',
97+
//'POST /kong/consumers/:id/:credential' : 'KongConsumerController.createCredential',
98+
//'DELETE /kong/consumers/:id/:credential/:credential_id' : 'KongConsumerController.removeCredential',
99+
100+
// Plugin routes
101+
//'POST /kong/plugins' : 'KongPluginController.create',
102+
//'DELETE /kong/plugins/:id' : 'KongPluginController.delete',
103+
//'PATCH /kong/plugins/:id' : 'KongPluginController.update',
104+
//
105+
//
106+
//'POST /kong/apis/:api/plugins' : 'KongPluginController.create',
107+
//'GET /kong/plugins/:id' : 'KongPluginController.retrieve',
108+
//'GET /kong/plugins/enabled' : 'KongPluginController.retrieveEnabled',
109+
//'GET /kong/plugins/schema/:plugin' : 'KongPluginController.retrieveSchema',
109110
'GET /kong/plugins' : 'KongPluginController.list',
110-
'GET /kong/apis/:api/plugins' : 'KongPluginController.listApi',
111-
'PATCH /kong/apis/:api/plugins/:id' : 'KongPluginController.update',
112-
'PUT /kong/apis/:api/plugins' : 'KongPluginController.updateOrCreate',
113-
'DELETE /kong/apis/:api/plugins/:id' : 'KongPluginController.delete',
111+
//'GET /kong/apis/:api/plugins' : 'KongPluginController.listApi',
112+
//'PATCH /kong/apis/:api/plugins/:id' : 'KongPluginController.update',
113+
//'PUT /kong/apis/:api/plugins' : 'KongPluginController.updateOrCreate',
114+
//'DELETE /kong/apis/:api/plugins/:id' : 'KongPluginController.delete',
114115

115116
// Remote Storage routes
116117
'GET /remote/adapters' : 'RemoteStorageController.loadAdapters',
@@ -143,22 +144,22 @@ module.exports.routes = {
143144
'GET /api/kongnodes/healthchecks/subscribe' : 'KongNodeController.subscribeHealthChecks',
144145
'GET /api/apis/healthchecks/subscribe' : 'ApiHealthCheckController.subscribeHealthChecks',
145146

146-
// Upstream routes
147-
//'GET /kong/upstreams' : 'KongUpstreamsController.list',
147+
// Upstream routes
148+
'GET /kong/upstreams' : 'KongUpstreamsController.list',
148149

149150

150-
'GET /api/settings/initial' : 'SettingsController.initial',
151+
'GET /api/settings' : 'SettingsController.find',
151152

152153

153154
/**
154155
* Fallback to proxy
155156
*/
156157

157-
'GET /api/*' : 'ApiController.proxy',
158-
'POST /api/*' : 'ApiController.proxy',
159-
'PUT /api/*' : 'ApiController.proxy',
160-
'PATCH /api/*' : 'ApiController.proxy',
161-
'DELETE /api/*' : 'ApiController.proxy'
158+
'GET /kong/*' : 'KongProxyController.proxy',
159+
'POST /kong/*' : 'KongProxyController.proxy',
160+
'PUT /kong/*' : 'KongProxyController.proxy',
161+
'PATCH /kong/*' : 'KongProxyController.proxy',
162+
'DELETE /kong/*' : 'KongProxyController.proxy'
162163

163164

164165
};

0 commit comments

Comments
 (0)