Skip to content

Commit

Permalink
Merge pull request #5 from leobeckp/sails-upgrade
Browse files Browse the repository at this point in the history
Sails upgrade
  • Loading branch information
leobeckp authored Jan 12, 2022
2 parents 158cde3 + bddc8aa commit ac55fa8
Show file tree
Hide file tree
Showing 69 changed files with 25,984 additions and 7,751 deletions.
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# to fit your needs!
################################################


kongadata


################################################
Expand Down
22 changes: 14 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
FROM node:12.16-alpine
FROM node:16.13-alpine

COPY . /app
RUN apk upgrade --update \
&& apk add bash git ca-certificates \
&& npm install -g bower

COPY package.json /app/package.json
COPY package-lock.json /app/package-lock.json
COPY bower.json /app/bower.json

WORKDIR /app

RUN apk upgrade --update \
&& apk add bash git ca-certificates \
&& npm install -g bower patch-package\
&& npm --unsafe-perm --production install \
&& apk del git \
&& rm -rf /var/cache/apk/* \
RUN npm --unsafe-perm --production ci \
&& apk del git

COPY . /app

RUN rm -rf /var/cache/apk/* \
/app/.git \
/app/screenshots \
/app/test \
Expand Down
85 changes: 13 additions & 72 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,82 +1,23 @@
/**
* Gruntfile
*
* This Node script is executed when you run `grunt` or `sails lift`.
* It's purpose is to load the Grunt tasks in your project's `tasks`
* folder, and allow you to add and remove tasks as you see fit.
* For more information on how this works, check out the `README.md`
* file that was generated in your `tasks` folder.
* This Node script is executed when you run `grunt`-- and also when
* you run `sails lift` (provided the grunt hook is installed and
* hasn't been disabled).
*
* WARNING:
* Unless you know what you're doing, you shouldn't change this file.
* Check out the `tasks` directory instead.
* Check out the `tasks/` directory instead.
*
* For more information see:
* https://sailsjs.com/anatomy/Gruntfile.js
*/
module.exports = function(grunt) {

module.exports = function(grunt) {


// Load the include-all library in order to require all of our grunt
// configurations and task registrations dynamically.
var includeAll;
try {
includeAll = require('include-all');
} catch (e0) {
try {
includeAll = require('sails/node_modules/include-all');
} catch (e1) {
console.error('Could not find `include-all` module.');
console.error('Skipping grunt tasks...');
console.error('To fix this, please run:');
console.error('npm install include-all --save`');
console.error();

grunt.registerTask('default', []);
return;
}
}


/**
* Loads Grunt configuration modules from the specified
* relative path. These modules should export a function
* that, when run, should either load/configure or register
* a Grunt task.
*/
function loadTasks(relPath) {
return includeAll({
dirname: require('path').resolve(__dirname, relPath),
filter: /(.+)\.js$/,
excludeDirs: /^\.(git|svn)$/
}) || {};
}

/**
* Invokes the function from a Grunt configuration module with
* a single argument - the `grunt` object.
*/
function invokeConfigFn(tasks) {
for (var taskName in tasks) {
if (tasks.hasOwnProperty(taskName)) {
tasks[taskName](grunt);
}
}
}



// Load task functions
var taskConfigurations = loadTasks('./tasks/config'),
registerDefinitions = loadTasks('./tasks/register');

// (ensure that a default task exists)
if (!registerDefinitions.default) {
registerDefinitions.default = function(grunt) {
grunt.registerTask('default', []);
};
}
var loadGruntTasks = require('sails-hook-grunt/accessible/load-grunt-tasks');

// Run task functions to configure Grunt.
invokeConfigFn(taskConfigurations);
invokeConfigFn(registerDefinitions);
// Load Grunt task configurations (from `tasks/config/`) and Grunt
// task registrations (from `tasks/register/`).
loadGruntTasks(__dirname, grunt);

};
};
8 changes: 7 additions & 1 deletion api/base/Controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ module.exports = {
* @param {Response} response
*/
count: function count(request, response) {
var Model = actionUtil.parseModel(request);
var model = request.options.action.split('/')[0];
if (!model) { throw new Error(util.format('No "model" specified in route options.')); }

// Get the model class.
var Model = request._sails.models[model];

if ( !Model ) { throw new Error(util.format('Invalid route option, "model".\nI don\'t know about any models named: `%s`',model)); }

Model
.count(actionUtil.parseCriteria(request))
Expand Down
26 changes: 9 additions & 17 deletions api/base/Model.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,24 @@
*/
module.exports = {
schema: true,

primaryKey: 'id',
attributes: {
id: {
type: 'number',
unique: true,
autoIncrement: true
},
// Relation to User object via created user id
createdUser: {
model: 'User',
columnName: 'createdUserId',
defaultsTo: null
},
// Relation to User object via updated user id
updatedUser: {
model: 'User',
columnName: 'updatedUserId',
defaultsTo: null
},

// Dynamic model data attributes

// Created timestamp as moment object
createdAtObject: function() {
return (this.createdAt && this.createdAt != '0000-00-00 00:00:00')
? sails.services['date'].convertDateObjectToUtc(this.createdAt) : null;
columnName: 'updatedUserId'
},
// Updated timestamp as moment object
updatedAtObject: function() {
return (this.updatedAt && this.updatedAt != '0000-00-00 00:00:00')
? sails.services['date'].convertDateObjectToUtc(this.updatedAt) : null;
}
createdAt: { type: 'number', autoCreatedAt: true },
updatedAt: { type: 'number', autoUpdatedAt: true }
}
};
2 changes: 1 addition & 1 deletion api/controllers/ApiHealthCheckController.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module.exports = _.merge(_.cloneDeep(require('../base/Controller')), {

reset : function (req, res) {
sails.models.apihealthcheck.destroy({}, function (err, done) {
if(err) return res.negotiate(err);
if(err) return res.serverError(err);
return res.json(done);
})
}
Expand Down
15 changes: 8 additions & 7 deletions api/controllers/AuthController.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var async = require('async');
var _ = require('lodash');
var uuidv4 = require('uuid/v4');
var UserSignUp = require("../events/user-events")
var Passport = require("../models/Passport")

/**
* Authentication Controller
Expand Down Expand Up @@ -114,7 +115,7 @@ var AuthController = {
password: data.password,
user: user.id
}).exec(function (err, passport) {
if (err) return res.negotiate(err)
if (err) return res.serverError(err)

return res.redirect(process.env.BASE_URL || '')
})
Expand All @@ -139,7 +140,7 @@ var AuthController = {
.find()
.limit(1)
.exec(function (err, settings) {
if (err) return res.negotiate(err)
if (err) return res.serverError(err)
var _settings = settings[0].data;

if (!_settings.signup_require_activation) {
Expand All @@ -150,15 +151,15 @@ var AuthController = {
sails.models.user
.create(data)
.exec(function (err, user) {
if (err) return res.negotiate(err)
if (err) return res.serverError(err)

sails.models.passport
.create({
protocol: passports.protocol,
password: passports.password,
user: user.id
}).exec(function (err, passport) {
if (err) return res.negotiate(err)
if (err) return res.serverError(err)

// Emit signUp event
UserSignUp.emit('user.signUp', {
Expand Down Expand Up @@ -189,14 +190,14 @@ var AuthController = {
activationToken: token,
active: false
}).exec(function (err, user) {
if (err) return res.negotiate(err)
if (err) return res.serverError(err)
if (!user) return res.notFound('Invalid token')

sails.models.user.update({
id: user.id
}, {active: true})
.exec(function (err, updated) {
if (err) return res.negotiate(err)
if (err) return res.serverError(err)
return res.redirect('/#!/login?activated=' + req.param('token'))
})
})
Expand Down Expand Up @@ -342,7 +343,7 @@ var AuthController = {
var validatePassword = function validatePassword(passport, next) {
var password = request.param('password');

passport.validatePassword(password, function callback(error, matched) {
Passport.validatePassword(passport, password, function callback(error, matched) {
if (error) {
next({message: 'Invalid password'});
} else {
Expand Down
16 changes: 8 additions & 8 deletions api/controllers/KongConsumersController.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var KongConsumersController = {

// Fetch all acls of the specified consumer
Kong.listAllCb(req, '/consumers/' + consumerId + '/acls', function (err, _acls) {
if (err) return res.negotiate(err);
if (err) return res.serverError(err);

// Make an array of group names
var consumerGroups = _.map(_acls.data, function (item) {
Expand All @@ -21,7 +21,7 @@ var KongConsumersController = {

// Fetch all apis
Kong.listAllCb(req, '/apis', function (err, data) {
if (err) return res.negotiate(err);
if (err) return res.serverError(err);

var apis = data.data;

Expand All @@ -40,7 +40,7 @@ var KongConsumersController = {

// Foreach api, fetch it's assigned plugins
async.series(apiPluginsFns, function (err, data) {
if (err) return res.negotiate(err);
if (err) return res.serverError(err);

data.forEach(function (plugins, index) {

Expand Down Expand Up @@ -236,8 +236,8 @@ var KongConsumersController = {
total : filtered.length,
data : filtered
});
}catch (e) {
return res.negotiate(e);
}catch (err) {
return res.serverError(err);
}

},
Expand Down Expand Up @@ -320,7 +320,7 @@ var KongConsumersController = {

// Foreach route, fetch it's assigned plugins
async.series(routePluginsFns,function (err,data) {
if(err) return res.negotiate(err);
if(err) return res.serverError(err);

data.forEach(function(plugins,index){

Expand Down Expand Up @@ -366,8 +366,8 @@ var KongConsumersController = {
data : _.uniqBy(open.concat(eligible), 'id')
});
});
}catch(e) {
return res.negotiate(e);
}catch(err) {
return res.serverError(err);
}
}

Expand Down
10 changes: 5 additions & 5 deletions api/controllers/KongNodeController.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ module.exports = _.merge(_.cloneDeep(require('../base/Controller')), {
update : function(req,res){
sails.models.kongnode.findOne({id:req.params.id}).exec(function afterwards(err, node){

if (err) return res.negotiate(err);
if (err) return res.serverError(err);
sails.models.kongnode.update({id:req.params.id},req.body).exec(function afterwards(err, resp){

if (err) return res.negotiate(err);
if (err) return res.serverError(err);
if(req.body.active && node.active != req.body.active) {
sails.models.kongnode.update({
where: { id:{ '!': req.params.id } },

},{active:false}).exec(function afterwards(err, upd){
if (err) return res.negotiate(err);
if (err) return res.serverError(err);
return res.json(resp[0])
})
}else{
Expand All @@ -47,7 +47,7 @@ module.exports = _.merge(_.cloneDeep(require('../base/Controller')), {
sails.models.kongnode.create(req.body)
.exec(function(err, node){
if(err) {
return res.negotiate(err);
return res.serverError(err);
}

if(process.env.NODE_ENV == 'test') {
Expand All @@ -65,7 +65,7 @@ module.exports = _.merge(_.cloneDeep(require('../base/Controller')), {
kong_version : info.version
}).exec(function (err, _node) {
if(err) {
return res.negotiate(err);
return res.serverError(err);
}

return res.created(_node);
Expand Down
4 changes: 2 additions & 2 deletions api/controllers/KongProxyController.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ var self = module.exports = {
sails.log.debug("KongProxyController:listAllEntityRecords:entity", entity)

KongService.listAllCb(req, req.url, (err, data) => {
if(err) return res.negotiate(err);
if(err) return res.serverError(err);
return res.json(data);
})
},
Expand All @@ -132,7 +132,7 @@ var self = module.exports = {
unirestReq.end(function (response) {
if (response.error) {
sails.log.error("KongProxyController", "request error", response.body);
return res.negotiate(response);
return res.serverError(response);
}


Expand Down
2 changes: 1 addition & 1 deletion api/controllers/KongRoutesController.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ module.exports = _.merge(_.cloneDeep(require('../base/Controller')), {

// Fetch all consumers
KongService.listAllCb(req, `/consumers`, (err, consumers) => {
if (err) return res.negotiate(err);
if (err) return res.serverError(err);
if(!consumers.data || !consumers.data.length) return res.json([]);


Expand Down
Loading

0 comments on commit ac55fa8

Please sign in to comment.