Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade sail && Fix kong 2.5 compatibility issue #3

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
1 change: 1 addition & 0 deletions .env_example
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ DB_ADAPTER=postgres
DB_URI=postgresql://localhost:5432/konga
KONGA_LOG_LEVEL=warn
TOKEN_SECRET=some_secret_token
DB_IS_PG12_OR_NEWER=true
291 changes: 291 additions & 0 deletions .github/README_pt_BR.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ npm-debug.log
.netbeans
nbproject
.idea
.vscode
.node_history
/logs/*
!/logs/.gitkeep
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ All notable changes to this project will be documented in this file.
* Konga can now be used without authentication. In order to do that,
simply set the env var `NO_AUTH=true`.
* You can now seed default Users and Kong Connections on first install.
Check out the [docs](./docs/SEED_DEFAULT_DATA.md).
Check out the [docs](./docs/en/SEED_DEFAULT_DATA.md).
* The new env var `BASE_URL`, allows you to run Konga behind a reverse proxy on a relative path.
For example, if you configure your proxy to route requests to `example.com/konga`
you will need to set `BASE_URL=/konga/`
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 \
&& 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);

};
};
27 changes: 17 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
## More than just another GUI to [KONG Admin API](http://getkong.org) [![Build Status](https://travis-ci.org/pantsel/konga.svg?branch=master)](https://travis-ci.org/pantsel/konga) [![Gitter chat](https://badges.gitter.im/pantsel-konga/Lobby.png)](https://gitter.im/pantsel-konga/Lobby)


[![Dashboard](screenshots/bc3.png)](https://raw.githubusercontent.com/pantsel/konga/master/screenshots/bc2.png)
[![Dashboard](screenshots/bc3.png)](https://raw.githubusercontent.com/pantsel/konga/master/screenshots/bc3.png)

_Konga is not an official app. No affiliation with [Kong](https://www.konghq.com/)._

<div align="center">
<span>README on other languages</span>
<p>
<a href=".github/README_pt_BR.md">Português Brasil (pt_BR)</a>
</p>
</div>

### Support the project
If you find Konga helpful,
you can show your support and help me continue maintaining the project by [buying me a coffee](buymeacoff.ee/F1aRIj8CG)
Expand Down Expand Up @@ -62,23 +69,22 @@ or `konga:legacy` from docker hub instead.
- Npm

## Used libraries
* Sails.js, http://sailsjs.org/
* AngularJS, https://angularjs.org/
* [Sails.js, http://sailsjs.org/](http://sailsjs.org/)
* [AngularJS, https://angularjs.org](https://angularjs.org/)

## Installation

Install `npm` and `node.js`. Instructions can be found [here](http://sailsjs.org/#/getStarted?q=what-os-do-i-need).

Install `bower`, ad `gulp` packages.
Install `bower`, and `gulp` packages.
```
$ git clone https://github.com/pantsel/konga.git
$ cd konga
$ npm i
```

## Configuration
You can configure your application to use your environment specified
settings.
You can configure your application to use your environment specific settings.

There is an example configuration file on the root folder.

Expand Down Expand Up @@ -108,12 +114,13 @@ These are the general environment variables Konga uses.
| DB_PASSWORD | If `DB_URI` is not specified, this is the database user's password. Depends on `DB_ADAPTER`. | - | - |
| DB_DATABASE | If `DB_URI` is not specified, this is the name of Konga's db. Depends on `DB_ADAPTER`. | - | `konga_database` |
| DB_PG_SCHEMA | If using postgres as a database, this is the schema that will be used. | - | `public` |
| DB_IS_PG12_OR_NEWER| If `true` will set `isVersion12OrNewer: true` to sails-postgresql in order to work with Postgres12 or newer. | true/false | | false |
| KONGA_LOG_LEVEL | The logging level | `silly`,`debug`,`info`,`warn`,`error` | `debug` on dev environment & `warn` on prod. |
| TOKEN_SECRET | The secret that will be used to sign JWT tokens issued by Konga | - | - |
| NO_AUTH | Run Konga without Authentication | true/false | - |
| BASE_URL | Define a base URL or relative path that Konga will be loaded from. Ex: www.example.com/konga | <string> | - |
| KONGA_SEED_USER_DATA_SOURCE_FILE | Seed default users on first run. [Docs](./docs/SEED_DEFAULT_DATA.md). | <string> | - |
| KONGA_SEED_KONG_NODE_DATA_SOURCE_FILE | Seed default Kong Admin API connections on first run [Docs](./docs/SEED_DEFAULT_DATA.md) | <string> | - |
| KONGA_SEED_USER_DATA_SOURCE_FILE | Seed default users on first run. [Docs](./docs/en/SEED_DEFAULT_DATA.md). | <string> | - |
| KONGA_SEED_KONG_NODE_DATA_SOURCE_FILE | Seed default Kong Admin API connections on first run [Docs](./docs/en/SEED_DEFAULT_DATA.md) | <string> | - |


### Databases Integration
Expand Down Expand Up @@ -229,9 +236,9 @@ $ docker run -p 1337:1337
The GUI will be available at `http://{your server's public ip}:1337`


[It is possible to seed default users on first install.](./docs/SEED_DEFAULT_DATA.md)
[It is possible to seed default users on first install.](./docs/en/SEED_DEFAULT_DATA.md)

You may also configure Konga to authenticate via [LDAP](./docs/LDAP.md).
You may also configure Konga to authenticate via [LDAP](./docs/en/LDAP.md).


## Upgrading
Expand Down
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
Loading