Skip to content

Commit

Permalink
liberouter-gui v0.3.0
Browse files Browse the repository at this point in the history
* devel: (78 commits)
  Bump to version 0.3.0
  Update paths to FA and .htaccess
  Copy FA fonts to assets folder
  Add steps to build production
  Update to @angular/cli@1.1.2
  Rename getConfig function to main
  FTAS: remove ftas from environment
  FTAS: add initial config setup
  NERD: add configuration to module
  FTAS: refactoring of modal triggering
  Config: all needed methods in service
  Config: do not force absence of name
  FTAS: add configuration
  Configuration API full implementation
  ng couldn't find entry module
  Base for configuration API
  Add source for app.module bootstraping
  WIP: Configuration service for modules
  Configurable HTTP interceptor via config.json file
  Config: Add sample config file and update gitignore
  ...
  • Loading branch information
petrstehlik committed Jun 19, 2017
2 parents 64b790d + 0c1bc01 commit ab6f872
Show file tree
Hide file tree
Showing 107 changed files with 3,772 additions and 830 deletions.
7 changes: 7 additions & 0 deletions api/liberouterapi/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,13 @@ def setup():
raise ApiException("API is already setup")
settings = request.get_json()
db = dbConnector()

if len(settings['username']) == 0:
raise ApiException("Missing username")

if len(settings['password']) == 0:
raise ApiException("Missing password")

try:
# Insert user to database via user module
from .modules.users import unprotected_add_user
Expand Down
148 changes: 148 additions & 0 deletions api/liberouterapi/modules/configuration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
"""
Configuration REST API
Configuration is separated into documents where each document is identified by
name of the module, where 'liberoutergui' module is reserved for future use
in case we need something globally configurable in the Liberouter GUI.
When inserting a configuration 'name' must be unique.
"""

from flask import request

from liberouterapi import auth, dbConnector
from liberouterapi.error import ApiException
from .module import Module
from bson import json_util as json
from pymongo import ReturnDocument

class ConfError(ApiException):
status_code = 400

# Initialize connector to the configuration collection
connector = dbConnector()
conf_db = connector.db["configuration"]

conf = Module('configuration', __name__, url_prefix='/configuration', no_version = True)

@conf.route('', methods=['GET'])
#@auth.required()
def get_conf():
res = list(conf_db.find())
return (json.dumps(res))

def unprotected_get_module_conf(module):
"""
Get module's configuration specified by the module's name
Prevent from storing module liberoutergui (reserved for future use).
Each module name is converted to lowercase
"""
if module == 'liberoutergui':
raise ConfError("'liberoutergui' module name is reserved", status_code=409)

res = conf_db.find_one({
'name' : module.lower()
})

if not res:
raise ConfError("Module '%s' not found" % module, status_code=404)

return(res)


@conf.route('/<string:module>', methods=['GET'])
def get_module_conf(module):
"""
Get module by its name using the unprotected function
"""
return (json.dumps(unprotected_get_module_conf(module)))

@conf.route('/<string:module>', methods=['PUT'])
def update_conf(module):
"""
Update a module's configuration specified by its name
'name' mustn't be specified in data and data must be non-empty
"""

data = request.get_json()

if not data:
raise ConfError("Nothing to update")

if "name" in data:
del data["name"]

if "_id" in data:
del data["_id"]

res = conf_db.find_one_and_update({
"name" : str(module).lower()
},
{
"$set" : data
},
return_document=ReturnDocument.AFTER)

if not res:
raise ConfError("Can't update module '%s'" % str(module).lower())

return(json.dumps(res))

@conf.route('', methods=['POST'])
def insert_conf():
"""
Insert module's configuration, the configuration name mustn't be present in
the collection
'name' is a mandatory key
"""

conf = request.get_json()
res = {}

if 'name' not in conf:
raise ConfError("'name' must be specified in configuration")

try:
# We expect it to raise ConfError (config not found)
res = unprotected_get_module_conf(conf['name'])
except ConfError:
# Name must be lowercase
conf['name'] = conf['name'].lower()

res = conf_db.insert_one(conf)

try:
res = conf_db.find_one({
"_id" : res.inserted_id
})
except Exception as e:
raise ConfError(str(e))
else:
raise ConfError("Configuration with name '%s' already exists" % conf['name'])

return(json.dumps(res))

@conf.route('/<string:module>', methods=['DELETE'])
def remove_conf(module):
"""
Remove specified module from db
Module is identified by its name in lowercase
"""

# Get the original document
orig_config = unprotected_get_module_conf(module)

res = conf_db.delete_one({
'name' : str(module).lower()
})

if res.deleted_count != 1:
raise ConfError("Module '%s' wasn't deleted" % module, status_code=404)

return(json.dumps(orig_config))

1 change: 1 addition & 0 deletions api/liberouterapi/modules/nemea-reporter-rest
68 changes: 68 additions & 0 deletions www/.angular-cli.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"project": {
"version": "0.2.0",
"name": "liberouter-gui"
},
"apps": [
{
"root": "src",
"outDir": "dist",
"assets": [
"assets",
"favicon.ico",
".htaccess",
"../node_modules/font-awesome/fonts/*.+(otf|eot|svg|ttf|woff|woff2)"
],
"index": "index.html",
"main": "main.ts",
"polyfills": "polyfills.ts",
"test": "test.ts",
"tsconfig": "tsconfig.app.json",
"testTsconfig": "tsconfig.spec.json",
"prefix": "app",
"styles": [
"styles/main.scss",
"../node_modules/bootstrap/dist/css/bootstrap.min.css",
"../node_modules/codemirror/lib/codemirror.css"
],
"scripts": [],
"environmentSource": "environments/environment.ts",
"environments": {
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
}
],
"sassCompiler" : {
"includePaths": ["src/styles"]
},
"e2e": {
"protractor": {
"config": "./protractor.conf.js"
}
},
"lint": [
{
"project": "src/tsconfig.app.json"
},
{
"project": "src/tsconfig.spec.json"
},
{
"project": "e2e/tsconfig.e2e.json"
}
],
"test": {
"karma": {
"config": "./karma.conf.js"
}
},
"defaults": {
"styleExt": "scss",
"component": {
"inlineTemplate": false,
"spec": true
}
}
}
4 changes: 2 additions & 2 deletions www/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
indent_style = tab
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true

Expand Down
2 changes: 2 additions & 0 deletions www/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,5 @@ testem.log
#System Files
.DS_Store
Thumbs.db

config.json
4 changes: 2 additions & 2 deletions www/.htaccess
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^$ /liberouter-gui/www/dist [L]
RewriteRule ^$ / [L]
RewriteBase /dist
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /liberouter-gui/www/dist/index.html [L]
RewriteRule . /index.html [L]
</IfModule>
7 changes: 5 additions & 2 deletions www/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.
Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/).
Before running the tests make sure you are serving the app via `ng serve`.

## Further help
## Building production Liberouter GUI
Because of some weird bug in Angular CLI or TypeScript one has to build the production version of Liberouter GUI like this:

To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md).
1. run `ng build --prod --bh="/liberouter-gui/www/dist/" --aot=false -w` This will give you an error `ERROR in AppModule is not an NgModule`
2. Trigger the watch routine of Angular CLI (i.e. open and save some file inside the src folder).
3. Build finishes sucessfully.
76 changes: 0 additions & 76 deletions www/angular-cli.json

This file was deleted.

17 changes: 5 additions & 12 deletions www/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,21 @@ module.exports = function (config) {
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular/cli/plugins/karma')
],
files: [
{ pattern: './src/test.ts', watched: false }
],
preprocessors: {
'./src/test.ts': ['@angular/cli']
},
mime: {
'text/x-typescript': ['ts','tsx']
client:{
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
coverageIstanbulReporter: {
reports: [ 'html', 'lcovonly' ],
fixWebpackSourcePaths: true
},
angularCli: {
config: './angular-cli.json',
environment: 'dev'
},
reporters: config.angularCli && config.angularCli.codeCoverage
? ['progress', 'coverage-istanbul']
: ['progress'],
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
Expand All @@ -39,3 +31,4 @@ module.exports = function (config) {
singleRun: false
});
};

Loading

0 comments on commit ab6f872

Please sign in to comment.